Commit | Line | Data |
---|---|---|
e55222ef GL |
1 | /* |
2 | * camera image capture (abstract) bus driver header | |
3 | * | |
4 | * Copyright (C) 2006, Sascha Hauer, Pengutronix | |
5 | * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de> | |
6 | * | |
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. | |
10 | */ | |
11 | ||
12 | #ifndef SOC_CAMERA_H | |
13 | #define SOC_CAMERA_H | |
14 | ||
15 | #include <linux/videodev2.h> | |
092d3921 | 16 | #include <media/videobuf-core.h> |
2e521061 | 17 | #include <linux/pm.h> |
e55222ef GL |
18 | |
19 | struct soc_camera_device { | |
20 | struct list_head list; | |
21 | struct device dev; | |
22 | struct device *control; | |
23 | unsigned short width; /* Current window */ | |
24 | unsigned short height; /* sizes */ | |
25 | unsigned short x_min; /* Camera capabilities */ | |
26 | unsigned short y_min; | |
27 | unsigned short x_current; /* Current window location */ | |
28 | unsigned short y_current; | |
29 | unsigned short width_min; | |
30 | unsigned short width_max; | |
31 | unsigned short height_min; | |
32 | unsigned short height_max; | |
33 | unsigned short y_skip_top; /* Lines to skip at the top */ | |
34 | unsigned short gain; | |
35 | unsigned short exposure; | |
36 | unsigned char iface; /* Host number */ | |
37 | unsigned char devnum; /* Device number per host */ | |
ad5f2e85 | 38 | unsigned char buswidth; /* See comment in .c */ |
a9bef518 | 39 | struct soc_camera_sense *sense; /* See comment in struct definition */ |
e55222ef GL |
40 | struct soc_camera_ops *ops; |
41 | struct video_device *vdev; | |
42 | const struct soc_camera_data_format *current_fmt; | |
26f1b942 GL |
43 | const struct soc_camera_data_format *formats; |
44 | int num_formats; | |
c2786ad2 GL |
45 | struct soc_camera_format_xlate *user_formats; |
46 | int num_user_formats; | |
e55222ef | 47 | struct module *owner; |
d2e3dce0 | 48 | void *host_priv; /* per-device host private data */ |
9dc4e48f GL |
49 | /* soc_camera.c private count. Only accessed with video_lock held */ |
50 | int use_count; | |
e55222ef GL |
51 | }; |
52 | ||
53 | struct soc_camera_file { | |
54 | struct soc_camera_device *icd; | |
55 | struct videobuf_queue vb_vidq; | |
56 | }; | |
57 | ||
58 | struct soc_camera_host { | |
59 | struct list_head list; | |
60 | struct device dev; | |
61 | unsigned char nr; /* Host number */ | |
e55222ef | 62 | void *priv; |
af128a10 | 63 | const char *drv_name; |
b8d9904c GL |
64 | struct soc_camera_host_ops *ops; |
65 | }; | |
66 | ||
67 | struct soc_camera_host_ops { | |
68 | struct module *owner; | |
e55222ef GL |
69 | int (*add)(struct soc_camera_device *); |
70 | void (*remove)(struct soc_camera_device *); | |
c2786ad2 | 71 | int (*suspend)(struct soc_camera_device *, pm_message_t); |
2e521061 | 72 | int (*resume)(struct soc_camera_device *); |
c2786ad2 GL |
73 | int (*get_formats)(struct soc_camera_device *, int, |
74 | struct soc_camera_format_xlate *); | |
d8fac217 GL |
75 | int (*set_fmt)(struct soc_camera_device *, __u32, struct v4l2_rect *); |
76 | int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); | |
a034d1b7 | 77 | void (*init_videobuf)(struct videobuf_queue *, |
092d3921 | 78 | struct soc_camera_device *); |
e55222ef GL |
79 | int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *); |
80 | int (*querycap)(struct soc_camera_host *, struct v4l2_capability *); | |
ad5f2e85 | 81 | int (*set_bus_param)(struct soc_camera_device *, __u32); |
e55222ef GL |
82 | unsigned int (*poll)(struct file *, poll_table *); |
83 | }; | |
84 | ||
bd73b36f GL |
85 | #define SOCAM_SENSOR_INVERT_PCLK (1 << 0) |
86 | #define SOCAM_SENSOR_INVERT_MCLK (1 << 1) | |
87 | #define SOCAM_SENSOR_INVERT_HSYNC (1 << 2) | |
88 | #define SOCAM_SENSOR_INVERT_VSYNC (1 << 3) | |
89 | #define SOCAM_SENSOR_INVERT_DATA (1 << 4) | |
90 | ||
e55222ef GL |
91 | struct soc_camera_link { |
92 | /* Camera bus id, used to match a camera and a bus */ | |
93 | int bus_id; | |
94 | /* GPIO number to switch between 8 and 10 bit modes */ | |
95 | unsigned int gpio; | |
bd73b36f GL |
96 | /* Per camera SOCAM_SENSOR_* bus flags */ |
97 | unsigned long flags; | |
81034663 SH |
98 | /* Optional callbacks to power on or off and reset the sensor */ |
99 | int (*power)(struct device *, int); | |
100 | int (*reset)(struct device *); | |
e55222ef GL |
101 | }; |
102 | ||
103 | static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev) | |
104 | { | |
105 | return container_of(dev, struct soc_camera_device, dev); | |
106 | } | |
107 | ||
108 | static inline struct soc_camera_host *to_soc_camera_host(struct device *dev) | |
109 | { | |
110 | return container_of(dev, struct soc_camera_host, dev); | |
111 | } | |
112 | ||
b8d9904c | 113 | extern int soc_camera_host_register(struct soc_camera_host *ici); |
e55222ef GL |
114 | extern void soc_camera_host_unregister(struct soc_camera_host *ici); |
115 | extern int soc_camera_device_register(struct soc_camera_device *icd); | |
116 | extern void soc_camera_device_unregister(struct soc_camera_device *icd); | |
117 | ||
118 | extern int soc_camera_video_start(struct soc_camera_device *icd); | |
119 | extern void soc_camera_video_stop(struct soc_camera_device *icd); | |
120 | ||
25c4d74e GL |
121 | extern const struct soc_camera_data_format *soc_camera_format_by_fourcc( |
122 | struct soc_camera_device *icd, unsigned int fourcc); | |
c2786ad2 GL |
123 | extern const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( |
124 | struct soc_camera_device *icd, unsigned int fourcc); | |
25c4d74e | 125 | |
e55222ef | 126 | struct soc_camera_data_format { |
af128a10 | 127 | const char *name; |
e55222ef GL |
128 | unsigned int depth; |
129 | __u32 fourcc; | |
130 | enum v4l2_colorspace colorspace; | |
131 | }; | |
132 | ||
c2786ad2 GL |
133 | /** |
134 | * struct soc_camera_format_xlate - match between host and sensor formats | |
135 | * @cam_fmt: sensor format provided by the sensor | |
136 | * @host_fmt: host format after host translation from cam_fmt | |
137 | * @buswidth: bus width for this format | |
138 | * | |
139 | * Host and sensor translation structure. Used in table of host and sensor | |
140 | * formats matchings in soc_camera_device. A host can override the generic list | |
141 | * generation by implementing get_formats(), and use it for format checks and | |
142 | * format setup. | |
143 | */ | |
144 | struct soc_camera_format_xlate { | |
145 | const struct soc_camera_data_format *cam_fmt; | |
146 | const struct soc_camera_data_format *host_fmt; | |
147 | unsigned char buswidth; | |
148 | }; | |
149 | ||
e55222ef GL |
150 | struct soc_camera_ops { |
151 | struct module *owner; | |
26f1b942 GL |
152 | int (*probe)(struct soc_camera_device *); |
153 | void (*remove)(struct soc_camera_device *); | |
2e521061 RJ |
154 | int (*suspend)(struct soc_camera_device *, pm_message_t state); |
155 | int (*resume)(struct soc_camera_device *); | |
e55222ef GL |
156 | int (*init)(struct soc_camera_device *); |
157 | int (*release)(struct soc_camera_device *); | |
158 | int (*start_capture)(struct soc_camera_device *); | |
159 | int (*stop_capture)(struct soc_camera_device *); | |
d8fac217 GL |
160 | int (*set_fmt)(struct soc_camera_device *, __u32, struct v4l2_rect *); |
161 | int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); | |
ad5f2e85 GL |
162 | unsigned long (*query_bus_param)(struct soc_camera_device *); |
163 | int (*set_bus_param)(struct soc_camera_device *, unsigned long); | |
e55222ef GL |
164 | int (*get_chip_id)(struct soc_camera_device *, |
165 | struct v4l2_chip_ident *); | |
166 | #ifdef CONFIG_VIDEO_ADV_DEBUG | |
167 | int (*get_register)(struct soc_camera_device *, struct v4l2_register *); | |
168 | int (*set_register)(struct soc_camera_device *, struct v4l2_register *); | |
169 | #endif | |
e55222ef GL |
170 | int (*get_control)(struct soc_camera_device *, struct v4l2_control *); |
171 | int (*set_control)(struct soc_camera_device *, struct v4l2_control *); | |
172 | const struct v4l2_queryctrl *controls; | |
173 | int num_controls; | |
e55222ef GL |
174 | }; |
175 | ||
a9bef518 GL |
176 | #define SOCAM_SENSE_PCLK_CHANGED (1 << 0) |
177 | ||
178 | /** | |
179 | * This struct can be attached to struct soc_camera_device by the host driver | |
180 | * to request sense from the camera, for example, when calling .set_fmt(). The | |
181 | * host then can check which flags are set and verify respective values if any. | |
182 | * For example, if SOCAM_SENSE_PCLK_CHANGED is set, it means, pixclock has | |
183 | * changed during this operation. After completion the host should detach sense. | |
184 | * | |
185 | * @flags ored SOCAM_SENSE_* flags | |
186 | * @master_clock if the host wants to be informed about pixel-clock | |
187 | * change, it better set master_clock. | |
188 | * @pixel_clock_max maximum pixel clock frequency supported by the host, | |
189 | * camera is not allowed to exceed this. | |
190 | * @pixel_clock if the camera driver changed pixel clock during this | |
191 | * operation, it sets SOCAM_SENSE_PCLK_CHANGED, uses | |
192 | * master_clock to calculate the new pixel-clock and | |
193 | * sets this field. | |
194 | */ | |
195 | struct soc_camera_sense { | |
196 | unsigned long flags; | |
197 | unsigned long master_clock; | |
198 | unsigned long pixel_clock_max; | |
199 | unsigned long pixel_clock; | |
200 | }; | |
201 | ||
e55222ef GL |
202 | static inline struct v4l2_queryctrl const *soc_camera_find_qctrl( |
203 | struct soc_camera_ops *ops, int id) | |
204 | { | |
205 | int i; | |
206 | ||
207 | for (i = 0; i < ops->num_controls; i++) | |
208 | if (ops->controls[i].id == id) | |
209 | return &ops->controls[i]; | |
210 | ||
211 | return NULL; | |
212 | } | |
213 | ||
ad5f2e85 GL |
214 | #define SOCAM_MASTER (1 << 0) |
215 | #define SOCAM_SLAVE (1 << 1) | |
216 | #define SOCAM_HSYNC_ACTIVE_HIGH (1 << 2) | |
217 | #define SOCAM_HSYNC_ACTIVE_LOW (1 << 3) | |
218 | #define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4) | |
219 | #define SOCAM_VSYNC_ACTIVE_LOW (1 << 5) | |
220 | #define SOCAM_DATAWIDTH_8 (1 << 6) | |
221 | #define SOCAM_DATAWIDTH_9 (1 << 7) | |
222 | #define SOCAM_DATAWIDTH_10 (1 << 8) | |
b15cf1fc MD |
223 | #define SOCAM_DATAWIDTH_16 (1 << 9) |
224 | #define SOCAM_PCLK_SAMPLE_RISING (1 << 10) | |
225 | #define SOCAM_PCLK_SAMPLE_FALLING (1 << 11) | |
ad5f2e85 GL |
226 | |
227 | #define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_9 | \ | |
b15cf1fc | 228 | SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_16) |
ad5f2e85 GL |
229 | |
230 | static inline unsigned long soc_camera_bus_param_compatible( | |
231 | unsigned long camera_flags, unsigned long bus_flags) | |
232 | { | |
233 | unsigned long common_flags, hsync, vsync, pclk; | |
234 | ||
235 | common_flags = camera_flags & bus_flags; | |
236 | ||
237 | hsync = common_flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW); | |
238 | vsync = common_flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW); | |
239 | pclk = common_flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING); | |
240 | ||
241 | return (!hsync || !vsync || !pclk) ? 0 : common_flags; | |
242 | } | |
e55222ef | 243 | |
bd73b36f GL |
244 | extern unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, |
245 | unsigned long flags); | |
246 | ||
e55222ef | 247 | #endif |