2016-01-18 11:40:19 +00:00
|
|
|
From f8c5db89e793a4bc6c1e87bd7b3a5cec16b75bc3 Mon Sep 17 00:00:00 2001
|
|
|
|
From: John Crispin <blogic@openwrt.org>
|
|
|
|
Date: Wed, 10 Sep 2014 22:42:14 +0200
|
|
|
|
Subject: [PATCH 35/36] owrt: lantiq: wifi and ethernet eeprom handling
|
|
|
|
|
|
|
|
Signed-off-by: John Crispin <blogic@openwrt.org>
|
|
|
|
---
|
2016-11-03 07:45:33 +00:00
|
|
|
.../mips/include/asm/mach-lantiq/xway/lantiq_soc.h | 3 +
|
|
|
|
arch/mips/lantiq/xway/Makefile | 3 +
|
2016-08-06 07:19:45 +00:00
|
|
|
arch/mips/lantiq/xway/ath5k_eep.c | 136 +++++++++++++++++++++
|
|
|
|
arch/mips/lantiq/xway/eth_mac.c | 25 ++++
|
2016-11-03 07:45:33 +00:00
|
|
|
drivers/net/ethernet/lantiq_etop.c | 6 +-
|
2016-08-06 07:19:45 +00:00
|
|
|
5 files changed, 172 insertions(+), 1 deletion(-)
|
|
|
|
create mode 100644 arch/mips/lantiq/xway/ath5k_eep.c
|
2016-01-18 11:40:19 +00:00
|
|
|
create mode 100644 arch/mips/lantiq/xway/eth_mac.c
|
|
|
|
|
|
|
|
--- a/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
|
|
|
|
+++ b/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
|
2016-06-15 12:17:27 +00:00
|
|
|
@@ -104,5 +104,8 @@ int xrx200_gphy_boot(struct device *dev,
|
2016-01-18 11:40:19 +00:00
|
|
|
extern void ltq_pmu_enable(unsigned int module);
|
|
|
|
extern void ltq_pmu_disable(unsigned int module);
|
|
|
|
|
|
|
|
+/* allow the ethernet driver to load a flash mapped mac addr */
|
|
|
|
+const u8* ltq_get_eth_mac(void);
|
|
|
|
+
|
|
|
|
#endif /* CONFIG_SOC_TYPE_XWAY */
|
|
|
|
#endif /* _LTQ_XWAY_H__ */
|
|
|
|
--- a/arch/mips/lantiq/xway/Makefile
|
|
|
|
+++ b/arch/mips/lantiq/xway/Makefile
|
2016-06-15 12:17:27 +00:00
|
|
|
@@ -2,4 +2,7 @@ obj-y := prom.o sysctrl.o clk.o reset.o
|
2016-01-18 11:40:19 +00:00
|
|
|
|
2017-03-25 18:24:26 +00:00
|
|
|
obj-y += vmmc.o
|
2016-01-18 11:40:19 +00:00
|
|
|
|
|
|
|
+obj-y += eth_mac.o
|
2016-08-06 07:19:45 +00:00
|
|
|
+obj-$(CONFIG_PCI) += ath5k_eep.o
|
2016-01-18 11:40:19 +00:00
|
|
|
+
|
|
|
|
obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
|
|
|
|
--- /dev/null
|
2016-08-06 07:19:45 +00:00
|
|
|
+++ b/arch/mips/lantiq/xway/ath5k_eep.c
|
|
|
|
@@ -0,0 +1,136 @@
|
2016-01-18 11:40:19 +00:00
|
|
|
+/*
|
|
|
|
+ * Copyright (C) 2011 Luca Olivetti <luca@ventoso.org>
|
|
|
|
+ * Copyright (C) 2011 John Crispin <blogic@openwrt.org>
|
|
|
|
+ * Copyright (C) 2011 Andrej Vlašić <andrej.vlasic0@gmail.com>
|
|
|
|
+ * Copyright (C) 2013 Álvaro Fernández Rojas <noltari@gmail.com>
|
|
|
|
+ * Copyright (C) 2013 Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
|
|
|
|
+ * Copyright (C) 2015 Vittorio Gambaletta <openwrt@vittgam.net>
|
|
|
|
+ *
|
|
|
|
+ * This program is free software; you can redistribute it and/or modify it
|
|
|
|
+ * under the terms of the GNU General Public License version 2 as published
|
|
|
|
+ * by the Free Software Foundation.
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+#include <linux/init.h>
|
|
|
|
+#include <linux/platform_device.h>
|
|
|
|
+#include <linux/etherdevice.h>
|
|
|
|
+#include <linux/ath5k_platform.h>
|
|
|
|
+#include <linux/pci.h>
|
|
|
|
+#include <linux/err.h>
|
|
|
|
+#include <linux/mtd/mtd.h>
|
|
|
|
+#include <lantiq_soc.h>
|
|
|
|
+
|
|
|
|
+extern int (*ltq_pci_plat_dev_init)(struct pci_dev *dev);
|
|
|
|
+struct ath5k_platform_data ath5k_pdata;
|
|
|
|
+static u8 athxk_eeprom_mac[6];
|
|
|
|
+
|
|
|
|
+static int ath5k_pci_plat_dev_init(struct pci_dev *dev)
|
|
|
|
+{
|
|
|
|
+ dev->dev.platform_data = &ath5k_pdata;
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
2016-08-23 19:14:36 +00:00
|
|
|
+static int ath5k_eep_load;
|
2016-01-18 11:40:19 +00:00
|
|
|
+int __init of_ath5k_eeprom_probe(struct platform_device *pdev)
|
|
|
|
+{
|
2016-08-02 20:25:59 +00:00
|
|
|
+ struct device_node *np = pdev->dev.of_node, *mtd_np = NULL;
|
2016-01-18 11:40:19 +00:00
|
|
|
+ int mac_offset;
|
|
|
|
+ u32 mac_inc = 0;
|
|
|
|
+ int i;
|
|
|
|
+ struct mtd_info *the_mtd;
|
|
|
|
+ size_t flash_readlen;
|
|
|
|
+ const __be32 *list;
|
|
|
|
+ const char *part;
|
|
|
|
+ phandle phandle;
|
|
|
|
+
|
2016-08-02 20:25:59 +00:00
|
|
|
+ list = of_get_property(np, "ath,eep-flash", &i);
|
|
|
|
+ if (!list || (i != (2 * sizeof(*list))))
|
|
|
|
+ return -ENODEV;
|
|
|
|
+
|
|
|
|
+ phandle = be32_to_cpup(list++);
|
|
|
|
+ if (phandle)
|
|
|
|
+ mtd_np = of_find_node_by_phandle(phandle);
|
|
|
|
+
|
|
|
|
+ if (!mtd_np)
|
|
|
|
+ return -ENODEV;
|
|
|
|
+
|
|
|
|
+ part = of_get_property(mtd_np, "label", NULL);
|
|
|
|
+ if (!part)
|
|
|
|
+ part = mtd_np->name;
|
|
|
|
+
|
|
|
|
+ the_mtd = get_mtd_device_nm(part);
|
|
|
|
+ if (IS_ERR(the_mtd))
|
|
|
|
+ return -ENODEV;
|
|
|
|
+
|
2016-08-23 19:14:36 +00:00
|
|
|
+ ath5k_pdata.eeprom_data = kmalloc(ATH5K_PLAT_EEP_MAX_WORDS<<1, GFP_KERNEL);
|
|
|
|
+
|
2016-08-02 20:25:59 +00:00
|
|
|
+ i = mtd_read(the_mtd, be32_to_cpup(list), ATH5K_PLAT_EEP_MAX_WORDS << 1,
|
2016-08-23 19:14:36 +00:00
|
|
|
+ &flash_readlen, (void *) ath5k_pdata.eeprom_data);
|
2016-08-02 20:25:59 +00:00
|
|
|
+
|
2016-08-23 19:14:36 +00:00
|
|
|
+ if (!of_property_read_u32(np, "ath,mac-offset", &mac_offset)) {
|
|
|
|
+ size_t mac_readlen;
|
|
|
|
+ mtd_read(the_mtd, mac_offset, 6, &mac_readlen,
|
|
|
|
+ (void *) athxk_eeprom_mac);
|
|
|
|
+ }
|
2016-08-02 20:25:59 +00:00
|
|
|
+ put_mtd_device(the_mtd);
|
|
|
|
+
|
2016-08-23 19:14:36 +00:00
|
|
|
+ if (((ATH5K_PLAT_EEP_MAX_WORDS<<1) != flash_readlen) || i) {
|
2016-08-02 20:25:59 +00:00
|
|
|
+ dev_err(&pdev->dev, "failed to load eeprom from mtd\n");
|
|
|
|
+ return -ENODEV;
|
2016-01-18 11:40:19 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (of_find_property(np, "ath,eep-swap", NULL))
|
|
|
|
+ for (i = 0; i < ATH5K_PLAT_EEP_MAX_WORDS; i++)
|
|
|
|
+ ath5k_pdata.eeprom_data[i] = swab16(ath5k_pdata.eeprom_data[i]);
|
|
|
|
+
|
2016-08-02 20:25:59 +00:00
|
|
|
+ if (!is_valid_ether_addr(athxk_eeprom_mac) && ltq_get_eth_mac())
|
2016-08-23 19:14:36 +00:00
|
|
|
+ ether_addr_copy(athxk_eeprom_mac, ltq_get_eth_mac());
|
2016-08-02 20:25:59 +00:00
|
|
|
+
|
|
|
|
+ if (!is_valid_ether_addr(athxk_eeprom_mac)) {
|
2016-01-18 11:40:19 +00:00
|
|
|
+ dev_warn(&pdev->dev, "using random mac\n");
|
|
|
|
+ random_ether_addr(athxk_eeprom_mac);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!of_property_read_u32(np, "ath,mac-increment", &mac_inc))
|
|
|
|
+ athxk_eeprom_mac[5] += mac_inc;
|
|
|
|
+
|
|
|
|
+ ath5k_pdata.macaddr = athxk_eeprom_mac;
|
|
|
|
+ ltq_pci_plat_dev_init = ath5k_pci_plat_dev_init;
|
|
|
|
+
|
|
|
|
+ dev_info(&pdev->dev, "loaded ath5k eeprom\n");
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static struct of_device_id ath5k_eeprom_ids[] = {
|
|
|
|
+ { .compatible = "ath5k,eeprom" },
|
|
|
|
+ { }
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static struct platform_driver ath5k_eeprom_driver = {
|
|
|
|
+ .driver = {
|
|
|
|
+ .name = "ath5k,eeprom",
|
|
|
|
+ .owner = THIS_MODULE,
|
|
|
|
+ .of_match_table = of_match_ptr(ath5k_eeprom_ids),
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static int __init of_ath5k_eeprom_init(void)
|
|
|
|
+{
|
2016-08-23 19:14:36 +00:00
|
|
|
+ int ret = platform_driver_probe(&ath5k_eeprom_driver, of_ath5k_eeprom_probe);
|
|
|
|
+
|
|
|
|
+ if (ret)
|
|
|
|
+ ath5k_eep_load = 1;
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int __init of_ath5k_eeprom_init_late(void)
|
|
|
|
+{
|
|
|
|
+ if (!ath5k_eep_load)
|
|
|
|
+ return 0;
|
|
|
|
+
|
2016-01-18 11:40:19 +00:00
|
|
|
+ return platform_driver_probe(&ath5k_eeprom_driver, of_ath5k_eeprom_probe);
|
|
|
|
+}
|
2016-08-23 19:14:36 +00:00
|
|
|
+late_initcall(of_ath5k_eeprom_init_late);
|
|
|
|
+subsys_initcall(of_ath5k_eeprom_init);
|
2016-01-18 11:40:19 +00:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/arch/mips/lantiq/xway/eth_mac.c
|
2016-08-02 20:26:02 +00:00
|
|
|
@@ -0,0 +1,25 @@
|
2016-01-18 11:40:19 +00:00
|
|
|
+/*
|
|
|
|
+ * Copyright (C) 2012 John Crispin <blogic@openwrt.org>
|
|
|
|
+ *
|
|
|
|
+ * This program is free software; you can redistribute it and/or modify it
|
|
|
|
+ * under the terms of the GNU General Public License version 2 as published
|
|
|
|
+ * by the Free Software Foundation.
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+#include <linux/init.h>
|
|
|
|
+#include <linux/if_ether.h>
|
|
|
|
+
|
|
|
|
+static u8 eth_mac[6];
|
|
|
|
+static int eth_mac_set;
|
|
|
|
+
|
|
|
|
+const u8* ltq_get_eth_mac(void)
|
|
|
|
+{
|
|
|
|
+ return eth_mac;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int __init setup_ethaddr(char *str)
|
|
|
|
+{
|
|
|
|
+ eth_mac_set = mac_pton(str, eth_mac);
|
|
|
|
+ return !eth_mac_set;
|
|
|
|
+}
|
2016-05-27 22:30:47 +00:00
|
|
|
+early_param("ethaddr", setup_ethaddr);
|
2016-01-18 11:40:19 +00:00
|
|
|
--- a/drivers/net/ethernet/lantiq_etop.c
|
|
|
|
+++ b/drivers/net/ethernet/lantiq_etop.c
|
2016-06-15 12:17:27 +00:00
|
|
|
@@ -840,7 +840,11 @@ ltq_etop_init(struct net_device *dev)
|
2016-01-18 11:40:19 +00:00
|
|
|
if (err)
|
|
|
|
goto err_hw;
|
|
|
|
|
|
|
|
- memcpy(&mac, &priv->pldata->mac, sizeof(struct sockaddr));
|
2016-05-27 22:30:47 +00:00
|
|
|
+ memcpy(&mac.sa_data, ltq_get_eth_mac(), ETH_ALEN);
|
|
|
|
+
|
|
|
|
+ if (priv->mac && !is_valid_ether_addr(mac.sa_data))
|
2016-01-18 11:40:19 +00:00
|
|
|
+ memcpy(&mac.sa_data, priv->mac, ETH_ALEN);
|
|
|
|
+
|
|
|
|
if (!is_valid_ether_addr(mac.sa_data)) {
|
|
|
|
pr_warn("etop: invalid MAC, using random\n");
|
|
|
|
eth_random_addr(mac.sa_data);
|