Skip to contentSkip to conversation

nvmem: Replace spaces with tab in documentation

PATCH Superseded Marek Vasut 2 participants 10 messages Jun 26, 2024 – Jun 28, 2024

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 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
V3: - No change

---
 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 v3 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
V3: - Add RB from Alexandre
- Add trailing full stop to the paragraph

---
 Documentation/ABI/stable/sysfs-bus-nvmem | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/ABI/stable/sysfs-bus-nvmem +11 -0
index 854bd11d72ac4..3f0a95250aa84 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
#2 lore raw

PATCH v3 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
V3: - No change

---
 drivers/nvmem/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvmem/core.c +1 -1
index a31ea4275d5ae..5b3606114628b 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
#3 lore raw

PATCH v3 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()
V3: - Expand ABI documentation with what the force_ro attribute
returns and what it can parse.

---
 Documentation/ABI/stable/sysfs-bus-nvmem | 17 +++++++++
 drivers/nvmem/core.c                     | 44 ++++++++++++++++++++++++
 drivers/nvmem/internals.h                |  1 +
 3 files changed, 62 insertions(+)
Documentation/ABI/stable/sysfs-bus-nvmem +17 -0
index 3f0a95250aa84..aa89adf18bc55 100644
@@ -1,3 +1,20 @@
+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.
+		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.
+
 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
#4 lore raw

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

Quoted 15 lines · Marek Vasut
  
  static const struct attribute_group *nvmem_dev_groups[] = {
drivers/nvmem/core.c +1 -0
@@ -945,6 +988,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 
  	nvmem->read_only = device_property_present(config->dev, "read-only") ||
  			   config->read_only || !nvmem->reg_write;
+	nvmem->default_read_only = nvmem->read_only;
 
  #ifdef CONFIG_NVMEM_SYSFS
  	nvmem->dev.groups = nvmem_dev_groups;
drivers/nvmem/internals.h +0 -0
index 18fed57270e5e..0667937ebb86b 100644

drivers/nvmem/internals.h struct nvmem_device { · line 19

Quoted 4 lines
drivers/nvmem/internals.h +1 -0
@@ -16,6 +16,7 @@ struct nvmem_device {
  	int			id;
  	struct kref		refcnt;
  	size_t			size;
+	bool			default_read_only;

Its not very clear what is the need for this?

--srini

Quoted 3 lines
drivers/nvmem/internals.h +0 -0
  	bool			read_only;
  	bool			root_only;
  	int			flags;
#5 lore raw

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

Quoted 15 lines · Srinivas Kandagatla
Quoted 12 lines · Marek Vasut

  static const struct attribute_group *nvmem_dev_groups[] = {

(quoted diff) +0 -0
@@ -945,6 +988,7 @@ struct nvmem_device *nvmem_register(const struct 
 nvmem_config *config)

      nvmem->read_only = device_property_present(config->dev, "read-only") || config->read_only || !nvmem->reg_write;
+    nvmem->default_read_only = nvmem->read_only;
  #ifdef CONFIG_NVMEM_SYSFS
      nvmem->dev.groups = nvmem_dev_groups;

drivers/nvmem/internals.h +0 -0
index 18fed57270e5e..0667937ebb86b 100644
Quoted 8 lines

drivers/nvmem/internals.h struct nvmem_device { · line 19

Quoted 5 lines
drivers/nvmem/internals.h +1 -0
@@ -16,6 +16,7 @@ struct nvmem_device {
       int            id;
       struct kref        refcnt;
       size_t            size;
+    bool            default_read_only;

Its not very clear what is the need for this?

This field is used to discern devices which are by default read-write from ones which are by default read-only. Only the former can be switched between read-write and read-only mode ; the later cannot be switched to read-write mode .

#6 lore raw

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

Quoted 25 lines · Marek Vasut
Quoted 15 lines · Srinivas Kandagatla
Quoted 12 lines · Marek Vasut

  static const struct attribute_group *nvmem_dev_groups[] = {

(quoted diff) +0 -0
@@ -945,6 +988,7 @@ struct nvmem_device *nvmem_register(const struct 
 nvmem_config *config)

      nvmem->read_only = device_property_present(config->dev, "read-only") || config->read_only || !nvmem->reg_write;
+    nvmem->default_read_only = nvmem->read_only;
  #ifdef CONFIG_NVMEM_SYSFS
      nvmem->dev.groups = nvmem_dev_groups;

drivers/nvmem/internals.h +0 -0
index 18fed57270e5e..0667937ebb86b 100644
Quoted 8 lines

drivers/nvmem/internals.h struct nvmem_device { · line 19

Quoted 5 lines
drivers/nvmem/internals.h +1 -0
@@ -16,6 +16,7 @@ struct nvmem_device {
       int            id;
       struct kref        refcnt;
       size_t            size;
+    bool            default_read_only;

Its not very clear what is the need for this?

Quoted 1 line

This field is used to discern devices which are by default read-write

provider drivers or any drivers should not be accessing this struct directly.

Quoted 1 line

from ones which are by default read-only. Only the former can be

Why should the drivers care about this?
If the read_only flag is set in the core, nvmem core should prohibit any writes for this provider.

--srini

Quoted 1 line

switched between read-write and read-only mode ; the later cannot be switched to read-write mode .

#7 lore raw

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

Quoted 28 lines · Srinivas Kandagatla
Quoted 25 lines · Marek Vasut
Quoted 23 lines · Srinivas Kandagatla
Quoted 13 lines · Marek Vasut

  static const struct attribute_group *nvmem_dev_groups[] = {

(quoted diff) +0 -0
@@ -945,6 +988,7 @@ struct nvmem_device *nvmem_register(const struct 
 nvmem_config *config)

      nvmem->read_only = device_property_present(config->dev, "read-only") || config->read_only || !nvmem->reg_write;
+    nvmem->default_read_only = nvmem->read_only;
  #ifdef CONFIG_NVMEM_SYSFS
      nvmem->dev.groups = nvmem_dev_groups;

drivers/nvmem/internals.h +0 -0
index 18fed57270e5e..0667937ebb86b 100644

drivers/nvmem/internals.h struct nvmem_device { · line 19

Quoted 4 lines
drivers/nvmem/internals.h +1 -0
@@ -16,6 +16,7 @@ struct nvmem_device {
       int            id;
       struct kref        refcnt;
       size_t            size;
+    bool            default_read_only;

Its not very clear what is the need for this?

Quoted 6 lines
Quoted 1 line

This field is used to discern devices which are by default read-write

provider drivers or any drivers should not be accessing this struct directly.

Quoted 1 line

from ones which are by default read-only. Only the former can be

Why should the drivers care about this?
If the read_only flag is set in the core, nvmem core should prohibit any writes for this provider.

I think this is a nvmem core patch , isn't it ?

#8 lore raw

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

Quoted 29 lines · Marek Vasut
Quoted 28 lines · Srinivas Kandagatla
Quoted 25 lines · Marek Vasut
Quoted 23 lines · Srinivas Kandagatla
Quoted 13 lines · Marek Vasut

  static const struct attribute_group *nvmem_dev_groups[] = {

(quoted diff) +0 -0
@@ -945,6 +988,7 @@ struct nvmem_device *nvmem_register(const 
 struct nvmem_config *config)

      nvmem->read_only = device_property_present(config->dev, "read-only") || config->read_only || !nvmem->reg_write;
+    nvmem->default_read_only = nvmem->read_only;
  #ifdef CONFIG_NVMEM_SYSFS
      nvmem->dev.groups = nvmem_dev_groups;

drivers/nvmem/internals.h +0 -0
index 18fed57270e5e..0667937ebb86b 100644

drivers/nvmem/internals.h struct nvmem_device { · line 19

Quoted 4 lines
drivers/nvmem/internals.h +1 -0
@@ -16,6 +16,7 @@ struct nvmem_device {
       int            id;
       struct kref        refcnt;
       size_t            size;
+    bool            default_read_only;

Its not very clear what is the need for this?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

This field is used to discern devices which are by default read-write

provider drivers or any drivers should not be accessing this struct directly.

Quoted 1 line

from ones which are by default read-only. Only the former can be

Why should the drivers care about this?
If the read_only flag is set in the core, nvmem core should prohibit any writes for this provider.

I think this is a nvmem core patch , isn't it ?

All that I see in this patch is setting default_read_only and no user for it. unless am looking at wrong patch.

--srin

#9 lore raw

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

Quoted 33 lines · Srinivas Kandagatla
Quoted 30 lines · Marek Vasut
Quoted 29 lines · Srinivas Kandagatla
Quoted 26 lines · Marek Vasut
Quoted 15 lines · Srinivas Kandagatla
Quoted 12 lines · Marek Vasut

  static const struct attribute_group *nvmem_dev_groups[] = {

(quoted diff) +0 -0
@@ -945,6 +988,7 @@ struct nvmem_device *nvmem_register(const 
 struct nvmem_config *config)

      nvmem->read_only = device_property_present(config->dev, "read-only") || config->read_only || !nvmem->reg_write;
+    nvmem->default_read_only = nvmem->read_only;
  #ifdef CONFIG_NVMEM_SYSFS
      nvmem->dev.groups = nvmem_dev_groups;

drivers/nvmem/internals.h +0 -0
index 18fed57270e5e..0667937ebb86b 100644
Quoted 8 lines

drivers/nvmem/internals.h struct nvmem_device { · line 19

Quoted 5 lines
drivers/nvmem/internals.h +1 -0
@@ -16,6 +16,7 @@ struct nvmem_device {
       int            id;
       struct kref        refcnt;
       size_t            size;
+    bool            default_read_only;

Its not very clear what is the need for this?

This field is used to discern devices which are by default read-write

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

provider drivers or any drivers should not be accessing this struct directly.

Quoted 1 line

from ones which are by default read-only. Only the former can be

Why should the drivers care about this?
If the read_only flag is set in the core, nvmem core should prohibit any writes for this provider.

I think this is a nvmem core patch , isn't it ?

All that I see in this patch is setting default_read_only and no user for it. unless am looking at wrong patch.

Oh, now I understand, doh ... this is a remnant which should be removed. The force_ro attribute is now hidden for read-only devices outright in nvmem_attr_is_visible, so they cannot be switched to read-write mode.

Fixed in V4, thanks.