From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796545528; b=gdI7Vg2uyWvfzY4wiBLGQ05IQNELoTIb0YXiHStMqdJFZXJbnDF5+FweJxylWoa/wC1/ geIoOe/2Do0TEMsDNxgBjt5O6WVTkxRcBXWrYybzBCCocpc5pMwQnd6hICZqXt9y1L3mm 7dQIKfgvVUKjshYA5LlIG/N5k2p52jb5STCZyIB2S3quRWR8IZznf2IQRQCLefCVFrGnv V1VIN6mCodVnlmFU058vMguBuJKgdMXoobzg/sPmqzC+poSk2nPzIHzKOxDRJpe2p/+Vz GazvRUh+XRCqjvxtuVY/aSUXNBMv0ewJnKLKcIobs4vY//DStbTtYKfLiSmWyOayYHA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796545528; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=Sp4Nsu2vApA3LwwQ45cG/m5J+W6n97rqT1l3jB7Jv+g=; b=wjSiP8DZtQtgUM2319R5dp1B2ixcHnq2XJiopgBh3ddWYpBIG0mEd1XaXE+ZIYzH6oiA Tu9CRLBJsqPhAP1Gwowl7S1CeRgWG7EAbnk6/tIRYVYS1mMwbLYaGH9xzgE+e/6ehoM6D z5Rbr7XBxF9f4agWG8nanpaXT6kvT9nNpgVYcG+ORT7Zm/L/gNrqmTxd99AxB2P9h8XI+ zlZS6TMAC0kos+1y/ykWk3dfCLHjUFRfGAXnOgx0yb0gH+VDWCI2mb+KDdKvF38Zr8XHv P26N5lDaQJdFbzE1VUQYeF5A69xoI/vhs/hWn9UH9ScwtI/+BzAIs2f1YJWkUM8oGbg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="c/3DFYnp"; arc=none smtp.remote-ip=74.125.82.52 Received: from mail-dl1-f52.google.com (mail-dl1-f52.google.com [74.125.82.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24B5B606A324 for ; Sun, 6 Dec 2026 08:25:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 24B5B606A324 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=c/3DFYnp Received: by mail-dl1-f52.google.com with SMTP id a92af1059eb24-1aefd1bf74aso1527217c88.1 for ; Sun, 06 Dec 2026 00:25:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796545527; x=1797150327; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Sp4Nsu2vApA3LwwQ45cG/m5J+W6n97rqT1l3jB7Jv+g=; b=c/3DFYnp5iJa6/zHhzXAkHvipwuWnizPy/hhaxghQJDN8/+3FYRp8bIHhjANS4HhwB ZULDV2gJ4fnMzsSLI7nB1xWmb2f/tjtOglvHYbJPDmyraVVWrcezSNRU3446EsECIBNb e8hb6Kl4dl4EfbNssRzSHR4Ue9vkdZWqqSr4rs6f5Rr+pSu3xE/gzIVcLi00g3ZWFTeP Z/HfPyLP67MIKvidqSxX4fDviFf+S93MCfhGNByh8AJau2Uon3UL8GpFbSdpubupKuLC YgeUsFSJ5QN5Zofj3JwWF/uu6IKBIycS76G8nS7QF6YJZw3UY9wA2FZOuPc8L059hOyT l7Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796545527; x=1797150327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Sp4Nsu2vApA3LwwQ45cG/m5J+W6n97rqT1l3jB7Jv+g=; b=UhJ1/Qs/+QBhvgZJjACV4rJZP2bs4xevBMcWi4mk4Ae96vDss6HVNbrXlhs/P16cAU yWutwMGatR7tDRa9ar6OukPLJbteq7RJV6S+byHVLuZ7CRUD/gt+jT/Zhf4OnPltw69D vzECNar3yruJrldY3QzU6PiNtX57xot0zJMuvMW5W5jsskaSQM7lJ/x1HkAM217+OZ0h 2yrs6h3uahAO5R8cCHOFsbqCLjvl7VW6D4CA16py8WT/dbpgzJCgdNYeOAO+h+0VmPa+ OJEjZgaxplTjcRO3cuLsS4uEb8jRZuwJCX8LJE/YDGi7grDgN8DUgd40lo03eFDzGzJ4 HIIg== X-Forwarded-Encrypted: i=1; AL+hErEGC/YN0sYoqX8ml+4zFJEV542b4a/OjkNnihMpdnviyXIkAwAzZFPJulvs6Xv7KcO4COQ/S8c/M75WKBo=@vger.kernel.org X-Gm-Message-State: APuU4Z96I2vnUs3YGWwaQrtEuX/3jpPO+Cb2mr+HAdSH0oxYmONNj4kW cht8tLEVMu7Lq5asSwqUgsbIJaXJr1zpwBAVy2ACdV/0c5yXD8KCcoeB X-Gm-Gg: AZFdTZd7UlkmUwGR2lN0tAgMrfsZchsCkw/SnFN2npz8QRZC3mwVuZ7qBQUXJ7C1DJH 3CM7fWgypHsa7RAw7WQEcwADI+5TOYAmpzQSN2+qSOxs7iydCUQLhrYUP/jH52qsdnNv3BP7fVx 1jwrvZQvPn9eGx42VJoYwvwAeOBrqRU0EJTJ6z6kysYSscsyeETTx9XewKfRTYlipZDT5ZTSl1U ZPDvDdb+SxiPxGu4a2ew6C/OdDW4c1jOv4Dz5wOb5uGUBgEmHm+SBD3Oy3/Mk6a98eWZ5K7VPVe wo4pMRT84wsQM2qJRPdmXl4YfKe7tDC8EASIkCC0+E/6HkoFq3b9htFpKQE9tWLnQY4wfVTW2i0 T/9kR1DC3h/boC9sL9RnctnYzRDfrTflD8aDVoHbenG78UzLi3/nRoTOrmTYJQW5IUyfFccnAL2 xceW80onQfyWgs3JEntChsZOKpH0/LTgtZ9OXyFskDzbog8Mh8iAxe7Hz5ciXvcniw7N7CkrLIh hF6sU195qt+decXCKxwSXKIP3Uz0msjBhz/4DK55T45aWzj6QJbH8k07zxtKFM3EbB5BQCu9Ras DoWWaaXqQccweVHdQcOrRBMP2d48sKcLaJrMLXvHeR/eHA1TzS0ahbiUXw== X-Received: by 2002:a05:701b:4181:10b0:1ab:90a8:87a2 with SMTP id a92af1059eb24-1b5ced893b0mr9174756c88.11.1796545527158; Sun, 06 Dec 2026 00:25:27 -0800 (PST) Received: from DESKTOP-0MCCH07.localdomain ([103.240.170.43]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d644171bsm23353219c88.7.2026.12.06.00.25.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 00:25:26 -0800 (PST) From: Prachoday Sutar To: sre@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, pali@kernel.org, afd@ti.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Prachoday Sutar Subject: [PATCH v3 1/2] power: supply: bq27xxx: Use i2c_get_match_data() Date: Sun, 6 Dec 2026 13:55:00 +0530 Message-Id: <20261206082501.10506-2-prachodaysutar7@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20261206082501.10506-1-prachodaysutar7@gmail.com> References: <20261206082501.10506-1-prachodaysutar7@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit bq27xxx_battery_i2c_probe() gets the chip type and the battery name from i2c_client_get_device_id(), which looks up the client name in the I2C ID table. The OF match table has no .data, so even when the device is matched through a DT compatible, the chip type comes from the I2C ID table. This only works as long as the two tables are kept in sync and the client name, which is taken from the first DT compatible, has an entry in the I2C ID table. A device described with a fallback compatible, where only the fallback is known to the driver, gets a NULL ID and probe dereferences it. Add the chip type as .data to every OF match entry and get it with i2c_get_match_data(), which uses the OF match data and falls back to the I2C ID table. Use client->name for the battery name. For every compatible in the OF match table, client->name is the same as the matching I2C ID name, so the names seen by userspace do not change. Suggested-by: Andrew Davis Signed-off-by: Prachoday Sutar --- drivers/power/supply/bq27xxx_battery_i2c.c | 76 ++++++++++++---------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c index 63bfc868a6d..8e54dbfee2d 100644 --- a/drivers/power/supply/bq27xxx_battery_i2c.c +++ b/drivers/power/supply/bq27xxx_battery_i2c.c @@ -157,12 +157,16 @@ static void bq27xxx_battery_i2c_devm_ida_free(void *data) static int bq27xxx_battery_i2c_probe(struct i2c_client *client) { - const struct i2c_device_id *id = i2c_client_get_device_id(client); struct bq27xxx_device_info *di; + enum bq27xxx_chip chip; int ret; char *name; long num; + chip = (uintptr_t)i2c_get_match_data(client); + if (!chip) + return -ENODEV; + /* Get new ID for the new battery device */ num = ida_alloc(&battery_id, GFP_KERNEL); if (num < 0) @@ -173,7 +177,7 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client) if (ret) return ret; - name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%ld", id->name, num); + name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%ld", client->name, num); if (!name) return -ENOMEM; @@ -182,7 +186,7 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client) return -ENOMEM; di->dev = &client->dev; - di->chip = id->driver_data; + di->chip = chip; di->name = name; di->bus.read = bq27xxx_battery_i2c_read; @@ -266,39 +270,39 @@ MODULE_DEVICE_TABLE(i2c, bq27xxx_i2c_id_table); #ifdef CONFIG_OF static const struct of_device_id bq27xxx_battery_i2c_of_match_table[] = { - { .compatible = "ti,bq27200" }, - { .compatible = "ti,bq27210" }, - { .compatible = "ti,bq27500" }, - { .compatible = "ti,bq27510" }, - { .compatible = "ti,bq27520" }, - { .compatible = "ti,bq27500-1" }, - { .compatible = "ti,bq27510g1" }, - { .compatible = "ti,bq27510g2" }, - { .compatible = "ti,bq27510g3" }, - { .compatible = "ti,bq27520g1" }, - { .compatible = "ti,bq27520g2" }, - { .compatible = "ti,bq27520g3" }, - { .compatible = "ti,bq27520g4" }, - { .compatible = "ti,bq27521" }, - { .compatible = "ti,bq27530" }, - { .compatible = "ti,bq27531" }, - { .compatible = "ti,bq27541" }, - { .compatible = "ti,bq27542" }, - { .compatible = "ti,bq27546" }, - { .compatible = "ti,bq27742" }, - { .compatible = "ti,bq27545" }, - { .compatible = "ti,bq27411" }, - { .compatible = "ti,bq27421" }, - { .compatible = "ti,bq27425" }, - { .compatible = "ti,bq27426" }, - { .compatible = "ti,bq27441" }, - { .compatible = "ti,bq27621" }, - { .compatible = "ti,bq27z561" }, - { .compatible = "ti,bq27z746" }, - { .compatible = "ti,bq28z610" }, - { .compatible = "ti,bq28z620" }, - { .compatible = "ti,bq34z100" }, - { .compatible = "ti,bq78z100" }, + { .compatible = "ti,bq27200", .data = (void *)BQ27000 }, + { .compatible = "ti,bq27210", .data = (void *)BQ27010 }, + { .compatible = "ti,bq27500", .data = (void *)BQ2750X }, + { .compatible = "ti,bq27510", .data = (void *)BQ2751X }, + { .compatible = "ti,bq27520", .data = (void *)BQ2752X }, + { .compatible = "ti,bq27500-1", .data = (void *)BQ27500 }, + { .compatible = "ti,bq27510g1", .data = (void *)BQ27510G1 }, + { .compatible = "ti,bq27510g2", .data = (void *)BQ27510G2 }, + { .compatible = "ti,bq27510g3", .data = (void *)BQ27510G3 }, + { .compatible = "ti,bq27520g1", .data = (void *)BQ27520G1 }, + { .compatible = "ti,bq27520g2", .data = (void *)BQ27520G2 }, + { .compatible = "ti,bq27520g3", .data = (void *)BQ27520G3 }, + { .compatible = "ti,bq27520g4", .data = (void *)BQ27520G4 }, + { .compatible = "ti,bq27521", .data = (void *)BQ27521 }, + { .compatible = "ti,bq27530", .data = (void *)BQ27530 }, + { .compatible = "ti,bq27531", .data = (void *)BQ27531 }, + { .compatible = "ti,bq27541", .data = (void *)BQ27541 }, + { .compatible = "ti,bq27542", .data = (void *)BQ27542 }, + { .compatible = "ti,bq27546", .data = (void *)BQ27546 }, + { .compatible = "ti,bq27742", .data = (void *)BQ27742 }, + { .compatible = "ti,bq27545", .data = (void *)BQ27545 }, + { .compatible = "ti,bq27411", .data = (void *)BQ27411 }, + { .compatible = "ti,bq27421", .data = (void *)BQ27421 }, + { .compatible = "ti,bq27425", .data = (void *)BQ27425 }, + { .compatible = "ti,bq27426", .data = (void *)BQ27426 }, + { .compatible = "ti,bq27441", .data = (void *)BQ27441 }, + { .compatible = "ti,bq27621", .data = (void *)BQ27621 }, + { .compatible = "ti,bq27z561", .data = (void *)BQ27Z561 }, + { .compatible = "ti,bq27z746", .data = (void *)BQ27Z746 }, + { .compatible = "ti,bq28z610", .data = (void *)BQ28Z610 }, + { .compatible = "ti,bq28z620", .data = (void *)BQ28Z620 }, + { .compatible = "ti,bq34z100", .data = (void *)BQ34Z100 }, + { .compatible = "ti,bq78z100", .data = (void *)BQ78Z100 }, {}, }; MODULE_DEVICE_TABLE(of, bq27xxx_battery_i2c_of_match_table); -- 2.25.1