2 * MikroTik RouterBOARD 95X support
4 * Copyright (C) 2012 Stijn Tintel <stijn@linux-ipv6.be>
5 * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
6 * Copyright (C) 2013 Kamil Trzcinski <ayufan@ayufan.eu>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
13 #define pr_fmt(fmt) "rb95x: " fmt
15 #include <linux/version.h>
16 #include <linux/phy.h>
17 #include <linux/delay.h>
18 #include <linux/platform_device.h>
19 #include <linux/ath9k_platform.h>
20 #include <linux/ar8216_platform.h>
21 #include <linux/mtd/mtd.h>
22 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
23 #include <linux/mtd/nand.h>
25 #include <linux/mtd/rawnand.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/spi/spi.h>
29 #include <linux/spi/flash.h>
30 #include <linux/routerboot.h>
31 #include <linux/gpio.h>
32 #include <linux/version.h>
34 #include <asm/mach-ath79/ath79.h>
35 #include <asm/mach-ath79/ar71xx_regs.h>
39 #include "dev-m25p80.h"
43 #include "machtypes.h"
44 #include "routerboot.h"
45 #include "dev-leds-gpio.h"
47 #define RB95X_GPIO_NAND_NCE 14
49 static struct mtd_partition rb95x_nand_partitions[] = {
54 .mask_flags = MTD_WRITEABLE,
58 .offset = (256 * 1024),
59 .size = (4 * 1024 * 1024) - (256 * 1024),
63 .offset = MTDPART_OFS_NXTBLK,
64 .size = MTDPART_SIZ_FULL,
68 static struct gpio_led rb951ui_leds_gpio[] __initdata = {
70 .name = "rb:green:wlan",
74 .name = "rb:green:act",
78 .name = "rb:green:port1",
82 .name = "rb:green:port2",
86 .name = "rb:green:port3",
90 .name = "rb:green:port4",
94 .name = "rb:green:port5",
100 static struct ar8327_pad_cfg rb95x_ar8327_pad0_cfg = {
101 .mode = AR8327_PAD_MAC_RGMII,
102 .txclk_delay_en = true,
103 .rxclk_delay_en = true,
104 .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
105 .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
108 static struct ar8327_platform_data rb95x_ar8327_data = {
109 .pad0_cfg = &rb95x_ar8327_pad0_cfg,
112 .speed = AR8327_PORT_SPEED_1000,
119 static struct mdio_board_info rb95x_mdio0_info[] = {
121 .bus_id = "ag71xx-mdio.0",
123 .platform_data = &rb95x_ar8327_data,
127 void __init rb95x_wlan_init(void)
130 u8 wlan_mac[ETH_ALEN];
132 art_buf = rb_get_wlan_data();
136 ath79_init_mac(wlan_mac, ath79_mac_base, 11);
137 ath79_register_wmac(art_buf + 0x1000, wlan_mac);
142 static void rb95x_nand_select_chip(int chip_no)
146 gpio_set_value(RB95X_GPIO_NAND_NCE, 0);
149 gpio_set_value(RB95X_GPIO_NAND_NCE, 1);
155 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
156 static struct nand_ecclayout rb95x_nand_ecclayout = {
158 .eccpos = { 8, 9, 10, 13, 14, 15 },
160 .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
165 static int rb95x_ooblayout_ecc(struct mtd_info *mtd, int section,
166 struct mtd_oob_region *oobregion)
170 oobregion->offset = 8;
171 oobregion->length = 3;
174 oobregion->offset = 13;
175 oobregion->length = 3;
182 static int rb95x_ooblayout_free(struct mtd_info *mtd, int section,
183 struct mtd_oob_region *oobregion)
187 oobregion->offset = 0;
188 oobregion->length = 4;
191 oobregion->offset = 4;
192 oobregion->length = 1;
195 oobregion->offset = 6;
196 oobregion->length = 2;
199 oobregion->offset = 11;
200 oobregion->length = 2;
207 static const struct mtd_ooblayout_ops rb95x_nand_ecclayout_ops = {
208 .ecc = rb95x_ooblayout_ecc,
209 .free = rb95x_ooblayout_free,
213 static int rb95x_nand_scan_fixup(struct mtd_info *mtd)
215 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
216 struct nand_chip *chip = mtd->priv;
218 struct nand_chip *chip = mtd_to_nand(mtd);
221 if (mtd->writesize == 512) {
223 * Use the OLD Yaffs-1 OOB layout, otherwise RouterBoot
224 * will not be able to find the kernel that we load.
226 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
227 chip->ecc.layout = &rb95x_nand_ecclayout;
229 mtd_set_ooblayout(mtd, &rb95x_nand_ecclayout_ops);
233 chip->options = NAND_NO_SUBPAGE_WRITE;
238 void __init rb95x_nand_init(void)
240 gpio_request_one(RB95X_GPIO_NAND_NCE, GPIOF_OUT_INIT_HIGH, "NAND nCE");
242 ath79_nfc_set_scan_fixup(rb95x_nand_scan_fixup);
243 ath79_nfc_set_parts(rb95x_nand_partitions,
244 ARRAY_SIZE(rb95x_nand_partitions));
245 ath79_nfc_set_select_chip(rb95x_nand_select_chip);
246 ath79_nfc_set_swap_dma(true);
247 ath79_register_nfc();
250 static int __init rb95x_setup(void)
252 const struct rb_info *info;
254 info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x10000);
263 static void __init rb951g_setup(void)
268 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
269 AR934X_ETH_CFG_RXD_DELAY |
270 AR934X_ETH_CFG_SW_ONLY_MODE);
272 ath79_register_mdio(0, 0x0);
274 mdiobus_register_board_info(rb95x_mdio0_info,
275 ARRAY_SIZE(rb95x_mdio0_info));
277 ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
278 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
279 ath79_eth0_data.phy_mask = BIT(0);
280 ath79_eth0_pll_data.pll_1000 = 0x6f000000;
282 ath79_register_eth(0);
285 ath79_register_usb();
288 MIPS_MACHINE(ATH79_MACH_RB_951G, "951G", "MikroTik RouterBOARD 951G-2HnD",
291 static void __init rb951ui_setup(void)
296 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
298 ath79_register_mdio(1, 0x0);
300 ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
301 ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 1);
303 ath79_switch_data.phy4_mii_en = 1;
304 ath79_switch_data.phy_poll_mask = BIT(4);
305 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
306 ath79_eth0_data.phy_mask = BIT(4);
307 ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
308 ath79_register_eth(0);
310 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
311 ath79_register_eth(1);
313 gpio_request_one(20, GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
316 gpio_request_one(2, GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
320 ath79_register_usb();
322 ath79_register_leds_gpio(-1, ARRAY_SIZE(rb951ui_leds_gpio),
326 MIPS_MACHINE(ATH79_MACH_RB_951U, "951HnD", "MikroTik RouterBOARD 951Ui-2HnD",