From patchwork Fri Sep 2 22:09:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowski X-Patchwork-Id: 9311731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2F3BC60760 for ; Fri, 2 Sep 2016 22:10:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15A3E28784 for ; Fri, 2 Sep 2016 22:10:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 087DE296F4; Fri, 2 Sep 2016 22:10:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEB0729730 for ; Fri, 2 Sep 2016 22:10:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753823AbcIBWKL (ORCPT ); Fri, 2 Sep 2016 18:10:11 -0400 Received: from gagarine.paulk.fr ([109.190.93.129]:54565 "EHLO gagarine.paulk.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753820AbcIBWKK (ORCPT ); Fri, 2 Sep 2016 18:10:10 -0400 Received: by gagarine.paulk.fr (Postfix, from userid 65534) id CF6AE1FF0D; Sat, 3 Sep 2016 00:10:07 +0200 (CEST) Received: from localhost.localdomain (collins [192.168.1.129]) by gagarine.paulk.fr (Postfix) with ESMTP id 44E131FE49; Sat, 3 Sep 2016 00:10:02 +0200 (CEST) From: Paul Kocialkowski To: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org, linux-tegra@vger.kernel.org, Dmitry Eremin-Solenikov , David Woodhouse , Sebastian Reichel , Paul Kocialkowski Subject: [PATCH v4] power: bq24735-charger: Request status GPIO with initial input setup Date: Sat, 3 Sep 2016 00:09:53 +0200 Message-Id: <20160902220953.28995-1-contact@paulk.fr> X-Mailer: git-send-email 2.9.3 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 gpio consumer. Signed-off-by: Paul Kocialkowski --- drivers/power/supply/bq24735-charger.c | 44 +++++++++++++--------------------- include/linux/power/bq24735-charger.h | 4 ---- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/drivers/power/supply/bq24735-charger.c b/drivers/power/supply/bq24735-charger.c index dc460bb..44e3659 100644 --- a/drivers/power/supply/bq24735-charger.c +++ b/drivers/power/supply/bq24735-charger.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include @@ -49,6 +49,7 @@ struct bq24735 { struct i2c_client *client; struct bq24735_platform *pdata; struct mutex lock; + struct gpio_desc *status_gpio; bool charging; }; @@ -177,12 +178,8 @@ static int bq24735_config_charger(struct bq24735 *charger) static bool bq24735_charger_is_present(struct bq24735 *charger) { - struct bq24735_platform *pdata = charger->pdata; - int ret; - - if (pdata->status_gpio_valid) { - ret = gpio_get_value_cansleep(pdata->status_gpio); - return ret ^= pdata->status_gpio_active_low == 0; + if (charger->status_gpio) { + return !gpiod_get_value_cansleep(charger->status_gpio); } else { int ac = 0; @@ -308,7 +305,6 @@ static struct bq24735_platform *bq24735_parse_dt_data(struct i2c_client *client) struct device_node *np = client->dev.of_node; u32 val; int ret; - enum of_gpio_flags flags; pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) { @@ -317,12 +313,6 @@ static struct bq24735_platform *bq24735_parse_dt_data(struct i2c_client *client) 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); if (!ret) pdata->charge_current = val; @@ -357,8 +347,11 @@ static int bq24735_charger_probe(struct i2c_client *client, charger->charging = true; charger->pdata = client->dev.platform_data; - if (IS_ENABLED(CONFIG_OF) && !charger->pdata && client->dev.of_node) + if (IS_ENABLED(CONFIG_OF) && !charger->pdata && client->dev.of_node) { charger->pdata = bq24735_parse_dt_data(client); + if (IS_ERR(charger->pdata)) + return PTR_ERR(charger->pdata); + } if (!charger->pdata) { dev_err(&client->dev, "no platform data provided\n"); @@ -396,21 +389,16 @@ static int bq24735_charger_probe(struct i2c_client *client, i2c_set_clientdata(client, charger); - if (gpio_is_valid(charger->pdata->status_gpio)) { - ret = devm_gpio_request(&client->dev, - charger->pdata->status_gpio, - name); - if (ret) { - dev_err(&client->dev, - "Failed GPIO request for GPIO %d: %d\n", - charger->pdata->status_gpio, ret); - } - - charger->pdata->status_gpio_valid = !ret; + charger->status_gpio = devm_gpiod_get_optional(&client->dev, + "ti,ac-detect", + GPIOD_IN); + if (IS_ERR(charger->status_gpio)) { + ret = PTR_ERR(charger->status_gpio); + dev_err(&client->dev, "Getting gpio failed: %d\n", ret); + return ret; } - if (!charger->pdata->status_gpio_valid - || bq24735_charger_is_present(charger)) { + if (!charger->status_gpio || bq24735_charger_is_present(charger)) { ret = bq24735_read_word(client, BQ24735_MANUFACTURER_ID); if (ret < 0) { 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 6b750c1a..b04be59 100644 --- a/include/linux/power/bq24735-charger.h +++ b/include/linux/power/bq24735-charger.h @@ -28,10 +28,6 @@ struct bq24735_platform { const char *name; - int status_gpio; - int status_gpio_active_low; - bool status_gpio_valid; - bool ext_control; char **supplied_to;