5da950bb88781aa1e86e229df8d9b3b28cf550b9
[openwrt/staging/yousong.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-rb941.c
1 /*
2 * MikroTik RouterBOARD 941-2nD support
3 *
4 * Copyright (C) 2016 Sergey Sergeev <adron@yapic.net>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10
11 #include <linux/export.h>
12 #include <linux/pci.h>
13 #include <linux/ath9k_platform.h>
14 #include <linux/platform_device.h>
15 #include <linux/phy.h>
16 #include <linux/ar8216_platform.h>
17 #include <linux/rle.h>
18 #include <linux/routerboot.h>
19 #include <linux/gpio.h>
20
21 #include <linux/mtd/mtd.h>
22 //#include <linux/mtd/nand.h>
23 #include <linux/mtd/partitions.h>
24
25 #include <asm/mach-ath79/ar71xx_regs.h>
26 #include <asm/mach-ath79/ath79.h>
27 #include <asm/mach-ath79/irq.h>
28
29 #include "common.h"
30 #include "dev-ap9x-pci.h"
31 #include "dev-eth.h"
32 #include "dev-spi.h"
33 #include "dev-gpio-buttons.h"
34 #include "dev-leds-gpio.h"
35 #include "dev-m25p80.h"
36 //#include "dev-usb.h"
37 #include "dev-wmac.h"
38 #include "machtypes.h"
39 #include "routerboot.h"
40
41 #define RB941_GPIO_LED_ACT 14
42 #define RB941_GPIO_BTN_RESET 16
43
44 #define RB941_KEYS_POLL_INTERVAL 20 /* msecs */
45 #define RB941_KEYS_DEBOUNCE_INTERVAL (3 * RB941_KEYS_POLL_INTERVAL)
46
47 #define RB_ROUTERBOOT_OFFSET 0x0000
48 #define RB_ROUTERBOOT_SIZE 0xe000
49 #define RB_HARD_CFG_OFFSET 0xe000
50 #define RB_HARD_CFG_SIZE 0x1000
51 #define RB_BIOS_OFFSET 0xf000
52 #define RB_BIOS_SIZE 0x1000
53 #define RB_ROUTERBOOT2_OFFSET 0x10000
54 #define RB_ROUTERBOOT2_SIZE 0xf000
55 #define RB_SOFT_CFG_OFFSET 0x1f000
56 #define RB_SOFT_CFG_SIZE 0x1000
57 #define RB_ROOTFS_OFFSET 0x20000
58 #define RB_ROOTFS_SIZE 0x9e0000
59 #define RB_KERNEL_OFFSET 0xa00000
60 #define RB_KERNEL_SIZE MTDPART_SIZ_FULL
61
62 void __init rb941_wlan_init(void)
63 {
64 char *art_buf;
65 u8 wlan_mac[ETH_ALEN];
66
67 art_buf = rb_get_wlan_data();
68 if (art_buf == NULL)
69 return;
70
71 ath79_init_mac(wlan_mac, ath79_mac_base, 11);
72 ath79_register_wmac(art_buf + 0x1000, wlan_mac);
73
74 kfree(art_buf);
75 }
76
77 static struct mtd_partition rb941_spi_partitions[] = {
78 {
79 .name = "routerboot",
80 .offset = RB_ROUTERBOOT_OFFSET,
81 .mask_flags = MTD_WRITEABLE,
82 .size = RB_ROUTERBOOT_SIZE,
83 }, {
84 .name = "hard_config",
85 .offset = RB_HARD_CFG_OFFSET,
86 .size = RB_HARD_CFG_SIZE,
87 .mask_flags = MTD_WRITEABLE,
88 }, {
89 .name = "bios",
90 .offset = RB_BIOS_OFFSET,
91 .size = RB_BIOS_SIZE,
92 .mask_flags = MTD_WRITEABLE,
93 }, {
94 .name = "routerboot2",
95 .offset = RB_ROUTERBOOT2_OFFSET,
96 .size = RB_ROUTERBOOT2_SIZE,
97 .mask_flags = MTD_WRITEABLE,
98 }, {
99 .name = "soft_config",
100 .offset = RB_SOFT_CFG_OFFSET,
101 .size = RB_SOFT_CFG_SIZE,
102 }, {
103 .name = "rootfs",
104 .offset = RB_ROOTFS_OFFSET,
105 .size = RB_ROOTFS_SIZE,
106 }, {
107 .name = "kernel",
108 .offset = RB_KERNEL_OFFSET,
109 .size = RB_KERNEL_SIZE,
110 }
111 };
112
113 static struct flash_platform_data rb941_spi_flash_data = {
114 .parts = rb941_spi_partitions,
115 .nr_parts = ARRAY_SIZE(rb941_spi_partitions),
116 };
117
118 static struct gpio_led rb941_leds[] __initdata = {
119 {
120 .name = "rb:green:act",
121 .gpio = RB941_GPIO_LED_ACT,
122 .active_low = 1,
123 },
124 };
125
126 static struct gpio_keys_button rb941_gpio_keys[] __initdata = {
127 {
128 .desc = "Reset button",
129 .type = EV_KEY,
130 .code = KEY_RESTART,
131 .debounce_interval = RB941_KEYS_DEBOUNCE_INTERVAL,
132 .gpio = RB941_GPIO_BTN_RESET,
133 .active_low = 1,
134 },
135 };
136
137 static void __init rb941_setup(void)
138 {
139 const struct rb_info *info;
140 //try to get rb_info data
141 info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x20000);
142 if (!info){
143 pr_err("%s: Can't get rb_info data from flash!\n", __func__);
144 //return -EINVAL; //Not critical ... continue!
145 }
146 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
147 ath79_register_m25p80(&rb941_spi_flash_data);
148 ath79_register_mdio(0, 0x0);
149
150 /* WAN. We have no WAN. Only LAN. */
151 /*ath79_switch_data.phy4_mii_en = 1;
152 ath79_switch_data.phy_poll_mask = BIT(4);
153 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
154 ath79_eth0_data.phy_mask = BIT(4);
155 ath79_init_mac(ath79_eth0_data.mac_addr, ath79_mac_base, 0);
156 ath79_register_eth(0); */
157
158 /* LAN */
159 ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 0);
160 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
161 ath79_register_eth(1);
162
163 //ath79_register_usb();
164
165 rb941_wlan_init();
166
167 ath79_register_leds_gpio(-1, ARRAY_SIZE(rb941_leds), rb941_leds);
168 ath79_register_gpio_keys_polled(-1, RB941_KEYS_POLL_INTERVAL,
169 ARRAY_SIZE(rb941_gpio_keys),
170 rb941_gpio_keys);
171 }
172
173 MIPS_MACHINE(ATH79_MACH_RB_941, "H951L", "MikroTik RouterBOARD 941-2nD", rb941_setup);