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