From patchwork Fri Oct 19 10:53:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 149251 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp3143134lji; Fri, 19 Oct 2018 03:53:34 -0700 (PDT) X-Google-Smtp-Source: ACcGV60LAUkOuZQzULuO/DfqM3AoIMYQEHJM+YErvDNRasPqiqW78TJllblo+XDYUNwB3TbwsDLB X-Received: by 2002:a17:902:24c:: with SMTP id 70-v6mr24049354plc.324.1539946414812; Fri, 19 Oct 2018 03:53:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539946414; cv=none; d=google.com; s=arc-20160816; b=zj/bGjRWBQUMNjn3F4vcrNsTbOOO3cLxs5nxjiU9BzcH8sNVBkTCXcFSi3ei5x6duC rVa2vvOASO8dZmuAauj/zUfSAeVQP32iRsWEvshGjf/zokZk+x67Z6QKlux2Lbk3VZzu VnKwnqGlH2vbEMltOxzNs7tbRrph2ti10wv3Hq/1F2dkO2gV6qrDkeKdCNQWE4rpwBZg 8MuR/LbiBz9pkEOcDdeLe5hq3YRxA3vYtBbTspK10y5WtQeWaM8Ls8jZ6mdS2K5k62UL NJeVADLPDQ61zWQrJV/B9mnJ2P7/bXwXA9WD4PlJgHNuLXI3R4Z9OYu+OgM6tY+J4dkI py6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=SosU5iF7Ey+1v+4vcDwsnnSkHEG3BRB043fFaX95JpI=; b=EiWW31BOe58+v9ShsEWPDNq/9BDfZankBgxuSwodnzwIM1qcTzlswrUowB49CRkjqx 8ZEl+FcieKDlacfHqV+1HNg9Pve/xwWZlTJO+m/fgp89MsObpPp2CqaamD7QwWkou3qr +BfdVN6eQoY9aTCSzKhN7dnsCe3Pc92ZrwIAGk9rVgYUvC5ulfJcjDELtk8WRNC6xztf x/WB5mIaOoXeJvx70VqHchdlr653Oiu4c7MEvxczKZgL10JIkaIt/j9fH9dCBBpbAzG1 XoCA6XfCm2aYi1wSZaNFug0TbQIyAiUntXS48u7W2vMPqLwPVlch6rIxOWUo2xq3Phht j6qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NzKaUFA7; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x10-v6si22994631plo.100.2018.10.19.03.53.34; Fri, 19 Oct 2018 03:53:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NzKaUFA7; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726609AbeJSS7F (ORCPT + 6 others); Fri, 19 Oct 2018 14:59:05 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:42977 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726542AbeJSS7F (ORCPT ); Fri, 19 Oct 2018 14:59:05 -0400 Received: by mail-pl1-f195.google.com with SMTP id c8-v6so15695778plo.9 for ; Fri, 19 Oct 2018 03:53:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=SosU5iF7Ey+1v+4vcDwsnnSkHEG3BRB043fFaX95JpI=; b=NzKaUFA7uW8Qqw8bJsA1H+ca3lfOsCI6241EZDrw0IQeIIQalm5JvoUuM84ae154wx VCkdfzJnHGvuUbuWHqxSza5v7L+9rNuKO8LCsxBUYOs4iyw9z3ldq7WXnVN5qRZzQdZ1 o72Vob3LeIT0oOHbUcfZoMmONULWd17TwL51g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SosU5iF7Ey+1v+4vcDwsnnSkHEG3BRB043fFaX95JpI=; b=DR9kEJpX1lODNh7jhW0NkMmCWnhESaIBi8v+XuyCQ6Z4nnEelPEqmj9vrw2yp+gyB2 qt/bWC8+PP+P9MspiVqrxHZehTMpyV/bOjWYAlIDjDhM0ZSs2AzYhPN9vxt0L9VqVLq0 tQeontkOWI8s20X8txRlIe7e1PltENE1ObSAIkYg/muONHe8Ffu6zLQfuviFDyu4jKja JMNaKTRtDqu7MtbeTdQZLbsXV7I9OoDDVs/5lSeejphTJxlAkB/SixyBLrHNqpoA6eNW z7fVA00J0GvAq0Z4nLP84cx51g++IRMB/Je5HX5qBqWigILa9oO/i7d2XFHZKNRrhRKh o8yQ== X-Gm-Message-State: ABuFfojvchETzPxkBLcDCOnAqXmh4CG0fwy17FfST0IGzIvVdsjesJJt X9SQJqBRZq824Itru6aPugjY+g== X-Received: by 2002:a17:902:a7:: with SMTP id a36-v6mr20823295pla.87.1539946412361; Fri, 19 Oct 2018 03:53:32 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id m67-v6sm54918pfm.13.2018.10.19.03.53.28 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Oct 2018 03:53:31 -0700 (PDT) From: Baolin Wang To: sre@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, yuanjiang.yu@unisoc.com, baolin.wang@linaro.org, broonie@kernel.org, ctatlor97@gmail.com, linus.walleij@linaro.org Subject: [PATCH v5 1/6] dt-bindings: power: Introduce one property to present the battery internal resistance Date: Fri, 19 Oct 2018 18:53:10 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The internal resistance of a battery is not a constant in its life cycle, this varies over the age of the battery or temperature and so on. But we just want use one constant battery internal resistance to estimate the battery capacity. Thus this patch introduces one property to present the battery factory internal resistance for battery information. Signed-off-by: Baolin Wang Reviewed-by: Linus Walleij --- Changes from v4: - None. Changes from v3: - Split binding into one separate patch. - Add LinusW reviewed tag. Changes from v2: - Rename the property. - Improve the commit message. Changes from v1: - New patch in v2. --- .../devicetree/bindings/power/supply/battery.txt | 2 ++ 1 file changed, 2 insertions(+) -- 1.7.9.5 diff --git a/Documentation/devicetree/bindings/power/supply/battery.txt b/Documentation/devicetree/bindings/power/supply/battery.txt index f4d3b4a..938d027 100644 --- a/Documentation/devicetree/bindings/power/supply/battery.txt +++ b/Documentation/devicetree/bindings/power/supply/battery.txt @@ -22,6 +22,7 @@ Optional Properties: - charge-term-current-microamp: current for charge termination phase - constant-charge-current-max-microamp: maximum constant input current - constant-charge-voltage-max-microvolt: maximum constant input voltage + - factory-internal-resistance-micro-ohms: battery factory internal resistance Battery properties are named, where possible, for the corresponding elements in enum power_supply_property, defined in @@ -42,6 +43,7 @@ Example: charge-term-current-microamp = <128000>; constant-charge-current-max-microamp = <900000>; constant-charge-voltage-max-microvolt = <4200000>; + factory-internal-resistance-micro-ohms = <250000>; }; charger: charger@11 { From patchwork Fri Oct 19 10:53:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 149254 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp3143360lji; Fri, 19 Oct 2018 03:53:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV63hTMEaoJX0qNMu3VfeAtPLYGNSPTsgKF2+utcQNSmMEX69mVt4Ei0rT9YlmDnRaW1qAlbg X-Received: by 2002:a62:4bd2:: with SMTP id d79-v6mr34098355pfj.38.1539946429776; Fri, 19 Oct 2018 03:53:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539946429; cv=none; d=google.com; s=arc-20160816; b=JjXDYljHpG/oUODo0OBF2h2s5O+8F5DQDsAOyQf0FHQUeOjK9N21RTm8L7gfKg0ML4 Noxf5qJljYTv7Jpd4bN74dwElFJBkvnERmhilqZkm0BiWVV3hi9yivxqjS7rARYjucyF Wa2V4OjHDmwQrHfjPr7/nx5LIezLJF/4N5oSGReHmA/BPofLcODomUhYsIDAUCZcpewL CEvaLxJNtDIYdcFXn75FaUBqFCnvbCycpL0v33rrKtnyfovXWxRlXg6ZMNPEiAGkC8oS OSzWNEVIN7o6LX0cJOT2zWMPuJam9y7OtIHWflETxCyQdcuPLTiW4xrRaS7Fd3JmLmni xecQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=p6TlAN3GTA2O6epc7Pk4ZVf3tcYffw0peZEOU8J4CQY=; b=UDIQ+sYW6duChFSvczsx+AS4W4A6tLGfVaGE+RexVtV3MBiB+zyaT4VTUKBw+e9QD0 HLMsUqncJQEuB4Z772gr+ZKNR6P8rXJoSai32/us00vESXeCiImBLgQ08Tr7E7Of5gJB 5kxAruU8vkYAMkXXKoOZdkD7k9zK4en12/5s8iyDflZFlSsUDCtYqX4+XQEg2vagCy8c Trcr9HJQB+J5DkOO08XpnnariFlp/pPpFuRhNq8N2bye0joVcIrg4QXYdjbI+CYp9qDF f4jJ0FUUNhral8ez462VMPAM6LsIC/3xOQIcnUu3l6vo5uUpKMl+kQ15UVIjGTaxCPec 2gRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HofzYi17; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q13-v6si23310790pgq.526.2018.10.19.03.53.49; Fri, 19 Oct 2018 03:53:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HofzYi17; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727245AbeJSS7S (ORCPT + 6 others); Fri, 19 Oct 2018 14:59:18 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:39033 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727182AbeJSS7R (ORCPT ); Fri, 19 Oct 2018 14:59:17 -0400 Received: by mail-pf1-f195.google.com with SMTP id c25-v6so16325955pfe.6 for ; Fri, 19 Oct 2018 03:53:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=p6TlAN3GTA2O6epc7Pk4ZVf3tcYffw0peZEOU8J4CQY=; b=HofzYi17kZQEvO7dVoZkzmqbZ7LmHhfp/AriMH7A5Lwv9BORkx6lqoGusD7pbcnjNE 7QHniuAYV+BEYSfBYeiFN4mVT05bvOXCo3v9lL2rbXLKo5QezombFAhmEfv4mTQOpCEe lncWmcT5wewPnDMOb0yHRpTUbvVW4NWXP4L1Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=p6TlAN3GTA2O6epc7Pk4ZVf3tcYffw0peZEOU8J4CQY=; b=Am0obdWunXLI8RRtdosD8xATEbG6htvKKdHv3fX3wArlJE4eRFZ68aRYbVeT0GC9Dg VaSjOoasRwAgSXEuDKOFSuFLKelWMVdwDRnn22kwFlDhUv2TcD0SYhxchoPnLU9xf+UQ fgkFFkmX61R3NBSOpdJsSt8G9xAluPK9XFl1nRLsbKcr/YLlxUzSZh6CWOe1EQ8uTBYW BUbufHGN/Ss2PkyWIbjwvl2PS8c/7GFUD4DkZSlWECmHAwjaHzcFhicx+shmLSxDC16a nur/oEeM3vM++oySOVPPR3vvXxRzHjykbXo/FZVnZNWMviLWdD2ZsFub6ObbzNroaLiH vobw== X-Gm-Message-State: ABuFfoiHA7GqX3KgbmOSfUWcp/Rrr7Vl8ViI/Ngai+vSiLE4klV3Bv+B Ju6AYKVcYAUiqLziEi4aeT7ZZg== X-Received: by 2002:aa7:88c2:: with SMTP id p2-v6mr26545651pfo.32.1539946424585; Fri, 19 Oct 2018 03:53:44 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id m67-v6sm54918pfm.13.2018.10.19.03.53.40 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Oct 2018 03:53:43 -0700 (PDT) From: Baolin Wang To: sre@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, yuanjiang.yu@unisoc.com, baolin.wang@linaro.org, broonie@kernel.org, ctatlor97@gmail.com, linus.walleij@linaro.org Subject: [PATCH v5 4/6] power: supply: core: Add some helpers to use the battery OCV capacity table Date: Fri, 19 Oct 2018 18:53:13 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org We have introduced some battery properties to present the OCV table temperatures and OCV capacity table values. Thus this patch add OCV temperature and OCV table for battery information, as well as providing some helper functions to use the OCV capacity table for users. Signed-off-by: Baolin Wang Reviewed-by: Linus Walleij --- Changes from v4: - None. Changes from v3: - Split core modification into one separate patch. - Rename ocv-capacity-table-temperatures to ocv-capacity-celsius. Changes from v2: - Use type __be32 to calculate the table length. - Update error messages. - Add some helper functions. Changes from v1: - New patch in v2. --- drivers/power/supply/power_supply_core.c | 123 +++++++++++++++++++++++++++++- include/linux/power_supply.h | 19 +++++ 2 files changed, 141 insertions(+), 1 deletion(-) -- 1.7.9.5 diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 307e0995..58c4309 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -570,7 +570,7 @@ int power_supply_get_battery_info(struct power_supply *psy, { struct device_node *battery_np; const char *value; - int err; + int err, len, index; info->energy_full_design_uwh = -EINVAL; info->charge_full_design_uah = -EINVAL; @@ -581,6 +581,12 @@ int power_supply_get_battery_info(struct power_supply *psy, info->constant_charge_voltage_max_uv = -EINVAL; info->factory_internal_resistance_uohm = -EINVAL; + for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) { + info->ocv_table[index] = NULL; + info->ocv_temp[index] = -EINVAL; + info->ocv_table_size[index] = -EINVAL; + } + if (!psy->of_node) { dev_warn(&psy->dev, "%s currently only supports devicetree\n", __func__); @@ -620,10 +626,125 @@ int power_supply_get_battery_info(struct power_supply *psy, of_property_read_u32(battery_np, "factory-internal-resistance-micro-ohms", &info->factory_internal_resistance_uohm); + len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius"); + if (len < 0 && len != -EINVAL) { + return len; + } else if (len > POWER_SUPPLY_OCV_TEMP_MAX) { + dev_err(&psy->dev, "Too many temperature values\n"); + return -EINVAL; + } else if (len > 0) { + of_property_read_u32_array(battery_np, "ocv-capacity-celsius", + info->ocv_temp, len); + } + + for (index = 0; index < len; index++) { + struct power_supply_battery_ocv_table *table; + char *propname; + const __be32 *list; + int i, tab_len, size; + + propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index); + list = of_get_property(battery_np, propname, &size); + if (!list || !size) { + dev_err(&psy->dev, "failed to get %s\n", propname); + kfree(propname); + power_supply_put_battery_info(psy, info); + return -EINVAL; + } + + kfree(propname); + tab_len = size / (2 * sizeof(__be32)); + info->ocv_table_size[index] = tab_len; + + table = info->ocv_table[index] = + devm_kzalloc(&psy->dev, tab_len * sizeof(*table), + GFP_KERNEL); + if (!info->ocv_table[index]) { + power_supply_put_battery_info(psy, info); + return -ENOMEM; + } + + for (i = 0; i < tab_len; i++) { + table[i].ocv = be32_to_cpu(*list++); + table[i].capacity = be32_to_cpu(*list++); + } + } + return 0; } EXPORT_SYMBOL_GPL(power_supply_get_battery_info); +void power_supply_put_battery_info(struct power_supply *psy, + struct power_supply_battery_info *info) +{ + int i; + + for (i = 0; i < POWER_SUPPLY_OCV_TEMP_MAX; i++) + kfree(info->ocv_table[i]); +} +EXPORT_SYMBOL_GPL(power_supply_put_battery_info); + +int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table, + int table_len, int ocv) +{ + int i, cap, tmp; + + for (i = 0; i < table_len; i++) + if (ocv > table[i].ocv) + break; + + if (i > 0 && i < table_len) { + tmp = (table[i - 1].capacity - table[i].capacity) * + (ocv - table[i].ocv); + tmp /= table[i - 1].ocv - table[i].ocv; + cap = tmp + table[i].capacity; + } else if (i == 0) { + cap = table[0].capacity; + } else { + cap = table[table_len - 1].capacity; + } + + return cap; +} +EXPORT_SYMBOL_GPL(power_supply_ocv2cap_simple); + +struct power_supply_battery_ocv_table * +power_supply_find_ocv2cap_table(struct power_supply_battery_info *info, + int temp, int *table_len) +{ + int best_temp_diff = INT_MAX, best_index = 0, temp_diff, i; + + if (!info->ocv_table[0]) + return NULL; + + for (i = 0; i < POWER_SUPPLY_OCV_TEMP_MAX; i++) { + temp_diff = abs(info->ocv_temp[i] - temp); + + if (temp_diff < best_temp_diff) { + best_temp_diff = temp_diff; + best_index = i; + } + } + + *table_len = info->ocv_table_size[best_index]; + return info->ocv_table[best_index]; +} +EXPORT_SYMBOL_GPL(power_supply_find_ocv2cap_table); + +int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info, + int ocv, int temp) +{ + struct power_supply_battery_ocv_table *table; + int table_len; + + table = power_supply_find_ocv2cap_table(info, temp, &table_len); + if (!table) + return -EINVAL; + + return power_supply_ocv2cap_simple(table, table_len, ocv); +} +EXPORT_SYMBOL_GPL(power_supply_batinfo_ocv2cap); + int power_supply_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index d089566..84fe93f 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -309,6 +309,13 @@ struct power_supply_info { int use_for_apm; }; +struct power_supply_battery_ocv_table { + int ocv; /* microVolts */ + int capacity; /* percent */ +}; + +#define POWER_SUPPLY_OCV_TEMP_MAX 20 + /* * This is the recommended struct to manage static battery parameters, * populated by power_supply_get_battery_info(). Most platform drivers should @@ -327,6 +334,9 @@ struct power_supply_battery_info { int constant_charge_current_max_ua; /* microAmps */ int constant_charge_voltage_max_uv; /* microVolts */ int factory_internal_resistance_uohm; /* microOhms */ + int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX];/* celsius */ + struct power_supply_battery_ocv_table *ocv_table[POWER_SUPPLY_OCV_TEMP_MAX]; + int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX]; }; extern struct atomic_notifier_head power_supply_notifier; @@ -350,6 +360,15 @@ extern struct power_supply *devm_power_supply_get_by_phandle( extern int power_supply_get_battery_info(struct power_supply *psy, struct power_supply_battery_info *info); +extern void power_supply_put_battery_info(struct power_supply *psy, + struct power_supply_battery_info *info); +extern int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table, + int table_len, int ocv); +extern struct power_supply_battery_ocv_table * +power_supply_find_ocv2cap_table(struct power_supply_battery_info *info, + int temp, int *table_len); +extern int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info, + int ocv, int temp); extern void power_supply_changed(struct power_supply *psy); extern int power_supply_am_i_supplied(struct power_supply *psy); extern int power_supply_set_input_current_limit_from_supplier( From patchwork Fri Oct 19 10:53:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 149255 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp3143384lji; Fri, 19 Oct 2018 03:53:51 -0700 (PDT) X-Google-Smtp-Source: ACcGV62XYzsrcqLfd8BI/vi6si2+jNJSKHnCIh6LAIuYYMNo/F91eKGTo7wOROmYNULtrCJWyFTX X-Received: by 2002:a63:e04d:: with SMTP id n13-v6mr12947349pgj.426.1539946431706; Fri, 19 Oct 2018 03:53:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539946431; cv=none; d=google.com; s=arc-20160816; b=BBC034WAQUDw87NITRPKn7hYIUP4a7vgD+X5ny/9mAc/M8eCxzZFga6hfvCPFEcAUP kt70O2q3aEwlVnL4nL02YTglt9BvlH7V8pQpnFuJcDQnt8KrqBm3EgGPqsDV6B6Mtqve ShmlRucB1R84y4VpfVq7M40LCWK579OnUd+LGUtKaGVGVhJBsi9hi+nIM2UXqPkoVbI2 vRtqukxsdyRLwgEc3L7O3HYEMjcm48tWwpfQ3F8v55pjkzcU8pSJvvxxUcDfUoleTwv0 HOcPH/yLvnfcIyupzddvGXI2TWto6Z32j9zb3r9v9qqIO7R/1fqR8S/bL8f8i6yMi5vS Rezg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=Yg2NqsPWyEaCTubWb3spqrxS0nBIYblv+mmU9f9ac4E=; b=fBTQc+3wXN7xx3Yq4TBEzf6PZeYZQX131ONrfyVf48jo5nIgWr9LTjpYTXAgwJKcbl NKRG4WtS/Am5ul85fFs+7Qy/LPwyjvMvPyqo45D8H/HSQFiNXKueh3bejPW/JoomX10F JrjnhGooE1WxxmeEKE6ApEtseZmFESOgSf0u/NHqCvo3jskH1vNb81ymEia465ovSvTD jqlJfpxvi/KWW5ZwPHZK0f8/Qs+gfFTcnBzxd1ezTqvB05D4KplwxCWWv/xlY3g34n/c Xt7spZpHRuLQGn/RUh6S6UwT+jqgpHFh0fTyOezq5EhKx0uqra8/9Mj4bFG5fzCkPyb+ V4tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=U4RJBdZW; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d12-v6si25766567pga.81.2018.10.19.03.53.51; Fri, 19 Oct 2018 03:53:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=U4RJBdZW; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727305AbeJSS7W (ORCPT + 6 others); Fri, 19 Oct 2018 14:59:22 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44651 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727300AbeJSS7V (ORCPT ); Fri, 19 Oct 2018 14:59:21 -0400 Received: by mail-pg1-f193.google.com with SMTP id w3-v6so70241pgs.11 for ; Fri, 19 Oct 2018 03:53:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Yg2NqsPWyEaCTubWb3spqrxS0nBIYblv+mmU9f9ac4E=; b=U4RJBdZWaiebK1+vfkLJ7ia5s0uBdGM/QAgsa2iThK6v72RmukPsnB+tGAE9qcB3FX FBTRwl8nAI+LEg20o0enhqQxmN/IPEZ7CZHdyflZRK/xFVB0Ko2QR+eP3uO82dbM0+I6 DATGs9wF7PCIhCOvvTpxYynyJjwc2CNzsZW24= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=Yg2NqsPWyEaCTubWb3spqrxS0nBIYblv+mmU9f9ac4E=; b=fhxUwDR94gSvxQTURkwSF9/8iojnmNmag/N0P3uIs9Km5okpnYuGkMiwJZVe79jCFp NjdMKhCEe8/cAQXZ452SfJ8GYIc2KMc/iVX2XrC/7rJuTvPVfhHN0de3OONsDKS2x20n N6ANJGypSEE8h8FiIj8C9t2pekkwfC7Sn0vxoJwo1M0+qjDvZDVpC6294WclyuYlj1x9 OKHt+ZURHYdVk8fGmQIXZ+B+FO/MHZTtx8moPcQj1Drvog6H/0seaqtu+SCJPYm/l3uE j4Di2PLF47sRiCG99D4V2SxV3QR+HqdIeCD67sibS6QWgmBeaVKKTs2fbDzZ/bx1GUbu zTmg== X-Gm-Message-State: ABuFfoixvcddncjTSh1a8onPN31gY2W6kBMXExkVqFLItT5Au5kc5ilU OZrgxHzJU49bo9Kc8sgWt4x24g== X-Received: by 2002:a63:5949:: with SMTP id j9-v6mr32169578pgm.210.1539946428500; Fri, 19 Oct 2018 03:53:48 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id m67-v6sm54918pfm.13.2018.10.19.03.53.44 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Oct 2018 03:53:47 -0700 (PDT) From: Baolin Wang To: sre@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, yuanjiang.yu@unisoc.com, baolin.wang@linaro.org, broonie@kernel.org, ctatlor97@gmail.com, linus.walleij@linaro.org Subject: [PATCH v5 5/6] dt-bindings: power: Add Spreadtrum SC27XX fuel gauge unit documentation Date: Fri, 19 Oct 2018 18:53:14 +0800 Message-Id: <14b947c6195133ed93cf0302b1575c033c4ccf04.1539915051.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This patch adds the binding documentation for Spreadtrum SC27XX series PMICs fuel gauge unit device, which is used to calculate the battery capacity. Signed-off-by: Baolin Wang Reviewed-by: Linus Walleij Reviewed-by: Rob Herring --- Changes from v4: - None. Changes from v3: - Add reviewed tag from Rob. Changes from v2: - Add reviewed tag from Linus. Changes from v1: - Renamed GPIO property. - Use standand battery properties instead of 'sprd,inner-resist' and 'sprd,ocv-cap-table'. - Remove battery node's description. --- .../devicetree/bindings/power/supply/sc27xx-fg.txt | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/sc27xx-fg.txt -- 1.7.9.5 diff --git a/Documentation/devicetree/bindings/power/supply/sc27xx-fg.txt b/Documentation/devicetree/bindings/power/supply/sc27xx-fg.txt new file mode 100644 index 0000000..98a2400 --- /dev/null +++ b/Documentation/devicetree/bindings/power/supply/sc27xx-fg.txt @@ -0,0 +1,52 @@ +Spreadtrum SC27XX PMICs Fuel Gauge Unit Power Supply Bindings + +Required properties: +- compatible: Should be one of the following: + "sprd,sc2720-fgu", + "sprd,sc2721-fgu", + "sprd,sc2723-fgu", + "sprd,sc2730-fgu", + "sprd,sc2731-fgu". +- reg: The address offset of fuel gauge unit. +- battery-detect-gpios: GPIO for battery detection. +- io-channels: Specify the IIO ADC channel to get temperature. +- io-channel-names: Should be "bat-temp". +- monitored-battery: Phandle of battery characteristics devicetree node. + See Documentation/devicetree/bindings/power/supply/battery.txt + +Example: + + bat: battery { + compatible = "simple-battery"; + charge-full-design-microamp-hours = <1900000>; + constant-charge-voltage-max-microvolt = <4350000>; + ocv-capacity-celsius = <20>; + ocv-capacity-table-0 = <4185000 100>, <4113000 95>, <4066000 90>, + <4022000 85>, <3983000 80>, <3949000 75>, + <3917000 70>, <3889000 65>, <3864000 60>, + <3835000 55>, <3805000 50>, <3787000 45>, + <3777000 40>, <3773000 35>, <3770000 30>, + <3765000 25>, <3752000 20>, <3724000 15>, + <3680000 10>, <3605000 5>, <3400000 0>; + ...... + }; + + sc2731_pmic: pmic@0 { + compatible = "sprd,sc2731"; + reg = <0>; + spi-max-frequency = <26000000>; + interrupts = ; + interrupt-controller; + #interrupt-cells = <2>; + #address-cells = <1>; + #size-cells = <0>; + + fgu@a00 { + compatible = "sprd,sc2731-fgu"; + reg = <0xa00>; + battery-detect-gpios = <&pmic_eic 9 GPIO_ACTIVE_HIGH>; + io-channels = <&pmic_adc 5>; + io-channel-names = "bat-temp"; + monitored-battery = <&bat>; + }; + };