mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-28 06:34:12 +08:00
power: supply: smb347-charger: Use resource-managed API
Simplify code, more convenient to use with Device Tree. Reviewed-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: David Heidelberg <david@ixit.cz> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
ef805f2177
commit
2d52f7102b
@ -836,21 +836,31 @@ 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);
|
||||
unsigned long irqflags = IRQF_ONESHOT;
|
||||
int ret;
|
||||
|
||||
ret = gpio_request_one(pdata->irq_gpio, GPIOF_IN, client->name);
|
||||
if (ret < 0)
|
||||
goto fail;
|
||||
/* Requesting GPIO for IRQ is only needed in non-DT way */
|
||||
if (!client->irq) {
|
||||
int irq = gpio_to_irq(pdata->irq_gpio);
|
||||
|
||||
ret = request_threaded_irq(irq, NULL, smb347_interrupt,
|
||||
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
|
||||
client->name, smb);
|
||||
ret = devm_gpio_request_one(smb->dev, pdata->irq_gpio,
|
||||
GPIOF_IN, client->name);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
irqflags |= IRQF_TRIGGER_FALLING;
|
||||
client->irq = irq;
|
||||
}
|
||||
|
||||
ret = devm_request_threaded_irq(smb->dev, client->irq, NULL,
|
||||
smb347_interrupt, irqflags,
|
||||
client->name, smb);
|
||||
if (ret < 0)
|
||||
goto fail_gpio;
|
||||
return ret;
|
||||
|
||||
ret = smb347_set_writable(smb, true);
|
||||
if (ret < 0)
|
||||
goto fail_irq;
|
||||
return ret;
|
||||
|
||||
/*
|
||||
* Configure the STAT output to be suitable for interrupts: disable
|
||||
@ -860,20 +870,10 @@ static int smb347_irq_init(struct smb347_charger *smb,
|
||||
CFG_STAT_ACTIVE_HIGH | CFG_STAT_DISABLED,
|
||||
CFG_STAT_DISABLED);
|
||||
if (ret < 0)
|
||||
goto fail_readonly;
|
||||
client->irq = 0;
|
||||
|
||||
smb347_set_writable(smb, false);
|
||||
client->irq = irq;
|
||||
return 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1251,32 +1251,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,
|
||||
&mains_usb_cfg);
|
||||
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,
|
||||
&mains_usb_cfg);
|
||||
if (IS_ERR(smb->usb)) {
|
||||
if (smb->pdata->use_mains)
|
||||
power_supply_unregister(smb->mains);
|
||||
smb->usb = devm_power_supply_register(dev, &smb347_usb_desc,
|
||||
&mains_usb_cfg);
|
||||
if (IS_ERR(smb->usb))
|
||||
return PTR_ERR(smb->usb);
|
||||
}
|
||||
}
|
||||
|
||||
battery_cfg.drv_data = smb;
|
||||
smb->battery = 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);
|
||||
smb->battery = devm_power_supply_register(dev, &smb347_battery_desc,
|
||||
&battery_cfg);
|
||||
if (IS_ERR(smb->battery))
|
||||
return PTR_ERR(smb->battery);
|
||||
}
|
||||
|
||||
/*
|
||||
* Interrupt pin is optional. If it is connected, we setup the
|
||||
@ -1299,17 +1291,8 @@ 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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user