From patchwork Mon Aug 7 19:54:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Breck X-Patchwork-Id: 9886083 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 B43BC60364 for ; Mon, 7 Aug 2017 19:54:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A65DC286BA for ; Mon, 7 Aug 2017 19:54:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98393286CB; Mon, 7 Aug 2017 19:54:47 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 251B4286E1 for ; Mon, 7 Aug 2017 19:54:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751921AbdHGTyq (ORCPT ); Mon, 7 Aug 2017 15:54:46 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:35573 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751560AbdHGTyp (ORCPT ); Mon, 7 Aug 2017 15:54:45 -0400 Received: by mail-pf0-f195.google.com with SMTP id j68so1293556pfc.2 for ; Mon, 07 Aug 2017 12:54:45 -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=zr/C4bS2Nfcq/eAziA2ITq8YXSafjJ2WeYUaaXGGwvI=; b=sOSkBLTvBz6pRrmPyrnY0UrBPf/DJKSa9bgR2VijJszDVt1jupXzKwq4p0pqbjkthQ dEwn+PI6D8ajA9UZYMJcdAWQaXrWtMEJRLiuC7hTlT6BRvOnvyc/duO+RE/PlZRPGpUP YqmZuxxppjCVLNan5eUyOkdj3u+vlJ4iuV4fYy/hOloNC4eiREWkIEybMkeExR2CzCkR Y2wLZba9dwbC8q0K0y7FM3jMn1NwN/PSXqMGPpJywTXYGjA/Pfwd+YcrvH1LGG9Yo6MT poOMuL8WEby8f+7iM1SsG+IuRdTE7pZ2QYirH37gwYegAREWsbmUABdW49yvNBeY0EjP XmQg== 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=zr/C4bS2Nfcq/eAziA2ITq8YXSafjJ2WeYUaaXGGwvI=; b=kHJNRzf+7+F8Ib9LIEw2dHNv78Fw/icDl8JdnYIw4SBU34JFUqy4j5/JahBPEBp4RD uZZb0U+j1OSB2sALEq0p5DoYuLRsAFstaIvg3va4RnKEMI3sgcCJibzEHueUVR8r90fD sg1ANnZyz9Mpicv6xPjO8xtLJIBqFxDEFPUblIExiWGpPXnSDkP+uryISyG3zMfKj5AJ L9WHFn0MNXCSBWAPUedTQnGATD8R/+L+KB/GcdxzWQFBIyrbqISg9Fpc3o4o1uAGIssL wMkWAGW2DgHQutgsWREdp9tQNSyY/bOOi0KqyJpNFtLfb1fsQP7KTx9Ec346A9U3ThBI KvCg== X-Gm-Message-State: AHYfb5gLVAQxeaCE/wE2WbQ4Qdb7xpWd7LpMQqrrUj849+uhMeVS6+OS gNA2iRjdslx4yQ== X-Received: by 10.99.124.5 with SMTP id x5mr1661989pgc.280.1502135685045; Mon, 07 Aug 2017 12:54:45 -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 o73sm16091912pfj.1.2017.08.07.12.54.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Aug 2017 12:54:44 -0700 (PDT) From: Liam Breck To: Sebastian Reichel , linux-pm@vger.kernel.org Cc: Tony Lindgren , Hans de Goede , Liam Breck Subject: [PATCH v2 5/5] power: bq24190_charger: Add power_supply_battery_info support Date: Mon, 7 Aug 2017 12:54:20 -0700 Message-Id: <20170807195420.20767-6-liam@networkimprov.net> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170807195420.20767-1-liam@networkimprov.net> References: <20170807195420.20767-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 --- drivers/power/supply/bq24190_charger.c | 86 ++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c index f20d2c68..8a2120cc 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, @@ -1485,6 +1551,7 @@ static int bq24190_get_config(struct bq24190_dev_info *bdi) { #ifdef CONFIG_OF const char * const s = "ti,system-minimum-microvolt"; + struct power_supply_battery_info info = {}; int v; if (!bdi->dev->of_node) @@ -1499,6 +1566,24 @@ static int bq24190_get_config(struct bq24190_dev_info *bdi) dev_warn(bdi->dev, "invalid value for %s: %u\n", s, v); } + if (!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); + } + #endif return 0; } @@ -1567,6 +1652,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,