rtl8366_smi: move RTL8366S driver into a separate file
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-wzr-hp-g300nh.c
1 /*
2  *  Buffalo WZR-HP-G300NH board support
3  *
4  *  Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
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/platform_device.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14 #include <linux/nxp_74hc153.h>
15 #include <linux/rtl8366s.h>
16
17 #include <asm/mips_machine.h>
18 #include <asm/mach-ar71xx/ar71xx.h>
19 #include <asm/mach-ar71xx/ar91xx_flash.h>
20
21 #include "machtype.h"
22 #include "devices.h"
23 #include "dev-ar913x-wmac.h"
24 #include "dev-gpio-buttons.h"
25 #include "dev-leds-gpio.h"
26 #include "dev-usb.h"
27
28 #define WZRHPG300NH_GPIO_LED_USB        0
29 #define WZRHPG300NH_GPIO_LED_DIAG       1
30 #define WZRHPG300NH_GPIO_LED_WIRELESS   6
31 #define WZRHPG300NH_GPIO_LED_SECURITY   17
32 #define WZRHPG300NH_GPIO_LED_ROUTER     18
33
34 #define WZRHPG300NH_GPIO_RTL8366_SDA    19
35 #define WZRHPG300NH_GPIO_RTL8366_SCK    20
36
37 #define WZRHPG300NH_GPIO_74HC153_S0     9
38 #define WZRHPG300NH_GPIO_74HC153_S1     11
39 #define WZRHPG300NH_GPIO_74HC153_1Y     12
40 #define WZRHPG300NH_GPIO_74HC153_2Y     14
41
42 #define WZRHPG300NH_GPIO_EXP_BASE       32
43 #define WZRHPG300NH_GPIO_BTN_AOSS       (WZRHPG300NH_GPIO_EXP_BASE + 0)
44 #define WZRHPG300NH_GPIO_BTN_RESET      (WZRHPG300NH_GPIO_EXP_BASE + 1)
45 #define WZRHPG300NH_GPIO_BTN_ROUTER_ON  (WZRHPG300NH_GPIO_EXP_BASE + 2)
46 #define WZRHPG300NH_GPIO_BTN_QOS_ON     (WZRHPG300NH_GPIO_EXP_BASE + 3)
47 #define WZRHPG300NH_GPIO_BTN_USB        (WZRHPG300NH_GPIO_EXP_BASE + 5)
48 #define WZRHPG300NH_GPIO_BTN_ROUTER_AUTO (WZRHPG300NH_GPIO_EXP_BASE + 6)
49 #define WZRHPG300NH_GPIO_BTN_QOS_OFF    (WZRHPG300NH_GPIO_EXP_BASE + 7)
50
51 #define WZRHPG300NH_BUTTONS_POLL_INTERVAL       20
52
53 #define WZRHPG300NH_MAC_OFFSET          0x20c
54
55 #ifdef CONFIG_MTD_PARTITIONS
56 static struct mtd_partition wzrhpg300nh_flash_partitions[] = {
57         {
58                 .name           = "u-boot",
59                 .offset         = 0,
60                 .size           = 0x0040000,
61                 .mask_flags     = MTD_WRITEABLE,
62         }, {
63                 .name           = "u-boot-env",
64                 .offset         = 0x0040000,
65                 .size           = 0x0020000,
66                 .mask_flags     = MTD_WRITEABLE,
67         }, {
68                 .name           = "kernel",
69                 .offset         = 0x0060000,
70                 .size           = 0x0100000,
71         }, {
72                 .name           = "rootfs",
73                 .offset         = 0x0160000,
74                 .size           = 0x1e60000,
75         }, {
76                 .name           = "user_property",
77                 .offset         = 0x1fc0000,
78                 .size           = 0x0020000,
79                 .mask_flags     = MTD_WRITEABLE,
80         }, {
81                 .name           = "art",
82                 .offset         = 0x1fe0000,
83                 .size           = 0x0020000,
84                 .mask_flags     = MTD_WRITEABLE,
85         }, {
86                 .name           = "firmware",
87                 .offset         = 0x0060000,
88                 .size           = 0x1f60000,
89         }
90 };
91 #endif /* CONFIG_MTD_PARTITIONS */
92
93 static struct ar91xx_flash_platform_data wzrhpg300nh_flash_data = {
94         .width          = 2,
95 #ifdef CONFIG_MTD_PARTITIONS
96         .parts          = wzrhpg300nh_flash_partitions,
97         .nr_parts       = ARRAY_SIZE(wzrhpg300nh_flash_partitions),
98 #endif
99 };
100
101 #define WZRHPG300NH_FLASH_BASE  0x1e000000
102 #define WZRHPG300NH_FLASH_SIZE  (32 * 1024 * 1024)
103
104 static struct resource wzrhpg300nh_flash_resources[] = {
105         [0] = {
106                 .start  = WZRHPG300NH_FLASH_BASE,
107                 .end    = WZRHPG300NH_FLASH_BASE + WZRHPG300NH_FLASH_SIZE - 1,
108                 .flags  = IORESOURCE_MEM,
109         },
110 };
111
112 static struct platform_device wzrhpg300nh_flash_device = {
113         .name           = "ar91xx-flash",
114         .id             = -1,
115         .resource       = wzrhpg300nh_flash_resources,
116         .num_resources  = ARRAY_SIZE(wzrhpg300nh_flash_resources),
117         .dev            = {
118                 .platform_data = &wzrhpg300nh_flash_data,
119         }
120 };
121
122 static struct gpio_led wzrhpg300nh_leds_gpio[] __initdata = {
123         {
124                 .name           = "wzr-hp-g300nh:orange:security",
125                 .gpio           = WZRHPG300NH_GPIO_LED_SECURITY,
126                 .active_low     = 1,
127         }, {
128                 .name           = "wzr-hp-g300nh:green:wireless",
129                 .gpio           = WZRHPG300NH_GPIO_LED_WIRELESS,
130                 .active_low     = 1,
131         }, {
132                 .name           = "wzr-hp-g300nh:green:router",
133                 .gpio           = WZRHPG300NH_GPIO_LED_ROUTER,
134                 .active_low     = 1,
135         }, {
136                 .name           = "wzr-hp-g300nh:red:diag",
137                 .gpio           = WZRHPG300NH_GPIO_LED_DIAG,
138                 .active_low     = 1,
139         }, {
140                 .name           = "wzr-hp-g300nh:blue:usb",
141                 .gpio           = WZRHPG300NH_GPIO_LED_USB,
142                 .active_low     = 1,
143         }
144 };
145
146 static struct gpio_button wzrhpg300nh_gpio_buttons[] __initdata = {
147         {
148                 .desc           = "reset",
149                 .type           = EV_KEY,
150                 .code           = BTN_0,
151                 .threshold      = 3,
152                 .gpio           = WZRHPG300NH_GPIO_BTN_RESET,
153                 .active_low     = 1,
154         }, {
155                 .desc           = "aoss",
156                 .type           = EV_KEY,
157                 .code           = BTN_1,
158                 .threshold      = 3,
159                 .gpio           = WZRHPG300NH_GPIO_BTN_AOSS,
160                 .active_low     = 1,
161         }, {
162                 .desc           = "usb",
163                 .type           = EV_KEY,
164                 .code           = BTN_2,
165                 .threshold      = 3,
166                 .gpio           = WZRHPG300NH_GPIO_BTN_USB,
167                 .active_low     = 1,
168         }, {
169                 .desc           = "qos_on",
170                 .type           = EV_KEY,
171                 .code           = BTN_3,
172                 .threshold      = 3,
173                 .gpio           = WZRHPG300NH_GPIO_BTN_QOS_ON,
174                 .active_low     = 0,
175         }, {
176                 .desc           = "qos_off",
177                 .type           = EV_KEY,
178                 .code           = BTN_4,
179                 .threshold      = 3,
180                 .gpio           = WZRHPG300NH_GPIO_BTN_QOS_OFF,
181                 .active_low     = 0,
182         }, {
183                 .desc           = "router_on",
184                 .type           = EV_KEY,
185                 .code           = BTN_5,
186                 .threshold      = 3,
187                 .gpio           = WZRHPG300NH_GPIO_BTN_ROUTER_ON,
188                 .active_low     = 0,
189         }, {
190                 .desc           = "router_auto",
191                 .type           = EV_KEY,
192                 .code           = BTN_6,
193                 .threshold      = 3,
194                 .gpio           = WZRHPG300NH_GPIO_BTN_ROUTER_AUTO,
195                 .active_low     = 0,
196         }
197 };
198
199 static struct nxp_74hc153_platform_data wzrhpg300nh_74hc153_data = {
200         .gpio_base      = WZRHPG300NH_GPIO_EXP_BASE,
201         .gpio_pin_s0    = WZRHPG300NH_GPIO_74HC153_S0,
202         .gpio_pin_s1    = WZRHPG300NH_GPIO_74HC153_S1,
203         .gpio_pin_1y    = WZRHPG300NH_GPIO_74HC153_1Y,
204         .gpio_pin_2y    = WZRHPG300NH_GPIO_74HC153_2Y,
205 };
206
207 static struct platform_device wzrhpg300nh_74hc153_device = {
208         .name           = NXP_74HC153_DRIVER_NAME,
209         .id             = -1,
210         .dev = {
211                 .platform_data  = &wzrhpg300nh_74hc153_data,
212         }
213 };
214
215 static struct rtl8366s_platform_data wzrhpg300nh_rtl8366s_data = {
216         .gpio_sda        = WZRHPG300NH_GPIO_RTL8366_SDA,
217         .gpio_sck        = WZRHPG300NH_GPIO_RTL8366_SCK,
218 };
219
220 static struct platform_device wzrhpg300nh_rtl8366s_device = {
221         .name           = RTL8366S_DRIVER_NAME,
222         .id             = -1,
223         .dev = {
224                 .platform_data  = &wzrhpg300nh_rtl8366s_data,
225         }
226 };
227
228 static void __init wzrhpg300nh_setup(void)
229 {
230         u8 *eeprom = (u8 *) KSEG1ADDR(0x1fff1000);
231
232         ar71xx_set_mac_base(eeprom + WZRHPG300NH_MAC_OFFSET);
233
234         ar71xx_eth0_pll_data.pll_1000 = 0x1e000100;
235         ar71xx_eth0_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
236         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
237         ar71xx_eth0_data.phy_mask = 0xf;
238         ar71xx_eth0_data.speed = SPEED_1000;
239         ar71xx_eth0_data.duplex = DUPLEX_FULL;
240
241         ar71xx_eth1_pll_data.pll_1000 = 0x1e000100;
242         ar71xx_eth1_data.mii_bus_dev = &wzrhpg300nh_rtl8366s_device.dev;
243         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
244         ar71xx_eth1_data.phy_mask = 0x10;
245
246         ar71xx_add_device_eth(0);
247         ar71xx_add_device_eth(1);
248
249         ar71xx_add_device_usb();
250         ar913x_add_device_wmac(eeprom, NULL);
251
252         platform_device_register(&wzrhpg300nh_74hc153_device);
253         platform_device_register(&wzrhpg300nh_flash_device);
254         platform_device_register(&wzrhpg300nh_rtl8366s_device);
255
256         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(wzrhpg300nh_leds_gpio),
257                                     wzrhpg300nh_leds_gpio);
258
259         ar71xx_add_device_gpio_buttons(-1, WZRHPG300NH_BUTTONS_POLL_INTERVAL,
260                                        ARRAY_SIZE(wzrhpg300nh_gpio_buttons),
261                                        wzrhpg300nh_gpio_buttons);
262
263 }
264
265 MIPS_MACHINE(AR71XX_MACH_WZR_HP_G300NH, "WZR-HP-G300NH",
266              "Buffalo WZR-HP-G300NH", wzrhpg300nh_setup);