From patchwork Fri Nov 10 10:20:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 163836 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b129:0:b0:403:3b70:6f57 with SMTP id q9csp1283945vqs; Fri, 10 Nov 2023 09:58:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfBKWmbnjgk4TYUc+T1+9Wrke+SVUj/ybZ8ObHHN7FXFYQO6Gr2UsAvt6KQFwZrmxKFM2P X-Received: by 2002:a05:6e02:1bc9:b0:357:fb77:63bf with SMTP id x9-20020a056e021bc900b00357fb7763bfmr80316ilv.24.1699639107306; Fri, 10 Nov 2023 09:58:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699639107; cv=none; d=google.com; s=arc-20160816; b=MZpm7Gn1aW09xCWstH5fkzpObbmoHRVIvbJnlbAG/LKBJ8Kp7PSFPhj7a9PPJGjqG4 5MdZW8jmQO4f0cp5fv33uKKSZNLGht3hRTop6q2spVIkdVqm9+C4F8CZjwt4YcE4nJcj BudZC2ekTjvOfadhJqIhV6QWwyT/7EzzSx3oO7l5pkyE26lgnOq5tL6LgJZGsqQ30tAy lQ8SgxivfL5P0MCuOuqn7AMk2Sc3Cr6Rg15X0Gi+haW4GIh6yXQHnBuhy/qv6N5rSMji Ljkdv/LcUD+uVukArhoXAedq++O56f1+dI6HsCmriE/7Io2isU6tsJN6W+SaWR1aSVSo PsBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=s+EHE1tSh9TUGp4Mr+oOFz1R80eazcuwhmi64rmgAyg=; fh=vnAlJkJLYOcvWI3xg4kglPjlF5P/QRjAU8F0zFAhFi8=; b=F/T6J4mdt9olVlK2CIpCSb+te31XFvoMai4tb0N6wr9lefC6a16VIdNXzDEagoxV7n cHB5IDCg2LJYiKCmsN9jJzcrbI2kjLSfnAfSLYyMY2Ttb43jFRVsJVyqrlgtUVsRaibr 5F/fSw5Zzi1wm/X6BT7Oax5RAU85DYDTqxnb6nqhKl+GI0bBsPO7W6mxxYhTw6Tnpi1u RLIHufKaIdnMm4T4KQ+3EqTbzruGiBpQvaiChJr1QyStRM65z0NII1bn8E6z6GFii4pt wG72z1dBFZHjJIxngFjWU62MO+UOSyaytUJ760+n352C0tciEkoPbdWyUTJgxILEgA1e L6oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qfmogPGS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c67-20020a633546000000b005895c80c902si9449696pga.438.2023.11.10.09.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Nov 2023 09:58:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qfmogPGS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4EBA283C1E2E; Fri, 10 Nov 2023 09:58:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235537AbjKJR56 (ORCPT + 30 others); Fri, 10 Nov 2023 12:57:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235701AbjKJR4F (ORCPT ); Fri, 10 Nov 2023 12:56:05 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EE3028122 for ; Fri, 10 Nov 2023 02:21:12 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5afa071d100so37642587b3.1 for ; Fri, 10 Nov 2023 02:21:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699611671; x=1700216471; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=s+EHE1tSh9TUGp4Mr+oOFz1R80eazcuwhmi64rmgAyg=; b=qfmogPGSjMtD2g/cQArtmPJ3hUBZMsIXAnqRFsUaLN1YIYqmcpD/etoyFu8Sdu+vTS 5o6TXkl1FSJ3CEBfrPSRyuMgT4bd/+b6h8ZuRcc2Oj1oqMdDNugCXf3b0Z2zrV8nOeCE VcUq1vfbfIa7SmR/ssWgl6qD7PWl29sogtfz77Kx6FO7yPuqoCuQZ6OrffOd+p+qSLMQ 7sTDX7rSRWnIxBLklmyLuJ1EzJPG6KzidKbQGWk6WBtsJFiXQw42EpALtBo92Zf+SbkS uTFWUiGJ68Uk6d0ICa+UJpCvHDYMVJ74Uo4x1WV/yPc4Xv3U2vuwykVR6U2/YfbHc2FL k9Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699611671; x=1700216471; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=s+EHE1tSh9TUGp4Mr+oOFz1R80eazcuwhmi64rmgAyg=; b=QKzv9zPaceXN9PD3zpwbtmYlI7ubxWZlNr+yA1hoDogluhKdWrCbGpBDB7NQnHO+tK J60mq+oR8zCDedZ0+ltKdojjqIuSuvuCeaBuY8sJLjz89EVmX+auHcSjG7/uTLHN1DV5 vnIuxbQZQbjTld1UqNAd3X68j/5h4AZ5KvuOPW2ap02ZGyiRhmLluAKAlxdzfax4XOjL DHAtKF20dXAslOFDBNrVW2MHZelv4zarynJwSM7YgX26riJg+MsoqWnjBWsK4KmMFe+Q YALH+s3/o7ACn6+6/pcqBDbs8xULvh8l0WM+0WVCzWMgHwAOGfSG2GFbqsgSCxmx+WeR hzqQ== X-Gm-Message-State: AOJu0Ywwu70qIhMGB/teiHD+bQm/q87G5ywhnO8oCdV1ZQKOIG4SgeQw Kq84arevK+ojFyznaHlFgrc5BXELKZwNxw== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a25:9805:0:b0:da0:ca55:3efb with SMTP id a5-20020a259805000000b00da0ca553efbmr206282ybo.11.1699611671409; Fri, 10 Nov 2023 02:21:11 -0800 (PST) Date: Fri, 10 Nov 2023 10:20:54 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231110102054.1393570-1-joychakr@google.com> Subject: [RFC PATCH] PM: runtime: Apply pinctrl settings if defined From: Joy Chakraborty To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Pavel Machek , Len Brown , Linus Walleij Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, manugautam@google.com, aniketmaurya@google.com, Joy Chakraborty X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 10 Nov 2023 09:58:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782200776677918777 X-GMAIL-MSGID: 1782200776677918777 Apply pinctrl state from runtime framework device state transtion. Pinctrl states if defined in DT are bookmarked in device structures but they need to be explicitly applied from device driver callbacks which is boiler plate code and also not present in many drivers. If there is a specific order of setting pinctrl state with other driver actions then the device driver can choose to do it from its pm callbacks, in such a case this call will be a no-op from the pinctrl core framework since the desired pinctrl state would already be set. We could also add a Kconfig knob to enable/disable this, but I do not see a need to. Signed-off-by: Joy Chakraborty --- drivers/base/pinctrl.c | 33 +++++++++++++++++++++++++++++++++ drivers/base/power/runtime.c | 9 ++++++++- include/linux/pinctrl/devinfo.h | 11 +++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/base/pinctrl.c b/drivers/base/pinctrl.c index c22864458511..24bb6dba8cb7 100644 --- a/drivers/base/pinctrl.c +++ b/drivers/base/pinctrl.c @@ -103,3 +103,36 @@ int pinctrl_bind_pins(struct device *dev) return 0; } + +#ifdef CONFIG_PM +/** + * pinctrl_state_try_default() - Try setting default state if available + * @dev The device to set pinctrl state + */ +inline void pinctrl_state_try_default(struct device *dev) +{ + if (dev->pins && !IS_ERR(dev->pins->default_state)) + pinctrl_select_state(dev->pins->p, dev->pins->default_state); +} + +/** + * pinctrl_state_try_idle() - Try setting idle state if available + * @dev The device to set pinctrl state + */ +inline void pinctrl_state_try_idle(struct device *dev) +{ + if (dev->pins && !IS_ERR(dev->pins->idle_state)) + pinctrl_select_state(dev->pins->p, dev->pins->idle_state); +} + +/** + * pinctrl_state_try_sleep() - Try setting sleep state if available + * @dev The device to set pinctrl state + */ +inline void pinctrl_state_try_sleep(struct device *dev) +{ + if (dev->pins && !IS_ERR(dev->pins->sleep_state)) + pinctrl_select_state(dev->pins->p, dev->pins->sleep_state); +} +#endif + diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 4545669cb973..a07efa446330 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -499,7 +500,7 @@ static int rpm_idle(struct device *dev, int rpmflags) /* If no callback assume success. */ if (!callback || dev->power.no_callbacks) - goto out; + goto no_callback; /* Carry out an asynchronous or a synchronous idle notification. */ if (rpmflags & RPM_ASYNC) { @@ -529,6 +530,8 @@ static int rpm_idle(struct device *dev, int rpmflags) dev->power.idle_notification = false; wake_up_all(&dev->power.wait_queue); + no_callback: + pinctrl_state_try_idle(dev); out: trace_rpm_return_int(dev, _THIS_IP_, retval); return retval ? retval : rpm_suspend(dev, rpmflags | RPM_AUTO); @@ -676,6 +679,7 @@ static int rpm_suspend(struct device *dev, int rpmflags) no_callback: __update_runtime_status(dev, RPM_SUSPENDED); pm_runtime_deactivate_timer(dev); + pinctrl_state_try_sleep(dev); if (dev->parent) { parent = dev->parent; @@ -918,6 +922,7 @@ static int rpm_resume(struct device *dev, int rpmflags) no_callback: __update_runtime_status(dev, RPM_ACTIVE); pm_runtime_mark_last_busy(dev); + pinctrl_state_try_default(dev); if (parent) atomic_inc(&parent->power.child_count); } @@ -1899,6 +1904,7 @@ int pm_runtime_force_suspend(struct device *dev) __update_runtime_status(dev, RPM_SUSPENDED); dev->power.needs_force_resume = 1; } + pinctrl_state_try_sleep(dev); return 0; @@ -1946,6 +1952,7 @@ int pm_runtime_force_resume(struct device *dev) } pm_runtime_mark_last_busy(dev); + pinctrl_state_try_default(dev); out: dev->power.needs_force_resume = 0; pm_runtime_enable(dev); diff --git a/include/linux/pinctrl/devinfo.h b/include/linux/pinctrl/devinfo.h index bb6653af4f92..c3a63e96dd37 100644 --- a/include/linux/pinctrl/devinfo.h +++ b/include/linux/pinctrl/devinfo.h @@ -54,6 +54,12 @@ static inline struct pinctrl *dev_pinctrl(struct device *dev) return dev->pins->p; } +#ifdef CONFIG_PM +extern inline void pinctrl_state_try_default(struct device *dev); +extern inline void pinctrl_state_try_idle(struct device *dev); +extern inline void pinctrl_state_try_sleep(struct device *dev); +#endif /* CONFIG_PM */ + #else /* Stubs if we're not using pinctrl */ @@ -73,5 +79,10 @@ static inline struct pinctrl *dev_pinctrl(struct device *dev) return NULL; } +#ifdef CONFIG_PM +static inline void pinctrl_state_try_default(struct device *dev) {} +static inline void pinctrl_state_try_idle(struct device *dev) {} +static inline void pinctrl_state_try_sleep(struct device *dev) {} +#endif /* CONFIG_PM */ #endif /* CONFIG_PINCTRL */ #endif /* PINCTRL_DEVINFO_H */