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 | |
Sylwester Nawrocki | cfca764 | 2013-07-19 12:14:46 -0300 | [diff] [blame] | 26 | enum v4l2_async_match_type { |
| 27 | V4L2_ASYNC_MATCH_CUSTOM, |
| 28 | V4L2_ASYNC_MATCH_DEVNAME, |
| 29 | V4L2_ASYNC_MATCH_I2C, |
Sylwester Nawrocki | e7359f8 | 2013-07-19 12:21:29 -0300 | [diff] [blame] | 30 | V4L2_ASYNC_MATCH_OF, |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | /** |
| 34 | * struct v4l2_async_subdev - sub-device descriptor, as known to a bridge |
| 35 | * @bus_type: subdevice bus type to select the appropriate matching method |
| 36 | * @match: union of per-bus type matching data sets |
| 37 | * @list: used to link struct v4l2_async_subdev objects, waiting to be |
| 38 | * probed, to a notifier->waiting list |
| 39 | */ |
| 40 | struct v4l2_async_subdev { |
Sylwester Nawrocki | cfca764 | 2013-07-19 12:14:46 -0300 | [diff] [blame] | 41 | enum v4l2_async_match_type match_type; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 42 | union { |
| 43 | struct { |
Sylwester Nawrocki | e7359f8 | 2013-07-19 12:21:29 -0300 | [diff] [blame] | 44 | const struct device_node *node; |
| 45 | } of; |
| 46 | struct { |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 47 | const char *name; |
Sylwester Nawrocki | cfca764 | 2013-07-19 12:14:46 -0300 | [diff] [blame] | 48 | } device_name; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 49 | struct { |
| 50 | int adapter_id; |
| 51 | unsigned short address; |
| 52 | } i2c; |
| 53 | struct { |
| 54 | bool (*match)(struct device *, |
| 55 | struct v4l2_async_subdev *); |
| 56 | void *priv; |
| 57 | } custom; |
| 58 | } match; |
| 59 | |
| 60 | /* v4l2-async core private: not to be used by drivers */ |
| 61 | struct list_head list; |
| 62 | }; |
| 63 | |
| 64 | /** |
| 65 | * v4l2_async_subdev_list - provided by subdevices |
| 66 | * @list: links struct v4l2_async_subdev_list objects to a global list |
| 67 | * before probing, and onto notifier->done after probing |
| 68 | * @asd: pointer to respective struct v4l2_async_subdev |
| 69 | * @notifier: pointer to managing notifier |
| 70 | */ |
| 71 | struct v4l2_async_subdev_list { |
| 72 | struct list_head list; |
| 73 | struct v4l2_async_subdev *asd; |
| 74 | struct v4l2_async_notifier *notifier; |
| 75 | }; |
| 76 | |
| 77 | /** |
| 78 | * v4l2_async_notifier - v4l2_device notifier data |
| 79 | * @num_subdevs:number of subdevices |
Sylwester Nawrocki | e8419d0 | 2013-07-19 12:31:10 -0300 | [diff] [blame^] | 80 | * @subdevs: array of pointers to subdevice descriptors |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 81 | * @v4l2_dev: pointer to struct v4l2_device |
| 82 | * @waiting: list of struct v4l2_async_subdev, waiting for their drivers |
| 83 | * @done: list of struct v4l2_async_subdev_list, already probed |
| 84 | * @list: member in a global list of notifiers |
| 85 | * @bound: a subdevice driver has successfully probed one of subdevices |
| 86 | * @complete: all subdevices have been probed successfully |
| 87 | * @unbind: a subdevice is leaving |
| 88 | */ |
| 89 | struct v4l2_async_notifier { |
| 90 | unsigned int num_subdevs; |
Sylwester Nawrocki | e8419d0 | 2013-07-19 12:31:10 -0300 | [diff] [blame^] | 91 | struct v4l2_async_subdev **subdevs; |
Guennadi Liakhovetski | e9e3104 | 2013-01-08 07:06:31 -0300 | [diff] [blame] | 92 | struct v4l2_device *v4l2_dev; |
| 93 | struct list_head waiting; |
| 94 | struct list_head done; |
| 95 | struct list_head list; |
| 96 | int (*bound)(struct v4l2_async_notifier *notifier, |
| 97 | struct v4l2_subdev *subdev, |
| 98 | struct v4l2_async_subdev *asd); |
| 99 | int (*complete)(struct v4l2_async_notifier *notifier); |
| 100 | void (*unbind)(struct v4l2_async_notifier *notifier, |
| 101 | struct v4l2_subdev *subdev, |
| 102 | struct v4l2_async_subdev *asd); |
| 103 | }; |
| 104 | |
| 105 | int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev, |
| 106 | struct v4l2_async_notifier *notifier); |
| 107 | void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier); |
| 108 | int v4l2_async_register_subdev(struct v4l2_subdev *sd); |
| 109 | void v4l2_async_unregister_subdev(struct v4l2_subdev *sd); |
| 110 | #endif |