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/phy.h>
16 #include <linux/delay.h>
17 #include <linux/platform_device.h>
18 #include <linux/ath9k_platform.h>
19 #include <linux/ar8216_platform.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/mtd/nand.h>
22 #include <linux/mtd/partitions.h>
23 #include <linux/spi/spi.h>
24 #include <linux/spi/flash.h>
25 #include <linux/routerboot.h>
26 #include <linux/gpio.h>
27 #include <linux/version.h>
29 #include <asm/mach-ath79/ath79.h>
30 #include <asm/mach-ath79/ar71xx_regs.h>
34 #include "dev-m25p80.h"
38 #include "machtypes.h"
39 #include "routerboot.h"
40 #include "dev-leds-gpio.h"
42 #define RB95X_GPIO_NAND_NCE 14
44 static struct mtd_partition rb95x_nand_partitions[] = {
49 .mask_flags = MTD_WRITEABLE,
53 .offset = (256 * 1024),
54 .size = (4 * 1024 * 1024) - (256 * 1024),
58 .offset = MTDPART_OFS_NXTBLK,
59 .size = MTDPART_SIZ_FULL,
63 static struct gpio_led rb951ui_leds_gpio[] __initdata = {
65 .name = "rb:green:wlan",
69 .name = "rb:green:act",
73 .name = "rb:green:port1",
77 .name = "rb:green:port2",
81 .name = "rb:green:port3",
85 .name = "rb:green:port4",
89 .name = "rb:green:port5",
95 static struct ar8327_pad_cfg rb95x_ar8327_pad0_cfg = {
96 .mode = AR8327_PAD_MAC_RGMII,
97 .txclk_delay_en = true,
98 .rxclk_delay_en = true,
99 .txclk_delay_sel = AR8327_CLK_DELAY_SEL1,
100 .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2,
103 static struct ar8327_platform_data rb95x_ar8327_data = {
104 .pad0_cfg = &rb95x_ar8327_pad0_cfg,
107 .speed = AR8327_PORT_SPEED_1000,
114 static struct mdio_board_info rb95x_mdio0_info[] = {
116 .bus_id = "ag71xx-mdio.0",
118 .platform_data = &rb95x_ar8327_data,
122 void __init rb95x_wlan_init(void)
125 u8 wlan_mac[ETH_ALEN];
127 art_buf = rb_get_wlan_data();
131 ath79_init_mac(wlan_mac, ath79_mac_base, 11);
132 ath79_register_wmac(art_buf + 0x1000, wlan_mac);
137 static void rb95x_nand_select_chip(int chip_no)
141 gpio_set_value(RB95X_GPIO_NAND_NCE, 0);
144 gpio_set_value(RB95X_GPIO_NAND_NCE, 1);
150 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
151 static struct nand_ecclayout rb95x_nand_ecclayout = {
153 .eccpos = { 8, 9, 10, 13, 14, 15 },
155 .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
160 static int rb95x_ooblayout_ecc(struct mtd_info *mtd, int section,
161 struct mtd_oob_region *oobregion)
165 oobregion->offset = 8;
166 oobregion->length = 3;
169 oobregion->offset = 13;
170 oobregion->length = 3;
177 static int rb95x_ooblayout_free(struct mtd_info *mtd, int section,
178 struct mtd_oob_region *oobregion)
182 oobregion->offset = 0;
183 oobregion->length = 4;
186 oobregion->offset = 4;
187 oobregion->length = 1;
190 oobregion->offset = 6;
191 oobregion->length = 2;
194 oobregion->offset = 11;
195 oobregion->length = 2;
202 static const struct mtd_ooblayout_ops rb95x_nand_ecclayout_ops = {
203 .ecc = rb95x_ooblayout_ecc,
204 .free = rb95x_ooblayout_free,
208 static int rb95x_nand_scan_fixup(struct mtd_info *mtd)
210 struct nand_chip *chip = mtd->priv;
212 if (mtd->writesize == 512) {
214 * Use the OLD Yaffs-1 OOB layout, otherwise RouterBoot
215 * will not be able to find the kernel that we load.
217 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
218 chip->ecc.layout = &rb95x_nand_ecclayout;
220 mtd_set_ooblayout(mtd, &rb95x_nand_ecclayout_ops);
224 chip->options = NAND_NO_SUBPAGE_WRITE;
229 void __init rb95x_nand_init(void)
231 gpio_request_one(RB95X_GPIO_NAND_NCE, GPIOF_OUT_INIT_HIGH, "NAND nCE");
233 ath79_nfc_set_scan_fixup(rb95x_nand_scan_fixup);
234 ath79_nfc_set_parts(rb95x_nand_partitions,
235 ARRAY_SIZE(rb95x_nand_partitions));
236 ath79_nfc_set_select_chip(rb95x_nand_select_chip);
237 ath79_nfc_set_swap_dma(true);
238 ath79_register_nfc();
241 static int __init rb95x_setup(void)
243 const struct rb_info *info;
245 info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x10000);
254 static void __init rb951g_setup(void)
259 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0 |
260 AR934X_ETH_CFG_SW_ONLY_MODE);
262 ath79_register_mdio(0, 0x0);
264 mdiobus_register_board_info(rb95x_mdio0_info,
265 ARRAY_SIZE(rb95x_mdio0_info));
267 ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
268 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
269 ath79_eth0_data.phy_mask = BIT(0);
271 ath79_register_eth(0);
274 ath79_register_usb();
277 MIPS_MACHINE(ATH79_MACH_RB_951G, "951G", "MikroTik RouterBOARD 951G-2HnD",
280 static void __init rb951ui_setup(void)
285 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
287 ath79_register_mdio(1, 0x0);
289 ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
290 ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 1);
292 ath79_switch_data.phy4_mii_en = 1;
293 ath79_switch_data.phy_poll_mask = BIT(4);
294 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
295 ath79_eth0_data.phy_mask = BIT(4);
296 ath79_eth0_data.mii_bus_dev = &ath79_mdio1_device.dev;
297 ath79_register_eth(0);
299 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
300 ath79_register_eth(1);
302 gpio_request_one(20, GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
305 gpio_request_one(2, GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
309 ath79_register_usb();
311 ath79_register_leds_gpio(-1, ARRAY_SIZE(rb951ui_leds_gpio),
315 MIPS_MACHINE(ATH79_MACH_RB_951U, "951HnD", "MikroTik RouterBOARD 951Ui-2HnD",