From patchwork Thu Jan 2 11:15:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Antoine via B4 Relay X-Patchwork-Id: 13924417 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B3CCE77188 for ; Thu, 2 Jan 2025 11:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=t5IWl3BvQPHOScGwejqrpJs/9y6l362oqwo8Shq0eWQ=; b=behLzajv+NVSN+eMb+emd46Gg5 B4EhdZRLwFW1pzF3xvV6p8ZpVdSzOLK0lPBVX0MHUBYtrTlc20lMggjWWf90aqoCNpl3YRGr+Nugw qqk8mE1CK0wq7YgipvUPyB1RK74ChsMRPzE14JNZ5TrnJQJlucqGfc1KGmAP8mXyTvEt/C7lj+8au dmILbeJQUh1geCGmscXNvYS3ptVkGDcET1N1rBNzjzP4VnveKdfvWL1K6IldgvpXtaKfSU4yqpX2t qj6j6JQUVxPK6gJDhyFDppciz6ONGkUm+FfXk4un9/6HvacluuKUf2Rj0n5bIe+StrY+g3gVP9Qzx gsiRP3rA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTJH8-0000000AEtQ-0qgH; Thu, 02 Jan 2025 11:22:02 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTJBN-0000000AE4d-2vE9 for linux-arm-kernel@lists.infradead.org; Thu, 02 Jan 2025 11:16:08 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 002E25C5B1B; Thu, 2 Jan 2025 11:15:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id BAD99C4CEDC; Thu, 2 Jan 2025 11:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735816563; bh=uVJM28w90mPn/pp+xt2Z5h+uFmTW6E8YN+Hi2DgyMQc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Vm7eXrlfqyc5ybPM/vOhiUJUpqBpniX4+q4ttFRUHr3EGZoevhYcIKCFcXIkEPWSc z9zKUj4qN2nDgZD5+Uq0PADQ+1J/KrIvYW3+MKCIyptIgrUND93jPh7w5qDYcO6p2S G+QRKQ2HLfGo2pmDAfq1tfKl+XxFaSxnHUGp6THqXhGY3c7vbmH81/elg0lsnkEhlF lfbie6Qu9GMiWvuJOFBr9/ffRopSImujLpN+iJTIS1YCiFCw3w6SQALI7t1meAq3nz bdmw+PQPNGbjq3i8ilP1tkeS7VlhqoIAWHWqDX/VVgOOxohASOsMW3JqwUQd9NJOZN fmwPnbrlGdWrg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8715E7718B; Thu, 2 Jan 2025 11:16:03 +0000 (UTC) From: Thomas Antoine via B4 Relay Date: Thu, 02 Jan 2025 12:15:03 +0100 Subject: [PATCH v2 1/4] power: supply: add support for max77759 fuel gauge MIME-Version: 1.0 Message-Id: <20250102-b4-gs101_max77759_fg-v2-1-87959abeb7ff@uclouvain.be> References: <20250102-b4-gs101_max77759_fg-v2-0-87959abeb7ff@uclouvain.be> In-Reply-To: <20250102-b4-gs101_max77759_fg-v2-0-87959abeb7ff@uclouvain.be> To: Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Dimitri Fedrau , Catalin Marinas , Will Deacon , Peter Griffin , Alim Akhtar , =?utf-8?q?Andr=C3=A9_Draszik?= Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Thomas Antoine X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735816515; l=11285; i=t.antoine@uclouvain.be; s=20241202; h=from:subject:message-id; bh=4IBL246Fhqd8ttrmprrDpul0IZFfaEgZlroRGDMXvR0=; b=G/RKsQ1nU4D1xA5pEpCVOpAbdQXgpvT7DmVsoImMwv94qnAd5VaLPNVuvpEnWA/eEmjkj4W76 Kolf6kKjJSCCoxnV63/r7ILZI1eAXDXclQCTpA/ALDbKj0Og/mYGpK/ X-Developer-Key: i=t.antoine@uclouvain.be; a=ed25519; pk=sw7UYl31W1LTpgWRiX4xIF5x6ok7YWZ6XZnHqy/d3dY= X-Endpoint-Received: by B4 Relay for t.antoine@uclouvain.be/20241202 with auth_id=289 X-Original-From: Thomas Antoine X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250102_031605_922492_2D26CA0A X-CRM114-Status: GOOD ( 28.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: t.antoine@uclouvain.be Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Thomas Antoine The interface of the Maxim max77759 fuel gauge has a lot of common with the Maxim max1720x. The major difference is the lack of non-volatile memory slave address. No slave is available at address 0xb of the i2c bus, which is coherent with the following driver from google: line 5836 disables non-volatile memory for m5 gauge. Link: https://android.googlesource.com/kernel/google-modules/bms/+/1a68c36bef474573cc8629cc1d121eb6a81ab68c/max1720x_battery.c Other differences include the lack of V_BATT register to read the battery level and a difference in the way to identify the chip (the same register is used but not the same mask). Add support for the max77759 by allowing to use the non-volatile memory or not based on the chip. Also add the V_CELL regsister as a fallback to read voltage value in the case where read of V_BATT fails. The cast is necessary to avoid an overflow when the value of the register is above 54975 (equivalent to a voltage around 4.29 V). The regmap of the max77759 will lead the read to fail for V_BATT and to correctly use V_CELL instead. This regmap was proposed by AndrĂ© Draszik in Link: https://lore.kernel.org/all/d1bade77b5281c1de6b2ddcb4dbbd033e455a116.camel@linaro.org/ Signed-off-by: Thomas Antoine --- drivers/power/supply/max1720x_battery.c | 189 +++++++++++++++++++++++++++----- 1 file changed, 164 insertions(+), 25 deletions(-) diff --git a/drivers/power/supply/max1720x_battery.c b/drivers/power/supply/max1720x_battery.c index 33105419e2427bb37963bda9948b647c239f8faa..a41976679eded44fbd13120ad756a626d2867919 100644 --- a/drivers/power/supply/max1720x_battery.c +++ b/drivers/power/supply/max1720x_battery.c @@ -27,6 +27,7 @@ #define MAX172XX_REPCAP 0x05 /* Average capacity */ #define MAX172XX_REPSOC 0x06 /* Percentage of charge */ #define MAX172XX_TEMP 0x08 /* Temperature */ +#define MAX172XX_VCELL 0x09 /* Lowest cell voltage */ #define MAX172XX_CURRENT 0x0A /* Actual current */ #define MAX172XX_AVG_CURRENT 0x0B /* Average current */ #define MAX172XX_TTE 0x11 /* Time to empty */ @@ -39,6 +40,8 @@ #define MAX172XX_DEV_NAME_TYPE_MASK GENMASK(3, 0) #define MAX172XX_DEV_NAME_TYPE_MAX17201 BIT(0) #define MAX172XX_DEV_NAME_TYPE_MAX17205 (BIT(0) | BIT(2)) +#define MAX77759_DEV_NAME_TYPE_MASK GENMASK(15, 9) +#define MAX77759_DEV_NAME_TYPE_MAX77759 0x31 #define MAX172XX_QR_TABLE10 0x22 #define MAX172XX_BATT 0xDA /* Battery voltage */ #define MAX172XX_ATAVCAP 0xDF @@ -46,12 +49,20 @@ static const char *const max1720x_manufacturer = "Maxim Integrated"; static const char *const max17201_model = "MAX17201"; static const char *const max17205_model = "MAX17205"; +static const char *const max77759_model = "MAX77759"; + +enum chip_id { + MAX1720X_ID, + MAX77759_ID, +}; struct max1720x_device_info { struct regmap *regmap; struct regmap *regmap_nv; struct i2c_client *ancillary; int rsense; + int has_nvmem; + enum chip_id id; }; /* @@ -254,6 +265,67 @@ static const enum power_supply_property max1720x_battery_props[] = { POWER_SUPPLY_PROP_MANUFACTURER, }; +/* + * Registers 0x80 up to 0xaf which contain the model for the fuel gauge + * algorithm (stored in nvmem for the max1720x) are locked. They can + * be unlocked by writing 0x59 to 0x62 and 0xc4 to 0x63. They should be + * enabled in the regmap if the driver is extended to manage the model. + */ +static const struct regmap_range max77759_registers[] = { + regmap_reg_range(0x00, 0x4f), + regmap_reg_range(0xb0, 0xbf), + regmap_reg_range(0xd0, 0xd0), + regmap_reg_range(0xdc, 0xdf), + regmap_reg_range(0xfb, 0xfb), + regmap_reg_range(0xff, 0xff), +}; + +static const struct regmap_range max77759_ro_registers[] = { + regmap_reg_range(0x3d, 0x3d), + regmap_reg_range(0xfb, 0xfb), + regmap_reg_range(0xff, 0xff), +}; + +static const struct regmap_access_table max77759_write_table = { + .yes_ranges = max77759_registers, + .n_yes_ranges = ARRAY_SIZE(max77759_registers), + .no_ranges = max77759_ro_registers, + .n_no_ranges = ARRAY_SIZE(max77759_ro_registers), +}; + +static const struct regmap_access_table max77759_rd_table = { + .yes_ranges = max77759_registers, + .n_yes_ranges = ARRAY_SIZE(max77759_registers), +}; + +static const struct regmap_config max77759_regmap_cfg = { + .reg_bits = 8, + .val_bits = 16, + .max_register = 0xff, + .wr_table = &max77759_write_table, + .rd_table = &max77759_rd_table, + .val_format_endian = REGMAP_ENDIAN_LITTLE, + .cache_type = REGCACHE_NONE, +}; + +struct chip_data { + u8 has_nvmem; + const struct regmap_config *regmap_cfg; + enum chip_id id; +}; + +static const struct chip_data max1720x_data = { + .has_nvmem = 1, + .regmap_cfg = &max1720x_regmap_cfg, + .id = MAX1720X_ID, +}; + +static const struct chip_data max77759_data = { + .has_nvmem = 0, + .regmap_cfg = &max77759_regmap_cfg, + .id = MAX77759_ID, +}; + /* Convert regs value to power_supply units */ static int max172xx_time_to_ps(unsigned int reg) @@ -271,6 +343,14 @@ static int max172xx_voltage_to_ps(unsigned int reg) return reg * 1250; /* in uV */ } +// Use 64 bits because computation on 32 bits leads to an overflow +static int max172xx_cell_voltage_to_ps(unsigned int reg) +{ + u64 val = reg; + + return val * 78125 / 1000; /* in uV */ +} + static int max172xx_capacity_to_ps(unsigned int reg) { return reg * 500; /* in uAh */ @@ -303,6 +383,33 @@ static int max172xx_current_to_voltage(unsigned int reg) return val * 156252; } +static int max1720x_devname_to_model(unsigned int reg_val, + union power_supply_propval *val, + struct max1720x_device_info *info) +{ + switch (info->id) { + case MAX1720X_ID: + reg_val = FIELD_GET(MAX172XX_DEV_NAME_TYPE_MASK, reg_val); + if (reg_val == MAX172XX_DEV_NAME_TYPE_MAX17201) + val->strval = max17201_model; + else if (reg_val == MAX172XX_DEV_NAME_TYPE_MAX17205) + val->strval = max17205_model; + else + return -ENODEV; + break; + case MAX77759_ID: + reg_val = FIELD_GET(MAX77759_DEV_NAME_TYPE_MASK, reg_val); + if (reg_val == MAX77759_DEV_NAME_TYPE_MAX77759) + val->strval = max77759_model; + else + return -ENODEV; + break; + default: + return -ENODEV; + } + return 0; +} + static int max1720x_battery_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -332,7 +439,12 @@ static int max1720x_battery_get_property(struct power_supply *psy, break; case POWER_SUPPLY_PROP_VOLTAGE_NOW: ret = regmap_read(info->regmap, MAX172XX_BATT, ®_val); - val->intval = max172xx_voltage_to_ps(reg_val); + if (!ret) + val->intval = max172xx_voltage_to_ps(reg_val); + else { + ret = regmap_read(info->regmap, MAX172XX_VCELL, ®_val); + val->intval = max172xx_cell_voltage_to_ps(reg_val); + } break; case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: ret = regmap_read(info->regmap, MAX172XX_DESIGN_CAP, ®_val); @@ -364,13 +476,8 @@ static int max1720x_battery_get_property(struct power_supply *psy, break; case POWER_SUPPLY_PROP_MODEL_NAME: ret = regmap_read(info->regmap, MAX172XX_DEV_NAME, ®_val); - reg_val = FIELD_GET(MAX172XX_DEV_NAME_TYPE_MASK, reg_val); - if (reg_val == MAX172XX_DEV_NAME_TYPE_MAX17201) - val->strval = max17201_model; - else if (reg_val == MAX172XX_DEV_NAME_TYPE_MAX17205) - val->strval = max17205_model; - else - return -ENODEV; + if (!ret) + ret = max1720x_devname_to_model(reg_val, val, info); break; case POWER_SUPPLY_PROP_MANUFACTURER: val->strval = max1720x_manufacturer; @@ -416,7 +523,6 @@ static int max1720x_probe_nvmem(struct i2c_client *client, .priv = info, }; struct nvmem_device *nvmem; - unsigned int val; int ret; info->ancillary = i2c_new_ancillary_device(client, "nvmem", 0xb); @@ -438,18 +544,6 @@ static int max1720x_probe_nvmem(struct i2c_client *client, return PTR_ERR(info->regmap_nv); } - ret = regmap_read(info->regmap_nv, MAX1720X_NRSENSE, &val); - if (ret < 0) { - dev_err(dev, "Failed to read sense resistor value\n"); - return ret; - } - - info->rsense = val; - if (!info->rsense) { - dev_warn(dev, "RSense not calibrated, set 10 mOhms!\n"); - info->rsense = 1000; /* in regs in 10^-5 */ - } - nvmem = devm_nvmem_register(dev, &nvmem_config); if (IS_ERR(nvmem)) { dev_err(dev, "Could not register nvmem!"); @@ -459,6 +553,36 @@ static int max1720x_probe_nvmem(struct i2c_client *client, return 0; } +static int max1720x_get_rsense(struct device *dev, + struct max1720x_device_info *info) +{ + unsigned int val; + int ret; + + if (info->has_nvmem) { + ret = regmap_read(info->regmap_nv, MAX1720X_NRSENSE, &val); + if (ret < 0) { + dev_err(dev, "Failed to read RSense from nvmem\n"); + return ret; + } + + info->rsense = val; + if (!info->rsense) { + dev_warn(dev, "RSense not calibrated, set 10 mOhms!\n"); + info->rsense = 1000; /* in regs in 10^-5 */ + } + } else { + ret = of_property_read_u32(dev->of_node, + "shunt-resistor-micro-ohms", &val); + if (ret) { + dev_err(dev, "Failed to read RSense from devicetree\n"); + return ret; + } + info->rsense = val/10; + } + return 0; +} + static const struct power_supply_desc max1720x_bat_desc = { .name = "max1720x", .no_thermal = true, @@ -474,6 +598,7 @@ static int max1720x_probe(struct i2c_client *client) struct device *dev = &client->dev; struct max1720x_device_info *info; struct power_supply *bat; + const struct chip_data *data; int ret; info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); @@ -483,14 +608,27 @@ static int max1720x_probe(struct i2c_client *client) psy_cfg.drv_data = info; psy_cfg.fwnode = dev_fwnode(dev); i2c_set_clientdata(client, info); - info->regmap = devm_regmap_init_i2c(client, &max1720x_regmap_cfg); + + data = device_get_match_data(dev); + if (!data) + return dev_err_probe(dev, ret, "Failed to get chip data\n"); + + info->has_nvmem = data->has_nvmem; + info->id = data->id; + info->regmap = devm_regmap_init_i2c(client, data->regmap_cfg); if (IS_ERR(info->regmap)) return dev_err_probe(dev, PTR_ERR(info->regmap), "regmap initialization failed\n"); - ret = max1720x_probe_nvmem(client, info); + if (data->has_nvmem) { + ret = max1720x_probe_nvmem(client, info); + if (ret) + return dev_err_probe(dev, ret, "Failed to probe nvmem\n"); + } + + ret = max1720x_get_rsense(dev, info); if (ret) - return dev_err_probe(dev, ret, "Failed to probe nvmem\n"); + return dev_err_probe(dev, ret, "Failed to get RSense"); bat = devm_power_supply_register(dev, &max1720x_bat_desc, &psy_cfg); if (IS_ERR(bat)) @@ -501,7 +639,8 @@ static int max1720x_probe(struct i2c_client *client) } static const struct of_device_id max1720x_of_match[] = { - { .compatible = "maxim,max17201" }, + { .compatible = "maxim,max17201", .data = (void *) &max1720x_data }, + { .compatible = "maxim,max77759-fg", .data = (void *) &max77759_data }, {} }; MODULE_DEVICE_TABLE(of, max1720x_of_match); From patchwork Thu Jan 2 11:15:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Antoine via B4 Relay X-Patchwork-Id: 13924415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7311CE77188 for ; Thu, 2 Jan 2025 11:19:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/sHbyVVVphEP21Gb1FWUwdcoubWd7dsPOQRT2FxUz/g=; b=OGIQ7cADHuuul/AZcsg1MvJDRu 1k8mjKwefo0W7cIX2GzLy466j5qXiQj8siiAU+cZBx7+dHVrW3RX6hM5dC8N1mCrZ5neex2++hxKB KZwZrT/2DJwwLYr3LPOyztNGlbYShuBAJytvfxQYY6xWUMfbkS9RDfWv+IHv+iWkf+heJ9vREYQVd JvfTCKvLx0UR5sKwPtgkR9iWFF22T5BQt0WsDZL4jMiXlfeciX2HeNzdFbIntnb5Yw8cBPR88EXD/ 3Rf0UGGqxOP1LLr2xgKAKV5biMYKUhekgxHFAovNp8e0VMDZRsFSPk6vSWQMmLMwCt5PJ0+0MC8RM p1/axzpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTJEp-0000000AEaF-3jO1; Thu, 02 Jan 2025 11:19:39 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTJBN-0000000AE4e-2d5i for linux-arm-kernel@lists.infradead.org; Thu, 02 Jan 2025 11:16:07 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 236435C5B86; Thu, 2 Jan 2025 11:15:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id D035AC4CEE0; Thu, 2 Jan 2025 11:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735816563; bh=YR3aOQfQRpjZeAPGaopQcbBOCXaW1wkvfZuiJhh9ZRs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=nwB82J1Pv2iNNTb2Af7IuogSNLkCde2a3t0qaAzS97CdDpXBqitQiDKZ1AV1o2hZ7 mbyzLeyQeB2TWP/VrsCWotg84pwCHlfJt2PpMlXIbfQhFrm0fsu9mf5gDe2jFG9Gef LF34GIxYDDxKGA+R+zsuHU8omuWo/piJT/j/rLeQapr0KgUDOmNl1l0eHYMqF9rd2A 4/VtzP9Uq/4PQ64doNWVk4mWeB5CM8UxTVBhSEzGkZiAApGDInZ6W4dXf6Cjq+6JXx 87zvrIWvHHgMaOtyPWkHg09EOqFbouIdB2oef/i1gdt2uUc1pkp/iUBN11gapKvdtr xiIJuV6M+pkaA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD23FE77197; Thu, 2 Jan 2025 11:16:03 +0000 (UTC) From: Thomas Antoine via B4 Relay Date: Thu, 02 Jan 2025 12:15:04 +0100 Subject: [PATCH v2 2/4] dt-bindings: power: supply: add max77759-fg flavor MIME-Version: 1.0 Message-Id: <20250102-b4-gs101_max77759_fg-v2-2-87959abeb7ff@uclouvain.be> References: <20250102-b4-gs101_max77759_fg-v2-0-87959abeb7ff@uclouvain.be> In-Reply-To: <20250102-b4-gs101_max77759_fg-v2-0-87959abeb7ff@uclouvain.be> To: Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Dimitri Fedrau , Catalin Marinas , Will Deacon , Peter Griffin , Alim Akhtar , =?utf-8?q?Andr=C3=A9_Draszik?= Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Thomas Antoine X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735816515; l=2599; i=t.antoine@uclouvain.be; s=20241202; h=from:subject:message-id; bh=NQEfG+SwFTGG+va2nEDX792ufRBYG0gtt35ac3EAHLY=; b=jM9VyggQ6eUW1RT5Sw+s3vgG3v7+G7XxjmfVHL2taeQU21fLP17pnVRrLZpT7NYIGIpDtxYrk OMqxPoSo6FqBEGjo0OnJe41tXf4Ii/jZK6JPj76xV1c1Vmui0kl7rNh X-Developer-Key: i=t.antoine@uclouvain.be; a=ed25519; pk=sw7UYl31W1LTpgWRiX4xIF5x6ok7YWZ6XZnHqy/d3dY= X-Endpoint-Received: by B4 Relay for t.antoine@uclouvain.be/20241202 with auth_id=289 X-Original-From: Thomas Antoine X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250102_031605_915583_1D41152F X-CRM114-Status: GOOD ( 11.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: t.antoine@uclouvain.be Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Thomas Antoine The max77759 is an IC used to manage the power supply of the battery and the USB-C. Based on drivers from google, it contains at least a PMIC, a fuel gauge, a TCPCI and a charger. Use max77759-fg compatible to avoid conflict with drivers for other functions. The max77759 has no non-volatile memory so it doesn't require an address and instead requires a value for the current sensing resistor. Signed-off-by: Thomas Antoine --- .../bindings/power/supply/maxim,max17201.yaml | 56 +++++++++++++++++----- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/Documentation/devicetree/bindings/power/supply/maxim,max17201.yaml b/Documentation/devicetree/bindings/power/supply/maxim,max17201.yaml index fe3dd9bd5585618e45220c51023391a5b21acfd2..7e95314508c27d0d90ea92f61bca6b4a2fe0e88e 100644 --- a/Documentation/devicetree/bindings/power/supply/maxim,max17201.yaml +++ b/Documentation/devicetree/bindings/power/supply/maxim,max17201.yaml @@ -9,31 +9,61 @@ title: Maxim MAX17201 fuel gauge maintainers: - Dimitri Fedrau -allOf: - - $ref: power-supply.yaml# - properties: compatible: oneOf: - const: maxim,max17201 + - const: maxim,max77759-fg - items: - enum: - maxim,max17205 - const: maxim,max17201 - reg: - items: - - description: ModelGauge m5 registers - - description: Nonvolatile registers - - reg-names: - items: - - const: m5 - - const: nvmem - interrupts: maxItems: 1 +allOf: + - $ref: power-supply.yaml# + - if: + properties: + compatible: + contains: + enum: + - maxim,max17201 + then: + properties: + reg: + items: + - description: ModelGauge m5 registers + - description: Nonvolatile registers + minItems: 1 + + reg-names: + items: + - const: m5 + - const: nvmem + - if: + properties: + compatible: + contains: + enum: + - maxim,max77759-fg + then: + properties: + reg: + items: + - description: ModelGauge m5 registers + + reg-names: + items: + - const: m5 + + shunt-resistor-micro-ohms: + description: The value of current sense resistor. + + required: + - shunt-resistor-micro-ohms + required: - compatible - reg From patchwork Thu Jan 2 11:15:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Antoine via B4 Relay X-Patchwork-Id: 13924398 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3E344E7718B for ; Thu, 2 Jan 2025 11:17:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6Sv8VlDcdty6dXKs5TqiCQneSEFJfWRoyrb9P0zJ3B4=; b=QbxkAXoIlyKvce6lHQZ2akEIPa RYv7JxQCdqlTLzWWl35SpJFgi/8LTuJc0/TDvdLciBtSdWCrRJPf45YHR+aVHGm8dUvISZcm3RuFK FgBC+lflwiB1kM5CT6prq5gHTihsClSMdmlixfJ4r0gV7KvL7jY4vmjl/9GioYUUmYy+i3UDajeGC dlzM4kpdxxs0+xoR9Lqwv5svEASHqZiGf18ihmYELZcJx+RdF1aD0/v4Ss3G1dO5hr83dljPU9PbS cMNJeiLsYl5z4AVMWjVy76oTwHuHwaKjjlb01Qp8elTV5TiHTyJ1zUDAjqTD49mfB4oRsX8rg2xD7 5LFTQ39w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTJCY-0000000AEJt-1TYo; Thu, 02 Jan 2025 11:17:18 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTJBN-0000000AE4f-3FMT for linux-arm-kernel@lists.infradead.org; Thu, 02 Jan 2025 11:16:06 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 3D3585C5BCA; Thu, 2 Jan 2025 11:15:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id DBB29C4CEDF; Thu, 2 Jan 2025 11:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735816563; bh=TzjaYhY/z3XxXLGIN2R6r5WrYgQeVscsnkIXZorYgOQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Tel1G9tDHbWDZKJA0yBm885Spi5Hv0lyWtvKOOeYMwHTURcTQMaoXl8s81R0ZRtoM iJmhF7GiURrp7P5zJmhhjPIe2Gjs654OAkSQDepm4v9ICVoPfixP6t46SFkvRTSxBG zoEr6iBi2T+ZP04eHVuein2/px8+IslsMqbJlDnDN7XxXw4m7oazWqgOyzFGM1yLGe DoyVHHbDEU0MiveeGVkZlDw2Wr5h8IBL+inL29Fo+ytxJGQKUXQtH3lQIr8kWU3qyh Z7voe7ZaGgzDqSRP2Ao2uaC31hsyQKfzCYyukGWwi3miHk1yPJjsMk7dBD8HdPd1oT 2jvkBTvgPkuQg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0B5BE77188; Thu, 2 Jan 2025 11:16:03 +0000 (UTC) From: Thomas Antoine via B4 Relay Date: Thu, 02 Jan 2025 12:15:05 +0100 Subject: [PATCH v2 3/4] arm64: defconfig: enable Maxim max1720x driver MIME-Version: 1.0 Message-Id: <20250102-b4-gs101_max77759_fg-v2-3-87959abeb7ff@uclouvain.be> References: <20250102-b4-gs101_max77759_fg-v2-0-87959abeb7ff@uclouvain.be> In-Reply-To: <20250102-b4-gs101_max77759_fg-v2-0-87959abeb7ff@uclouvain.be> To: Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Dimitri Fedrau , Catalin Marinas , Will Deacon , Peter Griffin , Alim Akhtar , =?utf-8?q?Andr=C3=A9_Draszik?= Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Thomas Antoine X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735816515; l=716; i=t.antoine@uclouvain.be; s=20241202; h=from:subject:message-id; bh=4mcHoKDe8g9Cb02OHRiFohYMU9w9oiqZT1kzkWCs778=; b=u0MDFhtyvDcPVMHQuoWVOLHGPzXV3ocxbaOLiaQom2uPtJRuCPR0HfSqrffKvygn/k6OgR/84 UQ452q5sO5HDwZZZ+qihb1/5ZRmhVbSBhf9AHV5ljOjW1yQ/N3jmcky X-Developer-Key: i=t.antoine@uclouvain.be; a=ed25519; pk=sw7UYl31W1LTpgWRiX4xIF5x6ok7YWZ6XZnHqy/d3dY= X-Endpoint-Received: by B4 Relay for t.antoine@uclouvain.be/20241202 with auth_id=289 X-Original-From: Thomas Antoine X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250102_031605_911925_384F035D X-CRM114-Status: UNSURE ( 8.97 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: t.antoine@uclouvain.be Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Thomas Antoine Enable the Maxim max1720x as it is used by the gs101-oriole (Google Pixel 6) board. Signed-off-by: Thomas Antoine --- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig index d13218d0c30f458d9c555ab9771a1fd9139ce1aa..7161387d1ebfea0d363e9413ef4350d83b581d96 100644 --- a/arch/arm64/configs/defconfig +++ b/arch/arm64/configs/defconfig @@ -676,6 +676,7 @@ CONFIG_BATTERY_QCOM_BATTMGR=m CONFIG_BATTERY_SBS=m CONFIG_BATTERY_BQ27XXX=y CONFIG_BATTERY_MAX17042=m +CONFIG_BATTERY_MAX1720X=m CONFIG_CHARGER_MT6360=m CONFIG_CHARGER_BQ25890=m CONFIG_CHARGER_BQ25980=m From patchwork Thu Jan 2 11:15:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Antoine via B4 Relay X-Patchwork-Id: 13924416 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2CF2CE77188 for ; Thu, 2 Jan 2025 11:21:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To: References:Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version: Subject:Date:From:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=XsTz3yxj73PvMooWjsRyjQL/jl+71VcPQ1lJJyc5WyE=; b=nLpCiX1yBzbk8WQ9cQTkuNtusg KXsqU6U3v3JuRM2Qs9CjsV+hX1HP67owQXI27qmjqABdiD5trw5LLMbYLeI82kw7176sAwpeFq2gy HFBgVAFHtKFu3mXD4kdN8gwFsrE9rFG28RPxCmds3aWlIo9M++F9U5ONu0vEwntzklRlB5gn49P8H u7LC+nxdcMnrfsNXTuXA6mTJhgLw5EHHZVKzH748lIVDFLtSKTs3AS4XfHu3L3QRMagm+AO52Ey1V pm/2ly6g5+D64MoSFmMYfm4O7TWJYvd7EtYWzWFaAOXLEItyaBvkL/ySiY4wxppTusklno5C0bEVi 8cSGKK/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTJG0-0000000AEiJ-2JTr; Thu, 02 Jan 2025 11:20:52 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTJBN-0000000AE4g-3344 for linux-arm-kernel@lists.infradead.org; Thu, 02 Jan 2025 11:16:07 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6FC1C5C5B12; Thu, 2 Jan 2025 11:15:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id EC3B4C4CEE4; Thu, 2 Jan 2025 11:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735816564; bh=cEnF3ovwUU25dT0wsQm5L10I978yEVeevFbc61/RQ9w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=pC7/Iq/hYbOMU0dmtsCyG38BVc069b6zrNQ+D4jl5WSlJN1A3z7hpRDea6DtcMl3A h82NEKQ9VBXwbPH5sjh82PqtjKGzocubCEjlaojhVDzJT1F/7KBPVhbiAWMarGvE5G Buw/+qvSMLSbxmQngFePpvp7q0HVK7JEZnI4ZyQCgTQYPt550RP3nbLaN3QCqUmDqR 2Hjdl3Qq2pq+M8q7vVOOyOfHAIS/8t+sWFqwsHBM20jW+LI/uz1TRZo76jOrjigCvM jCbfgIht/5UilrbzjAadxVFrDmNf+SJRxFLEJQlBnSMmdpsgFpBZgyr7GLx7TQ99Hl 9SS197wW5uZ3w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E29EDE77194; Thu, 2 Jan 2025 11:16:03 +0000 (UTC) From: Thomas Antoine via B4 Relay Date: Thu, 02 Jan 2025 12:15:06 +0100 Subject: [PATCH v2 4/4] arm64: dts: exynos: gs101-oriole: enable Maxim max77759 fuel gauge MIME-Version: 1.0 Message-Id: <20250102-b4-gs101_max77759_fg-v2-4-87959abeb7ff@uclouvain.be> References: <20250102-b4-gs101_max77759_fg-v2-0-87959abeb7ff@uclouvain.be> In-Reply-To: <20250102-b4-gs101_max77759_fg-v2-0-87959abeb7ff@uclouvain.be> To: Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Dimitri Fedrau , Catalin Marinas , Will Deacon , Peter Griffin , Alim Akhtar , =?utf-8?q?Andr=C3=A9_Draszik?= Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Thomas Antoine X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735816515; l=1485; i=t.antoine@uclouvain.be; s=20241202; h=from:subject:message-id; bh=GN3EniKaEOYE0aMNRzhLT0R4oirK05MCY9w8a0rDXYc=; b=eMvTZq9F+2RWFQ1BgK4RRLys8hBQwJ8vxzR3brqK5tBh//epZY74AciI9nsB10bwtDs1X2cbA YbKhbU97pEDDbvI3SWyzXLCMXp5vg1Z6AoNRMAQDFPtFUDxrpzy1Z+z X-Developer-Key: i=t.antoine@uclouvain.be; a=ed25519; pk=sw7UYl31W1LTpgWRiX4xIF5x6ok7YWZ6XZnHqy/d3dY= X-Endpoint-Received: by B4 Relay for t.antoine@uclouvain.be/20241202 with auth_id=289 X-Original-From: Thomas Antoine X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250102_031605_923712_C87D76E9 X-CRM114-Status: GOOD ( 10.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: t.antoine@uclouvain.be Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Thomas Antoine Add the node for the max77759 fuel gauge as a slave of the i2c. The todo is still applicable given there are other slaves on the bus (pca9468, other max77759 functions and the max20339 OVP). The fuel gauge has been tested and seems to give coherent results. Manual activation of the charger via i2cset shows that the sign of the current does indicate charging/discharging status. Signed-off-by: Thomas Antoine --- arch/arm64/boot/dts/exynos/google/gs101-oriole.dts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm64/boot/dts/exynos/google/gs101-oriole.dts b/arch/arm64/boot/dts/exynos/google/gs101-oriole.dts index 387fb779bd29ea3812331a7951f03b181c5fe659..6c83ee6f8a6b0327c576573d03a8d2bcc93f9e16 100644 --- a/arch/arm64/boot/dts/exynos/google/gs101-oriole.dts +++ b/arch/arm64/boot/dts/exynos/google/gs101-oriole.dts @@ -10,6 +10,7 @@ #include #include +#include #include "gs101-pinctrl.h" #include "gs101.dtsi" @@ -90,6 +91,15 @@ eeprom: eeprom@50 { &hsi2c_12 { status = "okay"; /* TODO: add the devices once drivers exist */ + + fuel-gauge@36 { + compatible = "maxim,max77759-fg"; + reg = <0x36>; + reg-names = "m5"; + shunt-resistor-micro-ohms = <5000>; + interrupt-parent = <&gpa9>; + interrupts = <3 IRQ_TYPE_LEVEL_LOW>; + }; }; &pinctrl_far_alive {