From patchwork Tue Nov 9 13:10:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kepplinger X-Patchwork-Id: 12610735 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B7A2C433F5 for ; Tue, 9 Nov 2021 13:10:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 151B661130 for ; Tue, 9 Nov 2021 13:10:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233997AbhKINNe (ORCPT ); Tue, 9 Nov 2021 08:13:34 -0500 Received: from comms.puri.sm ([159.203.221.185]:47342 "EHLO comms.puri.sm" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbhKINNd (ORCPT ); Tue, 9 Nov 2021 08:13:33 -0500 Received: from localhost (localhost [127.0.0.1]) by comms.puri.sm (Postfix) with ESMTP id 1B7C1E03CC; Tue, 9 Nov 2021 05:10:48 -0800 (PST) Received: from comms.puri.sm ([127.0.0.1]) by localhost (comms.puri.sm [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9rq4FAoVgiPD; Tue, 9 Nov 2021 05:10:47 -0800 (PST) From: Martin Kepplinger To: sakari.ailus@linux.intel.com, mchehab@kernel.org Cc: linux-media@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@puri.sm, Martin Kepplinger Subject: [PATCH v1 1/2] media: i2c: hi846: check return value of regulator_bulk_disable() Date: Tue, 9 Nov 2021 14:10:12 +0100 Message-Id: <20211109131013.2684058-2-martin.kepplinger@puri.sm> In-Reply-To: <20211109131013.2684058-1-martin.kepplinger@puri.sm> References: <20211109131013.2684058-1-martin.kepplinger@puri.sm> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org regulator_bulk_disable can fail and thus suspend() can. Handle that error gracefully. Signed-off-by: Martin Kepplinger --- drivers/media/i2c/hi846.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c index 4b94bdf2e5cb..ed55c3894284 100644 --- a/drivers/media/i2c/hi846.c +++ b/drivers/media/i2c/hi846.c @@ -1858,7 +1858,7 @@ static int hi846_power_on(struct hi846 *hi846) return ret; } -static void hi846_power_off(struct hi846 *hi846) +static int hi846_power_off(struct hi846 *hi846) { if (hi846->rst_gpio) gpiod_set_value_cansleep(hi846->rst_gpio, 1); @@ -1867,7 +1867,7 @@ static void hi846_power_off(struct hi846 *hi846) gpiod_set_value_cansleep(hi846->shutdown_gpio, 1); clk_disable_unprepare(hi846->clock); - regulator_bulk_disable(HI846_NUM_SUPPLIES, hi846->supplies); + return regulator_bulk_disable(HI846_NUM_SUPPLIES, hi846->supplies); } static int __maybe_unused hi846_suspend(struct device *dev) @@ -1879,9 +1879,7 @@ static int __maybe_unused hi846_suspend(struct device *dev) if (hi846->streaming) hi846_stop_streaming(hi846); - hi846_power_off(hi846); - - return 0; + return hi846_power_off(hi846); } static int __maybe_unused hi846_resume(struct device *dev) From patchwork Tue Nov 9 13:10:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kepplinger X-Patchwork-Id: 12610737 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFB0EC433FE for ; Tue, 9 Nov 2021 13:10:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90C8D61178 for ; Tue, 9 Nov 2021 13:10:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229998AbhKINNh (ORCPT ); Tue, 9 Nov 2021 08:13:37 -0500 Received: from comms.puri.sm ([159.203.221.185]:47352 "EHLO comms.puri.sm" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234488AbhKINNg (ORCPT ); Tue, 9 Nov 2021 08:13:36 -0500 Received: from localhost (localhost [127.0.0.1]) by comms.puri.sm (Postfix) with ESMTP id 47ECAE0304; Tue, 9 Nov 2021 05:10:50 -0800 (PST) Received: from comms.puri.sm ([127.0.0.1]) by localhost (comms.puri.sm [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LPH1gB_nCPrf; Tue, 9 Nov 2021 05:10:49 -0800 (PST) From: Martin Kepplinger To: sakari.ailus@linux.intel.com, mchehab@kernel.org Cc: linux-media@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@puri.sm, Martin Kepplinger Subject: [PATCH v1 2/2] media: i2c: hi846: use pm_runtime_force_suspend/resume for system suspend Date: Tue, 9 Nov 2021 14:10:13 +0100 Message-Id: <20211109131013.2684058-3-martin.kepplinger@puri.sm> In-Reply-To: <20211109131013.2684058-1-martin.kepplinger@puri.sm> References: <20211109131013.2684058-1-martin.kepplinger@puri.sm> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In cases like this when controlling regulators and clocks the suspend() and resume() functions are meant to be called balanced toggling the behaviour. It's wrong to use the same suspend function for runtime and system suspend in this case and leads to errors like [ 77.718890] Failed to disable vddd: -EIO Use pm_runtime_force_* helpers in order to support system suspend properly when runtime pm is already implemented and fix this. Signed-off-by: Martin Kepplinger --- drivers/media/i2c/hi846.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c index ed55c3894284..9bb96754a091 100644 --- a/drivers/media/i2c/hi846.c +++ b/drivers/media/i2c/hi846.c @@ -2418,7 +2418,11 @@ static int hi846_remove(struct i2c_client *client) return 0; } -static UNIVERSAL_DEV_PM_OPS(hi846_pm_ops, hi846_suspend, hi846_resume, NULL); +static const struct dev_pm_ops hi846_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) + SET_RUNTIME_PM_OPS(hi846_suspend, hi846_resume, NULL) +}; static const struct of_device_id hi846_of_match[] = { { .compatible = "hynix,hi846", },