From patchwork Sun Sep 12 18:44:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 510123 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 165EAC433F5 for ; Sun, 12 Sep 2021 18:46:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3F8F61026 for ; Sun, 12 Sep 2021 18:46:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235604AbhILSr0 (ORCPT ); Sun, 12 Sep 2021 14:47:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235364AbhILSrZ (ORCPT ); Sun, 12 Sep 2021 14:47:25 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84EF5C061574; Sun, 12 Sep 2021 11:46:10 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id i25so12205761lfg.6; Sun, 12 Sep 2021 11:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5KsYfuNRlvMrE9NTZucMYXQywZC0cvfGbwd3TTvoBus=; b=F6/2gZ2lcI7EMAJusRhiZ0/WloKbWLGv7Pqkl0DzVlelronblNjwRQhrRkeh7NZzSO 0n4GUizzOJT9eKx/BmqRPdTEchksRuEczSXJ0xqeh5KOEyk4chmy3OqTgdlgaB3DHyjG 1mTws3KxM93MjvLe5iHYN/Hgq+5gBuZ+btCVJQJrOM7IRIpdfCeaFTbiY24/sG77Y2Dz GqPsR4hlOxvzqn+pW15Ti0/OCWEMCCnFJl9Gnq8KaOZVJUc4NdCZCUu5XH3K3fsbZnZV T5xzw2UDGOeVixDEh4aLFp/1JiD0hKstcVfhmN0LckyUMJGu4l1m/pJIzfuOCZqM5HA2 KBWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5KsYfuNRlvMrE9NTZucMYXQywZC0cvfGbwd3TTvoBus=; b=by5WzGB4iP/zESgYPLauyljmC55vBMG4g60RyEkZxea4LzRvA4oQGro6QtvRbK/9aF uDPKWNgCRwNSr93jxdMaFH594xPgc1zhgCcSWPSc51yH2sQAI13sY2vhf6XDTJCaQKUG PlIRy7f1AYPHV/tR8arA+a3fJTl6Z/oIQt5jKgUEy4IOnXMOg/L/TtHopfptaj+Jm/o6 M7AcmpP+23fTwIX8gdB8zL0DgWvIBzmvuHteyPi0XebH7gWgjpn/RWRTnR72IKFaqRL1 y97GwYV3pXFRoM9HOob2Fvwxz98MonKIVN6I18eCynFuzvcOrz/k/mV3BaIeqfCcLjO4 VZzA== X-Gm-Message-State: AOAM533NJ7nObNYD57yxftjwudIDG2bEcu0Q7jB/GbZF5SvfgAe8m/4T JLsQZ9MuFdLAd13ByNDkPYkgle6+31o= X-Google-Smtp-Source: ABdhPJx2aJX677qx18QbIaaMBgBaIgcdcDE4og02j8bJno8wZ2+OMe4JANO5qGz7yOvYXsBWazcVRA== X-Received: by 2002:ac2:57cb:: with SMTP id k11mr473082lfo.70.1631472368956; Sun, 12 Sep 2021 11:46:08 -0700 (PDT) Received: from localhost.localdomain (46-138-83-36.dynamic.spd-mgts.ru. [46.138.83.36]) by smtp.gmail.com with ESMTPSA id q5sm588570lfg.36.2021.09.12.11.46.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 11:46:08 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Viresh Kumar , Nishanth Menon , MyungJoo Ham , Stephen Boyd , Kyungmin Park , Chanwoo Choi Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v1 1/4] opp: Add more resource-managed variants of dev_pm_opp_of_add_table() Date: Sun, 12 Sep 2021 21:44:55 +0300 Message-Id: <20210912184458.17995-2-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210912184458.17995-1-digetx@gmail.com> References: <20210912184458.17995-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add resource-managed variants of dev_pm_opp_of_add_table_indexed() and dev_pm_opp_of_add_table_noclk(), allowing drivers to remove boilerplate code. Signed-off-by: Dmitry Osipenko --- drivers/opp/of.c | 46 +++++++++++++++++++++++++++++++++++------- include/linux/pm_opp.h | 12 +++++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 2a97c6535c4c..bd01ecb1d85c 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -1081,6 +1081,17 @@ static void devm_pm_opp_of_table_release(void *data) dev_pm_opp_of_remove_table(data); } +static int devm_of_add_table_indexed(struct device *dev, int index, bool getclk) +{ + int ret; + + ret = _of_add_table_indexed(dev, index, getclk); + if (ret) + return ret; + + return devm_add_action_or_reset(dev, devm_pm_opp_of_table_release, dev); +} + /** * devm_pm_opp_of_add_table() - Initialize opp table from device tree * @dev: device pointer used to lookup OPP table. @@ -1102,13 +1113,7 @@ static void devm_pm_opp_of_table_release(void *data) */ int devm_pm_opp_of_add_table(struct device *dev) { - int ret; - - ret = dev_pm_opp_of_add_table(dev); - if (ret) - return ret; - - return devm_add_action_or_reset(dev, devm_pm_opp_of_table_release, dev); + return devm_of_add_table_indexed(dev, 0, true); } EXPORT_SYMBOL_GPL(devm_pm_opp_of_add_table); @@ -1151,6 +1156,19 @@ int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) } EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed); +/** + * devm_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree + * @dev: device pointer used to lookup OPP table. + * @index: Index number. + * + * This is a resource-managed variant of dev_pm_opp_of_add_table_indexed(). + */ +int devm_pm_opp_of_add_table_indexed(struct device *dev, int index) +{ + return devm_of_add_table_indexed(dev, index, true); +} +EXPORT_SYMBOL_GPL(devm_pm_opp_of_add_table_indexed); + /** * dev_pm_opp_of_add_table_noclk() - Initialize indexed opp table from device * tree without getting clk for device. @@ -1169,6 +1187,20 @@ int dev_pm_opp_of_add_table_noclk(struct device *dev, int index) } EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_noclk); +/** + * devm_pm_opp_of_add_table_noclk() - Initialize indexed opp table from device + * tree without getting clk for device. + * @dev: device pointer used to lookup OPP table. + * @index: Index number. + * + * This is a resource-managed variant of dev_pm_opp_of_add_table_noclk(). + */ +int devm_pm_opp_of_add_table_noclk(struct device *dev, int index) +{ + return devm_of_add_table_indexed(dev, index, false); +} +EXPORT_SYMBOL_GPL(devm_pm_opp_of_add_table_noclk); + /* CPU device specific helpers */ /** diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 84150a22fd7c..a95d6fdd20b6 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -439,7 +439,9 @@ static inline int dev_pm_opp_sync_regulators(struct device *dev) #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF) int dev_pm_opp_of_add_table(struct device *dev); int dev_pm_opp_of_add_table_indexed(struct device *dev, int index); +int devm_pm_opp_of_add_table_indexed(struct device *dev, int index); int dev_pm_opp_of_add_table_noclk(struct device *dev, int index); +int devm_pm_opp_of_add_table_noclk(struct device *dev, int index); void dev_pm_opp_of_remove_table(struct device *dev); int devm_pm_opp_of_add_table(struct device *dev); int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask); @@ -465,11 +467,21 @@ static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) return -EOPNOTSUPP; } +static inline int devm_pm_opp_of_add_table_indexed(struct device *dev, int index) +{ + return -EOPNOTSUPP; +} + static inline int dev_pm_opp_of_add_table_noclk(struct device *dev, int index) { return -EOPNOTSUPP; } +static inline int devm_pm_opp_of_add_table_noclk(struct device *dev, int index) +{ + return -EOPNOTSUPP; +} + static inline void dev_pm_opp_of_remove_table(struct device *dev) { } From patchwork Sun Sep 12 18:44:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 509634 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, 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 2BAA9C433F5 for ; Sun, 12 Sep 2021 18:46:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 173976101B for ; Sun, 12 Sep 2021 18:46:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235887AbhILSrd (ORCPT ); Sun, 12 Sep 2021 14:47:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234680AbhILSr0 (ORCPT ); Sun, 12 Sep 2021 14:47:26 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46CCFC061574; Sun, 12 Sep 2021 11:46:11 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id s3so13032199ljp.11; Sun, 12 Sep 2021 11:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oZx+fkLQGOQm9/g48OhQPkP+HxC/ux2/6Bzv6o5U8hw=; b=RvONcgMwXanSZ/m652FgRHZAs47qc4f/nJiqCxtCn0NFqmcvwrAnmhfg1CuFkty6yX zZxRein3t+AJS4D6m/sSwu9a2aUP1OoBb1SLQMosNxAhoAIS+k/gPFJcbIQfySzwsFAZ wkzTVyDrKWdw+sUBck72DxFRt2FTeeqeSN+ckyxRs9dgB/vjFOTxo65bWOV/YEe8gwyD vlP1eP6YvCNQlPaYVRMxuaoVjbEAqGEM6LYEEgS8L4+wLhu38Bdm8WwNLPiMXKYyiIhi IGPwhyoSpor4PlVKIEbOUQVOIFuY9t6tt9aJ3tP0vsy5qwaszReN1nICEVy/+OC13tOx x28Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oZx+fkLQGOQm9/g48OhQPkP+HxC/ux2/6Bzv6o5U8hw=; b=Ngt4RJct1wRUDpaXFks0DF/xePprpcSKzXMNa9+vm6ipUs7Ptw2uKNS1jqKa2SKH3q xZN3Y/Y3p2KD2y8hhOmlo7p16f1jK6PHe/v+iNYODKG8bD3mIbQo1DcDfRPyLzi0Tx0d fcSZpwk37i+VV1HQzXx0nG0F0b5H/7I6RmiDYsSMEORo8HjvVNRjWXRQNHkfMxO7v9Tv YoaOCuKhTfXIJkGAtBrNQCvpAaG/HAalQzT1Sl3E2tUWMK6Xku+h7bjYsSEAVE1qBXcg 3NLKv2r/Dt8LRrOh9HEetiY7ncI2jYLcClr9/yxbjh9mooiOaI5fCxJOkYjaK3KALowd q6vQ== X-Gm-Message-State: AOAM5306e0kYY070oSktTc8VSHoZr078Vf1mMQeY6YN9SqT6ev4Fwhhu Q4koGLx6bN+dzXbHAP+qd20= X-Google-Smtp-Source: ABdhPJwSX0/yNDmygLn8rBIyXQio8hvAFuX+Qzt5pxB4BKwYGBuhstNzUKLcG42SWlLAXM1YVP93AA== X-Received: by 2002:a2e:9c51:: with SMTP id t17mr7295656ljj.478.1631472369642; Sun, 12 Sep 2021 11:46:09 -0700 (PDT) Received: from localhost.localdomain (46-138-83-36.dynamic.spd-mgts.ru. [46.138.83.36]) by smtp.gmail.com with ESMTPSA id q5sm588570lfg.36.2021.09.12.11.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 11:46:09 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Viresh Kumar , Nishanth Menon , MyungJoo Ham , Stephen Boyd , Kyungmin Park , Chanwoo Choi Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v1 2/4] PM / devfreq: Add devm_devfreq_add_governor() Date: Sun, 12 Sep 2021 21:44:56 +0300 Message-Id: <20210912184458.17995-3-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210912184458.17995-1-digetx@gmail.com> References: <20210912184458.17995-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add resource-managed variant of devfreq_add_governor(). Signed-off-by: Dmitry Osipenko --- drivers/devfreq/devfreq.c | 26 ++++++++++++++++++++++++++ drivers/devfreq/governor.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 85faa7a5c7d1..d3af000ec290 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -1301,6 +1301,32 @@ int devfreq_add_governor(struct devfreq_governor *governor) } EXPORT_SYMBOL(devfreq_add_governor); +static void devm_devfreq_remove_governor(void *governor) +{ + devfreq_remove_governor(governor); +} + +/** + * devm_devfreq_add_governor() - Add devfreq governor + * @dev: device which adds devfreq governor + * @governor: the devfreq governor to be added + * + * This is a resource-managed variant of devfreq_add_governor(). + */ +int devm_devfreq_add_governor(struct device *dev, + struct devfreq_governor *governor) +{ + int err; + + err = devfreq_add_governor(governor); + if (err) + return err; + + return devm_add_action_or_reset(dev, devm_devfreq_remove_governor, + governor); +} +EXPORT_SYMBOL(devm_devfreq_add_governor); + /** * devfreq_remove_governor() - Remove devfreq feature from a device. * @governor: the devfreq governor to be removed diff --git a/drivers/devfreq/governor.h b/drivers/devfreq/governor.h index 2d69a0ce6291..0d70a9ad951e 100644 --- a/drivers/devfreq/governor.h +++ b/drivers/devfreq/governor.h @@ -94,4 +94,7 @@ static inline int devfreq_update_stats(struct devfreq *df) return df->profile->get_dev_status(df->dev.parent, &df->last_status); } + +int devm_devfreq_add_governor(struct device *dev, + struct devfreq_governor *governor); #endif /* _GOVERNOR_H */ From patchwork Sun Sep 12 18:44:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 510124 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, 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 4E38DC43217 for ; Sun, 12 Sep 2021 18:46:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 342FF61076 for ; Sun, 12 Sep 2021 18:46:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235986AbhILSrc (ORCPT ); Sun, 12 Sep 2021 14:47:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235736AbhILSr0 (ORCPT ); Sun, 12 Sep 2021 14:47:26 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED65BC06175F; Sun, 12 Sep 2021 11:46:11 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id c8so16187587lfi.3; Sun, 12 Sep 2021 11:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cA9wCB4pJs3LwykWyuF6E7GswKKTAqR9cFJTGNkwFK0=; b=ebGIUHhU/O3xwyDCfIyt78Idq3t7nmsldhA3xOCNUQUm0W+O+25Xx9UxvEv0tnGcxH /GQ4hKlJsfCyJTaosNtrPLsTkPWJaS7jvHOiz+iXEUtECZCX6BQW4Te3Q8vcInRIwdMo Eh0G7H/G2CFFBBaORNtrN82GXKMEy3DwSyMgrp+dRgKDU9DdnDybtUhxeVfBPDaUXvvE W0Q/lMpvPPGVJe0I7pNMPgc3QYIOPg8y8J0bHAC57GpXHfMoSXZIXVwEErQ1onwqTp0W g/DPUMDqxD1syBYmyq6xsdiqLpJNQ+rXEyQDGRRhaVa1rNtWxrRmNFLfmvMImhYfDzrp qwPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cA9wCB4pJs3LwykWyuF6E7GswKKTAqR9cFJTGNkwFK0=; b=Zk4i2vpnd84dkWvAQt6eP6r7q3XwtpXrpekstgaeS34km9m8vF4M81pEMA7qpF7adp YxrHLyH8u/LC1Sa1vzxuV1g+IBNFno6O1EOXG/MsNCtHFNeQpnoUKql5nCpDZvpFY1yh RZfjj7bjx21JNsTl7ZreAPH1cBlBUYPgsqzMsGLnhZV1lzjKlWiFRgYrpm5Rt3sj3gZ8 TvxUky4L2N1EBVLnA4zUFuVuuQNRw7lxGmd92Lu0NoSql8NMn3Mxd3E59daTG+cnqtBS fKXRNqxT8Rb5t6ts5k+V8ZmcUmqUyFcjprozPWieyyAQRatC76OAA6hcF2MxvxInnME+ N9eQ== X-Gm-Message-State: AOAM533mGFprNDQ3Nji3NUBc+AwfbTAFinKggA4ei07TdGgmKIxwOvBh f3glAcAOanBpoWbi3gf/7oE= X-Google-Smtp-Source: ABdhPJxs+Y1nLxWOSYcrF26pzuzYbCdwnhV7GWyzXdd1pPVwJm+WVLqVoZI5c/5I3IuH1CMZYYoyfw== X-Received: by 2002:a05:6512:96f:: with SMTP id v15mr6020534lft.455.1631472370361; Sun, 12 Sep 2021 11:46:10 -0700 (PDT) Received: from localhost.localdomain (46-138-83-36.dynamic.spd-mgts.ru. [46.138.83.36]) by smtp.gmail.com with ESMTPSA id q5sm588570lfg.36.2021.09.12.11.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 11:46:10 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Viresh Kumar , Nishanth Menon , MyungJoo Ham , Stephen Boyd , Kyungmin Park , Chanwoo Choi Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v1 3/4] PM / devfreq: tegra30: Use resource-managed helpers Date: Sun, 12 Sep 2021 21:44:57 +0300 Message-Id: <20210912184458.17995-4-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210912184458.17995-1-digetx@gmail.com> References: <20210912184458.17995-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Use resource-managed API helpers to simplify driver's probe() function, making code cleaner. Signed-off-by: Dmitry Osipenko --- drivers/devfreq/tegra30-devfreq.c | 107 +++++++++++++----------------- 1 file changed, 46 insertions(+), 61 deletions(-) diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c index 10661eb2aed8..d83fdc2713ed 100644 --- a/drivers/devfreq/tegra30-devfreq.c +++ b/drivers/devfreq/tegra30-devfreq.c @@ -178,7 +178,6 @@ struct tegra_devfreq_soc_data { struct tegra_devfreq { struct devfreq *devfreq; - struct opp_table *opp_table; struct reset_control *reset; struct clk *clock; @@ -789,6 +788,39 @@ static struct devfreq_governor tegra_devfreq_governor = { .event_handler = tegra_governor_event_handler, }; +static void devm_tegra_devfreq_deinit_hw(void *data) +{ + struct tegra_devfreq *tegra = data; + + reset_control_reset(tegra->reset); + clk_disable_unprepare(tegra->clock); +} + +static int devm_tegra_devfreq_init_hw(struct device *dev, + struct tegra_devfreq *tegra) +{ + int err; + + err = clk_prepare_enable(tegra->clock); + if (err) { + dev_err(dev, "Failed to prepare and enable ACTMON clock\n"); + return err; + } + + err = devm_add_action_or_reset(dev, devm_tegra_devfreq_deinit_hw, + tegra); + if (err) + return err; + + err = reset_control_reset(tegra->reset); + if (err) { + dev_err(dev, "Failed to reset hardware: %d\n", err); + return err; + } + + return err; +} + static int tegra_devfreq_probe(struct platform_device *pdev) { u32 hw_version = BIT(tegra_sku_info.soc_speedo_id); @@ -842,38 +874,26 @@ static int tegra_devfreq_probe(struct platform_device *pdev) return err; } - tegra->opp_table = dev_pm_opp_set_supported_hw(&pdev->dev, - &hw_version, 1); - err = PTR_ERR_OR_ZERO(tegra->opp_table); + err = devm_pm_opp_set_supported_hw(&pdev->dev, &hw_version, 1); if (err) { dev_err(&pdev->dev, "Failed to set supported HW: %d\n", err); return err; } - err = dev_pm_opp_of_add_table_noclk(&pdev->dev, 0); + err = devm_pm_opp_of_add_table_noclk(&pdev->dev, 0); if (err) { dev_err(&pdev->dev, "Failed to add OPP table: %d\n", err); - goto put_hw; - } - - err = clk_prepare_enable(tegra->clock); - if (err) { - dev_err(&pdev->dev, - "Failed to prepare and enable ACTMON clock\n"); - goto remove_table; + return err; } - err = reset_control_reset(tegra->reset); - if (err) { - dev_err(&pdev->dev, "Failed to reset hardware: %d\n", err); - goto disable_clk; - } + err = devm_tegra_devfreq_init_hw(&pdev->dev, tegra); + if (err) + return err; rate = clk_round_rate(tegra->emc_clock, ULONG_MAX); if (rate < 0) { dev_err(&pdev->dev, "Failed to round clock rate: %ld\n", rate); - err = rate; - goto disable_clk; + return rate; } tegra->max_freq = rate / KHZ; @@ -892,52 +912,18 @@ static int tegra_devfreq_probe(struct platform_device *pdev) INIT_DELAYED_WORK(&tegra->cpufreq_update_work, tegra_actmon_delayed_update); - err = devfreq_add_governor(&tegra_devfreq_governor); + err = devm_devfreq_add_governor(&pdev->dev, &tegra_devfreq_governor); if (err) { dev_err(&pdev->dev, "Failed to add governor: %d\n", err); - goto remove_opps; + return err; } tegra_devfreq_profile.initial_freq = clk_get_rate(tegra->emc_clock); - devfreq = devfreq_add_device(&pdev->dev, &tegra_devfreq_profile, - "tegra_actmon", NULL); - if (IS_ERR(devfreq)) { - err = PTR_ERR(devfreq); - goto remove_governor; - } - - return 0; - -remove_governor: - devfreq_remove_governor(&tegra_devfreq_governor); - -remove_opps: - dev_pm_opp_remove_all_dynamic(&pdev->dev); - - reset_control_reset(tegra->reset); -disable_clk: - clk_disable_unprepare(tegra->clock); -remove_table: - dev_pm_opp_of_remove_table(&pdev->dev); -put_hw: - dev_pm_opp_put_supported_hw(tegra->opp_table); - - return err; -} - -static int tegra_devfreq_remove(struct platform_device *pdev) -{ - struct tegra_devfreq *tegra = platform_get_drvdata(pdev); - - devfreq_remove_device(tegra->devfreq); - devfreq_remove_governor(&tegra_devfreq_governor); - - reset_control_reset(tegra->reset); - clk_disable_unprepare(tegra->clock); - - dev_pm_opp_of_remove_table(&pdev->dev); - dev_pm_opp_put_supported_hw(tegra->opp_table); + devfreq = devm_devfreq_add_device(&pdev->dev, &tegra_devfreq_profile, + "tegra_actmon", NULL); + if (IS_ERR(devfreq)) + return PTR_ERR(devfreq); return 0; } @@ -967,7 +953,6 @@ MODULE_DEVICE_TABLE(of, tegra_devfreq_of_match); static struct platform_driver tegra_devfreq_driver = { .probe = tegra_devfreq_probe, - .remove = tegra_devfreq_remove, .driver = { .name = "tegra-devfreq", .of_match_table = tegra_devfreq_of_match, From patchwork Sun Sep 12 18:44:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 509635 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 B21A7C433F5 for ; Sun, 12 Sep 2021 18:46:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9957761076 for ; Sun, 12 Sep 2021 18:46:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235872AbhILSr2 (ORCPT ); Sun, 12 Sep 2021 14:47:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235826AbhILSr1 (ORCPT ); Sun, 12 Sep 2021 14:47:27 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD392C061574; Sun, 12 Sep 2021 11:46:12 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id s12so13124275ljg.0; Sun, 12 Sep 2021 11:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z2RXcbB3tu0m4WW0OHBxApkMwFU6fLHEdrXt9r4rSKc=; b=CgYuDKKtuJGn0+8ts8VKdkmumCXL7q8NSFw115BOkLGhWNvDq56YpfN9LFPiylzIFH KdFw6zGb42NBBWS2V+FwMNwG5WiwgCjJI17bJIvl8R0xzcicNRyZOgFL77aHHLZRAl+Z OVVqm94poh3lk2Yp3hH9SFTwfawMlRg1795GVNAwkXRcXb+hgEX8P3NaD/0bnxxzWrRp nzsSdfVuseeXhCTFEdkiM8h+4zaggCy0kt5TbxN0uo8VQyxlEGFIwhkT+Qnb69tNq9Qh +CdIeNfBYva2xaJBMb9MBUQ4t53IemnzpQGL2i3x4/rWvVfpqyuqZSCI/co6nlToqv3p tE0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z2RXcbB3tu0m4WW0OHBxApkMwFU6fLHEdrXt9r4rSKc=; b=C8CfK/Pn20rWZdzCtg8FWrbfD2lCH6CMcBMHhkDXrnVhbZ7K/kMR22NqyIMkW3DOsI pehrcMYKs6oo8iRZZ20pZaMb1Rkgd8ucwq8tixtmB9x+sWIN9Qpik3810KPlwZIRGF0P xS2cNCDej0y5aLEBz9NJZ0WuT33+mvgrqHdO6EC/QnrJJCZPC4cubGE3gyDqE6kuiq3g 69xGGRXB/5892HIXsmP1ZhqzZIvbSoFl0TVjFZ+5q3rokq+hMDMIRk6KNJXHySDZRP4P M3Reycfv1PEODR+R6jSJIexsro2kSXzMpAQ6vWylxXITGzi/y8M8GoEQlOj4Z++d3bIj 82jA== X-Gm-Message-State: AOAM53190zzFOPchx+W1l/ede3OgNZs3skuHOPkdwkfxgoSRfCcp/OCk G8GWxBhMnNaqyhdGarwvrgw= X-Google-Smtp-Source: ABdhPJyHw+jtKCOivSBI+NMKRt8D7t8dUHjAg9UXh7vHT2KzI9E5J/jMOi7ETCAnPJ3OfY4VF2Gm4g== X-Received: by 2002:a05:651c:3dd:: with SMTP id f29mr7301561ljp.69.1631472371136; Sun, 12 Sep 2021 11:46:11 -0700 (PDT) Received: from localhost.localdomain (46-138-83-36.dynamic.spd-mgts.ru. [46.138.83.36]) by smtp.gmail.com with ESMTPSA id q5sm588570lfg.36.2021.09.12.11.46.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 11:46:10 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Viresh Kumar , Nishanth Menon , MyungJoo Ham , Stephen Boyd , Kyungmin Park , Chanwoo Choi Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v1 4/4] PM / devfreq: tegra30: Check whether clk_round_rate() returns zero rate Date: Sun, 12 Sep 2021 21:44:58 +0300 Message-Id: <20210912184458.17995-5-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210912184458.17995-1-digetx@gmail.com> References: <20210912184458.17995-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org EMC clock is always-on and can't be zero. Check whether clk_round_rate() returns zero rate and error out if it does. It can return zero if clock tree isn't initialized properly. Signed-off-by: Dmitry Osipenko Acked-by: Chanwoo Choi --- drivers/devfreq/tegra30-devfreq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c index d83fdc2713ed..65ecf17a36f4 100644 --- a/drivers/devfreq/tegra30-devfreq.c +++ b/drivers/devfreq/tegra30-devfreq.c @@ -891,9 +891,9 @@ static int tegra_devfreq_probe(struct platform_device *pdev) return err; rate = clk_round_rate(tegra->emc_clock, ULONG_MAX); - if (rate < 0) { + if (rate <= 0) { dev_err(&pdev->dev, "Failed to round clock rate: %ld\n", rate); - return rate; + return rate ?: -EINVAL; } tegra->max_freq = rate / KHZ;