2 * MikroTik RouterBOARD 941-2nD support
4 * Copyright (C) 2016 Sergey Sergeev <adron@yapic.net>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
11 #include <linux/export.h>
12 #include <linux/pci.h>
13 #include <linux/ath9k_platform.h>
14 #include <linux/platform_device.h>
15 #include <linux/phy.h>
16 #include <linux/ar8216_platform.h>
17 #include <linux/rle.h>
18 #include <linux/routerboot.h>
19 #include <linux/gpio.h>
21 #include <linux/mtd/mtd.h>
22 //#include <linux/mtd/nand.h>
23 #include <linux/mtd/partitions.h>
25 #include <asm/mach-ath79/ar71xx_regs.h>
26 #include <asm/mach-ath79/ath79.h>
27 #include <asm/mach-ath79/irq.h>
30 #include "dev-ap9x-pci.h"
33 #include "dev-gpio-buttons.h"
34 #include "dev-leds-gpio.h"
35 #include "dev-m25p80.h"
36 //#include "dev-usb.h"
38 #include "machtypes.h"
39 #include "routerboot.h"
41 #define RB941_GPIO_LED_ACT 14
42 #define RB941_GPIO_BTN_RESET 16
44 #define RB941_KEYS_POLL_INTERVAL 20 /* msecs */
45 #define RB941_KEYS_DEBOUNCE_INTERVAL (3 * RB941_KEYS_POLL_INTERVAL)
47 #define RB_ROUTERBOOT_OFFSET 0x0000
48 #define RB_ROUTERBOOT_SIZE 0xe000
49 #define RB_HARD_CFG_OFFSET 0xe000
50 #define RB_HARD_CFG_SIZE 0x1000
51 #define RB_BIOS_OFFSET 0xf000
52 #define RB_BIOS_SIZE 0x1000
53 #define RB_ROUTERBOOT2_OFFSET 0x10000
54 #define RB_ROUTERBOOT2_SIZE 0xf000
55 #define RB_SOFT_CFG_OFFSET 0x1f000
56 #define RB_SOFT_CFG_SIZE 0x1000
57 #define RB_ROOTFS_OFFSET 0x20000
58 #define RB_ROOTFS_SIZE 0x9e0000
59 #define RB_KERNEL_OFFSET 0xa00000
60 #define RB_KERNEL_SIZE MTDPART_SIZ_FULL
62 void __init rb941_wlan_init(void)
65 u8 wlan_mac[ETH_ALEN];
67 art_buf = rb_get_wlan_data();
71 ath79_init_mac(wlan_mac, ath79_mac_base, 11);
72 ath79_register_wmac(art_buf + 0x1000, wlan_mac);
77 static struct mtd_partition rb941_spi_partitions[] = {
80 .offset = RB_ROUTERBOOT_OFFSET,
81 .mask_flags = MTD_WRITEABLE,
82 .size = RB_ROUTERBOOT_SIZE,
84 .name = "hard_config",
85 .offset = RB_HARD_CFG_OFFSET,
86 .size = RB_HARD_CFG_SIZE,
87 .mask_flags = MTD_WRITEABLE,
90 .offset = RB_BIOS_OFFSET,
92 .mask_flags = MTD_WRITEABLE,
94 .name = "routerboot2",
95 .offset = RB_ROUTERBOOT2_OFFSET,
96 .size = RB_ROUTERBOOT2_SIZE,
97 .mask_flags = MTD_WRITEABLE,
99 .name = "soft_config",
100 .offset = RB_SOFT_CFG_OFFSET,
101 .size = RB_SOFT_CFG_SIZE,
104 .offset = RB_ROOTFS_OFFSET,
105 .size = RB_ROOTFS_SIZE,
108 .offset = RB_KERNEL_OFFSET,
109 .size = RB_KERNEL_SIZE,
113 static struct flash_platform_data rb941_spi_flash_data = {
114 .parts = rb941_spi_partitions,
115 .nr_parts = ARRAY_SIZE(rb941_spi_partitions),
118 static struct gpio_led rb941_leds[] __initdata = {
120 .name = "rb:green:act",
121 .gpio = RB941_GPIO_LED_ACT,
126 static struct gpio_keys_button rb941_gpio_keys[] __initdata = {
128 .desc = "Reset button",
131 .debounce_interval = RB941_KEYS_DEBOUNCE_INTERVAL,
132 .gpio = RB941_GPIO_BTN_RESET,
137 static void __init rb941_setup(void)
139 const struct rb_info *info;
140 //try to get rb_info data
141 info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x20000);
143 pr_err("%s: Can't get rb_info data from flash!\n", __func__);
144 //return -EINVAL; //Not critical ... continue!
146 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
147 ath79_register_m25p80(&rb941_spi_flash_data);
148 ath79_register_mdio(0, 0x0);
150 /* WAN. We have no WAN. Only LAN. */
151 /*ath79_switch_data.phy4_mii_en = 1;
152 ath79_switch_data.phy_poll_mask = BIT(4);
153 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
154 ath79_eth0_data.phy_mask = BIT(4);
155 ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
156 ath79_register_eth(0); */
159 ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 0);
160 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
161 ath79_register_eth(1);
163 //ath79_register_usb();
167 ath79_register_leds_gpio(-1, ARRAY_SIZE(rb941_leds), rb941_leds);
168 ath79_register_gpio_keys_polled(-1, RB941_KEYS_POLL_INTERVAL,
169 ARRAY_SIZE(rb941_gpio_keys),
173 MIPS_MACHINE(ATH79_MACH_RB_941, "H951L", "MikroTik RouterBOARD 941-2nD", rb941_setup);