From: Ezequiel Garcia <ezequiel@collabora.com>
To: Hans Verkuil <hans.verkuil@cisco.com>
Cc: kernel@collabora.com, linux-media@vger.kernel.org,
Ezequiel Garcia <ezequiel@collabora.com>
Subject: [PATCH 6/6] media: v4l2-core: introduce a helper to unregister a I2C subdev
Date: Mon, 15 Jul 2019 18:06:48 -0300 [thread overview]
Message-ID: <20190715210649.31681-8-ezequiel@collabora.com> (raw)
In-Reply-To: <20190715210649.31681-1-ezequiel@collabora.com>
Introduce a new video4linux2 I2C helper, to unregister a subdev.
This allows to get rid of yet another ifdefs.
Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
---
drivers/media/v4l2-core/v4l2-device.c | 25 ++-----------------------
drivers/media/v4l2-core/v4l2-i2c.c | 20 ++++++++++++++++++++
include/media/v4l2-common.h | 10 ++++++++++
3 files changed, 32 insertions(+), 23 deletions(-)
diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
index c2811238996f..63d6b147b21e 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -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);
}
diff --git a/drivers/media/v4l2-core/v4l2-i2c.c b/drivers/media/v4l2-core/v4l2-i2c.c
index f393dd4f1c00..3d7a3081ec0b 100644
--- a/drivers/media/v4l2-core/v4l2-i2c.c
+++ b/drivers/media/v4l2-core/v4l2-i2c.c
@@ -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)
{
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index e2878654d043..c070d8ae11e5 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -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
/* ------------------------------------------------------------------------- */
--
2.22.0
next prev parent reply other threads:[~2019-07-15 21:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-15 21:06 [PATCH 0/6] V4L2 core I2C/SPI code cleanup Ezequiel Garcia
2019-07-15 21:06 ` [PATCH 1/6] media: v4l2-core: Cleanup Makefile Ezequiel Garcia
2019-07-15 21:06 ` [PATCH 2/6] media: v4l2-core: Module re-organization Ezequiel Garcia
2019-07-25 16:31 ` Mauro Carvalho Chehab
2019-07-25 16:41 ` Ezequiel Garcia
2019-07-25 17:03 ` Mauro Carvalho Chehab
2019-07-25 17:07 ` Ezequiel Garcia
2019-07-15 21:06 ` [PATCH 3/6] media: v4l2-core: move spi helpers out of v4l2-common.c Ezequiel Garcia
2019-07-15 21:06 ` [PATCH 4/6] media: v4l2-core: move i2c " Ezequiel Garcia
2019-07-15 21:06 ` [PATCH 5/6] media: v4l2-core: introduce a helper to unregister a SPI subdev Ezequiel Garcia
2019-07-15 21:06 ` [PATCH 5/6] media: v4l2-core: introduce an unregister spi subdev helper Ezequiel Garcia
2019-07-15 21:06 ` Ezequiel Garcia [this message]
2019-07-15 21:06 ` [PATCH 6/6] media: v4l2-core: introduce unregister subdev i2c helper Ezequiel Garcia
2019-07-25 15:06 ` [PATCH 0/6] V4L2 core I2C/SPI code cleanup Hans Verkuil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190715210649.31681-8-ezequiel@collabora.com \
--to=ezequiel@collabora.com \
--cc=hans.verkuil@cisco.com \
--cc=kernel@collabora.com \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).