Skip to contentSkip to conversation

nvmem: Replace spaces with tab in documentation

PATCH Superseded Marek Vasut 3 participants 7 messages Jun 23, 2024 – Jun 24, 2024

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 nvmem: Replace spaces with tab in documentation

Replace two spaces with tab in the sysfs attribute documentation. No functional change.

---
Cc: Alexandre Belloni <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
---
V2: - New patch

---
 Documentation/ABI/stable/sysfs-bus-nvmem | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/ABI/stable/sysfs-bus-nvmem +1 -1
index c399323f37de3..854bd11d72ac4 100644
@@ -1,6 +1,6 @@
 What:		/sys/bus/nvmem/devices/.../nvmem
 Date:		July 2015
-KernelVersion:  4.2
+KernelVersion:	4.2
 Contact:	Srinivas Kandagatla <[email protected]>
 Description:
 		This file allows user to read/write the raw NVMEM contents.
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 2/4 nvmem: Document type attribute

Document a type attribute used by userspace to discern different types of NVMEM devices. The implementation is already present, the ABI document is missing, add it.

---
Cc: Alexandre Belloni <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
---
V2: - New patch

---
 Documentation/ABI/stable/sysfs-bus-nvmem | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/ABI/stable/sysfs-bus-nvmem +11 -0
index 854bd11d72ac4..0e3a8492a1082 100644
@@ -20,3 +20,14 @@ Description:
 		  ...
 		  *
 		  0001000
+
+What:		/sys/bus/nvmem/devices/.../type
+Date:		November 2018
+KernelVersion:	5.0
+Contact:	Alexandre Belloni <[email protected]>
+Description:
+		This read-only attribute allows user to read the NVMEM
+		device type. Supported types are "Unknown", "EEPROM",
+		"OTP", "Battery backed", "FRAM".
+		Note: This file is only present if CONFIG_NVMEM_SYSFS
+		is enabled
Signature · 1 line
2.43.0
Reviewed-by on v2 2/4
#2 lore raw

Re: [PATCH v2 2/4] nvmem: Document type attribute

Quoted 5 lines · Marek Vasut

Document a type attribute used by userspace to discern different types of NVMEM devices. The implementation is already present, the ABI document is missing, add it.

Quoted 35 lines

---
Cc: Alexandre Belloni <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
---
V2: - New patch

---
 Documentation/ABI/stable/sysfs-bus-nvmem | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/ABI/stable/sysfs-bus-nvmem +11 -0
index 854bd11d72ac4..0e3a8492a1082 100644
@@ -20,3 +20,14 @@ Description:
...
 		  *
 		  0001000
+
+What:		/sys/bus/nvmem/devices/.../type
+Date:		November 2018
+KernelVersion:	5.0
+Contact:	Alexandre Belloni <[email protected]>
+Description:
+		This read-only attribute allows user to read the NVMEM
+		device type. Supported types are "Unknown", "EEPROM",
+		"OTP", "Battery backed", "FRAM".
+		Note: This file is only present if CONFIG_NVMEM_SYSFS
+		is enabled
Signature · 1 line
2.43.0
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw

PATCH v2 3/4 nvmem: Use sysfs_emit() for type attribute

In reply to Marek Vasut

Use sysfs_emit() instead of sprintf() to follow best practice per Documentation/filesystems/sysfs.rst
"
show() should only use sysfs_emit()...
"

---
Cc: Alexandre Belloni <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
---
V2: - New patch

---
 drivers/nvmem/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvmem/core.c +1 -1
index e1ec3b7200d7b..b31abffcdfc00 100644
@@ -179,7 +179,7 @@ static ssize_t type_show(struct device *dev,
 {
 	struct nvmem_device *nvmem = to_nvmem_device(dev);
 
-	return sprintf(buf, "%s\n", nvmem_type_str[nvmem->type]);
+	return sysfs_emit(buf, "%s\n", nvmem_type_str[nvmem->type]);
 }
 
 static DEVICE_ATTR_RO(type);
Signature · 1 line
2.43.0
#4 lore raw

PATCH v2 4/4 nvmem: core: Implement force_ro sysfs attribute

In reply to Marek Vasut

Implement "force_ro" sysfs attribute to allow users to set read-write devices as read-only and back to read-write from userspace. The choice of the name is based on MMC core 'force_ro' attribute.

This solves a situation where an AT24 I2C EEPROM with GPIO based nWP signal may have to be occasionally updated. Such I2C EEPROM device is usually set as read-only during most of the regular system operation, but in case it has to be updated in a controlled manner, it could be unlocked using this new "force_ro" sysfs attribute and then re-locked again.

The "read-only" DT property and config->read_only configuration is respected and is used to set default state of the device, read-only or read-write, for devices which do implement .reg_write function. For devices which do not implement .reg_write function, the device is unconditionally read-only and the "force_ro" attribute is not visible.

---
Cc: Alexandre Belloni <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
---
V2: - Document the force_ro attribute
- Use sysfs_emit()

---
 Documentation/ABI/stable/sysfs-bus-nvmem | 13 +++++++
 drivers/nvmem/core.c                     | 44 ++++++++++++++++++++++++
 drivers/nvmem/internals.h                |  1 +
 3 files changed, 58 insertions(+)
Documentation/ABI/stable/sysfs-bus-nvmem +13 -0
index 0e3a8492a1082..c713c4e6cecb1 100644
@@ -1,3 +1,16 @@
+What:		/sys/bus/nvmem/devices/.../force_ro
+Date:		June 2024
+KernelVersion:	6.11
+Contact:	Marek Vasut <[email protected]>
+Description:
+		This read/write attribute allows users to set read-write
+		devices as read-only and back to read-write from userspace.
+		This can be used to unlock and relock write-protection of
+		devices which are generally locked, except during sporadic
+		programming operation.
+		Note: This file is only present if CONFIG_NVMEM_SYSFS
+		is enabled
+
 What:		/sys/bus/nvmem/devices/.../nvmem
 Date:		July 2015
 KernelVersion:	4.2
drivers/nvmem/core.c +44 -0

69 lines not on this page · raw message

drivers/nvmem/internals.h +1 -0
index 18fed57270e5e..0667937ebb86b 100644
@@ -16,6 +16,7 @@ struct nvmem_device {
 	int			id;
 	struct kref		refcnt;
 	size_t			size;
+	bool			default_read_only;
 	bool			read_only;
 	bool			root_only;
 	int			flags;
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v2 4/4] nvmem: core: Implement force_ro sysfs attribute

Quoted 42 lines · Marek Vasut

Implement "force_ro" sysfs attribute to allow users to set read-write devices as read-only and back to read-write from userspace. The choice of the name is based on MMC core 'force_ro' attribute.

This solves a situation where an AT24 I2C EEPROM with GPIO based nWP signal may have to be occasionally updated. Such I2C EEPROM device is usually set as read-only during most of the regular system operation, but in case it has to be updated in a controlled manner, it could be unlocked using this new "force_ro" sysfs attribute and then re-locked again.

The "read-only" DT property and config->read_only configuration is respected and is used to set default state of the device, read-only or read-write, for devices which do implement .reg_write function. For devices which do not implement .reg_write function, the device is unconditionally read-only and the "force_ro" attribute is not visible.

---
Cc: Alexandre Belloni <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
---
V2: - Document the force_ro attribute
- Use sysfs_emit()

---
 Documentation/ABI/stable/sysfs-bus-nvmem | 13 +++++++
 drivers/nvmem/core.c                     | 44 ++++++++++++++++++++++++
 drivers/nvmem/internals.h                |  1 +
 3 files changed, 58 insertions(+)
Documentation/ABI/stable/sysfs-bus-nvmem +2 -0
index 0e3a8492a1082..c713c4e6cecb1 100644
@@ -1,3 +1,16 @@
+What:		/sys/bus/nvmem/devices/.../force_ro
+Date:		June 2024

Documentation/ABI/stable/sysfs-bus-nvmem line 12

Quoted 10 lines
Documentation/ABI/stable/sysfs-bus-nvmem +10 -0
+KernelVersion:	6.11
+Contact:	Marek Vasut <[email protected]>
+Description:
+		This read/write attribute allows users to set read-write
+		devices as read-only and back to read-write from userspace.
+		This can be used to unlock and relock write-protection of
+		devices which are generally locked, except during sporadic
+		programming operation.
+		Note: This file is only present if CONFIG_NVMEM_SYSFS
+		is enabled

And what exactly are the values that can be read or written here?

thanks,

greg k-h

#6 lore raw

Re: [PATCH v2 4/4] nvmem: core: Implement force_ro sysfs attribute

Quoted 47 lines · Greg Kroah-Hartman
Quoted 46 lines · Marek Vasut

Implement "force_ro" sysfs attribute to allow users to set read-write devices as read-only and back to read-write from userspace. The choice of the name is based on MMC core 'force_ro' attribute.

This solves a situation where an AT24 I2C EEPROM with GPIO based nWP signal may have to be occasionally updated. Such I2C EEPROM device is usually set as read-only during most of the regular system operation, but in case it has to be updated in a controlled manner, it could be unlocked using this new "force_ro" sysfs attribute and then re-locked again.

The "read-only" DT property and config->read_only configuration is respected and is used to set default state of the device, read-only or read-write, for devices which do implement .reg_write function. For devices which do not implement .reg_write function, the device is unconditionally read-only and the "force_ro" attribute is not visible.

---
Cc: Alexandre Belloni <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Bartosz Golaszewski <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
---
V2: - Document the force_ro attribute
- Use sysfs_emit()

---
  Documentation/ABI/stable/sysfs-bus-nvmem | 13 +++++++
  drivers/nvmem/core.c                     | 44 ++++++++++++++++++++++++
  drivers/nvmem/internals.h                |  1 +
  3 files changed, 58 insertions(+)
Documentation/ABI/stable/sysfs-bus-nvmem +6 -0
index 0e3a8492a1082..c713c4e6cecb1 100644
@@ -1,3 +1,16 @@
+What:		/sys/bus/nvmem/devices/.../force_ro
+Date:		June 2024
+KernelVersion:	6.11
+Contact:	Marek Vasut <[email protected]>
+Description:
+		This read/write attribute allows users to set read-write
Quoted 8 lines

Documentation/ABI/stable/sysfs-bus-nvmem line 12

Quoted 6 lines
Documentation/ABI/stable/sysfs-bus-nvmem +6 -0
+		devices as read-only and back to read-write from userspace.
+		This can be used to unlock and relock write-protection of
+		devices which are generally locked, except during sporadic
+		programming operation.
+		Note: This file is only present if CONFIG_NVMEM_SYSFS
+		is enabled

And what exactly are the values that can be read or written here?

I expanded it to this:

This read/write attribute allows users to set read-write devices as read-only and back to read-write from userspace. This can be used to unlock and relock write-protection of devices which are generally locked, except during sporadic programming operation.
+Read returns '0' or '1' for read-write or read-only modes +respectively.
+Write parses one of 'YyTt1NnFf0', or [oO][NnFf] for "on" +and "off", i.e. what kstrbool() supports.
Note: This file is only present if CONFIG_NVMEM_SYSFS is enabled.

But I wonder, wouldn't it be better if write only supported '0' and '1' too, instead of the whole list of stuff that kstrbool() supports ?