* [PATCH v2 1/2] dt-bindings: i2c: Add the slave EEPROM backend
2026-11-20 4:32 [PATCH v2 0/2] i2c: slave-eeprom: DT binding and OF match table for module autoload Arun Iyengar via B4 Relay
@ 2026-11-20 4:32 ` Arun Iyengar via B4 Relay
2026-12-01 20:38 ` Rob Herring
2026-11-20 4:32 ` [PATCH v2 2/2] i2c: slave-eeprom: Add an OF match table for module autoload Arun Iyengar via B4 Relay
1 sibling, 1 reply; 4+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-20 4:32 UTC (permalink / raw)
To: Andi Shyti, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Wolfram Sang, Uwe Kleine-König, Björn Ardö,
linux-i2c, devicetree, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
A node with one of the i2c-slave-eeprom names as compatible and
I2C_OWN_SLAVE_ADDRESS in reg already binds to the backend, because the
I2C core names the client after the compatible and matches the I2C id.
The driver also reads firmware-name. None of this is documented.
Document the names without a vendor prefix, as the driver and
Documentation/i2c spell them (ipmb-dev and mctp-i2c-controller are
unprefixed too).
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
.../devicetree/bindings/i2c/slave-eeprom.yaml | 59 ++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/Documentation/devicetree/bindings/i2c/slave-eeprom.yaml b/Documentation/devicetree/bindings/i2c/slave-eeprom.yaml
new file mode 100644
index 000000000000..b7a6e6653a64
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/slave-eeprom.yaml
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i2c/slave-eeprom.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: I2C target EEPROM backend
+
+maintainers:
+ - Arun Iyengar <aiyengar1990@gmail.com>
+
+description:
+ The I2C controller answers on its own address as a target and behaves
+ like a 24Cxx EEPROM towards the other controllers on the bus. The
+ compatible selects the EEPROM type that is simulated. The "ro" variants
+ ignore writes from the bus.
+
+properties:
+ compatible:
+ enum:
+ - slave-24c02
+ - slave-24c02ro
+ - slave-24c32
+ - slave-24c32ro
+ - slave-24c64
+ - slave-24c64ro
+ - slave-24c512
+ - slave-24c512ro
+
+ reg:
+ maxItems: 1
+ description:
+ Own address of the controller on the bus. The I2C_OWN_SLAVE_ADDRESS
+ flag must be set.
+
+ firmware-name:
+ maxItems: 1
+ description:
+ File with the initial content. Without it all bytes start as 0xff.
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/i2c/i2c.h>
+
+ i2c {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ eeprom@64 {
+ compatible = "slave-24c02";
+ reg = <(0x64 | I2C_OWN_SLAVE_ADDRESS)>;
+ };
+ };
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/2] i2c: slave-eeprom: Add an OF match table for module autoload
2026-11-20 4:32 [PATCH v2 0/2] i2c: slave-eeprom: DT binding and OF match table for module autoload Arun Iyengar via B4 Relay
2026-11-20 4:32 ` [PATCH v2 1/2] dt-bindings: i2c: Add the slave EEPROM backend Arun Iyengar via B4 Relay
@ 2026-11-20 4:32 ` Arun Iyengar via B4 Relay
1 sibling, 0 replies; 4+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-20 4:32 UTC (permalink / raw)
To: Andi Shyti, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: Wolfram Sang, Uwe Kleine-König, Björn Ardö,
linux-i2c, devicetree, 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. Nodes that bind today keep binding
with the same size and flags.
With an OF table the driver also matches a node that lists one of these
names as a fallback compatible. Such a client is named after its first
compatible and has no i2c id, so give the OF entries the same data as
the i2c ids and read it with i2c_get_match_data().
Tested on an Orange Pi Zero2 (H616) with a local target-mode patch for
i2c-mv64xxx: a slave-24c02 overlay node autoloads the module and binds
with a 256-byte file; a node with slave-24c02 as fallback compatible
binds too (v1 oopsed there); new_device slave-24c32 still gives 4096
bytes.
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/i2c/i2c-slave-eeprom.c | 34 ++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/i2c-slave-eeprom.c b/drivers/i2c/i2c-slave-eeprom.c
index 226d722af662..0af48a9085b4 100644
--- a/drivers/i2c/i2c-slave-eeprom.c
+++ b/drivers/i2c/i2c-slave-eeprom.c
@@ -142,11 +142,11 @@ static int i2c_slave_init_eeprom_data(struct eeprom_data *eeprom, struct i2c_cli
static int i2c_slave_eeprom_probe(struct i2c_client *client)
{
- const struct i2c_device_id *id = i2c_client_get_device_id(client);
+ unsigned long data = (unsigned long)i2c_get_match_data(client);
struct eeprom_data *eeprom;
int ret;
- unsigned int size = FIELD_GET(I2C_SLAVE_BYTELEN, id->driver_data) + 1;
- unsigned int flag_addr16 = FIELD_GET(I2C_SLAVE_FLAG_ADDR16, id->driver_data);
+ unsigned int size = FIELD_GET(I2C_SLAVE_BYTELEN, data) + 1;
+ unsigned int flag_addr16 = FIELD_GET(I2C_SLAVE_FLAG_ADDR16, data);
eeprom = devm_kzalloc(&client->dev, sizeof(struct eeprom_data) + size, GFP_KERNEL);
if (!eeprom)
@@ -154,7 +154,7 @@ static int i2c_slave_eeprom_probe(struct i2c_client *client)
eeprom->num_address_bytes = flag_addr16 ? 2 : 1;
eeprom->address_mask = size - 1;
- eeprom->read_only = FIELD_GET(I2C_SLAVE_FLAG_RO, id->driver_data);
+ eeprom->read_only = FIELD_GET(I2C_SLAVE_FLAG_RO, data);
spin_lock_init(&eeprom->buffer_lock);
i2c_set_clientdata(client, eeprom);
@@ -203,9 +203,35 @@ static const struct i2c_device_id i2c_slave_eeprom_id[] = {
};
MODULE_DEVICE_TABLE(i2c, i2c_slave_eeprom_id);
+/* Same data as the I2C ids, for clients matched by a fallback compatible */
+#define I2C_SLAVE_OF_DATA(_len, _flags) \
+ ((void *)(unsigned long)I2C_SLAVE_DEVICE_MAGIC(_len, _flags))
+
+static const struct of_device_id i2c_slave_eeprom_of_match[] = {
+ { .compatible = "slave-24c02",
+ .data = I2C_SLAVE_OF_DATA(2048 / 8, 0) },
+ { .compatible = "slave-24c02ro",
+ .data = I2C_SLAVE_OF_DATA(2048 / 8, I2C_SLAVE_FLAG_RO) },
+ { .compatible = "slave-24c32",
+ .data = I2C_SLAVE_OF_DATA(32768 / 8, I2C_SLAVE_FLAG_ADDR16) },
+ { .compatible = "slave-24c32ro",
+ .data = I2C_SLAVE_OF_DATA(32768 / 8, I2C_SLAVE_FLAG_ADDR16 | I2C_SLAVE_FLAG_RO) },
+ { .compatible = "slave-24c64",
+ .data = I2C_SLAVE_OF_DATA(65536 / 8, I2C_SLAVE_FLAG_ADDR16) },
+ { .compatible = "slave-24c64ro",
+ .data = I2C_SLAVE_OF_DATA(65536 / 8, I2C_SLAVE_FLAG_ADDR16 | I2C_SLAVE_FLAG_RO) },
+ { .compatible = "slave-24c512",
+ .data = I2C_SLAVE_OF_DATA(524288 / 8, I2C_SLAVE_FLAG_ADDR16) },
+ { .compatible = "slave-24c512ro",
+ .data = I2C_SLAVE_OF_DATA(524288 / 8, I2C_SLAVE_FLAG_ADDR16 | I2C_SLAVE_FLAG_RO) },
+ { }
+};
+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,
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread