diff options
Diffstat (limited to 'include/media/soc_camera.h')
-rw-r--r-- | include/media/soc_camera.h | 111 |
1 files changed, 91 insertions, 20 deletions
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h index c5de7bb19fda..425b6a98c95c 100644 --- a/include/media/soc_camera.h +++ b/include/media/soc_camera.h | |||
@@ -12,9 +12,10 @@ | |||
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/mutex.h> | ||
16 | #include <linux/pm.h> | ||
15 | #include <linux/videodev2.h> | 17 | #include <linux/videodev2.h> |
16 | #include <media/videobuf-core.h> | 18 | #include <media/videobuf-core.h> |
17 | #include <linux/pm.h> | ||
18 | 19 | ||
19 | struct soc_camera_device { | 20 | struct soc_camera_device { |
20 | struct list_head list; | 21 | struct list_head list; |
@@ -36,14 +37,19 @@ struct soc_camera_device { | |||
36 | unsigned char iface; /* Host number */ | 37 | unsigned char iface; /* Host number */ |
37 | unsigned char devnum; /* Device number per host */ | 38 | unsigned char devnum; /* Device number per host */ |
38 | unsigned char buswidth; /* See comment in .c */ | 39 | unsigned char buswidth; /* See comment in .c */ |
40 | struct soc_camera_sense *sense; /* See comment in struct definition */ | ||
39 | struct soc_camera_ops *ops; | 41 | struct soc_camera_ops *ops; |
40 | struct video_device *vdev; | 42 | struct video_device *vdev; |
41 | const struct soc_camera_data_format *current_fmt; | 43 | const struct soc_camera_data_format *current_fmt; |
42 | const struct soc_camera_data_format *formats; | 44 | const struct soc_camera_data_format *formats; |
43 | int num_formats; | 45 | int num_formats; |
46 | struct soc_camera_format_xlate *user_formats; | ||
47 | int num_user_formats; | ||
44 | struct module *owner; | 48 | struct module *owner; |
45 | /* soc_camera.c private count. Only accessed with video_lock held */ | 49 | void *host_priv; /* Per-device host private data */ |
50 | /* soc_camera.c private count. Only accessed with .video_lock held */ | ||
46 | int use_count; | 51 | int use_count; |
52 | struct mutex video_lock; /* Protects device data */ | ||
47 | }; | 53 | }; |
48 | 54 | ||
49 | struct soc_camera_file { | 55 | struct soc_camera_file { |
@@ -56,7 +62,7 @@ struct soc_camera_host { | |||
56 | struct device dev; | 62 | struct device dev; |
57 | unsigned char nr; /* Host number */ | 63 | unsigned char nr; /* Host number */ |
58 | void *priv; | 64 | void *priv; |
59 | char *drv_name; | 65 | const char *drv_name; |
60 | struct soc_camera_host_ops *ops; | 66 | struct soc_camera_host_ops *ops; |
61 | }; | 67 | }; |
62 | 68 | ||
@@ -64,25 +70,33 @@ struct soc_camera_host_ops { | |||
64 | struct module *owner; | 70 | struct module *owner; |
65 | int (*add)(struct soc_camera_device *); | 71 | int (*add)(struct soc_camera_device *); |
66 | void (*remove)(struct soc_camera_device *); | 72 | void (*remove)(struct soc_camera_device *); |
67 | int (*suspend)(struct soc_camera_device *, pm_message_t state); | 73 | int (*suspend)(struct soc_camera_device *, pm_message_t); |
68 | int (*resume)(struct soc_camera_device *); | 74 | int (*resume)(struct soc_camera_device *); |
69 | int (*set_fmt_cap)(struct soc_camera_device *, __u32, | 75 | int (*get_formats)(struct soc_camera_device *, int, |
70 | struct v4l2_rect *); | 76 | struct soc_camera_format_xlate *); |
71 | int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *); | 77 | int (*set_fmt)(struct soc_camera_device *, __u32, struct v4l2_rect *); |
78 | int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); | ||
72 | void (*init_videobuf)(struct videobuf_queue *, | 79 | void (*init_videobuf)(struct videobuf_queue *, |
73 | struct soc_camera_device *); | 80 | struct soc_camera_device *); |
74 | int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *); | 81 | int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *); |
75 | int (*querycap)(struct soc_camera_host *, struct v4l2_capability *); | 82 | int (*querycap)(struct soc_camera_host *, struct v4l2_capability *); |
76 | int (*try_bus_param)(struct soc_camera_device *, __u32); | ||
77 | int (*set_bus_param)(struct soc_camera_device *, __u32); | 83 | int (*set_bus_param)(struct soc_camera_device *, __u32); |
78 | unsigned int (*poll)(struct file *, poll_table *); | 84 | unsigned int (*poll)(struct file *, poll_table *); |
79 | }; | 85 | }; |
80 | 86 | ||
87 | #define SOCAM_SENSOR_INVERT_PCLK (1 << 0) | ||
88 | #define SOCAM_SENSOR_INVERT_MCLK (1 << 1) | ||
89 | #define SOCAM_SENSOR_INVERT_HSYNC (1 << 2) | ||
90 | #define SOCAM_SENSOR_INVERT_VSYNC (1 << 3) | ||
91 | #define SOCAM_SENSOR_INVERT_DATA (1 << 4) | ||
92 | |||
81 | struct soc_camera_link { | 93 | struct soc_camera_link { |
82 | /* Camera bus id, used to match a camera and a bus */ | 94 | /* Camera bus id, used to match a camera and a bus */ |
83 | int bus_id; | 95 | int bus_id; |
84 | /* GPIO number to switch between 8 and 10 bit modes */ | 96 | /* GPIO number to switch between 8 and 10 bit modes */ |
85 | unsigned int gpio; | 97 | unsigned int gpio; |
98 | /* Per camera SOCAM_SENSOR_* bus flags */ | ||
99 | unsigned long flags; | ||
86 | /* Optional callbacks to power on or off and reset the sensor */ | 100 | /* Optional callbacks to power on or off and reset the sensor */ |
87 | int (*power)(struct device *, int); | 101 | int (*power)(struct device *, int); |
88 | int (*reset)(struct device *); | 102 | int (*reset)(struct device *); |
@@ -106,13 +120,35 @@ extern void soc_camera_device_unregister(struct soc_camera_device *icd); | |||
106 | extern int soc_camera_video_start(struct soc_camera_device *icd); | 120 | extern int soc_camera_video_start(struct soc_camera_device *icd); |
107 | extern void soc_camera_video_stop(struct soc_camera_device *icd); | 121 | extern void soc_camera_video_stop(struct soc_camera_device *icd); |
108 | 122 | ||
123 | extern const struct soc_camera_data_format *soc_camera_format_by_fourcc( | ||
124 | struct soc_camera_device *icd, unsigned int fourcc); | ||
125 | extern const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( | ||
126 | struct soc_camera_device *icd, unsigned int fourcc); | ||
127 | |||
109 | struct soc_camera_data_format { | 128 | struct soc_camera_data_format { |
110 | char *name; | 129 | const char *name; |
111 | unsigned int depth; | 130 | unsigned int depth; |
112 | __u32 fourcc; | 131 | __u32 fourcc; |
113 | enum v4l2_colorspace colorspace; | 132 | enum v4l2_colorspace colorspace; |
114 | }; | 133 | }; |
115 | 134 | ||
135 | /** | ||
136 | * struct soc_camera_format_xlate - match between host and sensor formats | ||
137 | * @cam_fmt: sensor format provided by the sensor | ||
138 | * @host_fmt: host format after host translation from cam_fmt | ||
139 | * @buswidth: bus width for this format | ||
140 | * | ||
141 | * Host and sensor translation structure. Used in table of host and sensor | ||
142 | * formats matchings in soc_camera_device. A host can override the generic list | ||
143 | * generation by implementing get_formats(), and use it for format checks and | ||
144 | * format setup. | ||
145 | */ | ||
146 | struct soc_camera_format_xlate { | ||
147 | const struct soc_camera_data_format *cam_fmt; | ||
148 | const struct soc_camera_data_format *host_fmt; | ||
149 | unsigned char buswidth; | ||
150 | }; | ||
151 | |||
116 | struct soc_camera_ops { | 152 | struct soc_camera_ops { |
117 | struct module *owner; | 153 | struct module *owner; |
118 | int (*probe)(struct soc_camera_device *); | 154 | int (*probe)(struct soc_camera_device *); |
@@ -123,13 +159,14 @@ struct soc_camera_ops { | |||
123 | int (*release)(struct soc_camera_device *); | 159 | int (*release)(struct soc_camera_device *); |
124 | int (*start_capture)(struct soc_camera_device *); | 160 | int (*start_capture)(struct soc_camera_device *); |
125 | int (*stop_capture)(struct soc_camera_device *); | 161 | int (*stop_capture)(struct soc_camera_device *); |
126 | int (*set_fmt_cap)(struct soc_camera_device *, __u32, | 162 | int (*set_fmt)(struct soc_camera_device *, __u32, struct v4l2_rect *); |
127 | struct v4l2_rect *); | 163 | int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); |
128 | int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *); | ||
129 | unsigned long (*query_bus_param)(struct soc_camera_device *); | 164 | unsigned long (*query_bus_param)(struct soc_camera_device *); |
130 | int (*set_bus_param)(struct soc_camera_device *, unsigned long); | 165 | int (*set_bus_param)(struct soc_camera_device *, unsigned long); |
131 | int (*get_chip_id)(struct soc_camera_device *, | 166 | int (*get_chip_id)(struct soc_camera_device *, |
132 | struct v4l2_chip_ident *); | 167 | struct v4l2_chip_ident *); |
168 | int (*set_std)(struct soc_camera_device *, v4l2_std_id *); | ||
169 | int (*enum_input)(struct soc_camera_device *, struct v4l2_input *); | ||
133 | #ifdef CONFIG_VIDEO_ADV_DEBUG | 170 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
134 | int (*get_register)(struct soc_camera_device *, struct v4l2_register *); | 171 | int (*get_register)(struct soc_camera_device *, struct v4l2_register *); |
135 | int (*set_register)(struct soc_camera_device *, struct v4l2_register *); | 172 | int (*set_register)(struct soc_camera_device *, struct v4l2_register *); |
@@ -140,6 +177,32 @@ struct soc_camera_ops { | |||
140 | int num_controls; | 177 | int num_controls; |
141 | }; | 178 | }; |
142 | 179 | ||
180 | #define SOCAM_SENSE_PCLK_CHANGED (1 << 0) | ||
181 | |||
182 | /** | ||
183 | * This struct can be attached to struct soc_camera_device by the host driver | ||
184 | * to request sense from the camera, for example, when calling .set_fmt(). The | ||
185 | * host then can check which flags are set and verify respective values if any. | ||
186 | * For example, if SOCAM_SENSE_PCLK_CHANGED is set, it means, pixclock has | ||
187 | * changed during this operation. After completion the host should detach sense. | ||
188 | * | ||
189 | * @flags ored SOCAM_SENSE_* flags | ||
190 | * @master_clock if the host wants to be informed about pixel-clock | ||
191 | * change, it better set master_clock. | ||
192 | * @pixel_clock_max maximum pixel clock frequency supported by the host, | ||
193 | * camera is not allowed to exceed this. | ||
194 | * @pixel_clock if the camera driver changed pixel clock during this | ||
195 | * operation, it sets SOCAM_SENSE_PCLK_CHANGED, uses | ||
196 | * master_clock to calculate the new pixel-clock and | ||
197 | * sets this field. | ||
198 | */ | ||
199 | struct soc_camera_sense { | ||
200 | unsigned long flags; | ||
201 | unsigned long master_clock; | ||
202 | unsigned long pixel_clock_max; | ||
203 | unsigned long pixel_clock; | ||
204 | }; | ||
205 | |||
143 | static inline struct v4l2_queryctrl const *soc_camera_find_qctrl( | 206 | static inline struct v4l2_queryctrl const *soc_camera_find_qctrl( |
144 | struct soc_camera_ops *ops, int id) | 207 | struct soc_camera_ops *ops, int id) |
145 | { | 208 | { |
@@ -158,15 +221,20 @@ static inline struct v4l2_queryctrl const *soc_camera_find_qctrl( | |||
158 | #define SOCAM_HSYNC_ACTIVE_LOW (1 << 3) | 221 | #define SOCAM_HSYNC_ACTIVE_LOW (1 << 3) |
159 | #define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4) | 222 | #define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4) |
160 | #define SOCAM_VSYNC_ACTIVE_LOW (1 << 5) | 223 | #define SOCAM_VSYNC_ACTIVE_LOW (1 << 5) |
161 | #define SOCAM_DATAWIDTH_8 (1 << 6) | 224 | #define SOCAM_DATAWIDTH_4 (1 << 6) |
162 | #define SOCAM_DATAWIDTH_9 (1 << 7) | 225 | #define SOCAM_DATAWIDTH_8 (1 << 7) |
163 | #define SOCAM_DATAWIDTH_10 (1 << 8) | 226 | #define SOCAM_DATAWIDTH_9 (1 << 8) |
164 | #define SOCAM_DATAWIDTH_16 (1 << 9) | 227 | #define SOCAM_DATAWIDTH_10 (1 << 9) |
165 | #define SOCAM_PCLK_SAMPLE_RISING (1 << 10) | 228 | #define SOCAM_DATAWIDTH_15 (1 << 10) |
166 | #define SOCAM_PCLK_SAMPLE_FALLING (1 << 11) | 229 | #define SOCAM_DATAWIDTH_16 (1 << 11) |
230 | #define SOCAM_PCLK_SAMPLE_RISING (1 << 12) | ||
231 | #define SOCAM_PCLK_SAMPLE_FALLING (1 << 13) | ||
232 | #define SOCAM_DATA_ACTIVE_HIGH (1 << 14) | ||
233 | #define SOCAM_DATA_ACTIVE_LOW (1 << 15) | ||
167 | 234 | ||
168 | #define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_9 | \ | 235 | #define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_4 | SOCAM_DATAWIDTH_8 | \ |
169 | SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_16) | 236 | SOCAM_DATAWIDTH_9 | SOCAM_DATAWIDTH_10 | \ |
237 | SOCAM_DATAWIDTH_15 | SOCAM_DATAWIDTH_16) | ||
170 | 238 | ||
171 | static inline unsigned long soc_camera_bus_param_compatible( | 239 | static inline unsigned long soc_camera_bus_param_compatible( |
172 | unsigned long camera_flags, unsigned long bus_flags) | 240 | unsigned long camera_flags, unsigned long bus_flags) |
@@ -182,4 +250,7 @@ static inline unsigned long soc_camera_bus_param_compatible( | |||
182 | return (!hsync || !vsync || !pclk) ? 0 : common_flags; | 250 | return (!hsync || !vsync || !pclk) ? 0 : common_flags; |
183 | } | 251 | } |
184 | 252 | ||
253 | extern unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, | ||
254 | unsigned long flags); | ||
255 | |||
185 | #endif | 256 | #endif |