From: Atul Raj <atul.r@samsung.com>
To: Sebastian Reichel <sre@kernel.org>
Cc: linux-pm@vger.kernel.org, vidushi.koul@samsung.com,
atulraj.nith@gmail.com, pankaj.s4@samsung.com
Subject: [PATCH v3] power: smb347_charger: Use device managed API's
Date: Sat, 10 Dec 2016 16:38:31 +0530 [thread overview]
Message-ID: <1481368111-4996-1-git-send-email-atul.r@samsung.com> (raw)
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
next reply other threads:[~2016-12-10 11:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-10 11:08 Atul Raj [this message]
2016-12-17 15:35 ` [PATCH v3] power: smb347_charger: Use device managed API's Sebastian Reichel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1481368111-4996-1-git-send-email-atul.r@samsung.com \
--to=atul.r@samsung.com \
--cc=atulraj.nith@gmail.com \
--cc=linux-pm@vger.kernel.org \
--cc=pankaj.s4@samsung.com \
--cc=sre@kernel.org \
--cc=vidushi.koul@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox