Commit 03add17f authored by Liam Breck's avatar Liam Breck Committed by Sebastian Reichel

power: supply: bq24190_charger: Clean up extcon code

Polishing and fixes for initial extcon patch.

Fixes: 4db249b6f3b4 ("power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost")
Cc: Tony Lindgren <tony@atomide.com>
Signed-off-by: default avatarLiam Breck <kernel@networkimprov.net>
Acked-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarSebastian Reichel <sre@kernel.org>
parent d63d07c6
...@@ -38,8 +38,9 @@ ...@@ -38,8 +38,9 @@
#define BQ24190_REG_POC_WDT_RESET_SHIFT 6 #define BQ24190_REG_POC_WDT_RESET_SHIFT 6
#define BQ24190_REG_POC_CHG_CONFIG_MASK (BIT(5) | BIT(4)) #define BQ24190_REG_POC_CHG_CONFIG_MASK (BIT(5) | BIT(4))
#define BQ24190_REG_POC_CHG_CONFIG_SHIFT 4 #define BQ24190_REG_POC_CHG_CONFIG_SHIFT 4
#define BQ24190_REG_POC_CHG_CONFIG_CHARGE 1 #define BQ24190_REG_POC_CHG_CONFIG_DISABLE 0x0
#define BQ24190_REG_POC_CHG_CONFIG_OTG 2 #define BQ24190_REG_POC_CHG_CONFIG_CHARGE 0x1
#define BQ24190_REG_POC_CHG_CONFIG_OTG 0x2
#define BQ24190_REG_POC_SYS_MIN_MASK (BIT(3) | BIT(2) | BIT(1)) #define BQ24190_REG_POC_SYS_MIN_MASK (BIT(3) | BIT(2) | BIT(1))
#define BQ24190_REG_POC_SYS_MIN_SHIFT 1 #define BQ24190_REG_POC_SYS_MIN_SHIFT 1
#define BQ24190_REG_POC_BOOST_LIM_MASK BIT(0) #define BQ24190_REG_POC_BOOST_LIM_MASK BIT(0)
...@@ -173,8 +174,9 @@ struct bq24190_dev_info { ...@@ -173,8 +174,9 @@ struct bq24190_dev_info {
*/ */
/* REG00[2:0] (IINLIM) in uAh */ /* REG00[2:0] (IINLIM) in uAh */
static const int bq24190_iinlim_values[] = { static const int bq24190_isc_iinlim_values[] = {
100000, 150000, 500000, 900000, 1200000, 1500000, 2000000, 3000000 }; 100000, 150000, 500000, 900000, 1200000, 1500000, 2000000, 3000000
};
/* REG02[7:2] (ICHG) in uAh */ /* REG02[7:2] (ICHG) in uAh */
static const int bq24190_ccc_ichg_values[] = { static const int bq24190_ccc_ichg_values[] = {
...@@ -1298,16 +1300,18 @@ static void bq24190_extcon_work(struct work_struct *work) ...@@ -1298,16 +1300,18 @@ static void bq24190_extcon_work(struct work_struct *work)
{ {
struct bq24190_dev_info *bdi = struct bq24190_dev_info *bdi =
container_of(work, struct bq24190_dev_info, extcon_work.work); container_of(work, struct bq24190_dev_info, extcon_work.work);
int ret, iinlim = 0; int error, iinlim = 0;
u8 v;
ret = pm_runtime_get_sync(bdi->dev); error = pm_runtime_get_sync(bdi->dev);
if (ret < 0) { if (error < 0) {
dev_err(bdi->dev, "Error getting runtime-pm ref: %d\n", ret); dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
pm_runtime_put_noidle(bdi->dev);
return; return;
} }
if (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_SDP) == 1) if (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_SDP) == 1)
iinlim = 500000; iinlim = 500000;
else if (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_CDP) == 1 || else if (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_CDP) == 1 ||
extcon_get_state(bdi->extcon, EXTCON_CHG_USB_ACA) == 1) extcon_get_state(bdi->extcon, EXTCON_CHG_USB_ACA) == 1)
iinlim = 1500000; iinlim = 1500000;
...@@ -1315,33 +1319,28 @@ static void bq24190_extcon_work(struct work_struct *work) ...@@ -1315,33 +1319,28 @@ static void bq24190_extcon_work(struct work_struct *work)
iinlim = 2000000; iinlim = 2000000;
if (iinlim) { if (iinlim) {
ret = bq24190_set_field_val(bdi, BQ24190_REG_ISC, error = bq24190_set_field_val(bdi, BQ24190_REG_ISC,
BQ24190_REG_ISC_IINLIM_MASK, BQ24190_REG_ISC_IINLIM_MASK,
BQ24190_REG_ISC_IINLIM_SHIFT, BQ24190_REG_ISC_IINLIM_SHIFT,
bq24190_iinlim_values, bq24190_isc_iinlim_values,
ARRAY_SIZE(bq24190_iinlim_values), ARRAY_SIZE(bq24190_isc_iinlim_values),
iinlim); iinlim);
if (ret) if (error < 0)
dev_err(bdi->dev, "Can't set IINLIM: %d\n", ret); dev_err(bdi->dev, "Can't set IINLIM: %d\n", error);
} }
/* /* if no charger found and in USB host mode, set OTG 5V boost, else normal */
* If no charger has been detected and host mode is requested, activate if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) == 1)
* the 5V boost converter, otherwise deactivate it. v = BQ24190_REG_POC_CHG_CONFIG_OTG;
*/ else
if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) == 1) { v = BQ24190_REG_POC_CHG_CONFIG_CHARGE;
ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
BQ24190_REG_POC_CHG_CONFIG_MASK, error = bq24190_write_mask(bdi, BQ24190_REG_POC,
BQ24190_REG_POC_CHG_CONFIG_SHIFT, BQ24190_REG_POC_CHG_CONFIG_MASK,
BQ24190_REG_POC_CHG_CONFIG_OTG); BQ24190_REG_POC_CHG_CONFIG_SHIFT,
} else { v);
ret = bq24190_write_mask(bdi, BQ24190_REG_POC, if (error < 0)
BQ24190_REG_POC_CHG_CONFIG_MASK, dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error);
BQ24190_REG_POC_CHG_CONFIG_SHIFT,
BQ24190_REG_POC_CHG_CONFIG_CHARGE);
}
if (ret)
dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", ret);
pm_runtime_mark_last_busy(bdi->dev); pm_runtime_mark_last_busy(bdi->dev);
pm_runtime_put_autosuspend(bdi->dev); pm_runtime_put_autosuspend(bdi->dev);
...@@ -1432,8 +1431,15 @@ static int bq24190_probe(struct i2c_client *client, ...@@ -1432,8 +1431,15 @@ static int bq24190_probe(struct i2c_client *client,
} }
/* /*
* The extcon-name property is purely an in kernel interface for * Devicetree platforms should get extcon via phandle (not yet supported).
* x86/ACPI use, DT platforms should get extcon via phandle. * On ACPI platforms, extcon clients may invoke us with:
* struct property_entry pe[] =
* { PROPERTY_ENTRY_STRING("extcon-name", client_name), ... };
* struct i2c_board_info bi =
* { .type = "bq24190", .addr = 0x6b, .properties = pe, .irq = irq };
* struct i2c_adapter ad = { ... };
* i2c_add_adapter(&ad);
* i2c_new_device(&ad, &bi);
*/ */
if (device_property_read_string(dev, "extcon-name", &name) == 0) { if (device_property_read_string(dev, "extcon-name", &name) == 0) {
bdi->extcon = extcon_get_extcon_dev(name); bdi->extcon = extcon_get_extcon_dev(name);
...@@ -1498,8 +1504,10 @@ static int bq24190_probe(struct i2c_client *client, ...@@ -1498,8 +1504,10 @@ static int bq24190_probe(struct i2c_client *client,
bdi->extcon_nb.notifier_call = bq24190_extcon_event; bdi->extcon_nb.notifier_call = bq24190_extcon_event;
ret = devm_extcon_register_notifier(dev, bdi->extcon, -1, ret = devm_extcon_register_notifier(dev, bdi->extcon, -1,
&bdi->extcon_nb); &bdi->extcon_nb);
if (ret) if (ret) {
dev_err(dev, "Can't register extcon\n");
goto out5; goto out5;
}
/* Sync initial cable state */ /* Sync initial cable state */
queue_delayed_work(system_wq, &bdi->extcon_work, 0); queue_delayed_work(system_wq, &bdi->extcon_work, 0);
......
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