1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef __SMIAPP_PRIV_H_
20#define __SMIAPP_PRIV_H_
21
22#include <linux/mutex.h>
23#include <media/v4l2-ctrls.h>
24#include <media/v4l2-subdev.h>
25#include <media/i2c/smiapp.h>
26
27#include "smiapp-pll.h"
28#include "smiapp-reg.h"
29#include "smiapp-regs.h"
30#include "smiapp-quirk.h"
31
32
33
34
35#define SMIA_VERSION_1 10
36#define SMIAPP_VERSION_0_8 8
37#define SMIAPP_VERSION_0_9 9
38#define SMIAPP_VERSION_1 10
39
40#define SMIAPP_PROFILE_0 0
41#define SMIAPP_PROFILE_1 1
42#define SMIAPP_PROFILE_2 2
43
44#define SMIAPP_NVM_PAGE_SIZE 64
45
46#define SMIAPP_RESET_DELAY_CLOCKS 2400
47#define SMIAPP_RESET_DELAY(clk) \
48 (1000 + (SMIAPP_RESET_DELAY_CLOCKS * 1000 \
49 + (clk) / 1000 - 1) / ((clk) / 1000))
50
51#define SMIAPP_COLOUR_COMPONENTS 4
52
53#include "smiapp-limits.h"
54
55struct smiapp_quirk;
56
57#define SMIAPP_MODULE_IDENT_FLAG_REV_LE (1 << 0)
58
59struct smiapp_module_ident {
60 u8 manufacturer_id;
61 u16 model_id;
62 u8 revision_number_major;
63
64 u8 flags;
65
66 char *name;
67 const struct smiapp_quirk *quirk;
68};
69
70struct smiapp_module_info {
71 u32 manufacturer_id;
72 u32 model_id;
73 u32 revision_number_major;
74 u32 revision_number_minor;
75
76 u32 module_year;
77 u32 module_month;
78 u32 module_day;
79
80 u32 sensor_manufacturer_id;
81 u32 sensor_model_id;
82 u32 sensor_revision_number;
83 u32 sensor_firmware_version;
84
85 u32 smia_version;
86 u32 smiapp_version;
87
88 u32 smiapp_profile;
89
90 char *name;
91 const struct smiapp_quirk *quirk;
92};
93
94#define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk) \
95 { .manufacturer_id = manufacturer, \
96 .model_id = model, \
97 .revision_number_major = rev, \
98 .flags = fl, \
99 .name = _name, \
100 .quirk = _quirk, }
101
102#define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk) \
103 { .manufacturer_id = manufacturer, \
104 .model_id = model, \
105 .revision_number_major = rev, \
106 .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
107 .name = _name, \
108 .quirk = _quirk, }
109
110#define SMIAPP_IDENT_L(manufacturer, model, rev, _name) \
111 { .manufacturer_id = manufacturer, \
112 .model_id = model, \
113 .revision_number_major = rev, \
114 .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
115 .name = _name, }
116
117#define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk) \
118 { .manufacturer_id = manufacturer, \
119 .model_id = model, \
120 .revision_number_major = rev, \
121 .flags = 0, \
122 .name = _name, \
123 .quirk = _quirk, }
124
125#define SMIAPP_IDENT(manufacturer, model, rev, _name) \
126 { .manufacturer_id = manufacturer, \
127 .model_id = model, \
128 .revision_number_major = rev, \
129 .flags = 0, \
130 .name = _name, }
131
132struct smiapp_reg_limits {
133 u32 addr;
134 char *what;
135};
136
137extern struct smiapp_reg_limits smiapp_reg_limits[];
138
139struct smiapp_csi_data_format {
140 u32 code;
141 u8 width;
142 u8 compressed;
143 u8 pixel_order;
144};
145
146#define SMIAPP_SUBDEVS 3
147
148#define SMIAPP_PA_PAD_SRC 0
149#define SMIAPP_PAD_SINK 0
150#define SMIAPP_PAD_SRC 1
151#define SMIAPP_PADS 2
152
153#define SMIAPP_COMPRESSED_BASE 8
154#define SMIAPP_COMPRESSED_MAX 16
155#define SMIAPP_NR_OF_COMPRESSED (SMIAPP_COMPRESSED_MAX - \
156 SMIAPP_COMPRESSED_BASE + 1)
157
158struct smiapp_binning_subtype {
159 u8 horizontal:4;
160 u8 vertical:4;
161} __packed;
162
163struct smiapp_subdev {
164 struct v4l2_subdev sd;
165 struct media_pad pads[2];
166 struct v4l2_rect sink_fmt;
167 struct v4l2_rect crop[2];
168 struct v4l2_rect compose;
169 unsigned short sink_pad;
170 unsigned short source_pad;
171 int npads;
172 struct smiapp_sensor *sensor;
173 struct v4l2_ctrl_handler ctrl_handler;
174};
175
176
177
178
179struct smiapp_sensor {
180
181
182
183
184
185
186
187 struct mutex mutex;
188
189
190
191
192
193 struct mutex power_mutex;
194 struct smiapp_subdev ssds[SMIAPP_SUBDEVS];
195 u32 ssds_used;
196 struct smiapp_subdev *src;
197 struct smiapp_subdev *binner;
198 struct smiapp_subdev *scaler;
199 struct smiapp_subdev *pixel_array;
200 struct smiapp_hwconfig *hwcfg;
201 struct regulator *vana;
202 struct clk *ext_clk;
203 struct gpio_desc *xshutdown;
204 u32 limits[SMIAPP_LIMIT_LAST];
205 u8 nbinning_subtypes;
206 struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES];
207 u32 mbus_frame_fmts;
208 const struct smiapp_csi_data_format *csi_format;
209 const struct smiapp_csi_data_format *internal_csi_format;
210 u32 default_mbus_frame_fmts;
211 int default_pixel_order;
212
213 u8 binning_horizontal;
214 u8 binning_vertical;
215
216 u8 scale_m;
217 u8 scaling_mode;
218
219 u8 hvflip_inv_mask;
220 u8 frame_skip;
221 u16 image_start;
222
223 int power_count;
224
225 bool streaming;
226 bool dev_init_done;
227
228 u8 *nvm;
229 unsigned int nvm_size;
230
231 struct smiapp_module_info minfo;
232
233 struct smiapp_pll pll;
234
235
236 unsigned long valid_link_freqs[SMIAPP_NR_OF_COMPRESSED];
237
238
239 struct v4l2_ctrl *analog_gain;
240 struct v4l2_ctrl *exposure;
241 struct v4l2_ctrl *hflip;
242 struct v4l2_ctrl *vflip;
243 struct v4l2_ctrl *vblank;
244 struct v4l2_ctrl *hblank;
245 struct v4l2_ctrl *pixel_rate_parray;
246
247 struct v4l2_ctrl *link_freq;
248 struct v4l2_ctrl *pixel_rate_csi;
249
250 struct v4l2_ctrl *test_data[SMIAPP_COLOUR_COMPONENTS];
251};
252
253#define to_smiapp_subdev(_sd) \
254 container_of(_sd, struct smiapp_subdev, sd)
255
256#define to_smiapp_sensor(_sd) \
257 (to_smiapp_subdev(_sd)->sensor)
258
259#endif
260