Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp746626ybk; Wed, 13 May 2020 11:59:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcAo6ErJBtE3Fihylh7srpuqFCIjnKjCrPTtO87ndTv1RVQWSc/fB4o8MNTPXUYfDvC0ss X-Received: by 2002:a17:907:20e5:: with SMTP id rh5mr488924ejb.72.1589396364387; Wed, 13 May 2020 11:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589396364; cv=none; d=google.com; s=arc-20160816; b=LMxmA/5F4Ln2lSi0a12vLwzNASijt8wP9ny9i5yuMV84vI+L5QTgPlzCiuFvoqBeCh A0AYFzIkr8U0hrMrGozA4xfo6ZwTHDzQAAO4arwlw+4Q5MfibS/2imjYFt2vvUkKATRl LsNLaOM8O0i3NrEFwBi1xTsEGEyonAiCL7qkV/pM/a3GhgQnnQ3MiZBd+FIFSACAT5ig q6QlLF4hV0Xes8zjsd+RbDIfIFZrRmsbhMrFoEFnS0fzrxYOKk/MR3jBNHNR7AB3ixlT DGVOXEPSPp5qyr+nv1RwooI/rDkU77KYoTPP5zJMuWyeFJX2XQqnxFfebBFVOUTPlxNd uqQQ== 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=Wx1y1opJLg9bOQtsBRur003dZsPzygV/UvpkV/6zGb0=; b=s/yCeFyk4pIvRkT3S61jJLx7lILtLA4qTU5cGvKx2Bm/LfFdyNanxH3vYs7fR4XSJx 3Lad8F8uQ+LS3uXT717J6qUhUd1rH4vx/K8YZHSWLDsKgZ59HCZ1XOoFkJg+lnjTAdlG NnxCR0YAHoaEko/h0fcZRcVwsf0eyH4egAEzmTw7jqPiyJBnZVe1MAXWo63kMIP8VVQi 9feCI6MApTqku6lHYXAAsTmqqY53p2PNvI/UM1YgewwBjLoEjuv+PmNTS2PNllN4Kqef gt3N0/XXQsnKbSMj8I4jHI025ALHi7eS/SDqvAu8uItKOG08NAFKllpk7HPLn+6s+6ld mVzw== 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 gr15si361237ejb.503.2020.05.13.11.59.01; Wed, 13 May 2020 11:59:24 -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 S2390505AbgEMS5M (ORCPT + 99 others); Wed, 13 May 2020 14:57:12 -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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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; } -- 2.26.2