1 From 71261ca81b491a4c3b08690347c12e96a75ad0d0 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 3/5] wifi: rt2x00: Add support for loading EEPROM from MTD
6 Add support for loading EEPROM from MTD.
8 Signed-off-by: John Crispin <blogic@openwrt.org>
9 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
11 drivers/net/wireless/ralink/rt2x00/Kconfig | 1 +
12 .../net/wireless/ralink/rt2x00/rt2x00eeprom.c | 66 +++++++++++++++++++
13 2 files changed, 67 insertions(+)
15 --- a/drivers/net/wireless/ralink/rt2x00/Kconfig
16 +++ b/drivers/net/wireless/ralink/rt2x00/Kconfig
17 @@ -220,6 +220,7 @@ config RT2800SOC
18 select RT2X00_LIB_EEPROM
20 select RT2800_LIB_MMIO
21 + select MTD if SOC_RT288X || SOC_RT305X
23 This adds support for Ralink WiSoC devices.
24 Supported chips: RT2880, RT3050, RT3052, RT3350, RT3352.
25 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
26 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 +#if IS_ENABLED(CONFIG_MTD)
32 +#include <linux/mtd/mtd.h>
33 +#include <linux/mtd/partitions.h>
38 #include "rt2x00soc.h"
40 +#if IS_ENABLED(CONFIG_MTD)
41 +static int rt2800lib_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev)
45 + struct device_node *np = rt2x00dev->dev->of_node, *mtd_np = NULL;
46 + int size, offset = 0;
47 + struct mtd_info *mtd;
53 + list = of_get_property(np, "ralink,mtd-eeprom", &size);
57 + phandle = be32_to_cpup(list++);
59 + mtd_np = of_find_node_by_phandle(phandle);
61 + dev_err(rt2x00dev->dev, "failed to load mtd phandle\n");
65 + part = of_get_property(mtd_np, "label", NULL);
67 + part = mtd_np->name;
69 + mtd = get_mtd_device_nm(part);
71 + dev_err(rt2x00dev->dev, "failed to get mtd device \"%s\"\n", part);
72 + return PTR_ERR(mtd);
75 + if (size > sizeof(*list))
76 + offset = be32_to_cpup(list);
78 + ret = mtd_read(mtd, offset, rt2x00dev->ops->eeprom_size,
79 + &retlen, (u_char *)rt2x00dev->eeprom);
80 + put_mtd_device(mtd);
82 + if (retlen != rt2x00dev->ops->eeprom_size || ret) {
83 + dev_err(rt2x00dev->dev, "failed to load eeprom from device \"%s\"\n", part);
87 + dev_info(rt2x00dev->dev, "loaded eeprom from mtd device \"%s\"\n", part);
95 rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
97 @@ -83,5 +141,13 @@ err_exit:
99 int rt2x00lib_read_eeprom(struct rt2x00_dev *rt2x00dev)
103 +#if IS_ENABLED(CONFIG_MTD)
104 + ret = rt2800lib_read_eeprom_mtd(rt2x00dev);
109 return rt2x00lib_read_eeprom_file(rt2x00dev);