From patchwork Wed May 13 18:55:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547115 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 68E29618 for ; Wed, 13 May 2020 18:58:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D0E32065C for ; Wed, 13 May 2020 18:58:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390583AbgEMS56 (ORCPT ); Wed, 13 May 2020 14:57:58 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51866 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732218AbgEMS4d (ORCPT ); Wed, 13 May 2020 14:56:33 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id D22F82A0188 Received: by jupiter.universe (Postfix, from userid 1000) id 6697A4800FF; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 01/19] kobject: increase allowed number of uevent variables Date: Wed, 13 May 2020 20:55:57 +0200 Message-Id: <20200513185615.508236-2-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org SBS battery driver exposes 32 power supply properties now, which will result in uevent failure on (un)plugging the battery. Other drivers (e.g. bq27xxx) are also coming close to this limit, so increase it. Signed-off-by: Sebastian Reichel Acked-by: Greg Kroah-Hartman Reviewed-by: Emil Velikov --- include/linux/kobject.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/kobject.h b/include/linux/kobject.h index e2ca0a292e21..75e822569e39 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -29,7 +29,7 @@ #include #define UEVENT_HELPER_PATH_LEN 256 -#define UEVENT_NUM_ENVP 32 /* number of env pointers */ +#define UEVENT_NUM_ENVP 64 /* number of env pointers */ #define UEVENT_BUFFER_SIZE 2048 /* buffer for the variables */ #ifdef CONFIG_UEVENT_HELPER From patchwork Wed May 13 18:55:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547117 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 10160912 for ; Wed, 13 May 2020 18:58:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 31A602065C for ; Wed, 13 May 2020 18:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390363AbgEMS4d (ORCPT ); Wed, 13 May 2020 14:56:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2390361AbgEMS4d (ORCPT ); Wed, 13 May 2020 14:56:33 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38190C061A0C; Wed, 13 May 2020 11:56:33 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id D71732A251E Received: by jupiter.universe (Postfix, from userid 1000) id 6A140480100; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 02/19] power: supply: core: add capacity error margin property Date: Wed, 13 May 2020 20:55:58 +0200 Message-Id: <20200513185615.508236-3-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add a property for reporting the error margin expected by fuel gauge chips. Signed-off-by: Sebastian Reichel --- Documentation/ABI/testing/sysfs-class-power | 15 +++++++++++++++ drivers/power/supply/power_supply_sysfs.c | 1 + include/linux/power_supply.h | 1 + 3 files changed, 17 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/ABI/testing/sysfs-class-power index bf3b48f022dc..2f896555ae23 100644 --- a/Documentation/ABI/testing/sysfs-class-power +++ b/Documentation/ABI/testing/sysfs-class-power @@ -74,6 +74,21 @@ Description: Access: Read, Write Valid values: 0 - 100 (percent) +What: /sys/class/power_supply//capacity_error_margin +Date: April 2019 +Contact: linux-pm@vger.kernel.org +Description: + Battery capacity measurement becomes unreliable without + recalibration. This values provides the maximum error + margin expected to exist by the fuel gauge in percent. + Values close to 0% will be returned after (re-)calibration + has happened. Over time the error margin will increase. + 100% means, that the capacity related values are basically + completely useless. + + Access: Read + Valid values: 0 - 100 (percent) + What: /sys/class/power_supply//capacity_level Date: June 2009 Contact: linux-pm@vger.kernel.org diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index d21b4e0edf38..e664774a2d1e 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -178,6 +178,7 @@ static struct power_supply_attr power_supply_attrs[] = { POWER_SUPPLY_ATTR(CAPACITY), POWER_SUPPLY_ATTR(CAPACITY_ALERT_MIN), POWER_SUPPLY_ATTR(CAPACITY_ALERT_MAX), + POWER_SUPPLY_ATTR(CAPACITY_ERROR_MARGIN), POWER_SUPPLY_ENUM_ATTR(CAPACITY_LEVEL), POWER_SUPPLY_ATTR(TEMP), POWER_SUPPLY_ATTR(TEMP_MAX), diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 1f60731ec7fe..453a85f25635 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -139,6 +139,7 @@ enum power_supply_property { POWER_SUPPLY_PROP_CAPACITY, /* in percents! */ POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, /* in percents! */ POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */ + POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN, /* in percents! */ POWER_SUPPLY_PROP_CAPACITY_LEVEL, POWER_SUPPLY_PROP_TEMP, POWER_SUPPLY_PROP_TEMP_MAX, From patchwork Wed May 13 18:55:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547111 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E9800618 for ; Wed, 13 May 2020 18:57:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A8BC2065C for ; Wed, 13 May 2020 18:57:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390374AbgEMS4e (ORCPT ); Wed, 13 May 2020 14:56:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2390370AbgEMS4d (ORCPT ); Wed, 13 May 2020 14:56:33 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B186FC061A0C; Wed, 13 May 2020 11:56:33 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id E65ED2A27A9 Received: by jupiter.universe (Postfix, from userid 1000) id 6C7E8480101; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 03/19] power: supply: core: add manufacture date properties Date: Wed, 13 May 2020 20:55:59 +0200 Message-Id: <20200513185615.508236-4-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Some smart batteries store their manufacture date, which is useful to identify the battery and/or to know about the cell quality. Signed-off-by: Sebastian Reichel --- Documentation/ABI/testing/sysfs-class-power | 28 +++++++++++++++++++++ drivers/power/supply/power_supply_sysfs.c | 3 +++ include/linux/power_supply.h | 3 +++ 3 files changed, 34 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/ABI/testing/sysfs-class-power index 2f896555ae23..e6d7348766b2 100644 --- a/Documentation/ABI/testing/sysfs-class-power +++ b/Documentation/ABI/testing/sysfs-class-power @@ -680,3 +680,31 @@ Description: Valid values: - 1: enabled - 0: disabled + +What: /sys/class/power_supply//manufacture_year +Date: January 2020 +Contact: linux-pm@vger.kernel.org +Description: + Reports the year (following Gregorian calendar) when the device has been + manufactured. + + Access: Read + Valid values: Reported as integer + +What: /sys/class/power_supply//manufacture_month +Date: January 2020 +Contact: linux-pm@vger.kernel.org +Description: + Reports the month when the device has been manufactured. + + Access: Read + Valid values: 1-12 + +What: /sys/class/power_supply//manufacture_day +Date: January 2020 +Contact: linux-pm@vger.kernel.org +Description: + Reports the day of month when the device has been manufactured. + + Access: Read + Valid values: 1-31 diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index e664774a2d1e..78d5382e69f1 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -198,6 +198,9 @@ static struct power_supply_attr power_supply_attrs[] = { POWER_SUPPLY_ATTR(PRECHARGE_CURRENT), POWER_SUPPLY_ATTR(CHARGE_TERM_CURRENT), POWER_SUPPLY_ATTR(CALIBRATE), + POWER_SUPPLY_ATTR(MANUFACTURE_YEAR), + POWER_SUPPLY_ATTR(MANUFACTURE_MONTH), + POWER_SUPPLY_ATTR(MANUFACTURE_DAY), /* Properties of type `const char *' */ POWER_SUPPLY_ATTR(MODEL_NAME), POWER_SUPPLY_ATTR(MANUFACTURER), diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 453a85f25635..63ffe2a0a87b 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -159,6 +159,9 @@ enum power_supply_property { POWER_SUPPLY_PROP_PRECHARGE_CURRENT, POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, POWER_SUPPLY_PROP_CALIBRATE, + POWER_SUPPLY_PROP_MANUFACTURE_YEAR, + POWER_SUPPLY_PROP_MANUFACTURE_MONTH, + POWER_SUPPLY_PROP_MANUFACTURE_DAY, /* Properties of type `const char *' */ POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_MANUFACTURER, From patchwork Wed May 13 18:56:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547113 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4DCA4618 for ; Wed, 13 May 2020 18:58:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F81D2065C for ; Wed, 13 May 2020 18:57:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389946AbgEMS5y (ORCPT ); Wed, 13 May 2020 14:57:54 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51886 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390068AbgEMS4e (ORCPT ); Wed, 13 May 2020 14:56:34 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id E38EE2A25D4 Received: by jupiter.universe (Postfix, from userid 1000) id 6F40C480102; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 04/19] power: supply: core: add POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED Date: Wed, 13 May 2020 20:56:00 +0200 Message-Id: <20200513185615.508236-5-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Some battery fuel gauges know when the battery needs to be recalibrated before providing usable values. This should be reported via the health property. Signed-off-by: Sebastian Reichel --- Documentation/ABI/testing/sysfs-class-power | 2 +- drivers/power/supply/power_supply_sysfs.c | 1 + include/linux/power_supply.h | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/ABI/testing/sysfs-class-power index e6d7348766b2..216d61a22f1e 100644 --- a/Documentation/ABI/testing/sysfs-class-power +++ b/Documentation/ABI/testing/sysfs-class-power @@ -205,7 +205,7 @@ Description: Valid values: "Unknown", "Good", "Overheat", "Dead", "Over voltage", "Unspecified failure", "Cold", "Watchdog timer expire", "Safety timer expire", - "Over current" + "Over current", "Calibration required" What: /sys/class/power_supply//precharge_current Date: June 2017 diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index 78d5382e69f1..bc79560229b5 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -100,6 +100,7 @@ static const char * const POWER_SUPPLY_HEALTH_TEXT[] = { [POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE] = "Watchdog timer expire", [POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE] = "Safety timer expire", [POWER_SUPPLY_HEALTH_OVERCURRENT] = "Over current", + [POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED] = "Calibration required", }; static const char * const POWER_SUPPLY_TECHNOLOGY_TEXT[] = { diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 63ffe2a0a87b..ac1345a48ad0 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -61,6 +61,7 @@ enum { POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE, POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE, POWER_SUPPLY_HEALTH_OVERCURRENT, + POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED, }; enum { From patchwork Wed May 13 18:56:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547091 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E60FD139A for ; Wed, 13 May 2020 18:57:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 154492054F for ; Wed, 13 May 2020 18:57:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390403AbgEMS4g (ORCPT ); Wed, 13 May 2020 14:56:36 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51900 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390381AbgEMS4g (ORCPT ); Wed, 13 May 2020 14:56:36 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id 4724A2A0188 Received: by jupiter.universe (Postfix, from userid 1000) id 7203A480103; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 05/19] power: supply: sbs-battery: Add TI BQ20Z65 support Date: Wed, 13 May 2020 20:56:01 +0200 Message-Id: <20200513185615.508236-6-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add support for BQ20Z65 manufacturer data to the sbs-battery driver. Implementation has been verified using the public TRM available from [0] and tested using a GE Flex 3S2P battery. [0] http://www.ti.com/lit/pdf/sluu386 Signed-off-by: Sebastian Reichel Acked-by: Rob Herring --- .../bindings/power/supply/sbs_sbs-battery.txt | 1 + drivers/power/supply/sbs-battery.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt b/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt index 4e78e51018eb..fa5a8b516dbf 100644 --- a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt +++ b/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt @@ -6,6 +6,7 @@ Required properties : part number compatible string might be used in order to take care of vendor specific registers. Known ,: + ti,bq20z65 ti,bq20z75 Optional properties : diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index 6acd242eed48..a15783802ef8 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -149,8 +149,8 @@ static enum power_supply_property sbs_properties[] = { POWER_SUPPLY_PROP_MODEL_NAME }; -/* Supports special manufacturer commands from TI BQ20Z75 IC. */ -#define SBS_FLAGS_TI_BQ20Z75 BIT(0) +/* Supports special manufacturer commands from TI BQ20Z65 and BQ20Z75 IC. */ +#define SBS_FLAGS_TI_BQ20ZX5 BIT(0) struct sbs_info { struct i2c_client *client; @@ -626,7 +626,7 @@ static int sbs_get_property(struct power_supply *psy, switch (psp) { case POWER_SUPPLY_PROP_PRESENT: case POWER_SUPPLY_PROP_HEALTH: - if (chip->flags & SBS_FLAGS_TI_BQ20Z75) + if (chip->flags & SBS_FLAGS_TI_BQ20ZX5) ret = sbs_get_ti_battery_presence_and_health(client, psp, val); else @@ -950,7 +950,7 @@ static int sbs_suspend(struct device *dev) if (chip->poll_time > 0) cancel_delayed_work_sync(&chip->work); - if (chip->flags & SBS_FLAGS_TI_BQ20Z75) { + if (chip->flags & SBS_FLAGS_TI_BQ20ZX5) { /* Write to manufacturer access with sleep command. */ ret = sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr, @@ -970,6 +970,7 @@ static SIMPLE_DEV_PM_OPS(sbs_pm_ops, sbs_suspend, NULL); #endif static const struct i2c_device_id sbs_id[] = { + { "bq20z65", 0 }, { "bq20z75", 0 }, { "sbs-battery", 1 }, {} @@ -978,9 +979,13 @@ MODULE_DEVICE_TABLE(i2c, sbs_id); static const struct of_device_id sbs_dt_ids[] = { { .compatible = "sbs,sbs-battery" }, + { + .compatible = "ti,bq20z65", + .data = (void *)SBS_FLAGS_TI_BQ20ZX5, + }, { .compatible = "ti,bq20z75", - .data = (void *)SBS_FLAGS_TI_BQ20Z75, + .data = (void *)SBS_FLAGS_TI_BQ20ZX5, }, { } }; From patchwork Wed May 13 18:56:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547107 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 275E7912 for ; Wed, 13 May 2020 18:57:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45F242065C for ; Wed, 13 May 2020 18:57:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390542AbgEMS5a (ORCPT ); Wed, 13 May 2020 14:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2390389AbgEMS4f (ORCPT ); Wed, 13 May 2020 14:56:35 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7721EC061A0C; Wed, 13 May 2020 11:56:35 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id 4A0F92A251E Received: by jupiter.universe (Postfix, from userid 1000) id 74B84480104; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 06/19] power: supply: sbs-battery: add POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN support Date: Wed, 13 May 2020 20:56:02 +0200 Message-Id: <20200513185615.508236-7-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add support for reporting the MaxError register from battery fuel gauges following the smart battery standard. Signed-off-by: Sebastian Reichel --- drivers/power/supply/sbs-battery.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index a15783802ef8..4356fdf25d4a 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -26,6 +26,7 @@ enum { REG_TEMPERATURE, REG_VOLTAGE, REG_CURRENT, + REG_MAX_ERR, REG_CAPACITY, REG_TIME_TO_EMPTY, REG_TIME_TO_FULL, @@ -85,6 +86,8 @@ static const struct chip_data { SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_NOW, 0x09, 0, 20000), [REG_CURRENT] = SBS_DATA(POWER_SUPPLY_PROP_CURRENT_NOW, 0x0A, -32768, 32767), + [REG_MAX_ERR] = + SBS_DATA(POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN, 0x0c, 0, 100), [REG_CAPACITY] = SBS_DATA(POWER_SUPPLY_PROP_CAPACITY, 0x0D, 0, 100), [REG_REMAINING_CAPACITY] = @@ -132,6 +135,7 @@ static enum power_supply_property sbs_properties[] = { POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_CAPACITY, + POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN, POWER_SUPPLY_PROP_TEMP, POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, @@ -676,6 +680,7 @@ static int sbs_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: case POWER_SUPPLY_PROP_CAPACITY: + case POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN: ret = sbs_get_property_index(client, psp); if (ret < 0) break; From patchwork Wed May 13 18:56:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547103 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A6AD4618 for ; Wed, 13 May 2020 18:57:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C88C920722 for ; Wed, 13 May 2020 18:57:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390533AbgEMS5a (ORCPT ); Wed, 13 May 2020 14:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2390394AbgEMS4g (ORCPT ); Wed, 13 May 2020 14:56:36 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEE64C05BD09; Wed, 13 May 2020 11:56:35 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id 4D5722A2521 Received: by jupiter.universe (Postfix, from userid 1000) id 777C3480105; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 07/19] power: supply: sbs-battery: simplify read_read_string_data Date: Wed, 13 May 2020 20:56:03 +0200 Message-Id: <20200513185615.508236-8-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The SBS battery implements SMBus block reads. Currently the driver "emulates" this by doing an I2C byte read for the length followed by an I2C block read. The I2C subsystem actually provides a proper API for doing SMBus block reads, which can and should be used instead. The current implementation does not properly handle packet error checking (PEC). This change requires, that I2C bus drivers support I2C_M_RECV_LEN or directly provide the SMBus API to access device manufacturer and model name. Signed-off-by: Sebastian Reichel --- drivers/power/supply/sbs-battery.c | 65 ++++++------------------------ 1 file changed, 12 insertions(+), 53 deletions(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index 4356fdf25d4a..a9a1d28dabbe 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -202,66 +202,32 @@ static int sbs_read_string_data(struct i2c_client *client, u8 address, char *values) { struct sbs_info *chip = i2c_get_clientdata(client); - s32 ret = 0, block_length = 0; - int retries_length, retries_block; - u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; - - retries_length = chip->i2c_retry_count; - retries_block = chip->i2c_retry_count; + int retries = chip->i2c_retry_count; + s32 ret = 0; - /* Adapter needs to support these two functions */ if (!i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE_DATA | - I2C_FUNC_SMBUS_I2C_BLOCK)){ + I2C_FUNC_SMBUS_READ_BLOCK_DATA)) { return -ENODEV; } - /* Get the length of block data */ - while (retries_length > 0) { - ret = i2c_smbus_read_byte_data(client, address); - if (ret >= 0) - break; - retries_length--; - } - - if (ret < 0) { - dev_dbg(&client->dev, - "%s: i2c read at address 0x%x failed\n", - __func__, address); - return ret; - } - - /* block_length does not include NULL terminator */ - block_length = ret; - if (block_length > I2C_SMBUS_BLOCK_MAX) { - dev_err(&client->dev, - "%s: Returned block_length is longer than 0x%x\n", - __func__, I2C_SMBUS_BLOCK_MAX); - return -EINVAL; - } - /* Get the block data */ - while (retries_block > 0) { - ret = i2c_smbus_read_i2c_block_data( - client, address, - block_length + 1, block_buffer); + while (retries > 0) { + ret = i2c_smbus_read_block_data(client, address, values); if (ret >= 0) break; - retries_block--; + retries--; } if (ret < 0) { - dev_dbg(&client->dev, - "%s: i2c read at address 0x%x failed\n", - __func__, address); + dev_dbg(&client->dev, "%s: failed to read block 0x%x: %d\n", + __func__, address, ret); return ret; } - /* block_buffer[0] == block_length */ - memcpy(values, block_buffer + 1, block_length); - values[block_length] = '\0'; + /* add string termination */ + values[ret] = '\0'; - return ret; + return 0; } static int sbs_write_word_data(struct i2c_client *client, u8 address, @@ -465,14 +431,7 @@ static int sbs_get_battery_property(struct i2c_client *client, static int sbs_get_battery_string_property(struct i2c_client *client, int reg_offset, enum power_supply_property psp, char *val) { - s32 ret; - - ret = sbs_read_string_data(client, sbs_data[reg_offset].addr, val); - - if (ret < 0) - return ret; - - return 0; + return sbs_read_string_data(client, sbs_data[reg_offset].addr, val); } static void sbs_unit_adjustment(struct i2c_client *client, From patchwork Wed May 13 18:56:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547097 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E746618 for ; Wed, 13 May 2020 18:57:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 517BF20671 for ; Wed, 13 May 2020 18:57:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390494AbgEMS5K (ORCPT ); Wed, 13 May 2020 14:57:10 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51916 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390383AbgEMS4g (ORCPT ); Wed, 13 May 2020 14:56:36 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id 4FD212A28AB Received: by jupiter.universe (Postfix, from userid 1000) id 7AAD6480106; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 08/19] power: supply: sbs-battery: add PEC support Date: Wed, 13 May 2020 20:56:04 +0200 Message-Id: <20200513185615.508236-9-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org SBS batteries optionally have support for PEC. This enables PEC handling based on the implemented SBS version as suggested by the standard. The support for PEC is re-evaluated when the battery is hotplugged into the system, since there might be systems supporting batteries from different SBS generations. Signed-off-by: Sebastian Reichel --- drivers/power/supply/sbs-battery.c | 72 ++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index a9a1d28dabbe..ab774d491269 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -46,6 +46,14 @@ enum { REG_MODEL_NAME, }; +#define REG_ADDR_SPEC_INFO 0x1A +#define SPEC_INFO_VERSION_MASK GENMASK(7, 4) +#define SPEC_INFO_VERSION_SHIFT 4 + +#define SBS_VERSION_1_0 1 +#define SBS_VERSION_1_1 2 +#define SBS_VERSION_1_1_WITH_PEC 3 + /* Battery Mode defines */ #define BATTERY_MODE_OFFSET 0x03 #define BATTERY_MODE_CAPACITY_MASK BIT(15) @@ -175,6 +183,64 @@ static char model_name[I2C_SMBUS_BLOCK_MAX + 1]; static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1]; static bool force_load; +static int sbs_update_presence(struct sbs_info *chip, bool is_present) +{ + struct i2c_client *client = chip->client; + int retries = chip->i2c_retry_count; + s32 ret = 0; + u8 version; + + if (chip->is_present == is_present) + return 0; + + if (!is_present) { + chip->is_present = false; + /* Disable PEC when no device is present */ + client->flags &= ~I2C_CLIENT_PEC; + return 0; + } + + /* Check if device supports packet error checking and use it */ + while (retries > 0) { + ret = i2c_smbus_read_word_data(client, REG_ADDR_SPEC_INFO); + if (ret >= 0) + break; + + /* + * Some batteries trigger the detection pin before the + * I2C bus is properly connected. This works around the + * issue. + */ + msleep(100); + + retries--; + } + + if (ret < 0) { + dev_dbg(&client->dev, "failed to read spec info: %d\n", ret); + + /* fallback to old behaviour */ + client->flags &= ~I2C_CLIENT_PEC; + chip->is_present = true; + + return ret; + } + + version = (ret & SPEC_INFO_VERSION_MASK) >> SPEC_INFO_VERSION_SHIFT; + + if (version == SBS_VERSION_1_1_WITH_PEC) + client->flags |= I2C_CLIENT_PEC; + else + client->flags &= ~I2C_CLIENT_PEC; + + dev_dbg(&client->dev, "PEC: %s\n", (client->flags & I2C_CLIENT_PEC) ? + "enabled" : "disabled"); + + chip->is_present = true; + + return 0; +} + static int sbs_read_word_data(struct i2c_client *client, u8 address) { struct sbs_info *chip = i2c_get_clientdata(client); @@ -579,7 +645,7 @@ static int sbs_get_property(struct power_supply *psy, return ret; if (psp == POWER_SUPPLY_PROP_PRESENT) { val->intval = ret; - chip->is_present = val->intval; + sbs_update_presence(chip, ret); return 0; } if (ret == 0) @@ -678,7 +744,7 @@ static int sbs_get_property(struct power_supply *psy, if (!chip->gpio_detect && chip->is_present != (ret >= 0)) { - chip->is_present = (ret >= 0); + sbs_update_presence(chip, (ret >= 0)); power_supply_changed(chip->power_supply); } @@ -709,7 +775,7 @@ static void sbs_supply_changed(struct sbs_info *chip) ret = gpiod_get_value_cansleep(chip->gpio_detect); if (ret < 0) return; - chip->is_present = ret; + sbs_update_presence(chip, ret); power_supply_changed(battery); } From patchwork Wed May 13 18:56:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547105 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A3AA139A for ; Wed, 13 May 2020 18:57:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BE1820690 for ; Wed, 13 May 2020 18:57:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390538AbgEMS5a (ORCPT ); Wed, 13 May 2020 14:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2390392AbgEMS4f (ORCPT ); Wed, 13 May 2020 14:56:35 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B762C061A0E; Wed, 13 May 2020 11:56:35 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id 51D7C2A28F6 Received: by jupiter.universe (Postfix, from userid 1000) id 7D6D4480107; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 09/19] power: supply: sbs-battery: add POWER_SUPPLY_PROP_CURRENT_AVG support Date: Wed, 13 May 2020 20:56:05 +0200 Message-Id: <20200513185615.508236-10-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Expose averaged current information, which is part of the SBS standard and should be supported by all batteries. Signed-off-by: Sebastian Reichel --- drivers/power/supply/sbs-battery.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index ab774d491269..611a11385496 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -25,7 +25,8 @@ enum { REG_MANUFACTURER_DATA, REG_TEMPERATURE, REG_VOLTAGE, - REG_CURRENT, + REG_CURRENT_NOW, + REG_CURRENT_AVG, REG_MAX_ERR, REG_CAPACITY, REG_TIME_TO_EMPTY, @@ -92,8 +93,10 @@ static const struct chip_data { SBS_DATA(POWER_SUPPLY_PROP_TEMP, 0x08, 0, 65535), [REG_VOLTAGE] = SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_NOW, 0x09, 0, 20000), - [REG_CURRENT] = + [REG_CURRENT_NOW] = SBS_DATA(POWER_SUPPLY_PROP_CURRENT_NOW, 0x0A, -32768, 32767), + [REG_CURRENT_AVG] = + SBS_DATA(POWER_SUPPLY_PROP_CURRENT_AVG, 0x0B, -32768, 32767), [REG_MAX_ERR] = SBS_DATA(POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN, 0x0c, 0, 100), [REG_CAPACITY] = @@ -142,6 +145,7 @@ static enum power_supply_property sbs_properties[] = { POWER_SUPPLY_PROP_CYCLE_COUNT, POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_CURRENT_NOW, + POWER_SUPPLY_PROP_CURRENT_AVG, POWER_SUPPLY_PROP_CAPACITY, POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN, POWER_SUPPLY_PROP_TEMP, @@ -324,7 +328,7 @@ static int sbs_status_correct(struct i2c_client *client, int *intval) { int ret; - ret = sbs_read_word_data(client, sbs_data[REG_CURRENT].addr); + ret = sbs_read_word_data(client, sbs_data[REG_CURRENT_NOW].addr); if (ret < 0) return ret; @@ -521,6 +525,7 @@ static void sbs_unit_adjustment(struct i2c_client *client, case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: case POWER_SUPPLY_PROP_CURRENT_NOW: + case POWER_SUPPLY_PROP_CURRENT_AVG: case POWER_SUPPLY_PROP_CHARGE_NOW: case POWER_SUPPLY_PROP_CHARGE_FULL: case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: @@ -699,6 +704,7 @@ static int sbs_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_CYCLE_COUNT: case POWER_SUPPLY_PROP_VOLTAGE_NOW: case POWER_SUPPLY_PROP_CURRENT_NOW: + case POWER_SUPPLY_PROP_CURRENT_AVG: case POWER_SUPPLY_PROP_TEMP: case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: From patchwork Wed May 13 18:56:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547101 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BEF50618 for ; Wed, 13 May 2020 18:57:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF80E20671 for ; Wed, 13 May 2020 18:57:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390400AbgEMS4g (ORCPT ); Wed, 13 May 2020 14:56:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2390393AbgEMS4g (ORCPT ); Wed, 13 May 2020 14:56:36 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CED23C061A0F; Wed, 13 May 2020 11:56:35 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id 68B3D2A28F8 Received: by jupiter.universe (Postfix, from userid 1000) id 80A39480108; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 10/19] power: supply: sbs-battery: Improve POWER_SUPPLY_PROP_TECHNOLOGY support Date: Wed, 13 May 2020 20:56:06 +0200 Message-Id: <20200513185615.508236-11-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This reads the battery chemistry from the battery chip instead of incorrectly hardcoding the type to be Li-Ion. Signed-off-by: Sebastian Reichel --- drivers/power/supply/sbs-battery.c | 43 ++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index 611a11385496..b697a42d9ccf 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -43,6 +43,7 @@ enum { REG_DESIGN_CAPACITY_CHARGE, REG_DESIGN_VOLTAGE_MIN, REG_DESIGN_VOLTAGE_MAX, + REG_CHEMISTRY, REG_MANUFACTURER, REG_MODEL_NAME, }; @@ -133,7 +134,9 @@ static const struct chip_data { [REG_MANUFACTURER] = SBS_DATA(POWER_SUPPLY_PROP_MANUFACTURER, 0x20, 0, 65535), [REG_MODEL_NAME] = - SBS_DATA(POWER_SUPPLY_PROP_MODEL_NAME, 0x21, 0, 65535) + SBS_DATA(POWER_SUPPLY_PROP_MODEL_NAME, 0x21, 0, 65535), + [REG_CHEMISTRY] = + SBS_DATA(POWER_SUPPLY_PROP_TECHNOLOGY, 0x22, 0, 65535) }; static enum power_supply_property sbs_properties[] = { @@ -185,6 +188,7 @@ struct sbs_info { static char model_name[I2C_SMBUS_BLOCK_MAX + 1]; static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1]; +static char chemistry[I2C_SMBUS_BLOCK_MAX + 1]; static bool force_load; static int sbs_update_presence(struct sbs_info *chip, bool is_present) @@ -636,6 +640,38 @@ static int sbs_get_property_index(struct i2c_client *client, return -EINVAL; } +static int sbs_get_chemistry(struct i2c_client *client, + union power_supply_propval *val) +{ + enum power_supply_property psp = POWER_SUPPLY_PROP_TECHNOLOGY; + int ret; + + ret = sbs_get_property_index(client, psp); + if (ret < 0) + return ret; + + ret = sbs_get_battery_string_property(client, ret, psp, + chemistry); + if (ret < 0) + return ret; + + if (!strncasecmp(chemistry, "LION", 4)) + val->intval = POWER_SUPPLY_TECHNOLOGY_LION; + else if (!strncasecmp(chemistry, "LiP", 3)) + val->intval = POWER_SUPPLY_TECHNOLOGY_LIPO; + else if (!strncasecmp(chemistry, "NiCd", 4)) + val->intval = POWER_SUPPLY_TECHNOLOGY_NiCd; + else if (!strncasecmp(chemistry, "NiMH", 4)) + val->intval = POWER_SUPPLY_TECHNOLOGY_NiMH; + else + val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN; + + if (val->intval == POWER_SUPPLY_TECHNOLOGY_UNKNOWN) + dev_warn(&client->dev, "Unknown chemistry: %s\n", chemistry); + + return 0; +} + static int sbs_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -673,7 +709,10 @@ static int sbs_get_property(struct power_supply *psy, break; case POWER_SUPPLY_PROP_TECHNOLOGY: - val->intval = POWER_SUPPLY_TECHNOLOGY_LION; + ret = sbs_get_chemistry(client, val); + if (ret < 0) + break; + goto done; /* don't trigger power_supply_changed()! */ case POWER_SUPPLY_PROP_ENERGY_NOW: From patchwork Wed May 13 18:56:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547109 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DACA2912 for ; Wed, 13 May 2020 18:57:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 072B320671 for ; Wed, 13 May 2020 18:57:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390512AbgEMS5a (ORCPT ); Wed, 13 May 2020 14:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2390395AbgEMS4g (ORCPT ); Wed, 13 May 2020 14:56:36 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D747AC05BD0A; Wed, 13 May 2020 11:56:35 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id 8CCAA2A29D1 Received: by jupiter.universe (Postfix, from userid 1000) id 844EA480109; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 11/19] power: supply: sbs-battery: add POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT/VOLTAGE_MAX support Date: Wed, 13 May 2020 20:56:07 +0200 Message-Id: <20200513185615.508236-12-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Expose maximum charge current/voltage information requested by the battery. Signed-off-by: Sebastian Reichel --- drivers/power/supply/sbs-battery.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index b697a42d9ccf..e6f61baa9bed 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -46,6 +46,8 @@ enum { REG_CHEMISTRY, REG_MANUFACTURER, REG_MODEL_NAME, + REG_CHARGE_CURRENT, + REG_CHARGE_VOLTAGE, }; #define REG_ADDR_SPEC_INFO 0x1A @@ -114,6 +116,10 @@ static const struct chip_data { SBS_DATA(POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, 0x12, 0, 65535), [REG_TIME_TO_FULL] = SBS_DATA(POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, 0x13, 0, 65535), + [REG_CHARGE_CURRENT] = + SBS_DATA(POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, 0x14, 0, 65535), + [REG_CHARGE_VOLTAGE] = + SBS_DATA(POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, 0x15, 0, 65535), [REG_STATUS] = SBS_DATA(POWER_SUPPLY_PROP_STATUS, 0x16, 0, 65535), [REG_CAPACITY_LEVEL] = @@ -163,6 +169,8 @@ static enum power_supply_property sbs_properties[] = { POWER_SUPPLY_PROP_CHARGE_NOW, POWER_SUPPLY_PROP_CHARGE_FULL, POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, /* Properties of type `const char *' */ POWER_SUPPLY_PROP_MANUFACTURER, POWER_SUPPLY_PROP_MODEL_NAME @@ -531,6 +539,8 @@ static void sbs_unit_adjustment(struct i2c_client *client, case POWER_SUPPLY_PROP_CURRENT_NOW: case POWER_SUPPLY_PROP_CURRENT_AVG: case POWER_SUPPLY_PROP_CHARGE_NOW: + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: case POWER_SUPPLY_PROP_CHARGE_FULL: case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: val->intval *= BASE_UNIT_CONVERSION; @@ -749,6 +759,8 @@ static int sbs_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: case POWER_SUPPLY_PROP_CAPACITY: case POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN: ret = sbs_get_property_index(client, psp); From patchwork Wed May 13 18:56:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547095 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7BB57618 for ; Wed, 13 May 2020 18:57:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E7792065C for ; Wed, 13 May 2020 18:57:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390397AbgEMS5J (ORCPT ); Wed, 13 May 2020 14:57:09 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51934 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390388AbgEMS4g (ORCPT ); Wed, 13 May 2020 14:56:36 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id A65292A25D4 Received: by jupiter.universe (Postfix, from userid 1000) id 869D048010A; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 12/19] power: supply: sbs-battery: add MANUFACTURE_DATE support Date: Wed, 13 May 2020 20:56:08 +0200 Message-Id: <20200513185615.508236-13-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Expose the battery's manufacture date to userspace. Signed-off-by: Sebastian Reichel --- drivers/power/supply/sbs-battery.c | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index e6f61baa9bed..4fa553d61db2 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -58,6 +58,8 @@ enum { #define SBS_VERSION_1_1 2 #define SBS_VERSION_1_1_WITH_PEC 3 +#define REG_ADDR_MANUFACTURE_DATE 0x1B + /* Battery Mode defines */ #define BATTERY_MODE_OFFSET 0x03 #define BATTERY_MODE_CAPACITY_MASK BIT(15) @@ -171,6 +173,9 @@ static enum power_supply_property sbs_properties[] = { POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, + POWER_SUPPLY_PROP_MANUFACTURE_YEAR, + POWER_SUPPLY_PROP_MANUFACTURE_MONTH, + POWER_SUPPLY_PROP_MANUFACTURE_DAY, /* Properties of type `const char *' */ POWER_SUPPLY_PROP_MANUFACTURER, POWER_SUPPLY_PROP_MODEL_NAME @@ -682,6 +687,38 @@ static int sbs_get_chemistry(struct i2c_client *client, return 0; } +static int sbs_get_battery_manufacture_date(struct i2c_client *client, + enum power_supply_property psp, + union power_supply_propval *val) +{ + int ret; + u16 day, month, year; + + ret = sbs_read_word_data(client, REG_ADDR_MANUFACTURE_DATE); + if (ret < 0) + return ret; + + day = ret & GENMASK(4, 0); + month = (ret & GENMASK(8, 5)) >> 5; + year = ((ret & GENMASK(15, 9)) >> 9) + 1980; + + switch (psp) { + case POWER_SUPPLY_PROP_MANUFACTURE_YEAR: + val->intval = year; + break; + case POWER_SUPPLY_PROP_MANUFACTURE_MONTH: + val->intval = month; + break; + case POWER_SUPPLY_PROP_MANUFACTURE_DAY: + val->intval = day; + break; + default: + return -EINVAL; + } + + return 0; +} + static int sbs_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -790,6 +827,12 @@ static int sbs_get_property(struct power_supply *psy, val->strval = manufacturer; break; + case POWER_SUPPLY_PROP_MANUFACTURE_YEAR: + case POWER_SUPPLY_PROP_MANUFACTURE_MONTH: + case POWER_SUPPLY_PROP_MANUFACTURE_DAY: + ret = sbs_get_battery_manufacture_date(client, psp, val); + break; + default: dev_err(&client->dev, "%s: INVALID property\n", __func__); From patchwork Wed May 13 18:56:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547099 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7C01912 for ; Wed, 13 May 2020 18:57:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 095B220671 for ; Wed, 13 May 2020 18:57:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390491AbgEMS5K (ORCPT ); Wed, 13 May 2020 14:57:10 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51936 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390390AbgEMS4g (ORCPT ); Wed, 13 May 2020 14:56:36 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id BB82F2A29D3 Received: by jupiter.universe (Postfix, from userid 1000) id 8981648010B; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 13/19] power: supply: sbs-battery: add POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED support Date: Wed, 13 May 2020 20:56:09 +0200 Message-Id: <20200513185615.508236-14-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add support for reporting the SBS battery's condition flag to userspace using the new "Calibration required" health status. Signed-off-by: Sebastian Reichel Reviewed-by: Emil Velikov --- drivers/power/supply/sbs-battery.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index 4fa553d61db2..2a2b926ad75c 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -23,6 +23,7 @@ enum { REG_MANUFACTURER_DATA, + REG_BATTERY_MODE, REG_TEMPERATURE, REG_VOLTAGE, REG_CURRENT_NOW, @@ -94,6 +95,8 @@ static const struct chip_data { } sbs_data[] = { [REG_MANUFACTURER_DATA] = SBS_DATA(POWER_SUPPLY_PROP_PRESENT, 0x00, 0, 65535), + [REG_BATTERY_MODE] = + SBS_DATA(-1, 0x03, 0, 65535), [REG_TEMPERATURE] = SBS_DATA(POWER_SUPPLY_PROP_TEMP, 0x08, 0, 65535), [REG_VOLTAGE] = @@ -366,6 +369,17 @@ static int sbs_status_correct(struct i2c_client *client, int *intval) return 0; } +static bool sbs_bat_needs_calibration(struct i2c_client *client) +{ + int ret; + + ret = sbs_read_word_data(client, sbs_data[REG_BATTERY_MODE].addr); + if (ret < 0) + return false; + + return !!(ret & BIT(7)); +} + static int sbs_get_battery_presence_and_health( struct i2c_client *client, enum power_supply_property psp, union power_supply_propval *val) @@ -385,9 +399,14 @@ static int sbs_get_battery_presence_and_health( if (psp == POWER_SUPPLY_PROP_PRESENT) val->intval = 1; /* battery present */ - else /* POWER_SUPPLY_PROP_HEALTH */ - /* SBS spec doesn't have a general health command. */ - val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; + else { /* POWER_SUPPLY_PROP_HEALTH */ + if (sbs_bat_needs_calibration(client)) { + val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED; + } else { + /* SBS spec doesn't have a general health command. */ + val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; + } + } return 0; } @@ -441,6 +460,8 @@ static int sbs_get_ti_battery_presence_and_health( val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; else if (ret == 0x0C) val->intval = POWER_SUPPLY_HEALTH_DEAD; + else if (sbs_bat_needs_calibration(client)) + val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED; else val->intval = POWER_SUPPLY_HEALTH_GOOD; } From patchwork Wed May 13 18:56:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547093 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 71A1D618 for ; Wed, 13 May 2020 18:57:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 93DCB207ED for ; Wed, 13 May 2020 18:57:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390480AbgEMS5F (ORCPT ); Wed, 13 May 2020 14:57:05 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51942 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390397AbgEMS4g (ORCPT ); Wed, 13 May 2020 14:56:36 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id C134A2A29D7 Received: by jupiter.universe (Postfix, from userid 1000) id 8D60948010D; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 14/19] power: supply: sbs-battery: fix idle battery status Date: Wed, 13 May 2020 20:56:10 +0200 Message-Id: <20200513185615.508236-15-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org A battery, that is neither charged, nor discharged is not always Full. If the charger is disabled for other reasons it might simply be idle and should be marked accordingly. Signed-off-by: Sebastian Reichel --- drivers/power/supply/sbs-battery.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index 2a2b926ad75c..e3c685b2c247 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -354,9 +354,9 @@ static int sbs_status_correct(struct i2c_client *client, int *intval) ret = (s16)ret; - /* Not drawing current means full (cannot be not charging) */ - if (ret == 0) - *intval = POWER_SUPPLY_STATUS_FULL; + /* Not drawing current -> not charging (i.e. idle) */ + if (*intval != POWER_SUPPLY_STATUS_FULL && ret == 0) + *intval = POWER_SUPPLY_STATUS_NOT_CHARGING; if (*intval == POWER_SUPPLY_STATUS_FULL) { /* Drawing or providing current when full */ From patchwork Wed May 13 18:56:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547087 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63560912 for ; Wed, 13 May 2020 18:57:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FEB32065C for ; Wed, 13 May 2020 18:57:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390418AbgEMS4i (ORCPT ); Wed, 13 May 2020 14:56:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2390413AbgEMS4h (ORCPT ); Wed, 13 May 2020 14:56:37 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF0BEC061A0C; Wed, 13 May 2020 11:56:37 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id 9F2C02A27A9 Received: by jupiter.universe (Postfix, from userid 1000) id 90659480110; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Jean-Francois Dagenais , Sebastian Reichel Subject: [PATCHv1 15/19] power: supply: sbs-battery: add ability to disable charger broadcasts Date: Wed, 13 May 2020 20:56:11 +0200 Message-Id: <20200513185615.508236-16-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Jean-Francois Dagenais In certain designs, it is possible to add a battery on a populated i2c bus without an sbs compliant charger. In that case, the battery will un-necessarily and sometimes un-desirably master the bus trying to write info in the charger. It is observed in many occasion that these battery "broadcasts" are even corrupting other ongoing master to slave communication. I.e. the multi-master support in the battery is inadequate. Thankfully, the CHARGER_MODE bit allows designers to disable that SBS battery behaviour. This needs to be done once when the battery is first seen on the bus. Signed-off-by: Jean-Francois Dagenais [rebased code] Signed-off-by: Sebastian Reichel --- .../bindings/power/supply/sbs_sbs-battery.txt | 2 ++ drivers/power/supply/sbs-battery.c | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt b/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt index fa5a8b516dbf..a5093ccef5c5 100644 --- a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt +++ b/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt @@ -16,6 +16,7 @@ Optional properties : after an external change notification. - sbs,battery-detect-gpios : The gpio which signals battery detection and a flag specifying its polarity. + - sbs,disable-charger-broadcasts: for systems without sbs compliant chargers Example: @@ -25,4 +26,5 @@ Example: sbs,i2c-retry-count = <2>; sbs,poll-retry-count = <10>; sbs,battery-detect-gpios = <&gpio-controller 122 1>; + sbs,disable-charger-broadcasts; } diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index e3c685b2c247..7c6905a486da 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -68,6 +68,7 @@ enum sbs_capacity_mode { CAPACITY_MODE_AMPS = 0, CAPACITY_MODE_WATTS = BATTERY_MODE_CAPACITY_MASK }; +#define BATTERY_MODE_CHARGER_MASK (1<<14) /* manufacturer access defines */ #define MANUFACTURER_ACCESS_STATUS 0x0006 @@ -193,6 +194,7 @@ struct sbs_info { bool is_present; struct gpio_desc *gpio_detect; bool enable_detection; + bool charger_broadcasts; int last_state; int poll_time; u32 i2c_retry_count; @@ -207,6 +209,27 @@ static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1]; static char chemistry[I2C_SMBUS_BLOCK_MAX + 1]; static bool force_load; +static int sbs_read_word_data(struct i2c_client *client, u8 address); +static int sbs_write_word_data(struct i2c_client *client, u8 address, u16 value); + +static void sbs_disable_charger_broadcasts(struct sbs_info *chip) +{ + int val = sbs_read_word_data(chip->client, BATTERY_MODE_OFFSET); + if (val < 0) + goto exit; + + val |= BATTERY_MODE_CHARGER_MASK; + + val = sbs_write_word_data(chip->client, BATTERY_MODE_OFFSET, val); + +exit: + if (val < 0) + dev_err(&chip->client->dev, + "Failed to disable charger broadcasting: %d\n", val); + else + dev_dbg(&chip->client->dev, "%s\n", __func__); +} + static int sbs_update_presence(struct sbs_info *chip, bool is_present) { struct i2c_client *client = chip->client; @@ -260,6 +283,9 @@ static int sbs_update_presence(struct sbs_info *chip, bool is_present) dev_dbg(&client->dev, "PEC: %s\n", (client->flags & I2C_CLIENT_PEC) ? "enabled" : "disabled"); + if (!chip->is_present && is_present && !chip->charger_broadcasts) + sbs_disable_charger_broadcasts(chip); + chip->is_present = true; return 0; @@ -1017,6 +1043,9 @@ static int sbs_probe(struct i2c_client *client, } chip->i2c_retry_count = chip->i2c_retry_count + 1; + chip->charger_broadcasts = !of_property_read_bool(client->dev.of_node, + "sbs,disable-charger-broadcasts"); + chip->gpio_detect = devm_gpiod_get_optional(&client->dev, "sbs,battery-detect", GPIOD_IN); if (IS_ERR(chip->gpio_detect)) { From patchwork Wed May 13 18:56:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547083 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8BE8E618 for ; Wed, 13 May 2020 18:57:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A9D172054F for ; Wed, 13 May 2020 18:56:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390423AbgEMS4j (ORCPT ); Wed, 13 May 2020 14:56:39 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51900 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390405AbgEMS4i (ORCPT ); Wed, 13 May 2020 14:56:38 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id A0F5C2A2A5C Received: by jupiter.universe (Postfix, from userid 1000) id 9319A480128; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 16/19] power: supply: sbs-battery: switch from of_property_* to device_property_* Date: Wed, 13 May 2020 20:56:12 +0200 Message-Id: <20200513185615.508236-17-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Switch from DT specific of_property_* API to generic and more modern device_property_* API. Signed-off-by: Sebastian Reichel --- drivers/power/supply/sbs-battery.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index 7c6905a486da..73dfe526c867 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -1016,7 +1016,7 @@ static int sbs_probe(struct i2c_client *client, if (!chip) return -ENOMEM; - chip->flags = (u32)(uintptr_t)of_device_get_match_data(&client->dev); + chip->flags = (u32)(uintptr_t)device_get_match_data(&client->dev); chip->client = client; chip->enable_detection = false; psy_cfg.of_node = client->dev.of_node; @@ -1027,13 +1027,13 @@ static int sbs_probe(struct i2c_client *client, /* use pdata if available, fall back to DT properties, * or hardcoded defaults if not */ - rc = of_property_read_u32(client->dev.of_node, "sbs,i2c-retry-count", - &chip->i2c_retry_count); + rc = device_property_read_u32(&client->dev, "sbs,i2c-retry-count", + &chip->i2c_retry_count); if (rc) chip->i2c_retry_count = 0; - rc = of_property_read_u32(client->dev.of_node, "sbs,poll-retry-count", - &chip->poll_retry_count); + rc = device_property_read_u32(&client->dev, "sbs,poll-retry-count", + &chip->poll_retry_count); if (rc) chip->poll_retry_count = 0; @@ -1043,7 +1043,7 @@ static int sbs_probe(struct i2c_client *client, } chip->i2c_retry_count = chip->i2c_retry_count + 1; - chip->charger_broadcasts = !of_property_read_bool(client->dev.of_node, + chip->charger_broadcasts = !device_property_read_bool(&client->dev, "sbs,disable-charger-broadcasts"); chip->gpio_detect = devm_gpiod_get_optional(&client->dev, From patchwork Wed May 13 18:56:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547085 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7AF6139A for ; Wed, 13 May 2020 18:57:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09F282065C for ; Wed, 13 May 2020 18:57:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390420AbgEMS4i (ORCPT ); Wed, 13 May 2020 14:56:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2390414AbgEMS4h (ORCPT ); Wed, 13 May 2020 14:56:37 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2F19C061A0E; Wed, 13 May 2020 11:56:37 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id A2E9B2A2A5E Received: by jupiter.universe (Postfix, from userid 1000) id 9633A480129; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 17/19] power: supply: sbs-battery: switch to i2c's probe_new Date: Wed, 13 May 2020 20:56:13 +0200 Message-Id: <20200513185615.508236-18-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org sbs-battery does not use the ID parameter, so switch to i2c's probe_new API. Signed-off-by: Sebastian Reichel --- drivers/power/supply/sbs-battery.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index 73dfe526c867..f0392be350eb 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -992,8 +992,7 @@ static const struct power_supply_desc sbs_default_desc = { .external_power_changed = sbs_external_power_changed, }; -static int sbs_probe(struct i2c_client *client, - const struct i2c_device_id *id) +static int sbs_probe(struct i2c_client *client) { struct sbs_info *chip; struct power_supply_desc *sbs_desc; @@ -1172,7 +1171,7 @@ static const struct of_device_id sbs_dt_ids[] = { MODULE_DEVICE_TABLE(of, sbs_dt_ids); static struct i2c_driver sbs_battery_driver = { - .probe = sbs_probe, + .probe_new = sbs_probe, .remove = sbs_remove, .alert = sbs_alert, .id_table = sbs_id, From patchwork Wed May 13 18:56:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547089 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 71BCC912 for ; Wed, 13 May 2020 18:57:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8FC51206A5 for ; Wed, 13 May 2020 18:57:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390470AbgEMS47 (ORCPT ); Wed, 13 May 2020 14:56:59 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51976 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390410AbgEMS4i (ORCPT ); Wed, 13 May 2020 14:56:38 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id A56252A2A62 Received: by jupiter.universe (Postfix, from userid 1000) id 9909B48012D; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 18/19] power: supply: sbs-battery: constify power-supply property array Date: Wed, 13 May 2020 20:56:14 +0200 Message-Id: <20200513185615.508236-19-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Signed-off-by: Sebastian Reichel --- drivers/power/supply/sbs-battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index f0392be350eb..f4f73e669460 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -151,7 +151,7 @@ static const struct chip_data { SBS_DATA(POWER_SUPPLY_PROP_TECHNOLOGY, 0x22, 0, 65535) }; -static enum power_supply_property sbs_properties[] = { +static const enum power_supply_property sbs_properties[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_CAPACITY_LEVEL, POWER_SUPPLY_PROP_HEALTH, From patchwork Wed May 13 18:56:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 11547081 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D272912 for ; Wed, 13 May 2020 18:56:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E122207D3 for ; Wed, 13 May 2020 18:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390426AbgEMS4j (ORCPT ); Wed, 13 May 2020 14:56:39 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51982 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390411AbgEMS4i (ORCPT ); Wed, 13 May 2020 14:56:38 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id A6BB12A2A71 Received: by jupiter.universe (Postfix, from userid 1000) id 9BA0048012E; Wed, 13 May 2020 20:56:29 +0200 (CEST) From: Sebastian Reichel To: Sebastian Reichel , Rob Herring , Greg Kroah-Hartman , "Rafael J . Wysocki" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, Sebastian Reichel Subject: [PATCHv1 19/19] dt-bindings: power: sbs-battery: Convert to yaml Date: Wed, 13 May 2020 20:56:15 +0200 Message-Id: <20200513185615.508236-20-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513185615.508236-1-sebastian.reichel@collabora.com> References: <20200513185615.508236-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Convert sbs-battery bindings to YAML. Signed-off-by: Sebastian Reichel Reviewed-by: Rob Herring --- .../power/supply/sbs,sbs-battery.yaml | 83 +++++++++++++++++++ .../bindings/power/supply/sbs_sbs-battery.txt | 30 ------- 2 files changed, 83 insertions(+), 30 deletions(-) create mode 100644 Documentation/devicetree/bindings/power/supply/sbs,sbs-battery.yaml delete mode 100644 Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt diff --git a/Documentation/devicetree/bindings/power/supply/sbs,sbs-battery.yaml b/Documentation/devicetree/bindings/power/supply/sbs,sbs-battery.yaml new file mode 100644 index 000000000000..205bc826bd20 --- /dev/null +++ b/Documentation/devicetree/bindings/power/supply/sbs,sbs-battery.yaml @@ -0,0 +1,83 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/supply/sbs,sbs-battery.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SBS compliant battery + +maintainers: + - Sebastian Reichel + +description: | + Battery compatible with the smart battery system specifications + +properties: + + compatible: + oneOf: + - items: + - enum: + - ti,bq20z65 + - ti,bq20z75 + - enum: + - sbs,sbs-battery + - items: + - const: sbs,sbs-battery + + reg: + maxItems: 1 + + sbs,i2c-retry-count: + description: + The number of times to retry I2C transactions on I2C IO failure. + default: 0 + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + + sbs,poll-retry-count: + description: + The number of times to try looking for new status after an external + change notification. + default: 0 + allOf: + - $ref: /schemas/types.yaml#/definitions/uint32 + + sbs,battery-detect-gpios: + description: + GPIO which signals battery detection. If this is not supplied, the bus + needs to be polled to detect the battery. + maxItems: 1 + + sbs,disable-charger-broadcasts: + description: + SBS batteries by default send broadcast messages to SBS compliant chargers to + configure max. charge current/voltage. If your hardware does not have an SBS + compliant charger it should be disabled via this property to avoid blocking + the bus. Also some SBS battery fuel gauges are known to have a buggy multi- + master implementation. + type: boolean + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + battery@b { + compatible = "ti,bq20z75", "sbs,sbs-battery"; + reg = <0xb>; + sbs,i2c-retry-count = <2>; + sbs,poll-retry-count = <10>; + sbs,battery-detect-gpios = <&gpio 122 GPIO_ACTIVE_HIGH>; + sbs,disable-charger-broadcasts; + }; + }; diff --git a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt b/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt deleted file mode 100644 index a5093ccef5c5..000000000000 --- a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt +++ /dev/null @@ -1,30 +0,0 @@ -SBS sbs-battery -~~~~~~~~~~ - -Required properties : - - compatible: ",", "sbs,sbs-battery" as fallback. The - part number compatible string might be used in order to take care of - vendor specific registers. - Known ,: - ti,bq20z65 - ti,bq20z75 - -Optional properties : - - sbs,i2c-retry-count : The number of times to retry i2c transactions on i2c - IO failure. - - sbs,poll-retry-count : The number of times to try looking for new status - after an external change notification. - - sbs,battery-detect-gpios : The gpio which signals battery detection and - a flag specifying its polarity. - - sbs,disable-charger-broadcasts: for systems without sbs compliant chargers - -Example: - - battery@b { - compatible = "ti,bq20z75", "sbs,sbs-battery"; - reg = <0xb>; - sbs,i2c-retry-count = <2>; - sbs,poll-retry-count = <10>; - sbs,battery-detect-gpios = <&gpio-controller 122 1>; - sbs,disable-charger-broadcasts; - }