1 From 9008cdacdc41f8233f4444b86cf3a17201686e2d Mon Sep 17 00:00:00 2001
2 From: Shiji Yang <yangshiji66@outlook.com>
3 Date: Tue, 18 Jul 2023 20:18:16 +0800
4 Subject: [PATCH 5/5] wifi: rt2x00: support loading eeprom from NVMEM cells
6 This patch allows rt2x00 to load eeprom from "eeprom" NVMEM cell.
10 /* load eeprom from NVMEM provider 'eep' */
13 nvmem-cell-names = "eeprom";
16 Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
17 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
19 .../net/wireless/ralink/rt2x00/rt2x00eeprom.c | 41 ++++++++++++++++++-
20 1 file changed, 40 insertions(+), 1 deletion(-)
22 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
23 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/partitions.h>
28 +#include <linux/nvmem-consumer.h>
32 #include "rt2x00soc.h"
34 -#if IS_ENABLED(CONFIG_MTD)
35 static void rt2800lib_eeprom_swap(struct rt2x00_dev *rt2x00dev)
37 struct device_node *np = rt2x00dev->dev->of_node;
38 @@ -33,6 +33,7 @@ static void rt2800lib_eeprom_swap(struct
39 rt2x00dev->eeprom[i] = swab16(rt2x00dev->eeprom[i]);
42 +#if IS_ENABLED(CONFIG_MTD)
43 static int rt2800lib_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev)
46 @@ -88,6 +89,40 @@ static int rt2800lib_read_eeprom_mtd(str
50 +static int rt2800lib_read_eeprom_nvmem(struct rt2x00_dev *rt2x00dev)
52 + struct device_node *np = rt2x00dev->dev->of_node;
53 + unsigned int len = rt2x00dev->ops->eeprom_size;
54 + struct nvmem_cell *cell;
59 + cell = of_nvmem_cell_get(np, "eeprom");
61 + return PTR_ERR(cell);
63 + data = nvmem_cell_read(cell, &retlen);
64 + nvmem_cell_put(cell);
67 + return PTR_ERR(data);
69 + if (retlen != len) {
70 + dev_err(rt2x00dev->dev, "invalid eeprom size, required: 0x%04x\n", len);
75 + memcpy(rt2x00dev->eeprom, data, len);
77 + rt2800lib_eeprom_swap(rt2x00dev);
85 rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
87 @@ -164,5 +199,9 @@ int rt2x00lib_read_eeprom(struct rt2x00_
91 + ret = rt2800lib_read_eeprom_nvmem(rt2x00dev);
95 return rt2x00lib_read_eeprom_file(rt2x00dev);