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>
This commit is contained in:
Ezequiel Garcia 2019-08-15 13:48:05 -03:00 committed by Mauro Carvalho Chehab
parent a9cff393c1
commit 51ff392c28
3 changed files with 32 additions and 23 deletions

View file

@ -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)
{