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/platform_device.h>
16 #include <linux/ath9k_platform.h>
17 #include <linux/ar8216_platform.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/partitions.h>
20 #include <linux/spi/spi.h>
21 #include <linux/spi/flash.h>
22 #include <linux/rle.h>
23 #include <linux/routerboot.h>
25 #include <asm/mach-ath79/ath79.h>
26 #include <asm/mach-ath79/ar71xx_regs.h>
30 #include "dev-m25p80.h"
32 #include "machtypes.h"
33 #include "routerboot.h"
35 #define RB_ROUTERBOOT_OFFSET 0x0000
36 #define RB_ROUTERBOOT_SIZE 0xb000
37 #define RB_HARD_CFG_OFFSET 0xb000
38 #define RB_HARD_CFG_SIZE 0x1000
39 #define RB_BIOS_OFFSET 0xd000
40 #define RB_BIOS_SIZE 0x2000
41 #define RB_SOFT_CFG_OFFSET 0xf000
42 #define RB_SOFT_CFG_SIZE 0x1000
44 #define RB_ART_SIZE 0x10000
46 static struct mtd_partition rb2011_spi_partitions
[] = {
49 .offset
= RB_ROUTERBOOT_OFFSET
,
50 .size
= RB_ROUTERBOOT_SIZE
,
51 .mask_flags
= MTD_WRITEABLE
,
53 .name
= "hard_config",
54 .offset
= RB_HARD_CFG_OFFSET
,
55 .size
= RB_HARD_CFG_SIZE
,
56 .mask_flags
= MTD_WRITEABLE
,
59 .offset
= RB_BIOS_OFFSET
,
61 .mask_flags
= MTD_WRITEABLE
,
63 .name
= "soft_config",
64 .offset
= RB_SOFT_CFG_OFFSET
,
65 .size
= RB_SOFT_CFG_SIZE
,
69 static struct flash_platform_data rb2011_spi_flash_data
= {
70 .parts
= rb2011_spi_partitions
,
71 .nr_parts
= ARRAY_SIZE(rb2011_spi_partitions
),
74 static struct ar8327_pad_cfg rb2011_ar8327_pad0_cfg
= {
75 .mode
= AR8327_PAD_MAC_RGMII
,
76 .txclk_delay_en
= true,
77 .rxclk_delay_en
= true,
78 .txclk_delay_sel
= AR8327_CLK_DELAY_SEL1
,
79 .rxclk_delay_sel
= AR8327_CLK_DELAY_SEL2
,
82 static struct ar8327_platform_data rb2011_ar8327_data
= {
83 .pad0_cfg
= &rb2011_ar8327_pad0_cfg
,
86 .speed
= AR8327_PORT_SPEED_1000
,
93 static struct mdio_board_info rb2011_mdio0_info
[] = {
95 .bus_id
= "ag71xx-mdio.0",
97 .platform_data
= &rb2011_ar8327_data
,
101 static void __init
rb2011_gmac_setup(void)
106 base
= ioremap(AR934X_GMAC_BASE
, AR934X_GMAC_SIZE
);
108 t
= __raw_readl(base
+ AR934X_GMAC_REG_ETH_CFG
);
109 t
&= ~(AR934X_ETH_CFG_RGMII_GMAC0
| AR934X_ETH_CFG_MII_GMAC0
|
110 AR934X_ETH_CFG_GMII_GMAC0
| AR934X_ETH_CFG_SW_ONLY_MODE
);
111 t
|= AR934X_ETH_CFG_RGMII_GMAC0
| AR934X_ETH_CFG_SW_ONLY_MODE
;
113 __raw_writel(t
, base
+ AR934X_GMAC_REG_ETH_CFG
);
118 static void __init
rb2011_wlan_init(void)
120 u8
*hard_cfg
= (u8
*) KSEG1ADDR(0x1f000000 + RB_HARD_CFG_OFFSET
);
124 u8 wlan_mac
[ETH_ALEN
];
127 err
= routerboot_find_tag(hard_cfg
, RB_HARD_CFG_SIZE
, RB_ID_WLAN_DATA
,
130 pr_err("no calibration data found\n");
134 art_buf
= kmalloc(RB_ART_SIZE
, GFP_KERNEL
);
135 if (art_buf
== NULL
) {
136 pr_err("no memory for calibration data\n");
140 err
= rle_decode((char *) tag
, tag_len
, art_buf
, RB_ART_SIZE
,
143 pr_err("unable to decode calibration data\n");
147 ath79_init_mac(wlan_mac
, ath79_mac_base
, 11);
148 ath79_register_wmac(art_buf
+ 0x1000, wlan_mac
);
154 static void __init
rb2011_setup(void)
156 ath79_register_m25p80(&rb2011_spi_flash_data
);
160 ath79_register_mdio(1, 0x0);
161 ath79_register_mdio(0, 0x0);
163 mdiobus_register_board_info(rb2011_mdio0_info
,
164 ARRAY_SIZE(rb2011_mdio0_info
));
166 /* GMAC0 is connected to an ar8327 switch */
167 ath79_init_mac(ath79_eth0_data
.mac_addr
, ath79_mac_base
, 0);
168 ath79_eth0_data
.phy_if_mode
= PHY_INTERFACE_MODE_RGMII
;
169 ath79_eth0_data
.phy_mask
= BIT(0);
170 ath79_eth0_data
.mii_bus_dev
= &ath79_mdio0_device
.dev
;
171 ath79_eth0_pll_data
.pll_1000
= 0x06000000;
173 ath79_register_eth(0);
175 /* GMAC1 is connected to the internal switch */
176 ath79_init_mac(ath79_eth1_data
.mac_addr
, ath79_mac_base
, 5);
177 ath79_eth1_data
.phy_if_mode
= PHY_INTERFACE_MODE_GMII
;
178 ath79_eth1_data
.speed
= SPEED_1000
;
179 ath79_eth1_data
.duplex
= DUPLEX_FULL
;
181 ath79_register_eth(1);
184 MIPS_MACHINE(ATH79_MACH_RB_2011L
, "2011L", "MikroTik RouterBOARD 2011L",
187 static void __init
rb2011g_setup(void)
193 MIPS_MACHINE(ATH79_MACH_RB_2011G
, "2011G", "MikroTik RouterBOARD 2011UAS-2HnD",