diff options
-rw-r--r-- | drivers/power/supply/bq24735-charger.c | 39 | ||||
-rw-r--r-- | include/linux/power/bq24735-charger.h | 4 |
2 files changed, 12 insertions, 31 deletions
diff --git a/drivers/power/supply/bq24735-charger.c b/drivers/power/supply/bq24735-charger.c index dc460bb03d84..eb7783b42e0a 100644 --- a/drivers/power/supply/bq24735-charger.c +++ b/drivers/power/supply/bq24735-charger.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | #include <linux/of.h> | 27 | #include <linux/of.h> |
28 | #include <linux/of_gpio.h> | 28 | #include <linux/gpio/consumer.h> |
29 | #include <linux/power_supply.h> | 29 | #include <linux/power_supply.h> |
30 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
31 | 31 | ||
@@ -49,6 +49,7 @@ struct bq24735 { | |||
49 | struct i2c_client *client; | 49 | struct i2c_client *client; |
50 | struct bq24735_platform *pdata; | 50 | struct bq24735_platform *pdata; |
51 | struct mutex lock; | 51 | struct mutex lock; |
52 | struct gpio_desc *status_gpio; | ||
52 | bool charging; | 53 | bool charging; |
53 | }; | 54 | }; |
54 | 55 | ||
@@ -177,12 +178,8 @@ static int bq24735_config_charger(struct bq24735 *charger) | |||
177 | 178 | ||
178 | static bool bq24735_charger_is_present(struct bq24735 *charger) | 179 | static bool bq24735_charger_is_present(struct bq24735 *charger) |
179 | { | 180 | { |
180 | struct bq24735_platform *pdata = charger->pdata; | 181 | if (charger->status_gpio) { |
181 | int ret; | 182 | return !gpiod_get_value_cansleep(charger->status_gpio); |
182 | |||
183 | if (pdata->status_gpio_valid) { | ||
184 | ret = gpio_get_value_cansleep(pdata->status_gpio); | ||
185 | return ret ^= pdata->status_gpio_active_low == 0; | ||
186 | } else { | 183 | } else { |
187 | int ac = 0; | 184 | int ac = 0; |
188 | 185 | ||
@@ -308,7 +305,6 @@ static struct bq24735_platform *bq24735_parse_dt_data(struct i2c_client *client) | |||
308 | struct device_node *np = client->dev.of_node; | 305 | struct device_node *np = client->dev.of_node; |
309 | u32 val; | 306 | u32 val; |
310 | int ret; | 307 | int ret; |
311 | enum of_gpio_flags flags; | ||
312 | 308 | ||
313 | pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); | 309 | pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); |
314 | if (!pdata) { | 310 | if (!pdata) { |
@@ -317,12 +313,6 @@ static struct bq24735_platform *bq24735_parse_dt_data(struct i2c_client *client) | |||
317 | return NULL; | 313 | return NULL; |
318 | } | 314 | } |
319 | 315 | ||
320 | pdata->status_gpio = of_get_named_gpio_flags(np, "ti,ac-detect-gpios", | ||
321 | 0, &flags); | ||
322 | |||
323 | if (flags & OF_GPIO_ACTIVE_LOW) | ||
324 | pdata->status_gpio_active_low = 1; | ||
325 | |||
326 | ret = of_property_read_u32(np, "ti,charge-current", &val); | 316 | ret = of_property_read_u32(np, "ti,charge-current", &val); |
327 | if (!ret) | 317 | if (!ret) |
328 | pdata->charge_current = val; | 318 | pdata->charge_current = val; |
@@ -396,21 +386,16 @@ static int bq24735_charger_probe(struct i2c_client *client, | |||
396 | 386 | ||
397 | i2c_set_clientdata(client, charger); | 387 | i2c_set_clientdata(client, charger); |
398 | 388 | ||
399 | if (gpio_is_valid(charger->pdata->status_gpio)) { | 389 | charger->status_gpio = devm_gpiod_get_optional(&client->dev, |
400 | ret = devm_gpio_request(&client->dev, | 390 | "ti,ac-detect", |
401 | charger->pdata->status_gpio, | 391 | GPIOD_IN); |
402 | name); | 392 | if (IS_ERR(charger->status_gpio)) { |
403 | if (ret) { | 393 | ret = PTR_ERR(charger->status_gpio); |
404 | dev_err(&client->dev, | 394 | dev_err(&client->dev, "Getting gpio failed: %d\n", ret); |
405 | "Failed GPIO request for GPIO %d: %d\n", | 395 | return ret; |
406 | charger->pdata->status_gpio, ret); | ||
407 | } | ||
408 | |||
409 | charger->pdata->status_gpio_valid = !ret; | ||
410 | } | 396 | } |
411 | 397 | ||
412 | if (!charger->pdata->status_gpio_valid | 398 | if (!charger->status_gpio || bq24735_charger_is_present(charger)) { |
413 | || bq24735_charger_is_present(charger)) { | ||
414 | ret = bq24735_read_word(client, BQ24735_MANUFACTURER_ID); | 399 | ret = bq24735_read_word(client, BQ24735_MANUFACTURER_ID); |
415 | if (ret < 0) { | 400 | if (ret < 0) { |
416 | dev_err(&client->dev, "Failed to read manufacturer id : %d\n", | 401 | dev_err(&client->dev, "Failed to read manufacturer id : %d\n", |
diff --git a/include/linux/power/bq24735-charger.h b/include/linux/power/bq24735-charger.h index 6b750c1a45fa..b04be59f914c 100644 --- a/include/linux/power/bq24735-charger.h +++ b/include/linux/power/bq24735-charger.h | |||
@@ -28,10 +28,6 @@ struct bq24735_platform { | |||
28 | 28 | ||
29 | const char *name; | 29 | const char *name; |
30 | 30 | ||
31 | int status_gpio; | ||
32 | int status_gpio_active_low; | ||
33 | bool status_gpio_valid; | ||
34 | |||
35 | bool ext_control; | 31 | bool ext_control; |
36 | 32 | ||
37 | char **supplied_to; | 33 | char **supplied_to; |