Commit 86217651 authored by Sakari Ailus's avatar Sakari Ailus Committed by Bryan Wu

v4l: async: Add a pointer to of_node to struct v4l2_subdev, match it

V4L2 async sub-devices are currently matched (OF case) based on the struct
device_node pointer in struct device. LED devices may have more than one
LED, and in that case the OF node to match is not directly the device's
node, but a LED's node.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@iki.fi>
Signed-off-by: default avatarBryan Wu <cooloney@gmail.com>
parent aaf2cbca
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
#include <media/v4l2-device.h> #include <media/v4l2-device.h>
#include <media/v4l2-subdev.h> #include <media/v4l2-subdev.h>
static bool match_i2c(struct device *dev, struct v4l2_async_subdev *asd) static bool match_i2c(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
{ {
#if IS_ENABLED(CONFIG_I2C) #if IS_ENABLED(CONFIG_I2C)
struct i2c_client *client = i2c_verify_client(dev); struct i2c_client *client = i2c_verify_client(sd->dev);
return client && return client &&
asd->match.i2c.adapter_id == client->adapter->nr && asd->match.i2c.adapter_id == client->adapter->nr &&
asd->match.i2c.address == client->addr; asd->match.i2c.address == client->addr;
...@@ -34,14 +34,24 @@ static bool match_i2c(struct device *dev, struct v4l2_async_subdev *asd) ...@@ -34,14 +34,24 @@ static bool match_i2c(struct device *dev, struct v4l2_async_subdev *asd)
#endif #endif
} }
static bool match_devname(struct device *dev, struct v4l2_async_subdev *asd) static bool match_devname(struct v4l2_subdev *sd,
struct v4l2_async_subdev *asd)
{ {
return !strcmp(asd->match.device_name.name, dev_name(dev)); return !strcmp(asd->match.device_name.name, dev_name(sd->dev));
} }
static bool match_of(struct device *dev, struct v4l2_async_subdev *asd) static bool match_of(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
{ {
return dev->of_node == asd->match.of.node; return sd->of_node == asd->match.of.node;
}
static bool match_custom(struct v4l2_subdev *sd, struct v4l2_async_subdev *asd)
{
if (!asd->match.custom.match)
/* Match always */
return true;
return asd->match.custom.match(sd->dev, asd);
} }
static LIST_HEAD(subdev_list); static LIST_HEAD(subdev_list);
...@@ -51,17 +61,14 @@ static DEFINE_MUTEX(list_lock); ...@@ -51,17 +61,14 @@ static DEFINE_MUTEX(list_lock);
static struct v4l2_async_subdev *v4l2_async_belongs(struct v4l2_async_notifier *notifier, static struct v4l2_async_subdev *v4l2_async_belongs(struct v4l2_async_notifier *notifier,
struct v4l2_subdev *sd) struct v4l2_subdev *sd)
{ {
bool (*match)(struct v4l2_subdev *, struct v4l2_async_subdev *);
struct v4l2_async_subdev *asd; struct v4l2_async_subdev *asd;
bool (*match)(struct device *, struct v4l2_async_subdev *);
list_for_each_entry(asd, &notifier->waiting, list) { list_for_each_entry(asd, &notifier->waiting, list) {
/* bus_type has been verified valid before */ /* bus_type has been verified valid before */
switch (asd->match_type) { switch (asd->match_type) {
case V4L2_ASYNC_MATCH_CUSTOM: case V4L2_ASYNC_MATCH_CUSTOM:
match = asd->match.custom.match; match = match_custom;
if (!match)
/* Match always */
return asd;
break; break;
case V4L2_ASYNC_MATCH_DEVNAME: case V4L2_ASYNC_MATCH_DEVNAME:
match = match_devname; match = match_devname;
...@@ -79,7 +86,7 @@ static struct v4l2_async_subdev *v4l2_async_belongs(struct v4l2_async_notifier * ...@@ -79,7 +86,7 @@ static struct v4l2_async_subdev *v4l2_async_belongs(struct v4l2_async_notifier *
} }
/* match cannot be NULL here */ /* match cannot be NULL here */
if (match(sd->dev, asd)) if (match(sd, asd))
return asd; return asd;
} }
...@@ -266,6 +273,14 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd) ...@@ -266,6 +273,14 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd)
{ {
struct v4l2_async_notifier *notifier; struct v4l2_async_notifier *notifier;
/*
* No reference taken. The reference is held by the device
* (struct v4l2_subdev.dev), and async sub-device does not
* exist independently of the device at any point of time.
*/
if (!sd->of_node && sd->dev)
sd->of_node = sd->dev->of_node;
mutex_lock(&list_lock); mutex_lock(&list_lock);
INIT_LIST_HEAD(&sd->async_list); INIT_LIST_HEAD(&sd->async_list);
......
...@@ -619,6 +619,8 @@ struct v4l2_subdev { ...@@ -619,6 +619,8 @@ struct v4l2_subdev {
struct video_device *devnode; struct video_device *devnode;
/* pointer to the physical device, if any */ /* pointer to the physical device, if any */
struct device *dev; struct device *dev;
/* The device_node of the subdev, usually the same as dev->of_node. */
struct device_node *of_node;
/* Links this subdev to a global subdev_list or @notifier->done list. */ /* Links this subdev to a global subdev_list or @notifier->done list. */
struct list_head async_list; struct list_head async_list;
/* Pointer to respective struct v4l2_async_subdev. */ /* Pointer to respective struct v4l2_async_subdev. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment