Commit c65a8b51 authored by Paul Kocialkowski's avatar Paul Kocialkowski Committed by Sebastian Reichel

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: default avatarPaul Kocialkowski <contact@paulk.fr>
Signed-off-by: default avatarSebastian Reichel <sre@kernel.org>
parent 3b5dd3a4
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_gpio.h> #include <linux/gpio/consumer.h>
#include <linux/power_supply.h> #include <linux/power_supply.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -49,6 +49,7 @@ struct bq24735 { ...@@ -49,6 +49,7 @@ struct bq24735 {
struct i2c_client *client; struct i2c_client *client;
struct bq24735_platform *pdata; struct bq24735_platform *pdata;
struct mutex lock; struct mutex lock;
struct gpio_desc *status_gpio;
bool charging; bool charging;
}; };
...@@ -177,12 +178,8 @@ static int bq24735_config_charger(struct bq24735 *charger) ...@@ -177,12 +178,8 @@ static int bq24735_config_charger(struct bq24735 *charger)
static bool bq24735_charger_is_present(struct bq24735 *charger) static bool bq24735_charger_is_present(struct bq24735 *charger)
{ {
struct bq24735_platform *pdata = charger->pdata; if (charger->status_gpio) {
int ret; return !gpiod_get_value_cansleep(charger->status_gpio);
if (pdata->status_gpio_valid) {
ret = gpio_get_value_cansleep(pdata->status_gpio);
return ret ^= pdata->status_gpio_active_low == 0;
} else { } else {
int ac = 0; int ac = 0;
...@@ -308,7 +305,6 @@ static struct bq24735_platform *bq24735_parse_dt_data(struct i2c_client *client) ...@@ -308,7 +305,6 @@ static struct bq24735_platform *bq24735_parse_dt_data(struct i2c_client *client)
struct device_node *np = client->dev.of_node; struct device_node *np = client->dev.of_node;
u32 val; u32 val;
int ret; int ret;
enum of_gpio_flags flags;
pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) { if (!pdata) {
...@@ -317,12 +313,6 @@ static struct bq24735_platform *bq24735_parse_dt_data(struct i2c_client *client) ...@@ -317,12 +313,6 @@ static struct bq24735_platform *bq24735_parse_dt_data(struct i2c_client *client)
return NULL; return NULL;
} }
pdata->status_gpio = of_get_named_gpio_flags(np, "ti,ac-detect-gpios",
0, &flags);
if (flags & OF_GPIO_ACTIVE_LOW)
pdata->status_gpio_active_low = 1;
ret = of_property_read_u32(np, "ti,charge-current", &val); ret = of_property_read_u32(np, "ti,charge-current", &val);
if (!ret) if (!ret)
pdata->charge_current = val; pdata->charge_current = val;
...@@ -396,21 +386,16 @@ static int bq24735_charger_probe(struct i2c_client *client, ...@@ -396,21 +386,16 @@ static int bq24735_charger_probe(struct i2c_client *client,
i2c_set_clientdata(client, charger); i2c_set_clientdata(client, charger);
if (gpio_is_valid(charger->pdata->status_gpio)) { charger->status_gpio = devm_gpiod_get_optional(&client->dev,
ret = devm_gpio_request(&client->dev, "ti,ac-detect",
charger->pdata->status_gpio, GPIOD_IN);
name); if (IS_ERR(charger->status_gpio)) {
if (ret) { ret = PTR_ERR(charger->status_gpio);
dev_err(&client->dev, dev_err(&client->dev, "Getting gpio failed: %d\n", ret);
"Failed GPIO request for GPIO %d: %d\n", return ret;
charger->pdata->status_gpio, ret);
}
charger->pdata->status_gpio_valid = !ret;
} }
if (!charger->pdata->status_gpio_valid if (!charger->status_gpio || bq24735_charger_is_present(charger)) {
|| bq24735_charger_is_present(charger)) {
ret = bq24735_read_word(client, BQ24735_MANUFACTURER_ID); ret = bq24735_read_word(client, BQ24735_MANUFACTURER_ID);
if (ret < 0) { if (ret < 0) {
dev_err(&client->dev, "Failed to read manufacturer id : %d\n", dev_err(&client->dev, "Failed to read manufacturer id : %d\n",
......
...@@ -28,10 +28,6 @@ struct bq24735_platform { ...@@ -28,10 +28,6 @@ struct bq24735_platform {
const char *name; const char *name;
int status_gpio;
int status_gpio_active_low;
bool status_gpio_valid;
bool ext_control; bool ext_control;
char **supplied_to; char **supplied_to;
......
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