diff options
Diffstat (limited to 'include/media/soc_camera.h')
-rw-r--r-- | include/media/soc_camera.h | 113 |
1 files changed, 69 insertions, 44 deletions
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h index 23ecead35e7..3d74e60032d 100644 --- a/include/media/soc_camera.h +++ b/include/media/soc_camera.h | |||
@@ -16,24 +16,17 @@ | |||
16 | #include <linux/pm.h> | 16 | #include <linux/pm.h> |
17 | #include <linux/videodev2.h> | 17 | #include <linux/videodev2.h> |
18 | #include <media/videobuf-core.h> | 18 | #include <media/videobuf-core.h> |
19 | #include <media/v4l2-device.h> | ||
19 | 20 | ||
20 | struct soc_camera_device { | 21 | struct soc_camera_device { |
21 | struct list_head list; | 22 | struct list_head list; |
22 | struct device dev; | 23 | struct device dev; |
23 | struct device *control; | 24 | struct device *pdev; /* Platform device */ |
24 | unsigned short width; /* Current window */ | 25 | s32 user_width; |
25 | unsigned short height; /* sizes */ | 26 | s32 user_height; |
26 | unsigned short x_min; /* Camera capabilities */ | ||
27 | unsigned short y_min; | ||
28 | unsigned short x_current; /* Current window location */ | ||
29 | unsigned short y_current; | ||
30 | unsigned short width_min; | 27 | unsigned short width_min; |
31 | unsigned short width_max; | ||
32 | unsigned short height_min; | 28 | unsigned short height_min; |
33 | unsigned short height_max; | ||
34 | unsigned short y_skip_top; /* Lines to skip at the top */ | 29 | unsigned short y_skip_top; /* Lines to skip at the top */ |
35 | unsigned short gain; | ||
36 | unsigned short exposure; | ||
37 | unsigned char iface; /* Host number */ | 30 | unsigned char iface; /* Host number */ |
38 | unsigned char devnum; /* Device number per host */ | 31 | unsigned char devnum; /* Device number per host */ |
39 | unsigned char buswidth; /* See comment in .c */ | 32 | unsigned char buswidth; /* See comment in .c */ |
@@ -46,7 +39,6 @@ struct soc_camera_device { | |||
46 | struct soc_camera_format_xlate *user_formats; | 39 | struct soc_camera_format_xlate *user_formats; |
47 | int num_user_formats; | 40 | int num_user_formats; |
48 | enum v4l2_field field; /* Preserve field over close() */ | 41 | enum v4l2_field field; /* Preserve field over close() */ |
49 | struct module *owner; | ||
50 | void *host_priv; /* Per-device host private data */ | 42 | void *host_priv; /* Per-device host private data */ |
51 | /* soc_camera.c private count. Only accessed with .video_lock held */ | 43 | /* soc_camera.c private count. Only accessed with .video_lock held */ |
52 | int use_count; | 44 | int use_count; |
@@ -59,8 +51,8 @@ struct soc_camera_file { | |||
59 | }; | 51 | }; |
60 | 52 | ||
61 | struct soc_camera_host { | 53 | struct soc_camera_host { |
54 | struct v4l2_device v4l2_dev; | ||
62 | struct list_head list; | 55 | struct list_head list; |
63 | struct device *dev; | ||
64 | unsigned char nr; /* Host number */ | 56 | unsigned char nr; /* Host number */ |
65 | void *priv; | 57 | void *priv; |
66 | const char *drv_name; | 58 | const char *drv_name; |
@@ -73,9 +65,18 @@ struct soc_camera_host_ops { | |||
73 | void (*remove)(struct soc_camera_device *); | 65 | void (*remove)(struct soc_camera_device *); |
74 | int (*suspend)(struct soc_camera_device *, pm_message_t); | 66 | int (*suspend)(struct soc_camera_device *, pm_message_t); |
75 | int (*resume)(struct soc_camera_device *); | 67 | int (*resume)(struct soc_camera_device *); |
68 | /* | ||
69 | * .get_formats() is called for each client device format, but | ||
70 | * .put_formats() is only called once. Further, if any of the calls to | ||
71 | * .get_formats() fail, .put_formats() will not be called at all, the | ||
72 | * failing .get_formats() must then clean up internally. | ||
73 | */ | ||
76 | int (*get_formats)(struct soc_camera_device *, int, | 74 | int (*get_formats)(struct soc_camera_device *, int, |
77 | struct soc_camera_format_xlate *); | 75 | struct soc_camera_format_xlate *); |
78 | int (*set_crop)(struct soc_camera_device *, struct v4l2_rect *); | 76 | void (*put_formats)(struct soc_camera_device *); |
77 | int (*cropcap)(struct soc_camera_device *, struct v4l2_cropcap *); | ||
78 | int (*get_crop)(struct soc_camera_device *, struct v4l2_crop *); | ||
79 | int (*set_crop)(struct soc_camera_device *, struct v4l2_crop *); | ||
79 | int (*set_fmt)(struct soc_camera_device *, struct v4l2_format *); | 80 | int (*set_fmt)(struct soc_camera_device *, struct v4l2_format *); |
80 | int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); | 81 | int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); |
81 | void (*init_videobuf)(struct videobuf_queue *, | 82 | void (*init_videobuf)(struct videobuf_queue *, |
@@ -83,7 +84,11 @@ struct soc_camera_host_ops { | |||
83 | int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *); | 84 | int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *); |
84 | int (*querycap)(struct soc_camera_host *, struct v4l2_capability *); | 85 | int (*querycap)(struct soc_camera_host *, struct v4l2_capability *); |
85 | int (*set_bus_param)(struct soc_camera_device *, __u32); | 86 | int (*set_bus_param)(struct soc_camera_device *, __u32); |
87 | int (*get_ctrl)(struct soc_camera_device *, struct v4l2_control *); | ||
88 | int (*set_ctrl)(struct soc_camera_device *, struct v4l2_control *); | ||
86 | unsigned int (*poll)(struct file *, poll_table *); | 89 | unsigned int (*poll)(struct file *, poll_table *); |
90 | const struct v4l2_queryctrl *controls; | ||
91 | int num_controls; | ||
87 | }; | 92 | }; |
88 | 93 | ||
89 | #define SOCAM_SENSOR_INVERT_PCLK (1 << 0) | 94 | #define SOCAM_SENSOR_INVERT_PCLK (1 << 0) |
@@ -102,6 +107,12 @@ struct soc_camera_link { | |||
102 | int i2c_adapter_id; | 107 | int i2c_adapter_id; |
103 | struct i2c_board_info *board_info; | 108 | struct i2c_board_info *board_info; |
104 | const char *module_name; | 109 | const char *module_name; |
110 | /* | ||
111 | * For non-I2C devices platform platform has to provide methods to | ||
112 | * add a device to the system and to remove | ||
113 | */ | ||
114 | int (*add_device)(struct soc_camera_link *, struct device *); | ||
115 | void (*del_device)(struct soc_camera_link *); | ||
105 | /* Optional callbacks to power on or off and reset the sensor */ | 116 | /* Optional callbacks to power on or off and reset the sensor */ |
106 | int (*power)(struct device *, int); | 117 | int (*power)(struct device *, int); |
107 | int (*reset)(struct device *); | 118 | int (*reset)(struct device *); |
@@ -115,27 +126,45 @@ struct soc_camera_link { | |||
115 | void (*free_bus)(struct soc_camera_link *); | 126 | void (*free_bus)(struct soc_camera_link *); |
116 | }; | 127 | }; |
117 | 128 | ||
118 | static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev) | 129 | static inline struct soc_camera_device *to_soc_camera_dev( |
130 | const struct device *dev) | ||
119 | { | 131 | { |
120 | return container_of(dev, struct soc_camera_device, dev); | 132 | return container_of(dev, struct soc_camera_device, dev); |
121 | } | 133 | } |
122 | 134 | ||
123 | static inline struct soc_camera_host *to_soc_camera_host(struct device *dev) | 135 | static inline struct soc_camera_host *to_soc_camera_host( |
136 | const struct device *dev) | ||
124 | { | 137 | { |
125 | return dev_get_drvdata(dev); | 138 | struct v4l2_device *v4l2_dev = dev_get_drvdata(dev); |
139 | |||
140 | return container_of(v4l2_dev, struct soc_camera_host, v4l2_dev); | ||
126 | } | 141 | } |
127 | 142 | ||
128 | extern int soc_camera_host_register(struct soc_camera_host *ici); | 143 | static inline struct soc_camera_link *to_soc_camera_link( |
129 | extern void soc_camera_host_unregister(struct soc_camera_host *ici); | 144 | const struct soc_camera_device *icd) |
130 | extern int soc_camera_device_register(struct soc_camera_device *icd); | 145 | { |
131 | extern void soc_camera_device_unregister(struct soc_camera_device *icd); | 146 | return icd->dev.platform_data; |
147 | } | ||
132 | 148 | ||
133 | extern int soc_camera_video_start(struct soc_camera_device *icd); | 149 | static inline struct device *to_soc_camera_control( |
134 | extern void soc_camera_video_stop(struct soc_camera_device *icd); | 150 | const struct soc_camera_device *icd) |
151 | { | ||
152 | return dev_get_drvdata(&icd->dev); | ||
153 | } | ||
135 | 154 | ||
136 | extern const struct soc_camera_data_format *soc_camera_format_by_fourcc( | 155 | static inline struct v4l2_subdev *soc_camera_to_subdev( |
156 | const struct soc_camera_device *icd) | ||
157 | { | ||
158 | struct device *control = to_soc_camera_control(icd); | ||
159 | return dev_get_drvdata(control); | ||
160 | } | ||
161 | |||
162 | int soc_camera_host_register(struct soc_camera_host *ici); | ||
163 | void soc_camera_host_unregister(struct soc_camera_host *ici); | ||
164 | |||
165 | const struct soc_camera_data_format *soc_camera_format_by_fourcc( | ||
137 | struct soc_camera_device *icd, unsigned int fourcc); | 166 | struct soc_camera_device *icd, unsigned int fourcc); |
138 | extern const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( | 167 | const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( |
139 | struct soc_camera_device *icd, unsigned int fourcc); | 168 | struct soc_camera_device *icd, unsigned int fourcc); |
140 | 169 | ||
141 | struct soc_camera_data_format { | 170 | struct soc_camera_data_format { |
@@ -163,30 +192,11 @@ struct soc_camera_format_xlate { | |||
163 | }; | 192 | }; |
164 | 193 | ||
165 | struct soc_camera_ops { | 194 | struct soc_camera_ops { |
166 | struct module *owner; | ||
167 | int (*probe)(struct soc_camera_device *); | ||
168 | void (*remove)(struct soc_camera_device *); | ||
169 | int (*suspend)(struct soc_camera_device *, pm_message_t state); | 195 | int (*suspend)(struct soc_camera_device *, pm_message_t state); |
170 | int (*resume)(struct soc_camera_device *); | 196 | int (*resume)(struct soc_camera_device *); |
171 | int (*init)(struct soc_camera_device *); | ||
172 | int (*release)(struct soc_camera_device *); | ||
173 | int (*start_capture)(struct soc_camera_device *); | ||
174 | int (*stop_capture)(struct soc_camera_device *); | ||
175 | int (*set_crop)(struct soc_camera_device *, struct v4l2_rect *); | ||
176 | int (*set_fmt)(struct soc_camera_device *, struct v4l2_format *); | ||
177 | int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); | ||
178 | unsigned long (*query_bus_param)(struct soc_camera_device *); | 197 | unsigned long (*query_bus_param)(struct soc_camera_device *); |
179 | int (*set_bus_param)(struct soc_camera_device *, unsigned long); | 198 | int (*set_bus_param)(struct soc_camera_device *, unsigned long); |
180 | int (*get_chip_id)(struct soc_camera_device *, | ||
181 | struct v4l2_dbg_chip_ident *); | ||
182 | int (*set_std)(struct soc_camera_device *, v4l2_std_id *); | ||
183 | int (*enum_input)(struct soc_camera_device *, struct v4l2_input *); | 199 | int (*enum_input)(struct soc_camera_device *, struct v4l2_input *); |
184 | #ifdef CONFIG_VIDEO_ADV_DEBUG | ||
185 | int (*get_register)(struct soc_camera_device *, struct v4l2_dbg_register *); | ||
186 | int (*set_register)(struct soc_camera_device *, struct v4l2_dbg_register *); | ||
187 | #endif | ||
188 | int (*get_control)(struct soc_camera_device *, struct v4l2_control *); | ||
189 | int (*set_control)(struct soc_camera_device *, struct v4l2_control *); | ||
190 | const struct v4l2_queryctrl *controls; | 200 | const struct v4l2_queryctrl *controls; |
191 | int num_controls; | 201 | int num_controls; |
192 | }; | 202 | }; |
@@ -268,6 +278,21 @@ static inline unsigned long soc_camera_bus_param_compatible( | |||
268 | common_flags; | 278 | common_flags; |
269 | } | 279 | } |
270 | 280 | ||
281 | static inline void soc_camera_limit_side(unsigned int *start, | ||
282 | unsigned int *length, unsigned int start_min, | ||
283 | unsigned int length_min, unsigned int length_max) | ||
284 | { | ||
285 | if (*length < length_min) | ||
286 | *length = length_min; | ||
287 | else if (*length > length_max) | ||
288 | *length = length_max; | ||
289 | |||
290 | if (*start < start_min) | ||
291 | *start = start_min; | ||
292 | else if (*start > start_min + length_max - *length) | ||
293 | *start = start_min + length_max - *length; | ||
294 | } | ||
295 | |||
271 | extern unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, | 296 | extern unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, |
272 | unsigned long flags); | 297 | unsigned long flags); |
273 | 298 | ||