blob: 1d6d7da4c45d14b5bc8387d371962de7ae7585a1 [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
Sylwester Nawrockicfca7642013-07-19 12:14:46 -030026enum v4l2_async_match_type {
27 V4L2_ASYNC_MATCH_CUSTOM,
28 V4L2_ASYNC_MATCH_DEVNAME,
29 V4L2_ASYNC_MATCH_I2C,
Sylwester Nawrockie7359f82013-07-19 12:21:29 -030030 V4L2_ASYNC_MATCH_OF,
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030031};
32
33/**
34 * struct v4l2_async_subdev - sub-device descriptor, as known to a bridge
Mauro Carvalho Chehabf8b27372015-08-22 05:16:24 -030035 *
36 * @match_type: type of match that will be used
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030037 * @match: union of per-bus type matching data sets
38 * @list: used to link struct v4l2_async_subdev objects, waiting to be
39 * probed, to a notifier->waiting list
40 */
41struct v4l2_async_subdev {
Sylwester Nawrockicfca7642013-07-19 12:14:46 -030042 enum v4l2_async_match_type match_type;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030043 union {
44 struct {
Sylwester Nawrockie7359f82013-07-19 12:21:29 -030045 const struct device_node *node;
46 } of;
47 struct {
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030048 const char *name;
Sylwester Nawrockicfca7642013-07-19 12:14:46 -030049 } device_name;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030050 struct {
51 int adapter_id;
52 unsigned short address;
53 } i2c;
54 struct {
55 bool (*match)(struct device *,
56 struct v4l2_async_subdev *);
57 void *priv;
58 } custom;
59 } match;
60
61 /* v4l2-async core private: not to be used by drivers */
62 struct list_head list;
63};
64
65/**
Mauro Carvalho Chehabf8b27372015-08-22 05:16:24 -030066 * struct v4l2_async_notifier - v4l2_device notifier data
67 *
68 * @num_subdevs: number of subdevices
Sylwester Nawrockie8419d02013-07-19 12:31:10 -030069 * @subdevs: array of pointers to subdevice descriptors
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030070 * @v4l2_dev: pointer to struct v4l2_device
71 * @waiting: list of struct v4l2_async_subdev, waiting for their drivers
Sylwester Nawrockib426b3a2013-07-22 08:01:33 -030072 * @done: list of struct v4l2_subdev, already probed
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030073 * @list: member in a global list of notifiers
74 * @bound: a subdevice driver has successfully probed one of subdevices
75 * @complete: all subdevices have been probed successfully
76 * @unbind: a subdevice is leaving
77 */
78struct v4l2_async_notifier {
79 unsigned int num_subdevs;
Sylwester Nawrockie8419d02013-07-19 12:31:10 -030080 struct v4l2_async_subdev **subdevs;
Guennadi Liakhovetskie9e31042013-01-08 07:06:31 -030081 struct v4l2_device *v4l2_dev;
82 struct list_head waiting;
83 struct list_head done;
84 struct list_head list;
85 int (*bound)(struct v4l2_async_notifier *notifier,
86 struct v4l2_subdev *subdev,
87 struct v4l2_async_subdev *asd);
88 int (*complete)(struct v4l2_async_notifier *notifier);
89 void (*unbind)(struct v4l2_async_notifier *notifier,
90 struct v4l2_subdev *subdev,
91 struct v4l2_async_subdev *asd);
92};
93
94int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
95 struct v4l2_async_notifier *notifier);
96void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier);
97int v4l2_async_register_subdev(struct v4l2_subdev *sd);
98void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
99#endif