diff options
Diffstat (limited to 'drivers/power/supply/wm831x_power.c')
| -rw-r--r-- | drivers/power/supply/wm831x_power.c | 77 |
1 files changed, 36 insertions, 41 deletions
diff --git a/drivers/power/supply/wm831x_power.c b/drivers/power/supply/wm831x_power.c index 927050d4444d..78fa0573ef25 100644 --- a/drivers/power/supply/wm831x_power.c +++ b/drivers/power/supply/wm831x_power.c @@ -1,11 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * PMU driver for Wolfson Microelectronics wm831x PMICs * * Copyright 2009 Wolfson Microelectronics PLC. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. */ #include <linux/module.h> @@ -92,7 +89,7 @@ static int wm831x_wall_get_prop(struct power_supply *psy, return ret; } -static enum power_supply_property wm831x_wall_props[] = { +static const enum power_supply_property wm831x_wall_props[] = { POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_VOLTAGE_NOW, }; @@ -123,7 +120,7 @@ static int wm831x_usb_get_prop(struct power_supply *psy, return ret; } -static enum power_supply_property wm831x_usb_props[] = { +static const enum power_supply_property wm831x_usb_props[] = { POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_VOLTAGE_NOW, }; @@ -147,6 +144,7 @@ static int wm831x_usb_limit_change(struct notifier_block *nb, struct wm831x_power, usb_notify); unsigned int i, best; + int ret; /* Find the highest supported limit */ best = 0; @@ -159,8 +157,13 @@ static int wm831x_usb_limit_change(struct notifier_block *nb, dev_dbg(wm831x_power->wm831x->dev, "Limiting USB current to %umA", wm831x_usb_limits[best]); - wm831x_set_bits(wm831x_power->wm831x, WM831X_POWER_STATE, - WM831X_USB_ILIM_MASK, best); + ret = wm831x_set_bits(wm831x_power->wm831x, WM831X_POWER_STATE, + WM831X_USB_ILIM_MASK, best); + if (ret < 0) { + dev_err(wm831x_power->wm831x->dev, + "Failed to set USB current limit: %d\n", ret); + return ret; + } return 0; } @@ -174,21 +177,21 @@ struct chg_map { int reg_val; }; -static struct chg_map trickle_ilims[] = { +static const struct chg_map trickle_ilims[] = { { 50, 0 << WM831X_CHG_TRKL_ILIM_SHIFT }, { 100, 1 << WM831X_CHG_TRKL_ILIM_SHIFT }, { 150, 2 << WM831X_CHG_TRKL_ILIM_SHIFT }, { 200, 3 << WM831X_CHG_TRKL_ILIM_SHIFT }, }; -static struct chg_map vsels[] = { +static const struct chg_map vsels[] = { { 4050, 0 << WM831X_CHG_VSEL_SHIFT }, { 4100, 1 << WM831X_CHG_VSEL_SHIFT }, { 4150, 2 << WM831X_CHG_VSEL_SHIFT }, { 4200, 3 << WM831X_CHG_VSEL_SHIFT }, }; -static struct chg_map fast_ilims[] = { +static const struct chg_map fast_ilims[] = { { 0, 0 << WM831X_CHG_FAST_ILIM_SHIFT }, { 50, 1 << WM831X_CHG_FAST_ILIM_SHIFT }, { 100, 2 << WM831X_CHG_FAST_ILIM_SHIFT }, @@ -207,7 +210,7 @@ static struct chg_map fast_ilims[] = { { 1000, 15 << WM831X_CHG_FAST_ILIM_SHIFT }, }; -static struct chg_map eoc_iterms[] = { +static const struct chg_map eoc_iterms[] = { { 20, 0 << WM831X_CHG_ITERM_SHIFT }, { 30, 1 << WM831X_CHG_ITERM_SHIFT }, { 40, 2 << WM831X_CHG_ITERM_SHIFT }, @@ -218,7 +221,7 @@ static struct chg_map eoc_iterms[] = { { 90, 7 << WM831X_CHG_ITERM_SHIFT }, }; -static struct chg_map chg_times[] = { +static const struct chg_map chg_times[] = { { 60, 0 << WM831X_CHG_TIME_SHIFT }, { 90, 1 << WM831X_CHG_TIME_SHIFT }, { 120, 2 << WM831X_CHG_TIME_SHIFT }, @@ -237,8 +240,8 @@ static struct chg_map chg_times[] = { { 510, 15 << WM831X_CHG_TIME_SHIFT }, }; -static void wm831x_battey_apply_config(struct wm831x *wm831x, - struct chg_map *map, int count, int val, +static void wm831x_battery_apply_config(struct wm831x *wm831x, + const struct chg_map *map, int count, int val, int *reg, const char *name, const char *units) { @@ -284,24 +287,24 @@ static void wm831x_config_battery(struct wm831x *wm831x) if (pdata->fast_enable) reg1 |= WM831X_CHG_FAST; - wm831x_battey_apply_config(wm831x, trickle_ilims, + wm831x_battery_apply_config(wm831x, trickle_ilims, ARRAY_SIZE(trickle_ilims), pdata->trickle_ilim, ®2, "trickle charge current limit", "mA"); - wm831x_battey_apply_config(wm831x, vsels, ARRAY_SIZE(vsels), + wm831x_battery_apply_config(wm831x, vsels, ARRAY_SIZE(vsels), pdata->vsel, ®2, "target voltage", "mV"); - wm831x_battey_apply_config(wm831x, fast_ilims, ARRAY_SIZE(fast_ilims), + wm831x_battery_apply_config(wm831x, fast_ilims, ARRAY_SIZE(fast_ilims), pdata->fast_ilim, ®2, "fast charge current limit", "mA"); - wm831x_battey_apply_config(wm831x, eoc_iterms, ARRAY_SIZE(eoc_iterms), + wm831x_battery_apply_config(wm831x, eoc_iterms, ARRAY_SIZE(eoc_iterms), pdata->eoc_iterm, ®1, "end of charge current threshold", "mA"); - wm831x_battey_apply_config(wm831x, chg_times, ARRAY_SIZE(chg_times), + wm831x_battery_apply_config(wm831x, chg_times, ARRAY_SIZE(chg_times), pdata->timeout, ®2, "charger timeout", "min"); @@ -465,7 +468,7 @@ static int wm831x_bat_get_prop(struct power_supply *psy, return ret; } -static enum power_supply_property wm831x_bat_props[] = { +static const enum power_supply_property wm831x_bat_props[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_VOLTAGE_NOW, @@ -473,7 +476,7 @@ static enum power_supply_property wm831x_bat_props[] = { POWER_SUPPLY_PROP_CHARGE_TYPE, }; -static const char *wm831x_bat_irqs[] = { +static const char * const wm831x_bat_irqs[] = { "BATT HOT", "BATT COLD", "BATT FAIL", @@ -573,8 +576,9 @@ static int wm831x_power_probe(struct platform_device *pdev) power->wall_desc.properties = wm831x_wall_props; power->wall_desc.num_properties = ARRAY_SIZE(wm831x_wall_props); power->wall_desc.get_property = wm831x_wall_get_prop; - power->wall = power_supply_register(&pdev->dev, &power->wall_desc, - NULL); + power->wall = devm_power_supply_register(&pdev->dev, + &power->wall_desc, + NULL); if (IS_ERR(power->wall)) { ret = PTR_ERR(power->wall); goto err; @@ -585,7 +589,9 @@ static int wm831x_power_probe(struct platform_device *pdev) power->usb_desc.properties = wm831x_usb_props; power->usb_desc.num_properties = ARRAY_SIZE(wm831x_usb_props); power->usb_desc.get_property = wm831x_usb_get_prop; - power->usb = power_supply_register(&pdev->dev, &power->usb_desc, NULL); + power->usb = devm_power_supply_register(&pdev->dev, + &power->usb_desc, + NULL); if (IS_ERR(power->usb)) { ret = PTR_ERR(power->usb); goto err_wall; @@ -602,9 +608,9 @@ static int wm831x_power_probe(struct platform_device *pdev) power->battery_desc.num_properties = ARRAY_SIZE(wm831x_bat_props); power->battery_desc.get_property = wm831x_bat_get_prop; power->battery_desc.use_for_apm = 1; - power->battery = power_supply_register(&pdev->dev, - &power->battery_desc, - NULL); + power->battery = devm_power_supply_register(&pdev->dev, + &power->battery_desc, + NULL); if (IS_ERR(power->battery)) { ret = PTR_ERR(power->battery); goto err_usb; @@ -668,10 +674,9 @@ static int wm831x_power_probe(struct platform_device *pdev) break; default: dev_err(&pdev->dev, "Failed to find USB phy: %d\n", ret); - /* fall-through */ + fallthrough; case -EPROBE_DEFER: goto err_bat_irq; - break; } return ret; @@ -688,17 +693,13 @@ err_syslo: irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "SYSLO")); free_irq(irq, power); err_battery: - if (power->have_battery) - power_supply_unregister(power->battery); err_usb: - power_supply_unregister(power->usb); err_wall: - power_supply_unregister(power->wall); err: return ret; } -static int wm831x_power_remove(struct platform_device *pdev) +static void wm831x_power_remove(struct platform_device *pdev) { struct wm831x_power *wm831x_power = platform_get_drvdata(pdev); struct wm831x *wm831x = wm831x_power->wm831x; @@ -721,12 +722,6 @@ static int wm831x_power_remove(struct platform_device *pdev) irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "SYSLO")); free_irq(irq, wm831x_power); - - if (wm831x_power->have_battery) - power_supply_unregister(wm831x_power->battery); - power_supply_unregister(wm831x_power->wall); - power_supply_unregister(wm831x_power->usb); - return 0; } static struct platform_driver wm831x_power_driver = { |
