1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * drivers/media/i2c/smiapp/ccs.h
5 * Generic driver for MIPI CCS/SMIA/SMIA++ compliant camera sensors
7 * Copyright (C) 2020 Intel Corporation
8 * Copyright (C) 2010--2012 Nokia Corporation
9 * Contact: Sakari Ailus <sakari.ailus@linux.intel.com>
15 #include <linux/mutex.h>
16 #include <linux/regmap.h>
17 #include <media/v4l2-ctrls.h>
18 #include <media/v4l2-subdev.h>
21 #include "ccs-limits.h"
22 #include "ccs-quirk.h"
24 #include "ccs-reg-access.h"
25 #include "../ccs-pll.h"
26 #include "smiapp-reg-defs.h"
29 * Standard SMIA++ constants
31 #define SMIA_VERSION_1 10
32 #define SMIAPP_VERSION_0_8 8 /* Draft 0.8 */
33 #define SMIAPP_VERSION_0_9 9 /* Draft 0.9 */
34 #define SMIAPP_VERSION_1 10
36 #define SMIAPP_PROFILE_0 0
37 #define SMIAPP_PROFILE_1 1
38 #define SMIAPP_PROFILE_2 2
40 #define SMIAPP_NVM_PAGE_SIZE 64 /* bytes */
42 #define SMIAPP_RESET_DELAY_CLOCKS 2400
43 #define SMIAPP_RESET_DELAY(clk) \
44 (1000 + (SMIAPP_RESET_DELAY_CLOCKS * 1000 \
45 + (clk) / 1000 - 1) / ((clk) / 1000))
47 #define CCS_COLOUR_COMPONENTS 4
49 #define SMIAPP_NAME "smiapp"
50 #define CCS_NAME "ccs"
52 #define CCS_DFL_I2C_ADDR (0x20 >> 1) /* Default I2C Address */
53 #define CCS_ALT_I2C_ADDR (0x6e >> 1) /* Alternate I2C Address */
55 #define CCS_LIM(sensor, limit) \
56 ccs_get_limit(sensor, CCS_L_##limit, 0)
58 #define CCS_LIM_AT(sensor, limit, offset) \
59 ccs_get_limit(sensor, CCS_L_##limit, CCS_L_##limit##_OFFSET(offset))
61 struct ccs_flash_strobe_parms
{
63 u32 strobe_width_high_us
;
65 u16 stobe_start_point
;
71 * Change the cci address if i2c_addr_alt is set.
72 * Both default and alternate cci addr need to be present
74 unsigned short i2c_addr_dfl
; /* Default i2c addr */
75 unsigned short i2c_addr_alt
; /* Alternate i2c addr */
77 u32 ext_clk
; /* sensor external clk */
79 unsigned int lanes
; /* Number of CSI-2 lanes */
80 u32 csi_signalling_mode
; /* CCS_CSI_SIGNALLING_MODE_* */
83 struct ccs_flash_strobe_parms
*strobe_setup
;
88 #define CCS_MODULE_IDENT_FLAG_REV_LE (1 << 0)
90 struct ccs_module_ident
{
91 u16 mipi_manufacturer_id
;
93 u8 smia_manufacturer_id
;
94 u8 revision_number_major
;
99 const struct ccs_quirk
*quirk
;
102 struct ccs_module_info
{
103 u32 smia_manufacturer_id
;
104 u32 mipi_manufacturer_id
;
112 u32 sensor_smia_manufacturer_id
;
113 u32 sensor_mipi_manufacturer_id
;
115 u32 sensor_revision_number
;
116 u32 sensor_firmware_version
;
123 const struct ccs_quirk
*quirk
;
126 #define CCS_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk) \
127 { .smia_manufacturer_id = manufacturer, \
129 .revision_number_major = rev, \
134 #define CCS_IDENT_LQ(manufacturer, model, rev, _name, _quirk) \
135 { .smia_manufacturer_id = manufacturer, \
137 .revision_number_major = rev, \
138 .flags = CCS_MODULE_IDENT_FLAG_REV_LE, \
142 #define CCS_IDENT_L(manufacturer, model, rev, _name) \
143 { .smia_manufacturer_id = manufacturer, \
145 .revision_number_major = rev, \
146 .flags = CCS_MODULE_IDENT_FLAG_REV_LE, \
149 #define CCS_IDENT_Q(manufacturer, model, rev, _name, _quirk) \
150 { .smia_manufacturer_id = manufacturer, \
152 .revision_number_major = rev, \
157 #define CCS_IDENT(manufacturer, model, rev, _name) \
158 { .smia_manufacturer_id = manufacturer, \
160 .revision_number_major = rev, \
164 struct ccs_csi_data_format
{
171 #define CCS_SUBDEVS 3
173 #define CCS_PA_PAD_SRC 0
174 #define CCS_PAD_SINK 0
175 #define CCS_PAD_SRC 1
178 struct ccs_binning_subtype
{
184 struct v4l2_subdev sd
;
185 struct media_pad pads
[CCS_PADS
];
186 unsigned short sink_pad
;
187 unsigned short source_pad
;
189 struct ccs_sensor
*sensor
;
190 struct v4l2_ctrl_handler ctrl_handler
;
194 * struct ccs_sensor - Main device structure
198 * "mutex" is used to serialise access to all fields here
199 * except v4l2_ctrls at the end of the struct. "mutex" is also
200 * used to serialise access to file handle specific
204 struct ccs_subdev ssds
[CCS_SUBDEVS
];
206 struct ccs_subdev
*src
;
207 struct ccs_subdev
*binner
;
208 struct ccs_subdev
*scaler
;
209 struct ccs_subdev
*pixel_array
;
210 struct ccs_hwconfig hwcfg
;
211 struct regulator_bulk_data
*regulators
;
213 struct gpio_desc
*xshutdown
;
214 struct gpio_desc
*reset
;
215 struct regmap
*regmap
;
217 u8 nbinning_subtypes
;
218 struct ccs_binning_subtype binning_subtypes
[CCS_LIM_BINNING_SUB_TYPE_MAX_N
+ 1];
220 const struct ccs_csi_data_format
*csi_format
;
221 const struct ccs_csi_data_format
*internal_csi_format
;
222 struct v4l2_rect pa_src
, scaler_sink
, src_src
;
223 u32 default_mbus_frame_fmts
;
224 int default_pixel_order
;
225 struct ccs_data_container sdata
, mdata
;
227 u8 binning_horizontal
;
234 u16 embedded_start
; /* embedded data start line */
236 u16 image_start
; /* image data start line */
237 u16 visible_pixel_start
; /* start pixel of the visible image */
241 bool handler_setup_needed
;
242 u8 compressed_min_bpp
;
244 struct ccs_module_info minfo
;
248 /* Is a default format supported for a given BPP? */
249 unsigned long *valid_link_freqs
;
251 /* Pixel array controls */
252 struct v4l2_ctrl
*exposure
;
253 struct v4l2_ctrl
*hflip
;
254 struct v4l2_ctrl
*vflip
;
255 struct v4l2_ctrl
*vblank
;
256 struct v4l2_ctrl
*hblank
;
257 struct v4l2_ctrl
*pixel_rate_parray
;
258 struct v4l2_ctrl
*luminance_level
;
260 struct v4l2_ctrl
*link_freq
;
261 struct v4l2_ctrl
*pixel_rate_csi
;
262 /* test pattern colour components */
263 struct v4l2_ctrl
*test_data
[CCS_COLOUR_COMPONENTS
];
266 #define to_ccs_subdev(_sd) \
267 container_of(_sd, struct ccs_subdev, sd)
269 #define to_ccs_sensor(_sd) \
270 (to_ccs_subdev(_sd)->sensor)
272 void ccs_replace_limit(struct ccs_sensor
*sensor
,
273 unsigned int limit
, unsigned int offset
, u32 val
);
274 u32
ccs_get_limit(struct ccs_sensor
*sensor
, unsigned int limit
,
275 unsigned int offset
);
277 #endif /* __CCS_H__ */