From patchwork Mon Oct 12 13:55:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lee X-Patchwork-Id: 11832725 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C412109B for ; Mon, 12 Oct 2020 13:56:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1AA532076E for ; Mon, 12 Oct 2020 13:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390585AbgJLNz5 (ORCPT ); Mon, 12 Oct 2020 09:55:57 -0400 Received: from smtp2207-205.mail.aliyun.com ([121.197.207.205]:43608 "EHLO smtp2207-205.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390538AbgJLNz4 (ORCPT ); Mon, 12 Oct 2020 09:55:56 -0400 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07487985|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.105473-0.0428101-0.851717;FP=0|0|0|0|0|-1|-1|-1;HT=ay29a033018047212;MF=frank@allwinnertech.com;NM=1;PH=DS;RN=20;RT=20;SR=0;TI=SMTPD_---.IiEO.rd_1602510932; Received: from allwinnertech.com(mailfrom:frank@allwinnertech.com fp:SMTPD_---.IiEO.rd_1602510932) by smtp.aliyun-inc.com(10.147.41.137); Mon, 12 Oct 2020 21:55:43 +0800 From: Frank Lee To: robdclark@gmail.com, sean@poorly.run, airlied@linux.ie, daniel@ffwll.ch, vireshk@kernel.org, nm@ti.com, sboyd@kernel.org, rjw@rjwysocki.net, jcrouse@codeaurora.org, eric@anholt.net, tiny.windzz@gmail.com, kholk11@gmail.com, emil.velikov@collabora.com, gustavoars@kernel.org Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Yangtao Li Subject: [PATCH 1/3] opp: Add devres wrapper for dev_pm_opp_set_supported_hw Date: Mon, 12 Oct 2020 21:55:15 +0800 Message-Id: <20201012135517.19468-2-frank@allwinnertech.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012135517.19468-1-frank@allwinnertech.com> References: <20201012135517.19468-1-frank@allwinnertech.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Yangtao Li Add devres wrapper for dev_pm_opp_set_supported_hw() to simplify driver code. Signed-off-by: Yangtao Li Signed-off-by: Yangtao Li --- drivers/opp/core.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 8 ++++++++ 2 files changed, 49 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 3ca7543142bf..b38852dde578 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1625,6 +1625,47 @@ void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) } EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw); +static void devm_pm_opp_put_supported_hw(struct device *dev, void *res) +{ + dev_pm_opp_put_supported_hw(*(struct opp_table **)res); +} + +/** + * devm_pm_opp_set_supported_hw() - Set supported platforms + * @dev: Device for which supported-hw has to be set. + * @versions: Array of hierarchy of versions to match. + * @count: Number of elements in the array. + * + * This is required only for the V2 bindings, and it enables a platform to + * specify the hierarchy of versions it supports. OPP layer will then enable + * OPPs, which are available for those versions, based on its 'opp-supported-hw' + * property. + * + * The opp_table structure will be freed after the device is destroyed. + */ +struct opp_table *devm_pm_opp_set_supported_hw(struct device *dev, + const u32 *versions, + unsigned int count) +{ + struct opp_table **ptr, *opp_table; + + ptr = devres_alloc(devm_pm_opp_put_supported_hw, + sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + opp_table = dev_pm_opp_set_supported_hw(dev, versions, count); + if (!IS_ERR(opp_table)) { + *ptr = opp_table; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return opp_table; +} +EXPORT_SYMBOL(devm_pm_opp_set_supported_hw); + /** * dev_pm_opp_set_prop_name() - Set prop-extn name * @dev: Device for which the prop-name has to be set. diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index dbb484524f82..901920e29c54 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -140,6 +140,7 @@ int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count); void dev_pm_opp_put_supported_hw(struct opp_table *opp_table); +struct opp_table *devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count); struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name); void dev_pm_opp_put_prop_name(struct opp_table *opp_table); struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count); @@ -298,6 +299,13 @@ static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {} +static inline struct opp_table *devm_pm_opp_set_supported_hw(struct device *dev, + const u32 *versions, + unsigned int count) +{ + return ERR_PTR(-ENOTSUPP); +} + static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)) { From patchwork Mon Oct 12 13:55:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lee X-Patchwork-Id: 11832729 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 336CF92C for ; Mon, 12 Oct 2020 13:56:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24A04208B8 for ; Mon, 12 Oct 2020 13:56:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390506AbgJLNzz (ORCPT ); Mon, 12 Oct 2020 09:55:55 -0400 Received: from smtp2207-205.mail.aliyun.com ([121.197.207.205]:50549 "EHLO smtp2207-205.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390248AbgJLNzx (ORCPT ); Mon, 12 Oct 2020 09:55:53 -0400 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07436685|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.0758005-0.0504991-0.8737;FP=0|0|0|0|0|-1|-1|-1;HT=ay29a033018047188;MF=frank@allwinnertech.com;NM=1;PH=DS;RN=20;RT=20;SR=0;TI=SMTPD_---.IiEO.rd_1602510932; Received: from allwinnertech.com(mailfrom:frank@allwinnertech.com fp:SMTPD_---.IiEO.rd_1602510932) by smtp.aliyun-inc.com(10.147.41.137); Mon, 12 Oct 2020 21:55:46 +0800 From: Frank Lee To: robdclark@gmail.com, sean@poorly.run, airlied@linux.ie, daniel@ffwll.ch, vireshk@kernel.org, nm@ti.com, sboyd@kernel.org, rjw@rjwysocki.net, jcrouse@codeaurora.org, eric@anholt.net, tiny.windzz@gmail.com, kholk11@gmail.com, emil.velikov@collabora.com, gustavoars@kernel.org Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Yangtao Li Subject: [PATCH 2/3] opp: Add devres wrapper for dev_pm_opp_set_prop_name Date: Mon, 12 Oct 2020 21:55:16 +0800 Message-Id: <20201012135517.19468-3-frank@allwinnertech.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012135517.19468-1-frank@allwinnertech.com> References: <20201012135517.19468-1-frank@allwinnertech.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Yangtao Li Add devres wrapper for dev_pm_opp_set_prop_name() to simplify driver code. Signed-off-by: Yangtao Li Signed-off-by: Yangtao Li --- drivers/opp/core.c | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 6 ++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index b38852dde578..3263fa8302c9 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1721,6 +1721,45 @@ void dev_pm_opp_put_prop_name(struct opp_table *opp_table) } EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name); +static void devm_pm_opp_put_prop_name(struct device *dev, void *res) +{ + dev_pm_opp_put_prop_name(*(struct opp_table **)res); +} + +/** + * devm_pm_opp_set_prop_name() - Set prop-extn name + * @dev: Device for which the prop-name has to be set. + * @name: name to postfix to properties. + * + * This is required only for the V2 bindings, and it enables a platform to + * specify the extn to be used for certain property names. The properties to + * which the extension will apply are opp-microvolt and opp-microamp. OPP core + * should postfix the property name with - while looking for them. + * + * The opp_table structure will be freed after the device is destroyed. + */ +struct opp_table *devm_pm_opp_set_prop_name(struct device *dev, + const char *name) +{ + struct opp_table **ptr, *opp_table; + + ptr = devres_alloc(devm_pm_opp_put_prop_name, + sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + opp_table = dev_pm_opp_set_prop_name(dev, name); + if (!IS_ERR(opp_table)) { + *ptr = opp_table; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return opp_table; +} +EXPORT_SYMBOL(devm_pm_opp_set_prop_name); + static int _allocate_set_opp_data(struct opp_table *opp_table) { struct dev_pm_set_opp_data *data; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 901920e29c54..1708485200dd 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -143,6 +143,7 @@ void dev_pm_opp_put_supported_hw(struct opp_table *opp_table); struct opp_table *devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count); struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name); void dev_pm_opp_put_prop_name(struct opp_table *opp_table); +struct opp_table *devm_pm_opp_set_prop_name(struct device *dev, const char *name); struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count); void dev_pm_opp_put_regulators(struct opp_table *opp_table); struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name); @@ -321,6 +322,11 @@ static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, con static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {} +static inline struct opp_table *devm_pm_opp_set_prop_name(struct device *dev, const char *name) +{ + return ERR_PTR(-ENOTSUPP); +} + static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count) { return ERR_PTR(-ENOTSUPP); From patchwork Mon Oct 12 13:55:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lee X-Patchwork-Id: 11832735 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE6D992C for ; Mon, 12 Oct 2020 13:56:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA6882080D for ; Mon, 12 Oct 2020 13:56:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390470AbgJLN4c (ORCPT ); Mon, 12 Oct 2020 09:56:32 -0400 Received: from smtp2207-205.mail.aliyun.com ([121.197.207.205]:42461 "EHLO smtp2207-205.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390558AbgJLN4W (ORCPT ); Mon, 12 Oct 2020 09:56:22 -0400 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.4745978|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.0102361-0.00261358-0.98715;FP=0|0|0|0|0|-1|-1|-1;HT=ay29a033018047193;MF=frank@allwinnertech.com;NM=1;PH=DS;RN=20;RT=20;SR=0;TI=SMTPD_---.IiEO.rd_1602510932; Received: from allwinnertech.com(mailfrom:frank@allwinnertech.com fp:SMTPD_---.IiEO.rd_1602510932) by smtp.aliyun-inc.com(10.147.41.137); Mon, 12 Oct 2020 21:55:47 +0800 From: Frank Lee To: robdclark@gmail.com, sean@poorly.run, airlied@linux.ie, daniel@ffwll.ch, vireshk@kernel.org, nm@ti.com, sboyd@kernel.org, rjw@rjwysocki.net, jcrouse@codeaurora.org, eric@anholt.net, tiny.windzz@gmail.com, kholk11@gmail.com, emil.velikov@collabora.com, gustavoars@kernel.org Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Yangtao Li Subject: [PATCH 3/3] drm/msm: Convert to devm_pm_opp_set_supported_hw Date: Mon, 12 Oct 2020 21:55:17 +0800 Message-Id: <20201012135517.19468-4-frank@allwinnertech.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012135517.19468-1-frank@allwinnertech.com> References: <20201012135517.19468-1-frank@allwinnertech.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Yangtao Li Use the devm_pm_opp_set_supported_hw() to avoid memory leaks in some cases. Signed-off-by: Yangtao Li Signed-off-by: Yangtao Li --- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c index 91726da82ed6..8d88f119a59f 100644 --- a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c +++ b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c @@ -1487,7 +1487,7 @@ static void check_speed_bin(struct device *dev) nvmem_cell_put(cell); } - dev_pm_opp_set_supported_hw(dev, &val, 1); + devm_pm_opp_set_supported_hw(dev, &val, 1); } struct msm_gpu *a5xx_gpu_init(struct drm_device *dev)