1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * drivers/media/i2c/smiapp/smiapp.h
5 * Generic driver for SMIA/SMIA++ compliant camera modules
7 * Copyright (C) 2010--2012 Nokia Corporation
8 * Contact: Sakari Ailus <sakari.ailus@iki.fi>
11 #ifndef __SMIAPP_PRIV_H_
12 #define __SMIAPP_PRIV_H_
14 #include <linux/mutex.h>
15 #include <media/v4l2-ctrls.h>
16 #include <media/v4l2-subdev.h>
18 #include "smiapp-pll.h"
19 #include "smiapp-reg.h"
20 #include "smiapp-regs.h"
21 #include "smiapp-quirk.h"
24 * Standard SMIA++ constants
26 #define SMIA_VERSION_1 10
27 #define SMIAPP_VERSION_0_8 8 /* Draft 0.8 */
28 #define SMIAPP_VERSION_0_9 9 /* Draft 0.9 */
29 #define SMIAPP_VERSION_1 10
31 #define SMIAPP_PROFILE_0 0
32 #define SMIAPP_PROFILE_1 1
33 #define SMIAPP_PROFILE_2 2
35 #define SMIAPP_NVM_PAGE_SIZE 64 /* bytes */
37 #define SMIAPP_RESET_DELAY_CLOCKS 2400
38 #define SMIAPP_RESET_DELAY(clk) \
39 (1000 + (SMIAPP_RESET_DELAY_CLOCKS * 1000 \
40 + (clk) / 1000 - 1) / ((clk) / 1000))
42 #define SMIAPP_COLOUR_COMPONENTS 4
44 #define SMIAPP_NAME "smiapp"
46 #define SMIAPP_DFL_I2C_ADDR (0x20 >> 1) /* Default I2C Address */
47 #define SMIAPP_ALT_I2C_ADDR (0x6e >> 1) /* Alternate I2C Address */
50 * Sometimes due to board layout considerations the camera module can be
51 * mounted rotated. The typical rotation used is 180 degrees which can be
52 * corrected by giving a default H-FLIP and V-FLIP in the sensor readout.
53 * FIXME: rotation also changes the bayer pattern.
55 enum smiapp_module_board_orient
{
56 SMIAPP_MODULE_BOARD_ORIENT_0
= 0,
57 SMIAPP_MODULE_BOARD_ORIENT_180
,
60 struct smiapp_flash_strobe_parms
{
62 u32 strobe_width_high_us
;
64 u16 stobe_start_point
;
68 struct smiapp_hwconfig
{
70 * Change the cci address if i2c_addr_alt is set.
71 * Both default and alternate cci addr need to be present
73 unsigned short i2c_addr_dfl
; /* Default i2c addr */
74 unsigned short i2c_addr_alt
; /* Alternate i2c addr */
76 uint32_t ext_clk
; /* sensor external clk */
78 unsigned int lanes
; /* Number of CSI-2 lanes */
79 uint32_t csi_signalling_mode
; /* SMIAPP_CSI_SIGNALLING_MODE_* */
80 uint64_t *op_sys_clock
;
82 enum smiapp_module_board_orient module_board_orient
;
84 struct smiapp_flash_strobe_parms
*strobe_setup
;
87 #include "smiapp-limits.h"
91 #define SMIAPP_MODULE_IDENT_FLAG_REV_LE (1 << 0)
93 struct smiapp_module_ident
{
96 u8 revision_number_major
;
101 const struct smiapp_quirk
*quirk
;
104 struct smiapp_module_info
{
107 u32 revision_number_major
;
108 u32 revision_number_minor
;
114 u32 sensor_manufacturer_id
;
116 u32 sensor_revision_number
;
117 u32 sensor_firmware_version
;
125 const struct smiapp_quirk
*quirk
;
128 #define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk) \
129 { .manufacturer_id = manufacturer, \
131 .revision_number_major = rev, \
136 #define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk) \
137 { .manufacturer_id = manufacturer, \
139 .revision_number_major = rev, \
140 .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
144 #define SMIAPP_IDENT_L(manufacturer, model, rev, _name) \
145 { .manufacturer_id = manufacturer, \
147 .revision_number_major = rev, \
148 .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
151 #define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk) \
152 { .manufacturer_id = manufacturer, \
154 .revision_number_major = rev, \
159 #define SMIAPP_IDENT(manufacturer, model, rev, _name) \
160 { .manufacturer_id = manufacturer, \
162 .revision_number_major = rev, \
166 struct smiapp_reg_limits
{
171 extern struct smiapp_reg_limits smiapp_reg_limits
[];
173 struct smiapp_csi_data_format
{
180 #define SMIAPP_SUBDEVS 3
182 #define SMIAPP_PA_PAD_SRC 0
183 #define SMIAPP_PAD_SINK 0
184 #define SMIAPP_PAD_SRC 1
185 #define SMIAPP_PADS 2
187 struct smiapp_binning_subtype
{
192 struct smiapp_subdev
{
193 struct v4l2_subdev sd
;
194 struct media_pad pads
[SMIAPP_PADS
];
195 struct v4l2_rect sink_fmt
;
196 struct v4l2_rect crop
[SMIAPP_PADS
];
197 struct v4l2_rect compose
; /* compose on sink */
198 unsigned short sink_pad
;
199 unsigned short source_pad
;
201 struct smiapp_sensor
*sensor
;
202 struct v4l2_ctrl_handler ctrl_handler
;
206 * struct smiapp_sensor - Main device structure
208 struct smiapp_sensor
{
210 * "mutex" is used to serialise access to all fields here
211 * except v4l2_ctrls at the end of the struct. "mutex" is also
212 * used to serialise access to file handle specific
216 struct smiapp_subdev ssds
[SMIAPP_SUBDEVS
];
218 struct smiapp_subdev
*src
;
219 struct smiapp_subdev
*binner
;
220 struct smiapp_subdev
*scaler
;
221 struct smiapp_subdev
*pixel_array
;
222 struct smiapp_hwconfig
*hwcfg
;
223 struct regulator
*vana
;
225 struct gpio_desc
*xshutdown
;
226 u32 limits
[SMIAPP_LIMIT_LAST
];
227 u8 nbinning_subtypes
;
228 struct smiapp_binning_subtype binning_subtypes
[SMIAPP_BINNING_SUBTYPES
];
230 const struct smiapp_csi_data_format
*csi_format
;
231 const struct smiapp_csi_data_format
*internal_csi_format
;
232 u32 default_mbus_frame_fmts
;
233 int default_pixel_order
;
235 u8 binning_horizontal
;
241 u8 hvflip_inv_mask
; /* H/VFLIP inversion due to sensor orientation */
243 u16 embedded_start
; /* embedded data start line */
245 u16 image_start
; /* image data start line */
246 u16 visible_pixel_start
; /* start pixel of the visible image */
250 u8 compressed_min_bpp
;
252 struct smiapp_module_info minfo
;
254 struct smiapp_pll pll
;
256 /* Is a default format supported for a given BPP? */
257 unsigned long *valid_link_freqs
;
259 /* Pixel array controls */
260 struct v4l2_ctrl
*analog_gain
;
261 struct v4l2_ctrl
*exposure
;
262 struct v4l2_ctrl
*hflip
;
263 struct v4l2_ctrl
*vflip
;
264 struct v4l2_ctrl
*vblank
;
265 struct v4l2_ctrl
*hblank
;
266 struct v4l2_ctrl
*pixel_rate_parray
;
268 struct v4l2_ctrl
*link_freq
;
269 struct v4l2_ctrl
*pixel_rate_csi
;
270 /* test pattern colour components */
271 struct v4l2_ctrl
*test_data
[SMIAPP_COLOUR_COMPONENTS
];
274 #define to_smiapp_subdev(_sd) \
275 container_of(_sd, struct smiapp_subdev, sd)
277 #define to_smiapp_sensor(_sd) \
278 (to_smiapp_subdev(_sd)->sensor)
280 #endif /* __SMIAPP_PRIV_H_ */