diff options
Diffstat (limited to 'include/media/soc_camera.h')
-rw-r--r-- | include/media/soc_camera.h | 104 |
1 files changed, 31 insertions, 73 deletions
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h index 7582952dceae..b1377b931eb7 100644 --- a/include/media/soc_camera.h +++ b/include/media/soc_camera.h | |||
@@ -12,12 +12,14 @@ | |||
12 | #ifndef SOC_CAMERA_H | 12 | #ifndef SOC_CAMERA_H |
13 | #define SOC_CAMERA_H | 13 | #define SOC_CAMERA_H |
14 | 14 | ||
15 | #include <linux/bitops.h> | ||
15 | #include <linux/device.h> | 16 | #include <linux/device.h> |
16 | #include <linux/mutex.h> | 17 | #include <linux/mutex.h> |
17 | #include <linux/pm.h> | 18 | #include <linux/pm.h> |
18 | #include <linux/videodev2.h> | 19 | #include <linux/videodev2.h> |
19 | #include <media/videobuf-core.h> | 20 | #include <media/videobuf-core.h> |
20 | #include <media/videobuf2-core.h> | 21 | #include <media/videobuf2-core.h> |
22 | #include <media/v4l2-ctrls.h> | ||
21 | #include <media/v4l2-device.h> | 23 | #include <media/v4l2-device.h> |
22 | 24 | ||
23 | struct file; | 25 | struct file; |
@@ -37,8 +39,8 @@ struct soc_camera_device { | |||
37 | unsigned char iface; /* Host number */ | 39 | unsigned char iface; /* Host number */ |
38 | unsigned char devnum; /* Device number per host */ | 40 | unsigned char devnum; /* Device number per host */ |
39 | struct soc_camera_sense *sense; /* See comment in struct definition */ | 41 | struct soc_camera_sense *sense; /* See comment in struct definition */ |
40 | struct soc_camera_ops *ops; | ||
41 | struct video_device *vdev; | 42 | struct video_device *vdev; |
43 | struct v4l2_ctrl_handler ctrl_handler; | ||
42 | const struct soc_camera_format_xlate *current_fmt; | 44 | const struct soc_camera_format_xlate *current_fmt; |
43 | struct soc_camera_format_xlate *user_formats; | 45 | struct soc_camera_format_xlate *user_formats; |
44 | int num_user_formats; | 46 | int num_user_formats; |
@@ -93,14 +95,10 @@ struct soc_camera_host_ops { | |||
93 | int (*reqbufs)(struct soc_camera_device *, struct v4l2_requestbuffers *); | 95 | int (*reqbufs)(struct soc_camera_device *, struct v4l2_requestbuffers *); |
94 | int (*querycap)(struct soc_camera_host *, struct v4l2_capability *); | 96 | int (*querycap)(struct soc_camera_host *, struct v4l2_capability *); |
95 | int (*set_bus_param)(struct soc_camera_device *, __u32); | 97 | int (*set_bus_param)(struct soc_camera_device *, __u32); |
96 | int (*get_ctrl)(struct soc_camera_device *, struct v4l2_control *); | ||
97 | int (*set_ctrl)(struct soc_camera_device *, struct v4l2_control *); | ||
98 | int (*get_parm)(struct soc_camera_device *, struct v4l2_streamparm *); | 98 | int (*get_parm)(struct soc_camera_device *, struct v4l2_streamparm *); |
99 | int (*set_parm)(struct soc_camera_device *, struct v4l2_streamparm *); | 99 | int (*set_parm)(struct soc_camera_device *, struct v4l2_streamparm *); |
100 | int (*enum_fsizes)(struct soc_camera_device *, struct v4l2_frmsizeenum *); | 100 | int (*enum_fsizes)(struct soc_camera_device *, struct v4l2_frmsizeenum *); |
101 | unsigned int (*poll)(struct file *, poll_table *); | 101 | unsigned int (*poll)(struct file *, poll_table *); |
102 | const struct v4l2_queryctrl *controls; | ||
103 | int num_controls; | ||
104 | }; | 102 | }; |
105 | 103 | ||
106 | #define SOCAM_SENSOR_INVERT_PCLK (1 << 0) | 104 | #define SOCAM_SENSOR_INVERT_PCLK (1 << 0) |
@@ -193,13 +191,6 @@ struct soc_camera_format_xlate { | |||
193 | const struct soc_mbus_pixelfmt *host_fmt; | 191 | const struct soc_mbus_pixelfmt *host_fmt; |
194 | }; | 192 | }; |
195 | 193 | ||
196 | struct soc_camera_ops { | ||
197 | unsigned long (*query_bus_param)(struct soc_camera_device *); | ||
198 | int (*set_bus_param)(struct soc_camera_device *, unsigned long); | ||
199 | const struct v4l2_queryctrl *controls; | ||
200 | int num_controls; | ||
201 | }; | ||
202 | |||
203 | #define SOCAM_SENSE_PCLK_CHANGED (1 << 0) | 194 | #define SOCAM_SENSE_PCLK_CHANGED (1 << 0) |
204 | 195 | ||
205 | /** | 196 | /** |
@@ -226,65 +217,18 @@ struct soc_camera_sense { | |||
226 | unsigned long pixel_clock; | 217 | unsigned long pixel_clock; |
227 | }; | 218 | }; |
228 | 219 | ||
229 | static inline struct v4l2_queryctrl const *soc_camera_find_qctrl( | 220 | #define SOCAM_DATAWIDTH(x) BIT((x) - 1) |
230 | struct soc_camera_ops *ops, int id) | 221 | #define SOCAM_DATAWIDTH_4 SOCAM_DATAWIDTH(4) |
231 | { | 222 | #define SOCAM_DATAWIDTH_8 SOCAM_DATAWIDTH(8) |
232 | int i; | 223 | #define SOCAM_DATAWIDTH_9 SOCAM_DATAWIDTH(9) |
233 | 224 | #define SOCAM_DATAWIDTH_10 SOCAM_DATAWIDTH(10) | |
234 | for (i = 0; i < ops->num_controls; i++) | 225 | #define SOCAM_DATAWIDTH_15 SOCAM_DATAWIDTH(15) |
235 | if (ops->controls[i].id == id) | 226 | #define SOCAM_DATAWIDTH_16 SOCAM_DATAWIDTH(16) |
236 | return &ops->controls[i]; | ||
237 | |||
238 | return NULL; | ||
239 | } | ||
240 | |||
241 | #define SOCAM_MASTER (1 << 0) | ||
242 | #define SOCAM_SLAVE (1 << 1) | ||
243 | #define SOCAM_HSYNC_ACTIVE_HIGH (1 << 2) | ||
244 | #define SOCAM_HSYNC_ACTIVE_LOW (1 << 3) | ||
245 | #define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4) | ||
246 | #define SOCAM_VSYNC_ACTIVE_LOW (1 << 5) | ||
247 | #define SOCAM_DATAWIDTH_4 (1 << 6) | ||
248 | #define SOCAM_DATAWIDTH_8 (1 << 7) | ||
249 | #define SOCAM_DATAWIDTH_9 (1 << 8) | ||
250 | #define SOCAM_DATAWIDTH_10 (1 << 9) | ||
251 | #define SOCAM_DATAWIDTH_15 (1 << 10) | ||
252 | #define SOCAM_DATAWIDTH_16 (1 << 11) | ||
253 | #define SOCAM_PCLK_SAMPLE_RISING (1 << 12) | ||
254 | #define SOCAM_PCLK_SAMPLE_FALLING (1 << 13) | ||
255 | #define SOCAM_DATA_ACTIVE_HIGH (1 << 14) | ||
256 | #define SOCAM_DATA_ACTIVE_LOW (1 << 15) | ||
257 | #define SOCAM_MIPI_1LANE (1 << 16) | ||
258 | #define SOCAM_MIPI_2LANE (1 << 17) | ||
259 | #define SOCAM_MIPI_3LANE (1 << 18) | ||
260 | #define SOCAM_MIPI_4LANE (1 << 19) | ||
261 | #define SOCAM_MIPI (SOCAM_MIPI_1LANE | SOCAM_MIPI_2LANE | \ | ||
262 | SOCAM_MIPI_3LANE | SOCAM_MIPI_4LANE) | ||
263 | 227 | ||
264 | #define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_4 | SOCAM_DATAWIDTH_8 | \ | 228 | #define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_4 | SOCAM_DATAWIDTH_8 | \ |
265 | SOCAM_DATAWIDTH_9 | SOCAM_DATAWIDTH_10 | \ | 229 | SOCAM_DATAWIDTH_9 | SOCAM_DATAWIDTH_10 | \ |
266 | SOCAM_DATAWIDTH_15 | SOCAM_DATAWIDTH_16) | 230 | SOCAM_DATAWIDTH_15 | SOCAM_DATAWIDTH_16) |
267 | 231 | ||
268 | static inline unsigned long soc_camera_bus_param_compatible( | ||
269 | unsigned long camera_flags, unsigned long bus_flags) | ||
270 | { | ||
271 | unsigned long common_flags, hsync, vsync, pclk, data, buswidth, mode; | ||
272 | unsigned long mipi; | ||
273 | |||
274 | common_flags = camera_flags & bus_flags; | ||
275 | |||
276 | hsync = common_flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW); | ||
277 | vsync = common_flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW); | ||
278 | pclk = common_flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING); | ||
279 | data = common_flags & (SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_LOW); | ||
280 | mode = common_flags & (SOCAM_MASTER | SOCAM_SLAVE); | ||
281 | buswidth = common_flags & SOCAM_DATAWIDTH_MASK; | ||
282 | mipi = common_flags & SOCAM_MIPI; | ||
283 | |||
284 | return ((!hsync || !vsync || !pclk || !data || !mode || !buswidth) && !mipi) ? 0 : | ||
285 | common_flags; | ||
286 | } | ||
287 | |||
288 | static inline void soc_camera_limit_side(int *start, int *length, | 232 | static inline void soc_camera_limit_side(int *start, int *length, |
289 | unsigned int start_min, | 233 | unsigned int start_min, |
290 | unsigned int length_min, unsigned int length_max) | 234 | unsigned int length_min, unsigned int length_max) |
@@ -300,23 +244,37 @@ static inline void soc_camera_limit_side(int *start, int *length, | |||
300 | *start = start_min + length_max - *length; | 244 | *start = start_min + length_max - *length; |
301 | } | 245 | } |
302 | 246 | ||
303 | extern unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, | 247 | unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, |
304 | unsigned long flags); | 248 | unsigned long flags); |
249 | unsigned long soc_camera_apply_board_flags(struct soc_camera_link *icl, | ||
250 | const struct v4l2_mbus_config *cfg); | ||
305 | 251 | ||
306 | /* This is only temporary here - until v4l2-subdev begins to link to video_device */ | 252 | /* This is only temporary here - until v4l2-subdev begins to link to video_device */ |
307 | #include <linux/i2c.h> | 253 | #include <linux/i2c.h> |
308 | static inline struct video_device *soc_camera_i2c_to_vdev(struct i2c_client *client) | 254 | static inline struct video_device *soc_camera_i2c_to_vdev(const struct i2c_client *client) |
255 | { | ||
256 | struct v4l2_subdev *sd = i2c_get_clientdata(client); | ||
257 | struct soc_camera_device *icd = (struct soc_camera_device *)sd->grp_id; | ||
258 | return icd ? icd->vdev : NULL; | ||
259 | } | ||
260 | |||
261 | static inline struct soc_camera_link *soc_camera_i2c_to_link(const struct i2c_client *client) | ||
262 | { | ||
263 | return client->dev.platform_data; | ||
264 | } | ||
265 | |||
266 | static inline struct v4l2_subdev *soc_camera_vdev_to_subdev(const struct video_device *vdev) | ||
309 | { | 267 | { |
310 | struct soc_camera_device *icd = client->dev.platform_data; | 268 | struct soc_camera_device *icd = dev_get_drvdata(vdev->parent); |
311 | return icd->vdev; | 269 | return soc_camera_to_subdev(icd); |
312 | } | 270 | } |
313 | 271 | ||
314 | static inline struct soc_camera_device *soc_camera_from_vb2q(struct vb2_queue *vq) | 272 | static inline struct soc_camera_device *soc_camera_from_vb2q(const struct vb2_queue *vq) |
315 | { | 273 | { |
316 | return container_of(vq, struct soc_camera_device, vb2_vidq); | 274 | return container_of(vq, struct soc_camera_device, vb2_vidq); |
317 | } | 275 | } |
318 | 276 | ||
319 | static inline struct soc_camera_device *soc_camera_from_vbq(struct videobuf_queue *vq) | 277 | static inline struct soc_camera_device *soc_camera_from_vbq(const struct videobuf_queue *vq) |
320 | { | 278 | { |
321 | return container_of(vq, struct soc_camera_device, vb_vidq); | 279 | return container_of(vq, struct soc_camera_device, vb_vidq); |
322 | } | 280 | } |