ramips: use gpio-keys-polled instead of gpio-buttons
[openwrt/svn-archive/archive.git] / target / linux / ramips / files / arch / mips / ralink / rt305x / mach-wl351.c
1 /*
2 * Sitecom WL-351 v1 002 board support
3 *
4 * Copyright (C) 2011 Tobias Diedrich <ranma+openwrt@tdiedrich.de>
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/init.h>
12 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/mtd/physmap.h>
16
17 #include <linux/rtl8366.h>
18
19 #include <asm/mach-ralink/machine.h>
20 #include <asm/mach-ralink/dev-gpio-buttons.h>
21 #include <asm/mach-ralink/dev-gpio-leds.h>
22 #include <asm/mach-ralink/rt305x.h>
23 #include <asm/mach-ralink/rt305x_regs.h>
24
25 #include "devices.h"
26
27 #define WL351_GPIO_LED_POWER_AMBER 8
28 #define WL351_GPIO_LED_UNPOPULATED_AMBER 12
29 #define WL351_GPIO_LED_UNPOPULATED_BLUE 13
30
31 #define WL351_GPIO_BUTTON_RESET 10
32 #define WL351_GPIO_BUTTON_WPS 0
33
34 #define WL351_KEYS_POLL_INTERVAL 20
35 #define WL351_KEYS_DEBOUNCE_INTERVAL (3 * WL351_KEYS_POLL_INTERVAL)
36
37 static struct gpio_led wl351_leds_gpio[] __initdata = {
38 {
39 .name = "wl-351:amber:power",
40 .gpio = WL351_GPIO_LED_POWER_AMBER,
41 .active_low = 1,
42 }, {
43 .name = "wl-351:amber:unpopulated",
44 .gpio = WL351_GPIO_LED_UNPOPULATED_AMBER,
45 .active_low = 1,
46 }, {
47 .name = "wl-351:blue:unpopulated",
48 .gpio = WL351_GPIO_LED_UNPOPULATED_BLUE,
49 .active_low = 1,
50 }
51 };
52
53
54 static struct gpio_keys_button wl351_gpio_buttons[] __initdata = {
55 {
56 .desc = "reset",
57 .type = EV_KEY,
58 .code = KEY_RESTART,
59 .debounce_interval = WL351_KEYS_DEBOUNCE_INTERVAL,
60 .gpio = WL351_GPIO_BUTTON_RESET,
61 .active_low = 1,
62 }, {
63 .desc = "wps",
64 .type = EV_KEY,
65 .code = KEY_WPS_BUTTON,
66 .debounce_interval = WL351_KEYS_DEBOUNCE_INTERVAL,
67 .gpio = WL351_GPIO_BUTTON_WPS,
68 .active_low = 1,
69 }
70 };
71
72 static struct mtd_partition wl351_partitions[] = {
73 {
74 .name = "u-boot",
75 .offset = 0,
76 .size = 0x030000,
77 .mask_flags = MTD_WRITEABLE,
78 }, {
79 .name = "u-boot-env",
80 .offset = 0x030000,
81 .size = 0x010000,
82 .mask_flags = MTD_WRITEABLE,
83 }, {
84 .name = "factory",
85 .offset = 0x040000,
86 .size = 0x010000,
87 .mask_flags = MTD_WRITEABLE,
88 }, {
89 .name = "kernel",
90 .offset = 0x050000,
91 .size = 0x110000,
92 }, {
93 .name = "rootfs",
94 .offset = 0x160000,
95 .size = 0x230000,
96 }, {
97 .name = "user (jffs2)",
98 .offset = 0x3F0000,
99 .size = 0x010000,
100 }, {
101 .name = "firmware",
102 .offset = 0x050000,
103 .size = 0x3a0000,
104 }
105 };
106
107 static struct physmap_flash_data wl351_flash_data = {
108 .nr_parts = ARRAY_SIZE(wl351_partitions),
109 .parts = wl351_partitions,
110 };
111
112
113 static struct rtl8366_platform_data wl351_switch_data = {
114 .gpio_sda = RT305X_GPIO_I2C_SD,
115 .gpio_sck = RT305X_GPIO_I2C_SCLK,
116 };
117
118 static struct platform_device wl351_switch = {
119 .name = RTL8366RB_DRIVER_NAME,
120 .id = -1,
121 .dev = {
122 .platform_data = &wl351_switch_data,
123 }
124 };
125
126 static void __init wl351_init(void)
127 {
128 rt305x_gpio_init((RT305X_GPIO_MODE_GPIO <<
129 RT305X_GPIO_MODE_UART0_SHIFT) |
130 RT305X_GPIO_MODE_I2C |
131 RT305X_GPIO_MODE_SPI |
132 RT305X_GPIO_MODE_MDIO);
133 rt305x_register_flash(0, &wl351_flash_data);
134 ramips_register_gpio_leds(-1, ARRAY_SIZE(wl351_leds_gpio),
135 wl351_leds_gpio);
136 ramips_register_gpio_buttons(-1, WL351_KEYS_POLL_INTERVAL,
137 ARRAY_SIZE(wl351_gpio_buttons),
138 wl351_gpio_buttons);
139 // external rtl8366rb
140 rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_BYPASS;
141 rt305x_esw_data.reg_initval_fct2 = 0x0002500c;
142 rt305x_esw_data.reg_initval_fpa2 = 0x1f003fff;
143 rt305x_register_ethernet();
144 platform_device_register(&wl351_switch);
145 rt305x_register_wifi();
146 rt305x_register_wdt();
147 rt305x_register_usb();
148 }
149
150 MIPS_MACHINE(RAMIPS_MACH_WL351, "WL-351", "Sitecom WL-351 v1 002",
151 wl351_init);