[LEDE-DEV] [PATCH 1/3] ar71xx: add support for RB mAP L-2nD

hacks at slashdirt.org hacks at slashdirt.org
Sun Feb 5 04:31:56 PST 2017


From: Thibaut VARENE <hacks at slashdirt.org>

This patch adds support for the MikroTik RouterBOARD mAP lite
https://routerboard.com/RBmAPL-2nD

Specifications:
- SoC: Qualcomm QCA9533 (650MHz)
- RAM: 64MB
- Storage: 16MB NOR SPI flash
- Wireless: builtin QCA9533, 2x2:2
- Ethernet: 1x100M

This is another 16M SPI NOR mikrotik device. The machine file is named
mach-rbxap.c because I plan to add support for most of the other "AP"
RouterBOARD devices in subsequent patches: they share most of the hardware
and thus the same codebase.

Signed-off-by: Thibaut VARENE <hacks at slashdirt.org>
---
 target/linux/ar71xx/base-files/etc/board.d/01_leds |   5 +
 .../linux/ar71xx/base-files/etc/board.d/02_network |   1 +
 target/linux/ar71xx/base-files/etc/diag.sh         |   3 +-
 target/linux/ar71xx/base-files/lib/ar71xx.sh       |   3 +
 .../ar71xx/base-files/lib/upgrade/platform.sh      |   7 +-
 target/linux/ar71xx/config-4.4                     |   1 +
 .../ar71xx/files/arch/mips/ath79/Kconfig.openwrt   |  13 ++
 target/linux/ar71xx/files/arch/mips/ath79/Makefile |   1 +
 .../ar71xx/files/arch/mips/ath79/mach-rbxap.c      | 209 +++++++++++++++++++++
 .../linux/ar71xx/files/arch/mips/ath79/machtypes.h |   1 +
 target/linux/ar71xx/image/mikrotik.mk              |   9 +-
 target/linux/ar71xx/mikrotik/config-default        |   1 +
 12 files changed, 250 insertions(+), 4 deletions(-)
 create mode 100644 target/linux/ar71xx/files/arch/mips/ath79/mach-rbxap.c

diff --git a/target/linux/ar71xx/base-files/etc/board.d/01_leds b/target/linux/ar71xx/base-files/etc/board.d/01_leds
index b1ecb02..c52f822 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/01_leds
+++ b/target/linux/ar71xx/base-files/etc/board.d/01_leds
@@ -228,6 +228,11 @@ rb-2011uias-2hnd)
 	ucidef_set_led_switch "eth9" "ETH9" "rb:green:eth9" "switch1" "0x04"
 	ucidef_set_led_switch "eth10" "ETH10" "rb:green:eth10" "switch1" "0x02"
 	;;
+rb-mapl-2nd)
+	ucidef_set_led_default "power" "POWER" "rb:green:power" "1"
+	ucidef_set_led_netdev "lan" "LAN" "rb:green:eth" "eth0"
+	ucidef_set_led_wlan "wlan" "WLAN" "rb:green:wlan" "phy0tpt"
+	;;
 dap-2695-a1)
 	ucidef_set_led_default "power" "POWER" "d-link:green:power" "1"
 	ucidef_set_led_default "diag" "DIAG" "d-link:red:power" "0"
diff --git a/target/linux/ar71xx/base-files/etc/board.d/02_network b/target/linux/ar71xx/base-files/etc/board.d/02_network
index 976440e..639ae55 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/02_network
+++ b/target/linux/ar71xx/base-files/etc/board.d/02_network
@@ -90,6 +90,7 @@ ar71xx_setup_interfaces()
 	rb-911g-5hpnd|\
 	rb-912uag-2hpnd|\
 	rb-912uag-5hpnd|\
+	rb-mapl-2nd|\
 	rb-sxt2n|\
 	rb-sxt5n|\
 	re450|\
diff --git a/target/linux/ar71xx/base-files/etc/diag.sh b/target/linux/ar71xx/base-files/etc/diag.sh
index edcf621..c7f377e 100644
--- a/target/linux/ar71xx/base-files/etc/diag.sh
+++ b/target/linux/ar71xx/base-files/etc/diag.sh
@@ -289,7 +289,8 @@ get_status_led() {
 	rb-911g-5hpacd|\
 	rb-911g-5hpnd|\
 	rb-912uag-2hpnd|\
-	rb-912uag-5hpnd)
+	rb-912uag-5hpnd|\
+	rb-mapl-2nd)
 		status_led="rb:green:user"
 		;;
 	rb-951ui-2hnd | rb-941-2nd)
diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh
index 3ca2c0d..7c249c5 100755
--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
@@ -868,6 +868,9 @@ ar71xx_board_detect() {
 	*"RouterBOARD 2011UiAS-2HnD")
 		name="rb-2011uias-2hnd"
 		;;
+	*"RouterBOARD mAP L-2nD")
+		name="rb-mapl-2nd"
+		;;
 	*"RouterBOARD SXT Lite2")
 		name="rb-sxt2n"
 		;;
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
index cf2aab2..17469b9 100755
--- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
@@ -343,6 +343,7 @@ platform_check_image() {
 	pb42|\
 	pb44|\
 	rb-941-2nd|\
+	rb-mapl-2nd|\
 	routerstation-pro|\
 	routerstation|\
 	wp543|\
@@ -609,7 +610,8 @@ platform_pre_upgrade() {
 	local board=$(ar71xx_board_name)
 
 	case "$board" in
-	rb-941-2nd)
+	rb-941-2nd|\
+	rb-mapl-2nd)
 		;;
 	rb*|\
 	c-60|\
@@ -645,7 +647,8 @@ platform_do_upgrade() {
 	local board=$(ar71xx_board_name)
 
 	case "$board" in
-	rb-941-2nd)
+	rb-941-2nd|\
+	rb-mapl-2nd)
 		PLATFORM_DO_UPGRADE_COMBINED_SEPARATE_MTD=1
 		platform_do_upgrade_combined "$ARGV"
 		;;
diff --git a/target/linux/ar71xx/config-4.4 b/target/linux/ar71xx/config-4.4
index 8ba0c2a..20f1f0b 100644
--- a/target/linux/ar71xx/config-4.4
+++ b/target/linux/ar71xx/config-4.4
@@ -148,6 +148,7 @@ CONFIG_ATH79_MACH_R6100=y
 # CONFIG_ATH79_MACH_RB922 is not set
 # CONFIG_ATH79_MACH_RB941 is not set
 # CONFIG_ATH79_MACH_RB95X is not set
+# CONFIG_ATH79_MACH_RBXAP is not set
 # CONFIG_ATH79_MACH_RBSXTLITE is not set
 CONFIG_ATH79_MACH_RE450=y
 CONFIG_ATH79_MACH_RW2458N=y
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
index 8b6554c..0378fed 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
+++ b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
@@ -914,6 +914,19 @@ config ATH79_MACH_RB2011
 	select ATH79_DEV_WMAC
 	select ATH79_ROUTERBOOT
 
+config ATH79_MACH_RBXAP
+	bool "MikroTik RouterBOARD XAP support"
+	select SOC_QCA953X
+	select ATH79_DEV_ETH
+	select ATH79_DEV_GPIO_BUTTONS
+	select ATH79_DEV_LEDS_GPIO
+	select ATH79_DEV_M25P80
+	select ATH79_DEV_WMAC
+	select ATH79_ROUTERBOOT
+	help
+	  Say 'Y' here if you want your kernel to support the
+	  MikroTik RouterBOARD mAP lite
+
 config ATH79_MACH_RBSXTLITE
 	bool "MikroTik RouterBOARD SXT Lite"
 	select SOC_AR934X
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Makefile b/target/linux/ar71xx/files/arch/mips/ath79/Makefile
index e9d69a4..fc104c3 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/Makefile
+++ b/target/linux/ar71xx/files/arch/mips/ath79/Makefile
@@ -152,6 +152,7 @@ obj-$(CONFIG_ATH79_MACH_RB91X)			+= mach-rb91x.o
 obj-$(CONFIG_ATH79_MACH_RB922)			+= mach-rb922.o
 obj-$(CONFIG_ATH79_MACH_RB941)			+= mach-rb941.o
 obj-$(CONFIG_ATH79_MACH_RB95X)			+= mach-rb95x.o
+obj-$(CONFIG_ATH79_MACH_RBXAP)			+= mach-rbxap.o
 obj-$(CONFIG_ATH79_MACH_RBSXTLITE)		+= mach-rbsxtlite.o
 obj-$(CONFIG_ATH79_MACH_RE450)			+= mach-re450.o
 obj-$(CONFIG_ATH79_MACH_RW2458N)		+= mach-rw2458n.o
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-rbxap.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-rbxap.c
new file mode 100644
index 0000000..7d2f840
--- /dev/null
+++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-rbxap.c
@@ -0,0 +1,209 @@
+/*
+ *  MikroTik RouterBOARD *AP (SPI NOR) support
+ *
+ *  - MikroTik RouterBOARD mAPL-2nD
+ *
+ *  Copyright (C) 2017 Thibaut VARENE <varenet at parisc-linux.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/export.h>
+#include <linux/platform_device.h>
+#include <linux/phy.h>
+#include <linux/routerboot.h>
+#include <linux/gpio.h>
+
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+
+#include <asm/prom.h>
+#include <asm/mach-ath79/ar71xx_regs.h>
+#include <asm/mach-ath79/ath79.h>
+
+#include "common.h"
+#include "dev-eth.h"
+#include "dev-spi.h"
+#include "dev-gpio-buttons.h"
+#include "dev-leds-gpio.h"
+#include "dev-m25p80.h"
+#include "dev-wmac.h"
+#include "machtypes.h"
+#include "routerboot.h"
+
+#define RBXAP_KEYS_POLL_INTERVAL 20 /* msecs */
+#define RBXAP_KEYS_DEBOUNCE_INTERVAL (3 * RBXAP_KEYS_POLL_INTERVAL)
+
+#define RB_ROUTERBOOT_OFFSET    0x0000
+#define RB_BIOS_SIZE            0x1000
+#define RB_SOFT_CFG_SIZE        0x1000
+#define RB_KERNEL_OFFSET        0xa00000
+#define RB_KERNEL_SIZE          MTDPART_SIZ_FULL
+
+void __init rbxap_wlan_init(int wmac_offset)
+{
+	char *art_buf;
+	u8 wlan_mac[ETH_ALEN];
+
+	art_buf = rb_get_wlan_data();
+	if (art_buf == NULL)
+		return;
+
+	ath79_init_mac(wlan_mac, ath79_mac_base, wmac_offset);
+	ath79_register_wmac(art_buf + 0x1000, wlan_mac);
+
+	kfree(art_buf);
+}
+
+static struct mtd_partition rbxap_spi_partitions[] = {
+	{
+		.name = "routerboot",
+		.offset = RB_ROUTERBOOT_OFFSET,
+		.mask_flags = MTD_WRITEABLE,
+	},
+	{
+		.name = "hard_config",
+		.mask_flags = MTD_WRITEABLE,
+	},
+	{
+		.name = "bios",
+		.size = RB_BIOS_SIZE,
+		.mask_flags = MTD_WRITEABLE,
+	},
+	{
+		.name = "routerboot2",
+		.mask_flags = MTD_WRITEABLE,
+	},
+	{
+		.name = "soft_config",
+		.size = RB_SOFT_CFG_SIZE,
+	},
+	{
+		.name = "rootfs",
+	},
+	{
+		.name = "kernel",
+		.offset = RB_KERNEL_OFFSET,
+		.size = RB_KERNEL_SIZE,
+	}
+};
+
+/* calculate the partitions offsets and size based on initial
+ * parsing. Kernel is fixed at RB_KERNEL_OFFSET so the rootfs
+ * partition adjusts accordingly */
+static void __init rbxap_init_partitions(const struct rb_info *info)
+{
+	rbxap_spi_partitions[0].size = info->hard_cfg_offs;
+	rbxap_spi_partitions[1].offset = info->hard_cfg_offs;
+	rbxap_spi_partitions[1].size = info->hard_cfg_size;
+	rbxap_spi_partitions[2].offset = info->hard_cfg_offs + info->hard_cfg_size;
+	rbxap_spi_partitions[3].offset = rbxap_spi_partitions[2].offset + RB_BIOS_SIZE;
+	rbxap_spi_partitions[3].size = info->soft_cfg_offs - rbxap_spi_partitions[3].offset;
+	rbxap_spi_partitions[4].offset = info->soft_cfg_offs;
+	rbxap_spi_partitions[5].offset = rbxap_spi_partitions[4].offset + RB_SOFT_CFG_SIZE;
+	rbxap_spi_partitions[5].size = RB_KERNEL_OFFSET - rbxap_spi_partitions[5].offset;
+}
+
+static struct flash_platform_data rbxap_spi_flash_data = {
+	.parts = rbxap_spi_partitions,
+	.nr_parts = ARRAY_SIZE(rbxap_spi_partitions),
+};
+
+
+/* RB mAP L-2nD gpios */
+#define RBMAPL_GPIO_LED_POWER	17
+#define RBMAPL_GPIO_LED_USER	14
+#define RBMAPL_GPIO_LED_ETH	4
+#define RBMAPL_GPIO_LED_WLAN	11
+#define RBMAPL_GPIO_BTN_RESET	16
+
+static struct gpio_led rbmapl_leds[] __initdata = {
+	{
+		.name = "rb:green:power",
+		.gpio = RBMAPL_GPIO_LED_POWER,
+		.active_low = 0,
+		.default_state = LEDS_GPIO_DEFSTATE_ON,
+	},
+	{
+		.name = "rb:green:user",
+		.gpio = RBMAPL_GPIO_LED_USER,
+		.active_low = 0,
+	},
+	{
+		.name = "rb:green:eth",
+		.gpio = RBMAPL_GPIO_LED_ETH,
+		.active_low = 0,
+	},
+	{
+		.name = "rb:green:wlan",
+		.gpio = RBMAPL_GPIO_LED_WLAN,
+		.active_low = 0,
+	},
+};
+
+static struct gpio_keys_button rbmapl_gpio_keys[] __initdata = {
+	{
+		.desc = "Reset button",
+		.type = EV_KEY,
+		.code = KEY_RESTART,
+		.debounce_interval = RBXAP_KEYS_DEBOUNCE_INTERVAL,
+		.gpio = RBMAPL_GPIO_BTN_RESET,
+		.active_low = 1,
+	},
+};
+
+static int __init rbxap_setup(int wmac_offset)
+{
+	const struct rb_info *info;
+	char buf[64];
+
+	info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x20000);
+	if (!info)
+		return -ENODEV;
+
+	scnprintf(buf, sizeof(buf), "MikroTik %s",
+		(info->board_name) ? info->board_name : "");
+	mips_set_machine_name(buf);
+
+	/* fix partitions based on flash parsing */
+	rbxap_init_partitions(info);
+	ath79_register_m25p80(&rbxap_spi_flash_data);
+
+	/* set the SoC to SW_ONLY_MODE, which connects all PHYs
+	 * to the internal switch */
+	ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
+	ath79_register_mdio(0, 0x0);
+
+	/* GMAC0 is left unused */
+	/* GMAC1 is connected to MAC0 on the internal switch */
+	ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 0);
+	ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
+	ath79_register_eth(1);
+
+	rbxap_wlan_init(wmac_offset);
+
+	return 0;
+}
+
+/* The mAP L-2nD (mAP lite) has a single ethernet port, connected to PHY0.
+ * Trying to use GMAC0 in direct mode was unsucessful, so we're
+ * using SW_ONLY_MODE, which connects PHY0 to MAC1 on the internal
+ * switch, which is connected to GMAC1 on the SoC. GMAC0 is unused. */
+static void __init rbmapl_setup(void)
+{
+	if (rbxap_setup(1))	/* WLAN MAC is HW MAC + 1 */
+		return;
+
+	ath79_register_leds_gpio(-1, ARRAY_SIZE(rbmapl_leds), rbmapl_leds);
+	ath79_register_gpio_keys_polled(-1, RBXAP_KEYS_POLL_INTERVAL,
+					ARRAY_SIZE(rbmapl_gpio_keys),
+					rbmapl_gpio_keys);
+
+	/* Clear internal multiplexing */
+	ath79_gpio_output_select(RBMAPL_GPIO_LED_ETH, 0);
+	ath79_gpio_output_select(RBMAPL_GPIO_LED_POWER, 0);
+}
+
+MIPS_MACHINE_NONAME(ATH79_MACH_RB_MAPL, "map-hb", rbmapl_setup);
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
index 12e81db..1e161de 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
+++ b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
@@ -168,6 +168,7 @@ enum ath79_mach_type {
 	ATH79_MACH_RB_941,			/* MikroTik RouterBOARD 941-2nD */
 	ATH79_MACH_RB_951G,			/* Mikrotik RouterBOARD 951G */
 	ATH79_MACH_RB_951U,			/* Mikrotik RouterBOARD 951Ui-2HnD */
+	ATH79_MACH_RB_MAPL,			/* Mikrotik RouterBOARD mAP L-2nD */
 	ATH79_MACH_RB_SXTLITE2ND,		/* Mikrotik RouterBOARD SXT Lite 2nD */
 	ATH79_MACH_RB_SXTLITE5ND,		/* Mikrotik RouterBOARD SXT Lite 5nD */
 	ATH79_MACH_RE450,			/* TP-LINK RE450 */
diff --git a/target/linux/ar71xx/image/mikrotik.mk b/target/linux/ar71xx/image/mikrotik.mk
index a2b682f..257c618 100644
--- a/target/linux/ar71xx/image/mikrotik.mk
+++ b/target/linux/ar71xx/image/mikrotik.mk
@@ -25,6 +25,7 @@ TARGET_DEVICES += nand-64m nand-large
 
 define Device/rb-nor-flash-16M
   DEVICE_TITLE := MikroTik RouterBoard with 16 MB NOR flash
+  DEVICE_PACKAGES := rbcfg
   BLOCKSIZE := 64k
   IMAGE_SIZE := 16000k
   LOADER_TYPE := elf
@@ -42,4 +43,10 @@ $(Device/rb-nor-flash-16M)
   BOARDNAME:= rb-941-2nd
 endef
 
-TARGET_DEVICES += rb-nor-flash-16M rb-941-2nd
+define Device/rb-xap
+$(Device/rb-nor-flash-16M)
+  DEVICE_TITLE := xAP devices
+  BOARDNAME:= rb-xap
+endef
+
+TARGET_DEVICES += rb-nor-flash-16M rb-941-2nd rb-xap
diff --git a/target/linux/ar71xx/mikrotik/config-default b/target/linux/ar71xx/mikrotik/config-default
index 324c6f7..8db03f4 100644
--- a/target/linux/ar71xx/mikrotik/config-default
+++ b/target/linux/ar71xx/mikrotik/config-default
@@ -114,6 +114,7 @@ CONFIG_ATH79_MACH_RB91X=y
 CONFIG_ATH79_MACH_RB922=y
 CONFIG_ATH79_MACH_RB941=y
 CONFIG_ATH79_MACH_RB95X=y
+CONFIG_ATH79_MACH_RBXAP=y
 CONFIG_ATH79_MACH_RBSXTLITE=y
 # CONFIG_ATH79_MACH_RE450 is not set
 # CONFIG_ATH79_MACH_RW2458N is not set
-- 
2.1.4




More information about the Lede-dev mailing list