[PATCH 4/4] ath79: add support of Mikrotik RouterBoard 91xG series

Denis Kalashnikov denis281089 at gmail.com
Thu May 6 17:25:14 BST 2021


This board has been supported in the ar71xx.

Links:
* https://mikrotik.com/product/RB912UAG-2HPnD
* https://openwrt.org/toh/hwdata/mikrotik/mikrotik_rb912uag-2hpnd

Hardware:
 * SoC: Atheros AR9342, 1 core, 600MHz, MIPS, code name "Wasp"
   (like AR9341, AR9344, AR9350),

 * RAM: DDR 64MB,

 * Storage:
   * 64KB SPI NOR: chip Winbond 25X05. With Mikrotik first-stage Bootloader
     and hardware config (Ethernet MAC addr, wireless calibration data, etc).
     Driver: upstream m25p80/spi-nor.

   * 128MB NAND: chip Winbond W29N01GV. With Mikrotik second-stage Bootloader,
     kernel, initramfs, rootfs and user data. Driver: ad-hoc rb91x-nand,
     since Mikrotik guys doesn't use a SoC NAND controller on this board and
     controls NAND chip through gpio lines multiplexed with data lines by a
     latch,

 * Ethernet: x1 10/10/1000 port with POE, MAC is embedded in SoC and is
   managed by upstream ag71xx driver. PHY is on the separate chip AR8033,
   connected through RGMII and MDIO and controlled by upstream at803x driver,

 * Wi-Fi: 802.11bgn, MAC in SoC, driver: ath9k, wireless calibration data
   is in SPI NOR flash in hard_config partition (offset 0x1000),

 * PCIe: host controller embedded in SoC. Driver: ar724x. On PCIe there is
   only USB 2.0 ECHI host controller, connected to USB port and mPCIe slot,
   that can be used for LTE cell modem. Only one can be powerd at the same
   time.

 * SoC GPIO: 23 lines, driver: ath79-gpio,

 * SPI bus: SPI controller is embedded in SoC. 3 nCS lines. Devices:
   SPI NOR flash (nCS 0) and a Shift Register (see below, uses gpio line as
   nCS). Driver: ath79-spi.

 * Shift register: 8-bit, on SPI bus, chip 74HC595, driver: 74x164,
   nCS is on gpio line,

 * Latch: 8-bit latch, chip NXP LVC573A. Used for multiplaction of
   NAND control and data lines (NAND connected to SoC GPIO lines).
   Several lines of the latch, that is not used for NAND control lines,
   are used for power LED and user LED and nCS of a shift register,

 * Button: controlled by ???

 * Beeper/buzzer: controller by SoC gpio line ???

 * LEDs: 5 general purpose LEDs connected to the shift register,
   power LED and user LED, connected to the latch. All them can be
   controlled by software. Ethernet phy LED,

What is working:
 * Gigabit Ethernet (should be tested more under load),
 * SPI NOR and NAND flash (sysupgrade can be used),
 * 2.4 GHz Wi-Fi ('iw dev wlan0 scan' is working),
 * LEDs,

What is not working:
 * USB port and mPCIe slot,
 * Beeper,
 * Button,

You can flash image by sysupgrade utility or load it by net
(by DHCP/TFTP, hold the button while booting).

Signed-off-by: Denis Kalashnikov <denis281089 at gmail.com>
---
 .../dts/ar9342_mikrotik_routerboard-912g.dts  | 314 ++++++++++++++++++
 target/linux/ath79/image/mikrotik.mk          |   9 +
 .../base-files/etc/board.d/02_network         |   2 +
 .../etc/hotplug.d/firmware/10-ath9k-eeprom    |   1 +
 .../base-files/lib/upgrade/platform.sh        |   1 +
 5 files changed, 327 insertions(+)
 create mode 100644 target/linux/ath79/dts/ar9342_mikrotik_routerboard-912g.dts

diff --git a/target/linux/ath79/dts/ar9342_mikrotik_routerboard-912g.dts b/target/linux/ath79/dts/ar9342_mikrotik_routerboard-912g.dts
new file mode 100644
index 0000000000..bc4aeeb6d0
--- /dev/null
+++ b/target/linux/ath79/dts/ar9342_mikrotik_routerboard-912g.dts
@@ -0,0 +1,314 @@
+#include "ar9344.dtsi"
+
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/input/input.h>
+
+/*
+ * TODO list:
+ *   - Enable beeper/buzzer,
+ *   - Enable button/key,
+ *   - Enable usb EHCI and export GPIOs for
+ *     turning on/off power for USB port and mPCIe slot,
+ *   - Test Wi-Fi working,
+ *   - Test Gigabit Ethernet working (see pll settings),
+ */
+
+/ {
+	compatible = "mikrotik,routerboard-912g";
+	model = "Mikrotik RB912G";
+};
+
+&ahb {
+	/*
+	 * MFD: NAND plus GPIO-controller. They use/share SoC GPIO lines. Some of the
+	 * GPIO lines are multiplexed by a 8-bit latch (LVC573).
+	 * NAND is controlled by GPIO lines (bitbang), also some NAND control lines
+	 * (nCE, ALE, CLE, READ) and data lines are multiplexed by a latch. So driver
+	 * set control lines, enable latch ("latched them") and then transfer data.
+	 * Several lines of the latch (not used for NAND control lines) are used
+	 * as general-purpose GPIO. NAND ECC format is Mikrotik specific.
+	 */
+	/*
+                                                                            +-----------+
+                                                                            |           |
++-----------------+                                                         |           |
+|                 |                                                         |           |
+|                 |                                                         |           |
+|                 |                                                         |           |   3-4 lines
+|                 |                                                         |           +--------
+|               G |                           8 lines                       |   8-bit   |    GPIO
+|               P +-------+-------------------------------------------------+           |  (leds, SSR nCS)
+|               I |       |                                                 |   Latch   |
+|               O |       |                                                 |           |
+|               s |       |                                                 |   LVC573  |  4 lines
+|                 |       |                                                 |           +-------+
+|                 |       |                                                 |           |       |
+|                 |       |                                                 |           |       |
+|                 |       |                                                 |           |       |
+|                 |       |                                                 |           |       |
+|                 |       |                                                 |           |       |
+|                 |       | 8                                               +-----------+       |
+|                 |       |                                                                     |
+|                 |       | l                                                                   |
+|                 |       | i                                                                   |
+|      SoC        |       | n                                                                   |
+|                 |       | e                                                                   |
+|                 |       | s               +----------------------------------+                |
+|                 |       |                 |                                  |                |
+|                 |       |                 |                               C  |                |
+|                 |       |                 |                                  | nCE, CLE, ALE, |
+|                 |       |                 |                               O  +----------------+
+|                 |       |                 | D                                |   READ
+|                 |       |                 |                               N  |
+|                 |       |                 | A                                |
+|                 |       |                 |          N  A  N  D           T  |
+|                 |       +-----------------+ T                                |
+|                 |                         |                               R  | nRW, RDY
+|                 |                         | A                                +----------+
+|                 |                         |                               O  |          |
+|                 |                         |                                  |          |
+|                 |                         |                               L  |          |
+|                 |                         |                                  |          |
+|               G |                         |                                  |          |
+|               P |                         +----------------------------------+          |
+|               I |     2 lines                                                           |
+|               O +-----------------------------------------------------------------------+
+|               s |
+|                 |
++-----------------+
+	  Drawn on https://asciiflow.com
+	*/
+	nand_gpio {
+		compatible = "mikrotik,nand-gpio-latch";
+
+		/* NAND control gpios */
+		nand-read-gpios = <&gpio 3 0>; /* Read */
+		nand-rdy-gpios  = <&gpio 4 0>; /* Ready */
+		nand-nrw-gpios  = <&gpio 12 GPIO_ACTIVE_LOW>; /* Read/Write Strobe */
+		nand-nce-gpios  = <&gpio 13 GPIO_ACTIVE_LOW>; /* Chip Enable */
+		nand-cle-gpios  = <&gpio 14 0>; /* Command Latch */
+		nand-ale-gpios  = <&gpio 15 0>; /* Address Latch */
+
+		/* Latch Enable */
+		nle-gpios = <&gpio 11 GPIO_ACTIVE_LOW>;
+
+		nand-data-gpios = <&gpio 0 0>,
+				  <&gpio 1 0>,
+				  <&gpio 2 0>,
+				  <&gpio 3 0>,
+				  <&gpio 4 0>,
+				  <&gpio 13 0>,
+				  <&gpio 14 0>,
+				  <&gpio 15 0>;
+
+		latch-gpios = <&gpio 0 GPIO_ACTIVE_LOW>,
+			      <&gpio 1 GPIO_ACTIVE_LOW>,
+			      <&gpio 2 GPIO_ACTIVE_LOW>;
+
+		nand {
+			compatible = "mikrotik,rb91x-nand";
+
+			partitions {
+				compatible = "fixed-partitions";
+				#size-cells = <1>;
+
+				/* Mikrotik second-stage bootloader */
+				partition at 0 {
+					label = "booter";
+					reg = <0x0000000 0x0040000>;
+					read-only;
+				};
+
+				/* Kernel and initramfs */
+				partition at 40000 {
+					label = "kernel";
+					reg = <0x0040000 0x03c0000>;
+				};
+
+				/* Read-only rootfs and user data (overlayfs) */
+				partition at 400000 {
+					label = "ubi";
+					reg = <0x0400000 0x7c00000>;
+				};
+			};
+		};
+
+		/*
+		 * GPIO lines of the latch, that are not used for the NAND
+		 * control lines. Used for Serial Shift register nCS and
+		 * controling two LEDs: power adn user.
+		 */
+		gpio_latch: gpio {
+			compatible = "mikrotik,rb91x-gpio-latch";
+			gpio-controller;
+			#gpio-cells = <2>;
+		};
+	};
+};
+
+/* We just copy-past this */
+&mdio0 {
+	status = "okay";
+
+	phy-mask = <0>;
+
+	phy0: ethernet-phy at 0 {
+		reg = <0>;
+	};
+};
+
+/* We just copy-paste this */
+&eth0 {
+	status = "okay";
+
+	/* pll-data = <0x02000000 0x00000101 0x00001313>; */
+
+	/* mtd-mac-address = <&hard_config 0x10>; */
+
+	phy-mode = "rgmii-id";
+	phy-handle = <&phy0>;
+
+	gmac-config {
+		device = <&gmac>;
+		rxd-delay = <3>;
+		rxdv-delay = <3>;
+	};
+};
+
+&spi {
+	status = "okay";
+
+	/*
+	 * New spi-ar934x driver (that superseeds spi-ath79 and support
+	 * new shift-register mode) seems doesn't support gpio line nCS
+	 * (cs-gpios) (do it?).
+	 */
+	compatible = "qca,ar7100-spi";
+
+	/* Gpio nCS line for the shift register */
+	cs-gpios = <0>, <&gpio_latch 0 GPIO_ACTIVE_LOW>;
+
+	/* 64KB NOR SPI flash with routerboot and board config data */
+	flash at 0 {
+		compatible = "jedec,spi-nor";
+		reg = <0>;
+		spi-max-frequency = <25000000>;
+
+		partitions {
+			compatible = "mikrotik,routerboot-partitions";
+			#address-cells = <1>;
+			#size-cells = <1>;
+
+			/* Mikrotik first-stage Bootloader */
+			partition at 0 {
+				label = "routerboot";
+				reg = <0x0 0x0>;
+				read-only;
+			};
+
+			/*
+			 * Ethernet MAC address, wireless calibration data,
+			 * etc. You can read them from
+			 * /sys/firmware/mikrotik/hard_config.
+			 * You don't need to use rbcfg util anymore. 
+			 */
+			hard_config: hard_config {
+				read-only;
+			};
+
+			bios {
+				size = <0x1000>;
+				read-only;
+			};
+
+			/* Mikrotik Bootloader's Config */
+			soft_config {
+			};
+		};
+	};
+
+	/*
+	 * 8-bit Shift register 74HC595 used as output GPIO chip (5 LEDs and
+	 * 2 lines for turning on/off power for USB port and mPCIe slot).
+	 * nCS is connected to gpio line (not to the internal SPI controller
+	 * line), this line goes from the SoC through the latch.
+	 */
+	ssr: ssr at 1 {
+		compatible = "fairchild,74hc595";
+		gpio-controller;
+		#gpio-cells = <2>;
+		registers-number = <1>;
+		/* SPI params */
+		reg = <1>;
+		spi-max-frequency = <10000000>;
+	};
+};
+
+/ {
+	leds {
+		compatible = "gpio-leds";
+
+		led_power {
+			label = "green:power";
+			gpios = <&gpio_latch 1 GPIO_ACTIVE_HIGH>;
+			default-state = "on";
+		};
+
+		led_user {
+			label = "green:user";
+			gpios = <&gpio_latch 2 GPIO_ACTIVE_HIGH>;
+		};
+
+		led1 {
+			label = "green:led1";
+			gpios = <&ssr 0 GPIO_ACTIVE_HIGH>;
+		};
+
+		led2 {
+			label = "green:led2";
+			gpios = <&ssr 1 GPIO_ACTIVE_HIGH>;
+		};
+
+		led3 {
+			label = "green:led3";
+			gpios = <&ssr 2 GPIO_ACTIVE_HIGH>;
+		};
+
+		led4 {
+			label = "green:led4";
+			gpios = <&ssr 3 GPIO_ACTIVE_HIGH>;
+		};
+
+		led5 {
+			label = "green:led5";
+			gpios = <&ssr 4 GPIO_ACTIVE_HIGH>;
+			default-state = "on";
+		};
+	};
+
+	/* Is not working now -- we don't know why */
+	beeper {
+		compatible = "gpio-beeper";
+		gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
+	};
+};
+
+/* It is needed for USB port and mPCIe slot */
+&pcie {
+	status = "okay";
+};
+
+/* SoC Wi-Fi MAC managed by ath9k driver (RB912UAG-2HPnD) */
+&wmac {
+	status = "okay";
+	/*
+	 * Wireless calibration data is in SPI NOR flash
+	 * hard_config partition. In OpenWrt you can also
+	 * read it from sysfs file
+	 * /sys/firmware/mikrotik/hard_config/wlan_data
+	 * from offset 0x1000
+	 * (/etc/hotplug.d/firmware/10-ath9k-eeprom script
+	 * does this).
+	 */
+	qca,no-eeprom;
+};
diff --git a/target/linux/ath79/image/mikrotik.mk b/target/linux/ath79/image/mikrotik.mk
index 74f8603b5a..b9c21dab7d 100644
--- a/target/linux/ath79/image/mikrotik.mk
+++ b/target/linux/ath79/image/mikrotik.mk
@@ -1,5 +1,14 @@
 include ./common-mikrotik.mk
 
+define Device/mikrotik_routerboard-912g
+  $(Device/mikrotik_nand)
+  SOC := ar9342
+  DEVICE_MODEL := RouterBOARD 912G
+  DEVICE_PACKAGES += kmod-usb-ehci kmod-usb2
+  SUPPORTED_DEVICES += rb-912g
+endef
+TARGET_DEVICES += mikrotik_routerboard-912g
+
 define Device/mikrotik_routerboard-493g
   $(Device/mikrotik_nand)
   SOC := ar7161
diff --git a/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network b/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network
index 4ffe82588c..07bb22c088 100644
--- a/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network
+++ b/target/linux/ath79/mikrotik/base-files/etc/board.d/02_network
@@ -14,6 +14,7 @@ ath79_setup_interfaces()
 		ucidef_add_switch "switch1" \
 			"0 at eth1" "1:lan:4" "2:lan:1" "3:lan:2" "4:lan:3"
 		;;
+	mikrotik,routerboard-912g|\
 	mikrotik,routerboard-921gs-5hpacd-15s|\
 	mikrotik,routerboard-lhg-2nd|\
 	mikrotik,routerboard-sxt-5nd-r2|\
@@ -36,6 +37,7 @@ ath79_setup_macs()
 	local mac_base="$(cat /sys/firmware/mikrotik/hard_config/mac_base)"
 
 	case "$board" in
+	mikrotik,routerboard-912g|\
 	mikrotik,routerboard-921gs-5hpacd-15s|\
 	mikrotik,routerboard-lhg-2nd|\
 	mikrotik,routerboard-sxt-5nd-r2|\
diff --git a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
index 7ef6fdbe0f..7868ceaac9 100644
--- a/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
+++ b/target/linux/ath79/mikrotik/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
@@ -23,6 +23,7 @@ board=$(board_name)
 case "$FIRMWARE" in
 "ath9k-eeprom-ahb-18100000.wmac.bin")
 	case $board in
+	mikrotik,routerboard-912g|\
 	mikrotik,routerboard-lhg-2nd|\
 	mikrotik,routerboard-sxt-5nd-r2|\
 	mikrotik,routerboard-wapr-2nd)
diff --git a/target/linux/ath79/mikrotik/base-files/lib/upgrade/platform.sh b/target/linux/ath79/mikrotik/base-files/lib/upgrade/platform.sh
index 97d388168f..736a0932f7 100644
--- a/target/linux/ath79/mikrotik/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ath79/mikrotik/base-files/lib/upgrade/platform.sh
@@ -32,6 +32,7 @@ platform_do_upgrade() {
 
 	case "$board" in
 	mikrotik,routerboard-493g|\
+	mikrotik,routerboard-912g|\
 	mikrotik,routerboard-921gs-5hpacd-15s|\
 	mikrotik,routerboard-922uags-5hpacd|\
 	mikrotik,routerboard-sxt-5nd-r2)
-- 
2.26.3




More information about the openwrt-devel mailing list