2 * MikroTik RouterBOARD 2011 support
4 * Copyright (C) 2012 Stijn Tintel <stijn@linux-ipv6.be>
5 * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
12 #define pr_fmt(fmt) "rb2011: " fmt
14 #include <linux/version.h>
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 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
22 #include <linux/mtd/nand.h>
24 #include <linux/mtd/rawnand.h>
26 #include <linux/mtd/partitions.h>
27 #include <linux/spi/spi.h>
28 #include <linux/spi/flash.h>
29 #include <linux/routerboot.h>
30 #include <linux/gpio.h>
31 #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"
46 #define RB2011_GPIO_NAND_NCE 14
47 #define RB2011_GPIO_SFP_LOS 21
49 #define RB_ROUTERBOOT_OFFSET 0x0000
50 #define RB_ROUTERBOOT_MIN_SIZE 0xb000
51 #define RB_HARD_CFG_SIZE 0x1000
52 #define RB_BIOS_OFFSET 0xd000
53 #define RB_BIOS_SIZE 0x1000
54 #define RB_SOFT_CFG_OFFSET 0xf000
55 #define RB_SOFT_CFG_SIZE 0x1000
57 #define RB_ART_SIZE 0x10000
59 #define RB2011_FLAG_SFP BIT(0)
60 #define RB2011_FLAG_USB BIT(1)
61 #define RB2011_FLAG_WLAN BIT(2)
63 static struct mtd_partition rb2011_spi_partitions
[] = {
66 .offset
= RB_ROUTERBOOT_OFFSET
,
67 .mask_flags
= MTD_WRITEABLE
,
69 .name
= "hard_config",
70 .size
= RB_HARD_CFG_SIZE
,
71 .mask_flags
= MTD_WRITEABLE
,
74 .offset
= RB_BIOS_OFFSET
,
76 .mask_flags
= MTD_WRITEABLE
,
78 .name
= "soft_config",
79 .size
= RB_SOFT_CFG_SIZE
,
83 static void __init
rb2011_init_partitions(const struct rb_info
*info
)
85 rb2011_spi_partitions
[0].size
= info
->hard_cfg_offs
;
86 rb2011_spi_partitions
[1].offset
= info
->hard_cfg_offs
;
87 rb2011_spi_partitions
[3].offset
= info
->soft_cfg_offs
;
90 static struct mtd_partition rb2011_nand_partitions
[] = {
95 .mask_flags
= MTD_WRITEABLE
,
99 .offset
= (256 * 1024),
100 .size
= (4 * 1024 * 1024) - (256 * 1024),
104 .offset
= MTDPART_OFS_NXTBLK
,
105 .size
= MTDPART_SIZ_FULL
,
109 static struct flash_platform_data rb2011_spi_flash_data
= {
110 .parts
= rb2011_spi_partitions
,
111 .nr_parts
= ARRAY_SIZE(rb2011_spi_partitions
),
114 static struct ar8327_pad_cfg rb2011_ar8327_pad0_cfg
= {
115 .mode
= AR8327_PAD_MAC_RGMII
,
116 .txclk_delay_en
= true,
117 .rxclk_delay_en
= true,
118 .txclk_delay_sel
= AR8327_CLK_DELAY_SEL3
,
119 .rxclk_delay_sel
= AR8327_CLK_DELAY_SEL0
,
122 static struct ar8327_pad_cfg rb2011_ar8327_pad6_cfg
;
123 static struct ar8327_sgmii_cfg rb2011_ar8327_sgmii_cfg
;
125 static struct ar8327_led_cfg rb2011_ar8327_led_cfg
= {
126 .led_ctrl0
= 0xc731c731,
127 .led_ctrl1
= 0x00000000,
128 .led_ctrl2
= 0x00000000,
129 .led_ctrl3
= 0x0030c300,
133 static const struct ar8327_led_info rb2011_ar8327_leds
[] = {
134 AR8327_LED_INFO(PHY0_0
, HW
, "rb:green:eth1"),
135 AR8327_LED_INFO(PHY1_0
, HW
, "rb:green:eth2"),
136 AR8327_LED_INFO(PHY2_0
, HW
, "rb:green:eth3"),
137 AR8327_LED_INFO(PHY3_0
, HW
, "rb:green:eth4"),
138 AR8327_LED_INFO(PHY4_0
, HW
, "rb:green:eth5"),
139 AR8327_LED_INFO(PHY0_1
, SW
, "rb:green:eth6"),
140 AR8327_LED_INFO(PHY1_1
, SW
, "rb:green:eth7"),
141 AR8327_LED_INFO(PHY2_1
, SW
, "rb:green:eth8"),
142 AR8327_LED_INFO(PHY3_1
, SW
, "rb:green:eth9"),
143 AR8327_LED_INFO(PHY4_1
, SW
, "rb:green:eth10"),
144 AR8327_LED_INFO(PHY4_2
, SW
, "rb:green:usr"),
147 static struct ar8327_platform_data rb2011_ar8327_data
= {
148 .pad0_cfg
= &rb2011_ar8327_pad0_cfg
,
151 .speed
= AR8327_PORT_SPEED_1000
,
156 .led_cfg
= &rb2011_ar8327_led_cfg
,
157 .num_leds
= ARRAY_SIZE(rb2011_ar8327_leds
),
158 .leds
= rb2011_ar8327_leds
,
161 static struct mdio_board_info rb2011_mdio0_info
[] = {
163 .bus_id
= "ag71xx-mdio.0",
165 .platform_data
= &rb2011_ar8327_data
,
169 static void __init
rb2011_wlan_init(void)
172 u8 wlan_mac
[ETH_ALEN
];
174 art_buf
= rb_get_wlan_data();
178 ath79_init_mac(wlan_mac
, ath79_mac_base
, 11);
179 ath79_register_wmac(art_buf
+ 0x1000, wlan_mac
);
184 static void rb2011_nand_select_chip(int chip_no
)
188 gpio_set_value(RB2011_GPIO_NAND_NCE
, 0);
191 gpio_set_value(RB2011_GPIO_NAND_NCE
, 1);
197 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
198 static struct nand_ecclayout rb2011_nand_ecclayout
= {
200 .eccpos
= { 8, 9, 10, 13, 14, 15 },
202 .oobfree
= { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
207 static int rb2011_ooblayout_ecc(struct mtd_info
*mtd
, int section
,
208 struct mtd_oob_region
*oobregion
)
212 oobregion
->offset
= 8;
213 oobregion
->length
= 3;
216 oobregion
->offset
= 13;
217 oobregion
->length
= 3;
224 static int rb2011_ooblayout_free(struct mtd_info
*mtd
, int section
,
225 struct mtd_oob_region
*oobregion
)
229 oobregion
->offset
= 0;
230 oobregion
->length
= 4;
233 oobregion
->offset
= 4;
234 oobregion
->length
= 1;
237 oobregion
->offset
= 6;
238 oobregion
->length
= 2;
241 oobregion
->offset
= 11;
242 oobregion
->length
= 2;
249 static const struct mtd_ooblayout_ops rb2011_nand_ecclayout_ops
= {
250 .ecc
= rb2011_ooblayout_ecc
,
251 .free
= rb2011_ooblayout_free
,
255 static int rb2011_nand_scan_fixup(struct mtd_info
*mtd
)
257 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
258 struct nand_chip
*chip
= mtd
->priv
;
260 struct nand_chip
*chip
= mtd_to_nand(mtd
);
263 if (mtd
->writesize
== 512) {
265 * Use the OLD Yaffs-1 OOB layout, otherwise RouterBoot
266 * will not be able to find the kernel that we load.
268 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
269 chip
->ecc
.layout
= &rb2011_nand_ecclayout
;
271 mtd_set_ooblayout(mtd
, &rb2011_nand_ecclayout_ops
);
275 chip
->options
= NAND_NO_SUBPAGE_WRITE
;
280 static void __init
rb2011_nand_init(void)
282 gpio_request_one(RB2011_GPIO_NAND_NCE
, GPIOF_OUT_INIT_HIGH
, "NAND nCE");
284 ath79_nfc_set_scan_fixup(rb2011_nand_scan_fixup
);
285 ath79_nfc_set_parts(rb2011_nand_partitions
,
286 ARRAY_SIZE(rb2011_nand_partitions
));
287 ath79_nfc_set_select_chip(rb2011_nand_select_chip
);
288 ath79_nfc_set_swap_dma(true);
289 ath79_register_nfc();
292 static int rb2011_get_port_link(unsigned port
)
297 /* The Loss of signal line is active low */
298 return !gpio_get_value(RB2011_GPIO_SFP_LOS
);
301 static void __init
rb2011_sfp_init(void)
303 gpio_request_one(RB2011_GPIO_SFP_LOS
, GPIOF_IN
, "SFP LOS");
305 rb2011_ar8327_pad6_cfg
.mode
= AR8327_PAD_MAC_SGMII
;
307 rb2011_ar8327_data
.pad6_cfg
= &rb2011_ar8327_pad6_cfg
;
309 rb2011_ar8327_sgmii_cfg
.sgmii_ctrl
= 0xc70167d0;
310 rb2011_ar8327_sgmii_cfg
.serdes_aen
= true;
312 rb2011_ar8327_data
.sgmii_cfg
= &rb2011_ar8327_sgmii_cfg
;
314 rb2011_ar8327_data
.port6_cfg
.force_link
= 1;
315 rb2011_ar8327_data
.port6_cfg
.speed
= AR8327_PORT_SPEED_1000
;
316 rb2011_ar8327_data
.port6_cfg
.duplex
= 1;
318 rb2011_ar8327_data
.get_port_link
= rb2011_get_port_link
;
321 static int __init
rb2011_setup(u32 flags
)
323 const struct rb_info
*info
;
326 info
= rb_init_info((void *) KSEG1ADDR(0x1f000000), 0x10000);
330 scnprintf(buf
, sizeof(buf
), "Mikrotik RouterBOARD %s",
331 (info
->board_name
) ? info
->board_name
: "");
332 mips_set_machine_name(buf
);
334 rb2011_init_partitions(info
);
336 ath79_register_m25p80(&rb2011_spi_flash_data
);
339 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0
|
340 AR934X_ETH_CFG_RXD_DELAY
|
341 AR934X_ETH_CFG_SW_ONLY_MODE
);
343 ath79_register_mdio(1, 0x0);
344 ath79_register_mdio(0, 0x0);
346 mdiobus_register_board_info(rb2011_mdio0_info
,
347 ARRAY_SIZE(rb2011_mdio0_info
));
349 /* GMAC0 is connected to an ar8327 switch */
350 ath79_init_mac(ath79_eth0_data
.mac_addr
, ath79_mac_base
, 0);
351 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
352 ath79_eth0_data
.phy_mask
= BIT(0);
353 ath79_eth0_data
.mii_bus_dev
= &ath79_mdio0_device
.dev
;
354 ath79_eth0_pll_data
.pll_1000
= 0x6f000000;
356 ath79_register_eth(0);
358 /* GMAC1 is connected to the internal switch */
359 ath79_init_mac(ath79_eth1_data
.mac_addr
, ath79_mac_base
, 5);
360 ath79_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_GMII
;
361 ath79_eth1_data
.speed
= SPEED_1000
;
362 ath79_eth1_data
.duplex
= DUPLEX_FULL
;
364 ath79_register_eth(1);
366 if (flags
& RB2011_FLAG_SFP
)
369 if (flags
& RB2011_FLAG_WLAN
)
372 if (flags
& RB2011_FLAG_USB
)
373 ath79_register_usb();
378 static void __init
rb2011l_setup(void)
383 MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011L
, "2011L", rb2011l_setup
);
385 static void __init
rb2011us_setup(void)
387 rb2011_setup(RB2011_FLAG_SFP
| RB2011_FLAG_USB
);
390 MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011US
, "2011US", rb2011us_setup
);
392 static void __init
rb2011r5_setup(void)
394 rb2011_setup(RB2011_FLAG_SFP
| RB2011_FLAG_USB
| RB2011_FLAG_WLAN
);
397 MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011R5
, "2011r5", rb2011r5_setup
);
399 static void __init
rb2011g_setup(void)
401 rb2011_setup(RB2011_FLAG_SFP
|
406 MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011G
, "2011G", rb2011g_setup
);