Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 1 | /* |
| 2 | * V4L2 asynchronous subdevice registration API |
| 3 | * |
| 4 | * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #ifndef V4L2_ASYNC_H |
| 12 | #define V4L2_ASYNC_H |
| 13 | |
| 14 | #include <linux/list.h> |
| 15 | #include <linux/mutex.h> |
| 16 | |
| 17 | struct device; |
Sylwester Nawrocki | e7359f8 | 2013-07-19 12:21:29 -0300 | [diff] [blame] | 18 | struct device_node; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 19 | struct v4l2_device; |
| 20 | struct v4l2_subdev; |
| 21 | struct v4l2_async_notifier; |
| 22 | |
| 23 | /* A random max subdevice number, used to allocate an array on stack */ |
| 24 | #define V4L2_MAX_SUBDEVS 128U |
| 25 | |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 26 | /** |
| 27 | * enum v4l2_async_match_type - type of asynchronous subdevice logic to be used |
| 28 | * in order to identify a match |
| 29 | * |
| 30 | * @V4L2_ASYNC_MATCH_CUSTOM: Match will use the logic provided by &struct |
| 31 | * v4l2_async_subdev.match ops |
| 32 | * @V4L2_ASYNC_MATCH_DEVNAME: Match will use the device name |
| 33 | * @V4L2_ASYNC_MATCH_I2C: Match will check for I2C adapter ID and address |
| 34 | * @V4L2_ASYNC_MATCH_OF: Match will use OF node |
| 35 | * |
| 36 | * This enum is used by the asyncrhronous sub-device logic to define the |
| 37 | * algorithm that will be used to match an asynchronous device. |
| 38 | */ |
Sylwester Nawrocki | cfca764 | 2013-07-19 12:14:46 -0300 | [diff] [blame] | 39 | enum v4l2_async_match_type { |
| 40 | V4L2_ASYNC_MATCH_CUSTOM, |
| 41 | V4L2_ASYNC_MATCH_DEVNAME, |
| 42 | V4L2_ASYNC_MATCH_I2C, |
Sylwester Nawrocki | e7359f8 | 2013-07-19 12:21:29 -0300 | [diff] [blame] | 43 | V4L2_ASYNC_MATCH_OF, |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * struct v4l2_async_subdev - sub-device descriptor, as known to a bridge |
Mauro Carvalho Chehab | f8b2737 | 2015-08-22 05:16:24 -0300 | [diff] [blame] | 48 | * |
| 49 | * @match_type: type of match that will be used |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 50 | * @match: union of per-bus type matching data sets |
| 51 | * @list: used to link struct v4l2_async_subdev objects, waiting to be |
| 52 | * probed, to a notifier->waiting list |
| 53 | */ |
| 54 | struct v4l2_async_subdev { |
Sylwester Nawrocki | cfca764 | 2013-07-19 12:14:46 -0300 | [diff] [blame] | 55 | enum v4l2_async_match_type match_type; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 56 | union { |
| 57 | struct { |
Sylwester Nawrocki | e7359f8 | 2013-07-19 12:21:29 -0300 | [diff] [blame] | 58 | const struct device_node *node; |
| 59 | } of; |
| 60 | struct { |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 61 | const char *name; |
Sylwester Nawrocki | cfca764 | 2013-07-19 12:14:46 -0300 | [diff] [blame] | 62 | } device_name; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 63 | struct { |
| 64 | int adapter_id; |
| 65 | unsigned short address; |
| 66 | } i2c; |
| 67 | struct { |
| 68 | bool (*match)(struct device *, |
| 69 | struct v4l2_async_subdev *); |
| 70 | void *priv; |
| 71 | } custom; |
| 72 | } match; |
| 73 | |
| 74 | /* v4l2-async core private: not to be used by drivers */ |
| 75 | struct list_head list; |
| 76 | }; |
| 77 | |
| 78 | /** |
Mauro Carvalho Chehab | f8b2737 | 2015-08-22 05:16:24 -0300 | [diff] [blame] | 79 | * struct v4l2_async_notifier - v4l2_device notifier data |
| 80 | * |
| 81 | * @num_subdevs: number of subdevices |
Sylwester Nawrocki | e8419d0 | 2013-07-19 12:31:10 -0300 | [diff] [blame] | 82 | * @subdevs: array of pointers to subdevice descriptors |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 83 | * @v4l2_dev: pointer to struct v4l2_device |
| 84 | * @waiting: list of struct v4l2_async_subdev, waiting for their drivers |
Sylwester Nawrocki | b426b3a | 2013-07-22 08:01:33 -0300 | [diff] [blame] | 85 | * @done: list of struct v4l2_subdev, already probed |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 86 | * @list: member in a global list of notifiers |
| 87 | * @bound: a subdevice driver has successfully probed one of subdevices |
| 88 | * @complete: all subdevices have been probed successfully |
| 89 | * @unbind: a subdevice is leaving |
| 90 | */ |
| 91 | struct v4l2_async_notifier { |
| 92 | unsigned int num_subdevs; |
Sylwester Nawrocki | e8419d0 | 2013-07-19 12:31:10 -0300 | [diff] [blame] | 93 | struct v4l2_async_subdev **subdevs; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 94 | struct v4l2_device *v4l2_dev; |
| 95 | struct list_head waiting; |
| 96 | struct list_head done; |
| 97 | struct list_head list; |
| 98 | int (*bound)(struct v4l2_async_notifier *notifier, |
| 99 | struct v4l2_subdev *subdev, |
| 100 | struct v4l2_async_subdev *asd); |
| 101 | int (*complete)(struct v4l2_async_notifier *notifier); |
| 102 | void (*unbind)(struct v4l2_async_notifier *notifier, |
| 103 | struct v4l2_subdev *subdev, |
| 104 | struct v4l2_async_subdev *asd); |
| 105 | }; |
| 106 | |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 107 | /** |
| 108 | * v4l2_async_notifier_register - registers a subdevice asynchronous notifier |
| 109 | * |
| 110 | * @v4l2_dev: pointer to &struct v4l2_device |
| 111 | * @notifier: pointer to &struct v4l2_async_notifier |
| 112 | */ |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 113 | int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev, |
| 114 | struct v4l2_async_notifier *notifier); |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * v4l2_async_notifier_unregister - unregisters a subdevice asynchronous notifier |
| 118 | * |
| 119 | * @notifier: pointer to &struct v4l2_async_notifier |
| 120 | */ |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 121 | void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier); |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 122 | |
| 123 | /** |
| 124 | * v4l2_async_register_subdev - registers a sub-device to the asynchronous |
| 125 | * subdevice framework |
| 126 | * |
| 127 | * @sd: pointer to &struct v4l2_subdev |
| 128 | */ |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 129 | int v4l2_async_register_subdev(struct v4l2_subdev *sd); |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 130 | |
| 131 | /** |
| 132 | * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous |
| 133 | * subdevice framework |
| 134 | * |
| 135 | * @sd: pointer to &struct v4l2_subdev |
| 136 | */ |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 137 | void v4l2_async_unregister_subdev(struct v4l2_subdev *sd); |
| 138 | #endif |