2013-04-04 14:57:43 +00: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>
|
|
|
|
---
|
2016-11-04 06:43:39 +00:00
|
|
|
drivers/net/wireless/ralink/rt2x00/Kconfig | 1 +
|
2016-11-04 06:43:40 +00:00
|
|
|
drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c | 65 +++++++++++++++++++++++
|
|
|
|
2 files changed, 66 insertions(+)
|
2013-04-04 14:57:43 +00:00
|
|
|
|
2015-12-04 22:39:37 +00:00
|
|
|
--- a/drivers/net/wireless/ralink/rt2x00/Kconfig
|
|
|
|
+++ b/drivers/net/wireless/ralink/rt2x00/Kconfig
|
2013-11-12 22:11:33 +00:00
|
|
|
@@ -219,6 +219,7 @@ config RT2800SOC
|
2013-06-15 20:14:06 +00:00
|
|
|
select RT2X00_LIB_EEPROM
|
2013-11-12 22:11:33 +00:00
|
|
|
select RT2800_LIB
|
|
|
|
select RT2800_LIB_MMIO
|
2013-04-04 14:57:43 +00:00
|
|
|
+ select MTD if SOC_RT288X || SOC_RT305X
|
|
|
|
---help---
|
2013-11-12 22:11:33 +00:00
|
|
|
This adds support for Ralink WiSoC devices.
|
|
|
|
Supported chips: RT2880, RT3050, RT3052, RT3350, RT3352.
|
2015-12-04 22:39:37 +00:00
|
|
|
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
|
|
|
|
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
|
2019-02-24 09:23:18 +00:00
|
|
|
@@ -26,11 +26,72 @@
|
2013-04-04 14:57:43 +00:00
|
|
|
|
2013-11-12 22:11:33 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2013-04-04 14:57:43 +00:00
|
|
|
+#include <linux/mtd/mtd.h>
|
|
|
|
+#include <linux/mtd/partitions.h>
|
2013-11-12 22:11:33 +00:00
|
|
|
#include <linux/of.h>
|
|
|
|
|
|
|
|
#include "rt2x00.h"
|
|
|
|
#include "rt2x00lib.h"
|
|
|
|
|
|
|
|
+static int rt2800lib_read_eeprom_mtd(struct rt2x00_dev *rt2x00dev)
|
2013-04-04 14:57:43 +00:00
|
|
|
+{
|
2013-11-12 22:11:33 +00:00
|
|
|
+ int ret = -EINVAL;
|
|
|
|
+#ifdef CONFIG_OF
|
|
|
|
+ static struct firmware mtd_fw;
|
2013-04-04 14:57:43 +00:00
|
|
|
+ struct device_node *np = rt2x00dev->dev->of_node, *mtd_np = NULL;
|
|
|
|
+ size_t retlen, len = rt2x00dev->ops->eeprom_size;
|
2016-11-04 06:43:40 +00:00
|
|
|
+ int i, size, offset = 0;
|
2013-04-04 14:57:43 +00:00
|
|
|
+ struct mtd_info *mtd;
|
|
|
|
+ const char *part;
|
|
|
|
+ const __be32 *list;
|
|
|
|
+ phandle phandle;
|
|
|
|
+
|
|
|
|
+ list = of_get_property(np, "ralink,mtd-eeprom", &size);
|
2016-11-04 06:43:39 +00:00
|
|
|
+ if (!list)
|
2013-04-04 14:57:43 +00:00
|
|
|
+ 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);
|
|
|
|
+
|
2016-11-04 06:43:39 +00:00
|
|
|
+ if ((retlen != rt2x00dev->ops->eeprom_size) || ret) {
|
|
|
|
+ dev_err(rt2x00dev->dev, "failed to load eeprom from device \"%s\"\n", part);
|
|
|
|
+ return ret;
|
2013-04-04 14:57:43 +00:00
|
|
|
+ }
|
2016-11-04 06:43:39 +00:00
|
|
|
+
|
2016-11-04 06:43:40 +00:00
|
|
|
+ if (of_find_property(np, "ralink,mtd-eeprom-swap", NULL))
|
|
|
|
+ for (i = 0; i < len/sizeof(u16); i++)
|
|
|
|
+ rt2x00dev->eeprom[i] = swab16(rt2x00dev->eeprom[i]);
|
|
|
|
+
|
2016-11-04 06:43:39 +00:00
|
|
|
+ rt2x00dev->eeprom_file = &mtd_fw;
|
|
|
|
+ mtd_fw.data = (const u8 *) rt2x00dev->eeprom;
|
|
|
|
+
|
|
|
|
+ dev_info(rt2x00dev->dev, "loaded eeprom from mtd device \"%s\"\n", part);
|
2013-11-12 22:11:33 +00:00
|
|
|
+#endif
|
2013-04-04 14:57:43 +00:00
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
2013-11-12 22:11:33 +00:00
|
|
|
static const char *
|
|
|
|
rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
|
|
|
|
{
|
2019-02-24 09:23:18 +00:00
|
|
|
@@ -58,6 +119,9 @@ static int rt2x00lib_request_eeprom_file
|
2014-01-30 13:21:36 +00:00
|
|
|
const char *ee_name;
|
2013-04-04 14:57:43 +00:00
|
|
|
int retval;
|
|
|
|
|
2013-11-12 22:11:33 +00:00
|
|
|
+ if (!rt2800lib_read_eeprom_mtd(rt2x00dev))
|
2013-04-04 14:57:43 +00:00
|
|
|
+ return 0;
|
|
|
|
+
|
2013-11-12 22:11:33 +00:00
|
|
|
ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
|
2016-11-04 06:43:38 +00:00
|
|
|
if (!ee_name && test_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags)) {
|
|
|
|
rt2x00_err(rt2x00dev, "Required EEPROM name is missing.");
|