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; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 21 | |
| 22 | /* A random max subdevice number, used to allocate an array on stack */ |
| 23 | #define V4L2_MAX_SUBDEVS 128U |
| 24 | |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 25 | /** |
| 26 | * enum v4l2_async_match_type - type of asynchronous subdevice logic to be used |
| 27 | * in order to identify a match |
| 28 | * |
| 29 | * @V4L2_ASYNC_MATCH_CUSTOM: Match will use the logic provided by &struct |
| 30 | * v4l2_async_subdev.match ops |
| 31 | * @V4L2_ASYNC_MATCH_DEVNAME: Match will use the device name |
| 32 | * @V4L2_ASYNC_MATCH_I2C: Match will check for I2C adapter ID and address |
Sakari Ailus | ecdf0cf | 2016-08-16 06:54:59 -0300 | [diff] [blame] | 33 | * @V4L2_ASYNC_MATCH_FWNODE: Match will use firmware node |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 34 | * |
| 35 | * This enum is used by the asyncrhronous sub-device logic to define the |
| 36 | * algorithm that will be used to match an asynchronous device. |
| 37 | */ |
Sylwester Nawrocki | cfca764 | 2013-07-19 12:14:46 -0300 | [diff] [blame] | 38 | enum v4l2_async_match_type { |
| 39 | V4L2_ASYNC_MATCH_CUSTOM, |
| 40 | V4L2_ASYNC_MATCH_DEVNAME, |
| 41 | V4L2_ASYNC_MATCH_I2C, |
Sakari Ailus | ecdf0cf | 2016-08-16 06:54:59 -0300 | [diff] [blame] | 42 | V4L2_ASYNC_MATCH_FWNODE, |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | /** |
| 46 | * 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] | 47 | * |
| 48 | * @match_type: type of match that will be used |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 49 | * @match: union of per-bus type matching data sets |
| 50 | * @list: used to link struct v4l2_async_subdev objects, waiting to be |
| 51 | * probed, to a notifier->waiting list |
Sakari Ailus | 9ca4653 | 2017-08-17 11:28:21 -0400 | [diff] [blame^] | 52 | * |
| 53 | * When this struct is used as a member in a driver specific struct, |
| 54 | * the driver specific struct shall contain the &struct |
| 55 | * v4l2_async_subdev as its first member. |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 56 | */ |
| 57 | struct v4l2_async_subdev { |
Sylwester Nawrocki | cfca764 | 2013-07-19 12:14:46 -0300 | [diff] [blame] | 58 | enum v4l2_async_match_type match_type; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 59 | union { |
| 60 | struct { |
Sakari Ailus | ecdf0cf | 2016-08-16 06:54:59 -0300 | [diff] [blame] | 61 | struct fwnode_handle *fwnode; |
| 62 | } fwnode; |
| 63 | struct { |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 64 | const char *name; |
Sylwester Nawrocki | cfca764 | 2013-07-19 12:14:46 -0300 | [diff] [blame] | 65 | } device_name; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 66 | struct { |
| 67 | int adapter_id; |
| 68 | unsigned short address; |
| 69 | } i2c; |
| 70 | struct { |
| 71 | bool (*match)(struct device *, |
| 72 | struct v4l2_async_subdev *); |
| 73 | void *priv; |
| 74 | } custom; |
| 75 | } match; |
| 76 | |
| 77 | /* v4l2-async core private: not to be used by drivers */ |
| 78 | struct list_head list; |
| 79 | }; |
| 80 | |
| 81 | /** |
Mauro Carvalho Chehab | f8b2737 | 2015-08-22 05:16:24 -0300 | [diff] [blame] | 82 | * struct v4l2_async_notifier - v4l2_device notifier data |
| 83 | * |
Sakari Ailus | 9ca4653 | 2017-08-17 11:28:21 -0400 | [diff] [blame^] | 84 | * @num_subdevs: number of subdevices used in the subdevs array |
| 85 | * @max_subdevs: number of subdevices allocated in the subdevs array |
Sylwester Nawrocki | e8419d0 | 2013-07-19 12:31:10 -0300 | [diff] [blame] | 86 | * @subdevs: array of pointers to subdevice descriptors |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 87 | * @v4l2_dev: pointer to struct v4l2_device |
| 88 | * @waiting: list of struct v4l2_async_subdev, waiting for their drivers |
Sylwester Nawrocki | b426b3a | 2013-07-22 08:01:33 -0300 | [diff] [blame] | 89 | * @done: list of struct v4l2_subdev, already probed |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 90 | * @list: member in a global list of notifiers |
| 91 | * @bound: a subdevice driver has successfully probed one of subdevices |
| 92 | * @complete: all subdevices have been probed successfully |
| 93 | * @unbind: a subdevice is leaving |
| 94 | */ |
| 95 | struct v4l2_async_notifier { |
| 96 | unsigned int num_subdevs; |
Sakari Ailus | 9ca4653 | 2017-08-17 11:28:21 -0400 | [diff] [blame^] | 97 | unsigned int max_subdevs; |
Sylwester Nawrocki | e8419d0 | 2013-07-19 12:31:10 -0300 | [diff] [blame] | 98 | struct v4l2_async_subdev **subdevs; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 99 | struct v4l2_device *v4l2_dev; |
| 100 | struct list_head waiting; |
| 101 | struct list_head done; |
| 102 | struct list_head list; |
| 103 | int (*bound)(struct v4l2_async_notifier *notifier, |
| 104 | struct v4l2_subdev *subdev, |
| 105 | struct v4l2_async_subdev *asd); |
| 106 | int (*complete)(struct v4l2_async_notifier *notifier); |
| 107 | void (*unbind)(struct v4l2_async_notifier *notifier, |
| 108 | struct v4l2_subdev *subdev, |
| 109 | struct v4l2_async_subdev *asd); |
| 110 | }; |
| 111 | |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 112 | /** |
| 113 | * v4l2_async_notifier_register - registers a subdevice asynchronous notifier |
| 114 | * |
| 115 | * @v4l2_dev: pointer to &struct v4l2_device |
| 116 | * @notifier: pointer to &struct v4l2_async_notifier |
| 117 | */ |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 118 | int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev, |
| 119 | struct v4l2_async_notifier *notifier); |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 120 | |
| 121 | /** |
| 122 | * v4l2_async_notifier_unregister - unregisters a subdevice asynchronous notifier |
| 123 | * |
| 124 | * @notifier: pointer to &struct v4l2_async_notifier |
| 125 | */ |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 126 | void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier); |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 127 | |
| 128 | /** |
Sakari Ailus | 9ca4653 | 2017-08-17 11:28:21 -0400 | [diff] [blame^] | 129 | * v4l2_async_notifier_cleanup - clean up notifier resources |
| 130 | * @notifier: the notifier the resources of which are to be cleaned up |
| 131 | * |
| 132 | * Release memory resources related to a notifier, including the async |
| 133 | * sub-devices allocated for the purposes of the notifier but not the notifier |
| 134 | * itself. The user is responsible for calling this function to clean up the |
| 135 | * notifier after calling @v4l2_async_notifier_parse_fwnode_endpoints. |
| 136 | * |
| 137 | * There is no harm from calling v4l2_async_notifier_cleanup in other |
| 138 | * cases as long as its memory has been zeroed after it has been |
| 139 | * allocated. |
| 140 | */ |
| 141 | void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier); |
| 142 | |
| 143 | /** |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 144 | * v4l2_async_register_subdev - registers a sub-device to the asynchronous |
| 145 | * subdevice framework |
| 146 | * |
| 147 | * @sd: pointer to &struct v4l2_subdev |
| 148 | */ |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 149 | int v4l2_async_register_subdev(struct v4l2_subdev *sd); |
Mauro Carvalho Chehab | ab4f5a4a | 2016-07-21 09:24:55 -0300 | [diff] [blame] | 150 | |
| 151 | /** |
| 152 | * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous |
| 153 | * subdevice framework |
| 154 | * |
| 155 | * @sd: pointer to &struct v4l2_subdev |
| 156 | */ |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 157 | void v4l2_async_unregister_subdev(struct v4l2_subdev *sd); |
| 158 | #endif |