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/phy.h>
15 #include <linux/delay.h>
16 #include <linux/platform_device.h>
17 #include <linux/ath9k_platform.h>
18 #include <linux/ar8216_platform.h>
19 #include <linux/mtd/mtd.h>
20 #include <linux/mtd/nand.h>
21 #include <linux/mtd/partitions.h>
22 #include <linux/spi/spi.h>
23 #include <linux/spi/flash.h>
24 #include <linux/routerboot.h>
25 #include <linux/gpio.h>
26 #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"
41 #define RB2011_GPIO_NAND_NCE 14
42 #define RB2011_GPIO_SFP_LOS 21
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 RB_ART_SIZE 0x10000
54 #define RB2011_FLAG_SFP BIT(0)
55 #define RB2011_FLAG_USB BIT(1)
56 #define RB2011_FLAG_WLAN BIT(2)
58 static struct mtd_partition rb2011_spi_partitions
[] = {
61 .offset
= RB_ROUTERBOOT_OFFSET
,
62 .mask_flags
= MTD_WRITEABLE
,
64 .name
= "hard_config",
65 .size
= RB_HARD_CFG_SIZE
,
66 .mask_flags
= MTD_WRITEABLE
,
69 .offset
= RB_BIOS_OFFSET
,
71 .mask_flags
= MTD_WRITEABLE
,
73 .name
= "soft_config",
74 .size
= RB_SOFT_CFG_SIZE
,
78 static void __init
rb2011_init_partitions(const struct rb_info
*info
)
80 rb2011_spi_partitions
[0].size
= info
->hard_cfg_offs
;
81 rb2011_spi_partitions
[1].offset
= info
->hard_cfg_offs
;
82 rb2011_spi_partitions
[3].offset
= info
->soft_cfg_offs
;
85 static struct mtd_partition rb2011_nand_partitions
[] = {
90 .mask_flags
= MTD_WRITEABLE
,
94 .offset
= (256 * 1024),
95 .size
= (4 * 1024 * 1024) - (256 * 1024),
99 .offset
= MTDPART_OFS_NXTBLK
,
100 .size
= MTDPART_SIZ_FULL
,
104 static struct flash_platform_data rb2011_spi_flash_data
= {
105 .parts
= rb2011_spi_partitions
,
106 .nr_parts
= ARRAY_SIZE(rb2011_spi_partitions
),
109 static struct ar8327_pad_cfg rb2011_ar8327_pad0_cfg
= {
110 .mode
= AR8327_PAD_MAC_RGMII
,
111 .txclk_delay_en
= true,
112 .rxclk_delay_en
= true,
113 .txclk_delay_sel
= AR8327_CLK_DELAY_SEL3
,
114 .rxclk_delay_sel
= AR8327_CLK_DELAY_SEL0
,
117 static struct ar8327_pad_cfg rb2011_ar8327_pad6_cfg
;
118 static struct ar8327_sgmii_cfg rb2011_ar8327_sgmii_cfg
;
120 static struct ar8327_led_cfg rb2011_ar8327_led_cfg
= {
121 .led_ctrl0
= 0xc731c731,
122 .led_ctrl1
= 0x00000000,
123 .led_ctrl2
= 0x00000000,
124 .led_ctrl3
= 0x0030c300,
128 static const struct ar8327_led_info rb2011_ar8327_leds
[] = {
129 AR8327_LED_INFO(PHY0_0
, HW
, "rb:green:eth1"),
130 AR8327_LED_INFO(PHY1_0
, HW
, "rb:green:eth2"),
131 AR8327_LED_INFO(PHY2_0
, HW
, "rb:green:eth3"),
132 AR8327_LED_INFO(PHY3_0
, HW
, "rb:green:eth4"),
133 AR8327_LED_INFO(PHY4_0
, HW
, "rb:green:eth5"),
134 AR8327_LED_INFO(PHY0_1
, SW
, "rb:green:eth6"),
135 AR8327_LED_INFO(PHY1_1
, SW
, "rb:green:eth7"),
136 AR8327_LED_INFO(PHY2_1
, SW
, "rb:green:eth8"),
137 AR8327_LED_INFO(PHY3_1
, SW
, "rb:green:eth9"),
138 AR8327_LED_INFO(PHY4_1
, SW
, "rb:green:eth10"),
139 AR8327_LED_INFO(PHY4_2
, SW
, "rb:green:usr"),
142 static struct ar8327_platform_data rb2011_ar8327_data
= {
143 .pad0_cfg
= &rb2011_ar8327_pad0_cfg
,
146 .speed
= AR8327_PORT_SPEED_1000
,
151 .led_cfg
= &rb2011_ar8327_led_cfg
,
152 .num_leds
= ARRAY_SIZE(rb2011_ar8327_leds
),
153 .leds
= rb2011_ar8327_leds
,
156 static struct mdio_board_info rb2011_mdio0_info
[] = {
158 .bus_id
= "ag71xx-mdio.0",
160 .platform_data
= &rb2011_ar8327_data
,
164 static void __init
rb2011_wlan_init(void)
167 u8 wlan_mac
[ETH_ALEN
];
169 art_buf
= rb_get_wlan_data();
173 ath79_init_mac(wlan_mac
, ath79_mac_base
, 11);
174 ath79_register_wmac(art_buf
+ 0x1000, wlan_mac
);
179 static void rb2011_nand_select_chip(int chip_no
)
183 gpio_set_value(RB2011_GPIO_NAND_NCE
, 0);
186 gpio_set_value(RB2011_GPIO_NAND_NCE
, 1);
192 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
193 static struct nand_ecclayout rb2011_nand_ecclayout
= {
195 .eccpos
= { 8, 9, 10, 13, 14, 15 },
197 .oobfree
= { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
202 static int rb2011_ooblayout_ecc(struct mtd_info
*mtd
, int section
,
203 struct mtd_oob_region
*oobregion
)
207 oobregion
->offset
= 8;
208 oobregion
->length
= 3;
211 oobregion
->offset
= 13;
212 oobregion
->length
= 3;
219 static int rb2011_ooblayout_free(struct mtd_info
*mtd
, int section
,
220 struct mtd_oob_region
*oobregion
)
224 oobregion
->offset
= 0;
225 oobregion
->length
= 4;
228 oobregion
->offset
= 4;
229 oobregion
->length
= 1;
232 oobregion
->offset
= 6;
233 oobregion
->length
= 2;
236 oobregion
->offset
= 11;
237 oobregion
->length
= 2;
244 static const struct mtd_ooblayout_ops rb2011_nand_ecclayout_ops
= {
245 .ecc
= rb2011_ooblayout_ecc
,
246 .free
= rb2011_ooblayout_free
,
250 static int rb2011_nand_scan_fixup(struct mtd_info
*mtd
)
252 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
253 struct nand_chip
*chip
= mtd
->priv
;
256 if (mtd
->writesize
== 512) {
258 * Use the OLD Yaffs-1 OOB layout, otherwise RouterBoot
259 * will not be able to find the kernel that we load.
261 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
262 chip
->ecc
.layout
= &rb2011_nand_ecclayout
;
264 mtd_set_ooblayout(mtd
, &rb2011_nand_ecclayout_ops
);
271 static void __init
rb2011_nand_init(void)
273 gpio_request_one(RB2011_GPIO_NAND_NCE
, GPIOF_OUT_INIT_HIGH
, "NAND nCE");
275 ath79_nfc_set_scan_fixup(rb2011_nand_scan_fixup
);
276 ath79_nfc_set_parts(rb2011_nand_partitions
,
277 ARRAY_SIZE(rb2011_nand_partitions
));
278 ath79_nfc_set_select_chip(rb2011_nand_select_chip
);
279 ath79_nfc_set_swap_dma(true);
280 ath79_register_nfc();
283 static int rb2011_get_port_link(unsigned port
)
288 /* The Loss of signal line is active low */
289 return !gpio_get_value(RB2011_GPIO_SFP_LOS
);
292 static void __init
rb2011_sfp_init(void)
294 gpio_request_one(RB2011_GPIO_SFP_LOS
, GPIOF_IN
, "SFP LOS");
296 rb2011_ar8327_pad6_cfg
.mode
= AR8327_PAD_MAC_SGMII
;
298 rb2011_ar8327_data
.pad6_cfg
= &rb2011_ar8327_pad6_cfg
;
300 rb2011_ar8327_sgmii_cfg
.sgmii_ctrl
= 0xc70167d0;
301 rb2011_ar8327_sgmii_cfg
.serdes_aen
= true;
303 rb2011_ar8327_data
.sgmii_cfg
= &rb2011_ar8327_sgmii_cfg
;
305 rb2011_ar8327_data
.port6_cfg
.force_link
= 1;
306 rb2011_ar8327_data
.port6_cfg
.speed
= AR8327_PORT_SPEED_1000
;
307 rb2011_ar8327_data
.port6_cfg
.duplex
= 1;
309 rb2011_ar8327_data
.get_port_link
= rb2011_get_port_link
;
312 static int __init
rb2011_setup(u32 flags
)
314 const struct rb_info
*info
;
317 info
= rb_init_info((void *) KSEG1ADDR(0x1f000000), 0x10000);
321 scnprintf(buf
, sizeof(buf
), "Mikrotik RouterBOARD %s",
322 (info
->board_name
) ? info
->board_name
: "");
323 mips_set_machine_name(buf
);
325 rb2011_init_partitions(info
);
327 ath79_register_m25p80(&rb2011_spi_flash_data
);
330 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_RGMII_GMAC0
|
331 AR934X_ETH_CFG_RXD_DELAY
|
332 AR934X_ETH_CFG_SW_ONLY_MODE
);
334 ath79_register_mdio(1, 0x0);
335 ath79_register_mdio(0, 0x0);
337 mdiobus_register_board_info(rb2011_mdio0_info
,
338 ARRAY_SIZE(rb2011_mdio0_info
));
340 /* GMAC0 is connected to an ar8327 switch */
341 ath79_init_mac(ath79_eth0_data
.mac_addr
, ath79_mac_base
, 0);
342 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
343 ath79_eth0_data
.phy_mask
= BIT(0);
344 ath79_eth0_data
.mii_bus_dev
= &ath79_mdio0_device
.dev
;
345 ath79_eth0_pll_data
.pll_1000
= 0x6f000000;
347 ath79_register_eth(0);
349 /* GMAC1 is connected to the internal switch */
350 ath79_init_mac(ath79_eth1_data
.mac_addr
, ath79_mac_base
, 5);
351 ath79_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_GMII
;
352 ath79_eth1_data
.speed
= SPEED_1000
;
353 ath79_eth1_data
.duplex
= DUPLEX_FULL
;
355 ath79_register_eth(1);
357 if (flags
& RB2011_FLAG_SFP
)
360 if (flags
& RB2011_FLAG_WLAN
)
363 if (flags
& RB2011_FLAG_USB
)
364 ath79_register_usb();
369 static void __init
rb2011l_setup(void)
374 MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011L
, "2011L", rb2011l_setup
);
376 static void __init
rb2011us_setup(void)
378 rb2011_setup(RB2011_FLAG_SFP
| RB2011_FLAG_USB
);
381 MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011US
, "2011US", rb2011us_setup
);
383 static void __init
rb2011r5_setup(void)
385 rb2011_setup(RB2011_FLAG_SFP
| RB2011_FLAG_USB
| RB2011_FLAG_WLAN
);
388 MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011R5
, "2011r5", rb2011r5_setup
);
390 static void __init
rb2011g_setup(void)
392 rb2011_setup(RB2011_FLAG_SFP
|
397 MIPS_MACHINE_NONAME(ATH79_MACH_RB_2011G
, "2011G", rb2011g_setup
);