diff options
author | Ezequiel Garcia <ezequiel@collabora.com> | 2019-08-15 12:48:05 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab+samsung@kernel.org> | 2019-08-26 09:52:06 -0400 |
commit | 51ff392c280733aa9e6bd47b3f5e83e32bfdf16a (patch) | |
tree | b61a41e79f08d1a3a1fe26c0d5946f5faccbfe03 | |
parent | a9cff393c1d78ecbbc33e6196e79bb05ccb4a709 (diff) |
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: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
[hverkuil-cisco@xs4all.nl: fix checkpatch warning]
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
-rw-r--r-- | drivers/media/v4l2-core/v4l2-device.c | 25 | ||||
-rw-r--r-- | drivers/media/v4l2-core/v4l2-i2c.c | 20 | ||||
-rw-r--r-- | 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 @@ | |||
9 | #include <linux/types.h> | 9 | #include <linux/types.h> |
10 | #include <linux/ioctl.h> | 10 | #include <linux/ioctl.h> |
11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
12 | #include <linux/i2c.h> | ||
13 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
14 | #include <linux/videodev2.h> | 13 | #include <linux/videodev2.h> |
15 | #include <media/v4l2-device.h> | 14 | #include <media/v4l2-device.h> |
@@ -99,28 +98,8 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev) | |||
99 | /* Unregister subdevs */ | 98 | /* Unregister subdevs */ |
100 | list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) { | 99 | list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) { |
101 | v4l2_device_unregister_subdev(sd); | 100 | v4l2_device_unregister_subdev(sd); |
102 | #if IS_ENABLED(CONFIG_I2C) | 101 | if (sd->flags & V4L2_SUBDEV_FL_IS_I2C) |
103 | if (sd->flags & V4L2_SUBDEV_FL_IS_I2C) { | 102 | v4l2_i2c_subdev_unregister(sd); |
104 | struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
105 | |||
106 | /* | ||
107 | * We need to unregister the i2c client | ||
108 | * explicitly. We cannot rely on | ||
109 | * i2c_del_adapter to always unregister | ||
110 | * clients for us, since if the i2c bus is a | ||
111 | * platform bus, then it is never deleted. | ||
112 | * | ||
113 | * Device tree or ACPI based devices must not | ||
114 | * be unregistered as they have not been | ||
115 | * registered by us, and would not be | ||
116 | * re-created by just probing the V4L2 driver. | ||
117 | */ | ||
118 | if (client && | ||
119 | !client->dev.of_node && !client->dev.fwnode) | ||
120 | i2c_unregister_device(client); | ||
121 | continue; | ||
122 | } | ||
123 | #endif | ||
124 | else if (sd->flags & V4L2_SUBDEV_FL_IS_SPI) | 103 | else if (sd->flags & V4L2_SUBDEV_FL_IS_SPI) |
125 | v4l2_spi_subdev_unregister(sd); | 104 | v4l2_spi_subdev_unregister(sd); |
126 | } | 105 | } |
diff --git a/drivers/media/v4l2-core/v4l2-i2c.c b/drivers/media/v4l2-core/v4l2-i2c.c index f393dd4f1c00..a26d48f23a2d 100644 --- a/drivers/media/v4l2-core/v4l2-i2c.c +++ b/drivers/media/v4l2-core/v4l2-i2c.c | |||
@@ -8,6 +8,26 @@ | |||
8 | #include <media/v4l2-common.h> | 8 | #include <media/v4l2-common.h> |
9 | #include <media/v4l2-device.h> | 9 | #include <media/v4l2-device.h> |
10 | 10 | ||
11 | void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd) | ||
12 | { | ||
13 | struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
14 | |||
15 | /* | ||
16 | * We need to unregister the i2c client | ||
17 | * explicitly. We cannot rely on | ||
18 | * i2c_del_adapter to always unregister | ||
19 | * clients for us, since if the i2c bus is a | ||
20 | * platform bus, then it is never deleted. | ||
21 | * | ||
22 | * Device tree or ACPI based devices must not | ||
23 | * be unregistered as they have not been | ||
24 | * registered by us, and would not be | ||
25 | * re-created by just probing the V4L2 driver. | ||
26 | */ | ||
27 | if (client && !client->dev.of_node && !client->dev.fwnode) | ||
28 | i2c_unregister_device(client); | ||
29 | } | ||
30 | |||
11 | void v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client, | 31 | void v4l2_i2c_subdev_set_name(struct v4l2_subdev *sd, struct i2c_client *client, |
12 | const char *devname, const char *postfix) | 32 | const char *devname, const char *postfix) |
13 | { | 33 | { |
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); | |||
211 | */ | 211 | */ |
212 | const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type); | 212 | const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type); |
213 | 213 | ||
214 | /** | ||
215 | * v4l2_i2c_subdev_unregister - Unregister a v4l2_subdev | ||
216 | * | ||
217 | * @sd: pointer to &struct v4l2_subdev | ||
218 | */ | ||
219 | void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd); | ||
220 | |||
214 | #else | 221 | #else |
215 | 222 | ||
216 | static inline struct v4l2_subdev * | 223 | static inline struct v4l2_subdev * |
@@ -250,6 +257,9 @@ v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type) | |||
250 | return NULL; | 257 | return NULL; |
251 | } | 258 | } |
252 | 259 | ||
260 | static inline void v4l2_i2c_subdev_unregister(struct v4l2_subdev *sd) | ||
261 | {} | ||
262 | |||
253 | #endif | 263 | #endif |
254 | 264 | ||
255 | /* ------------------------------------------------------------------------- */ | 265 | /* ------------------------------------------------------------------------- */ |