2013-04-04 22:57:43 +08:00
|
|
|
From 339fe73f340161a624cc08e738d2244814852c3e Mon Sep 17 00:00:00 2001
|
|
|
|
From: John Crispin <blogic@openwrt.org>
|
|
|
|
Date: Sun, 17 Mar 2013 00:55:04 +0100
|
|
|
|
Subject: [PATCH] rt2x00: load eeprom on SoC from a mtd device defines inside
|
|
|
|
OF
|
|
|
|
|
|
|
|
Signed-off-by: John Crispin <blogic@openwrt.org>
|
|
|
|
---
|
|
|
|
drivers/net/wireless/rt2x00/Kconfig | 1 +
|
|
|
|
drivers/net/wireless/rt2x00/rt2800pci.c | 44 ++++++++++++++++++++++++++-----
|
|
|
|
2 files changed, 39 insertions(+), 6 deletions(-)
|
|
|
|
|
2013-04-08 06:05:36 +08:00
|
|
|
--- a/drivers/net/wireless/rt2x00/Kconfig
|
|
|
|
+++ b/drivers/net/wireless/rt2x00/Kconfig
|
2013-11-13 06:11:33 +08:00
|
|
|
@@ -219,6 +219,7 @@ config RT2800SOC
|
2013-06-16 04:14:06 +08:00
|
|
|
select RT2X00_LIB_EEPROM
|
2013-11-13 06:11:33 +08:00
|
|
|
select RT2800_LIB
|
|
|
|
select RT2800_LIB_MMIO
|
2013-04-04 22:57:43 +08:00
|
|
|
+ select MTD if SOC_RT288X || SOC_RT305X
|
|
|
|
---help---
|
2013-11-13 06:11:33 +08:00
|
|
|
This adds support for Ralink WiSoC devices.
|
|
|
|
Supported chips: RT2880, RT3050, RT3052, RT3350, RT3352.
|
2013-04-08 06:05:36 +08:00
|
|
|
--- a/drivers/net/wireless/rt2x00/rt2x00eeprom.c
|
|
|
|
+++ b/drivers/net/wireless/rt2x00/rt2x00eeprom.c
|
2013-11-13 06:11:33 +08:00
|
|
|
@@ -26,17 +26,72 @@
|
2013-04-04 22:57:43 +08:00
|
|
|
|
2013-11-13 06:11:33 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2013-04-04 22:57:43 +08:00
|
|
|
+#include <linux/mtd/mtd.h>
|
|
|
|
+#include <linux/mtd/partitions.h>
|
2013-11-13 06:11:33 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
|
|
|
|
#include "rt2x00.h"
|
|
|
|
#include "rt2x00lib.h"
|
|
|
|
|
|
|
|
+static int rt2800lib_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev)
|
2013-04-04 22:57:43 +08:00
|
|
|
+{
|
2013-11-13 06:11:33 +08:00
|
|
|
+ int ret = -EINVAL;
|
|
|
|
+#ifdef CONFIG_OF
|
|
|
|
+ static struct firmware mtd_fw;
|
2013-04-04 22:57:43 +08:00
|
|
|
+ struct device_node *np = rt2x00dev->dev->of_node, *mtd_np = NULL;
|
|
|
|
+ size_t retlen, len = rt2x00dev->ops->eeprom_size;
|
2013-11-13 06:11:33 +08:00
|
|
|
+ int size, offset = 0;
|
2013-04-04 22:57:43 +08:00
|
|
|
+ struct mtd_info *mtd;
|
|
|
|
+ const char *part;
|
|
|
|
+ const __be32 *list;
|
|
|
|
+ phandle phandle;
|
|
|
|
+
|
|
|
|
+ list = of_get_property(np, "ralink,mtd-eeprom", &size);
|
|
|
|
+ if (!list) {
|
|
|
|
+ dev_err(rt2x00dev->dev, "failed to load eeprom property\n");
|
|
|
|
+ return -ENOENT;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ phandle = be32_to_cpup(list++);
|
|
|
|
+ if (phandle)
|
|
|
|
+ mtd_np = of_find_node_by_phandle(phandle);
|
|
|
|
+ if (!mtd_np) {
|
|
|
|
+ dev_err(rt2x00dev->dev, "failed to load mtd phandle\n");
|
|
|
|
+ return -EINVAL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ part = of_get_property(mtd_np, "label", NULL);
|
|
|
|
+ if (!part)
|
|
|
|
+ part = mtd_np->name;
|
|
|
|
+
|
|
|
|
+ mtd = get_mtd_device_nm(part);
|
|
|
|
+ if (IS_ERR(mtd)) {
|
|
|
|
+ dev_err(rt2x00dev->dev, "failed to get mtd device \"%s\"\n", part);
|
|
|
|
+ return PTR_ERR(mtd);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (size > sizeof(*list))
|
|
|
|
+ offset = be32_to_cpup(list);
|
|
|
|
+
|
|
|
|
+ ret = mtd_read(mtd, offset, len, &retlen, (u_char *) rt2x00dev->eeprom);
|
|
|
|
+ put_mtd_device(mtd);
|
|
|
|
+
|
|
|
|
+ if (!ret) {
|
|
|
|
+ rt2x00dev->eeprom_file = &mtd_fw;
|
|
|
|
+ mtd_fw.size = len;
|
|
|
|
+ mtd_fw.data = rt2x00dev->eeprom;
|
|
|
|
+ }
|
2013-11-13 06:11:33 +08:00
|
|
|
+#endif
|
2013-04-04 22:57:43 +08:00
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
2013-11-13 06:11:33 +08:00
|
|
|
static const char *
|
|
|
|
rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
|
|
|
|
{
|
|
|
|
struct rt2x00_platform_data *pdata = rt2x00dev->dev->platform_data;
|
|
|
|
struct device_node *np;
|
|
|
|
- char *eep;
|
|
|
|
+ const char *eep;
|
|
|
|
|
|
|
|
if (pdata && pdata->eeprom_file_name)
|
|
|
|
return pdata->eeprom_file_name;
|
|
|
|
@@ -53,9 +108,12 @@ rt2x00lib_get_eeprom_file_name(struct rt
|
2013-04-04 22:57:43 +08:00
|
|
|
static int rt2x00lib_request_eeprom_file(struct rt2x00_dev *rt2x00dev)
|
|
|
|
{
|
|
|
|
const struct firmware *ee;
|
2013-11-13 06:11:33 +08:00
|
|
|
- char *ee_name;
|
|
|
|
+ const char *ee_name;
|
2013-04-04 22:57:43 +08:00
|
|
|
int retval;
|
|
|
|
|
2013-11-13 06:11:33 +08:00
|
|
|
+ if (!rt2800lib_read_eeprom_mtd(rt2x00dev))
|
2013-04-04 22:57:43 +08:00
|
|
|
+ return 0;
|
|
|
|
+
|
2013-11-13 06:11:33 +08:00
|
|
|
ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
|
2013-04-04 22:57:43 +08:00
|
|
|
if (!ee_name) {
|
2013-06-16 04:14:06 +08:00
|
|
|
rt2x00_err(rt2x00dev,
|