blob: 329aeebd1a80a377159d170bd0654b51c0d1d8a1 [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;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030021
22/* A random max subdevice number, used to allocate an array on stack */
23#define V4L2_MAX_SUBDEVS 128U
24
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -030025/**
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 Ailusecdf0cf2016-08-16 06:54:59 -030033 * @V4L2_ASYNC_MATCH_FWNODE: Match will use firmware node
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -030034 *
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 Nawrockicfca7642013-07-19 12:14:46 -030038enum v4l2_async_match_type {
39 V4L2_ASYNC_MATCH_CUSTOM,
40 V4L2_ASYNC_MATCH_DEVNAME,
41 V4L2_ASYNC_MATCH_I2C,
Sakari Ailusecdf0cf2016-08-16 06:54:59 -030042 V4L2_ASYNC_MATCH_FWNODE,
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030043};
44
45/**
46 * struct v4l2_async_subdev - sub-device descriptor, as known to a bridge
Mauro Carvalho Chehabf8b27372015-08-22 05:16:24 -030047 *
48 * @match_type: type of match that will be used
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030049 * @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 Ailus9ca46532017-08-17 11:28:21 -040052 *
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 Liakhovetskie9e31042013-01-08 07:06:31 -030056 */
57struct v4l2_async_subdev {
Sylwester Nawrockicfca7642013-07-19 12:14:46 -030058 enum v4l2_async_match_type match_type;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030059 union {
60 struct {
Sakari Ailusecdf0cf2016-08-16 06:54:59 -030061 struct fwnode_handle *fwnode;
62 } fwnode;
63 struct {
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030064 const char *name;
Sylwester Nawrockicfca7642013-07-19 12:14:46 -030065 } device_name;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030066 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 Chehabf8b27372015-08-22 05:16:24 -030082 * struct v4l2_async_notifier - v4l2_device notifier data
83 *
Sakari Ailus9ca46532017-08-17 11:28:21 -040084 * @num_subdevs: number of subdevices used in the subdevs array
85 * @max_subdevs: number of subdevices allocated in the subdevs array
Sylwester Nawrockie8419d02013-07-19 12:31:10 -030086 * @subdevs: array of pointers to subdevice descriptors
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030087 * @v4l2_dev: pointer to struct v4l2_device
88 * @waiting: list of struct v4l2_async_subdev, waiting for their drivers
Sylwester Nawrockib426b3a2013-07-22 08:01:33 -030089 * @done: list of struct v4l2_subdev, already probed
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030090 * @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 */
95struct v4l2_async_notifier {
96 unsigned int num_subdevs;
Sakari Ailus9ca46532017-08-17 11:28:21 -040097 unsigned int max_subdevs;
Sylwester Nawrockie8419d02013-07-19 12:31:10 -030098 struct v4l2_async_subdev **subdevs;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030099 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 Chehabab4f5a4a2016-07-21 09:24:55 -0300112/**
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 Liakhovetskie9e31042013-01-08 07:06:31 -0300118int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
119 struct v4l2_async_notifier *notifier);
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300120
121/**
122 * v4l2_async_notifier_unregister - unregisters a subdevice asynchronous notifier
123 *
124 * @notifier: pointer to &struct v4l2_async_notifier
125 */
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -0300126void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier);
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300127
128/**
Sakari Ailus9ca46532017-08-17 11:28:21 -0400129 * 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 */
141void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier);
142
143/**
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300144 * v4l2_async_register_subdev - registers a sub-device to the asynchronous
145 * subdevice framework
146 *
147 * @sd: pointer to &struct v4l2_subdev
148 */
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -0300149int v4l2_async_register_subdev(struct v4l2_subdev *sd);
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300150
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 Liakhovetskie9e31042013-01-08 07:06:31 -0300157void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
158#endif