Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp746435ybk; Wed, 13 May 2020 11:59:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzD5qUEEqghiRzQ7HSenCKwnKvin5tG3lqM3P1qaJCTfKbR4spBeuqwRqNX4tAR8HRo2znG X-Received: by 2002:a50:d9cb:: with SMTP id x11mr1018968edj.88.1589396343744; Wed, 13 May 2020 11:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589396343; cv=none; d=google.com; s=arc-20160816; b=GL+6+dIFBjWRmq3Sf6uc0vy8j9a0ZbVLmMmPbJI3EH6ZR9q9SbNjbL3s/OwZ+TNut2 L56H2Qp7WbNkYYoSkX5ajcBMnfOmqNbpaYi0WMuwI/G0igh9oFeL4/62llrHx0D6XSyn tRTFkEv/kxx51D5JpdfovVv/LLKnE/9TPe2vbAHGaUQ1jPJTKodXNbca6+146C2KbwLz iEqNLqp/3hnQqPCvk9Z4ZxhqRou4rT8Kqt5BCUXAl5txYkL5yHxIF4Ianw09158MyLD3 OwQHd8Qn5p5SaWyzk8M8GWsRr2yFv8dHg3oJcicQfpwUh5O0MA+3bFEqUYEBYOf4x96g VTZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=IdfCHc4Kho0dv2WSk5IlU7PqXhRJisiDMJ0LIDRAwSM=; b=GW/y0k+tgAxvS/lKdgqSBDRgEGaP/R61RE2YvE9OwlMPmgnYStMbBlv80DJLkmvXcl 1WgE0JvRZyGAhdV8KwbB54T8Xn1ZCWvGC8kpCXSVFwONRLQym4+gmgo0LSDxgHywkTYZ 8FlYF/P5X8rw7IHmsCZIBiCBhOvC4oDhOrg7+t1UJgCkTbjKy6zx2zjBiXnoSFSRVSKN XACTlt8DtEgWjeG3H/b/7Q8VQdgIno4EjR8TucWxkKDyPMAYaVW8maZbBbZJmFbZfMQd V3In0Y9dbYFRGGCS56teqDD0kIZ9dtBHfqMhBtSqUqFsdQU2L3Ug+KJfFtp3PxpwEapS kcEQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g8si394936ejb.85.2020.05.13.11.58.18; Wed, 13 May 2020 11:59:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390441AbgEMS4m (ORCPT + 99 others); Wed, 13 May 2020 14:56:42 -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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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)) { -- 2.26.2