From patchwork Mon Aug 28 21:23:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Breck X-Patchwork-Id: 9926223 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 D2B0160380 for ; Mon, 28 Aug 2017 21:25:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C55B8287CE for ; Mon, 28 Aug 2017 21:25:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA4AD287D0; Mon, 28 Aug 2017 21:25:04 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 16E9C287E9 for ; Mon, 28 Aug 2017 21:25:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751280AbdH1VYY (ORCPT ); Mon, 28 Aug 2017 17:24:24 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35482 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751270AbdH1VYW (ORCPT ); Mon, 28 Aug 2017 17:24:22 -0400 Received: by mail-pg0-f67.google.com with SMTP id r133so1215313pgr.2 for ; Mon, 28 Aug 2017 14:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=dTU/2tO/Emy5mV06tXxhxUPPgQFyE7oBVXDbQqPr0Gc=; b=oLr6xt/GiiQY8TxK9sIlDnQAnf6cPy2aQZT/dOygh4cN+m2Vu90qEJPQ8scRLc29LF UMPDixDiaOeH65usLYA8mKA7QYkG0pJJFeXWPc+rRRnI6K55raL3VD6jT8E3nC045fl/ o6kVSag5iQQPDLbpE3rILFSEafCyITlx9nzefQZ75CVj79JDFLN1Dvws6KAzTaCXLuUB vSfmaSH5A6tJkBvq49GyjV7kyFce/TcoGv2ji5wWJoqhL/RJGJrU2FDndPMFME5CVBHE SxHGBWuHyswMKo+9AEZehHsBNbDEM71v7UMHjggQnwokiMU5pSVPbY7dN6EbPBmd5Th8 WRkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=dTU/2tO/Emy5mV06tXxhxUPPgQFyE7oBVXDbQqPr0Gc=; b=WRerFZJIMX/s6IdgD2qoQAgnKsGzN+n8QZ+QL4xoynH2jn0h/kjxY4WDyxJ2CYsYsL V48RyJVdg1gRz52PAJo501bY1+PYrCQWwT5XbtIxm97g7bf9PJqy+7xq0zVYZcT6p0us BhTRK5cyt21rueIum5aUZnmI9mx6/ELQw2UC+mNyQeHsnjndy4vdOKowxbT/Am+irzmM wJHXskVzOjihygaT1pPOKWK9nR6lDtBYTGRrci2O8ofqdDCb+gsfFSd8q3RWD7eBnVX/ ELMNfsBnqGdXQT6ZMqAj5USR49Xsh1x1VT7JZy1BOPLoe/Zkk0lm5GyGelARDMUytBt5 FjwQ== X-Gm-Message-State: AHYfb5g3WNqw6Z4KbKc5JNPhw4JOyoIbcx3udojeRP70IVXxUGnqYhBK ESdMZEhdC31R2g== X-Received: by 10.99.122.69 with SMTP id j5mr1919971pgn.12.1503955462187; Mon, 28 Aug 2017 14:24:22 -0700 (PDT) Received: from localhost.localdomain (c-73-223-93-234.hsd1.ca.comcast.net. [73.223.93.234]) by smtp.gmail.com with ESMTPSA id t29sm2155952pgo.4.2017.08.28.14.24.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Aug 2017 14:24:21 -0700 (PDT) From: Liam Breck To: Sebastian Reichel , linux-pm@vger.kernel.org Cc: Tony Lindgren , Hans de Goede , Liam Breck Subject: [PATCH v4 3/5] power: bq24190_charger: Enable devicetree config Date: Mon, 28 Aug 2017 14:23:47 -0700 Message-Id: <20170828212349.19037-4-liam@networkimprov.net> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170828212349.19037-1-liam@networkimprov.net> References: <20170828212349.19037-1-liam@networkimprov.net> 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 From: Liam Breck Add get_config(). Rename set_mode_host() to set_config(). Call get_config() and hw_init() after power_supply_register(). No functional changes. Cc: Tony Lindgren Cc: Hans de Goede Signed-off-by: Liam Breck Acked-by: Tony Lindgren --- drivers/power/supply/bq24190_charger.c | 56 ++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c index 40b4bba7..af4688db 100644 --- a/drivers/power/supply/bq24190_charger.c +++ b/drivers/power/supply/bq24190_charger.c @@ -504,15 +504,7 @@ static int bq24190_sysfs_create_group(struct bq24190_dev_info *bdi) static inline void bq24190_sysfs_remove_group(struct bq24190_dev_info *bdi) {} #endif -/* - * According to the "Host Mode and default Mode" section of the - * manual, a write to any register causes the bq24190 to switch - * from default mode to host mode. It will switch back to default - * mode after a WDT timeout unless the WDT is turned off as well. - * So, by simply turning off the WDT, we accomplish both with the - * same write. - */ -static int bq24190_set_mode_host(struct bq24190_dev_info *bdi) +static int bq24190_set_config(struct bq24190_dev_info *bdi) { int ret; u8 v; @@ -523,9 +515,22 @@ static int bq24190_set_mode_host(struct bq24190_dev_info *bdi) bdi->watchdog = ((v & BQ24190_REG_CTTC_WATCHDOG_MASK) >> BQ24190_REG_CTTC_WATCHDOG_SHIFT); + + /* + * According to the "Host Mode and default Mode" section of the + * manual, a write to any register causes the bq24190 to switch + * from default mode to host mode. It will switch back to default + * mode after a WDT timeout unless the WDT is turned off as well. + * So, by simply turning off the WDT, we accomplish both with the + * same write. + */ v &= ~BQ24190_REG_CTTC_WATCHDOG_MASK; - return bq24190_write(bdi, BQ24190_REG_CTTC, v); + ret = bq24190_write(bdi, BQ24190_REG_CTTC, v); + if (ret < 0) + return ret; + + return 0; } static int bq24190_register_reset(struct bq24190_dev_info *bdi) @@ -1456,13 +1461,18 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi) if (ret < 0) return ret; - ret = bq24190_set_mode_host(bdi); + ret = bq24190_set_config(bdi); if (ret < 0) return ret; return bq24190_read(bdi, BQ24190_REG_SS, &bdi->ss_reg); } +static int bq24190_get_config(struct bq24190_dev_info *bdi) +{ + return 0; +} + static int bq24190_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1493,7 +1503,7 @@ static int bq24190_probe(struct i2c_client *client, i2c_set_clientdata(client, bdi); - if (!client->irq) { + if (client->irq <= 0) { dev_err(dev, "Can't get irq info\n"); return -EINVAL; } @@ -1526,12 +1536,6 @@ static int bq24190_probe(struct i2c_client *client, goto out_pmrt; } - ret = bq24190_hw_init(bdi); - if (ret < 0) { - dev_err(dev, "Hardware init failed\n"); - goto out_pmrt; - } - charger_cfg.drv_data = bdi; charger_cfg.supplied_to = bq24190_charger_supplied_to; charger_cfg.num_supplicants = ARRAY_SIZE(bq24190_charger_supplied_to), @@ -1556,8 +1560,20 @@ static int bq24190_probe(struct i2c_client *client, } } + ret = bq24190_get_config(bdi); + if (ret < 0) { + dev_err(dev, "Can't get devicetree config\n"); + goto out_charger; + } + + ret = bq24190_hw_init(bdi); + if (ret < 0) { + dev_err(dev, "Hardware init failed\n"); + goto out_charger; + } + ret = bq24190_sysfs_create_group(bdi); - if (ret) { + if (ret < 0) { dev_err(dev, "Can't create sysfs entries\n"); goto out_charger; } @@ -1700,7 +1716,7 @@ static __maybe_unused int bq24190_pm_resume(struct device *dev) } bq24190_register_reset(bdi); - bq24190_set_mode_host(bdi); + bq24190_set_config(bdi); bq24190_read(bdi, BQ24190_REG_SS, &bdi->ss_reg); if (error >= 0) {