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 @@ -219,6 +219,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 +#include <linux/mtd/mtd.h>
30 +#include <linux/mtd/partitions.h>
34 #include "rt2x00lib.h"
36 +static int rt2800lib_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev)
40 + static struct firmware mtd_fw;
41 + struct device_node *np = rt2x00dev->dev->of_node, *mtd_np = NULL;
42 + size_t retlen, len = rt2x00dev->ops->eeprom_size;
43 + int i, size, offset = 0;
44 + struct mtd_info *mtd;
49 + list = of_get_property(np, "ralink,mtd-eeprom", &size);
53 + phandle = be32_to_cpup(list++);
55 + mtd_np = of_find_node_by_phandle(phandle);
57 + dev_err(rt2x00dev->dev, "failed to load mtd phandle\n");
61 + part = of_get_property(mtd_np, "label", NULL);
63 + part = mtd_np->name;
65 + mtd = get_mtd_device_nm(part);
67 + dev_err(rt2x00dev->dev, "failed to get mtd device \"%s\"\n", part);
68 + return PTR_ERR(mtd);
71 + if (size > sizeof(*list))
72 + offset = be32_to_cpup(list);
74 + ret = mtd_read(mtd, offset, len, &retlen, (u_char *) rt2x00dev->eeprom);
75 + put_mtd_device(mtd);
77 + if ((retlen != rt2x00dev->ops->eeprom_size) || ret) {
78 + dev_err(rt2x00dev->dev, "failed to load eeprom from device \"%s\"\n", part);
82 + if (of_find_property(np, "ralink,mtd-eeprom-swap", NULL))
83 + for (i = 0; i < len/sizeof(u16); i++)
84 + rt2x00dev->eeprom[i] = swab16(rt2x00dev->eeprom[i]);
86 + rt2x00dev->eeprom_file = &mtd_fw;
88 + mtd_fw.data = (const u8 *) rt2x00dev->eeprom;
90 + dev_info(rt2x00dev->dev, "loaded eeprom from mtd device \"%s\"\n", part);
97 rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
99 @@ -58,6 +120,9 @@ static int rt2x00lib_request_eeprom_file
103 + if (!rt2800lib_read_eeprom_mtd(rt2x00dev))
106 ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
107 if (!ee_name && test_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags)) {
108 rt2x00_err(rt2x00dev, "Required EEPROM name is missing.");