[PATCH 07/18] platform/x86: amd: pmf: sps: Use devm_platform_profile_register()

Kurt Borja posted 18 patches 11 months, 2 weeks ago
There is a newer version of this series
[PATCH 07/18] platform/x86: amd: pmf: sps: Use devm_platform_profile_register()
Posted by Kurt Borja 11 months, 2 weeks ago
Replace platform_profile_register() with it's device managed version.
While at it, pass amd_pmf_dev to the class device as drvdata and replace
uses of container_of() with dev_get_drvdata().

Signed-off-by: Kurt Borja <kuurtb@gmail.com>
---
 drivers/platform/x86/amd/pmf/core.c |  1 -
 drivers/platform/x86/amd/pmf/pmf.h  |  1 -
 drivers/platform/x86/amd/pmf/sps.c  | 11 +++--------
 3 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c
index 57ee95a327be..1211a753fee8 100644
--- a/drivers/platform/x86/amd/pmf/core.c
+++ b/drivers/platform/x86/amd/pmf/core.c
@@ -371,7 +371,6 @@ static void amd_pmf_deinit_features(struct amd_pmf_dev *dev)
 	if (is_apmf_func_supported(dev, APMF_FUNC_STATIC_SLIDER_GRANULAR) ||
 	    is_apmf_func_supported(dev, APMF_FUNC_OS_POWER_SLIDER_UPDATE)) {
 		power_supply_unreg_notifier(&dev->pwr_src_notifier);
-		amd_pmf_deinit_sps(dev);
 	}
 
 	if (dev->smart_pc_enabled) {
diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h
index 56024eb40266..198bfe3306be 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -764,7 +764,6 @@ int amd_pmf_get_pprof_modes(struct amd_pmf_dev *pmf);
 void amd_pmf_update_slider(struct amd_pmf_dev *dev, bool op, int idx,
 			   struct amd_pmf_static_slider_granular *table);
 int amd_pmf_init_sps(struct amd_pmf_dev *dev);
-void amd_pmf_deinit_sps(struct amd_pmf_dev *dev);
 int apmf_get_static_slider_granular(struct amd_pmf_dev *pdev,
 				    struct apmf_static_slider_granular_output *output);
 bool is_pprof_balanced(struct amd_pmf_dev *pmf);
diff --git a/drivers/platform/x86/amd/pmf/sps.c b/drivers/platform/x86/amd/pmf/sps.c
index 8e75ebd25e21..4f80a73eff9f 100644
--- a/drivers/platform/x86/amd/pmf/sps.c
+++ b/drivers/platform/x86/amd/pmf/sps.c
@@ -285,7 +285,7 @@ bool is_pprof_balanced(struct amd_pmf_dev *pmf)
 static int amd_pmf_profile_get(struct platform_profile_handler *pprof,
 			       enum platform_profile_option *profile)
 {
-	struct amd_pmf_dev *pmf = container_of(pprof, struct amd_pmf_dev, pprof);
+	struct amd_pmf_dev *pmf = dev_get_drvdata(&pprof->class_dev);
 
 	*profile = pmf->current_profile;
 	return 0;
@@ -366,7 +366,7 @@ int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev)
 static int amd_pmf_profile_set(struct platform_profile_handler *pprof,
 			       enum platform_profile_option profile)
 {
-	struct amd_pmf_dev *pmf = container_of(pprof, struct amd_pmf_dev, pprof);
+	struct amd_pmf_dev *pmf = dev_get_drvdata(&pprof->class_dev);
 	int ret = 0;
 
 	pmf->current_profile = profile;
@@ -425,15 +425,10 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev)
 	dev->pprof.ops = &amd_pmf_profile_ops;
 
 	/* Create platform_profile structure and register */
-	err = platform_profile_register(&dev->pprof, NULL);
+	err = devm_platform_profile_register(&dev->pprof, dev);
 	if (err)
 		dev_err(dev->dev, "Failed to register SPS support, this is most likely an SBIOS bug: %d\n",
 			err);
 
 	return err;
 }
-
-void amd_pmf_deinit_sps(struct amd_pmf_dev *dev)
-{
-	platform_profile_remove(&dev->pprof);
-}
-- 
2.47.1
Re: [PATCH 07/18] platform/x86: amd: pmf: sps: Use devm_platform_profile_register()
Posted by Mario Limonciello 11 months, 2 weeks ago
On 1/9/2025 09:06, Kurt Borja wrote:
> Replace platform_profile_register() with it's device managed version.
> While at it, pass amd_pmf_dev to the class device as drvdata and replace
> uses of container_of() with dev_get_drvdata().
> 
> Signed-off-by: Kurt Borja <kuurtb@gmail.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
>   drivers/platform/x86/amd/pmf/core.c |  1 -
>   drivers/platform/x86/amd/pmf/pmf.h  |  1 -
>   drivers/platform/x86/amd/pmf/sps.c  | 11 +++--------
>   3 files changed, 3 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c
> index 57ee95a327be..1211a753fee8 100644
> --- a/drivers/platform/x86/amd/pmf/core.c
> +++ b/drivers/platform/x86/amd/pmf/core.c
> @@ -371,7 +371,6 @@ static void amd_pmf_deinit_features(struct amd_pmf_dev *dev)
>   	if (is_apmf_func_supported(dev, APMF_FUNC_STATIC_SLIDER_GRANULAR) ||
>   	    is_apmf_func_supported(dev, APMF_FUNC_OS_POWER_SLIDER_UPDATE)) {
>   		power_supply_unreg_notifier(&dev->pwr_src_notifier);
> -		amd_pmf_deinit_sps(dev);
>   	}
>   
>   	if (dev->smart_pc_enabled) {
> diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h
> index 56024eb40266..198bfe3306be 100644
> --- a/drivers/platform/x86/amd/pmf/pmf.h
> +++ b/drivers/platform/x86/amd/pmf/pmf.h
> @@ -764,7 +764,6 @@ int amd_pmf_get_pprof_modes(struct amd_pmf_dev *pmf);
>   void amd_pmf_update_slider(struct amd_pmf_dev *dev, bool op, int idx,
>   			   struct amd_pmf_static_slider_granular *table);
>   int amd_pmf_init_sps(struct amd_pmf_dev *dev);
> -void amd_pmf_deinit_sps(struct amd_pmf_dev *dev);
>   int apmf_get_static_slider_granular(struct amd_pmf_dev *pdev,
>   				    struct apmf_static_slider_granular_output *output);
>   bool is_pprof_balanced(struct amd_pmf_dev *pmf);
> diff --git a/drivers/platform/x86/amd/pmf/sps.c b/drivers/platform/x86/amd/pmf/sps.c
> index 8e75ebd25e21..4f80a73eff9f 100644
> --- a/drivers/platform/x86/amd/pmf/sps.c
> +++ b/drivers/platform/x86/amd/pmf/sps.c
> @@ -285,7 +285,7 @@ bool is_pprof_balanced(struct amd_pmf_dev *pmf)
>   static int amd_pmf_profile_get(struct platform_profile_handler *pprof,
>   			       enum platform_profile_option *profile)
>   {
> -	struct amd_pmf_dev *pmf = container_of(pprof, struct amd_pmf_dev, pprof);
> +	struct amd_pmf_dev *pmf = dev_get_drvdata(&pprof->class_dev);
>   
>   	*profile = pmf->current_profile;
>   	return 0;
> @@ -366,7 +366,7 @@ int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev)
>   static int amd_pmf_profile_set(struct platform_profile_handler *pprof,
>   			       enum platform_profile_option profile)
>   {
> -	struct amd_pmf_dev *pmf = container_of(pprof, struct amd_pmf_dev, pprof);
> +	struct amd_pmf_dev *pmf = dev_get_drvdata(&pprof->class_dev);
>   	int ret = 0;
>   
>   	pmf->current_profile = profile;
> @@ -425,15 +425,10 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev)
>   	dev->pprof.ops = &amd_pmf_profile_ops;
>   
>   	/* Create platform_profile structure and register */
> -	err = platform_profile_register(&dev->pprof, NULL);
> +	err = devm_platform_profile_register(&dev->pprof, dev);
>   	if (err)
>   		dev_err(dev->dev, "Failed to register SPS support, this is most likely an SBIOS bug: %d\n",
>   			err);
>   
>   	return err;
>   }
> -
> -void amd_pmf_deinit_sps(struct amd_pmf_dev *dev)
> -{
> -	platform_profile_remove(&dev->pprof);
> -}