From patchwork Fri Apr 21 09:59:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Breck X-Patchwork-Id: 9692337 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 35C8D6037F for ; Fri, 21 Apr 2017 10:00:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 300C92860E for ; Fri, 21 Apr 2017 10:00:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2472928614; Fri, 21 Apr 2017 10:00:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F8CF2861A for ; Fri, 21 Apr 2017 10:00:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1037615AbdDUKAY (ORCPT ); Fri, 21 Apr 2017 06:00:24 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:33868 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1037614AbdDUKAX (ORCPT ); Fri, 21 Apr 2017 06:00:23 -0400 Received: by mail-io0-f195.google.com with SMTP id h41so28520942ioi.1 for ; Fri, 21 Apr 2017 03:00:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=oQRuoeLahC4DOu4IlLv0++V+hWqBtD4pAzGKfyhDzb0=; b=UEQynvqMxjRZy334LBuKf5m5xTFw6xVkfiXUVdxtkQxUpgnNMixVwCTks05E+/TApx +GO/c1KZni09fTx/pkfcAJ/nK8/uUFBbvt1PmDKYGYOm8VP1rVz0bSb+o4UMu2lhOfrQ kV8ullcDlnPbACqKc5rM8wONXRvZd8U4vuVWixMN/NLC+YAB1UT2nxGjDuj4MyLb4k6z cE6lDz0cT0NJCCBSc9vaJ5s6bOfEq2fthb8KPOybN9mCi9js7mv9IUVvhocka/8QkPi1 XcIwSMHjM9xZqnEog9QSHwOI/rkz2Ub/LqTsDstv3SKYgj1NI7VbLznySzrJ9J4Rl39O ialg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=oQRuoeLahC4DOu4IlLv0++V+hWqBtD4pAzGKfyhDzb0=; b=C+3OzB9fqlIKO2Djz8cCsrACE6YVljB2zElpx6MxrkOanRCDhsSiFPvxNiqcm0Wd6c 9binCBzRfLijDoF7SBxORHELseLbS/5a2zSsw6b9bCbhkDuMLT9F3yrBPT7qYgKvyjHN bYPQl45Y9R63hxppTsP4I6zgKJ8zvfgmR0wE4m2KJrBD3riH4PXXGecY8gQTk1fnWEVZ G3sEtNtn3hrD0LE2zci+mTJLCSi3cMoJs1fKV6tOPOi5UytYZcxkYbEZPz6Wih02Ll0S 7oq9QlcOlt0ST8mfeZkwlDsIebDFq16Pn/+NndodDONUR/u9P4nHB/6uoZ5J4t6SaOBJ S3pw== X-Gm-Message-State: AN3rC/7B0/LVbCw2tDFqgwE98d9ALGpECjlJmryHLoAuLQTWzaOd/E87 GP+pJbp8WvoF6kB6f0s= X-Received: by 10.99.167.71 with SMTP id w7mr11718738pgo.138.1492768822351; Fri, 21 Apr 2017 03:00:22 -0700 (PDT) Received: from localhost.localdomain (c-73-223-93-234.hsd1.ca.comcast.net. [73.223.93.234]) by smtp.gmail.com with ESMTPSA id r90sm15169402pfl.120.2017.04.21.03.00.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Apr 2017 03:00:21 -0700 (PDT) From: Liam Breck To: "Andrew F. Davis" , linux-pm@vger.kernel.org Cc: Liam Breck Subject: [PATCH v12.7 08/10] power: bq27xxx_battery: Enable data memory update for certain chips Date: Fri, 21 Apr 2017 02:59:57 -0700 Message-Id: <20170421095959.14151-6-liam@networkimprov.net> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170421095959.14151-1-liam@networkimprov.net> References: <20170421095959.14151-1-liam@networkimprov.net> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Liam Breck Support data memory update on BQ27500, 545, 425, 421, 441, 621. Create IDs for for previously unID'd chips, to index arrays for unseal keys and data memory register tables. Signed-off-by: Liam Breck --- drivers/power/supply/bq27xxx_battery.c | 90 ++++++++++++++++++++++++++++-- drivers/power/supply/bq27xxx_battery_i2c.c | 16 +++--- include/linux/power/bq27xxx_battery.h | 13 +++++ 3 files changed, 107 insertions(+), 12 deletions(-) diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c index 7152370..4497bc0 100644 --- a/drivers/power/supply/bq27xxx_battery.c +++ b/drivers/power/supply/bq27xxx_battery.c @@ -58,7 +58,7 @@ #include -#define DRIVER_VERSION "1.2.0" +#define DRIVER_VERSION "1.3.0" #define BQ27XXX_MANUFACTURER "Texas Instruments" @@ -132,7 +132,7 @@ enum bq27xxx_reg_index { [BQ27XXX_DM_CKSUM] = 0x60 /* Register mappings */ -static u8 bq27xxx_regs[][BQ27XXX_REG_MAX] = { +static u8 bq27xxx_regs[BQ27MAX][BQ27XXX_REG_MAX] = { [BQ27000] = { [BQ27XXX_REG_CTRL] = 0x00, [BQ27XXX_REG_TEMP] = 0x06, @@ -779,7 +779,7 @@ static enum power_supply_property bq27421_battery_props[] = { static struct { enum power_supply_property *props; size_t size; -} bq27xxx_battery_props[] = { +} bq27xxx_battery_props[BQ27MAX] = { BQ27XXX_PROP(BQ27000, bq27000_battery_props), BQ27XXX_PROP(BQ27010, bq27010_battery_props), BQ27XXX_PROP(BQ2750X, bq2750x_battery_props), @@ -798,6 +798,33 @@ static struct { BQ27XXX_PROP(BQ27421, bq27421_battery_props), }; +static enum bq27xxx_chip bq27xxx_chips[] = { + [BQ27000] = BQ27000, + [BQ27010] = BQ27010, + [BQ2750X] = BQ2750X, + [BQ2751X] = BQ2751X, + [BQ2752X] = BQ2751X, + [BQ27500] = BQ27500, + [BQ27510G1] = BQ27510G1, + [BQ27510G2] = BQ27510G2, + [BQ27510G3] = BQ27510G3, + [BQ27520G1] = BQ27520G1, + [BQ27520G2] = BQ27520G2, + [BQ27520G3] = BQ27520G3, + [BQ27520G4] = BQ27520G4, + [BQ27530] = BQ27530, + [BQ27531] = BQ27530, + [BQ27541] = BQ27541, + [BQ27542] = BQ27541, + [BQ27546] = BQ27541, + [BQ27742] = BQ27541, + [BQ27545] = BQ27545, + [BQ27421] = BQ27421, + [BQ27425] = BQ27421, + [BQ27441] = BQ27421, + [BQ27621] = BQ27421, +}; + static DEFINE_MUTEX(bq27xxx_list_lock); static LIST_HEAD(bq27xxx_battery_devices); @@ -856,6 +883,54 @@ static const char * const bq27xxx_dm_reg_name[] = { [BQ27XXX_DM_TERMINATE_VOLTAGE] = "terminate-voltage", }; +static struct bq27xxx_dm_reg bq27500_dm_regs[] = { + [BQ27XXX_DM_DESIGN_CAPACITY] = { 48, 10, 2, 0, 65535 }, + [BQ27XXX_DM_DESIGN_ENERGY] = { }, /* missing on chip */ + [BQ27XXX_DM_TERMINATE_VOLTAGE] = { 80, 48, 2, 1000, 32767 }, +}; + +static struct bq27xxx_dm_reg bq27545_dm_regs[] = { + [BQ27XXX_DM_DESIGN_CAPACITY] = { 48, 23, 2, 0, 32767 }, + [BQ27XXX_DM_DESIGN_ENERGY] = { 48, 25, 2, 0, 32767 }, + [BQ27XXX_DM_TERMINATE_VOLTAGE] = { 80, 67, 2, 2800, 3700 }, +}; + +static struct bq27xxx_dm_reg bq27421_dm_regs[] = { + [BQ27XXX_DM_DESIGN_CAPACITY] = { 82, 10, 2, 0, 8000 }, + [BQ27XXX_DM_DESIGN_ENERGY] = { 82, 12, 2, 0, 32767 }, + [BQ27XXX_DM_TERMINATE_VOLTAGE] = { 82, 16, 2, 2500, 3700 }, +}; + +static struct bq27xxx_dm_reg bq27425_dm_regs[] = { + [BQ27XXX_DM_DESIGN_CAPACITY] = { 82, 12, 2, 0, 32767 }, + [BQ27XXX_DM_DESIGN_ENERGY] = { 82, 14, 2, 0, 32767 }, + [BQ27XXX_DM_TERMINATE_VOLTAGE] = { 82, 18, 2, 2800, 3700 }, +}; + +static struct bq27xxx_dm_reg bq27621_dm_regs[] = { + [BQ27XXX_DM_DESIGN_CAPACITY] = { 82, 3, 2, 0, 8000 }, + [BQ27XXX_DM_DESIGN_ENERGY] = { 82, 5, 2, 0, 32767 }, + [BQ27XXX_DM_TERMINATE_VOLTAGE] = { 82, 9, 2, 2500, 3700 }, +}; + +static struct bq27xxx_dm_reg *bq27xxx_dm_regs[] = { + [BQ27500] = bq27500_dm_regs, + [BQ27545] = bq27545_dm_regs, + [BQ27421] = bq27421_dm_regs, + [BQ27425] = bq27425_dm_regs, + [BQ27441] = bq27421_dm_regs, + [BQ27621] = bq27621_dm_regs, +}; + +static u32 bq27xxx_unseal_keys[] = { + [BQ27500] = 0x04143672, + [BQ27545] = 0x04143672, + [BQ27421] = 0x80008000, + [BQ27425] = 0x04143672, + [BQ27441] = 0x80008000, + [BQ27621] = 0x80008000, +}; + #ifdef CONFIG_BATTERY_BQ27XXX_DT_UPDATES_NVM static bool bq27xxx_dt_to_nvm = true; @@ -1865,9 +1940,16 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di) .drv_data = di, }; + di->ram_chip = di->chip == BQ27421 || di->chip == BQ27441 || di->chip == BQ27621; + + di->unseal_key = bq27xxx_unseal_keys[di->chip]; + di->dm_regs = bq27xxx_dm_regs[di->chip]; + di->chip = bq27xxx_chips[di->chip]; + + di->regs = bq27xxx_regs[di->chip]; + INIT_DELAYED_WORK(&di->work, bq27xxx_battery_poll); mutex_init(&di->lock); - di->regs = bq27xxx_regs[di->chip]; psy_desc = devm_kzalloc(di->dev, sizeof(*psy_desc), GFP_KERNEL); if (!psy_desc) diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c index a597221..0b11ed4 100644 --- a/drivers/power/supply/bq27xxx_battery_i2c.c +++ b/drivers/power/supply/bq27xxx_battery_i2c.c @@ -230,7 +230,7 @@ static const struct i2c_device_id bq27xxx_i2c_id_table[] = { { "bq27210", BQ27010 }, { "bq27500", BQ2750X }, { "bq27510", BQ2751X }, - { "bq27520", BQ2751X }, + { "bq27520", BQ2752X }, { "bq27500-1", BQ27500 }, { "bq27510g1", BQ27510G1 }, { "bq27510g2", BQ27510G2 }, @@ -240,16 +240,16 @@ static const struct i2c_device_id bq27xxx_i2c_id_table[] = { { "bq27520g3", BQ27520G3 }, { "bq27520g4", BQ27520G4 }, { "bq27530", BQ27530 }, - { "bq27531", BQ27530 }, + { "bq27531", BQ27531 }, { "bq27541", BQ27541 }, - { "bq27542", BQ27541 }, - { "bq27546", BQ27541 }, - { "bq27742", BQ27541 }, + { "bq27542", BQ27542 }, + { "bq27546", BQ27546 }, + { "bq27742", BQ27742 }, { "bq27545", BQ27545 }, { "bq27421", BQ27421 }, - { "bq27425", BQ27421 }, - { "bq27441", BQ27421 }, - { "bq27621", BQ27421 }, + { "bq27425", BQ27425 }, + { "bq27441", BQ27441 }, + { "bq27621", BQ27621 }, {}, }; MODULE_DEVICE_TABLE(i2c, bq27xxx_i2c_id_table); diff --git a/include/linux/power/bq27xxx_battery.h b/include/linux/power/bq27xxx_battery.h index 11e1168..543c10e 100644 --- a/include/linux/power/bq27xxx_battery.h +++ b/include/linux/power/bq27xxx_battery.h @@ -2,6 +2,8 @@ #define __LINUX_BQ27X00_BATTERY_H__ enum bq27xxx_chip { + /* these index bq27xxx_regs[] & bq27xxx_battery_props[] */ + /* and map to themselves in bq27xxx_chips[] */ BQ27000 = 1, /* bq27000, bq27200 */ BQ27010, /* bq27010, bq27210 */ BQ2750X, /* bq27500 deprecated alias */ @@ -18,6 +20,17 @@ enum bq27xxx_chip { BQ27541, /* bq27541, bq27542, bq27546, bq27742 */ BQ27545, /* bq27545 */ BQ27421, /* bq27421, bq27425, bq27441, bq27621 */ + BQ27MAX, + + /* these map to above in bq27xxx_chips[] */ + BQ2752X, /* deprecated alias */ + BQ27531, + BQ27542, + BQ27546, + BQ27742, + BQ27425, + BQ27441, + BQ27621, }; /**