From patchwork Mon Aug 28 21:23:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Breck X-Patchwork-Id: 9926221 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 2F4D9603B4 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 221B8287D0 for ; Mon, 28 Aug 2017 21:25:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16F70287CE; 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 58F36287DC for ; Mon, 28 Aug 2017 21:25:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751182AbdH1VYZ (ORCPT ); Mon, 28 Aug 2017 17:24:25 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34117 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751270AbdH1VYY (ORCPT ); Mon, 28 Aug 2017 17:24:24 -0400 Received: by mail-pg0-f68.google.com with SMTP id 63so1217912pgc.1 for ; Mon, 28 Aug 2017 14:24:24 -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=j+e9XU4vrHCJtecbUZYUBC8/LL7kG5hCfbDIASIxwfk=; b=LrOC/I1iWoPllT/2+3MTCOMsumjAITP5MQM7lkYvjx9lfPV01DWYfx1Dk9JlaUAsli KVQJ93uU5KZkgSoeWeKlV91W/2/VZPA1iIwQe5Y9jptEgr3mnmpI7m8xIfhN7Jk6D0sR 1/aAi8EAIhJgVhjQJMVjKD6cy6ZTfGRKwPagNEXr4eZ0Gp9M7Sel5v1Xsvr8AOOr/Q/M gAq7XuchkofivnmecyLKkxMCF+NCmcdjYxkk3ojCIkDFr0dWqya02EHKtpQCWKK6YHvr 3XmE6/kmXi0UbDSPCSSlgHJ3QiDlus/jqFuP+40gfPtRceIO0SxHA7GOjl6xYWxbYqRX QtFw== 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=j+e9XU4vrHCJtecbUZYUBC8/LL7kG5hCfbDIASIxwfk=; b=TLpJJ8nvo0VcmPwwkDAEBeP5kcqG5MlbOR8hJdPn3SNQv/p2eHJX0az+z/jXO2HsQL 11h4nW5wy0++7D4ap4uFZZmjskaCz0PThdrl86LWkHXBPKlGkkKbJjAoyQQZVoZXKczv e1PvI7I3NIs4aWn2b9JfmdWlAPr/5iYs49XMIP9uytGsN2VfUvxY0Hm1g4PEFD/8uFBi Hugd1q4tX4Rq0uS0NM41ohlZ7z6py79WJoEHca5gYJq80aXM4Q7ouIPzgAA2pkqhEp59 whd4rM6yeQ6D1EKtYkshTwh9FcIojtwsBTDm7QWAal1T9PAa2QPsaukdTOmIPdQPXO3W 1v1A== X-Gm-Message-State: AHYfb5h1RZzWO01WztYDDSA8zcHeF/myOTkbNXl+fjnt+vgNd9g5N8CT GnHZy6dwt7I17w== X-Received: by 10.84.218.71 with SMTP id f7mr2372307plm.274.1503955464260; Mon, 28 Aug 2017 14:24:24 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Aug 2017 14:24:23 -0700 (PDT) From: Liam Breck To: Sebastian Reichel , linux-pm@vger.kernel.org Cc: Tony Lindgren , Hans de Goede , Liam Breck Subject: [PATCH v4 5/5] power: bq24190_charger: Add power_supply_battery_info support Date: Mon, 28 Aug 2017 14:23:49 -0700 Message-Id: <20170828212349.19037-6-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 Set pre-charge and charge-term current, obtained from power_supply_battery_info. Add sysfs attributes precharge_current & charge_term_current. Cc: Tony Lindgren Cc: Hans de Goede Signed-off-by: Liam Breck Acked-by: Tony Lindgren --- drivers/power/supply/bq24190_charger.c | 87 ++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c index c0b23db8..c05aa27a 100644 --- a/drivers/power/supply/bq24190_charger.c +++ b/drivers/power/supply/bq24190_charger.c @@ -59,9 +59,13 @@ #define BQ24190_REG_PCTCC_IPRECHG_MASK (BIT(7) | BIT(6) | BIT(5) | \ BIT(4)) #define BQ24190_REG_PCTCC_IPRECHG_SHIFT 4 +#define BQ24190_REG_PCTCC_IPRECHG_MIN 128 +#define BQ24190_REG_PCTCC_IPRECHG_MAX 2048 #define BQ24190_REG_PCTCC_ITERM_MASK (BIT(3) | BIT(2) | BIT(1) | \ BIT(0)) #define BQ24190_REG_PCTCC_ITERM_SHIFT 0 +#define BQ24190_REG_PCTCC_ITERM_MIN 128 +#define BQ24190_REG_PCTCC_ITERM_MAX 2048 #define BQ24190_REG_CVC 0x04 /* Charge Voltage Control */ #define BQ24190_REG_CVC_VREG_MASK (BIT(7) | BIT(6) | BIT(5) | \ @@ -162,6 +166,8 @@ struct bq24190_dev_info { bool initialized; bool irq_event; u16 sys_min; + u16 iprechg; + u16 iterm; struct mutex f_reg_lock; u8 f_reg; u8 ss_reg; @@ -543,6 +549,26 @@ static int bq24190_set_config(struct bq24190_dev_info *bdi) return ret; } + if (bdi->iprechg) { + v = bdi->iprechg / 128 - 1; // manual section 9.5.1.4, table 11 + ret = bq24190_write_mask(bdi, BQ24190_REG_PCTCC, + BQ24190_REG_PCTCC_IPRECHG_MASK, + BQ24190_REG_PCTCC_IPRECHG_SHIFT, + v); + if (ret < 0) + return ret; + } + + if (bdi->iterm) { + v = bdi->iterm / 128 - 1; // manual section 9.5.1.4, table 11 + ret = bq24190_write_mask(bdi, BQ24190_REG_PCTCC, + BQ24190_REG_PCTCC_ITERM_MASK, + BQ24190_REG_PCTCC_ITERM_SHIFT, + v); + if (ret < 0) + return ret; + } + return 0; } @@ -787,6 +813,38 @@ static int bq24190_charger_set_temp_alert_max(struct bq24190_dev_info *bdi, return bq24190_battery_set_temp_alert_max(bdi, val); } +static int bq24190_charger_get_precharge(struct bq24190_dev_info *bdi, + union power_supply_propval *val) +{ + u8 v; + int ret; + + ret = bq24190_read_mask(bdi, BQ24190_REG_PCTCC, + BQ24190_REG_PCTCC_IPRECHG_MASK, + BQ24190_REG_PCTCC_IPRECHG_SHIFT, &v); + if (ret < 0) + return ret; + + val->intval = ++v * 128 * 1000; + return 0; +} + +static int bq24190_charger_get_charge_term(struct bq24190_dev_info *bdi, + union power_supply_propval *val) +{ + u8 v; + int ret; + + ret = bq24190_read_mask(bdi, BQ24190_REG_PCTCC, + BQ24190_REG_PCTCC_ITERM_MASK, + BQ24190_REG_PCTCC_ITERM_SHIFT, &v); + if (ret < 0) + return ret; + + val->intval = ++v * 128 * 1000; + return 0; +} + static int bq24190_charger_get_current(struct bq24190_dev_info *bdi, union power_supply_propval *val) { @@ -907,6 +965,12 @@ static int bq24190_charger_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_TEMP_ALERT_MAX: ret = bq24190_charger_get_temp_alert_max(bdi, val); break; + case POWER_SUPPLY_PROP_PRECHARGE_CURRENT: + ret = bq24190_charger_get_precharge(bdi, val); + break; + case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: + ret = bq24190_charger_get_charge_term(bdi, val); + break; case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: ret = bq24190_charger_get_current(bdi, val); break; @@ -1006,6 +1070,8 @@ static enum power_supply_property bq24190_charger_properties[] = { POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_TEMP_ALERT_MAX, + POWER_SUPPLY_PROP_PRECHARGE_CURRENT, + POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, @@ -1484,6 +1550,7 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi) static int bq24190_get_config(struct bq24190_dev_info *bdi) { const char * const s = "ti,system-minimum-microvolt"; + struct power_supply_battery_info info = {}; int v; if (device_property_read_u32(bdi->dev, s, &v) == 0) { @@ -1495,6 +1562,25 @@ static int bq24190_get_config(struct bq24190_dev_info *bdi) dev_warn(bdi->dev, "invalid value for %s: %u\n", s, v); } + if (bdi->dev->of_node && + !power_supply_get_battery_info(bdi->charger, &info)) { + v = info.precharge_current_ua / 1000; + if (v >= BQ24190_REG_PCTCC_IPRECHG_MIN + && v <= BQ24190_REG_PCTCC_IPRECHG_MAX) + bdi->iprechg = v; + else + dev_warn(bdi->dev, "invalid value for battery:precharge-current-microamp: %d\n", + v); + + v = info.charge_term_current_ua / 1000; + if (v >= BQ24190_REG_PCTCC_ITERM_MIN + && v <= BQ24190_REG_PCTCC_ITERM_MAX) + bdi->iterm = v; + else + dev_warn(bdi->dev, "invalid value for battery:charge-term-current-microamp: %d\n", + v); + } + return 0; } @@ -1562,6 +1648,7 @@ static int bq24190_probe(struct i2c_client *client, } charger_cfg.drv_data = bdi; + charger_cfg.of_node = dev->of_node; charger_cfg.supplied_to = bq24190_charger_supplied_to; charger_cfg.num_supplicants = ARRAY_SIZE(bq24190_charger_supplied_to), bdi->charger = power_supply_register(dev, &bq24190_charger_desc,