62063e06a2bd5bc2ed82481d8f2683c16412fd59
[openwrt/staging/dedeckeh.git] / target / linux / ar71xx / files / arch / mips / ath79 / mach-rbsxtlite.c
1 /*
2 * MikroTik RouterBOARD SXT Lite support
3 *
4 * Copyright (C) 2012 Stijn Tintel <stijn@linux-ipv6.be>
5 * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
6 * Copyright (C) 2013 Vyacheslav Adamanov <adamanov@gmail.com>
7 *
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.
11 */
12
13 #define pr_fmt(fmt) "sxtlite: " fmt
14
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/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/rle.h>
25 #include <linux/routerboot.h>
26 #include <linux/gpio.h>
27
28 #include <asm/mach-ath79/ath79.h>
29 #include <asm/mach-ath79/ar71xx_regs.h>
30 #include "common.h"
31 #include "dev-ap9x-pci.h"
32 #include "dev-gpio-buttons.h"
33 #include "dev-leds-gpio.h"
34 #include "dev-eth.h"
35 #include "dev-m25p80.h"
36 #include "dev-nfc.h"
37 #include "dev-wmac.h"
38 #include "dev-usb.h"
39 #include "machtypes.h"
40 #include "routerboot.h"
41 #include <linux/ar8216_platform.h>
42
43 #define SXTLITE_GPIO_NAND_NCE 14
44 #define SXTLITE_GPIO_LED_USER 3
45 #define SXTLITE_GPIO_LED_1 13
46 #define SXTLITE_GPIO_LED_2 12
47 #define SXTLITE_GPIO_LED_3 4
48 #define SXTLITE_GPIO_LED_4 21
49 #define SXTLITE_GPIO_LED_5 18
50 #define SXTLITE_GPIO_LED_POWER 11
51
52 #define SXTLITE_GPIO_BUZZER 19
53
54 #define SXTLITE_GPIO_BTN_RESET 15
55
56 #define SXTLITE_KEYS_POLL_INTERVAL 20
57 #define SXTLITE_KEYS_DEBOUNCE_INTERVAL (3 * SXTLITE_KEYS_POLL_INTERVAL)
58
59 static struct mtd_partition rbsxtlite_nand_partitions[] = {
60 {
61 .name = "booter",
62 .offset = 0,
63 .size = (256 * 1024),
64 .mask_flags = MTD_WRITEABLE,
65 },
66 {
67 .name = "kernel",
68 .offset = (256 * 1024),
69 .size = (4 * 1024 * 1024) - (256 * 1024),
70 },
71 {
72 .name = "ubi",
73 .offset = MTDPART_OFS_NXTBLK,
74 .size = MTDPART_SIZ_FULL,
75 },
76 };
77
78 static struct gpio_led rbsxtlite_leds_gpio[] __initdata = {
79 {
80 .name = "rb:green:user",
81 .gpio = SXTLITE_GPIO_LED_USER,
82 .active_low = 1,
83 },
84 {
85 .name = "rb:green:led1",
86 .gpio = SXTLITE_GPIO_LED_1,
87 .active_low = 1,
88 },
89 {
90 .name = "rb:green:led2",
91 .gpio = SXTLITE_GPIO_LED_2,
92 .active_low = 1,
93 },
94 {
95 .name = "rb:green:led3",
96 .gpio = SXTLITE_GPIO_LED_3,
97 .active_low = 1,
98 },
99 {
100 .name = "rb:green:led4",
101 .gpio = SXTLITE_GPIO_LED_4,
102 .active_low = 1,
103 },
104 {
105 .name = "rb:green:led5",
106 .gpio = SXTLITE_GPIO_LED_5,
107 .active_low = 1,
108 },
109 {
110 .name = "rb:green:power",
111 .gpio = SXTLITE_GPIO_LED_POWER,
112 .default_state = LEDS_GPIO_DEFSTATE_KEEP,
113 },
114 };
115
116 static struct gpio_keys_button rbsxtlite_gpio_keys[] __initdata = {
117 {
118 .desc = "Reset button",
119 .type = EV_KEY,
120 .code = KEY_RESTART,
121 .debounce_interval = SXTLITE_KEYS_DEBOUNCE_INTERVAL,
122 .gpio = SXTLITE_GPIO_BTN_RESET,
123 .active_low = 0,
124 },
125 };
126
127 static int __init rbsxtlite_rbinfo_init(void)
128 {
129 const struct rb_info *info;
130
131 info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x10000);
132 if (!info)
133 return -EINVAL;
134 return 0;
135
136 }
137
138 void __init rbsxtlite_wlan_init(void)
139 {
140 char *art_buf;
141 u8 wlan_mac[ETH_ALEN];
142
143 art_buf = rb_get_wlan_data();
144 if (art_buf == NULL)
145 return;
146
147 ath79_init_mac(wlan_mac, ath79_mac_base, 1);
148 ath79_register_wmac(art_buf + 0x1000, wlan_mac);
149
150 kfree(art_buf);
151 }
152
153 static void rbsxtlite_nand_select_chip(int chip_no)
154 {
155 switch (chip_no) {
156 case 0:
157 gpio_set_value(SXTLITE_GPIO_NAND_NCE, 0);
158 break;
159 default:
160 gpio_set_value(SXTLITE_GPIO_NAND_NCE, 1);
161 break;
162 }
163 ndelay(500);
164 }
165
166 static struct nand_ecclayout rbsxtlite_nand_ecclayout = {
167 .eccbytes = 6,
168 .eccpos = { 8, 9, 10, 13, 14, 15 },
169 .oobavail = 9,
170 .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } }
171 };
172
173 static int rbsxtlite_nand_scan_fixup(struct mtd_info *mtd)
174 {
175 struct nand_chip *chip = mtd->priv;
176
177 if (mtd->writesize == 512) {
178 /*
179 * Use the OLD Yaffs-1 OOB layout, otherwise RouterBoot
180 * will not be able to find the kernel that we load.
181 */
182 chip->ecc.layout = &rbsxtlite_nand_ecclayout;
183 }
184
185 return 0;
186 }
187
188 void __init rbsxtlite_gpio_init(void)
189 {
190 gpio_request_one(SXTLITE_GPIO_NAND_NCE, GPIOF_OUT_INIT_HIGH, "NAND nCE");
191 }
192
193 void __init rbsxtlite_nand_init(void)
194 {
195 ath79_nfc_set_scan_fixup(rbsxtlite_nand_scan_fixup);
196 ath79_nfc_set_parts(rbsxtlite_nand_partitions,
197 ARRAY_SIZE(rbsxtlite_nand_partitions));
198 ath79_nfc_set_select_chip(rbsxtlite_nand_select_chip);
199 ath79_nfc_set_swap_dma(true);
200 ath79_register_nfc();
201 }
202
203
204 static void __init rbsxtlite_setup(void)
205 {
206 if(rbsxtlite_rbinfo_init())
207 return;
208 rbsxtlite_nand_init();
209 rbsxtlite_wlan_init();
210
211 ath79_register_leds_gpio(-1, ARRAY_SIZE(rbsxtlite_leds_gpio),
212 rbsxtlite_leds_gpio);
213 ath79_register_gpio_keys_polled(-1, SXTLITE_KEYS_POLL_INTERVAL,
214 ARRAY_SIZE(rbsxtlite_gpio_keys),
215 rbsxtlite_gpio_keys);
216
217 ath79_setup_ar934x_eth_cfg(AR934X_ETH_CFG_SW_ONLY_MODE);
218
219 ath79_register_mdio(1, 0x0);
220
221 /* GMAC0 is left unused */
222
223 /* GMAC1 is connected to MAC0 on the internal switch */
224 /* The ethernet port connects to PHY P0, which connects to MAC1
225 on the internal switch */
226 ath79_init_mac(ath79_eth1_data.mac_addr, ath79_mac_base, 0);
227 ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
228 ath79_register_eth(1);
229
230
231 }
232
233
234 MIPS_MACHINE(ATH79_MACH_RB_SXTLITE2ND, "sxt2n", "MikroTik RouterBOARD SXT Lite2",
235 rbsxtlite_setup);
236
237 MIPS_MACHINE(ATH79_MACH_RB_SXTLITE5ND, "sxt5n", "MikroTik RouterBOARD SXT Lite5",
238 rbsxtlite_setup);
239