• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * camss-csid.h
4  *
5  * Qualcomm MSM Camera Subsystem - CSID (CSI Decoder) Module
6  *
7  * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
8  * Copyright (C) 2015-2018 Linaro Ltd.
9  */
10 #ifndef QC_MSM_CAMSS_CSID_H
11 #define QC_MSM_CAMSS_CSID_H
12 
13 #include <linux/clk.h>
14 #include <linux/interrupt.h>
15 #include <media/media-entity.h>
16 #include <media/v4l2-ctrls.h>
17 #include <media/v4l2-device.h>
18 #include <media/v4l2-mediabus.h>
19 #include <media/v4l2-subdev.h>
20 
21 #define MSM_CSID_PAD_SINK 0
22 #define MSM_CSID_PAD_FIRST_SRC 1
23 #define MSM_CSID_PADS_NUM 5
24 
25 #define MSM_CSID_PAD_SRC (MSM_CSID_PAD_FIRST_SRC)
26 
27 /* CSID hardware can demultiplex up to 4 outputs */
28 #define MSM_CSID_MAX_SRC_STREAMS	4
29 
30 #define DATA_TYPE_EMBEDDED_DATA_8BIT	0x12
31 #define DATA_TYPE_YUV420_8BIT		0x18
32 #define DATA_TYPE_YUV420_10BIT		0x19
33 #define DATA_TYPE_YUV420_8BIT_LEGACY	0x1a
34 #define DATA_TYPE_YUV420_8BIT_SHIFTED	0x1c /* Chroma Shifted Pixel Sampling */
35 #define DATA_TYPE_YUV420_10BIT_SHIFTED	0x1d /* Chroma Shifted Pixel Sampling */
36 #define DATA_TYPE_YUV422_8BIT		0x1e
37 #define DATA_TYPE_YUV422_10BIT		0x1f
38 #define DATA_TYPE_RGB444		0x20
39 #define DATA_TYPE_RGB555		0x21
40 #define DATA_TYPE_RGB565		0x22
41 #define DATA_TYPE_RGB666		0x23
42 #define DATA_TYPE_RGB888		0x24
43 #define DATA_TYPE_RAW_24BIT		0x27
44 #define DATA_TYPE_RAW_6BIT		0x28
45 #define DATA_TYPE_RAW_7BIT		0x29
46 #define DATA_TYPE_RAW_8BIT		0x2a
47 #define DATA_TYPE_RAW_10BIT		0x2b
48 #define DATA_TYPE_RAW_12BIT		0x2c
49 #define DATA_TYPE_RAW_14BIT		0x2d
50 #define DATA_TYPE_RAW_16BIT		0x2e
51 #define DATA_TYPE_RAW_20BIT		0x2f
52 
53 #define CSID_RESET_TIMEOUT_MS 500
54 
55 enum csid_testgen_mode {
56 	CSID_PAYLOAD_MODE_DISABLED = 0,
57 	CSID_PAYLOAD_MODE_INCREMENTING = 1,
58 	CSID_PAYLOAD_MODE_ALTERNATING_55_AA = 2,
59 	CSID_PAYLOAD_MODE_ALL_ZEROES = 3,
60 	CSID_PAYLOAD_MODE_ALL_ONES = 4,
61 	CSID_PAYLOAD_MODE_RANDOM = 5,
62 	CSID_PAYLOAD_MODE_USER_SPECIFIED = 6,
63 	CSID_PAYLOAD_MODE_NUM_SUPPORTED_GEN1 = 6, /* excluding disabled */
64 	CSID_PAYLOAD_MODE_COMPLEX_PATTERN = 7,
65 	CSID_PAYLOAD_MODE_COLOR_BOX = 8,
66 	CSID_PAYLOAD_MODE_COLOR_BARS = 9,
67 	CSID_PAYLOAD_MODE_NUM_SUPPORTED_GEN2 = 9, /* excluding disabled */
68 };
69 
70 struct csid_format {
71 	u32 code;
72 	u8 data_type;
73 	u8 decode_format;
74 	u8 bpp;
75 	u8 spp; /* bus samples per pixel */
76 };
77 
78 struct csid_testgen_config {
79 	enum csid_testgen_mode mode;
80 	const char * const*modes;
81 	u8 nmodes;
82 	u8 enabled;
83 };
84 
85 struct csid_phy_config {
86 	u8 csiphy_id;
87 	u8 lane_cnt;
88 	u32 lane_assign;
89 	u32 en_vc;
90 	u8 need_vc_update;
91 };
92 
93 struct csid_device;
94 
95 struct csid_hw_ops {
96 	/*
97 	 * configure_stream - Configures and starts CSID input stream
98 	 * @csid: CSID device
99 	 */
100 	void (*configure_stream)(struct csid_device *csid, u8 enable);
101 
102 	/*
103 	 * configure_testgen_pattern - Validates and configures output pattern mode
104 	 * of test pattern generator
105 	 * @csid: CSID device
106 	 */
107 	int (*configure_testgen_pattern)(struct csid_device *csid, s32 val);
108 
109 	/*
110 	 * hw_version - Read hardware version register from hardware
111 	 * @csid: CSID device
112 	 */
113 	u32 (*hw_version)(struct csid_device *csid);
114 
115 	/*
116 	 * isr - CSID module interrupt service routine
117 	 * @irq: Interrupt line
118 	 * @dev: CSID device
119 	 *
120 	 * Return IRQ_HANDLED on success
121 	 */
122 	irqreturn_t (*isr)(int irq, void *dev);
123 
124 	/*
125 	 * reset - Trigger reset on CSID module and wait to complete
126 	 * @csid: CSID device
127 	 *
128 	 * Return 0 on success or a negative error code otherwise
129 	 */
130 	int (*reset)(struct csid_device *csid);
131 
132 	/*
133 	 * src_pad_code - Pick an output/src format based on the input/sink format
134 	 * @csid: CSID device
135 	 * @sink_code: The sink format of the input
136 	 * @match_format_idx: Request preferred index, as defined by subdevice csid_format.
137 	 *	Set @match_code to 0 if used.
138 	 * @match_code: Request preferred code, set @match_format_idx to 0 if used
139 	 *
140 	 * Return 0 on failure or src format code otherwise
141 	 */
142 	u32 (*src_pad_code)(struct csid_device *csid, u32 sink_code,
143 			    unsigned int match_format_idx, u32 match_code);
144 
145 	/*
146 	 * subdev_init - Initialize CSID device according for hardware revision
147 	 * @csid: CSID device
148 	 */
149 	void (*subdev_init)(struct csid_device *csid);
150 };
151 
152 struct csid_device {
153 	struct camss *camss;
154 	u8 id;
155 	struct v4l2_subdev subdev;
156 	struct media_pad pads[MSM_CSID_PADS_NUM];
157 	void __iomem *base;
158 	u32 irq;
159 	char irq_name[30];
160 	struct camss_clock *clock;
161 	int nclocks;
162 	struct regulator *vdda;
163 	struct completion reset_complete;
164 	struct csid_testgen_config testgen;
165 	struct csid_phy_config phy;
166 	struct v4l2_mbus_framefmt fmt[MSM_CSID_PADS_NUM];
167 	struct v4l2_ctrl_handler ctrls;
168 	struct v4l2_ctrl *testgen_mode;
169 	const struct csid_format *formats;
170 	unsigned int nformats;
171 	const struct csid_hw_ops *ops;
172 };
173 
174 struct resources;
175 
176 /*
177  * csid_find_code - Find a format code in an array using array index or format code
178  * @codes: Array of format codes
179  * @ncodes: Length of @code array
180  * @req_format_idx: Request preferred index, as defined by subdevice csid_format.
181  *	Set @match_code to 0 if used.
182  * @match_code: Request preferred code, set @req_format_idx to 0 if used
183  *
184  * Return 0 on failure or format code otherwise
185  */
186 u32 csid_find_code(u32 *codes, unsigned int ncode,
187 		   unsigned int match_format_idx, u32 match_code);
188 
189 /*
190  * csid_get_fmt_entry - Find csid_format entry with matching format code
191  * @formats: Array of format csid_format entries
192  * @nformats: Length of @nformats array
193  * @code: Desired format code
194  *
195  * Return formats[0] on failure to find code
196  */
197 const struct csid_format *csid_get_fmt_entry(const struct csid_format *formats,
198 					     unsigned int nformats,
199 					     u32 code);
200 
201 int msm_csid_subdev_init(struct camss *camss, struct csid_device *csid,
202 			 const struct resources *res, u8 id);
203 
204 int msm_csid_register_entity(struct csid_device *csid,
205 			     struct v4l2_device *v4l2_dev);
206 
207 void msm_csid_unregister_entity(struct csid_device *csid);
208 
209 void msm_csid_get_csid_id(struct media_entity *entity, u8 *id);
210 
211 extern const char * const csid_testgen_modes[];
212 
213 extern const struct csid_hw_ops csid_ops_4_1;
214 extern const struct csid_hw_ops csid_ops_4_7;
215 extern const struct csid_hw_ops csid_ops_170;
216 
217 
218 #endif /* QC_MSM_CAMSS_CSID_H */
219