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>
17 #include <media/i2c/smiapp.h>
19 #include "smiapp-pll.h"
20 #include "smiapp-reg.h"
21 #include "smiapp-regs.h"
22 #include "smiapp-quirk.h"
25 * Standard SMIA++ constants
27 #define SMIA_VERSION_1 10
28 #define SMIAPP_VERSION_0_8 8 /* Draft 0.8 */
29 #define SMIAPP_VERSION_0_9 9 /* Draft 0.9 */
30 #define SMIAPP_VERSION_1 10
32 #define SMIAPP_PROFILE_0 0
33 #define SMIAPP_PROFILE_1 1
34 #define SMIAPP_PROFILE_2 2
36 #define SMIAPP_NVM_PAGE_SIZE 64 /* bytes */
38 #define SMIAPP_RESET_DELAY_CLOCKS 2400
39 #define SMIAPP_RESET_DELAY(clk) \
40 (1000 + (SMIAPP_RESET_DELAY_CLOCKS * 1000 \
41 + (clk) / 1000 - 1) / ((clk) / 1000))
43 #define SMIAPP_COLOUR_COMPONENTS 4
45 #include "smiapp-limits.h"
49 #define SMIAPP_MODULE_IDENT_FLAG_REV_LE (1 << 0)
51 struct smiapp_module_ident
{
54 u8 revision_number_major
;
59 const struct smiapp_quirk
*quirk
;
62 struct smiapp_module_info
{
65 u32 revision_number_major
;
66 u32 revision_number_minor
;
72 u32 sensor_manufacturer_id
;
74 u32 sensor_revision_number
;
75 u32 sensor_firmware_version
;
83 const struct smiapp_quirk
*quirk
;
86 #define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk) \
87 { .manufacturer_id = manufacturer, \
89 .revision_number_major = rev, \
94 #define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk) \
95 { .manufacturer_id = manufacturer, \
97 .revision_number_major = rev, \
98 .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
102 #define SMIAPP_IDENT_L(manufacturer, model, rev, _name) \
103 { .manufacturer_id = manufacturer, \
105 .revision_number_major = rev, \
106 .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
109 #define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk) \
110 { .manufacturer_id = manufacturer, \
112 .revision_number_major = rev, \
117 #define SMIAPP_IDENT(manufacturer, model, rev, _name) \
118 { .manufacturer_id = manufacturer, \
120 .revision_number_major = rev, \
124 struct smiapp_reg_limits
{
129 extern struct smiapp_reg_limits smiapp_reg_limits
[];
131 struct smiapp_csi_data_format
{
138 #define SMIAPP_SUBDEVS 3
140 #define SMIAPP_PA_PAD_SRC 0
141 #define SMIAPP_PAD_SINK 0
142 #define SMIAPP_PAD_SRC 1
143 #define SMIAPP_PADS 2
145 struct smiapp_binning_subtype
{
150 struct smiapp_subdev
{
151 struct v4l2_subdev sd
;
152 struct media_pad pads
[SMIAPP_PADS
];
153 struct v4l2_rect sink_fmt
;
154 struct v4l2_rect crop
[SMIAPP_PADS
];
155 struct v4l2_rect compose
; /* compose on sink */
156 unsigned short sink_pad
;
157 unsigned short source_pad
;
159 struct smiapp_sensor
*sensor
;
160 struct v4l2_ctrl_handler ctrl_handler
;
164 * struct smiapp_sensor - Main device structure
166 struct smiapp_sensor
{
168 * "mutex" is used to serialise access to all fields here
169 * except v4l2_ctrls at the end of the struct. "mutex" is also
170 * used to serialise access to file handle specific
174 struct smiapp_subdev ssds
[SMIAPP_SUBDEVS
];
176 struct smiapp_subdev
*src
;
177 struct smiapp_subdev
*binner
;
178 struct smiapp_subdev
*scaler
;
179 struct smiapp_subdev
*pixel_array
;
180 struct smiapp_hwconfig
*hwcfg
;
181 struct regulator
*vana
;
183 struct gpio_desc
*xshutdown
;
184 u32 limits
[SMIAPP_LIMIT_LAST
];
185 u8 nbinning_subtypes
;
186 struct smiapp_binning_subtype binning_subtypes
[SMIAPP_BINNING_SUBTYPES
];
188 const struct smiapp_csi_data_format
*csi_format
;
189 const struct smiapp_csi_data_format
*internal_csi_format
;
190 u32 default_mbus_frame_fmts
;
191 int default_pixel_order
;
193 u8 binning_horizontal
;
199 u8 hvflip_inv_mask
; /* H/VFLIP inversion due to sensor orientation */
201 u16 embedded_start
; /* embedded data start line */
203 u16 image_start
; /* image data start line */
204 u16 visible_pixel_start
; /* start pixel of the visible image */
208 u8 compressed_min_bpp
;
210 struct smiapp_module_info minfo
;
212 struct smiapp_pll pll
;
214 /* Is a default format supported for a given BPP? */
215 unsigned long *valid_link_freqs
;
217 /* Pixel array controls */
218 struct v4l2_ctrl
*analog_gain
;
219 struct v4l2_ctrl
*exposure
;
220 struct v4l2_ctrl
*hflip
;
221 struct v4l2_ctrl
*vflip
;
222 struct v4l2_ctrl
*vblank
;
223 struct v4l2_ctrl
*hblank
;
224 struct v4l2_ctrl
*pixel_rate_parray
;
226 struct v4l2_ctrl
*link_freq
;
227 struct v4l2_ctrl
*pixel_rate_csi
;
228 /* test pattern colour components */
229 struct v4l2_ctrl
*test_data
[SMIAPP_COLOUR_COMPONENTS
];
232 #define to_smiapp_subdev(_sd) \
233 container_of(_sd, struct smiapp_subdev, sd)
235 #define to_smiapp_sensor(_sd) \
236 (to_smiapp_subdev(_sd)->sensor)
238 #endif /* __SMIAPP_PRIV_H_ */