Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp814441ybg; Tue, 9 Jun 2020 13:36:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhTpyRJ5KpJiso3RXDTsBntCXMCkTPWa59cFYafA79E1EV453gxTANldw0Dq6/j5WlrnX1 X-Received: by 2002:a17:906:4406:: with SMTP id x6mr198412ejo.160.1591735015993; Tue, 09 Jun 2020 13:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591735015; cv=none; d=google.com; s=arc-20160816; b=l6pwY7mNdcp1v6v4rXMMrYtJpW9Di23cY5OEsTDRMX8pxcv4AJdaMdGqgJuSa+1I6Q vyE68nl4Jks7cHvuPv/uGGd2JQLnRPQpuubFxzryaR6j0YYH3M1Orv4UWGPss0fL6UvR g/1sfwdx3RC6KqpgQzSH35AY9mSPFVU11OczPtjhzYs6E2pFleapn1adnkvBxL27iQXm 6VjXpX3o5Hpfe1ADeYEr7WAldyopchx+M9u8qDGxabea+nuZ9rnNC87y969tixqbCefX REKV7q+w+KvyrtwUvHKUNZnVk3hBBVpmIfs2otv4p6EEqravvgNaxzSQI6YZA73B3p6H v7/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=+UJnkDxVkadhbJZh7bYn2L5UqyxoXGSxqxY/M/szSR4=; b=OwJfajRz8j39Y6pEX9Vs1SmhQRItv4JXnRXUjq/woc7zbqjwZbEroqVK+jRG0Qv3qY 1KF5SSgMjb9p0B+J8jp+c8KrJ2ObtWXlPelCtniqzDPjBauEyyvcsCQyVRIHCi0aE2BU xKwzRiA+3y6VVoQgOo9RKM/0dK8mkJUk4mpdCEFgh/lmfgWIKw8KzELbeJ/LvDSu/6JO 2Go/EqGwzAgRWRWltki8843GohNeFNC3JVNpF0EqB39chfyg5alCJw/DBUbZ3gTVq+iN 4C/34rMSVUD+5eZlGz2bB2U6+/d9IVB1NK+D39wneGzlhND85iHAbo2dd/R6PUf+9Wsh G5IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b="BrU/V7wm"; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w7si271258eji.484.2020.06.09.13.36.33; Tue, 09 Jun 2020 13:36:55 -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; dkim=fail header.i=@chromium.org header.s=google header.b="BrU/V7wm"; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389191AbgFITWw (ORCPT + 99 others); Tue, 9 Jun 2020 15:22:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731054AbgFITWv (ORCPT ); Tue, 9 Jun 2020 15:22:51 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 253B5C05BD1E for ; Tue, 9 Jun 2020 12:22:50 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id d6so1831484pjs.3 for ; Tue, 09 Jun 2020 12:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+UJnkDxVkadhbJZh7bYn2L5UqyxoXGSxqxY/M/szSR4=; b=BrU/V7wm9SzSTlMa8d22kFnOE4mN00rol//Jjz+04Hn6J1erJsseYX8zVrPSDUiylf GCiRfTPX3BJzekyQUwvZG0UkyfGeJKUXqpeqCIPoehqbw3R5pqXRqXmpwlyZwepS/TGr YAH9JlZLOfppxeutohPijYHDPE5e6jQ6REAiA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+UJnkDxVkadhbJZh7bYn2L5UqyxoXGSxqxY/M/szSR4=; b=MzRxwmiOnh8QkKk7MaFgrpKcqXdIb3kR6GahtsEsHYsu/b+F8GDPX2kSojjNITOiZl meVVvUDhz9/q9hqzhY7RpaHqfg2FIn09/4MfYTZepuEqLElJEZld4lKaRw8GM+TFvmA/ rwJXRd0hehdKDIhBo/TN+im3qjZNl2ukm8xfRDZeETLTA82O6g/xyKet/XFHLFEzS7jp IBSxsmVYF/dwHvibjouQhOJwU/j0k5vLH2WjxTO02a67nOGr7p/83E4O4G4EtzVJ2Nz6 jNKX9INmexPcYjm0bEpclEGv7xUY7Rj6qlYQL/C02j4Vn6arHPCSm+IN1cUR9UKUO9Gk wa5A== X-Gm-Message-State: AOAM531nZM0KMn9FC/JlAlBQBmHAD795m97OXryPdWJvwq5LtmG8y3FB 1C6uYu3eoX8VqSx9idaSbn/X7UaT5dLU1g== X-Received: by 2002:a17:902:a513:: with SMTP id s19mr4474055plq.140.1591730569654; Tue, 09 Jun 2020 12:22:49 -0700 (PDT) Received: from twawrzynczak.bld.corp.google.com ([161.97.245.194]) by smtp.gmail.com with ESMTPSA id p12sm10883174pfq.69.2020.06.09.12.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 12:22:49 -0700 (PDT) From: Tim Wawrzynczak Cc: Sebastian Reichel , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Tim Wawrzynczak Subject: [PATCH 2/2] power: supply: sbs_battery: Support Manufacture Date field Date: Tue, 9 Jun 2020 13:22:37 -0600 Message-Id: <20200609192237.32571-2-twawrzynczak@chromium.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200609192237.32571-1-twawrzynczak@chromium.org> References: <20200609192237.32571-1-twawrzynczak@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds support for the sbs-battery driver to export a battery's manufacture date as a field in sysfs. It is exported as a simple Y/M/D format for ease of consumption. Signed-off-by: Tim Wawrzynczak Change-Id: Ia952624f33700587f4d71ad09ad68c0940c7f508 --- drivers/power/supply/sbs-battery.c | 31 +++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index f8d74e9f79317..989625be80743 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -42,6 +42,7 @@ enum { REG_DESIGN_VOLTAGE_MAX, REG_MANUFACTURER, REG_MODEL_NAME, + REG_MANUFACTURE_DATE, }; /* Battery Mode defines */ @@ -112,6 +113,10 @@ static const struct chip_data { SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 0x19, 0, 65535), [REG_DESIGN_VOLTAGE_MAX] = SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 0x19, 0, 65535), + /* Manufacture Date is encoded as a 16-bit register, but is exported + * from here as a string */ + [REG_MANUFACTURE_DATE] = + SBS_DATA(POWER_SUPPLY_PROP_MANUFACTURE_DATE, 0x1B, 0, 65535), [REG_SERIAL_NUMBER] = SBS_DATA(POWER_SUPPLY_PROP_SERIAL_NUMBER, 0x1C, 0, 65535), /* Properties of type `const char *' */ @@ -145,7 +150,8 @@ static enum power_supply_property sbs_properties[] = { POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, /* Properties of type `const char *' */ POWER_SUPPLY_PROP_MANUFACTURER, - POWER_SUPPLY_PROP_MODEL_NAME + POWER_SUPPLY_PROP_MODEL_NAME, + POWER_SUPPLY_PROP_MANUFACTURE_DATE, }; /* Supports special manufacturer commands from TI BQ20Z75 IC. */ @@ -170,6 +176,10 @@ static char model_name[I2C_SMBUS_BLOCK_MAX + 1]; static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1]; static bool force_load; +/* manufacture_date is returned as a 16-bit word in the smart battery itself. + * It is decoded here and displayed as "%4d/%2d/%2d", Y/m/d format. */ +static char manufacture_date[11]; + static int sbs_read_word_data(struct i2c_client *client, u8 address) { struct sbs_info *chip = i2c_get_clientdata(client); @@ -682,6 +692,25 @@ static int sbs_get_property(struct power_supply *psy, ret = sbs_get_battery_property(client, ret, psp, val); break; + case POWER_SUPPLY_PROP_MANUFACTURE_DATE: + ret = sbs_get_property_index(client, psp); + if (ret < 0) + break; + + ret = sbs_get_battery_property(client, ret, psp, val); + + /* Convert encoded data (from the SBS 1.1 spec) into a string: + * bits 9-15 are the year, encoded as years since 1980 + * bits 5-8 are the month, encoded as 1-12 + * bits 0-4 are the day of the month, encoded as 1-31 */ + snprintf(manufacture_date, sizeof(manufacture_date), + "%4d/%2d/%2d", + ((val->intval >> 9) & 0x7f) + 1980, + (val->intval >> 5) & 0xf, + val->intval & 0x1f); + val->strval = manufacture_date; + break; + case POWER_SUPPLY_PROP_MODEL_NAME: ret = sbs_get_property_index(client, psp); if (ret < 0) -- 2.26.2