Skip to contentSkip to conversation

add support for FRAM

PATCH Superseded Jiri Prchal 3 participants 9 messages Jun 7, 2021

Subsystems (3)

v6 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v6 cover add support for FRAM

Adds support for Cypress FRAMs.

Jiri Prchal (5):
nvmem: eeprom: at25: prepare basics for FRAM support
nvmem: eeprom: at25: add support for FRAM
nvmem: eeprom: add documentation for FRAM
nvmem: eeprom: at25: export FRAM serial num
nvmem: eeprom: add documentation of sysfs sernum file

 .../ABI/testing/sysfs-class-spi-eeprom        |   6 +
 .../devicetree/bindings/eeprom/at25.yaml      |  31 +++-
 drivers/misc/eeprom/Kconfig                   |   5 +-
 drivers/misc/eeprom/at25.c                    | 167 ++++++++++++++----
 drivers/nvmem/core.c                          |   4 +
 include/linux/nvmem-provider.h                |   1 +
 6 files changed, 176 insertions(+), 38 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-spi-eeprom
Signature · 1 line
2.25.1
#1 lore raw

PATCH v6 1/5 nvmem: eeprom: at25: prepare basics for FRAM support

Added enum and string for FRAM to expose it as "fram".

---
v2: no change here
v3: resend and added more recipients
v4: resend
v5: no change here
v6: changed commit subject

---
 drivers/nvmem/core.c           | 4 ++++
 include/linux/nvmem-provider.h | 1 +
 2 files changed, 5 insertions(+)
drivers/nvmem/core.c +4 -0
index 177f5bf27c6d..01ef9a934b0a 100644
@@ -180,6 +180,7 @@ static const char * const nvmem_type_str[] = {
 	[NVMEM_TYPE_EEPROM] = "EEPROM",
 	[NVMEM_TYPE_OTP] = "OTP",
 	[NVMEM_TYPE_BATTERY_BACKED] = "Battery backed",
+	[NVMEM_TYPE_FRAM] = "FRAM",
 };
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
@@ -359,6 +360,9 @@ static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem,
 	if (!config->base_dev)
 		return -EINVAL;
 
+	if (config->type == NVMEM_TYPE_FRAM)
+		bin_attr_nvmem_eeprom_compat.attr.name = "fram";
+
 	nvmem->eeprom = bin_attr_nvmem_eeprom_compat;
 	nvmem->eeprom.attr.mode = nvmem_bin_attr_get_umode(nvmem);
 	nvmem->eeprom.size = nvmem->size;
include/linux/nvmem-provider.h +1 -0
index e162b757b6d5..890003565761 100644
@@ -25,6 +25,7 @@ enum nvmem_type {
 	NVMEM_TYPE_EEPROM,
 	NVMEM_TYPE_OTP,
 	NVMEM_TYPE_BATTERY_BACKED,
+	NVMEM_TYPE_FRAM,
 };
 
 #define NVMEM_DEVID_NONE	(-1)
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v6 1/5] nvmem: eeprom: at25: prepare basics for FRAM support

Quoted 1 line · Jiri Prchal

Added enum and string for FRAM to expose it as "fram".

Is "at25" in subject of this patch really correct ? Seems that patch is against to nvmen core, not at25 driver.

--mtx

Signature · 8 lines
---
Hinweis: unverschlüsselte E-Mails können leicht abgehört und manipuliert
werden ! Für eine vertrauliche Kommunikation senden Sie bitte ihren
GPG/PGP-Schlüssel zu.
---
Enrico Weigelt, metux IT consult
Free software and Linux embedded engineering
[email protected] -- +49-151-27565287
#3 lore raw

PATCH v6 2/5 nvmem: eeprom: at25: add support for FRAM

In reply to Jiri Prchal

Added support for Cypress FRAMs.
These frams have ID and some of them have serial number too. Size of them is recognized by ID. They don't have pages, it could be read or written at once, but it's limited in this driver to io limit 4096.

---
v2: fixed warning at %zd at int

v3: resend and added more recipients
v4: resend
v5: used in-kernel function int_pow
v6: no change here

---
 drivers/misc/eeprom/Kconfig |   5 +-
 drivers/misc/eeprom/at25.c  | 141 ++++++++++++++++++++++++++++--------
 2 files changed, 114 insertions(+), 32 deletions(-)
drivers/misc/eeprom/Kconfig +3 -2
index 0f791bfdc1f5..f0a7531f354c 100644
@@ -32,12 +32,13 @@ config EEPROM_AT24
 	  will be called at24.
 
 config EEPROM_AT25
-	tristate "SPI EEPROMs from most vendors"
+	tristate "SPI EEPROMs (FRAMs) from most vendors"
 	depends on SPI && SYSFS
 	select NVMEM
 	select NVMEM_SYSFS
 	help
-	  Enable this driver to get read/write support to most SPI EEPROMs,
+	  Enable this driver to get read/write support to most SPI EEPROMs
+	  and Cypress FRAMs,
 	  after you configure the board init code to know about each eeprom
 	  on your target board.
 
drivers/misc/eeprom/at25.c +111 -30

219 lines not on this page · raw message

Signature · 1 line
2.25.1
#4 lore raw

PATCH v6 3/5 nvmem: eeprom: add documentation for FRAM

In reply to Jiri Prchal

Added dt binding documentation.

---
v2: fixed dt_binding_check warnings thanks to Rob Herring
v3: resend and added more recipients
v4: resend
v5: no change here
v6: no change here

---
 .../devicetree/bindings/eeprom/at25.yaml      | 31 +++++++++++++++----
 1 file changed, 25 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/eeprom/at25.yaml +25 -6
index 121a601db22e..840ee7a83a14 100644
@@ -4,14 +4,16 @@
 $id: "http://devicetree.org/schemas/eeprom/at25.yaml#"
 $schema: "http://devicetree.org/meta-schemas/core.yaml#"
 
-title: SPI EEPROMs compatible with Atmel's AT25
+title: SPI EEPROMs or FRAMs compatible with Atmel's AT25
 
 maintainers:
   - Christian Eggers <[email protected]>
 
 properties:
   $nodename:
-    pattern: "^eeprom@[0-9a-f]{1,2}$"
+    anyOf:
+      - pattern: "^eeprom@[0-9a-f]{1,2}$"
+      - pattern: "^fram@[0-9a-f]{1,2}$"
 
   # There are multiple known vendors who manufacture EEPROM chips compatible
   # with Atmel's AT25. The compatible string requires two items where the
@@ -31,6 +33,7 @@ properties:
               - microchip,25lc040
               - st,m95m02
               - st,m95256
+              - cypress,fm25
 
           - const: atmel,at25
 
@@ -48,7 +51,7 @@ properties:
     $ref: /schemas/types.yaml#/definitions/uint32
     enum: [1, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072]
     description:
-      Size of the eeprom page.
+      Size of the eeprom page. FRAMs don't have pages.
 
   size:
     $ref: /schemas/types.yaml#/definitions/uint32
@@ -101,9 +104,19 @@ required:
   - compatible
   - reg
   - spi-max-frequency
-  - pagesize
-  - size
-  - address-width
+
+allOf:
+  - if:
+      properties:
+        compatible:
+          not:
+            contains:
+              const: cypress,fm25
+    then:
+      required:
+        - pagesize
+        - size
+        - address-width
 
 additionalProperties: false
 
@@ -126,4 +139,10 @@ examples:
             size = <32768>;
             address-width = <16>;
         };
+
+        fram@1 {
+            compatible = "cypress,fm25", "atmel,at25";
+            reg = <1>;
+            spi-max-frequency = <40000000>;
+        };
     };
Signature · 1 line
2.25.1
#5 lore raw

PATCH v6 4/5 nvmem: eeprom: at25: export FRAM serial num

In reply to Jiri Prchal

This exports serial number of FRAM in sysfs file named "sernum". Formatted in hex, each byte separated by space. Example:

$ cat /sys/class/spi_master/spi0/spi0.0/sernum
0000a43644f2ae6c

---
v2: no change here
v3: resend and added more recipients
v4: resend
v5: reworked up on Greg comments: no spaces in string, sysfs done correctly
v6: no change here

---
 drivers/misc/eeprom/at25.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/misc/eeprom/at25.c +27 -1
index 45a486994828..4e4fa8d3ba5d 100644
@@ -39,6 +39,7 @@ struct at25_data {
 	struct nvmem_config	nvmem_config;
 	struct nvmem_device	*nvmem;
 	int has_sernum;
+	char *sernum;
 };
 
 #define	AT25_WREN	0x06		/* latch the write enable */
@@ -173,6 +174,25 @@ static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command,
 	return status;
 }
 
+static ssize_t sernum_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct at25_data *at25;
+	int i;
+
+	at25 = dev_get_drvdata(dev);
+	for (i = FM25_SN_LEN - 1; i >= 0; i--)
+		buf += sprintf(buf, "%02x", at25->sernum[i]);
+	sprintf(buf, "\n");
+	return (2 * FM25_SN_LEN + 1);
+}
+static DEVICE_ATTR(sernum, 0440, sernum_show, NULL);
+
+static struct attribute *sernum_attrs[] = {
+	&dev_attr_sernum.attr,
+	NULL,
+};
+ATTRIBUTE_GROUPS(sernum);
+
 static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
 {
 	struct at25_data *at25 = priv;
@@ -417,8 +437,13 @@ static int at25_probe(struct spi_device *spi)
 		else
 			at25->chip.flags |= EE_ADDR2;
 
-		if (id[8])
+		if (id[8]) {
 			at25->has_sernum = 1;
+			at25->sernum = kzalloc(FM25_SN_LEN, GFP_KERNEL);
+			if (!at25->sernum)
+				return -ENOMEM;
+			fm25_aux_read(at25, at25->sernum, FM25_RDSN, FM25_SN_LEN);
+		}
 		else
 			at25->has_sernum = 0;
 
@@ -472,6 +497,7 @@ static struct spi_driver at25_driver = {
 	.driver = {
 		.name		= "at25",
 		.of_match_table = at25_of_match,
+		.dev_groups	= sernum_groups,
 	},
 	.probe		= at25_probe,
 };
Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH v6 4/5] nvmem: eeprom: at25: export FRAM serial num

Quoted 32 lines · Jiri Prchal

This exports serial number of FRAM in sysfs file named "sernum". Formatted in hex, each byte separated by space. Example:

$ cat /sys/class/spi_master/spi0/spi0.0/sernum
0000a43644f2ae6c

---
v2: no change here
v3: resend and added more recipients
v4: resend
v5: reworked up on Greg comments: no spaces in string, sysfs done correctly
v6: no change here

---
 drivers/misc/eeprom/at25.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/misc/eeprom/at25.c +1 -0
index 45a486994828..4e4fa8d3ba5d 100644
@@ -39,6 +39,7 @@ struct at25_data {
 	struct nvmem_config	nvmem_config;
 	struct nvmem_device	*nvmem;
 	int has_sernum;
+	char *sernum;
 };
 
 #define	AT25_WREN	0x06		/* latch the write enable */
@@ -173,6 +174,25 @@ static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command,
 	return status;
 }

drivers/misc/eeprom/at25.c static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command, · line 185

Quoted 10 lines
drivers/misc/eeprom/at25.c +9 -0
 
+static ssize_t sernum_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct at25_data *at25;
+	int i;
+
+	at25 = dev_get_drvdata(dev);
+	for (i = FM25_SN_LEN - 1; i >= 0; i--)
+		buf += sprintf(buf, "%02x", at25->sernum[i]);
+	sprintf(buf, "\n");

Please use sysfs_emit() with the proper print modifier for an array of bytes in hex (I think there is one...)

drivers/misc/eeprom/at25.c static int fm25_aux_read(struct at25_data *at25, char *buf, uint8_t command, · line 188

Quoted 3 lines
drivers/misc/eeprom/at25.c +3 -0
+	return (2 * FM25_SN_LEN + 1);
+}
+static DEVICE_ATTR(sernum, 0440, sernum_show, NULL);

DEVICE_ATTR_RO() please.

Quoted 11 lines
drivers/misc/eeprom/at25.c +7 -0
+
+static struct attribute *sernum_attrs[] = {
+	&dev_attr_sernum.attr,
+	NULL,
+};
+ATTRIBUTE_GROUPS(sernum);
+
 static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
 {
 	struct at25_data *at25 = priv;

drivers/misc/eeprom/at25.c static int at25_probe(struct spi_device *spi) · line 442

Quoted 7 lines
drivers/misc/eeprom/at25.c +2 -1
@@ -417,8 +437,13 @@ static int at25_probe(struct spi_device *spi)
 		else
 			at25->chip.flags |= EE_ADDR2;
 
-		if (id[8])
+		if (id[8]) {
 			at25->has_sernum = 1;
+			at25->sernum = kzalloc(FM25_SN_LEN, GFP_KERNEL);

Where do you free this memory?

And why does it have to be 0 filled?

thanks,

greg k-h

#7 lore raw

Re: [PATCH v6 4/5] nvmem: eeprom: at25: export FRAM serial num

In reply to Jiri Prchal
Quoted 22 lines · Jiri Prchal

This exports serial number of FRAM in sysfs file named "sernum". Formatted in hex, each byte separated by space. Example:

$ cat /sys/class/spi_master/spi0/spi0.0/sernum
0000a43644f2ae6c

---
v2: no change here
v3: resend and added more recipients
v4: resend
v5: reworked up on Greg comments: no spaces in string, sysfs done correctly
v6: no change here

---
 drivers/misc/eeprom/at25.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/misc/eeprom/at25.c +0 -0
index 45a486994828..4e4fa8d3ba5d 100644

drivers/misc/eeprom/at25.c struct at25_data { · line 42

Quoted 4 lines
drivers/misc/eeprom/at25.c +1 -0
@@ -39,6 +39,7 @@ struct at25_data {
 	struct nvmem_config	nvmem_config;
 	struct nvmem_device	*nvmem;
 	int has_sernum;
+	char *sernum;

If this really is only 8 bytes long, just make it an 8 byte array of u8 please.

thanks,

greg k-h

#8 lore raw

PATCH v6 5/5 nvmem: eeprom: add documentation of sysfs sernum file

In reply to Jiri Prchal

Added sysfs sernum file documentation.

---
v5: new
v6: no change here

---
 Documentation/ABI/testing/sysfs-class-spi-eeprom | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-spi-eeprom
Documentation/ABI/testing/sysfs-class-spi-eeprom new file +6 -0
new file mode 100644
index 000000000000..4f063a97b735
@@ -0,0 +1,6 @@
+What:		/sys/class/spi_master/spi<bus>/spi<bus>.<dev>/sernum
+Date:		May 2021
+KernelVersion:	5.12.1
+Contact:	Jiri Prchal <[email protected]>
+Description:
+		Exports serial number of Cypress FRAM (FM25VN). 8 bytes as is in chip in hex string.
Signature · 1 line
2.25.1