From patchwork Sun May 23 16:23:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12274915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8737BC47080 for ; Sun, 23 May 2021 16:24:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AFEF61205 for ; Sun, 23 May 2021 16:24:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231800AbhEWQZ3 (ORCPT ); Sun, 23 May 2021 12:25:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:57878 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231821AbhEWQZ3 (ORCPT ); Sun, 23 May 2021 12:25:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1F55E6117A; Sun, 23 May 2021 16:24:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621787042; bh=+nVxAJ/PfEMJfyNe2C1fd113hNSpgLW7/UQow6+A4Ew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NJ9jwfj9hBV1a9X8qYUxQJJWftiOCLKBJpkPwPc0M9JgzxN63YvzjOsov5u8T8iy0 J91SfcVu7doUTMFyJhwHcY4xxMHFLvNOlYrDCb+Km9L1gqSQDQe5Xd2OUU7/9qwgqa eYwVvKm5Bs1tUyxtuMOcz4SQURG+5C2D12X24mWd8rxUs5g+qSLHEp5Aa2PzhsSTcQ WBrB5EazEXGsBbrcu1jfqarkkEYFmqYtMxtDGd9fCF6V/Hi1NNfH1u7P8Z2F3UNhwN LadJI/zG5NOkJMHIP11sU8ni9PoZYXykSwUIMYbPdWRb+XjF2aRvsSkOUSLVrRcZTG 8uhYQtiPsl+PQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Andy Shevchenko , Alexandru Ardelean , Jonathan Cameron Subject: [PATCH 1/5] iio: accel: mma9551/mma9553: Drop explicit ACPI match support Date: Sun, 23 May 2021 17:23:11 +0100 Message-Id: <20210523162315.1965869-2-jic23@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210523162315.1965869-1-jic23@kernel.org> References: <20210523162315.1965869-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron The IDs look highly suspicious as they are just the part numbers in capitals, so lets drop these if no one screams. Signed-off-by: Jonathan Cameron Cc: Andy Shevchenko Acked-by: Andy Shevchenko Reviewed-by: Alexandru Ardelean --- drivers/iio/accel/mma9551.c | 21 --------------------- drivers/iio/accel/mma9553.c | 21 --------------------- 2 files changed, 42 deletions(-) diff --git a/drivers/iio/accel/mma9551.c b/drivers/iio/accel/mma9551.c index 4c359fb05480..2b74f67536a3 100644 --- a/drivers/iio/accel/mma9551.c +++ b/drivers/iio/accel/mma9551.c @@ -435,17 +435,6 @@ static int mma9551_gpio_probe(struct iio_dev *indio_dev) return 0; } -static const char *mma9551_match_acpi_device(struct device *dev) -{ - const struct acpi_device_id *id; - - id = acpi_match_device(dev->driver->acpi_match_table, dev); - if (!id) - return NULL; - - return dev_name(dev); -} - static int mma9551_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -464,8 +453,6 @@ static int mma9551_probe(struct i2c_client *client, if (id) name = id->name; - else if (ACPI_HANDLE(&client->dev)) - name = mma9551_match_acpi_device(&client->dev); ret = mma9551_init(data); if (ret < 0) @@ -591,13 +578,6 @@ static const struct dev_pm_ops mma9551_pm_ops = { mma9551_runtime_resume, NULL) }; -static const struct acpi_device_id mma9551_acpi_match[] = { - {"MMA9551", 0}, - {}, -}; - -MODULE_DEVICE_TABLE(acpi, mma9551_acpi_match); - static const struct i2c_device_id mma9551_id[] = { {"mma9551", 0}, {} @@ -608,7 +588,6 @@ MODULE_DEVICE_TABLE(i2c, mma9551_id); static struct i2c_driver mma9551_driver = { .driver = { .name = MMA9551_DRV_NAME, - .acpi_match_table = ACPI_PTR(mma9551_acpi_match), .pm = &mma9551_pm_ops, }, .probe = mma9551_probe, diff --git a/drivers/iio/accel/mma9553.c b/drivers/iio/accel/mma9553.c index ba3ecb3b57dc..32c9a79ebfec 100644 --- a/drivers/iio/accel/mma9553.c +++ b/drivers/iio/accel/mma9553.c @@ -1062,17 +1062,6 @@ static irqreturn_t mma9553_event_handler(int irq, void *private) return IRQ_HANDLED; } -static const char *mma9553_match_acpi_device(struct device *dev) -{ - const struct acpi_device_id *id; - - id = acpi_match_device(dev->driver->acpi_match_table, dev); - if (!id) - return NULL; - - return dev_name(dev); -} - static int mma9553_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1091,8 +1080,6 @@ static int mma9553_probe(struct i2c_client *client, if (id) name = id->name; - else if (ACPI_HANDLE(&client->dev)) - name = mma9553_match_acpi_device(&client->dev); else return -ENOSYS; @@ -1230,13 +1217,6 @@ static const struct dev_pm_ops mma9553_pm_ops = { mma9553_runtime_resume, NULL) }; -static const struct acpi_device_id mma9553_acpi_match[] = { - {"MMA9553", 0}, - {}, -}; - -MODULE_DEVICE_TABLE(acpi, mma9553_acpi_match); - static const struct i2c_device_id mma9553_id[] = { {"mma9553", 0}, {}, @@ -1247,7 +1227,6 @@ MODULE_DEVICE_TABLE(i2c, mma9553_id); static struct i2c_driver mma9553_driver = { .driver = { .name = MMA9553_DRV_NAME, - .acpi_match_table = ACPI_PTR(mma9553_acpi_match), .pm = &mma9553_pm_ops, }, .probe = mma9553_probe, From patchwork Sun May 23 16:23:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12274917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88864C4707A for ; Sun, 23 May 2021 16:24:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67BE761261 for ; Sun, 23 May 2021 16:24:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231828AbhEWQZb (ORCPT ); Sun, 23 May 2021 12:25:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:57888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231821AbhEWQZb (ORCPT ); Sun, 23 May 2021 12:25:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2B235611CC; Sun, 23 May 2021 16:24:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621787044; bh=34Z2gtEINic9myvnviQtqAcZXUsU87y0kk+JCLbCgkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LgwH3M+Z2piUtxARf1hMRO0l9EFJtqaQK27/4KATY2qxM2r8vC+/+GGE73YIuansZ 0LgVEO/Q2oznzC/Zw5qsN7pKhoqjFOHhq8lgo4cAvj2wSBj1NG80P50HTTvPdky1Uv jipOHFw/UdWPpjDOt0l55i2FfknCktIvw+oDpbaNVoBnxhY+PtbwQVT5LdGENRD/ye vAEMr8OzSJM4B2XKjF99/cPZ0JBdWw7aVqdifC78Om19NIUObvBzodFZpu0ScoHE+8 AkOw5UWtUPv0Eu9pgEl+jphKMFdYSgZChTQrz4juQuAzqXoqpbsNLslNqHmOykkHNR goC3caHd9y9KQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Andy Shevchenko , Alexandru Ardelean , Jonathan Cameron Subject: [PATCH 2/5] iio: accel: mma9551/mma9553: Simplify pm logic Date: Sun, 23 May 2021 17:23:12 +0100 Message-Id: <20210523162315.1965869-3-jic23@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210523162315.1965869-1-jic23@kernel.org> References: <20210523162315.1965869-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron I can't see why we shouldn't sleep in the system resume path to allow the device firmware to fully wakeup. Having done that, the runtime system functions are identical (down to an error print) so use pm_runtime_force_suspend() and pm_runtime_force_resume() to reduce repitition. General preference in IIO is now to mark these functions __maybe_unused instead of using ifdefs as it is easy to get them wrong. Here they appear correct, but provide a less than desirable example to copy into other drivers. Signed-off-by: Jonathan Cameron Reviewed-by: Alexandru Ardelean --- drivers/iio/accel/mma9551.c | 37 ++++-------------------------------- drivers/iio/accel/mma9553.c | 38 ++++--------------------------------- 2 files changed, 8 insertions(+), 67 deletions(-) diff --git a/drivers/iio/accel/mma9551.c b/drivers/iio/accel/mma9551.c index 2b74f67536a3..1b4a8b27f14a 100644 --- a/drivers/iio/accel/mma9551.c +++ b/drivers/iio/accel/mma9551.c @@ -510,8 +510,7 @@ static int mma9551_remove(struct i2c_client *client) return 0; } -#ifdef CONFIG_PM -static int mma9551_runtime_suspend(struct device *dev) +static __maybe_unused int mma9551_runtime_suspend(struct device *dev) { struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); struct mma9551_data *data = iio_priv(indio_dev); @@ -522,13 +521,13 @@ static int mma9551_runtime_suspend(struct device *dev) mutex_unlock(&data->mutex); if (ret < 0) { dev_err(&data->client->dev, "powering off device failed\n"); - return -EAGAIN; + return ret; } return 0; } -static int mma9551_runtime_resume(struct device *dev) +static __maybe_unused int mma9551_runtime_resume(struct device *dev) { struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); struct mma9551_data *data = iio_priv(indio_dev); @@ -542,38 +541,10 @@ static int mma9551_runtime_resume(struct device *dev) return 0; } -#endif - -#ifdef CONFIG_PM_SLEEP -static int mma9551_suspend(struct device *dev) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); - struct mma9551_data *data = iio_priv(indio_dev); - int ret; - - mutex_lock(&data->mutex); - ret = mma9551_set_device_state(data->client, false); - mutex_unlock(&data->mutex); - - return ret; -} - -static int mma9551_resume(struct device *dev) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); - struct mma9551_data *data = iio_priv(indio_dev); - int ret; - mutex_lock(&data->mutex); - ret = mma9551_set_device_state(data->client, true); - mutex_unlock(&data->mutex); - - return ret; -} -#endif static const struct dev_pm_ops mma9551_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(mma9551_suspend, mma9551_resume) + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) SET_RUNTIME_PM_OPS(mma9551_runtime_suspend, mma9551_runtime_resume, NULL) }; diff --git a/drivers/iio/accel/mma9553.c b/drivers/iio/accel/mma9553.c index 32c9a79ebfec..dc2a3316c1a3 100644 --- a/drivers/iio/accel/mma9553.c +++ b/drivers/iio/accel/mma9553.c @@ -1149,8 +1149,7 @@ static int mma9553_remove(struct i2c_client *client) return 0; } -#ifdef CONFIG_PM -static int mma9553_runtime_suspend(struct device *dev) +static __maybe_unused int mma9553_runtime_suspend(struct device *dev) { struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); struct mma9553_data *data = iio_priv(indio_dev); @@ -1161,13 +1160,13 @@ static int mma9553_runtime_suspend(struct device *dev) mutex_unlock(&data->mutex); if (ret < 0) { dev_err(&data->client->dev, "powering off device failed\n"); - return -EAGAIN; + return ret; } return 0; } -static int mma9553_runtime_resume(struct device *dev) +static __maybe_unused int mma9553_runtime_resume(struct device *dev) { struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); struct mma9553_data *data = iio_priv(indio_dev); @@ -1181,38 +1180,9 @@ static int mma9553_runtime_resume(struct device *dev) return 0; } -#endif - -#ifdef CONFIG_PM_SLEEP -static int mma9553_suspend(struct device *dev) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); - struct mma9553_data *data = iio_priv(indio_dev); - int ret; - - mutex_lock(&data->mutex); - ret = mma9551_set_device_state(data->client, false); - mutex_unlock(&data->mutex); - - return ret; -} - -static int mma9553_resume(struct device *dev) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); - struct mma9553_data *data = iio_priv(indio_dev); - int ret; - - mutex_lock(&data->mutex); - ret = mma9551_set_device_state(data->client, true); - mutex_unlock(&data->mutex); - - return ret; -} -#endif static const struct dev_pm_ops mma9553_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(mma9553_suspend, mma9553_resume) + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) SET_RUNTIME_PM_OPS(mma9553_runtime_suspend, mma9553_runtime_resume, NULL) }; From patchwork Sun May 23 16:23:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12274919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A5DDC4707A for ; Sun, 23 May 2021 16:24:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F65D61263 for ; Sun, 23 May 2021 16:24:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231829AbhEWQZd (ORCPT ); Sun, 23 May 2021 12:25:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:57900 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231821AbhEWQZc (ORCPT ); Sun, 23 May 2021 12:25:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1C73D610A0; Sun, 23 May 2021 16:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621787046; bh=d5O9xGV535ammETxSNzdmMqaH6P52vOlfmbm7tfvxes=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y+1Jm8ezqT4fh9Qw0hHsS/l73hJATjKSHK2c7p0FSZCd09It3iLfB+eIdo/Mn5XCQ zxwm4UJsCPVwQ6xzE0FYC5vbtOG67qNrLYaZlBXGEhIqirA89GGvI06miyqArwxTDB saQ+2UQ08n9+okB9a3+dmuczfm+V315brrsOaud6ZYm/8IHSfQPIHVm6MS9jAlUgKg lrAqlMSkGIobeuSobcXCyMdeROhv92gIVM7pIJ9RAnEh5mj5yXpZDcsJW1f5CNkkFG x25I0jwCiuWGoIJk0P+lQYsPtnQceqyLrnNE4eXCdfNN+J028RoUbuAeh+mGhdPMyd fxJ2YTbn4xJ/w== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Andy Shevchenko , Alexandru Ardelean , Jonathan Cameron Subject: [PATCH 3/5] iio: accel: mma9551: Add support to get irqs directly from fwnode Date: Sun, 23 May 2021 17:23:13 +0100 Message-Id: <20210523162315.1965869-4-jic23@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210523162315.1965869-1-jic23@kernel.org> References: <20210523162315.1965869-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron The driver previous supported using GPIO requests to retrieve multiple interrupt lines. As existing firmware may be using this method, we need to continue to support it. However, that doesn't stop us also supporting just getting irqs directly. The handling of irqflags has to take into account the fact that using a GPIO method to identify the interrupt does not convey direction of the trigger that fwnode_irq_get() will. So we need to set the IRQF_TRIGGER_RISING in that path but not otherwise, where it will cause an issue if we reprobe the driver after removal. Signed-off-by: Jonathan Cameron --- drivers/iio/accel/mma9551.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/iio/accel/mma9551.c b/drivers/iio/accel/mma9551.c index 1b4a8b27f14a..a0bb4ccdbec7 100644 --- a/drivers/iio/accel/mma9551.c +++ b/drivers/iio/accel/mma9551.c @@ -406,30 +406,37 @@ static int mma9551_gpio_probe(struct iio_dev *indio_dev) int i, ret; struct mma9551_data *data = iio_priv(indio_dev); struct device *dev = &data->client->dev; + unsigned long irqflags = IRQF_ONESHOT; for (i = 0; i < MMA9551_GPIO_COUNT; i++) { - gpio = devm_gpiod_get_index(dev, NULL, i, GPIOD_IN); - if (IS_ERR(gpio)) { - dev_err(dev, "acpi gpio get index failed\n"); - return PTR_ERR(gpio); - } - - ret = gpiod_to_irq(gpio); - if (ret < 0) + /* GPIO provided for backwards compatibility reasons */ + ret = fwnode_irq_get(dev_fwnode(dev), i); + if (ret == -EPROBE_DEFER) return ret; + /* fwnode_irq_get() returns 0 for not present on OF, and -EINVAL for ACPI */ + if (ret == 0 || ret == -EINVAL) { + gpio = devm_gpiod_get_index(dev, NULL, i, GPIOD_IN); + if (IS_ERR(gpio)) { + dev_err(dev, "gpio get index failed\n"); + return PTR_ERR(gpio); + } + + ret = gpiod_to_irq(gpio); + if (ret < 0) + return ret; + /* GPIO interrupt does npt have a specified direction */ + irqflags |= IRQF_TRIGGER_RISING; + } data->irqs[i] = ret; ret = devm_request_threaded_irq(dev, data->irqs[i], - NULL, mma9551_event_handler, - IRQF_TRIGGER_RISING | IRQF_ONESHOT, - MMA9551_IRQ_NAME, indio_dev); + NULL, mma9551_event_handler, + irqflags, + MMA9551_IRQ_NAME, indio_dev); if (ret < 0) { dev_err(dev, "request irq %d failed\n", data->irqs[i]); return ret; } - - dev_dbg(dev, "gpio resource, no:%d irq:%d\n", - desc_to_gpio(gpio), data->irqs[i]); } return 0; From patchwork Sun May 23 16:23:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12274921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10F77C47081 for ; Sun, 23 May 2021 16:24:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4BAE61261 for ; Sun, 23 May 2021 16:24:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231835AbhEWQZe (ORCPT ); Sun, 23 May 2021 12:25:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:57910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231821AbhEWQZe (ORCPT ); Sun, 23 May 2021 12:25:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D2E6C61205; Sun, 23 May 2021 16:24:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621787048; bh=2ioaM8MTlzGibbmclLPnYtdsACW9d+l3HnWE17v65oQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fnCzylIDr796dvfcRJ5EJ3WTWClqCjW5qm5eQSzjtzFcPh7VFaL1fsQITXNOD9ZKK FTbFOAT1Iu2AOdFqwUV5hS/Jq+XCcWISDKU7ZUgFsfP/WnBnM/cx7TQkRQpZ8p8uVx vcv0zvmnlNQRb9minVmeSratXkh56RjE+ZYWyDzMHYfxoLLYKySKlAxszeVXF9g5Wi vbV2plUP9+n6XdEt9A5pOGuMvJj5dgHT2TflnpWGatyz1Kki3As4GwkHYyugynDfLW dh/goU2J9t+PNQh4eBBXHbZAqmefY8UeRo9TCcDenzbRHVJXtcMYPtO+YW279lTLos qrrNinoiFUC9A== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Andy Shevchenko , Alexandru Ardelean , Jonathan Cameron Subject: [PATCH 4/5] iio: accel: mma9551: Use devm managed functions to tidy up probe() Date: Sun, 23 May 2021 17:23:14 +0100 Message-Id: <20210523162315.1965869-5-jic23@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210523162315.1965869-1-jic23@kernel.org> References: <20210523162315.1965869-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron The error handling in here left runtime pm enabled, and didn't do the same steps as occurred in remove. Moving over to fully devm_ managed makes it harder to get this stuff wrong, so let's do that. Signed-off-by: Jonathan Cameron Reviewed-by: Alexandru Ardelean --- drivers/iio/accel/mma9551.c | 71 ++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/drivers/iio/accel/mma9551.c b/drivers/iio/accel/mma9551.c index a0bb4ccdbec7..f539772f8295 100644 --- a/drivers/iio/accel/mma9551.c +++ b/drivers/iio/accel/mma9551.c @@ -389,6 +389,15 @@ static irqreturn_t mma9551_event_handler(int irq, void *private) return IRQ_HANDLED; } +static void mma9551_disable_cb(void *_data) +{ + struct mma9551_data *data = _data; + + mutex_lock(&data->mutex); + mma9551_set_device_state(data->client, false); + mutex_unlock(&data->mutex); +} + static int mma9551_init(struct mma9551_data *data) { int ret; @@ -397,7 +406,12 @@ static int mma9551_init(struct mma9551_data *data) if (ret) return ret; - return mma9551_set_device_state(data->client, true); + ret = mma9551_set_device_state(data->client, true); + if (ret) + return ret; + + return devm_add_action_or_reset(&data->client->dev, mma9551_disable_cb, + data); } static int mma9551_gpio_probe(struct iio_dev *indio_dev) @@ -442,6 +456,16 @@ static int mma9551_gpio_probe(struct iio_dev *indio_dev) return 0; } +static void mma9551_rpm_susp(void *d) +{ + pm_runtime_set_suspended(d); +} + +static void mma9551_rpm_disable(void *d) +{ + pm_runtime_disable(d); +} + static int mma9551_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -475,46 +499,28 @@ static int mma9551_probe(struct i2c_client *client, ret = mma9551_gpio_probe(indio_dev); if (ret < 0) - goto out_poweroff; + return ret; ret = pm_runtime_set_active(&client->dev); if (ret < 0) - goto out_poweroff; + return ret; + + ret = devm_add_action_or_reset(&client->dev, mma9551_rpm_susp, + &client->dev); + if (ret) + return ret; pm_runtime_enable(&client->dev); + ret = devm_add_action_or_reset(&client->dev, mma9551_rpm_disable, + &client->dev); + if (ret) + return ret; + pm_runtime_set_autosuspend_delay(&client->dev, MMA9551_AUTO_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(&client->dev); - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(&client->dev, "unable to register iio device\n"); - goto out_poweroff; - } - - return 0; - -out_poweroff: - mma9551_set_device_state(client, false); - - return ret; -} - -static int mma9551_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - struct mma9551_data *data = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - - pm_runtime_disable(&client->dev); - pm_runtime_set_suspended(&client->dev); - - mutex_lock(&data->mutex); - mma9551_set_device_state(data->client, false); - mutex_unlock(&data->mutex); - - return 0; + return devm_iio_device_register(&client->dev, indio_dev); } static __maybe_unused int mma9551_runtime_suspend(struct device *dev) @@ -569,7 +575,6 @@ static struct i2c_driver mma9551_driver = { .pm = &mma9551_pm_ops, }, .probe = mma9551_probe, - .remove = mma9551_remove, .id_table = mma9551_id, }; From patchwork Sun May 23 16:23:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12274923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D264AC47080 for ; Sun, 23 May 2021 16:24:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3E06610A0 for ; Sun, 23 May 2021 16:24:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231842AbhEWQZg (ORCPT ); Sun, 23 May 2021 12:25:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:57924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231821AbhEWQZg (ORCPT ); Sun, 23 May 2021 12:25:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AAC666117A; Sun, 23 May 2021 16:24:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621787049; bh=Z0P4r1dCUgEDfsa4CtP560vDgjEiLt5/rkR+lk+HPYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NF/2GOUBFK8Mq86YxlR2m1l9iJeoaHEbUuBgPQhmS+QqJTF5HvvuIX2DZthlcEjpg T490Z+06r9jF90mO423skhGa5V7t/90k6cFexjTgL+TFAQwtl4cY/KgbC1ylMZ8vGb tkkt1YgsQX9YJYkQZGDhYw1SdvR9QVNCXAzs4SlwWQu8Oxd3suOuYKd5V1JWHtgsOr YHyomTUnpDm3hWdBQQIX6zhMYevEzao6jQ3nQ/vrk3/4AZ5D2NkPAEkoQJjc2a17CO GPNq3uzIkw8iE0om9yCtqTo2q03hN9t8+MZZouRe9OXLyIdrRD8Spov/qUMKDC6/x3 +cbVGAhFg6cXg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Andy Shevchenko , Alexandru Ardelean , Jonathan Cameron Subject: [PATCH 5/5] iio: accel: mma9553: Use devm managed functions to tidy up probe() Date: Sun, 23 May 2021 17:23:15 +0100 Message-Id: <20210523162315.1965869-6-jic23@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210523162315.1965869-1-jic23@kernel.org> References: <20210523162315.1965869-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron The error handling in here left runtime pm enabled, and didn't do the same steps as occurred in remove. Moving over to fully devm_ managed makes it harder to get this stuff wrong, so let's do that. Signed-off-by: Jonathan Cameron Reviewed-by: Alexandru Ardelean --- drivers/iio/accel/mma9553.c | 70 ++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/drivers/iio/accel/mma9553.c b/drivers/iio/accel/mma9553.c index dc2a3316c1a3..14a9d5fedc06 100644 --- a/drivers/iio/accel/mma9553.c +++ b/drivers/iio/accel/mma9553.c @@ -375,6 +375,15 @@ static int mma9553_conf_gpio(struct mma9553_data *data) return 0; } +static void mma9553_disable_cb(void *_data) +{ + struct mma9553_data *data = _data; + + mutex_lock(&data->mutex); + mma9551_set_device_state(data->client, false); + mutex_unlock(&data->mutex); +} + static int mma9553_init(struct mma9553_data *data) { int ret; @@ -430,7 +439,11 @@ static int mma9553_init(struct mma9553_data *data) return ret; } - return mma9551_set_device_state(data->client, true); + ret = mma9551_set_device_state(data->client, true); + if (ret) + return ret; + + return devm_add_action_or_reset(&data->client->dev, mma9553_disable_cb, data); } static int mma9553_read_status_word(struct mma9553_data *data, u16 reg, @@ -1062,6 +1075,16 @@ static irqreturn_t mma9553_event_handler(int irq, void *private) return IRQ_HANDLED; } +static void mma9553_rpm_set_susp(void *d) +{ + pm_runtime_set_suspended(d); +} + +static void mma9553_rpm_disable(void *d) +{ + pm_runtime_disable(d); +} + static int mma9553_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1105,48 +1128,30 @@ static int mma9553_probe(struct i2c_client *client, if (ret < 0) { dev_err(&client->dev, "request irq %d failed\n", client->irq); - goto out_poweroff; + return ret; } } ret = pm_runtime_set_active(&client->dev); if (ret < 0) - goto out_poweroff; + return ret; + + ret = devm_add_action_or_reset(&client->dev, mma9553_rpm_set_susp, + &client->dev); + if (ret) + return ret; pm_runtime_enable(&client->dev); + ret = devm_add_action_or_reset(&client->dev, mma9553_rpm_disable, + &client->dev); + if (ret) + return ret; + pm_runtime_set_autosuspend_delay(&client->dev, MMA9551_AUTO_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(&client->dev); - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(&client->dev, "unable to register iio device\n"); - goto out_poweroff; - } - - dev_dbg(&indio_dev->dev, "Registered device %s\n", name); - return 0; - -out_poweroff: - mma9551_set_device_state(client, false); - return ret; -} - -static int mma9553_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - struct mma9553_data *data = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - - pm_runtime_disable(&client->dev); - pm_runtime_set_suspended(&client->dev); - - mutex_lock(&data->mutex); - mma9551_set_device_state(data->client, false); - mutex_unlock(&data->mutex); - - return 0; + return devm_iio_device_register(&client->dev, indio_dev); } static __maybe_unused int mma9553_runtime_suspend(struct device *dev) @@ -1200,7 +1205,6 @@ static struct i2c_driver mma9553_driver = { .pm = &mma9553_pm_ops, }, .probe = mma9553_probe, - .remove = mma9553_remove, .id_table = mma9553_id, };