blob: a010af5134b23cba1ceb994313c1a92f341c68ad [file] [log] [blame]
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -03001/*
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
17struct device;
Sylwester Nawrockie7359f82013-07-19 12:21:29 -030018struct device_node;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030019struct v4l2_device;
20struct v4l2_subdev;
Laurent Pinchartb6ee3f02017-08-30 13:18:04 -040021struct v4l2_async_notifier;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030022
23/* A random max subdevice number, used to allocate an array on stack */
24#define V4L2_MAX_SUBDEVS 128U
25
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -030026/**
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
Sakari Ailusecdf0cf2016-08-16 06:54:59 -030034 * @V4L2_ASYNC_MATCH_FWNODE: Match will use firmware node
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -030035 *
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 Nawrockicfca7642013-07-19 12:14:46 -030039enum v4l2_async_match_type {
40 V4L2_ASYNC_MATCH_CUSTOM,
41 V4L2_ASYNC_MATCH_DEVNAME,
42 V4L2_ASYNC_MATCH_I2C,
Sakari Ailusecdf0cf2016-08-16 06:54:59 -030043 V4L2_ASYNC_MATCH_FWNODE,
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030044};
45
46/**
47 * struct v4l2_async_subdev - sub-device descriptor, as known to a bridge
Mauro Carvalho Chehabf8b27372015-08-22 05:16:24 -030048 *
49 * @match_type: type of match that will be used
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030050 * @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
Sakari Ailus9ca46532017-08-17 11:28:21 -040053 *
54 * When this struct is used as a member in a driver specific struct,
55 * the driver specific struct shall contain the &struct
56 * v4l2_async_subdev as its first member.
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030057 */
58struct v4l2_async_subdev {
Sylwester Nawrockicfca7642013-07-19 12:14:46 -030059 enum v4l2_async_match_type match_type;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030060 union {
Mauro Carvalho Chehab4e48afe2017-09-27 10:12:00 -040061 struct fwnode_handle *fwnode;
62 const char *device_name;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030063 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/**
Laurent Pinchartb6ee3f02017-08-30 13:18:04 -040079 * struct v4l2_async_notifier_operations - Asynchronous V4L2 notifier operations
80 * @bound: a subdevice driver has successfully probed one of the subdevices
Sakari Ailus2cab00b2017-09-24 20:54:31 -040081 * @complete: All subdevices have been probed successfully. The complete
82 * callback is only executed for the root notifier.
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030083 * @unbind: a subdevice is leaving
84 */
Laurent Pinchartb6ee3f02017-08-30 13:18:04 -040085struct v4l2_async_notifier_operations {
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030086 int (*bound)(struct v4l2_async_notifier *notifier,
87 struct v4l2_subdev *subdev,
88 struct v4l2_async_subdev *asd);
89 int (*complete)(struct v4l2_async_notifier *notifier);
90 void (*unbind)(struct v4l2_async_notifier *notifier,
91 struct v4l2_subdev *subdev,
92 struct v4l2_async_subdev *asd);
93};
94
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -030095/**
Laurent Pinchartb6ee3f02017-08-30 13:18:04 -040096 * struct v4l2_async_notifier - v4l2_device notifier data
97 *
98 * @ops: notifier operations
99 * @num_subdevs: number of subdevices used in the subdevs array
100 * @max_subdevs: number of subdevices allocated in the subdevs array
101 * @subdevs: array of pointers to subdevice descriptors
Sakari Ailus2cab00b2017-09-24 20:54:31 -0400102 * @v4l2_dev: v4l2_device of the root notifier, NULL otherwise
103 * @sd: sub-device that registered the notifier, NULL otherwise
104 * @parent: parent notifier
Laurent Pinchartb6ee3f02017-08-30 13:18:04 -0400105 * @waiting: list of struct v4l2_async_subdev, waiting for their drivers
106 * @done: list of struct v4l2_subdev, already probed
107 * @list: member in a global list of notifiers
108 */
109struct v4l2_async_notifier {
110 const struct v4l2_async_notifier_operations *ops;
111 unsigned int num_subdevs;
112 unsigned int max_subdevs;
113 struct v4l2_async_subdev **subdevs;
114 struct v4l2_device *v4l2_dev;
Sakari Ailus2cab00b2017-09-24 20:54:31 -0400115 struct v4l2_subdev *sd;
116 struct v4l2_async_notifier *parent;
Laurent Pinchartb6ee3f02017-08-30 13:18:04 -0400117 struct list_head waiting;
118 struct list_head done;
119 struct list_head list;
120};
121
122/**
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300123 * v4l2_async_notifier_register - registers a subdevice asynchronous notifier
124 *
125 * @v4l2_dev: pointer to &struct v4l2_device
126 * @notifier: pointer to &struct v4l2_async_notifier
127 */
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -0300128int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
129 struct v4l2_async_notifier *notifier);
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300130
131/**
Sakari Ailus2cab00b2017-09-24 20:54:31 -0400132 * v4l2_async_subdev_notifier_register - registers a subdevice asynchronous
133 * notifier for a sub-device
134 *
135 * @sd: pointer to &struct v4l2_subdev
136 * @notifier: pointer to &struct v4l2_async_notifier
137 */
138int v4l2_async_subdev_notifier_register(struct v4l2_subdev *sd,
139 struct v4l2_async_notifier *notifier);
140
141/**
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300142 * v4l2_async_notifier_unregister - unregisters a subdevice asynchronous notifier
143 *
144 * @notifier: pointer to &struct v4l2_async_notifier
145 */
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -0300146void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier);
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300147
148/**
Sakari Ailus9ca46532017-08-17 11:28:21 -0400149 * v4l2_async_notifier_cleanup - clean up notifier resources
150 * @notifier: the notifier the resources of which are to be cleaned up
151 *
152 * Release memory resources related to a notifier, including the async
153 * sub-devices allocated for the purposes of the notifier but not the notifier
154 * itself. The user is responsible for calling this function to clean up the
Sakari Ailus7a9ec802017-09-06 08:35:42 -0400155 * notifier after calling @v4l2_async_notifier_parse_fwnode_endpoints or
156 * @v4l2_fwnode_reference_parse_sensor_common.
Sakari Ailus9ca46532017-08-17 11:28:21 -0400157 *
158 * There is no harm from calling v4l2_async_notifier_cleanup in other
159 * cases as long as its memory has been zeroed after it has been
160 * allocated.
161 */
162void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier);
163
164/**
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300165 * v4l2_async_register_subdev - registers a sub-device to the asynchronous
166 * subdevice framework
167 *
168 * @sd: pointer to &struct v4l2_subdev
169 */
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -0300170int v4l2_async_register_subdev(struct v4l2_subdev *sd);
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300171
172/**
Sakari Ailusaef69d52017-09-24 18:47:44 -0400173 * v4l2_async_register_subdev_sensor_common - registers a sensor sub-device to
174 * the asynchronous sub-device
175 * framework and parse set up common
176 * sensor related devices
177 *
178 * @sd: pointer to struct &v4l2_subdev
179 *
180 * This function is just like v4l2_async_register_subdev() with the exception
181 * that calling it will also parse firmware interfaces for remote references
182 * using v4l2_async_notifier_parse_fwnode_sensor_common() and registers the
183 * async sub-devices. The sub-device is similarly unregistered by calling
184 * v4l2_async_unregister_subdev().
185 *
186 * While registered, the subdev module is marked as in-use.
187 *
188 * An error is returned if the module is no longer loaded on any attempts
189 * to register it.
190 */
191int __must_check v4l2_async_register_subdev_sensor_common(
192 struct v4l2_subdev *sd);
193
194/**
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300195 * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
196 * subdevice framework
197 *
198 * @sd: pointer to &struct v4l2_subdev
199 */
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -0300200void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
201#endif