2 * camera image capture (abstract) bus driver header
4 * Copyright (C) 2006, Sascha Hauer, Pengutronix
5 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
15 #include <linux/videodev2.h>
16 #include <media/videobuf-dma-sg.h>
18 struct soc_camera_device {
19 struct list_head list;
21 struct device *control;
22 unsigned short width; /* Current window */
23 unsigned short height; /* sizes */
24 unsigned short x_min; /* Camera capabilities */
26 unsigned short x_current; /* Current window location */
27 unsigned short y_current;
28 unsigned short width_min;
29 unsigned short width_max;
30 unsigned short height_min;
31 unsigned short height_max;
32 unsigned short y_skip_top; /* Lines to skip at the top */
34 unsigned short exposure;
35 unsigned char iface; /* Host number */
36 unsigned char devnum; /* Device number per host */
37 unsigned char cached_datawidth; /* See comment in .c */
38 struct soc_camera_ops *ops;
39 struct video_device *vdev;
40 const struct soc_camera_data_format *current_fmt;
41 int (*probe)(struct soc_camera_device *icd);
42 void (*remove)(struct soc_camera_device *icd);
44 /* soc_camera.c private count. Only accessed with video_lock held */
48 struct soc_camera_file {
49 struct soc_camera_device *icd;
50 struct videobuf_queue vb_vidq;
53 struct soc_camera_host {
54 struct list_head list;
56 unsigned char nr; /* Host number */
58 struct videobuf_queue_ops *vbq_ops;
62 int (*add)(struct soc_camera_device *);
63 void (*remove)(struct soc_camera_device *);
64 int (*set_capture_format)(struct soc_camera_device *, __u32,
66 int (*try_fmt_cap)(struct soc_camera_host *, struct v4l2_format *);
67 int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *);
68 int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
69 unsigned int (*poll)(struct file *, poll_table *);
72 struct soc_camera_link {
73 /* Camera bus id, used to match a camera and a bus */
75 /* GPIO number to switch between 8 and 10 bit modes */
79 static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev)
81 return container_of(dev, struct soc_camera_device, dev);
84 static inline struct soc_camera_host *to_soc_camera_host(struct device *dev)
86 return container_of(dev, struct soc_camera_host, dev);
89 extern int soc_camera_host_register(struct soc_camera_host *ici,
90 struct module *owner);
91 extern void soc_camera_host_unregister(struct soc_camera_host *ici);
92 extern int soc_camera_device_register(struct soc_camera_device *icd);
93 extern void soc_camera_device_unregister(struct soc_camera_device *icd);
95 extern int soc_camera_video_start(struct soc_camera_device *icd);
96 extern void soc_camera_video_stop(struct soc_camera_device *icd);
98 struct soc_camera_data_format {
102 enum v4l2_colorspace colorspace;
105 struct soc_camera_ops {
106 struct module *owner;
107 int (*init)(struct soc_camera_device *);
108 int (*release)(struct soc_camera_device *);
109 int (*start_capture)(struct soc_camera_device *);
110 int (*stop_capture)(struct soc_camera_device *);
111 int (*set_capture_format)(struct soc_camera_device *, __u32,
112 struct v4l2_rect *, unsigned int);
113 int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
114 int (*get_chip_id)(struct soc_camera_device *,
115 struct v4l2_chip_ident *);
116 #ifdef CONFIG_VIDEO_ADV_DEBUG
117 int (*get_register)(struct soc_camera_device *, struct v4l2_register *);
118 int (*set_register)(struct soc_camera_device *, struct v4l2_register *);
120 const struct soc_camera_data_format *formats;
122 int (*get_control)(struct soc_camera_device *, struct v4l2_control *);
123 int (*set_control)(struct soc_camera_device *, struct v4l2_control *);
124 const struct v4l2_queryctrl *controls;
126 unsigned int(*get_datawidth)(struct soc_camera_device *icd);
129 static inline struct v4l2_queryctrl const *soc_camera_find_qctrl(
130 struct soc_camera_ops *ops, int id)
134 for (i = 0; i < ops->num_controls; i++)
135 if (ops->controls[i].id == id)
136 return &ops->controls[i];
141 #define IS_MASTER (1<<0)
142 #define IS_HSYNC_ACTIVE_HIGH (1<<1)
143 #define IS_VSYNC_ACTIVE_HIGH (1<<2)
144 #define IS_DATAWIDTH_8 (1<<3)
145 #define IS_DATAWIDTH_9 (1<<4)
146 #define IS_DATAWIDTH_10 (1<<5)
147 #define IS_PCLK_SAMPLE_RISING (1<<6)