Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932613AbdHWQMF (ORCPT ); Wed, 23 Aug 2017 12:12:05 -0400 Received: from mail-sn1nam02on0057.outbound.protection.outlook.com ([104.47.36.57]:12160 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932251AbdHWQKV (ORCPT ); Wed, 23 Aug 2017 12:10:21 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; From: Dong Aisheng To: CC: , , , , , , , , , Dong Aisheng Subject: [PATCH 1/7] PM / OPP: Add platform specific set_clk function Date: Thu, 24 Aug 2017 00:10:04 +0800 Message-ID: <1503504610-12880-2-git-send-email-aisheng.dong@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503504610-12880-1-git-send-email-aisheng.dong@nxp.com> References: <1503504610-12880-1-git-send-email-aisheng.dong@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131479782193736456;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(336005)(39860400002)(39380400002)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(5660300001)(76176999)(81156014)(54906002)(81166006)(85426001)(53936002)(97736004)(189998001)(33646002)(50986999)(498600001)(48376002)(7416002)(106466001)(356003)(8656003)(105606002)(68736007)(305945005)(110136004)(2351001)(626005)(4326008)(50466002)(8676002)(8936002)(86362001)(2906002)(47776003)(6666003)(36756003)(6916009)(104016004)(50226002)(5003940100001)(2950100002)(77096006);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR03MB2267;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD020;1:qv0hOWnBa0IFhsvK3m6mYDIw4jVovlY0Q5D17PCNAaF+O8WSaT6a9GybI5/IUAoUkNGkTnsbinbotFgOhlu4xWVIWKREP13GGxaBj4qdGHsLJBC0tnq9SzdlXDR82+HM MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b0c907bb-0b9f-4f1d-a000-08d4ea417331 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(300000503095)(300135400095)(2017052603186)(201703131430075)(201703131517081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:CY1PR03MB2267; X-Microsoft-Exchange-Diagnostics: 1;CY1PR03MB2267;3:jYh9/pqRs1QBBB8S052nluSjkgNFGddRDOBjmvhCFNLRrjm9EkWfAVggzn/CzX0L2HG2C4ZSKvFU1s6wHUeGqV6v52GHro2Toi0JTgi3g7XHjRsmCOTIc9Oe56vwMD1zqHMXo5yN927YO+S59SsnIMGwOCyCeGsdlhigIQ+WRjOgQKOolmpWLSKrmpoiGs6bJT1JQ69CgTvZ3/Xp9srAa0t/srWF/icvUJIV+rbTNDq3ScXjYyoDGK3UVjyflRR6xeo86uf8Szj/emDFqo99loot0OTNew3uavOb4VhEFuhIBBdUEw0AuAEa65bzBLQ3aRhzGzAMG0wTpdSZuw0jm1NP6bG0JcNXH20LJrxqp3c=;25:7SVrFOjLVdGHnnmg6Tu4G5MDPLFIz0c4ZUV/lM9MtEOFbpNg+qernIxUxSwsA6WRGtkkzAPsx1cZ53tIt2lW3rrxnsxbLmazIbwYkKUD2bE+9ySj/85J/GEZxlsFtSbl3qBy8rN6lICxxG4dZF52FpldC+KM/WVhuaoxiT1Pq/pmiNJGfxbV+b6Y+lcvk/QjlWBBQXm1mmryWgosOkCvI/XYOYuqx8qko6XtiQ9PDWsvPI5EUQlVyXmdOA+WlmAsB+R6U5/uLS83XB1d3sV4H+vtIpMv8P+w1K4bwV639lCSdRxN+MEOjl3o5GHU126zrIWuw68iTsuiEqhSQKpcNg== X-MS-TrafficTypeDiagnostic: CY1PR03MB2267: X-Microsoft-Exchange-Diagnostics: 1;CY1PR03MB2267;31:xaonE/EfAS5tkPFrMEUvRXkcMQFe6wlC4Uud6CE2iwLJ9UsOzX4Hbix/eBWJHgDEE8d/hCR0hUVwu6HukZDl5APgfqUl/F2wQgKxkKSocSHQusImI9JrYq/yKXecFyEabHnFmi3jv5rujR/svQ1x8LN2biHMJzXaopPMaykv90LUlYqbucIWBWQOxD4qHMrLi3VqMYqCelRs0g8jwndO69pVDIc9KO0Ywr4Pk1pvZsQ=;4:zcMf6wMb7Yr690j7A18WKIINPc2lOqx67krLwrhxuXBxw9r3yb22UpVG+XXP3lv6BO1eg057tbHXh0IQkyGHFA/G/mQRogtcELYKECaZFqws3+TBBddYwaRiySHdeDyBlCoaL3Xqz6Bc8Yy3E9/KgqcVcGlVi9ei0xrxliri3BmFclxGrjUjOTrLR+SjdtNYUC2DdEmMkpoZHE6jcGvK+FJjJBcPakp0/Ugq2LEe+niGeKhqJ0NVCSEqJtl5RDD964Hbf1Efgm+y4cmktNKwvMWaLOyxLdxeRsNPyVsAVz32g8eezh1MizdqAsAyC5gy5XVBr7FFOgqsu0QmlPNVTQ== X-Exchange-Antispam-Report-Test: UriScan:(31051911155226)(185117386973197); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(601004)(2401047)(13018025)(5005006)(13016025)(8121501046)(3002001)(10201501046)(100000703101)(100105400095)(93006095)(93001095)(6055026)(6096035)(20161123561025)(201703131430075)(201703131433075)(201703131448075)(201703161259150)(201703151042153)(20161123563025)(20161123559100)(20161123565025)(20161123556025)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY1PR03MB2267;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY1PR03MB2267; X-Forefront-PRVS: 040866B734 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR03MB2267;23:L6MCh2+p45Wy7uXTs3DIebRUqluZHYpOVb+g1IrPd?= =?us-ascii?Q?DAE4LFx4z2OP6MaYnk64vDdwGWw4KSFhTAh69Q5xlP72O8ZQlFSHwUTJbq3a?= =?us-ascii?Q?ojDb8ZnEzlRXrI9nVebA7r1EhKsUEy5bJD8SksAFuS0JM1BRc8uUFIWdyPcf?= =?us-ascii?Q?LHQ7KdUZ+HLToWZuT8h0MoneW+uv5ibDDfqwg6D1HiOFRZVLmyeiStroprMZ?= =?us-ascii?Q?dJrV+bS3P7/Y1XHkE0Cg50TCDrDPralIQx/0TQcAALjsYYtTYBrlRT/7Pxko?= =?us-ascii?Q?8p9OLDADnvRiWQptmDfClk75AApL2zNdmO9xUevzPO+MLVxM9iDyG5HuweKZ?= =?us-ascii?Q?ZJLpaU3pumIn4uXfJd4Y9sGojwbEr0XYoEhYooXLH7yQYijad+TV9m1bpLe/?= =?us-ascii?Q?H6SDqFhtd4LjK5I6zl0ME5eKvezGuLK271QnSN+7wFwjd0h9IBjdN260l1Ah?= =?us-ascii?Q?aqSj0W8U1yDCbzGb3WQDemYlPVfjYByTeXvXrp8zfcpcKY2vF3RhJaY3WdqA?= =?us-ascii?Q?YEq+183swNQTfLAzI1T+IgVdOybnfP2nhRVoFMfcycuzI8DpZTUKip76Ae8t?= =?us-ascii?Q?BrXtiPyTif2KypQc+O/u1zYi0JTP4dQnlTbz0Txgnx9gYaslIcmL5Bk37gY6?= =?us-ascii?Q?KVTnXtHwKEHzWKLtxsZEtojLGso5K+mAxXKyTK9yFBIQy4zTdkgIbGtdP1Xg?= =?us-ascii?Q?/jwGpJ1eJK46R7ib70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CHbGGuCD6onY+6OhZc4VmLXAmMuv0iKapEFJQxy6RmhVbiIaOFj/C+S/Gt4gIEgdbC3IkImWqfDFYaZ7G8rTnRJ2cgAIjZWE=;7:F4CLsdp2NFnd5TSMtjUYliJlbw+SSBZL+wJTOjRpEcr+WMvJWDDTkhhnW0IxeBsJxmBwNXw9WBYXEcZMNcsyK8PMX8bdx5E0lCKS5IYubaHymDeQAnVuUGoQ5d9eyKSuaS+FVE9YGbmzkQ781VFhZYSOQ8RIdE8Dac8+EGF20WSjpoKplV2t3qZbWTAxlRdOckN8WBhZoqIm081D/XThD7PX6lLZsFBxur0ufBKeMMc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2017 16:10:19.0460 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB2267 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7775 Lines: 208 This is useful to support platforms which only the clk setting is different from the generic OPP set rate but others like voltage setting are still the same. Users can use this function to register a custom OPP set clk helper working in place of the default simple clk setting in the generic dev_pm_opp_set_rate(). Then user can still use dev_pm_opp_set_rate() with .set_clk() to save a lot duplicated work. Cc: Viresh Kumar Cc: Nishanth Menon Cc: Stephen Boyd Cc: "Rafael J. Wysocki" Signed-off-by: Dong Aisheng --- drivers/base/power/opp/core.c | 90 ++++++++++++++++++++++++++++++++++++++++--- drivers/base/power/opp/opp.h | 4 ++ include/linux/pm_opp.h | 13 +++++++ 3 files changed, 102 insertions(+), 5 deletions(-) diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index a8cc14f..37cf970 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -521,12 +521,15 @@ static int _set_opp_voltage(struct device *dev, struct regulator *reg, } static inline int -_generic_set_opp_clk_only(struct device *dev, struct clk *clk, +_generic_set_opp_clk_only(const struct opp_table *opp_table, struct device *dev, unsigned long old_freq, unsigned long freq) { int ret; - ret = clk_set_rate(clk, freq); + if (opp_table->set_clk) + return opp_table->set_clk(dev, opp_table->clk, old_freq, freq); + + ret = clk_set_rate(opp_table->clk, freq); if (ret) { dev_err(dev, "%s: failed to set clock rate: %d\n", __func__, ret); @@ -559,7 +562,7 @@ static int _generic_set_opp_regulator(const struct opp_table *opp_table, } /* Change frequency */ - ret = _generic_set_opp_clk_only(dev, opp_table->clk, old_freq, freq); + ret = _generic_set_opp_clk_only(opp_table, dev, old_freq, freq); if (ret) goto restore_voltage; @@ -573,7 +576,7 @@ static int _generic_set_opp_regulator(const struct opp_table *opp_table, return 0; restore_freq: - if (_generic_set_opp_clk_only(dev, opp_table->clk, freq, old_freq)) + if (_generic_set_opp_clk_only(opp_table, dev, freq, old_freq)) dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n", __func__, old_freq); restore_voltage: @@ -653,7 +656,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) /* Only frequency scaling */ if (!opp_table->regulators) { - ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq); + ret = _generic_set_opp_clk_only(opp_table, dev, old_freq, freq); } else if (!opp_table->set_opp) { ret = _generic_set_opp_regulator(opp_table, dev, old_freq, freq, IS_ERR(old_opp) ? NULL : old_opp->supplies, @@ -1500,6 +1503,83 @@ void dev_pm_opp_register_put_opp_helper(struct opp_table *opp_table) EXPORT_SYMBOL_GPL(dev_pm_opp_register_put_opp_helper); /** + * dev_pm_opp_register_set_clk_helper() - Register custom OPP set clk helper + * @dev: Device for which the helper is getting registered. + * @set_clk: Custom OPP set clk helper. + * + * This is useful to support complex platforms which only the clk setting + * is different from the generic OPP set rate but others like voltage + * setting are still the same. + * + * Users can use this function to register a custom OPP set clk helper + * working in place of the default simple clk setting in the generic + * dev_pm_opp_set_rate(). + * + * This must be called before any OPPs are initialized for the device. + */ +struct opp_table *dev_pm_opp_register_set_clk_helper(struct device *dev, + int (*set_clk)(struct device *dev, struct clk *clk, + unsigned long old_freq, unsigned long freq)) +{ + struct opp_table *opp_table; + int ret; + + if (!set_clk) + return ERR_PTR(-EINVAL); + + opp_table = dev_pm_opp_get_opp_table(dev); + if (!opp_table) + return ERR_PTR(-ENOMEM); + + /* This should be called before OPPs are initialized */ + if (WARN_ON(!list_empty(&opp_table->opp_list))) { + ret = -EBUSY; + goto err; + } + + /* Already have custom set_clk helper */ + if (WARN_ON(opp_table->set_clk)) { + ret = -EBUSY; + goto err; + } + + opp_table->set_clk = set_clk; + + return opp_table; + +err: + dev_pm_opp_put_opp_table(opp_table); + + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_register_set_clk_helper); + +/** + * dev_pm_opp_register_put_clk_helper() - Releases resources blocked for + * set_clk helper + * @opp_table: OPP table returned from dev_pm_opp_register_set_clk_helper(). + * + * Release resources blocked for platform specific set_clk helper. + */ +void dev_pm_opp_register_put_clk_helper(struct opp_table *opp_table) +{ + if (!opp_table->set_clk) { + pr_err("%s: Doesn't have custom set_clk helper set\n", + __func__); + return; + } + + /* Make sure there are no concurrent readers while updating opp_table */ + WARN_ON(!list_empty(&opp_table->opp_list)); + + opp_table->set_clk = NULL; + + dev_pm_opp_put_opp_table(opp_table); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_register_put_clk_helper); + + +/** * dev_pm_opp_add() - Add an OPP table from a table definitions * @dev: device for which we do this operation * @freq: Frequency in Hz for this OPP diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h index 166eef9..c85405e 100644 --- a/drivers/base/power/opp/opp.h +++ b/drivers/base/power/opp/opp.h @@ -137,6 +137,8 @@ enum opp_table_access { * @regulator_count: Number of power supply regulators * @set_opp: Platform specific set_opp callback * @set_opp_data: Data to be passed to set_opp callback + * @set_clk: Platform specific set_clk callback. Different from @set_opp, + @set_clk only handles the clk part setting. * @dentry: debugfs dentry pointer of the real device directory (not links). * @dentry_name: Name of the real dentry. * @@ -174,6 +176,8 @@ struct opp_table { int (*set_opp)(struct dev_pm_set_opp_data *data); struct dev_pm_set_opp_data *set_opp_data; + int (*set_clk)(struct device *dev, struct clk *clk, unsigned long old_freq, unsigned long freq); + #ifdef CONFIG_DEBUG_FS struct dentry *dentry; char dentry_name[NAME_MAX]; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 51ec727..a8b1e4d 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -125,6 +125,9 @@ struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name); void dev_pm_opp_put_clkname(struct opp_table *opp_table); struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)); void dev_pm_opp_register_put_opp_helper(struct opp_table *opp_table); +struct opp_table *dev_pm_opp_register_set_clk_helper(struct device *dev, int (*set_clk)(struct device *dev, struct clk *clk, + unsigned long old_freq, unsigned long freq)); +void dev_pm_opp_register_put_clk_helper(struct opp_table *opp_table); int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask); int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); @@ -245,6 +248,16 @@ static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device static inline void dev_pm_opp_register_put_opp_helper(struct opp_table *opp_table) {} + +static inline struct opp_table *dev_pm_opp_register_set_clk_helper(struct device *dev, + int (*set_clk)(struct device *dev, struct clk *clk, + unsigned long old_freq, unsigned long freq)) +{ + return ERR_PTR(-ENOTSUPP); +} + +static inline void dev_pm_opp_register_put_clk_helper(struct opp_table *opp_table) {} + static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) { return ERR_PTR(-ENOTSUPP); -- 2.7.4