Skip to contentSkip to conversation

Add support for STMicroelectronics M24LR EEPROM/NFC chips

PATCH Superseded Abd-Alrhman Masalkhi 3 participants 11 messages Jul 4, 2025

Subsystems (2)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover Add support for STMicroelectronics M24LR EEPROM/NFC chips

This patch series adds support for the STMicroelectronics M24LR series RFID/NFC EEPROM devices. These chips expose two I2C addresses: the primary one provides access to system control and configuration registers, while the secondary address is used for EEPROM access.

The driver implements both functionalities:
- A sysfs-based interface for the control and system parameter registers.
- EEPROM access via the nvmem subsystem using a secondary I2C dummy client.

Tested on: M24LR04E-R using Yocto on Raspberry Pi 4

Abd-Alrhman Masalkhi (3):
dt-bindings: eeprom: Add ST M24LR support
eeprom: add driver for ST M24LR series RFID/NFC EEPROM chips
ABI: sysfs: add documentation for ST M24LR EEPROM and control
interface

 .../ABI/testing/sysfs-bus-i2c-devices-m24lr   | 100 +++
 .../devicetree/bindings/eeprom/st,m24lr.yaml  |  52 ++
 drivers/misc/eeprom/Kconfig                   |  18 +
 drivers/misc/eeprom/Makefile                  |   1 +
 drivers/misc/eeprom/m24lr.c                   | 653 ++++++++++++++++++
 5 files changed, 824 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-i2c-devices-m24lr
 create mode 100644 Documentation/devicetree/bindings/eeprom/st,m24lr.yaml
 create mode 100644 drivers/misc/eeprom/m24lr.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v5 1/3 dt-bindings: eeprom: Add ST M24LR support

Add support for STMicroelectronics M24LR RFID/NFC EEPROM chips. These devices use two I2C addresses: the primary address provides access to control and system parameter registers, while the secondary address is used for EEPROM access.

---
Changes in v5:
- No changes and already reviewed by Krzysztof Kozlowski
- Link to v4: https://lore.kernel.org/lkml/[email protected]/

Changes in v4:
- Moved the binding file to the eeprom/ directory
- Updated reg property to use items: with per-address descriptions
instead of minItems/maxItems
- Link to v3: https://lore.kernel.org/lkml/[email protected]/

Changes in v3:
- Dropped reference to the i2c-mux binding.
- Added reference to the nvmem binding to reflect EEPROM usage.
- Updated 'reg' property to represent the device using two I2C addresses.
- Fixed DT schema errors and yamllint warnings.
- Removed the unused 'pagesize' property.
- Link to v2: https://lore.kernel.org/lkml/[email protected]/

Changes in v2:
- Moved file from misc/ to eeprom/.
- Updated $id and $ref paths.
- Reformatted maintainers field.
- Clarified description text.
- Added enum and default to pagesize.
- Replaced additionalProperties with unevaluatedProperties.
- Revised example to use explicit i2c mux layout.
- Fixed style and formatting issues.
- Link to v1: https://lore.kernel.org/lkml/[email protected]/

---
 .../devicetree/bindings/eeprom/st,m24lr.yaml  | 52 +++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/eeprom/st,m24lr.yaml
Documentation/devicetree/bindings/eeprom/st,m24lr.yaml new file +52 -0
new file mode 100644
index 000000000000..0a0820e9d11f
@@ -0,0 +1,52 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/eeprom/st,m24lr.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: STMicroelectronics M24LR NFC/RFID EEPROM
+
+maintainers:
+  - Abd-Alrhman Masalkhi <[email protected]>
+
+description:
+  STMicroelectronics M24LR series are dual-interface (RF + I2C)
+  EEPROM chips. These devices support I2C-based access to both
+  memory and a system area that controls authentication and configuration.
+  They expose two I2C addresses, one for the system parameter sector and
+  one for the EEPROM.
+
+allOf:
+  - $ref: /schemas/nvmem/nvmem.yaml#
+
+properties:
+  compatible:
+    enum:
+      - st,m24lr04e-r
+      - st,m24lr16e-r
+      - st,m24lr64e-r
+
+  reg:
+    items:
+      - description: I2C address used for control/system registers
+      - description: I2C address used for EEPROM memory access
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      eeprom@57 {
+        compatible = "st,m24lr04e-r";
+        reg = <0x57>, /* primary-device */
+              <0x53>; /* secondary-device */
+      };
+    };
+...
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v5 1/3] dt-bindings: eeprom: Add ST M24LR support

Quoted 10 lines · Abd-Alrhman Masalkhi

Add support for STMicroelectronics M24LR RFID/NFC EEPROM chips. These devices use two I2C addresses: the primary address provides access to control and system parameter registers, while the secondary address is used for EEPROM access.

---
Changes in v5:
- No changes and already reviewed by Krzysztof Kozlowski
- Link to v4: https://lore.kernel.org/lkml/[email protected]/

So you just ignore the tag?

<form letter>
This is a friendly reminder during the review process.

It looks like you received a tag and forgot to add it.

If you do not know the process, here is a short explanation:
Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions of patchset, under or above your Signed-off-by tag, unless patch changed significantly (e.g. new properties added to the DT bindings). Tag is "received", when provided in a message replied to you on the mailing list. Tools like b4 can help here. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for tags received on the version they apply.

Please read:
https://elixir.bootlin.com/linux/v6.12-rc3/source/Documentation/process/submitting-patches.rst#L577

If a tag was not added on purpose, please state why and what changed. </form letter>

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v5 1/3] dt-bindings: eeprom: Add ST M24LR support

Quoted 28 lines · Krzysztof Kozlowski
Quoted 10 lines · Abd-Alrhman Masalkhi

Add support for STMicroelectronics M24LR RFID/NFC EEPROM chips. These devices use two I2C addresses: the primary address provides access to control and system parameter registers, while the secondary address is used for EEPROM access.

---
Changes in v5:
- No changes and already reviewed by Krzysztof Kozlowski
- Link to v4: https://lore.kernel.org/lkml/[email protected]/

So you just ignore the tag?

<form letter>
This is a friendly reminder during the review process.

It looks like you received a tag and forgot to add it.

If you do not know the process, here is a short explanation:
Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions of patchset, under or above your Signed-off-by tag, unless patch changed significantly (e.g. new properties added to the DT bindings). Tag is "received", when provided in a message replied to you on the mailing list. Tools like b4 can help here. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for tags received on the version they apply.

Quoted 5 lines

Please read:
https://elixir.bootlin.com/linux/v6.12-rc3/source/Documentation/process/submitting-patches.rst#L577

If a tag was not added on purpose, please state why and what changed. </form letter>

Hi Krzysztof,

Thank you for the clear explanation. I wasn't aware of the process, I will make sure to include the tags properly in future versions.

Best regards,
Abd-Alrhman Masalkhi

#4 lore raw

PATCH v5 2/3 eeprom: add driver for ST M24LR series RFID/NFC EEPROM chips

In reply to Abd-Alrhman Masalkhi

adds support for STMicroelectronics M24LRxx devices, which expose two separate I2C addresses: one for system control and one for EEPROM access. The driver implements both a sysfs-based interface for control registers (e.g. UID, password authentication) and an nvmem provider for EEPROM access.

---
Changes in v5:
- Fixed function signatures in m24lr_ctl_sss_read and m24lr_ctl_sss_write
to use const struct bin_attribute *attr
- Link to v4: https://lore.kernel.org/lkml/[email protected]/

Changes in v4:
- Moved the source file to the eeprom/ directory
- Removed use of unlikely() macro
- Removed use of EIO as a fallback error
- Stopped dynamically creating sysfs attributes
- Replaced per-sector SSS attributes with a single bin_attribute
for all SSS
- Introduced total_sectors sysfs attribute to report the number
of valid sectors
- Avoided sharing a single show/store callback across multiple
attribute types
- Link to v3: https://lore.kernel.org/lkml/[email protected]/

Changes in v3:
- Fully support the M24LR chips, including EEPROM access, no need for
the standard at24 driver to handle EEPROM separately.
- Rename the driver file from m24lr_ctl.c to m24lr.c.
- Rename all identifiers from the m24lr_ctl prefix to m24lr.
- Retain the m24lr_ctl prefix for control-related routines to distinguish them from EEPROM-related logic.
- Drop usage of the I2C mux API.
- Use the NVMEM subsystem to handle EEPROM access.
- Add REGMAP support for EEPROM register access.
- Update Kconfig entry to reflect that the driver now supports both
control and EEPROM functionality.
- Link to v2: https://lore.kernel.org/lkml/[email protected]/

Changes in v2:
- Fix compiling Errors and Warnings
- Replace scnprintf with sysfs_emit
- Drop success log message from probe.
- Link to v1: https://lore.kernel.org/lkml/[email protected]/

Comment:
- Running checkpatch emit a warning for non-const regmap_config. The variable must remain auto and mutable due to runtime manipulation.

---
 drivers/misc/eeprom/Kconfig  |  18 +
 drivers/misc/eeprom/Makefile |   1 +
 drivers/misc/eeprom/m24lr.c  | 653 +++++++++++++++++++++++++++++++++++
 3 files changed, 672 insertions(+)
 create mode 100644 drivers/misc/eeprom/m24lr.c
drivers/misc/eeprom/Kconfig +18 -0
index cb1c4b8e7fd3..cb0ce243babd 100644
@@ -119,4 +119,22 @@ config EEPROM_EE1004
 	  This driver can also be built as a module.  If so, the module
 	  will be called ee1004.
 
+config EEPROM_M24LR
+	tristate "STMicroelectronics M24LR RFID/NFC EEPROM support"
+	depends on I2C && SYSFS
+	select REGMAP_I2C
+	select NVMEM
+	select NVMEM_SYSFS
+	help
+	  This enables support for STMicroelectronics M24LR RFID/NFC EEPROM
+	  chips. These dual-interface devices expose two I2C addresses:
+	  one for EEPROM memory access and another for control and system
+	  configuration (e.g. UID, password handling).
+
+	  This driver provides a sysfs interface for control functions and
+	  integrates with the nvmem subsystem for EEPROM access.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called m24lr.
+
 endmenu
drivers/misc/eeprom/Makefile +1 -0
index 65794e526d5d..8f311fd6a4ce 100644
@@ -7,3 +7,4 @@ obj-$(CONFIG_EEPROM_93XX46)	+= eeprom_93xx46.o
 obj-$(CONFIG_EEPROM_DIGSY_MTC_CFG) += digsy_mtc_eeprom.o
 obj-$(CONFIG_EEPROM_IDT_89HPESX) += idt_89hpesx.o
 obj-$(CONFIG_EEPROM_EE1004)	+= ee1004.o
+obj-$(CONFIG_EEPROM_M24LR) += m24lr.o
drivers/misc/eeprom/m24lr.c new file +653 -0

653 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v5 2/3] eeprom: add driver for ST M24LR series RFID/NFC EEPROM chips

Le 04/07/2025 à 14:39, Abd-Alrhman Masalkhi a écrit :

Quoted 5 lines

adds support for STMicroelectronics M24LRxx devices, which expose two separate I2C addresses: one for system control and one for EEPROM access. The driver implements both a sysfs-based interface for control registers (e.g. UID, password authentication) and an nvmem provider for EEPROM access.

Hi, some nitpicks below, mostly related to types.

...

drivers/misc/eeprom/m24lr.c line 20

Quoted 7 lines
drivers/misc/eeprom/m24lr.c new file +7 -0
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/nvmem-provider.h>

Sometimes, alphabetical order is preferred.

Quoted 3 lines
drivers/misc/eeprom/m24lr.c new file +3 -0
+
+#define M24LR_WRITE_TIMEOUT	  25u
+#define M24LR_READ_TIMEOUT	  (M24LR_WRITE_TIMEOUT)

...

Quoted 8 lines
drivers/misc/eeprom/m24lr.c new file +8 -0
+/**
+ * m24lr_regmap_read - read data using regmap with retry on failure
+ * @regmap:  regmap instance for the device
+ * @buf:     buffer to store the read data
+ * @size:    number of bytes to read
+ * @offset:  starting register address
+ *
+ * Attempts to read a block of data from the device with retries and timeout.

drivers/misc/eeprom/m24lr.c line 195

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+ * Some M24LR chips may transiently NACK reads (e.g., during internal write
+ * cycles), so this function retries with a short sleep until the timeout
+ * expires.
+ *
+ * Returns:
+ *	 Number of bytes read on success,
+ *	 -ETIMEDOUT if the read fails within the timeout window.
+ */
+static ssize_t m24lr_regmap_read(struct regmap *regmap, u8 *buf,
+				 size_t size, unsigned int offset)

Why returning a ssize_t?
regmap_bulk_read() returns an int.

Quoted 20 lines
drivers/misc/eeprom/m24lr.c new file +20 -0
+{
+	int err;
+	unsigned long timeout, read_time;
+	ssize_t ret = -ETIMEDOUT;
+
+	timeout = jiffies + msecs_to_jiffies(M24LR_READ_TIMEOUT);
+	do {
+		read_time = jiffies;
+
+		err = regmap_bulk_read(regmap, offset, buf, size);
+		if (!err) {
+			ret = size;
+			break;
+		}
+
+		usleep_range(1000, 2000);
+	} while (time_before(read_time, timeout));
+
+	return ret;
+}

...

drivers/misc/eeprom/m24lr.c line 261

Quoted 5 lines
drivers/misc/eeprom/m24lr.c new file +5 -0
+static ssize_t m24lr_read(struct m24lr *m24lr, u8 *buf, size_t size,
+			  unsigned int offset, bool is_eeprom)
+{
+	struct regmap *regmap;
+	long ret;

Why long?
m24lr_regmap_read() returns a ssize_t. (+ see comment there for why a ssize_t)

(same comment applies to several places)

Quoted 35 lines
drivers/misc/eeprom/m24lr.c new file +35 -0
+
+	if (is_eeprom)
+		regmap = m24lr->eeprom_regmap;
+	else
+		regmap = m24lr->ctl_regmap;
+
+	mutex_lock(&m24lr->lock);
+	ret = m24lr_regmap_read(regmap, buf, size, offset);
+	mutex_unlock(&m24lr->lock);
+
+	return ret;
+}
+
+/**
+ * m24lr_write - write buffer to M24LR device with page alignment handling
+ * @m24lr:     pointer to driver context
+ * @buf:       data buffer to write
+ * @size:      number of bytes to write
+ * @offset:    target register address in the device
+ * @is_eeprom: true if the write should target the EEPROM,
+ *             false if it should target the system parameters sector.
+ *
+ * Writes data to the M24LR device using regmap, split into chunks no larger
+ * than page_size to respect device-specific write limitations (e.g., page
+ * size or I2C hold-time concerns). Each chunk is aligned to the page boundary
+ * defined by page_size.
+ *
+ * Returns:
+ *	 Total number of bytes written on success,
+ *	 A negative error code if any write fails.
+ */
+static ssize_t m24lr_write(struct m24lr *m24lr, const u8 *buf, size_t size,
+			   unsigned int offset, bool is_eeprom)
+{
+	unsigned int n, next_sector;

drivers/misc/eeprom/m24lr.c line 306

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+	struct regmap *regmap;
+	ssize_t ret = 0;
+	long err;
+
+	if (is_eeprom)
+		regmap = m24lr->eeprom_regmap;
+	else
+		regmap = m24lr->ctl_regmap;
+
+	n = min(size, m24lr->page_size);

min_t()?

drivers/misc/eeprom/m24lr.c line 318

Quoted 12 lines
drivers/misc/eeprom/m24lr.c new file +12 -0
+	next_sector = roundup(offset + 1, m24lr->page_size);
+	if (offset + n > next_sector)
+		n = next_sector - offset;
+
+	mutex_lock(&m24lr->lock);
+	while (n) {
+		err = m24lr_regmap_write(regmap, buf, n, offset);
+		if (IS_ERR_VALUE(err)) {
+			mutex_unlock(&m24lr->lock);
+			if (ret)
+				return ret;
+			else

Unneeded else.

drivers/misc/eeprom/m24lr.c line 325

Quoted 7 lines
drivers/misc/eeprom/m24lr.c new file +7 -0
+				return err;
+		}
+
+		offset += n;
+		size -= n;
+		ret += n;
+		n = min(size, m24lr->page_size);

min_t()?
Or change the type of page_size?

Quoted 19 lines
drivers/misc/eeprom/m24lr.c new file +19 -0
+	}
+	mutex_unlock(&m24lr->lock);
+
+	return ret;
+}
+
+/**
+ * m24lr_write_pass - Write password to M24LR043-R using secure format
+ * @m24lr: Pointer to device control structure
+ * @buf:   Input buffer containing hex-encoded password
+ * @count: Number of bytes in @buf
+ * @code:  Operation code to embed between password copies
+ *
+ * This function parses a 4-byte password, encodes it in  big-endian format,
+ * and constructs a 9-byte sequence of the form:
+ *
+ *	  [BE(password), code, BE(password)]
+ *
+ * The result is written to register 0x0900 (2304), which is the password

drivers/misc/eeprom/m24lr.c line 354

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+ * register in M24LR04E-R chip.
+ *
+ * Return: Number of bytes written on success, or negative error code on failure
+ */
+static ssize_t m24lr_write_pass(struct m24lr *m24lr, const char *buf,
+				size_t count, u8 code)
+{
+	__be32 be_pass;
+	u8 output[9];
+	long ret;

long vs ssize_t vs int.

Quoted 21 lines
drivers/misc/eeprom/m24lr.c new file +21 -0
+	u32 pass;
+	int err;
+
+	if (!count)
+		return -EINVAL;
+
+	if (count > 8)
+		return -EINVAL;
+
+	err = kstrtou32(buf, 16, &pass);
+	if (err)
+		return err;
+
+	be_pass = cpu_to_be32(pass);
+
+	memcpy(output, &be_pass, sizeof(be_pass));
+	output[4] = code;
+	memcpy(output + 5, &be_pass, sizeof(be_pass));
+
+	mutex_lock(&m24lr->lock);
+	ret = m24lr_regmap_write(m24lr->ctl_regmap, output, 9, 2304);

drivers/misc/eeprom/m24lr.c line 385

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+	mutex_unlock(&m24lr->lock);
+
+	return ret;
+}
+
+static ssize_t m24lr_read_reg_le(struct m24lr *m24lr, u64 *val,
+				 unsigned int reg_addr,
+				 unsigned int reg_size)
+{
+	long ret;

same

Quoted 31 lines
drivers/misc/eeprom/m24lr.c new file +31 -0
+	__le64 input = 0;
+
+	ret = m24lr_read(m24lr, (u8 *)&input, reg_size, reg_addr, false);
+	if (IS_ERR_VALUE(ret))
+		return ret;
+
+	if (ret != reg_size)
+		return -EINVAL;
+
+	switch (reg_size) {
+	case 1:
+		*val = *(u8 *)&input;
+		break;
+	case 2:
+		*val = le16_to_cpu((__le16)input);
+		break;
+	case 4:
+		*val = le32_to_cpu((__le32)input);
+		break;
+	case 8:
+		*val = le64_to_cpu((__le64)input);
+		break;
+	default:
+		return -EINVAL;
+	};
+
+	return 0;
+}
+
+static int m24lr_nvmem_read(void *priv, unsigned int offset, void *val,
+			    size_t bytes)

drivers/misc/eeprom/m24lr.c line 426

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+{
+	struct m24lr *m24lr = priv;
+
+	if (!bytes)
+		return bytes;
+
+	if (offset + bytes > m24lr->eeprom_size)
+		return -EINVAL;
+
+	return m24lr_read(m24lr, val, bytes, offset, true);

We return an int now?

Quoted 1 line

+}

...

drivers/misc/eeprom/m24lr.c line 452

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+static ssize_t m24lr_ctl_sss_read(struct file *filep, struct kobject *kobj,
+				  const struct bin_attribute *attr, char *buf,
+				  loff_t offset, size_t count)
+{
+	struct m24lr *m24lr = attr->private;
+
+	if (!count)
+		return count;
+
+	if (offset + count > m24lr->sss_len)

Does using size_add() would make sense?

Quoted 5 lines
drivers/misc/eeprom/m24lr.c new file +5 -0
+		return -EINVAL;
+
+	return m24lr_read(m24lr, buf, count, offset, false);
+}
+

drivers/misc/eeprom/m24lr.c line 467

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+static ssize_t m24lr_ctl_sss_write(struct file *filep, struct kobject *kobj,
+				   const struct bin_attribute *attr, char *buf,
+				   loff_t offset, size_t count)
+{
+	struct m24lr *m24lr = attr->private;
+
+	if (!count)
+		return -EINVAL;
+
+	if (offset + count > m24lr->sss_len)

Same

Quoted 5 lines
drivers/misc/eeprom/m24lr.c new file +5 -0
+		return -EINVAL;
+
+	return m24lr_write(m24lr, buf, count, offset, false);
+}
+static BIN_ATTR(sss, 0600, m24lr_ctl_sss_read, m24lr_ctl_sss_write, 0);

...

drivers/misc/eeprom/m24lr.c line 515

Quoted 6 lines
drivers/misc/eeprom/m24lr.c new file +6 -0
+static struct attribute *m24lr_ctl_dev_attrs[] = {
+	&dev_attr_unlock.attr,
+	&dev_attr_new_pass.attr,
+	&dev_attr_uid.attr,
+	&dev_attr_total_sectors.attr,
+	NULL,

Unneeded trailing ,

Quoted 1 line

+};

...

Quoted 18 lines
drivers/misc/eeprom/m24lr.c new file +18 -0
+static int m24lr_probe(struct i2c_client *client)
+{
+	struct regmap_config eeprom_regmap_conf = {0};
+	struct nvmem_config nvmem_conf = {0};
+	struct device *dev = &client->dev;
+	struct i2c_client *eeprom_client;
+	const struct m24lr_chip *chip;
+	struct regmap *eeprom_regmap;
+	struct nvmem_device *nvmem;
+	struct regmap *ctl_regmap;
+	struct m24lr *m24lr;
+	u32 regs[2];
+	long err;
+
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+		return -EOPNOTSUPP;
+
+	chip = m24lr_get_chip(dev);

drivers/misc/eeprom/m24lr.c line 562

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+	if (!chip)
+		return -ENODEV;
+
+	m24lr = devm_kzalloc(dev, sizeof(struct m24lr), GFP_KERNEL);
+	if (!m24lr)
+		return -ENOMEM;
+
+	err = device_property_read_u32_array(dev, "reg", regs, ARRAY_SIZE(regs));
+	if (err) {
+		dev_err(dev, "device_property_read_u32_array\n");

return dev_err_probe() maybe?

drivers/misc/eeprom/m24lr.c line 569

Quoted 7 lines
drivers/misc/eeprom/m24lr.c new file +7 -0
+		return err;
+	}
+	/* Create a second I2C client for the eeprom interface */
+	eeprom_client = devm_i2c_new_dummy_device(dev, client->adapter, regs[1]);
+	if (IS_ERR(eeprom_client)) {
+		dev_err(dev,
+			"Failed to create dummy I2C client for the EEPROM\n");

return dev_err_probe() maybe?
...

Quoted 47 lines
drivers/misc/eeprom/m24lr.c new file +47 -0
+		return PTR_ERR(eeprom_client);
+	}
+
+	ctl_regmap = devm_regmap_init_i2c(client, &m24lr_ctl_regmap_conf);
+	if (IS_ERR(ctl_regmap)) {
+		err = PTR_ERR(ctl_regmap);
+		dev_err(dev, "Failed to init regmap\n");
+		return err;
+	}
+
+	eeprom_regmap_conf.name = "m24lr_eeprom";
+	eeprom_regmap_conf.reg_bits = 16;
+	eeprom_regmap_conf.val_bits = 8;
+	eeprom_regmap_conf.disable_locking = true;
+	eeprom_regmap_conf.max_register = chip->eeprom_size - 1;
+
+	eeprom_regmap = devm_regmap_init_i2c(eeprom_client,
+					     &eeprom_regmap_conf);
+	if (IS_ERR(eeprom_regmap)) {
+		err = PTR_ERR(eeprom_regmap);
+		dev_err(dev, "Failed to init regmap\n");
+		return err;
+	}
+
+	mutex_init(&m24lr->lock);
+	m24lr->sss_len = chip->sss_len;
+	m24lr->page_size = chip->page_size;
+	m24lr->eeprom_size = chip->eeprom_size;
+	m24lr->eeprom_regmap = eeprom_regmap;
+	m24lr->ctl_regmap = ctl_regmap;
+
+	nvmem_conf.dev = &eeprom_client->dev;
+	nvmem_conf.owner = THIS_MODULE;
+	nvmem_conf.type = NVMEM_TYPE_EEPROM;
+	nvmem_conf.reg_read = m24lr_nvmem_read;
+	nvmem_conf.reg_write = m24lr_nvmem_write;
+	nvmem_conf.size = chip->eeprom_size;
+	nvmem_conf.word_size = 1;
+	nvmem_conf.stride = 1;
+	nvmem_conf.priv = m24lr;
+
+	nvmem = devm_nvmem_register(dev, &nvmem_conf);
+	if (IS_ERR(nvmem))
+		return PTR_ERR(nvmem);
+
+	i2c_set_clientdata(client, m24lr);
+	i2c_set_clientdata(eeprom_client, m24lr);

drivers/misc/eeprom/m24lr.c line 626

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+
+	bin_attr_sss.size = chip->sss_len;
+	bin_attr_sss.private = m24lr;
+	err = sysfs_create_bin_file(&dev->kobj, &bin_attr_sss);
+	if (err)
+		return err;
+
+	/* test by reading the uid, if success store it */
+	err = m24lr_read_reg_le(m24lr, &m24lr->uid, 2324, sizeof(m24lr->uid));
+	if (IS_ERR_VALUE(err))

Missing sysfs_remove_bin_file() or error handling pah?

drivers/misc/eeprom/m24lr.c line 630

Quoted 4 lines
drivers/misc/eeprom/m24lr.c new file +4 -0
+		return -ENODEV;
+
+	return 0;
+}

...

CJ

#6 lore raw

Re: [PATCH v5 2/3] eeprom: add driver for ST M24LR series RFID/NFC EEPROM chips

Quoted 418 lines · Christophe JAILLET

Hi, some nitpicks below, mostly related to types.

...

drivers/misc/eeprom/m24lr.c line 20

Quoted 7 lines
drivers/misc/eeprom/m24lr.c new file +7 -0
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/nvmem-provider.h>

Sometimes, alphabetical order is preferred.

Quoted 3 lines
drivers/misc/eeprom/m24lr.c new file +3 -0
+
+#define M24LR_WRITE_TIMEOUT	  25u
+#define M24LR_READ_TIMEOUT	  (M24LR_WRITE_TIMEOUT)

...

Quoted 8 lines
drivers/misc/eeprom/m24lr.c new file +8 -0
+/**
+ * m24lr_regmap_read - read data using regmap with retry on failure
+ * @regmap:  regmap instance for the device
+ * @buf:     buffer to store the read data
+ * @size:    number of bytes to read
+ * @offset:  starting register address
+ *
+ * Attempts to read a block of data from the device with retries and timeout.

drivers/misc/eeprom/m24lr.c line 195

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+ * Some M24LR chips may transiently NACK reads (e.g., during internal write
+ * cycles), so this function retries with a short sleep until the timeout
+ * expires.
+ *
+ * Returns:
+ *	 Number of bytes read on success,
+ *	 -ETIMEDOUT if the read fails within the timeout window.
+ */
+static ssize_t m24lr_regmap_read(struct regmap *regmap, u8 *buf,
+				 size_t size, unsigned int offset)

Why returning a ssize_t?
regmap_bulk_read() returns an int.

Quoted 20 lines
drivers/misc/eeprom/m24lr.c new file +20 -0
+{
+	int err;
+	unsigned long timeout, read_time;
+	ssize_t ret = -ETIMEDOUT;
+
+	timeout = jiffies + msecs_to_jiffies(M24LR_READ_TIMEOUT);
+	do {
+		read_time = jiffies;
+
+		err = regmap_bulk_read(regmap, offset, buf, size);
+		if (!err) {
+			ret = size;
+			break;
+		}
+
+		usleep_range(1000, 2000);
+	} while (time_before(read_time, timeout));
+
+	return ret;
+}

...

drivers/misc/eeprom/m24lr.c line 261

Quoted 5 lines
drivers/misc/eeprom/m24lr.c new file +5 -0
+static ssize_t m24lr_read(struct m24lr *m24lr, u8 *buf, size_t size,
+			  unsigned int offset, bool is_eeprom)
+{
+	struct regmap *regmap;
+	long ret;

Why long?
m24lr_regmap_read() returns a ssize_t. (+ see comment there for why a ssize_t)

(same comment applies to several places)

Quoted 35 lines
drivers/misc/eeprom/m24lr.c new file +35 -0
+
+	if (is_eeprom)
+		regmap = m24lr->eeprom_regmap;
+	else
+		regmap = m24lr->ctl_regmap;
+
+	mutex_lock(&m24lr->lock);
+	ret = m24lr_regmap_read(regmap, buf, size, offset);
+	mutex_unlock(&m24lr->lock);
+
+	return ret;
+}
+
+/**
+ * m24lr_write - write buffer to M24LR device with page alignment handling
+ * @m24lr:     pointer to driver context
+ * @buf:       data buffer to write
+ * @size:      number of bytes to write
+ * @offset:    target register address in the device
+ * @is_eeprom: true if the write should target the EEPROM,
+ *             false if it should target the system parameters sector.
+ *
+ * Writes data to the M24LR device using regmap, split into chunks no larger
+ * than page_size to respect device-specific write limitations (e.g., page
+ * size or I2C hold-time concerns). Each chunk is aligned to the page boundary
+ * defined by page_size.
+ *
+ * Returns:
+ *	 Total number of bytes written on success,
+ *	 A negative error code if any write fails.
+ */
+static ssize_t m24lr_write(struct m24lr *m24lr, const u8 *buf, size_t size,
+			   unsigned int offset, bool is_eeprom)
+{
+	unsigned int n, next_sector;

drivers/misc/eeprom/m24lr.c line 306

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+	struct regmap *regmap;
+	ssize_t ret = 0;
+	long err;
+
+	if (is_eeprom)
+		regmap = m24lr->eeprom_regmap;
+	else
+		regmap = m24lr->ctl_regmap;
+
+	n = min(size, m24lr->page_size);

min_t()?

drivers/misc/eeprom/m24lr.c line 318

Quoted 12 lines
drivers/misc/eeprom/m24lr.c new file +12 -0
+	next_sector = roundup(offset + 1, m24lr->page_size);
+	if (offset + n > next_sector)
+		n = next_sector - offset;
+
+	mutex_lock(&m24lr->lock);
+	while (n) {
+		err = m24lr_regmap_write(regmap, buf, n, offset);
+		if (IS_ERR_VALUE(err)) {
+			mutex_unlock(&m24lr->lock);
+			if (ret)
+				return ret;
+			else

Unneeded else.

drivers/misc/eeprom/m24lr.c line 325

Quoted 7 lines
drivers/misc/eeprom/m24lr.c new file +7 -0
+				return err;
+		}
+
+		offset += n;
+		size -= n;
+		ret += n;
+		n = min(size, m24lr->page_size);

min_t()?
Or change the type of page_size?

Quoted 19 lines
drivers/misc/eeprom/m24lr.c new file +19 -0
+	}
+	mutex_unlock(&m24lr->lock);
+
+	return ret;
+}
+
+/**
+ * m24lr_write_pass - Write password to M24LR043-R using secure format
+ * @m24lr: Pointer to device control structure
+ * @buf:   Input buffer containing hex-encoded password
+ * @count: Number of bytes in @buf
+ * @code:  Operation code to embed between password copies
+ *
+ * This function parses a 4-byte password, encodes it in  big-endian format,
+ * and constructs a 9-byte sequence of the form:
+ *
+ *	  [BE(password), code, BE(password)]
+ *
+ * The result is written to register 0x0900 (2304), which is the password

drivers/misc/eeprom/m24lr.c line 354

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+ * register in M24LR04E-R chip.
+ *
+ * Return: Number of bytes written on success, or negative error code on failure
+ */
+static ssize_t m24lr_write_pass(struct m24lr *m24lr, const char *buf,
+				size_t count, u8 code)
+{
+	__be32 be_pass;
+	u8 output[9];
+	long ret;

long vs ssize_t vs int.

Quoted 21 lines
drivers/misc/eeprom/m24lr.c new file +21 -0
+	u32 pass;
+	int err;
+
+	if (!count)
+		return -EINVAL;
+
+	if (count > 8)
+		return -EINVAL;
+
+	err = kstrtou32(buf, 16, &pass);
+	if (err)
+		return err;
+
+	be_pass = cpu_to_be32(pass);
+
+	memcpy(output, &be_pass, sizeof(be_pass));
+	output[4] = code;
+	memcpy(output + 5, &be_pass, sizeof(be_pass));
+
+	mutex_lock(&m24lr->lock);
+	ret = m24lr_regmap_write(m24lr->ctl_regmap, output, 9, 2304);

drivers/misc/eeprom/m24lr.c line 385

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+	mutex_unlock(&m24lr->lock);
+
+	return ret;
+}
+
+static ssize_t m24lr_read_reg_le(struct m24lr *m24lr, u64 *val,
+				 unsigned int reg_addr,
+				 unsigned int reg_size)
+{
+	long ret;

same

Quoted 31 lines
drivers/misc/eeprom/m24lr.c new file +31 -0
+	__le64 input = 0;
+
+	ret = m24lr_read(m24lr, (u8 *)&input, reg_size, reg_addr, false);
+	if (IS_ERR_VALUE(ret))
+		return ret;
+
+	if (ret != reg_size)
+		return -EINVAL;
+
+	switch (reg_size) {
+	case 1:
+		*val = *(u8 *)&input;
+		break;
+	case 2:
+		*val = le16_to_cpu((__le16)input);
+		break;
+	case 4:
+		*val = le32_to_cpu((__le32)input);
+		break;
+	case 8:
+		*val = le64_to_cpu((__le64)input);
+		break;
+	default:
+		return -EINVAL;
+	};
+
+	return 0;
+}
+
+static int m24lr_nvmem_read(void *priv, unsigned int offset, void *val,
+			    size_t bytes)

drivers/misc/eeprom/m24lr.c line 426

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+{
+	struct m24lr *m24lr = priv;
+
+	if (!bytes)
+		return bytes;
+
+	if (offset + bytes > m24lr->eeprom_size)
+		return -EINVAL;
+
+	return m24lr_read(m24lr, val, bytes, offset, true);

We return an int now?

Quoted 1 line

+}

...

drivers/misc/eeprom/m24lr.c line 452

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+static ssize_t m24lr_ctl_sss_read(struct file *filep, struct kobject *kobj,
+				  const struct bin_attribute *attr, char *buf,
+				  loff_t offset, size_t count)
+{
+	struct m24lr *m24lr = attr->private;
+
+	if (!count)
+		return count;
+
+	if (offset + count > m24lr->sss_len)

Does using size_add() would make sense?

Quoted 5 lines
drivers/misc/eeprom/m24lr.c new file +5 -0
+		return -EINVAL;
+
+	return m24lr_read(m24lr, buf, count, offset, false);
+}
+

drivers/misc/eeprom/m24lr.c line 467

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+static ssize_t m24lr_ctl_sss_write(struct file *filep, struct kobject *kobj,
+				   const struct bin_attribute *attr, char *buf,
+				   loff_t offset, size_t count)
+{
+	struct m24lr *m24lr = attr->private;
+
+	if (!count)
+		return -EINVAL;
+
+	if (offset + count > m24lr->sss_len)

Same

Quoted 5 lines
drivers/misc/eeprom/m24lr.c new file +5 -0
+		return -EINVAL;
+
+	return m24lr_write(m24lr, buf, count, offset, false);
+}
+static BIN_ATTR(sss, 0600, m24lr_ctl_sss_read, m24lr_ctl_sss_write, 0);

...

drivers/misc/eeprom/m24lr.c line 515

Quoted 6 lines
drivers/misc/eeprom/m24lr.c new file +6 -0
+static struct attribute *m24lr_ctl_dev_attrs[] = {
+	&dev_attr_unlock.attr,
+	&dev_attr_new_pass.attr,
+	&dev_attr_uid.attr,
+	&dev_attr_total_sectors.attr,
+	NULL,

Unneeded trailing ,

Quoted 1 line

+};

...

Quoted 18 lines
drivers/misc/eeprom/m24lr.c new file +18 -0
+static int m24lr_probe(struct i2c_client *client)
+{
+	struct regmap_config eeprom_regmap_conf = {0};
+	struct nvmem_config nvmem_conf = {0};
+	struct device *dev = &client->dev;
+	struct i2c_client *eeprom_client;
+	const struct m24lr_chip *chip;
+	struct regmap *eeprom_regmap;
+	struct nvmem_device *nvmem;
+	struct regmap *ctl_regmap;
+	struct m24lr *m24lr;
+	u32 regs[2];
+	long err;
+
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+		return -EOPNOTSUPP;
+
+	chip = m24lr_get_chip(dev);

drivers/misc/eeprom/m24lr.c line 562

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+	if (!chip)
+		return -ENODEV;
+
+	m24lr = devm_kzalloc(dev, sizeof(struct m24lr), GFP_KERNEL);
+	if (!m24lr)
+		return -ENOMEM;
+
+	err = device_property_read_u32_array(dev, "reg", regs, ARRAY_SIZE(regs));
+	if (err) {
+		dev_err(dev, "device_property_read_u32_array\n");

return dev_err_probe() maybe?

drivers/misc/eeprom/m24lr.c line 569

Quoted 7 lines
drivers/misc/eeprom/m24lr.c new file +7 -0
+		return err;
+	}
+	/* Create a second I2C client for the eeprom interface */
+	eeprom_client = devm_i2c_new_dummy_device(dev, client->adapter, regs[1]);
+	if (IS_ERR(eeprom_client)) {
+		dev_err(dev,
+			"Failed to create dummy I2C client for the EEPROM\n");

return dev_err_probe() maybe?
...

Quoted 47 lines
drivers/misc/eeprom/m24lr.c new file +47 -0
+		return PTR_ERR(eeprom_client);
+	}
+
+	ctl_regmap = devm_regmap_init_i2c(client, &m24lr_ctl_regmap_conf);
+	if (IS_ERR(ctl_regmap)) {
+		err = PTR_ERR(ctl_regmap);
+		dev_err(dev, "Failed to init regmap\n");
+		return err;
+	}
+
+	eeprom_regmap_conf.name = "m24lr_eeprom";
+	eeprom_regmap_conf.reg_bits = 16;
+	eeprom_regmap_conf.val_bits = 8;
+	eeprom_regmap_conf.disable_locking = true;
+	eeprom_regmap_conf.max_register = chip->eeprom_size - 1;
+
+	eeprom_regmap = devm_regmap_init_i2c(eeprom_client,
+					     &eeprom_regmap_conf);
+	if (IS_ERR(eeprom_regmap)) {
+		err = PTR_ERR(eeprom_regmap);
+		dev_err(dev, "Failed to init regmap\n");
+		return err;
+	}
+
+	mutex_init(&m24lr->lock);
+	m24lr->sss_len = chip->sss_len;
+	m24lr->page_size = chip->page_size;
+	m24lr->eeprom_size = chip->eeprom_size;
+	m24lr->eeprom_regmap = eeprom_regmap;
+	m24lr->ctl_regmap = ctl_regmap;
+
+	nvmem_conf.dev = &eeprom_client->dev;
+	nvmem_conf.owner = THIS_MODULE;
+	nvmem_conf.type = NVMEM_TYPE_EEPROM;
+	nvmem_conf.reg_read = m24lr_nvmem_read;
+	nvmem_conf.reg_write = m24lr_nvmem_write;
+	nvmem_conf.size = chip->eeprom_size;
+	nvmem_conf.word_size = 1;
+	nvmem_conf.stride = 1;
+	nvmem_conf.priv = m24lr;
+
+	nvmem = devm_nvmem_register(dev, &nvmem_conf);
+	if (IS_ERR(nvmem))
+		return PTR_ERR(nvmem);
+
+	i2c_set_clientdata(client, m24lr);
+	i2c_set_clientdata(eeprom_client, m24lr);

drivers/misc/eeprom/m24lr.c line 626

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+
+	bin_attr_sss.size = chip->sss_len;
+	bin_attr_sss.private = m24lr;
+	err = sysfs_create_bin_file(&dev->kobj, &bin_attr_sss);
+	if (err)
+		return err;
+
+	/* test by reading the uid, if success store it */
+	err = m24lr_read_reg_le(m24lr, &m24lr->uid, 2324, sizeof(m24lr->uid));
+	if (IS_ERR_VALUE(err))

Missing sysfs_remove_bin_file() or error handling pah?

Quoted 4 lines

drivers/misc/eeprom/m24lr.c line 630

Quoted 4 lines
drivers/misc/eeprom/m24lr.c new file +4 -0
+		return -ENODEV;
+
+	return 0;
+}

Hi Christophe,

Thank you for the review!

It is done.

Best regards,
Abd-Alrhman Masalkhi

#7 lore raw

Re: [PATCH v5 2/3] eeprom: add driver for ST M24LR series RFID/NFC EEPROM chips

In reply to Christophe JAILLET

Hi Christophe,

Thank you for the review!

Quoted 13 lines · Christophe JAILLET
Quoted 13 lines

+/**
+ * m24lr_regmap_read - read data using regmap with retry on failure

+ * @regmap:  regmap instance for the device
+ * @buf:     buffer to store the read data
+ * @size:    number of bytes to read
+ * @offset:  starting register address

+ *
+ * Attempts to read a block of data from the device with retries and timeout.
+ * Some M24LR chips may transiently NACK reads (e.g., during internal write
+ * cycles), so this function retries with a short sleep until the timeout
+ * expires.
+ *
+ * Returns:

Quoted 8 lines

Review

Quoted 5 lines

+ * Number of bytes read on success,
+ * -ETIMEDOUT if the read fails within the timeout window.
+ */

(quoted diff) +2 -0
+static ssize_t m24lr_regmap_read(struct regmap *regmap, u8 *buf,
+				 size_t size, unsigned int offset)

Why returning a ssize_t?
regmap_bulk_read() returns an int.

Since I return @size (of type size_t) on success, should I keep the return type as ssize_t, or would it be better to change it to int to match regmap_bulk_read()?

Best regards,
Abd-Alrhman Masalkhi

#8 lore raw

Re: [PATCH v5 2/3] eeprom: add driver for ST M24LR series RFID/NFC EEPROM chips

Le 04/07/2025 à 17:11, Abd-Alrhman Masalkhi a écrit :

Quoted 27 lines

Hi Christophe,

Thank you for the review!

Quoted 13 lines · Christophe JAILLET
Quoted 13 lines

+/**
+ * m24lr_regmap_read - read data using regmap with retry on failure

+ * @regmap:  regmap instance for the device
+ * @buf:     buffer to store the read data
+ * @size:    number of bytes to read
+ * @offset:  starting register address

+ *
+ * Attempts to read a block of data from the device with retries and timeout.
+ * Some M24LR chips may transiently NACK reads (e.g., during internal write
+ * cycles), so this function retries with a short sleep until the timeout
+ * expires.
+ *
+ * Returns:

Quoted 8 lines

Review

Quoted 5 lines

+ * Number of bytes read on success,
+ * -ETIMEDOUT if the read fails within the timeout window.
+ */

(quoted diff) +2 -0
+static ssize_t m24lr_regmap_read(struct regmap *regmap, u8 *buf,
+				 size_t size, unsigned int offset)

Why returning a ssize_t?
regmap_bulk_read() returns an int.

Quoted 3 lines

Since I return @size (of type size_t) on success, should I keep the return type as ssize_t, or would it be better to change it to int to match regmap_bulk_read()?

Hmm, this ends being used with BIN_ATTR() in m24lr_ctl_sss_[read|write]() so it needs to keep with ssize_t.

CJ

Quoted 5 lines

Best regards,
Abd-Alrhman Masalkhi

#9 lore raw

Re: [PATCH v5 2/3] eeprom: add driver for ST M24LR series RFID/NFC EEPROM chips

Hi Christophe

Quoted 22 lines · Christophe JAILLET
Quoted 22 lines
Quoted 21 lines
Quoted 8 lines
drivers/misc/eeprom/m24lr.c new file +8 -0
+/**
+ * m24lr_regmap_read - read data using regmap with retry on failure
+ * @regmap:  regmap instance for the device
+ * @buf:     buffer to store the read data
+ * @size:    number of bytes to read
+ * @offset:  starting register address
+ *
+ * Attempts to read a block of data from the device with retries and timeout.

drivers/misc/eeprom/m24lr.c line 195

Quoted 10 lines
drivers/misc/eeprom/m24lr.c new file +10 -0
+ * Some M24LR chips may transiently NACK reads (e.g., during internal write
+ * cycles), so this function retries with a short sleep until the timeout
+ * expires.
+ *
+ * Returns:
+ *	 Number of bytes read on success,
+ *	 -ETIMEDOUT if the read fails within the timeout window.
+ */
+static ssize_t m24lr_regmap_read(struct regmap *regmap, u8 *buf,
+				 size_t size, unsigned int offset)

Why returning a ssize_t?
regmap_bulk_read() returns an int.

Quoted 6 lines
Quoted 3 lines

Since I return @size (of type size_t) on success, should I keep the return type as ssize_t, or would it be better to change it to int to match regmap_bulk_read()?

Hmm, this ends being used with BIN_ATTR() in m24lr_ctl_sss_[read|write]() so it needs to keep with ssize_t.

Done.

Best regards,
Abd-Alrhman Masalkhi

#10 lore raw

PATCH v5 3/3 ABI: sysfs: add documentation for ST M24LR EEPROM and control interface

In reply to Abd-Alrhman Masalkhi

Add sysfs ABI documentation for the STMicroelectronics M24LR device, covering both the control interface (e.g., unlock, password update, UID, total sectors, and SSS entries) and EEPROM access via the nvmem subsystem.

---
Changes in v5:
- Fix dates and update targeted kernel version.
- Link to v4: https://lore.kernel.org/lkml/[email protected]/

Changes in v4:
- Replaced 'sss<N>' entries with a single binary 'sss' attribute
- Added 'total_sectors' attribute to report the number of valid SSS bytes
- removed 'mem_size' attribute
- Fix dates and update targeted kernel version.
- Link to v3: https://lore.kernel.org/lkml/[email protected]/

Changes in v3:
- Updated sysfs entry paths to use <busnum>-<primary-addr> to reflect the control address.
- Link to v2: https://lore.kernel.org/lkml/[email protected]/

Changes in v2:
- Added initial sysfs ABI documentation.

---
 .../ABI/testing/sysfs-bus-i2c-devices-m24lr   | 100 ++++++++++++++++++
 1 file changed, 100 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-i2c-devices-m24lr
Documentation/ABI/testing/sysfs-bus-i2c-devices-m24lr new file +100 -0
new file mode 100644
index 000000000000..7c51ce8d38ba
@@ -0,0 +1,100 @@
+What:           /sys/bus/i2c/devices/<busnum>-<primary-addr>/unlock
+Date:           2025-07-04
+KernelVersion:  6.17
+Contact:        Abd-Alrhman Masalkhi <[email protected]>
+Description:
+                Write-only attribute used to present a password and unlock
+                access to protected areas of the M24LR chip, including
+                configuration registers such as the Sector Security Status
+                (SSS) bytes. A valid password must be written to enable write
+                access to these regions via the I2C interface.
+
+                Format:
+                  - Hexadecimal string representing a 32-bit (4-byte) password
+                  - Accepts 1 to 8 hex digits (e.g., "c", "1F", "a1b2c3d4")
+                  - No "0x" prefix, whitespace, or trailing newline
+                  - Case-insensitive
+
+                Behavior:
+                  - If the password matches the internal stored value,
+                    access to protected memory/configuration is granted
+                  - If the password does not match the internally stored value,
+                    it will fail silently
+
+What:           /sys/bus/i2c/devices/<busnum>-<primary-addr>/new_pass
+Date:           2025-07-04
+KernelVersion:  6.17
+Contact:        Abd-Alrhman Masalkhi <[email protected]>
+Description:
+                Write-only attribute used to update the password required to
+                unlock the M24LR chip.
+
+                Format:
+                  - Hexadecimal string representing a new 32-bit password
+                  - Accepts 1 to 8 hex digits (e.g., "1A", "ffff", "c0ffee00")
+                  - No "0x" prefix, whitespace, or trailing newline
+                  - Case-insensitive
+
+                Behavior:
+                  - Overwrites the current password stored in the I2C password
+                    register
+                  - Requires the device to be unlocked before changing the
+                    password
+                  - If the device is locked, the write silently fails
+
+What:           /sys/bus/i2c/devices/<busnum>-<primary-addr>/uid
+Date:           2025-07-04
+KernelVersion:  6.17
+Contact:        Abd-Alrhman Masalkhi <[email protected]>
+Description:
+                Read-only attribute that exposes the 8-byte unique identifier
+                programmed into the M24LR chip at the factory.
+
+                Format:
+                  - Lowercase hexadecimal string representing a 64-bit value
+                  - 1 to 16 hex digits (e.g., "e00204f12345678")
+                  - No "0x" prefix
+                  - Includes a trailing newline
+
+What:           /sys/bus/i2c/devices/<busnum>-<primary-addr>/total_sectors
+Date:           2025-07-04
+KernelVersion:  6.17
+Contact:        Abd-Alrhman Masalkhi <[email protected]>
+Description:
+                Read-only attribute that exposes the total number of EEPROM
+                sectors available in the M24LR chip.
+
+                Format:
+                  - 1 to 2 hex digits (e.g. "F")
+                  - No "0x" prefix
+                  - Includes a trailing newline
+
+                Notes:
+                  - Value is encoded by the chip and corresponds to the EEPROM
+                    size (e.g., 3 = 4 kbit for M24LR04E-R)
+
+What:           /sys/bus/i2c/devices/<busnum>-<primary-addr>/sss
+Date:           2025-07-04
+KernelVersion:  6.17
+Contact:        Abd-Alrhman Masalkhi <[email protected]>
+Description:
+                Read/write binary attribute representing the Sector Security
+                Status (SSS) bytes for all EEPROM sectors in STMicroelectronics
+                M24LR chips.
+
+                Each EEPROM sector has one SSS byte, which controls I2C and
+                RF access through protection bits and optional password
+                authentication.
+
+                Format:
+                  - The file contains one byte per EEPROM sector
+                  - Byte at offset N corresponds to sector N
+                  - Binary access only; use tools like dd, Python, or C that
+                    support byte-level I/O and offset control.
+
+                Notes:
+                  - The number of valid bytes in this file is equal to the
+                    value exposed by 'total_sectors' file
+                  - Write access requires prior password authentication in
+                    I2C mode
+                  - Refer to the M24LR datasheet for full SSS bit layout
Signature · 1 line
2.43.0