Commit 0df2deea authored by Vaishali Thakkar's avatar Vaishali Thakkar Committed by Sebastian Reichel

max8903_charger: Convert to using managed resources

Use managed resource functions devm_request_threaded_irq and
devm_power_supply_register to simplify error handling.

To be compatible with the change, various gotos are replaced
with direct returns and unneeded labels are dropped. Also,
remove max8903_remove as it is now redundant.
Signed-off-by: default avatarVaishali Thakkar <vthakkar1994@gmail.com>
Signed-off-by: default avatarSebastian Reichel <sre@kernel.org>
parent 50bddb99
...@@ -201,8 +201,7 @@ static int max8903_probe(struct platform_device *pdev) ...@@ -201,8 +201,7 @@ static int max8903_probe(struct platform_device *pdev)
if (pdata->dc_valid == false && pdata->usb_valid == false) { if (pdata->dc_valid == false && pdata->usb_valid == false) {
dev_err(dev, "No valid power sources.\n"); dev_err(dev, "No valid power sources.\n");
ret = -EINVAL; return -EINVAL;
goto err;
} }
if (pdata->dc_valid) { if (pdata->dc_valid) {
...@@ -216,8 +215,7 @@ static int max8903_probe(struct platform_device *pdev) ...@@ -216,8 +215,7 @@ static int max8903_probe(struct platform_device *pdev)
} else { } else {
dev_err(dev, "When DC is wired, DOK and DCM should" dev_err(dev, "When DC is wired, DOK and DCM should"
" be wired as well.\n"); " be wired as well.\n");
ret = -EINVAL; return -EINVAL;
goto err;
} }
} else { } else {
if (pdata->dcm) { if (pdata->dcm) {
...@@ -225,8 +223,7 @@ static int max8903_probe(struct platform_device *pdev) ...@@ -225,8 +223,7 @@ static int max8903_probe(struct platform_device *pdev)
gpio_set_value(pdata->dcm, 0); gpio_set_value(pdata->dcm, 0);
else { else {
dev_err(dev, "Invalid pin: dcm.\n"); dev_err(dev, "Invalid pin: dcm.\n");
ret = -EINVAL; return -EINVAL;
goto err;
} }
} }
} }
...@@ -238,8 +235,7 @@ static int max8903_probe(struct platform_device *pdev) ...@@ -238,8 +235,7 @@ static int max8903_probe(struct platform_device *pdev)
} else { } else {
dev_err(dev, "When USB is wired, UOK should be wired." dev_err(dev, "When USB is wired, UOK should be wired."
"as well.\n"); "as well.\n");
ret = -EINVAL; return -EINVAL;
goto err;
} }
} }
...@@ -248,32 +244,28 @@ static int max8903_probe(struct platform_device *pdev) ...@@ -248,32 +244,28 @@ static int max8903_probe(struct platform_device *pdev)
gpio_set_value(pdata->cen, (ta_in || usb_in) ? 0 : 1); gpio_set_value(pdata->cen, (ta_in || usb_in) ? 0 : 1);
} else { } else {
dev_err(dev, "Invalid pin: cen.\n"); dev_err(dev, "Invalid pin: cen.\n");
ret = -EINVAL; return -EINVAL;
goto err;
} }
} }
if (pdata->chg) { if (pdata->chg) {
if (!gpio_is_valid(pdata->chg)) { if (!gpio_is_valid(pdata->chg)) {
dev_err(dev, "Invalid pin: chg.\n"); dev_err(dev, "Invalid pin: chg.\n");
ret = -EINVAL; return -EINVAL;
goto err;
} }
} }
if (pdata->flt) { if (pdata->flt) {
if (!gpio_is_valid(pdata->flt)) { if (!gpio_is_valid(pdata->flt)) {
dev_err(dev, "Invalid pin: flt.\n"); dev_err(dev, "Invalid pin: flt.\n");
ret = -EINVAL; return -EINVAL;
goto err;
} }
} }
if (pdata->usus) { if (pdata->usus) {
if (!gpio_is_valid(pdata->usus)) { if (!gpio_is_valid(pdata->usus)) {
dev_err(dev, "Invalid pin: usus.\n"); dev_err(dev, "Invalid pin: usus.\n");
ret = -EINVAL; return -EINVAL;
goto err;
} }
} }
...@@ -291,77 +283,49 @@ static int max8903_probe(struct platform_device *pdev) ...@@ -291,77 +283,49 @@ static int max8903_probe(struct platform_device *pdev)
psy_cfg.drv_data = data; psy_cfg.drv_data = data;
data->psy = power_supply_register(dev, &data->psy_desc, &psy_cfg); data->psy = devm_power_supply_register(dev, &data->psy_desc, &psy_cfg);
if (IS_ERR(data->psy)) { if (IS_ERR(data->psy)) {
dev_err(dev, "failed: power supply register.\n"); dev_err(dev, "failed: power supply register.\n");
ret = PTR_ERR(data->psy); return PTR_ERR(data->psy);
goto err;
} }
if (pdata->dc_valid) { if (pdata->dc_valid) {
ret = request_threaded_irq(gpio_to_irq(pdata->dok), ret = devm_request_threaded_irq(dev, gpio_to_irq(pdata->dok),
NULL, max8903_dcin, NULL, max8903_dcin,
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, IRQF_TRIGGER_FALLING |
IRQF_TRIGGER_RISING,
"MAX8903 DC IN", data); "MAX8903 DC IN", data);
if (ret) { if (ret) {
dev_err(dev, "Cannot request irq %d for DC (%d)\n", dev_err(dev, "Cannot request irq %d for DC (%d)\n",
gpio_to_irq(pdata->dok), ret); gpio_to_irq(pdata->dok), ret);
goto err_psy; return ret;
} }
} }
if (pdata->usb_valid) { if (pdata->usb_valid) {
ret = request_threaded_irq(gpio_to_irq(pdata->uok), ret = devm_request_threaded_irq(dev, gpio_to_irq(pdata->uok),
NULL, max8903_usbin, NULL, max8903_usbin,
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, IRQF_TRIGGER_FALLING |
IRQF_TRIGGER_RISING,
"MAX8903 USB IN", data); "MAX8903 USB IN", data);
if (ret) { if (ret) {
dev_err(dev, "Cannot request irq %d for USB (%d)\n", dev_err(dev, "Cannot request irq %d for USB (%d)\n",
gpio_to_irq(pdata->uok), ret); gpio_to_irq(pdata->uok), ret);
goto err_dc_irq; return ret;
} }
} }
if (pdata->flt) { if (pdata->flt) {
ret = request_threaded_irq(gpio_to_irq(pdata->flt), ret = devm_request_threaded_irq(dev, gpio_to_irq(pdata->flt),
NULL, max8903_fault, NULL, max8903_fault,
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, IRQF_TRIGGER_FALLING |
IRQF_TRIGGER_RISING,
"MAX8903 Fault", data); "MAX8903 Fault", data);
if (ret) { if (ret) {
dev_err(dev, "Cannot request irq %d for Fault (%d)\n", dev_err(dev, "Cannot request irq %d for Fault (%d)\n",
gpio_to_irq(pdata->flt), ret); gpio_to_irq(pdata->flt), ret);
goto err_usb_irq;
}
}
return 0;
err_usb_irq:
if (pdata->usb_valid)
free_irq(gpio_to_irq(pdata->uok), data);
err_dc_irq:
if (pdata->dc_valid)
free_irq(gpio_to_irq(pdata->dok), data);
err_psy:
power_supply_unregister(data->psy);
err:
return ret; return ret;
} }
static int max8903_remove(struct platform_device *pdev)
{
struct max8903_data *data = platform_get_drvdata(pdev);
if (data) {
struct max8903_pdata *pdata = &data->pdata;
if (pdata->flt)
free_irq(gpio_to_irq(pdata->flt), data);
if (pdata->usb_valid)
free_irq(gpio_to_irq(pdata->uok), data);
if (pdata->dc_valid)
free_irq(gpio_to_irq(pdata->dok), data);
power_supply_unregister(data->psy);
} }
return 0; return 0;
...@@ -369,7 +333,6 @@ static int max8903_remove(struct platform_device *pdev) ...@@ -369,7 +333,6 @@ static int max8903_remove(struct platform_device *pdev)
static struct platform_driver max8903_driver = { static struct platform_driver max8903_driver = {
.probe = max8903_probe, .probe = max8903_probe,
.remove = max8903_remove,
.driver = { .driver = {
.name = "max8903-charger", .name = "max8903-charger",
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment