Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: bq24735-charger: Request status GPIO with initial input setup

This requests the status GPIO with initial input setup. It is required
to read the GPIO status at probe time and thus correctly avoid sending
I2C messages when AC is not plugged.

When requesting the GPIO without initial input setup, it always reads 0
which causes probe to fail as it assumes the charger is connected, sends
I2C messages and fails.

While at it, this switches the driver over to gpiod API.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Signed-off-by: Sebastian Reichel <sre@kernel.org>

authored by

Paul Kocialkowski and committed by
Sebastian Reichel
c65a8b51 3b5dd3a4

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