[39/46] power: tosa: simplify probe function
diff mbox series

Message ID 20191018154201.1276638-39-arnd@arndb.de
State New
Headers show
Series
  • ARM: pxa: towards multiplatform support
Related show

Commit Message

Arnd Bergmann Oct. 18, 2019, 3:41 p.m. UTC
We have three power supplies that need similar initialization.
As a preparation for the gpio lookup table conversion, split
out the initialization into a separate function.

Cc: Sebastian Reichel <sre@kernel.org>
Cc: linux-pm@vger.kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/power/supply/tosa_battery.c | 50 ++++++++++++++---------------
 1 file changed, 24 insertions(+), 26 deletions(-)

Comments

Sebastian Reichel Oct. 19, 2019, 9:07 a.m. UTC | #1
Hi Arnd,

On Fri, Oct 18, 2019 at 05:41:54PM +0200, Arnd Bergmann wrote:
> We have three power supplies that need similar initialization.
> As a preparation for the gpio lookup table conversion, split
> out the initialization into a separate function.
> 
> Cc: Sebastian Reichel <sre@kernel.org>
> Cc: linux-pm@vger.kernel.org
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---

Assuming, that the whole series goes through ARM:

Reviewed-by: Sebastian Reichel <sre@kernel.org>
Acked-by: Sebastian Reichel <sre@kernel.org>

If the series doesn't make it into 5.5, I can also apply
this cleanup patch.

-- Sebastian

>  drivers/power/supply/tosa_battery.c | 50 ++++++++++++++---------------
>  1 file changed, 24 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/power/supply/tosa_battery.c b/drivers/power/supply/tosa_battery.c
> index 32cc31cd4761..b26b0eca33e1 100644
> --- a/drivers/power/supply/tosa_battery.c
> +++ b/drivers/power/supply/tosa_battery.c
> @@ -343,12 +343,24 @@ static int tosa_bat_resume(struct platform_device *dev)
>  #define tosa_bat_resume NULL
>  #endif
>  
> +static int tosa_power_supply_register(struct device *dev,
> +			struct tosa_bat *bat,
> +			const struct power_supply_desc *desc)
> +{
> +	struct power_supply_config cfg = {
> +		.drv_data = bat,
> +	};
> +
> +	mutex_init(&bat->work_lock);
> +	bat->psy = power_supply_register(dev, desc, &cfg);
> +
> +	return PTR_ERR_OR_ZERO(bat->psy);
> +}
> +
> +
>  static int tosa_bat_probe(struct platform_device *dev)
>  {
>  	int ret;
> -	struct power_supply_config main_psy_cfg = {},
> -				   jacket_psy_cfg = {},
> -				   bu_psy_cfg = {};
>  
>  	if (!machine_is_tosa())
>  		return -ENODEV;
> @@ -357,36 +369,22 @@ static int tosa_bat_probe(struct platform_device *dev)
>  	if (ret)
>  		return ret;
>  
> -	mutex_init(&tosa_bat_main.work_lock);
> -	mutex_init(&tosa_bat_jacket.work_lock);
> -
>  	INIT_WORK(&bat_work, tosa_bat_work);
>  
> -	main_psy_cfg.drv_data = &tosa_bat_main;
> -	tosa_bat_main.psy = power_supply_register(&dev->dev,
> -						  &tosa_bat_main_desc,
> -						  &main_psy_cfg);
> -	if (IS_ERR(tosa_bat_main.psy)) {
> -		ret = PTR_ERR(tosa_bat_main.psy);
> +	ret = tosa_power_supply_register(&dev->dev, &tosa_bat_main,
> +					 &tosa_bat_main_desc);
> +	if (ret)
>  		goto err_psy_reg_main;
> -	}
>  
> -	jacket_psy_cfg.drv_data = &tosa_bat_jacket;
> -	tosa_bat_jacket.psy = power_supply_register(&dev->dev,
> -						    &tosa_bat_jacket_desc,
> -						    &jacket_psy_cfg);
> -	if (IS_ERR(tosa_bat_jacket.psy)) {
> -		ret = PTR_ERR(tosa_bat_jacket.psy);
> +	ret = tosa_power_supply_register(&dev->dev, &tosa_bat_jacket,
> +					 &tosa_bat_jacket_desc);
> +	if (ret)
>  		goto err_psy_reg_jacket;
> -	}
>  
> -	bu_psy_cfg.drv_data = &tosa_bat_bu;
> -	tosa_bat_bu.psy = power_supply_register(&dev->dev, &tosa_bat_bu_desc,
> -						&bu_psy_cfg);
> -	if (IS_ERR(tosa_bat_bu.psy)) {
> -		ret = PTR_ERR(tosa_bat_bu.psy);
> +	ret = tosa_power_supply_register(&dev->dev, &tosa_bat_bu,
> +					 &tosa_bat_bu_desc);
> +	if (ret)
>  		goto err_psy_reg_bu;
> -	}
>  
>  	ret = request_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG),
>  				tosa_bat_gpio_isr,
> -- 
> 2.20.0
>
Robert Jarzmik Oct. 30, 2019, 9:12 p.m. UTC | #2
Sebastian Reichel <sre@kernel.org> writes:

> Hi Arnd,
>
> On Fri, Oct 18, 2019 at 05:41:54PM +0200, Arnd Bergmann wrote:
>> We have three power supplies that need similar initialization.
>> As a preparation for the gpio lookup table conversion, split
>> out the initialization into a separate function.
>> 
>> Cc: Sebastian Reichel <sre@kernel.org>
>> Cc: linux-pm@vger.kernel.org
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> ---
>
> Assuming, that the whole series goes through ARM:
>
> Reviewed-by: Sebastian Reichel <sre@kernel.org>
> Acked-by: Sebastian Reichel <sre@kernel.org>
>
> If the series doesn't make it into 5.5, I can also apply
> this cleanup patch.
>
> -- Sebastian
Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>

Cheers.

--
Robert
Robert Jarzmik Oct. 30, 2019, 9:21 p.m. UTC | #3
Sebastian Reichel <sre@kernel.org> writes:

> Hi Arnd,
>
> On Fri, Oct 18, 2019 at 05:41:54PM +0200, Arnd Bergmann wrote:
>> We have three power supplies that need similar initialization.
>> As a preparation for the gpio lookup table conversion, split
>> out the initialization into a separate function.
>> 
>> Cc: Sebastian Reichel <sre@kernel.org>
>> Cc: linux-pm@vger.kernel.org
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> ---
>
> Assuming, that the whole series goes through ARM:
>
> Reviewed-by: Sebastian Reichel <sre@kernel.org>
> Acked-by: Sebastian Reichel <sre@kernel.org>
>
> If the series doesn't make it into 5.5, I can also apply
> this cleanup patch.
>
> -- Sebastian
Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>

Cheers.

--
Robert

Patch
diff mbox series

diff --git a/drivers/power/supply/tosa_battery.c b/drivers/power/supply/tosa_battery.c
index 32cc31cd4761..b26b0eca33e1 100644
--- a/drivers/power/supply/tosa_battery.c
+++ b/drivers/power/supply/tosa_battery.c
@@ -343,12 +343,24 @@  static int tosa_bat_resume(struct platform_device *dev)
 #define tosa_bat_resume NULL
 #endif
 
+static int tosa_power_supply_register(struct device *dev,
+			struct tosa_bat *bat,
+			const struct power_supply_desc *desc)
+{
+	struct power_supply_config cfg = {
+		.drv_data = bat,
+	};
+
+	mutex_init(&bat->work_lock);
+	bat->psy = power_supply_register(dev, desc, &cfg);
+
+	return PTR_ERR_OR_ZERO(bat->psy);
+}
+
+
 static int tosa_bat_probe(struct platform_device *dev)
 {
 	int ret;
-	struct power_supply_config main_psy_cfg = {},
-				   jacket_psy_cfg = {},
-				   bu_psy_cfg = {};
 
 	if (!machine_is_tosa())
 		return -ENODEV;
@@ -357,36 +369,22 @@  static int tosa_bat_probe(struct platform_device *dev)
 	if (ret)
 		return ret;
 
-	mutex_init(&tosa_bat_main.work_lock);
-	mutex_init(&tosa_bat_jacket.work_lock);
-
 	INIT_WORK(&bat_work, tosa_bat_work);
 
-	main_psy_cfg.drv_data = &tosa_bat_main;
-	tosa_bat_main.psy = power_supply_register(&dev->dev,
-						  &tosa_bat_main_desc,
-						  &main_psy_cfg);
-	if (IS_ERR(tosa_bat_main.psy)) {
-		ret = PTR_ERR(tosa_bat_main.psy);
+	ret = tosa_power_supply_register(&dev->dev, &tosa_bat_main,
+					 &tosa_bat_main_desc);
+	if (ret)
 		goto err_psy_reg_main;
-	}
 
-	jacket_psy_cfg.drv_data = &tosa_bat_jacket;
-	tosa_bat_jacket.psy = power_supply_register(&dev->dev,
-						    &tosa_bat_jacket_desc,
-						    &jacket_psy_cfg);
-	if (IS_ERR(tosa_bat_jacket.psy)) {
-		ret = PTR_ERR(tosa_bat_jacket.psy);
+	ret = tosa_power_supply_register(&dev->dev, &tosa_bat_jacket,
+					 &tosa_bat_jacket_desc);
+	if (ret)
 		goto err_psy_reg_jacket;
-	}
 
-	bu_psy_cfg.drv_data = &tosa_bat_bu;
-	tosa_bat_bu.psy = power_supply_register(&dev->dev, &tosa_bat_bu_desc,
-						&bu_psy_cfg);
-	if (IS_ERR(tosa_bat_bu.psy)) {
-		ret = PTR_ERR(tosa_bat_bu.psy);
+	ret = tosa_power_supply_register(&dev->dev, &tosa_bat_bu,
+					 &tosa_bat_bu_desc);
+	if (ret)
 		goto err_psy_reg_bu;
-	}
 
 	ret = request_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG),
 				tosa_bat_gpio_isr,