2 * MikroTik RouterBOARD 91X support
4 * Copyright (C) 2013 Gabor Juhos <juhosg@openwrt.org>
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 #define pr_fmt(fmt) "rb91x: " fmt
13 #include <linux/phy.h>
14 #include <linux/delay.h>
15 #include <linux/platform_device.h>
16 #include <linux/ath9k_platform.h>
17 #include <linux/mtd/mtd.h>
18 #include <linux/mtd/nand.h>
19 #include <linux/mtd/partitions.h>
20 #include <linux/spi/spi.h>
21 #include <linux/spi/74x164.h>
22 #include <linux/spi/flash.h>
23 #include <linux/routerboot.h>
24 #include <linux/gpio.h>
25 #include <linux/platform_data/gpio-latch.h>
26 #include <linux/platform_data/rb91x_nand.h>
29 #include <asm/mach-ath79/ath79.h>
30 #include <asm/mach-ath79/ath79_spi_platform.h>
31 #include <asm/mach-ath79/ar71xx_regs.h>
35 #include "dev-leds-gpio.h"
36 #include "dev-m25p80.h"
40 #include "machtypes.h"
42 #include "routerboot.h"
44 #define RB_ROUTERBOOT_OFFSET 0x0000
45 #define RB_ROUTERBOOT_MIN_SIZE 0xb000
46 #define RB_HARD_CFG_SIZE 0x1000
47 #define RB_BIOS_OFFSET 0xd000
48 #define RB_BIOS_SIZE 0x1000
49 #define RB_SOFT_CFG_OFFSET 0xf000
50 #define RB_SOFT_CFG_SIZE 0x1000
52 #define RB91X_FLAG_USB BIT(0)
53 #define RB91X_FLAG_PCIE BIT(1)
55 #define RB91X_LATCH_GPIO_BASE AR934X_GPIO_COUNT
56 #define RB91X_LATCH_GPIO(_x) (RB91X_LATCH_GPIO_BASE + (_x))
58 #define RB91X_GPIO_NAND_READ RB91X_LATCH_GPIO(3)
59 #define RB91X_GPIO_NAND_RDY RB91X_LATCH_GPIO(4)
60 #define RB91X_GPIO_NLE RB91X_LATCH_GPIO(11)
61 #define RB91X_GPIO_NAND_NRW RB91X_LATCH_GPIO(12)
62 #define RB91X_GPIO_NAND_NCE RB91X_LATCH_GPIO(13)
63 #define RB91X_GPIO_NAND_CLE RB91X_LATCH_GPIO(14)
64 #define RB91X_GPIO_NAND_ALE RB91X_LATCH_GPIO(15)
66 struct rb_board_info
{
71 static struct mtd_partition rb711gr100_spi_partitions
[] = {
74 .offset
= RB_ROUTERBOOT_OFFSET
,
75 .mask_flags
= MTD_WRITEABLE
,
77 .name
= "hard_config",
78 .size
= RB_HARD_CFG_SIZE
,
79 .mask_flags
= MTD_WRITEABLE
,
82 .offset
= RB_BIOS_OFFSET
,
84 .mask_flags
= MTD_WRITEABLE
,
86 .name
= "soft_config",
87 .size
= RB_SOFT_CFG_SIZE
,
91 static struct flash_platform_data rb711gr100_spi_flash_data
= {
92 .parts
= rb711gr100_spi_partitions
,
93 .nr_parts
= ARRAY_SIZE(rb711gr100_spi_partitions
),
96 static int rb711gr100_gpio_latch_gpios
[AR934X_GPIO_COUNT
] __initdata
= {
97 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
98 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
101 static struct gpio_latch_platform_data rb711gr100_gpio_latch_data __initdata
= {
102 .base
= RB91X_LATCH_GPIO_BASE
,
103 .num_gpios
= ARRAY_SIZE(rb711gr100_gpio_latch_gpios
),
104 .gpios
= rb711gr100_gpio_latch_gpios
,
106 .le_active_low
= true,
109 static struct rb91x_nand_platform_data rb711gr100_nand_data __initdata
= {
110 .gpio_nce
= RB91X_GPIO_NAND_NCE
,
111 .gpio_ale
= RB91X_GPIO_NAND_ALE
,
112 .gpio_cle
= RB91X_GPIO_NAND_CLE
,
113 .gpio_rdy
= RB91X_GPIO_NAND_RDY
,
114 .gpio_read
= RB91X_GPIO_NAND_READ
,
115 .gpio_nrw
= RB91X_GPIO_NAND_NRW
,
116 .gpio_nle
= RB91X_GPIO_NLE
,
119 static void __init
rb711gr100_init_partitions(const struct rb_info
*info
)
121 rb711gr100_spi_partitions
[0].size
= info
->hard_cfg_offs
;
122 rb711gr100_spi_partitions
[1].offset
= info
->hard_cfg_offs
;
124 rb711gr100_spi_partitions
[3].offset
= info
->soft_cfg_offs
;
127 void __init
rb711gr100_wlan_init(void)
130 u8 wlan_mac
[ETH_ALEN
];
132 caldata
= rb_get_wlan_data();
136 ath79_init_mac(wlan_mac
, ath79_mac_base
, 1);
137 ath79_register_wmac(caldata
+ 0x1000, wlan_mac
);
142 #define RB_BOARD_INFO(_name, _flags) \
148 static const struct rb_board_info rb711gr100_boards
[] __initconst
= {
149 RB_BOARD_INFO("911G-2HPnD", 0),
150 RB_BOARD_INFO("911G-5HPnD", 0),
151 RB_BOARD_INFO("912UAG-2HPnD", RB91X_FLAG_USB
| RB91X_FLAG_PCIE
),
152 RB_BOARD_INFO("912UAG-5HPnD", RB91X_FLAG_USB
| RB91X_FLAG_PCIE
),
155 static u32
rb711gr100_get_flags(const struct rb_info
*info
)
159 for (i
= 0; i
< ARRAY_SIZE(rb711gr100_boards
); i
++) {
160 const struct rb_board_info
*bi
;
162 bi
= &rb711gr100_boards
[i
];
163 if (strcmp(info
->board_name
, bi
->name
) == 0)
170 static void __init
rb711gr100_setup(void)
172 const struct rb_info
*info
;
176 info
= rb_init_info((void *) KSEG1ADDR(0x1f000000), 0x10000);
180 scnprintf(buf
, sizeof(buf
), "Mikrotik RouterBOARD %s",
181 (info
->board_name
) ? info
->board_name
: "");
182 mips_set_machine_name(buf
);
184 rb711gr100_init_partitions(info
);
185 ath79_register_m25p80(&rb711gr100_spi_flash_data
);
187 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0
|
188 AR934X_ETH_CFG_SW_ONLY_MODE
);
190 ath79_register_mdio(0, 0x0);
192 ath79_init_mac(ath79_eth0_data
.mac_addr
, ath79_mac_base
, 0);
193 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
194 ath79_eth0_data
.phy_mask
= BIT(0);
195 ath79_eth0_pll_data
.pll_1000
= 0x02000000;
197 ath79_register_eth(0);
199 rb711gr100_wlan_init();
201 platform_device_register_data(NULL
, "rb91x-nand", -1,
202 &rb711gr100_nand_data
,
203 sizeof(rb711gr100_nand_data
));
205 platform_device_register_data(NULL
, "gpio-latch", -1,
206 &rb711gr100_gpio_latch_data
,
207 sizeof(rb711gr100_gpio_latch_data
));
209 flags
= rb711gr100_get_flags(info
);
211 if (flags
& RB91X_FLAG_USB
)
212 ath79_register_usb();
214 if (flags
& RB91X_FLAG_PCIE
)
215 ath79_register_pci();
219 MIPS_MACHINE_NONAME(ATH79_MACH_RB_711GR100
, "711Gr100", rb711gr100_setup
);