This source file includes following definitions.
- to_soc_camera_host
- to_soc_camera_desc
- to_soc_camera_control
- soc_camera_to_subdev
- soc_camera_limit_side
- soc_camera_set_power
- soc_camera_i2c_to_vdev
- soc_camera_i2c_to_desc
- soc_camera_vdev_to_subdev
- soc_camera_from_vb2q
- soc_camera_grp_id
1
2
3
4
5
6
7
8
9 #ifndef SOC_CAMERA_H
10 #define SOC_CAMERA_H
11
12 #include <linux/bitops.h>
13 #include <linux/device.h>
14 #include <linux/mutex.h>
15 #include <linux/pm.h>
16 #include <linux/videodev2.h>
17 #include <media/videobuf2-v4l2.h>
18 #include <media/v4l2-async.h>
19 #include <media/v4l2-ctrls.h>
20 #include <media/v4l2-device.h>
21
22 struct file;
23 struct soc_camera_desc;
24 struct soc_camera_async_client;
25
26 struct soc_camera_device {
27 struct list_head list;
28 struct soc_camera_desc *sdesc;
29 struct device *pdev;
30 struct device *parent;
31 struct device *control;
32 s32 user_width;
33 s32 user_height;
34 u32 bytesperline;
35 u32 sizeimage;
36 enum v4l2_colorspace colorspace;
37 unsigned char iface;
38 unsigned char devnum;
39 struct soc_camera_sense *sense;
40 struct video_device *vdev;
41 struct v4l2_ctrl_handler ctrl_handler;
42 const struct soc_camera_format_xlate *current_fmt;
43 struct soc_camera_format_xlate *user_formats;
44 int num_user_formats;
45 enum v4l2_field field;
46 void *host_priv;
47
48 int use_count;
49 struct file *streamer;
50 struct v4l2_clk *clk;
51
52 struct soc_camera_async_client *sasc;
53
54 struct vb2_queue vb2_vidq;
55 };
56
57
58 #define SOCAM_HOST_CAP_STRIDE (1 << 0)
59
60 enum soc_camera_subdev_role {
61 SOCAM_SUBDEV_DATA_SOURCE = 1,
62 SOCAM_SUBDEV_DATA_SINK,
63 SOCAM_SUBDEV_DATA_PROCESSOR,
64 };
65
66 struct soc_camera_async_subdev {
67 struct v4l2_async_subdev asd;
68 enum soc_camera_subdev_role role;
69 };
70
71 struct soc_camera_host {
72 struct v4l2_device v4l2_dev;
73 struct list_head list;
74 struct mutex host_lock;
75 struct mutex clk_lock;
76 unsigned char nr;
77 u32 capabilities;
78 struct soc_camera_device *icd;
79 void *priv;
80 const char *drv_name;
81 struct soc_camera_host_ops *ops;
82 struct v4l2_async_subdev **asd;
83 unsigned int *asd_sizes;
84 };
85
86 struct soc_camera_host_ops {
87 struct module *owner;
88 int (*add)(struct soc_camera_device *);
89 void (*remove)(struct soc_camera_device *);
90 int (*clock_start)(struct soc_camera_host *);
91 void (*clock_stop)(struct soc_camera_host *);
92
93
94
95
96
97
98 int (*get_formats)(struct soc_camera_device *, unsigned int,
99 struct soc_camera_format_xlate *);
100 void (*put_formats)(struct soc_camera_device *);
101 int (*get_selection)(struct soc_camera_device *, struct v4l2_selection *);
102 int (*set_selection)(struct soc_camera_device *, struct v4l2_selection *);
103
104
105
106
107 int (*set_liveselection)(struct soc_camera_device *, struct v4l2_selection *);
108 int (*set_fmt)(struct soc_camera_device *, struct v4l2_format *);
109 int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *);
110 int (*init_videobuf2)(struct vb2_queue *,
111 struct soc_camera_device *);
112 int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
113 int (*set_bus_param)(struct soc_camera_device *);
114 int (*get_parm)(struct soc_camera_device *, struct v4l2_streamparm *);
115 int (*set_parm)(struct soc_camera_device *, struct v4l2_streamparm *);
116 int (*enum_framesizes)(struct soc_camera_device *, struct v4l2_frmsizeenum *);
117 __poll_t (*poll)(struct file *, poll_table *);
118 };
119
120 #define SOCAM_SENSOR_INVERT_PCLK (1 << 0)
121 #define SOCAM_SENSOR_INVERT_MCLK (1 << 1)
122 #define SOCAM_SENSOR_INVERT_HSYNC (1 << 2)
123 #define SOCAM_SENSOR_INVERT_VSYNC (1 << 3)
124 #define SOCAM_SENSOR_INVERT_DATA (1 << 4)
125
126 struct i2c_board_info;
127 struct regulator_bulk_data;
128
129 struct soc_camera_subdev_desc {
130
131 unsigned long flags;
132
133
134 void *drv_priv;
135
136
137
138
139
140
141
142 bool unbalanced_power;
143 unsigned long clock_state;
144
145
146 int (*power)(struct device *, int);
147 int (*reset)(struct device *);
148
149
150
151
152
153
154 int (*set_bus_param)(struct soc_camera_subdev_desc *, unsigned long flags);
155 unsigned long (*query_bus_param)(struct soc_camera_subdev_desc *);
156 void (*free_bus)(struct soc_camera_subdev_desc *);
157
158
159 struct v4l2_subdev_platform_data sd_pdata;
160 };
161
162 struct soc_camera_host_desc {
163
164 int bus_id;
165 int i2c_adapter_id;
166 struct i2c_board_info *board_info;
167 const char *module_name;
168
169
170
171
172
173 int (*add_device)(struct soc_camera_device *);
174 void (*del_device)(struct soc_camera_device *);
175 };
176
177
178
179
180
181
182
183 struct soc_camera_desc {
184 struct soc_camera_subdev_desc subdev_desc;
185 struct soc_camera_host_desc host_desc;
186 };
187
188
189 struct soc_camera_link {
190
191
192
193
194
195
196 unsigned long flags;
197
198 void *priv;
199
200
201 bool unbalanced_power;
202
203 unsigned long clock_state;
204
205
206 int (*power)(struct device *, int);
207 int (*reset)(struct device *);
208
209
210
211
212
213 int (*set_bus_param)(struct soc_camera_link *, unsigned long flags);
214 unsigned long (*query_bus_param)(struct soc_camera_link *);
215 void (*free_bus)(struct soc_camera_link *);
216
217
218 struct regulator_bulk_data *regulators;
219 int num_regulators;
220
221 void *host_priv;
222
223
224
225
226
227
228
229 int bus_id;
230 int i2c_adapter_id;
231 struct i2c_board_info *board_info;
232 const char *module_name;
233
234
235
236
237
238 int (*add_device)(struct soc_camera_device *);
239 void (*del_device)(struct soc_camera_device *);
240 };
241
242 static inline struct soc_camera_host *to_soc_camera_host(
243 const struct device *dev)
244 {
245 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
246
247 return container_of(v4l2_dev, struct soc_camera_host, v4l2_dev);
248 }
249
250 static inline struct soc_camera_desc *to_soc_camera_desc(
251 const struct soc_camera_device *icd)
252 {
253 return icd->sdesc;
254 }
255
256 static inline struct device *to_soc_camera_control(
257 const struct soc_camera_device *icd)
258 {
259 return icd->control;
260 }
261
262 static inline struct v4l2_subdev *soc_camera_to_subdev(
263 const struct soc_camera_device *icd)
264 {
265 struct device *control = to_soc_camera_control(icd);
266 return dev_get_drvdata(control);
267 }
268
269 int soc_camera_host_register(struct soc_camera_host *ici);
270 void soc_camera_host_unregister(struct soc_camera_host *ici);
271
272 const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
273 struct soc_camera_device *icd, unsigned int fourcc);
274
275
276
277
278
279
280
281
282
283
284
285 struct soc_camera_format_xlate {
286 u32 code;
287 const struct soc_mbus_pixelfmt *host_fmt;
288 };
289
290 #define SOCAM_SENSE_PCLK_CHANGED (1 << 0)
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309 struct soc_camera_sense {
310 unsigned long flags;
311 unsigned long master_clock;
312 unsigned long pixel_clock_max;
313 unsigned long pixel_clock;
314 };
315
316 #define SOCAM_DATAWIDTH(x) BIT((x) - 1)
317 #define SOCAM_DATAWIDTH_4 SOCAM_DATAWIDTH(4)
318 #define SOCAM_DATAWIDTH_8 SOCAM_DATAWIDTH(8)
319 #define SOCAM_DATAWIDTH_9 SOCAM_DATAWIDTH(9)
320 #define SOCAM_DATAWIDTH_10 SOCAM_DATAWIDTH(10)
321 #define SOCAM_DATAWIDTH_12 SOCAM_DATAWIDTH(12)
322 #define SOCAM_DATAWIDTH_15 SOCAM_DATAWIDTH(15)
323 #define SOCAM_DATAWIDTH_16 SOCAM_DATAWIDTH(16)
324 #define SOCAM_DATAWIDTH_18 SOCAM_DATAWIDTH(18)
325 #define SOCAM_DATAWIDTH_24 SOCAM_DATAWIDTH(24)
326
327 #define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_4 | SOCAM_DATAWIDTH_8 | \
328 SOCAM_DATAWIDTH_9 | SOCAM_DATAWIDTH_10 | \
329 SOCAM_DATAWIDTH_12 | SOCAM_DATAWIDTH_15 | \
330 SOCAM_DATAWIDTH_16 | SOCAM_DATAWIDTH_18 | \
331 SOCAM_DATAWIDTH_24)
332
333 static inline void soc_camera_limit_side(int *start, int *length,
334 unsigned int start_min,
335 unsigned int length_min, unsigned int length_max)
336 {
337 if (*length < length_min)
338 *length = length_min;
339 else if (*length > length_max)
340 *length = length_max;
341
342 if (*start < start_min)
343 *start = start_min;
344 else if (*start > start_min + length_max - *length)
345 *start = start_min + length_max - *length;
346 }
347
348 unsigned long soc_camera_apply_board_flags(struct soc_camera_subdev_desc *ssdd,
349 const struct v4l2_mbus_config *cfg);
350
351 int soc_camera_power_init(struct device *dev, struct soc_camera_subdev_desc *ssdd);
352 int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd,
353 struct v4l2_clk *clk);
354 int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd,
355 struct v4l2_clk *clk);
356
357 static inline int soc_camera_set_power(struct device *dev,
358 struct soc_camera_subdev_desc *ssdd, struct v4l2_clk *clk, bool on)
359 {
360 return on ? soc_camera_power_on(dev, ssdd, clk)
361 : soc_camera_power_off(dev, ssdd, clk);
362 }
363
364
365 #include <linux/i2c.h>
366 static inline struct video_device *soc_camera_i2c_to_vdev(const struct i2c_client *client)
367 {
368 struct v4l2_subdev *sd = i2c_get_clientdata(client);
369 struct soc_camera_device *icd = v4l2_get_subdev_hostdata(sd);
370 return icd ? icd->vdev : NULL;
371 }
372
373 static inline struct soc_camera_subdev_desc *soc_camera_i2c_to_desc(const struct i2c_client *client)
374 {
375 return client->dev.platform_data;
376 }
377
378 static inline struct v4l2_subdev *soc_camera_vdev_to_subdev(struct video_device *vdev)
379 {
380 struct soc_camera_device *icd = video_get_drvdata(vdev);
381 return soc_camera_to_subdev(icd);
382 }
383
384 static inline struct soc_camera_device *soc_camera_from_vb2q(const struct vb2_queue *vq)
385 {
386 return container_of(vq, struct soc_camera_device, vb2_vidq);
387 }
388
389 static inline u32 soc_camera_grp_id(const struct soc_camera_device *icd)
390 {
391 return (icd->iface << 8) | (icd->devnum + 1);
392 }
393
394 void soc_camera_lock(struct vb2_queue *vq);
395 void soc_camera_unlock(struct vb2_queue *vq);
396
397 #endif