1 From 339fe73f340161a624cc08e738d2244814852c3e Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sun, 17 Mar 2013 00:55:04 +0100
4 Subject: [PATCH] rt2x00: load eeprom on SoC from a mtd device defines inside
7 Signed-off-by: John Crispin <blogic@openwrt.org>
9 drivers/net/wireless/ralink/rt2x00/Kconfig | 1 +
10 drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c | 65 +++++++++++++++++++++++
11 2 files changed, 66 insertions(+)
13 --- a/drivers/net/wireless/ralink/rt2x00/Kconfig
14 +++ b/drivers/net/wireless/ralink/rt2x00/Kconfig
15 @@ -220,6 +220,7 @@ config RT2800SOC
16 select RT2X00_LIB_EEPROM
18 select RT2800_LIB_MMIO
19 + select MTD if SOC_RT288X || SOC_RT305X
21 This adds support for Ralink WiSoC devices.
22 Supported chips: RT2880, RT3050, RT3052, RT3350, RT3352.
23 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
24 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 +#if IS_ENABLED(CONFIG_MTD)
30 +#include <linux/mtd/mtd.h>
31 +#include <linux/mtd/partitions.h>
36 #include "rt2x00lib.h"
38 +#if IS_ENABLED(CONFIG_MTD)
39 +static int rt2800lib_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev)
43 + static struct firmware mtd_fw;
44 + struct device_node *np = rt2x00dev->dev->of_node, *mtd_np = NULL;
45 + size_t retlen, len = rt2x00dev->ops->eeprom_size;
46 + int i, size, offset = 0;
47 + struct mtd_info *mtd;
52 + list = of_get_property(np, "ralink,mtd-eeprom", &size);
56 + phandle = be32_to_cpup(list++);
58 + mtd_np = of_find_node_by_phandle(phandle);
60 + dev_err(rt2x00dev->dev, "failed to load mtd phandle\n");
64 + part = of_get_property(mtd_np, "label", NULL);
66 + part = mtd_np->name;
68 + mtd = get_mtd_device_nm(part);
70 + dev_err(rt2x00dev->dev, "failed to get mtd device \"%s\"\n", part);
71 + return PTR_ERR(mtd);
74 + if (size > sizeof(*list))
75 + offset = be32_to_cpup(list);
77 + ret = mtd_read(mtd, offset, len, &retlen, (u_char *) rt2x00dev->eeprom);
78 + put_mtd_device(mtd);
80 + if ((retlen != rt2x00dev->ops->eeprom_size) || ret) {
81 + dev_err(rt2x00dev->dev, "failed to load eeprom from device \"%s\"\n", part);
85 + if (of_find_property(np, "ralink,mtd-eeprom-swap", NULL))
86 + for (i = 0; i < len/sizeof(u16); i++)
87 + rt2x00dev->eeprom[i] = swab16(rt2x00dev->eeprom[i]);
89 + rt2x00dev->eeprom_file = &mtd_fw;
90 + mtd_fw.data = (const u8 *) rt2x00dev->eeprom;
92 + dev_info(rt2x00dev->dev, "loaded eeprom from mtd device \"%s\"\n", part);
100 rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
102 @@ -58,6 +123,11 @@ static int rt2x00lib_request_eeprom_file
106 +#if IS_ENABLED(CONFIG_MTD)
107 + if (!rt2800lib_read_eeprom_mtd(rt2x00dev))
111 ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
112 if (!ee_name && test_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags)) {
113 rt2x00_err(rt2x00dev, "Required EEPROM name is missing.");