Commit 51ff392c authored by Ezequiel Garcia's avatar Ezequiel Garcia Committed by Mauro Carvalho Chehab
Browse files

media: v4l2-core: introduce a helper to unregister a i2c subdev



Introduce a new video4linux2 i2c helper, to unregister a subdev.
This allows to get rid of yet another ifdef.

Signed-off-by: default avatarEzequiel Garcia <ezequiel@collabora.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
[hverkuil-cisco@xs4all.nl: fix checkpatch warning]
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent a9cff393
Loading
Loading
Loading
Loading
+2 −23
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@
#include <linux/types.h>
#include <linux/ioctl.h>
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/videodev2.h>
#include <media/v4l2-device.h>
@@ -99,28 +98,8 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
	/* Unregister subdevs */
	list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) {
		v4l2_device_unregister_subdev(sd);
#if IS_ENABLED(CONFIG_I2C)
		if (sd->flags & V4L2_SUBDEV_FL_IS_I2C) {
			struct i2c_client *client = v4l2_get_subdevdata(sd);

			/*
			 * We need to unregister the i2c client
			 * explicitly. We cannot rely on
			 * i2c_del_adapter to always unregister
			 * clients for us, since if the i2c bus is a
			 * platform bus, then it is never deleted.
			 *
			 * Device tree or ACPI based devices must not
			 * be unregistered as they have not been
			 * registered by us, and would not be
			 * re-created by just probing the V4L2 driver.
			 */
			if (client &&
			    !client->dev.of_node && !client->dev.fwnode)
				i2c_unregister_device(client);
			continue;
		}
#endif
		if (sd->flags & V4L2_SUBDEV_FL_IS_I2C)
			v4l2_i2c_subdev_unregister(sd);
		else if (sd->flags & V4L2_SUBDEV_FL_IS_SPI)
			v4l2_spi_subdev_unregister(sd);
	}
+20 −0
Original line number Diff line number Diff line
@@ -8,6 +8,26 @@
#include <media/v4l2-common.h>
#include <media/v4l2-device.h>

void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd)
{
	struct i2c_client *client = v4l2_get_subdevdata(sd);

	/*
	 * We need to unregister the i2c client
	 * explicitly. We cannot rely on
	 * i2c_del_adapter to always unregister
	 * clients for us, since if the i2c bus is a
	 * platform bus, then it is never deleted.
	 *
	 * Device tree or ACPI based devices must not
	 * be unregistered as they have not been
	 * registered by us, and would not be
	 * re-created by just probing the V4L2 driver.
	 */
	if (client && !client->dev.of_node && !client->dev.fwnode)
		i2c_unregister_device(client);
}

void v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client,
			      const char *devname, const char *postfix)
{
+10 −0
Original line number Diff line number Diff line
@@ -211,6 +211,13 @@ unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd);
 */
const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type);

/**
 * v4l2_i2c_subdev_unregister - Unregister a v4l2_subdev
 *
 * @sd: pointer to &struct v4l2_subdev
 */
void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd);

#else

static inline struct v4l2_subdev *
@@ -250,6 +257,9 @@ v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type)
	return NULL;
}

static inline void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd)
{}

#endif

/* ------------------------------------------------------------------------- */