2023-10-15 14:07:22 +00:00
|
|
|
From 71261ca81b491a4c3b08690347c12e96a75ad0d0 Mon Sep 17 00:00:00 2001
|
2013-04-04 14:57:43 +00:00
|
|
|
From: John Crispin <blogic@openwrt.org>
|
|
|
|
Date: Sun, 17 Mar 2013 00:55:04 +0100
|
2023-10-15 14:07:22 +00:00
|
|
|
Subject: [PATCH 3/5] wifi: rt2x00: Add support for loading EEPROM from MTD
|
|
|
|
|
|
|
|
Add support for loading EEPROM from MTD.
|
2013-04-04 14:57:43 +00:00
|
|
|
|
|
|
|
Signed-off-by: John Crispin <blogic@openwrt.org>
|
2023-10-15 14:07:22 +00:00
|
|
|
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
|
2013-04-04 14:57:43 +00:00
|
|
|
---
|
2023-10-15 14:07:22 +00:00
|
|
|
drivers/net/wireless/ralink/rt2x00/Kconfig | 1 +
|
|
|
|
.../net/wireless/ralink/rt2x00/rt2x00eeprom.c | 66 +++++++++++++++++++
|
|
|
|
2 files changed, 67 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
|
2019-07-06 22:08:20 +00:00
|
|
|
@@ -220,6 +220,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
|
2020-06-20 21:11:17 +00:00
|
|
|
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
|
2023-10-15 14:07:22 +00:00
|
|
|
@@ -10,11 +10,69 @@
|
2013-04-04 14:57:43 +00:00
|
|
|
|
2013-11-12 22:11:33 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2020-02-23 19:26:46 +00:00
|
|
|
+#if IS_ENABLED(CONFIG_MTD)
|
2013-04-04 14:57:43 +00:00
|
|
|
+#include <linux/mtd/mtd.h>
|
|
|
|
+#include <linux/mtd/partitions.h>
|
2020-02-23 19:26:46 +00:00
|
|
|
+#endif
|
2013-11-12 22:11:33 +00:00
|
|
|
#include <linux/of.h>
|
|
|
|
|
|
|
|
#include "rt2x00.h"
|
2023-10-15 14:07:22 +00:00
|
|
|
#include "rt2x00soc.h"
|
2013-11-12 22:11:33 +00:00
|
|
|
|
2020-02-23 19:26:46 +00:00
|
|
|
+#if IS_ENABLED(CONFIG_MTD)
|
2013-11-12 22:11:33 +00:00
|
|
|
+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
|
2013-04-04 14:57:43 +00:00
|
|
|
+ struct device_node *np = rt2x00dev->dev->of_node, *mtd_np = NULL;
|
2023-10-15 14:07:22 +00:00
|
|
|
+ int size, offset = 0;
|
2013-04-04 14:57:43 +00:00
|
|
|
+ struct mtd_info *mtd;
|
|
|
|
+ const char *part;
|
|
|
|
+ const __be32 *list;
|
|
|
|
+ phandle phandle;
|
2023-10-15 14:07:22 +00:00
|
|
|
+ size_t retlen;
|
2013-04-04 14:57:43 +00:00
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+
|
2023-10-15 14:07:22 +00:00
|
|
|
+ ret = mtd_read(mtd, offset, rt2x00dev->ops->eeprom_size,
|
|
|
|
+ &retlen, (u_char *)rt2x00dev->eeprom);
|
2013-04-04 14:57:43 +00:00
|
|
|
+ put_mtd_device(mtd);
|
|
|
|
+
|
2023-10-15 14:07:22 +00:00
|
|
|
+ if (retlen != rt2x00dev->ops->eeprom_size || ret) {
|
2016-11-04 06:43:39 +00:00
|
|
|
+ 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
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+}
|
2020-02-23 19:26:46 +00:00
|
|
|
+#endif
|
2013-04-04 14:57:43 +00:00
|
|
|
+
|
2013-11-12 22:11:33 +00:00
|
|
|
static const char *
|
|
|
|
rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
|
|
|
|
{
|
2023-10-25 12:09:23 +00:00
|
|
|
@@ -83,6 +141,14 @@ err_exit:
|
2013-04-04 14:57:43 +00:00
|
|
|
|
2023-10-15 14:07:22 +00:00
|
|
|
int rt2x00lib_read_eeprom(struct rt2x00_dev *rt2x00dev)
|
|
|
|
{
|
|
|
|
+ int ret;
|
|
|
|
+
|
2020-02-23 19:26:46 +00:00
|
|
|
+#if IS_ENABLED(CONFIG_MTD)
|
2023-10-15 14:07:22 +00:00
|
|
|
+ ret = rt2800lib_read_eeprom_mtd(rt2x00dev);
|
|
|
|
+ if (!ret)
|
2013-04-04 14:57:43 +00:00
|
|
|
+ return 0;
|
2020-02-23 19:26:46 +00:00
|
|
|
+#endif
|
2013-04-04 14:57:43 +00:00
|
|
|
+
|
2023-10-15 14:07:22 +00:00
|
|
|
return rt2x00lib_read_eeprom_file(rt2x00dev);
|
|
|
|
}
|
2023-10-25 12:09:23 +00:00
|
|
|
EXPORT_SYMBOL_GPL(rt2x00lib_read_eeprom);
|