Skip to contentSkip to conversation

add support for FRAM

PATCH Superseded Jiri Prchal 1 participant 5 messages Apr 20, 2021

Subsystems (3)

v3 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v3 cover add support for FRAM

Adds sopport for Cypress FRAMs.

Jiri Prchal (4):
nvmem: eeprom: at25: add support for FRAM
nvmem: eeprom: at25: add support for FRAM
nvmem: eeprom: add documentation for FRAM
nvmem: eeprom: at25: export FRAM serial num

 .../devicetree/bindings/eeprom/at25.yaml      |  31 ++-
 drivers/misc/eeprom/Kconfig                   |   5 +-
 drivers/misc/eeprom/at25.c                    | 177 +++++++++++++++---
 drivers/nvmem/core.c                          |   4 +
 include/linux/nvmem-provider.h                |   1 +
 5 files changed, 180 insertions(+), 38 deletions(-)
Signature · 3 lines
v3: resend and added more recepients
---
2.25.1
#1 lore raw

PATCH v3 1/4 nvmem: eeprom: at25: add support for FRAM

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

---
 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

PATCH v3 2/4 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

---
 drivers/misc/eeprom/Kconfig |   5 +-
 drivers/misc/eeprom/at25.c  | 151 +++++++++++++++++++++++++++++-------
 2 files changed, 124 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 +121 -30

229 lines not on this page · raw message

Signature · 1 line
2.25.1
#3 lore raw

PATCH v3 3/4 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

---
 .../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
#4 lore raw

PATCH v3 4/4 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
a4 36 44 f2 ae 6c 00 00
---
 drivers/misc/eeprom/at25.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/misc/eeprom/at25.c +27 -1
index 4f6e983c278b..b2cffeb3af2c 100644
@@ -38,6 +38,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 */
@@ -172,6 +173,19 @@ 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 = 0; i < FM25_SN_LEN; i++)
+		buf += sprintf(buf, "%02x ", at25->sernum[i]);
+	sprintf(--buf, "\n");
+	return (3 * i);
+}
+static DEVICE_ATTR_RO(sernum);
+
 static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
 {
 	struct at25_data *at25 = priv;
@@ -427,8 +441,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;
 
@@ -467,6 +486,13 @@ static int at25_probe(struct spi_device *spi)
 	if (IS_ERR(at25->nvmem))
 		return PTR_ERR(at25->nvmem);
 
+	/* Export the FM25 serial number */
+	if (at25->has_sernum) {
+		err = device_create_file(&spi->dev, &dev_attr_sernum);
+		if (err)
+			return err;
+	}
+
 	dev_info(&spi->dev, "%d %s %s %s%s, pagesize %u\n",
 		 (chip.byte_len < 1024) ? chip.byte_len : (chip.byte_len / 1024),
 		 (chip.byte_len < 1024) ? "Byte" : "KByte",
Signature · 1 line
2.25.1