From patchwork Mon Oct 22 07:43:59 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: 149376 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2317919lji; Mon, 22 Oct 2018 00:44:38 -0700 (PDT) X-Google-Smtp-Source: ACcGV62h8G27FWf0o2Qx9Ua+pj5jiOG5qTD8ki2jsoB3r0oCAOdeZ5fumXPSsfBqKJqUkOpJ3eaD X-Received: by 2002:a62:1985:: with SMTP id 127-v6mr43500463pfz.51.1540194278456; Mon, 22 Oct 2018 00:44:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540194278; cv=none; d=google.com; s=arc-20160816; b=F41U5GT0rDeIzm5B79ii9xxfKH4gohKDaNCLCUQK71QvjA3q8/zMup6fBH8fdPH/Pk jFEAqR5m9p7SrKxKdC/Zmps1ied8wYX4AZQWd2apQzbFsyhNqSVL1qILqvmWjcfE2v9I TXQaN4gsOus/+PI9O6nFA6D1mw5RTY6gXCm7b9Sec4kqli4rSMPL9/8Fn+v2EQWi0gh4 pCLUiTOxTtPkirRlCnIUSqHyaCwIDvNDRjLAUjWkFWBGtpeKO+eYJooHbw/jRPipvrZI 6QfZJ6Ml5AVkFam1QWLng1jiQcNKS8/enfPikmBT8yKhp9DzX+mT1x6xG8lNEcQkPwv6 4uCw== 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=Rzrg3Nb5SBp7VXw/4XGUW1RnZO/wOXB9fjUvxLQgixU=; b=C7BCnVJHiBdkDH8HOc/glM3leI4+GPFHOJfqx72Xylfp0Cbr/H1eak24Xf8BrbDo0c ZhmbFtfY5bV2zd26AonuI9kvJAR3fJobt+5BNEtyp5miqcLrO8BcuOKHVwPy8dPSVBMf talGzGrFl0Eo0oUakgRr2qoAnJiIG+ZpMEOKCwd3fZte7kFfHPzMWUUH17d17U78O8Dq go55BdjNvJzUcSEktkUdcrsAHotMt7fMuKFkxz8XdakHcRAXvQnw/a2YTRkrjJFH09Ip kbg2JhlMz9c2WKN+p9miHqry/2gkWlMW8t/6Ker2XvCcqvq5cI6RR4JyEiVo7jXzeNCF 4a6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CNSutfge; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 e193-v6si32528205pfc.131.2018.10.22.00.44.38; Mon, 22 Oct 2018 00:44:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=CNSutfge; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1727850AbeJVQB7 (ORCPT + 10 others); Mon, 22 Oct 2018 12:01:59 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:33335 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727793AbeJVQB6 (ORCPT ); Mon, 22 Oct 2018 12:01:58 -0400 Received: by mail-pl1-f196.google.com with SMTP id x6-v6so1834996pln.0 for ; Mon, 22 Oct 2018 00:44:35 -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=Rzrg3Nb5SBp7VXw/4XGUW1RnZO/wOXB9fjUvxLQgixU=; b=CNSutfgeYez61SScuGiZBcS0sQx0HpKErIh5fP+To7wM2JI32SOunMCA8/x8jM2yUh VKfZpJY7VYNnwcP4RO/uawA5icXn/x0urmaoMLC4ZWOE5AacGLOTt5/pfFvBYy4WGIai AAZcz/UplOKkCsmP5pxU6NgnrzZyvIuyvhPmM= 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=Rzrg3Nb5SBp7VXw/4XGUW1RnZO/wOXB9fjUvxLQgixU=; b=dp36ltLsNbhFxUTYyf5Mi2nScBgeJN+bv+5DYaGk3cNmpCgj3eiApIX3a7ReFr2d9J IJo8N2Z/ODfGWf9XF+MuvgxFjf1hsSbN5a89OHPxrQKCReudreJXAmHHhqyDoqR+3Ggd C51ihIPPUKDku/hQwhFiLH5mMdIBMxz5Gag3VckhWjWU5sj2kSQXKFiFwinCeRl8LGDQ ebqlRhyhy7SNU5WvwQziL6zwiJkTlMu/0uAZ1wxKkQUyeFFcG/hWIMMcZqkMp3DLhrc5 DnICRZLSsf2Lsf3lA8hIF18nt8W7nBb4KyG9HusKtqZw1nRuiGNpPzErzPalfO8POCPK TGkw== X-Gm-Message-State: AGRZ1gJNkR9pR3S6UojXB9ESkMSbJWtdO2EpEY+94HYoK6ND3I3oYC3I DyTCY0lo7WW3tdWfWLT9x2kXog== X-Received: by 2002:a17:902:6b04:: with SMTP id o4-v6mr3255754plk.333.1540194275537; Mon, 22 Oct 2018 00:44:35 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id d186-v6sm43704253pfg.173.2018.10.22.00.44.32 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Oct 2018 00:44:34 -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 v6 3/6] dt-bindings: power: Introduce properties to present the battery OCV capacity table Date: Mon, 22 Oct 2018 15:43:59 +0800 Message-Id: <3a0c6487c9503cf64432f630e65790cc5c3f70ab.1540189330.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Some battery driver will use the open circuit voltage (OCV) value to look up the corresponding battery capacity percent in one certain degree Celsius. Thus this patch provides some battery properties to present the OCV table temperatures and OCV capacity table values. Suggested-by: Sebastian Reichel Signed-off-by: Baolin Wang Reviewed-by: Linus Walleij --- Changes from v5: - None. Changes from v4: - Improve the description of ocv-capacity-table-n to make the order clear. Changes from v3: - Split binding into one separate patch. - Rename ocv-capacity-table-temperatures to ocv-capacity-celsius. - Add some words to specify the OCV's unit. 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. --- .../devicetree/bindings/power/supply/battery.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) -- 1.7.9.5 diff --git a/Documentation/devicetree/bindings/power/supply/battery.txt b/Documentation/devicetree/bindings/power/supply/battery.txt index 938d027..89871ab 100644 --- a/Documentation/devicetree/bindings/power/supply/battery.txt +++ b/Documentation/devicetree/bindings/power/supply/battery.txt @@ -23,6 +23,17 @@ Optional Properties: - 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 + - ocv-capacity-table-0: An array providing the open circuit voltage (OCV) + of the battery and corresponding battery capacity percent, which is used + to look up battery capacity according to current OCV value. And the open + circuit voltage unit is microvolt. + - ocv-capacity-table-1: Same as ocv-capacity-table-0 + ...... + - ocv-capacity-table-n: Same as ocv-capacity-table-0 + - ocv-capacity-celsius: An array containing the temperature in degree Celsius, + for each of the battery capacity lookup table. The first temperature value + specifies the OCV table 0, and the second temperature value specifies the + OCV table 1, and so on. Battery properties are named, where possible, for the corresponding elements in enum power_supply_property, defined in @@ -44,6 +55,10 @@ Example: constant-charge-current-max-microamp = <900000>; constant-charge-voltage-max-microvolt = <4200000>; factory-internal-resistance-micro-ohms = <250000>; + ocv-capacity-celsius = <(-10) 0 10>; + ocv-capacity-table-0 = <4185000 100>, <4113000 95>, <4066000 90>, ...; + ocv-capacity-table-1 = <4200000 100>, <4185000 95>, <4113000 90>, ...; + ocv-capacity-table-2 = <4250000 100>, <4200000 95>, <4185000 90>, ...; }; charger: charger@11 { From patchwork Mon Oct 22 07:44:00 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: 149377 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2317954lji; Mon, 22 Oct 2018 00:44:42 -0700 (PDT) X-Google-Smtp-Source: ACcGV63vqk/I8hLuIMC6gPfyI3juuK4p4EW+zEkygS/VsopXYcDLxfuGIF3/eT5RDjxw/Z4mzUbH X-Received: by 2002:a65:5608:: with SMTP id l8-v6mr12029683pgs.433.1540194282150; Mon, 22 Oct 2018 00:44:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540194282; cv=none; d=google.com; s=arc-20160816; b=js/mLwLHVWxGWWvoJ04VNqDt7k9KO2jiZndElvaYOnCZa4Z2BW+Wu62MsAzt2RnAkQ s/FpfKtvCzZVdDwrILuqcKhlWgRcUmllZ14Gse7ufikscJDM5/lPMa2Dfz1uufGMDK5h KzqhtlFdZIVCY5IjpEv/eD3u3bz0reqksmQBB28HZ2izZxE0RPq4lfZdcAZGHE8OAWMJ 1flwTGcHrNyls9EsWw0XhXP7CuBYqcLPWy776G3jjBZnY9NztxPj8ZhBTIx5uNs1xNiI 5z74yfflabynt/JpJzDNmShnIniFY0Dpk0bkBcWRfTYbVrTI/ukK1RgcCRYmju713ufw airw== 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=Z57yf52t/lWuTj+rST8ssOx3kmGLn9qQywFmkfd/Lr4=; b=d83o+YXcWHeNyyH/9j2gg5+I/angSEGpWLKFgUo8hqUoT+lGO/t4y85VH1hf81o7xl 3WmIX+IkJzG8o//4J6/2RLzQFyoe6UaFV61Cvu5VJJ1bl6HjWuYiIewvJGA8Sy3Sy1Yz ifUZMEQu4EyAbHbre8vWQxSQPknI7/ND7pD7w8Vq/nJKEREIu5PYRLtkfe3JuMgmO8Vy CMtH8+7xNo5JxnhpZu9IJV1XkW2uCnyUfMdANe4iczJftv/a8VgQ355uXBfkLbY6ALqy R1FEIhmBsUbGrleTWWL06rZdJ4f3v0q9a5hHKxgSbBf3gIA5LGPVojdWNMGYQZcGhoN2 6tbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eo7lLpaM; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 f1-v6si28705730pld.49.2018.10.22.00.44.41; Mon, 22 Oct 2018 00:44:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=eo7lLpaM; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1727962AbeJVQCC (ORCPT + 10 others); Mon, 22 Oct 2018 12:02:02 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41635 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727852AbeJVQCC (ORCPT ); Mon, 22 Oct 2018 12:02:02 -0400 Received: by mail-pg1-f194.google.com with SMTP id 23-v6so18616534pgc.8 for ; Mon, 22 Oct 2018 00:44:39 -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=Z57yf52t/lWuTj+rST8ssOx3kmGLn9qQywFmkfd/Lr4=; b=eo7lLpaMop1ejlZGFKbaRKfwcscxdS1bYE4o+pSQQZ2xJQb1afje+P8ozYo0WfeoId 6p7KWbVbaMSiQglLpKBcq54p1jPv2YBJRjZrwiY6lwUBvon4huOZse1+NL6GHglow6w3 AJg5GPl4aCMtRjekbH2QlZGK1er9XNA/9ibXY= 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=Z57yf52t/lWuTj+rST8ssOx3kmGLn9qQywFmkfd/Lr4=; b=ikqXW1W9t3TopByiBdkhGGFcQE1mkN4WkA2VJQUQzdGu3u94L3mFj3jKc1Tgi9nK2D aV3w9y675NjjxniP0Q8PQZq+I7V+fhHN8FicOhUXR9TRiYvPoJ/lEfaxc1Vk3rk/7kap VSPpk6Jny2G6uJMjfsjz45eqHFpIvbmKf2Zt1FrIede7kKAnF9J7S8Foyd5qM994raZV rx4YVVObY30NR4dabkCDngz0cmXz9yUHWQR07YZJVzN7YV9CL1Ch5U++fazVnGHAglMU TS3apECPXTuvtn8J94XtIXKDBos7xi3Offmi8FZwV2aQ3CSe0cqijGuh9QI9jEaOSqYV VcaQ== X-Gm-Message-State: ABuFfojmHpq5A5LIjysZkMZGriX9UXlyvM7E0Ecy9IlmTijqBsq/psk/ +Sxn6GF6nRoXDXT9FLrDqHDM9Q== X-Received: by 2002:a63:36c8:: with SMTP id d191-v6mr10870120pga.404.1540194279090; Mon, 22 Oct 2018 00:44:39 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id d186-v6sm43704253pfg.173.2018.10.22.00.44.35 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Oct 2018 00:44:38 -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 v6 4/6] power: supply: core: Add some helpers to use the battery OCV capacity table Date: Mon, 22 Oct 2018 15:44:00 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 v5: - None. 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 Mon Oct 22 07:44:01 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: 149378 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2317990lji; Mon, 22 Oct 2018 00:44:45 -0700 (PDT) X-Google-Smtp-Source: ACcGV60JaMMvyt/NDG8So82vm+zSwFfmWsoqX++xIowUCWS1p4RhmF3a7CK2OhJpTvLS4v7Hugap X-Received: by 2002:a62:35c2:: with SMTP id c185-v6mr44319971pfa.69.1540194285147; Mon, 22 Oct 2018 00:44:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540194285; cv=none; d=google.com; s=arc-20160816; b=k0c8g7Z4jiRpgeBGrgxaUu5mhHGK7PmMCEwCSsBAFBRY/8cDxZqjXQXVNHqozVW34q AQKBOEOix38MlaYFRtVWNRUEWYSM6ofgGBBCy0dK7XCdISG0PSAvzqb6bkDWyKxSL2n4 xUVJmZsfHA6R6CKbD4SK0UH2oAQujiLcPlF683/POU2rgkuZNYhzb4qBI/WhCyna+Tfh sH9W9kIIdpoKyktMArhYGYsszY7yB8jCOjXhKhHnZzKLdYD+DqzYzZ0FY3JcySsveC7T lLeM+mvHeKlyxXKxG5h0e41+4ARnWpprYRkZKwBK0qkJI03GLf4baPhGDJNPSg3tMx9Z D0uw== 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=+Y1K5QL8FD/m4PSkMA+x2dLfylUdGuE/onAnmlwpJnk=; b=LAfaa1YTNsbjz5Y8fIk8Q3CDqBbw1XlbeA9/iy/ZXH7wW/Lb3KK7MPfcCRSCWIaYiA W3emfq0mZfuSW8o14YtkIQqrcUFXMxg8yvNncSClmimR3N0lX0P8277wJ1DBAVORsa/B tgIoELcdrZ9nTUT6IkErn6gEKAXlYXmHVwVvenbQerSknMyAjJsrrEsI57aB5mYL07pN gL5c77Kn2JeNScUWSn/elVVyUrkJ9leUbjx/o2tqlgmvqgkr1xfiM+SA2A8c5Wr69mXK jjPJbKlBHyzkllep93uMfHc5HK6IdiT1AfPLQXRTkSMs1TPYdjQfm6W7d83IbOPlD9Bd mkMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="CmP5/V8n"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 q33-v6si16908887pgk.2.2018.10.22.00.44.44; Mon, 22 Oct 2018 00:44:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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="CmP5/V8n"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1728030AbeJVQCF (ORCPT + 10 others); Mon, 22 Oct 2018 12:02:05 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43020 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728028AbeJVQCF (ORCPT ); Mon, 22 Oct 2018 12:02:05 -0400 Received: by mail-pf1-f194.google.com with SMTP id q1-v6so2165202pfh.10 for ; Mon, 22 Oct 2018 00:44:43 -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=+Y1K5QL8FD/m4PSkMA+x2dLfylUdGuE/onAnmlwpJnk=; b=CmP5/V8nV0BmV0qLAy7IUWvAfBz0CnB7OzWcIm1CAs+IxuBnpYk3LM1C07hem02BAM Hafk97ZJew6AgGljwpg4SsBYiNVWIHKwTbNjTrULZEacFdAWpZUmpsuLJ2CTTJXcVdqK UwOj++E/noEmmUkXt5f1YtoNcs0j1RP5p/jeg= 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=+Y1K5QL8FD/m4PSkMA+x2dLfylUdGuE/onAnmlwpJnk=; b=fmS4V/yLKK+2KDZLCg0l3gQwHQhUvIlGH4Krb8AB4tSODGavECqXRLdAdz9E9jbKC5 iRnvsh69Zy6ow9QN+na+LBKZoMKhzNJx/8kJmMaOKA2CSPhh2Pz+RfIJukuoSFcVRQyx jqoDwU0dQ1rP1dHHJrt92gCrj4ceZFqZ4YzIEj6gxRVkKReWpDKlYDWEH9IL783S1CDs VQ6lUH+IYT9VE5ImiV8e+MesxvkgwBZsxQikvjlknM7y1bNJd7g7zoACaTQR3gjDEG8j eLFIau2xJF5iEy7eGbXWb80f7dXCgfb/n+bI+wcD3AvJkBVLS8SV2ia/hNQ39nQ5v6fx 1M5g== X-Gm-Message-State: ABuFfoi+AM+p2hccJodutnHj8hlF3HEpZF5HHP9JH/GARhrLlPZG4sS3 w30hc8Dw21AkOdMribdG0vEGRg== X-Received: by 2002:a65:47cb:: with SMTP id f11-v6mr42826682pgs.166.1540194282691; Mon, 22 Oct 2018 00:44:42 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id d186-v6sm43704253pfg.173.2018.10.22.00.44.39 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Oct 2018 00:44:41 -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 v6 5/6] dt-bindings: power: Add Spreadtrum SC27XX fuel gauge unit documentation Date: Mon, 22 Oct 2018 15:44:01 +0800 Message-Id: <14b947c6195133ed93cf0302b1575c033c4ccf04.1540189330.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 v5: - None. 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>; + }; + };