aboutsummaryrefslogtreecommitdiffstats
path: root/include/media/v4l2-device.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/media/v4l2-device.h')
-rw-r--r--include/media/v4l2-device.h40
1 files changed, 26 insertions, 14 deletions
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
index 55e41afd95ef..0dd3e8e8653e 100644
--- a/include/media/v4l2-device.h
+++ b/include/media/v4l2-device.h
@@ -33,7 +33,9 @@
33#define V4L2_DEVICE_NAME_SIZE (BUS_ID_SIZE + 16) 33#define V4L2_DEVICE_NAME_SIZE (BUS_ID_SIZE + 16)
34 34
35struct v4l2_device { 35struct v4l2_device {
36 /* dev->driver_data points to this struct */ 36 /* dev->driver_data points to this struct.
37 Note: dev might be NULL if there is no parent device
38 as is the case with e.g. ISA devices. */
37 struct device *dev; 39 struct device *dev;
38 /* used to keep track of the registered subdevs */ 40 /* used to keep track of the registered subdevs */
39 struct list_head subdevs; 41 struct list_head subdevs;
@@ -42,33 +44,43 @@ struct v4l2_device {
42 spinlock_t lock; 44 spinlock_t lock;
43 /* unique device name, by default the driver name + bus ID */ 45 /* unique device name, by default the driver name + bus ID */
44 char name[V4L2_DEVICE_NAME_SIZE]; 46 char name[V4L2_DEVICE_NAME_SIZE];
47 /* notify callback called by some sub-devices. */
48 void (*notify)(struct v4l2_subdev *sd,
49 unsigned int notification, void *arg);
45}; 50};
46 51
47/* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev */ 52/* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev.
53 dev may be NULL in rare cases (ISA devices). In that case you
54 must fill in the v4l2_dev->name field before calling this function. */
48int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev); 55int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev);
49/* Set v4l2_dev->dev->driver_data to NULL and unregister all sub-devices */ 56/* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
57 Since the parent disappears this ensures that v4l2_dev doesn't have an
58 invalid parent pointer. */
59void v4l2_device_disconnect(struct v4l2_device *v4l2_dev);
60/* Unregister all sub-devices and any other resources related to v4l2_dev. */
50void v4l2_device_unregister(struct v4l2_device *v4l2_dev); 61void v4l2_device_unregister(struct v4l2_device *v4l2_dev);
51 62
52/* Register a subdev with a v4l2 device. While registered the subdev module 63/* Register a subdev with a v4l2 device. While registered the subdev module
53 is marked as in-use. An error is returned if the module is no longer 64 is marked as in-use. An error is returned if the module is no longer
54 loaded when you attempt to register it. */ 65 loaded when you attempt to register it. */
55int __must_check v4l2_device_register_subdev(struct v4l2_device *dev, struct v4l2_subdev *sd); 66int __must_check v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
67 struct v4l2_subdev *sd);
56/* Unregister a subdev with a v4l2 device. Can also be called if the subdev 68/* Unregister a subdev with a v4l2 device. Can also be called if the subdev
57 wasn't registered. In that case it will do nothing. */ 69 wasn't registered. In that case it will do nothing. */
58void v4l2_device_unregister_subdev(struct v4l2_subdev *sd); 70void v4l2_device_unregister_subdev(struct v4l2_subdev *sd);
59 71
60/* Iterate over all subdevs. */ 72/* Iterate over all subdevs. */
61#define v4l2_device_for_each_subdev(sd, dev) \ 73#define v4l2_device_for_each_subdev(sd, v4l2_dev) \
62 list_for_each_entry(sd, &(dev)->subdevs, list) 74 list_for_each_entry(sd, &(v4l2_dev)->subdevs, list)
63 75
64/* Call the specified callback for all subdevs matching the condition. 76/* Call the specified callback for all subdevs matching the condition.
65 Ignore any errors. Note that you cannot add or delete a subdev 77 Ignore any errors. Note that you cannot add or delete a subdev
66 while walking the subdevs list. */ 78 while walking the subdevs list. */
67#define __v4l2_device_call_subdevs(dev, cond, o, f, args...) \ 79#define __v4l2_device_call_subdevs(v4l2_dev, cond, o, f, args...) \
68 do { \ 80 do { \
69 struct v4l2_subdev *sd; \ 81 struct v4l2_subdev *sd; \
70 \ 82 \
71 list_for_each_entry(sd, &(dev)->subdevs, list) \ 83 list_for_each_entry(sd, &(v4l2_dev)->subdevs, list) \
72 if ((cond) && sd->ops->o && sd->ops->o->f) \ 84 if ((cond) && sd->ops->o && sd->ops->o->f) \
73 sd->ops->o->f(sd , ##args); \ 85 sd->ops->o->f(sd , ##args); \
74 } while (0) 86 } while (0)
@@ -77,12 +89,12 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd);
77 If the callback returns an error other than 0 or -ENOIOCTLCMD, then 89 If the callback returns an error other than 0 or -ENOIOCTLCMD, then
78 return with that error code. Note that you cannot add or delete a 90 return with that error code. Note that you cannot add or delete a
79 subdev while walking the subdevs list. */ 91 subdev while walking the subdevs list. */
80#define __v4l2_device_call_subdevs_until_err(dev, cond, o, f, args...) \ 92#define __v4l2_device_call_subdevs_until_err(v4l2_dev, cond, o, f, args...) \
81({ \ 93({ \
82 struct v4l2_subdev *sd; \ 94 struct v4l2_subdev *sd; \
83 long err = 0; \ 95 long err = 0; \
84 \ 96 \
85 list_for_each_entry(sd, &(dev)->subdevs, list) { \ 97 list_for_each_entry(sd, &(v4l2_dev)->subdevs, list) { \
86 if ((cond) && sd->ops->o && sd->ops->o->f) \ 98 if ((cond) && sd->ops->o && sd->ops->o->f) \
87 err = sd->ops->o->f(sd , ##args); \ 99 err = sd->ops->o->f(sd , ##args); \
88 if (err && err != -ENOIOCTLCMD) \ 100 if (err && err != -ENOIOCTLCMD) \
@@ -94,16 +106,16 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd);
94/* Call the specified callback for all subdevs matching grp_id (if 0, then 106/* Call the specified callback for all subdevs matching grp_id (if 0, then
95 match them all). Ignore any errors. Note that you cannot add or delete 107 match them all). Ignore any errors. Note that you cannot add or delete
96 a subdev while walking the subdevs list. */ 108 a subdev while walking the subdevs list. */
97#define v4l2_device_call_all(dev, grpid, o, f, args...) \ 109#define v4l2_device_call_all(v4l2_dev, grpid, o, f, args...) \
98 __v4l2_device_call_subdevs(dev, \ 110 __v4l2_device_call_subdevs(v4l2_dev, \
99 !(grpid) || sd->grp_id == (grpid), o, f , ##args) 111 !(grpid) || sd->grp_id == (grpid), o, f , ##args)
100 112
101/* Call the specified callback for all subdevs matching grp_id (if 0, then 113/* Call the specified callback for all subdevs matching grp_id (if 0, then
102 match them all). If the callback returns an error other than 0 or 114 match them all). If the callback returns an error other than 0 or
103 -ENOIOCTLCMD, then return with that error code. Note that you cannot 115 -ENOIOCTLCMD, then return with that error code. Note that you cannot
104 add or delete a subdev while walking the subdevs list. */ 116 add or delete a subdev while walking the subdevs list. */
105#define v4l2_device_call_until_err(dev, grpid, o, f, args...) \ 117#define v4l2_device_call_until_err(v4l2_dev, grpid, o, f, args...) \
106 __v4l2_device_call_subdevs_until_err(dev, \ 118 __v4l2_device_call_subdevs_until_err(v4l2_dev, \
107 !(grpid) || sd->grp_id == (grpid), o, f , ##args) 119 !(grpid) || sd->grp_id == (grpid), o, f , ##args)
108 120
109#endif 121#endif