blob: c3695fa2c903963eb43f4c37739ca7916df631d5 [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;
21struct v4l2_async_notifier;
22
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
34 * @V4L2_ASYNC_MATCH_OF: Match will use OF node
Sakari Ailusecdf0cf2016-08-16 06:54:59 -030035 * @V4L2_ASYNC_MATCH_FWNODE: Match will use firmware node
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -030036 *
37 * This enum is used by the asyncrhronous sub-device logic to define the
38 * algorithm that will be used to match an asynchronous device.
39 */
Sylwester Nawrockicfca7642013-07-19 12:14:46 -030040enum v4l2_async_match_type {
41 V4L2_ASYNC_MATCH_CUSTOM,
42 V4L2_ASYNC_MATCH_DEVNAME,
43 V4L2_ASYNC_MATCH_I2C,
Sylwester Nawrockie7359f82013-07-19 12:21:29 -030044 V4L2_ASYNC_MATCH_OF,
Sakari Ailusecdf0cf2016-08-16 06:54:59 -030045 V4L2_ASYNC_MATCH_FWNODE,
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030046};
47
48/**
49 * struct v4l2_async_subdev - sub-device descriptor, as known to a bridge
Mauro Carvalho Chehabf8b27372015-08-22 05:16:24 -030050 *
51 * @match_type: type of match that will be used
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030052 * @match: union of per-bus type matching data sets
53 * @list: used to link struct v4l2_async_subdev objects, waiting to be
54 * probed, to a notifier->waiting list
55 */
56struct v4l2_async_subdev {
Sylwester Nawrockicfca7642013-07-19 12:14:46 -030057 enum v4l2_async_match_type match_type;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030058 union {
59 struct {
Sylwester Nawrockie7359f82013-07-19 12:21:29 -030060 const struct device_node *node;
61 } of;
62 struct {
Sakari Ailusecdf0cf2016-08-16 06:54:59 -030063 struct fwnode_handle *fwnode;
64 } fwnode;
65 struct {
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030066 const char *name;
Sylwester Nawrockicfca7642013-07-19 12:14:46 -030067 } device_name;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030068 struct {
69 int adapter_id;
70 unsigned short address;
71 } i2c;
72 struct {
73 bool (*match)(struct device *,
74 struct v4l2_async_subdev *);
75 void *priv;
76 } custom;
77 } match;
78
79 /* v4l2-async core private: not to be used by drivers */
80 struct list_head list;
81};
82
83/**
Mauro Carvalho Chehabf8b27372015-08-22 05:16:24 -030084 * struct v4l2_async_notifier - v4l2_device notifier data
85 *
86 * @num_subdevs: number of subdevices
Sylwester Nawrockie8419d02013-07-19 12:31:10 -030087 * @subdevs: array of pointers to subdevice descriptors
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030088 * @v4l2_dev: pointer to struct v4l2_device
89 * @waiting: list of struct v4l2_async_subdev, waiting for their drivers
Sylwester Nawrockib426b3a2013-07-22 08:01:33 -030090 * @done: list of struct v4l2_subdev, already probed
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030091 * @list: member in a global list of notifiers
92 * @bound: a subdevice driver has successfully probed one of subdevices
93 * @complete: all subdevices have been probed successfully
94 * @unbind: a subdevice is leaving
95 */
96struct v4l2_async_notifier {
97 unsigned int num_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/**
129 * v4l2_async_register_subdev - registers a sub-device to the asynchronous
130 * subdevice framework
131 *
132 * @sd: pointer to &struct v4l2_subdev
133 */
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -0300134int v4l2_async_register_subdev(struct v4l2_subdev *sd);
Mauro Carvalho Chehabab4f5a4a2016-07-21 09:24:55 -0300135
136/**
137 * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
138 * subdevice framework
139 *
140 * @sd: pointer to &struct v4l2_subdev
141 */
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -0300142void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
143#endif