xref: /linux/drivers/media/platform/qcom/camss/camss-csid.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
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_info {
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_formats {
79 	unsigned int nformats;
80 	const struct csid_format_info *formats;
81 };
82 
83 struct csid_testgen_config {
84 	enum csid_testgen_mode mode;
85 	const char * const*modes;
86 	u8 nmodes;
87 	u8 enabled;
88 };
89 
90 struct csid_phy_config {
91 	u8 csiphy_id;
92 	u8 lane_cnt;
93 	u32 lane_assign;
94 	u32 en_vc;
95 	u8 need_vc_update;
96 };
97 
98 struct csid_device;
99 
100 struct csid_hw_ops {
101 	/*
102 	 * configure_stream - Configures and starts CSID input stream
103 	 * @csid: CSID device
104 	 */
105 	void (*configure_stream)(struct csid_device *csid, u8 enable);
106 
107 	/*
108 	 * configure_testgen_pattern - Validates and configures output pattern mode
109 	 * of test pattern generator
110 	 * @csid: CSID device
111 	 */
112 	int (*configure_testgen_pattern)(struct csid_device *csid, s32 val);
113 
114 	/*
115 	 * hw_version - Read hardware version register from hardware
116 	 * @csid: CSID device
117 	 */
118 	u32 (*hw_version)(struct csid_device *csid);
119 
120 	/*
121 	 * isr - CSID module interrupt service routine
122 	 * @irq: Interrupt line
123 	 * @dev: CSID device
124 	 *
125 	 * Return IRQ_HANDLED on success
126 	 */
127 	irqreturn_t (*isr)(int irq, void *dev);
128 
129 	/*
130 	 * reset - Trigger reset on CSID module and wait to complete
131 	 * @csid: CSID device
132 	 *
133 	 * Return 0 on success or a negative error code otherwise
134 	 */
135 	int (*reset)(struct csid_device *csid);
136 
137 	/*
138 	 * src_pad_code - Pick an output/src format based on the input/sink format
139 	 * @csid: CSID device
140 	 * @sink_code: The sink format of the input
141 	 * @match_format_idx: Request preferred index, as defined by subdevice csid_format.
142 	 *	Set @match_code to 0 if used.
143 	 * @match_code: Request preferred code, set @match_format_idx to 0 if used
144 	 *
145 	 * Return 0 on failure or src format code otherwise
146 	 */
147 	u32 (*src_pad_code)(struct csid_device *csid, u32 sink_code,
148 			    unsigned int match_format_idx, u32 match_code);
149 
150 	/*
151 	 * subdev_init - Initialize CSID device according for hardware revision
152 	 * @csid: CSID device
153 	 */
154 	void (*subdev_init)(struct csid_device *csid);
155 };
156 
157 struct csid_subdev_resources {
158 	bool is_lite;
159 	const struct csid_hw_ops *hw_ops;
160 	const struct parent_dev_ops *parent_dev_ops;
161 	const struct csid_formats *formats;
162 };
163 
164 struct csid_device {
165 	struct camss *camss;
166 	u8 id;
167 	struct v4l2_subdev subdev;
168 	struct media_pad pads[MSM_CSID_PADS_NUM];
169 	void __iomem *base;
170 	u32 irq;
171 	char irq_name[30];
172 	struct camss_clock *clock;
173 	int nclocks;
174 	struct regulator_bulk_data *supplies;
175 	int num_supplies;
176 	struct completion reset_complete;
177 	struct csid_testgen_config testgen;
178 	struct csid_phy_config phy;
179 	struct v4l2_mbus_framefmt fmt[MSM_CSID_PADS_NUM];
180 	struct v4l2_ctrl_handler ctrls;
181 	struct v4l2_ctrl *testgen_mode;
182 	const struct csid_subdev_resources *res;
183 };
184 
185 struct camss_subdev_resources;
186 
187 /*
188  * csid_find_code - Find a format code in an array using array index or format code
189  * @codes: Array of format codes
190  * @ncodes: Length of @code array
191  * @req_format_idx: Request preferred index, as defined by subdevice csid_format.
192  *	Set @match_code to 0 if used.
193  * @match_code: Request preferred code, set @req_format_idx to 0 if used
194  *
195  * Return 0 on failure or format code otherwise
196  */
197 u32 csid_find_code(u32 *codes, unsigned int ncode,
198 		   unsigned int match_format_idx, u32 match_code);
199 
200 /*
201  * csid_get_fmt_entry - Find csid_format_info entry with matching format code
202  * @formats: Array of format csid_format_info entries
203  * @nformats: Length of @nformats array
204  * @code: Desired format code
205  *
206  * Return formats[0] on failure to find code
207  */
208 const struct csid_format_info *csid_get_fmt_entry(const struct csid_format_info *formats,
209 						  unsigned int nformats,
210 						  u32 code);
211 
212 int msm_csid_subdev_init(struct camss *camss, struct csid_device *csid,
213 			 const struct camss_subdev_resources *res, u8 id);
214 
215 int msm_csid_register_entity(struct csid_device *csid,
216 			     struct v4l2_device *v4l2_dev);
217 
218 void msm_csid_unregister_entity(struct csid_device *csid);
219 
220 void msm_csid_get_csid_id(struct media_entity *entity, u8 *id);
221 
222 extern const char * const csid_testgen_modes[];
223 
224 extern const struct csid_formats csid_formats_4_1;
225 extern const struct csid_formats csid_formats_4_7;
226 extern const struct csid_formats csid_formats_gen2;
227 
228 extern const struct csid_hw_ops csid_ops_4_1;
229 extern const struct csid_hw_ops csid_ops_4_7;
230 extern const struct csid_hw_ops csid_ops_gen2;
231 
232 /*
233  * csid_is_lite - Check if CSID is CSID lite.
234  * @csid: CSID Device
235  *
236  * Return whether CSID is CSID lite
237  */
238 bool csid_is_lite(struct csid_device *csid);
239 
240 #endif /* QC_MSM_CAMSS_CSID_H */
241