From patchwork Thu Aug 15 16:48:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 11096079 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C7BFF1395 for ; Thu, 15 Aug 2019 16:48:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B90E41FFBD for ; Thu, 15 Aug 2019 16:48:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACFB4285C8; Thu, 15 Aug 2019 16:48:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46DC31FFBD for ; Thu, 15 Aug 2019 16:48:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730150AbfHOQsZ (ORCPT ); Thu, 15 Aug 2019 12:48:25 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:38918 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729579AbfHOQsZ (ORCPT ); Thu, 15 Aug 2019 12:48:25 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id F386228CF71 From: Ezequiel Garcia To: linux-media@vger.kernel.org Cc: kernel@collabora.com, Ezequiel Garcia Subject: [PATCH v2 5/6] media: v4l2-core: introduce a helper to unregister a i2c subdev Date: Thu, 15 Aug 2019 13:48:05 -0300 Message-Id: <20190815164806.19248-6-ezequiel@collabora.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190815164806.19248-1-ezequiel@collabora.com> References: <20190815164806.19248-1-ezequiel@collabora.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce a new video4linux2 i2c helper, to unregister a subdev. This allows to get rid of yet another ifdef. Signed-off-by: Ezequiel Garcia --- Changes v2: * None. --- 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 #include #include -#include #include #include #include @@ -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 #include +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 /* ------------------------------------------------------------------------- */