blob: 68606afb5ef92a4e5b17362feb40b299e2feef49 [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 {
61 struct {
Sakari Ailusecdf0cf2016-08-16 06:54:59 -030062 struct fwnode_handle *fwnode;
63 } fwnode;
64 struct {
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030065 const char *name;
Sylwester Nawrockicfca7642013-07-19 12:14:46 -030066 } device_name;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030067 struct {
68 int adapter_id;
69 unsigned short address;
70 } i2c;
71 struct {
72 bool (*match)(struct device *,
73 struct v4l2_async_subdev *);
74 void *priv;
75 } custom;
76 } match;
77
78 /* v4l2-async core private: not to be used by drivers */
79 struct list_head list;
80};
81
82/**
Laurent Pinchartb6ee3f02017-08-30 13:18:04 -040083 * struct v4l2_async_notifier_operations - Asynchronous V4L2 notifier operations
84 * @bound: a subdevice driver has successfully probed one of the subdevices
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030085 * @complete: all subdevices have been probed successfully
86 * @unbind: a subdevice is leaving
87 */
Laurent Pinchartb6ee3f02017-08-30 13:18:04 -040088struct v4l2_async_notifier_operations {
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030089 int (*bound)(struct v4l2_async_notifier *notifier,
90 struct v4l2_subdev *subdev,
91 struct v4l2_async_subdev *asd);
92 int (*complete)(struct v4l2_async_notifier *notifier);
93 void (*unbind)(struct v4l2_async_notifier *notifier,
94 struct v4l2_subdev *subdev,
95 struct v4l2_async_subdev *asd);
96};
97
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -030098/**
Laurent Pinchartb6ee3f02017-08-30 13:18:04 -040099 * struct v4l2_async_notifier - v4l2_device notifier data
100 *
101 * @ops: notifier operations
102 * @num_subdevs: number of subdevices used in the subdevs array
103 * @max_subdevs: number of subdevices allocated in the subdevs array
104 * @subdevs: array of pointers to subdevice descriptors
105 * @v4l2_dev: pointer to struct v4l2_device
106 * @waiting: list of struct v4l2_async_subdev, waiting for their drivers
107 * @done: list of struct v4l2_subdev, already probed
108 * @list: member in a global list of notifiers
109 */
110struct v4l2_async_notifier {
111 const struct v4l2_async_notifier_operations *ops;
112 unsigned int num_subdevs;
113 unsigned int max_subdevs;
114 struct v4l2_async_subdev **subdevs;
115 struct v4l2_device *v4l2_dev;
116 struct list_head waiting;
117 struct list_head done;
118 struct list_head list;
119};
120
121/**
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300122 * v4l2_async_notifier_register - registers a subdevice asynchronous notifier
123 *
124 * @v4l2_dev: pointer to &struct v4l2_device
125 * @notifier: pointer to &struct v4l2_async_notifier
126 */
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -0300127int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
128 struct v4l2_async_notifier *notifier);
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300129
130/**
131 * v4l2_async_notifier_unregister - unregisters a subdevice asynchronous notifier
132 *
133 * @notifier: pointer to &struct v4l2_async_notifier
134 */
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -0300135void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier);
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300136
137/**
Sakari Ailus9ca46532017-08-17 11:28:21 -0400138 * v4l2_async_notifier_cleanup - clean up notifier resources
139 * @notifier: the notifier the resources of which are to be cleaned up
140 *
141 * Release memory resources related to a notifier, including the async
142 * sub-devices allocated for the purposes of the notifier but not the notifier
143 * itself. The user is responsible for calling this function to clean up the
144 * notifier after calling @v4l2_async_notifier_parse_fwnode_endpoints.
145 *
146 * There is no harm from calling v4l2_async_notifier_cleanup in other
147 * cases as long as its memory has been zeroed after it has been
148 * allocated.
149 */
150void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier);
151
152/**
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300153 * v4l2_async_register_subdev - registers a sub-device to the asynchronous
154 * subdevice framework
155 *
156 * @sd: pointer to &struct v4l2_subdev
157 */
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -0300158int v4l2_async_register_subdev(struct v4l2_subdev *sd);
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300159
160/**
161 * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
162 * subdevice framework
163 *
164 * @sd: pointer to &struct v4l2_subdev
165 */
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -0300166void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
167#endif