Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH v3] power:  smb347_charger: Use device managed API's
@ 2016-12-10 11:08 Atul Raj
  2016-12-17 15:35 ` Sebastian Reichel
  0 siblings, 1 reply; 2+ messages in thread
From: Atul Raj @ 2016-12-10 11:08 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, vidushi.koul, atulraj.nith, pankaj.s4

Using device managed API to make the code simpler

using devm_gpio_request_one in place of gpio_request_one
using devm_request_threaded_irq in place of request_threaded_irq
using devm_power_supply_register in place of power_supply_register
using gpiod_* API's in place of gpio_* API's

Signed-off-by: Atul Raj <atul.r@samsung.com>
---
Changes in v2:
  - using gpiod_* API's in place of gpio_* API's

Changes in v3
  - chaning suject as per directory in file path in supply git
    adding signoff
    sorry for wrong v2 patch. Kindly ignore v2.

 drivers/power/smb347-charger.c |   59 ++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 35 deletions(-)

diff --git a/drivers/power/smb347-charger.c b/drivers/power/smb347-charger.c
index 072c518..5b2b5cb 100644
--- a/drivers/power/smb347-charger.c
+++ b/drivers/power/smb347-charger.c
@@ -12,7 +12,7 @@
  */
 
 #include <linux/err.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
@@ -145,6 +145,7 @@ struct smb347_charger {
 	bool			mains_online;
 	bool			usb_online;
 	bool			charging_enabled;
+	struct gpio_desc	*irq_gpio;
 	const struct smb347_charger_platform_data *pdata;
 };
 
@@ -835,21 +836,29 @@ static int smb347_irq_init(struct smb347_charger *smb,
 			   struct i2c_client *client)
 {
 	const struct smb347_charger_platform_data *pdata = smb->pdata;
-	int ret, irq = gpio_to_irq(pdata->irq_gpio);
+	int ret, irq;
+	struct gpio_desc *gpiod;
 
-	ret = gpio_request_one(pdata->irq_gpio, GPIOF_IN, client->name);
-	if (ret < 0)
+	smb->irq_gpio = gpio_to_desc(pdata->irq_gpio);
+	irq = gpiod_to_irq(smb->irq_gpio);
+
+	gpiod = devm_gpiod_get_optional(&client->dev, NULL, GPIOD_IN);
+	if (IS_ERR(gpiod)) {
+		ret = PTR_ERR(gpiod);
 		goto fail;
+	}
 
-	ret = request_threaded_irq(irq, NULL, smb347_interrupt,
-				   IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
-				   client->name, smb);
+
+	ret = devm_request_threaded_irq(&client->dev, irq, NULL,
+				smb347_interrupt,
+				IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+				client->name, smb);
 	if (ret < 0)
-		goto fail_gpio;
+		goto fail;
 
 	ret = smb347_set_writable(smb, true);
 	if (ret < 0)
-		goto fail_irq;
+		goto fail;
 
 	/*
 	 * Configure the STAT output to be suitable for interrupts: disable
@@ -867,10 +876,6 @@ static int smb347_irq_init(struct smb347_charger *smb,
 
 fail_readonly:
 	smb347_set_writable(smb, false);
-fail_irq:
-	free_irq(irq, smb);
-fail_gpio:
-	gpio_free(pdata->irq_gpio);
 fail:
 	client->irq = 0;
 	return ret;
@@ -1249,32 +1254,24 @@ static int smb347_probe(struct i2c_client *client,
 	mains_usb_cfg.num_supplicants = ARRAY_SIZE(battery);
 	mains_usb_cfg.drv_data = smb;
 	if (smb->pdata->use_mains) {
-		smb->mains = power_supply_register(dev, &smb347_mains_desc,
+		smb->mains = devm_power_supply_register(dev, &smb347_mains_desc,
 						   &mains_usb_cfg);
 		if (IS_ERR(smb->mains))
 			return PTR_ERR(smb->mains);
 	}
 
 	if (smb->pdata->use_usb) {
-		smb->usb = power_supply_register(dev, &smb347_usb_desc,
+		smb->usb = devm_power_supply_register(dev, &smb347_usb_desc,
 						 &mains_usb_cfg);
-		if (IS_ERR(smb->usb)) {
-			if (smb->pdata->use_mains)
-				power_supply_unregister(smb->mains);
+		if (IS_ERR(smb->usb))
 			return PTR_ERR(smb->usb);
-		}
 	}
 
 	battery_cfg.drv_data = smb;
-	smb->battery = power_supply_register(dev, &smb347_battery_desc,
+	smb->battery = devm_power_supply_register(dev, &smb347_battery_desc,
 					     &battery_cfg);
-	if (IS_ERR(smb->battery)) {
-		if (smb->pdata->use_usb)
-			power_supply_unregister(smb->usb);
-		if (smb->pdata->use_mains)
-			power_supply_unregister(smb->mains);
+	if (IS_ERR(smb->battery))
 		return PTR_ERR(smb->battery);
-	}
 
 	/*
 	 * Interrupt pin is optional. If it is connected, we setup the
@@ -1297,17 +1294,9 @@ static int smb347_remove(struct i2c_client *client)
 {
 	struct smb347_charger *smb = i2c_get_clientdata(client);
 
-	if (client->irq) {
+	if (client->irq)
 		smb347_irq_disable(smb);
-		free_irq(client->irq, smb);
-		gpio_free(smb->pdata->irq_gpio);
-	}
 
-	power_supply_unregister(smb->battery);
-	if (smb->pdata->use_usb)
-		power_supply_unregister(smb->usb);
-	if (smb->pdata->use_mains)
-		power_supply_unregister(smb->mains);
 	return 0;
 }
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-12-17 15:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-10 11:08 [PATCH v3] power: smb347_charger: Use device managed API's Atul Raj
2016-12-17 15:35 ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox