mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] i2c: slave-eeprom: Add an OF match table for module autoload
@ 2026-11-10  5:34 Arun Iyengar via B4 Relay
  2026-11-10 18:15 ` Uwe Kleine-König
  0 siblings, 1 reply; 2+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-10  5:34 UTC (permalink / raw)
  To: Andi Shyti; +Cc: Wolfram Sang, linux-i2c, linux-kernel, Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

A backend instantiated from the device tree (compatible "slave-24c02",
reg = <(0x64 | I2C_OWN_SLAVE_ADDRESS)>) gets an i2c client, but the
uevent of a client with an of_node carries an of: modalias
(of:N...Cslave-24c02). The module only declares i2c: aliases, so udev
never loads it and the client stays unbound: there is no slave-eeprom
file and no target is registered, with nothing in the log. Only the
sysfs new_device path (i2c: modalias) or a manual modprobe works.

Declare the same names as an OF table and export it, so the module
autoloads for DT and overlay clients. Matching and probe are unchanged:
the client name is the compatible without a vendor prefix, so
i2c_client_get_device_id() still finds the size and flags.

Tested on an Orange Pi Zero2 (H616) with a slave-24c02 node under TWI3
from a DT overlay, using a local target-mode patch for i2c-mv64xxx:
without this change the client stays unbound after boot; with it the
module autoloads, binds to 3-1064 and creates the 256-byte slave-eeprom
file.

Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
The slave backends have no DT binding (they are debug devices, as
Documentation/i2c/slave-testunit-backend.rst says), so checkpatch reports
the compatibles as undocumented.

This patch was developed with Claude (Anthropic) as a coding assistant:
it investigated the problem, wrote the code and the commit message. I
reviewed it, and it was tested on an Orange Pi Zero2 (H616) as described
above.
---
 drivers/i2c/i2c-slave-eeprom.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/i2c/i2c-slave-eeprom.c b/drivers/i2c/i2c-slave-eeprom.c
index 226d722af662..a08abd895412 100644
--- a/drivers/i2c/i2c-slave-eeprom.c
+++ b/drivers/i2c/i2c-slave-eeprom.c
@@ -20,6 +20,7 @@
 #include <linux/firmware.h>
 #include <linux/i2c.h>
 #include <linux/init.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/slab.h>
@@ -203,9 +204,28 @@ static const struct i2c_device_id i2c_slave_eeprom_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, i2c_slave_eeprom_id);
 
+/*
+ * A backend instantiated from the device tree, with the I2C id as
+ * compatible and I2C_OWN_SLAVE_ADDRESS in reg, announces an of: modalias.
+ * List the same names here so that the module autoloads for it.
+ */
+static const struct of_device_id i2c_slave_eeprom_of_match[] = {
+	{ .compatible = "slave-24c02" },
+	{ .compatible = "slave-24c02ro" },
+	{ .compatible = "slave-24c32" },
+	{ .compatible = "slave-24c32ro" },
+	{ .compatible = "slave-24c64" },
+	{ .compatible = "slave-24c64ro" },
+	{ .compatible = "slave-24c512" },
+	{ .compatible = "slave-24c512ro" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, i2c_slave_eeprom_of_match);
+
 static struct i2c_driver i2c_slave_eeprom_driver = {
 	.driver = {
 		.name = "i2c-slave-eeprom",
+		.of_match_table = i2c_slave_eeprom_of_match,
 	},
 	.probe = i2c_slave_eeprom_probe,
 	.remove = i2c_slave_eeprom_remove,

---
base-commit: 00fb8097ca5a4fcf0e0cc1550075aa7313bbd32a
change-id: 20261110-i2c-slave-eeprom-of-match-ba9fdb67a830

Best regards,
--  
Arun Iyengar <aiyengar1990@gmail.com>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-10 18:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10  5:34 [PATCH] i2c: slave-eeprom: Add an OF match table for module autoload Arun Iyengar via B4 Relay
2026-11-10 18:15 ` Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®