Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / media / platform / qcom / camss / camss-csid.h
blob8cdae98e4dca6d39d9d2c3807dd171aeb5458762
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * camss-csid.h
5 * Qualcomm MSM Camera Subsystem - CSID (CSI Decoder) Module
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
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>
21 #define MSM_CSID_PAD_SINK 0
22 #define MSM_CSID_PAD_FIRST_SRC 1
23 #define MSM_CSID_PADS_NUM 5
25 #define MSM_CSID_PAD_SRC (MSM_CSID_PAD_FIRST_SRC)
27 /* CSID hardware can demultiplex up to 4 outputs */
28 #define MSM_CSID_MAX_SRC_STREAMS 4
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
53 #define CSID_RESET_TIMEOUT_MS 500
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 */
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 */
78 struct csid_formats {
79 unsigned int nformats;
80 const struct csid_format_info *formats;
83 struct csid_testgen_config {
84 enum csid_testgen_mode mode;
85 const char * const*modes;
86 u8 nmodes;
87 u8 enabled;
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;
98 struct csid_device;
100 struct csid_hw_ops {
102 * configure_stream - Configures and starts CSID input stream
103 * @csid: CSID device
105 void (*configure_stream)(struct csid_device *csid, u8 enable);
108 * configure_testgen_pattern - Validates and configures output pattern mode
109 * of test pattern generator
110 * @csid: CSID device
112 int (*configure_testgen_pattern)(struct csid_device *csid, s32 val);
115 * hw_version - Read hardware version register from hardware
116 * @csid: CSID device
118 u32 (*hw_version)(struct csid_device *csid);
121 * isr - CSID module interrupt service routine
122 * @irq: Interrupt line
123 * @dev: CSID device
125 * Return IRQ_HANDLED on success
127 irqreturn_t (*isr)(int irq, void *dev);
130 * reset - Trigger reset on CSID module and wait to complete
131 * @csid: CSID device
133 * Return 0 on success or a negative error code otherwise
135 int (*reset)(struct csid_device *csid);
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
145 * Return 0 on failure or src format code otherwise
147 u32 (*src_pad_code)(struct csid_device *csid, u32 sink_code,
148 unsigned int match_format_idx, u32 match_code);
151 * subdev_init - Initialize CSID device according for hardware revision
152 * @csid: CSID device
154 void (*subdev_init)(struct csid_device *csid);
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;
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;
185 struct camss_subdev_resources;
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
195 * Return 0 on failure or format code otherwise
197 u32 csid_find_code(u32 *codes, unsigned int ncode,
198 unsigned int match_format_idx, u32 match_code);
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
206 * Return formats[0] on failure to find code
208 const struct csid_format_info *csid_get_fmt_entry(const struct csid_format_info *formats,
209 unsigned int nformats,
210 u32 code);
212 int msm_csid_subdev_init(struct camss *camss, struct csid_device *csid,
213 const struct camss_subdev_resources *res, u8 id);
215 int msm_csid_register_entity(struct csid_device *csid,
216 struct v4l2_device *v4l2_dev);
218 void msm_csid_unregister_entity(struct csid_device *csid);
220 void msm_csid_get_csid_id(struct media_entity *entity, u8 *id);
222 extern const char * const csid_testgen_modes[];
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;
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;
233 * csid_is_lite - Check if CSID is CSID lite.
234 * @csid: CSID Device
236 * Return whether CSID is CSID lite
238 bool csid_is_lite(struct csid_device *csid);
240 #endif /* QC_MSM_CAMSS_CSID_H */