Blame view
include/media/soc_camera.h
9.71 KB
e55222ef2 V4L/DVB (7170): s... |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/* * camera image capture (abstract) bus driver header * * Copyright (C) 2006, Sascha Hauer, Pengutronix * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #ifndef SOC_CAMERA_H #define SOC_CAMERA_H |
d839fe17a [media] V4L: soc-... |
14 |
#include <linux/bitops.h> |
52d268a36 V4L/DVB: V4L2: so... |
15 |
#include <linux/device.h> |
1c3bb7431 V4L/DVB (10083): ... |
16 17 |
#include <linux/mutex.h> #include <linux/pm.h> |
e55222ef2 V4L/DVB (7170): s... |
18 |
#include <linux/videodev2.h> |
092d39211 V4L/DVB (8337): s... |
19 |
#include <media/videobuf-core.h> |
592c2aba2 [media] V4L: soc-... |
20 |
#include <media/videobuf2-core.h> |
ee02da645 [media] soc_camer... |
21 |
#include <media/v4l2-ctrls.h> |
979ea1ddf V4L/DVB (12510): ... |
22 |
#include <media/v4l2-device.h> |
e55222ef2 V4L/DVB (7170): s... |
23 |
|
57bee29d6 V4L/DVB: soc-came... |
24 |
struct file; |
7dfff9536 [media] V4L: soc-... |
25 |
struct soc_camera_link; |
57bee29d6 V4L/DVB: soc-came... |
26 |
|
e55222ef2 V4L/DVB (7170): s... |
27 |
struct soc_camera_device { |
d33b290a1 [media] V4L: soc-... |
28 |
struct list_head list; /* list of all registered devices */ |
7dfff9536 [media] V4L: soc-... |
29 |
struct soc_camera_link *link; |
979ea1ddf V4L/DVB (12510): ... |
30 |
struct device *pdev; /* Platform device */ |
7dfff9536 [media] V4L: soc-... |
31 32 |
struct device *parent; /* Camera host device */ struct device *control; /* E.g., the i2c client */ |
6a6c87867 V4L/DVB (12534): ... |
33 34 |
s32 user_width; s32 user_height; |
0e4c180d3 [media] v4l: soc-... |
35 36 |
u32 bytesperline; /* for padding, zero if unused */ u32 sizeimage; |
760697bec V4L/DVB (13659): ... |
37 |
enum v4l2_colorspace colorspace; |
e55222ef2 V4L/DVB (7170): s... |
38 39 |
unsigned char iface; /* Host number */ unsigned char devnum; /* Device number per host */ |
a9bef518c V4L/DVB (10074): ... |
40 |
struct soc_camera_sense *sense; /* See comment in struct definition */ |
e55222ef2 V4L/DVB (7170): s... |
41 |
struct video_device *vdev; |
ee02da645 [media] soc_camer... |
42 |
struct v4l2_ctrl_handler ctrl_handler; |
760697bec V4L/DVB (13659): ... |
43 |
const struct soc_camera_format_xlate *current_fmt; |
c2786ad27 V4L/DVB (9790): s... |
44 45 |
struct soc_camera_format_xlate *user_formats; int num_user_formats; |
025c18a19 V4L/DVB (11027): ... |
46 |
enum v4l2_field field; /* Preserve field over close() */ |
1c3bb7431 V4L/DVB (10083): ... |
47 48 |
void *host_priv; /* Per-device host private data */ /* soc_camera.c private count. Only accessed with .video_lock held */ |
9dc4e48fb V4L/DVB (7276): s... |
49 |
int use_count; |
1c3bb7431 V4L/DVB (10083): ... |
50 |
struct mutex video_lock; /* Protects device data */ |
57bee29d6 V4L/DVB: soc-came... |
51 |
struct file *streamer; /* stream owner */ |
592c2aba2 [media] V4L: soc-... |
52 53 54 55 |
union { struct videobuf_queue vb_vidq; struct vb2_queue vb2_vidq; }; |
e55222ef2 V4L/DVB (7170): s... |
56 57 58 |
}; struct soc_camera_host { |
979ea1ddf V4L/DVB (12510): ... |
59 |
struct v4l2_device v4l2_dev; |
e55222ef2 V4L/DVB (7170): s... |
60 |
struct list_head list; |
e55222ef2 V4L/DVB (7170): s... |
61 |
unsigned char nr; /* Host number */ |
e55222ef2 V4L/DVB (7170): s... |
62 |
void *priv; |
af128a102 V4L/DVB (9521): V... |
63 |
const char *drv_name; |
b8d9904c3 V4L/DVB (7500): s... |
64 65 66 67 68 |
struct soc_camera_host_ops *ops; }; struct soc_camera_host_ops { struct module *owner; |
e55222ef2 V4L/DVB (7170): s... |
69 70 |
int (*add)(struct soc_camera_device *); void (*remove)(struct soc_camera_device *); |
fa48984e3 V4L/DVB (12519): ... |
71 72 73 74 75 76 |
/* * .get_formats() is called for each client device format, but * .put_formats() is only called once. Further, if any of the calls to * .get_formats() fail, .put_formats() will not be called at all, the * failing .get_formats() must then clean up internally. */ |
3805f2019 V4L/DVB: v4l2-sub... |
77 |
int (*get_formats)(struct soc_camera_device *, unsigned int, |
c2786ad27 V4L/DVB (9790): s... |
78 |
struct soc_camera_format_xlate *); |
fa48984e3 V4L/DVB (12519): ... |
79 |
void (*put_formats)(struct soc_camera_device *); |
6a6c87867 V4L/DVB (12534): ... |
80 81 |
int (*cropcap)(struct soc_camera_device *, struct v4l2_cropcap *); int (*get_crop)(struct soc_camera_device *, struct v4l2_crop *); |
08590b961 V4L/DVB (12529): ... |
82 |
int (*set_crop)(struct soc_camera_device *, struct v4l2_crop *); |
aee5c2f1f [media] V4L: soc-... |
83 84 85 86 87 |
/* * The difference to .set_crop() is, that .set_livecrop is not allowed * to change the output sizes */ int (*set_livecrop)(struct soc_camera_device *, struct v4l2_crop *); |
09e231b35 V4L/DVB (11024): ... |
88 |
int (*set_fmt)(struct soc_camera_device *, struct v4l2_format *); |
d8fac217c V4L/DVB (9788): s... |
89 |
int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); |
a034d1b76 V4L/DVB (8338): s... |
90 |
void (*init_videobuf)(struct videobuf_queue *, |
092d39211 V4L/DVB (8337): s... |
91 |
struct soc_camera_device *); |
592c2aba2 [media] V4L: soc-... |
92 93 |
int (*init_videobuf2)(struct vb2_queue *, struct soc_camera_device *); |
57bee29d6 V4L/DVB: soc-came... |
94 |
int (*reqbufs)(struct soc_camera_device *, struct v4l2_requestbuffers *); |
e55222ef2 V4L/DVB (7170): s... |
95 |
int (*querycap)(struct soc_camera_host *, struct v4l2_capability *); |
8843d119e [media] soc-camer... |
96 |
int (*set_bus_param)(struct soc_camera_device *); |
c9f6ef698 soc-camera: add s... |
97 98 |
int (*get_parm)(struct soc_camera_device *, struct v4l2_streamparm *); int (*set_parm)(struct soc_camera_device *, struct v4l2_streamparm *); |
ed5b65dc3 [media] V4L: soc-... |
99 |
int (*enum_fsizes)(struct soc_camera_device *, struct v4l2_frmsizeenum *); |
e55222ef2 V4L/DVB (7170): s... |
100 101 |
unsigned int (*poll)(struct file *, poll_table *); }; |
bd73b36f0 V4L/DVB (10072): ... |
102 103 104 105 106 |
#define SOCAM_SENSOR_INVERT_PCLK (1 << 0) #define SOCAM_SENSOR_INVERT_MCLK (1 << 1) #define SOCAM_SENSOR_INVERT_HSYNC (1 << 2) #define SOCAM_SENSOR_INVERT_VSYNC (1 << 3) #define SOCAM_SENSOR_INVERT_DATA (1 << 4) |
0fd327bd0 V4L/DVB (11705): ... |
107 |
struct i2c_board_info; |
96e442c1b [media] soc_camer... |
108 |
struct regulator_bulk_data; |
0fd327bd0 V4L/DVB (11705): ... |
109 |
|
e55222ef2 V4L/DVB (7170): s... |
110 111 112 |
struct soc_camera_link { /* Camera bus id, used to match a camera and a bus */ int bus_id; |
bd73b36f0 V4L/DVB (10072): ... |
113 114 |
/* Per camera SOCAM_SENSOR_* bus flags */ unsigned long flags; |
0fd327bd0 V4L/DVB (11705): ... |
115 116 117 |
int i2c_adapter_id; struct i2c_board_info *board_info; const char *module_name; |
3fd7ceffd V4L/DVB (13648): ... |
118 |
void *priv; |
96e442c1b [media] soc_camer... |
119 120 121 |
/* Optional regulators that have to be managed on power on/off events */ struct regulator_bulk_data *regulators; int num_regulators; |
c41debafc V4L/DVB (12504): ... |
122 |
/* |
d33b290a1 [media] V4L: soc-... |
123 124 |
* For non-I2C devices platform has to provide methods to add a device * to the system and to remove it |
c41debafc V4L/DVB (12504): ... |
125 |
*/ |
7dfff9536 [media] V4L: soc-... |
126 127 |
int (*add_device)(struct soc_camera_device *); void (*del_device)(struct soc_camera_device *); |
810346631 V4L/DVB (8687): s... |
128 129 130 |
/* Optional callbacks to power on or off and reset the sensor */ int (*power)(struct device *, int); int (*reset)(struct device *); |
28f59339f V4L/DVB (11030): ... |
131 132 133 134 135 136 137 |
/* * some platforms may support different data widths than the sensors * native ones due to different data line routing. Let the board code * overwrite the width flags. */ int (*set_bus_param)(struct soc_camera_link *, unsigned long flags); unsigned long (*query_bus_param)(struct soc_camera_link *); |
594bb46db V4L/DVB (11607): ... |
138 |
void (*free_bus)(struct soc_camera_link *); |
e55222ef2 V4L/DVB (7170): s... |
139 |
}; |
96c753995 V4L/DVB (12536): ... |
140 141 |
static inline struct soc_camera_host *to_soc_camera_host( const struct device *dev) |
e55222ef2 V4L/DVB (7170): s... |
142 |
{ |
979ea1ddf V4L/DVB (12510): ... |
143 144 145 |
struct v4l2_device *v4l2_dev = dev_get_drvdata(dev); return container_of(v4l2_dev, struct soc_camera_host, v4l2_dev); |
e55222ef2 V4L/DVB (7170): s... |
146 |
} |
96c753995 V4L/DVB (12536): ... |
147 148 |
static inline struct soc_camera_link *to_soc_camera_link( const struct soc_camera_device *icd) |
40e2e0927 V4L/DVB (12506): ... |
149 |
{ |
7dfff9536 [media] V4L: soc-... |
150 |
return icd->link; |
40e2e0927 V4L/DVB (12506): ... |
151 |
} |
e55222ef2 V4L/DVB (7170): s... |
152 |
|
96c753995 V4L/DVB (12536): ... |
153 154 |
static inline struct device *to_soc_camera_control( const struct soc_camera_device *icd) |
40e2e0927 V4L/DVB (12506): ... |
155 |
{ |
7dfff9536 [media] V4L: soc-... |
156 |
return icd->control; |
40e2e0927 V4L/DVB (12506): ... |
157 |
} |
e55222ef2 V4L/DVB (7170): s... |
158 |
|
96c753995 V4L/DVB (12536): ... |
159 160 |
static inline struct v4l2_subdev *soc_camera_to_subdev( const struct soc_camera_device *icd) |
c9c1f1c0d V4L/DVB (12530): ... |
161 162 163 164 |
{ struct device *control = to_soc_camera_control(icd); return dev_get_drvdata(control); } |
40e2e0927 V4L/DVB (12506): ... |
165 166 |
int soc_camera_host_register(struct soc_camera_host *ici); void soc_camera_host_unregister(struct soc_camera_host *ici); |
40e2e0927 V4L/DVB (12506): ... |
167 |
const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( |
c2786ad27 V4L/DVB (9790): s... |
168 |
struct soc_camera_device *icd, unsigned int fourcc); |
25c4d74ea V4L/DVB (9787): s... |
169 |
|
c2786ad27 V4L/DVB (9790): s... |
170 171 |
/** * struct soc_camera_format_xlate - match between host and sensor formats |
760697bec V4L/DVB (13659): ... |
172 173 |
* @code: code of a sensor provided format * @host_fmt: host format after host translation from code |
c2786ad27 V4L/DVB (9790): s... |
174 175 176 177 178 179 180 |
* * Host and sensor translation structure. Used in table of host and sensor * formats matchings in soc_camera_device. A host can override the generic list * generation by implementing get_formats(), and use it for format checks and * format setup. */ struct soc_camera_format_xlate { |
760697bec V4L/DVB (13659): ... |
181 182 |
enum v4l2_mbus_pixelcode code; const struct soc_mbus_pixelfmt *host_fmt; |
c2786ad27 V4L/DVB (9790): s... |
183 |
}; |
a9bef518c V4L/DVB (10074): ... |
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
#define SOCAM_SENSE_PCLK_CHANGED (1 << 0) /** * This struct can be attached to struct soc_camera_device by the host driver * to request sense from the camera, for example, when calling .set_fmt(). The * host then can check which flags are set and verify respective values if any. * For example, if SOCAM_SENSE_PCLK_CHANGED is set, it means, pixclock has * changed during this operation. After completion the host should detach sense. * * @flags ored SOCAM_SENSE_* flags * @master_clock if the host wants to be informed about pixel-clock * change, it better set master_clock. * @pixel_clock_max maximum pixel clock frequency supported by the host, * camera is not allowed to exceed this. * @pixel_clock if the camera driver changed pixel clock during this * operation, it sets SOCAM_SENSE_PCLK_CHANGED, uses * master_clock to calculate the new pixel-clock and * sets this field. */ struct soc_camera_sense { unsigned long flags; unsigned long master_clock; unsigned long pixel_clock_max; unsigned long pixel_clock; }; |
d839fe17a [media] V4L: soc-... |
209 210 211 212 213 214 215 |
#define SOCAM_DATAWIDTH(x) BIT((x) - 1) #define SOCAM_DATAWIDTH_4 SOCAM_DATAWIDTH(4) #define SOCAM_DATAWIDTH_8 SOCAM_DATAWIDTH(8) #define SOCAM_DATAWIDTH_9 SOCAM_DATAWIDTH(9) #define SOCAM_DATAWIDTH_10 SOCAM_DATAWIDTH(10) #define SOCAM_DATAWIDTH_15 SOCAM_DATAWIDTH(15) #define SOCAM_DATAWIDTH_16 SOCAM_DATAWIDTH(16) |
042d87900 V4L/DVB (10093): ... |
216 217 218 219 |
#define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_4 | SOCAM_DATAWIDTH_8 | \ SOCAM_DATAWIDTH_9 | SOCAM_DATAWIDTH_10 | \ SOCAM_DATAWIDTH_15 | SOCAM_DATAWIDTH_16) |
ad5f2e859 V4L/DVB (7336): s... |
220 |
|
e26b31449 V4L/DVB: The firs... |
221 222 |
static inline void soc_camera_limit_side(int *start, int *length, unsigned int start_min, |
6a6c87867 V4L/DVB (12534): ... |
223 224 225 226 227 228 229 230 231 232 233 234 |
unsigned int length_min, unsigned int length_max) { if (*length < length_min) *length = length_min; else if (*length > length_max) *length = length_max; if (*start < start_min) *start = start_min; else if (*start > start_min + length_max - *length) *start = start_min + length_max - *length; } |
32c69fcc7 [media] V4L: soc-... |
235 236 237 238 |
unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, unsigned long flags); unsigned long soc_camera_apply_board_flags(struct soc_camera_link *icl, const struct v4l2_mbus_config *cfg); |
bd73b36f0 V4L/DVB (10072): ... |
239 |
|
4f9fb5ed0 V4L/DVB: soc-came... |
240 241 |
/* This is only temporary here - until v4l2-subdev begins to link to video_device */ #include <linux/i2c.h> |
14178aa57 [media] V4L: soc-... |
242 |
static inline struct video_device *soc_camera_i2c_to_vdev(const struct i2c_client *client) |
4f9fb5ed0 V4L/DVB: soc-came... |
243 |
{ |
2f0babb7e [media] V4L: soc-... |
244 |
struct v4l2_subdev *sd = i2c_get_clientdata(client); |
4c0b036db [media] V4L: soc-... |
245 |
struct soc_camera_device *icd = v4l2_get_subdev_hostdata(sd); |
14178aa57 [media] V4L: soc-... |
246 |
return icd ? icd->vdev : NULL; |
4f9fb5ed0 V4L/DVB: soc-came... |
247 |
} |
14178aa57 [media] V4L: soc-... |
248 249 |
static inline struct soc_camera_link *soc_camera_i2c_to_link(const struct i2c_client *client) { |
2f0babb7e [media] V4L: soc-... |
250 |
return client->dev.platform_data; |
14178aa57 [media] V4L: soc-... |
251 252 253 254 255 256 257 |
} static inline struct v4l2_subdev *soc_camera_vdev_to_subdev(const struct video_device *vdev) { struct soc_camera_device *icd = dev_get_drvdata(vdev->parent); return soc_camera_to_subdev(icd); } |
14178aa57 [media] V4L: soc-... |
258 |
static inline struct soc_camera_device *soc_camera_from_vb2q(const struct vb2_queue *vq) |
8eb4476d4 [media] V4L: soc-... |
259 260 261 |
{ return container_of(vq, struct soc_camera_device, vb2_vidq); } |
14178aa57 [media] V4L: soc-... |
262 |
static inline struct soc_camera_device *soc_camera_from_vbq(const struct videobuf_queue *vq) |
8eb4476d4 [media] V4L: soc-... |
263 264 265 |
{ return container_of(vq, struct soc_camera_device, vb_vidq); } |
4c0b036db [media] V4L: soc-... |
266 267 268 269 |
static inline u32 soc_camera_grp_id(const struct soc_camera_device *icd) { return (icd->iface << 8) | (icd->devnum + 1); } |
592c2aba2 [media] V4L: soc-... |
270 271 |
void soc_camera_lock(struct vb2_queue *vq); void soc_camera_unlock(struct vb2_queue *vq); |
e55222ef2 V4L/DVB (7170): s... |
272 |
#endif |