ar71xx: use the gpio_keys_polled driver instead of gpio_buttons
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-pb44.c
1 /*
2 * Atheros PB44 board support
3 *
4 * Copyright (C) 2009 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/init.h>
12 #include <linux/bitops.h>
13 #include <linux/delay.h>
14 #include <linux/platform_device.h>
15 #include <linux/spi/spi.h>
16 #include <linux/spi/flash.h>
17 #include <linux/spi/vsc7385.h>
18 #include <linux/i2c.h>
19 #include <linux/i2c-gpio.h>
20 #include <linux/i2c/pcf857x.h>
21
22 #include <asm/mach-ar71xx/ar71xx.h>
23
24 #include "machtype.h"
25 #include "devices.h"
26 #include "dev-pb42-pci.h"
27 #include "dev-gpio-buttons.h"
28 #include "dev-leds-gpio.h"
29 #include "dev-usb.h"
30
31 #define PB44_PCF8757_VSC7395_CS 0
32 #define PB44_PCF8757_STEREO_CS 1
33 #define PB44_PCF8757_SLIC_CS0 2
34 #define PB44_PCF8757_SLIC_TEST 3
35 #define PB44_PCF8757_SLIC_INT0 4
36 #define PB44_PCF8757_SLIC_INT1 5
37 #define PB44_PCF8757_SW_RESET 6
38 #define PB44_PCF8757_SW_JUMP 8
39 #define PB44_PCF8757_LED_JUMP1 9
40 #define PB44_PCF8757_LED_JUMP2 10
41 #define PB44_PCF8757_TP24 11
42 #define PB44_PCF8757_TP25 12
43 #define PB44_PCF8757_TP26 13
44 #define PB44_PCF8757_TP27 14
45 #define PB44_PCF8757_TP28 15
46
47 #define PB44_GPIO_I2C_SCL 0
48 #define PB44_GPIO_I2C_SDA 1
49
50 #define PB44_GPIO_EXP_BASE 16
51 #define PB44_GPIO_VSC7395_CS (PB44_GPIO_EXP_BASE + PB44_PCF8757_VSC7395_CS)
52 #define PB44_GPIO_SW_RESET (PB44_GPIO_EXP_BASE + PB44_PCF8757_SW_RESET)
53 #define PB44_GPIO_SW_JUMP (PB44_GPIO_EXP_BASE + PB44_PCF8757_SW_JUMP)
54 #define PB44_GPIO_LED_JUMP1 (PB44_GPIO_EXP_BASE + PB44_PCF8757_LED_JUMP1)
55 #define PB44_GPIO_LED_JUMP2 (PB44_GPIO_EXP_BASE + PB44_PCF8757_LED_JUMP2)
56
57 #define PB44_KEYS_POLL_INTERVAL 20 /* msecs */
58 #define PB44_KEYS_DEBOUNCE_INTERVAL (3 * PB44_KEYS_POLL_INTERVAL)
59
60 static struct i2c_gpio_platform_data pb44_i2c_gpio_data = {
61 .sda_pin = PB44_GPIO_I2C_SDA,
62 .scl_pin = PB44_GPIO_I2C_SCL,
63 };
64
65 static struct platform_device pb44_i2c_gpio_device = {
66 .name = "i2c-gpio",
67 .id = 0,
68 .dev = {
69 .platform_data = &pb44_i2c_gpio_data,
70 }
71 };
72
73 static struct pcf857x_platform_data pb44_pcf857x_data = {
74 .gpio_base = PB44_GPIO_EXP_BASE,
75 };
76
77 static struct i2c_board_info pb44_i2c_board_info[] __initdata = {
78 {
79 I2C_BOARD_INFO("pcf8575", 0x20),
80 .platform_data = &pb44_pcf857x_data,
81 },
82 };
83
84 static struct gpio_led pb44_leds_gpio[] __initdata = {
85 {
86 .name = "pb44:amber:jump1",
87 .gpio = PB44_GPIO_LED_JUMP1,
88 .active_low = 1,
89 }, {
90 .name = "pb44:green:jump2",
91 .gpio = PB44_GPIO_LED_JUMP2,
92 .active_low = 1,
93 },
94 };
95
96 static struct gpio_keys_button pb44_gpio_keys[] __initdata = {
97 {
98 .desc = "soft_reset",
99 .type = EV_KEY,
100 .code = KEY_RESTART,
101 .debounce_interval = PB44_KEYS_DEBOUNCE_INTERVAL,
102 .gpio = PB44_GPIO_SW_RESET,
103 .active_low = 1,
104 }, {
105 .desc = "jumpstart",
106 .type = EV_KEY,
107 .code = KEY_WPS_BUTTON,
108 .debounce_interval = PB44_KEYS_DEBOUNCE_INTERVAL,
109 .gpio = PB44_GPIO_SW_JUMP,
110 .active_low = 1,
111 }
112 };
113
114 static void pb44_vsc7395_reset(void)
115 {
116 ar71xx_device_stop(RESET_MODULE_GE1_PHY);
117 udelay(10);
118 ar71xx_device_start(RESET_MODULE_GE1_PHY);
119 mdelay(50);
120 }
121
122 static struct vsc7385_platform_data pb44_vsc7395_data = {
123 .reset = pb44_vsc7395_reset,
124 .ucode_name = "vsc7395_ucode_pb44.bin",
125 .mac_cfg = {
126 .tx_ipg = 6,
127 .bit2 = 1,
128 .clk_sel = 0,
129 },
130 };
131
132 static struct spi_board_info pb44_spi_info[] = {
133 {
134 .bus_num = 0,
135 .chip_select = 0,
136 .max_speed_hz = 25000000,
137 .modalias = "m25p80",
138 }, {
139 .bus_num = 0,
140 .chip_select = 1,
141 .max_speed_hz = 25000000,
142 .modalias = "spi-vsc7385",
143 .platform_data = &pb44_vsc7395_data,
144 .controller_data = (void *) PB44_GPIO_VSC7395_CS,
145 },
146 };
147
148 static struct resource pb44_spi_resources[] = {
149 [0] = {
150 .start = AR71XX_SPI_BASE,
151 .end = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
152 .flags = IORESOURCE_MEM,
153 },
154 };
155
156 static struct ar71xx_spi_platform_data pb44_spi_data = {
157 .bus_num = 0,
158 .num_chipselect = 2,
159 };
160
161 static struct platform_device pb44_spi_device = {
162 .name = "pb44-spi",
163 .id = -1,
164 .resource = pb44_spi_resources,
165 .num_resources = ARRAY_SIZE(pb44_spi_resources),
166 .dev = {
167 .platform_data = &pb44_spi_data,
168 },
169 };
170
171 #define PB44_WAN_PHYMASK BIT(0)
172 #define PB44_LAN_PHYMASK 0
173 #define PB44_MDIO_PHYMASK (PB44_LAN_PHYMASK | PB44_WAN_PHYMASK)
174
175 static void __init pb44_init(void)
176 {
177 ar71xx_add_device_mdio(~PB44_MDIO_PHYMASK);
178
179 ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
180 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
181 ar71xx_eth0_data.phy_mask = PB44_WAN_PHYMASK;
182
183 ar71xx_add_device_eth(0);
184
185 ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 1);
186 ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
187 ar71xx_eth1_data.speed = SPEED_1000;
188 ar71xx_eth1_data.duplex = DUPLEX_FULL;
189 ar71xx_eth1_pll_data.pll_1000 = 0x110000;
190
191 ar71xx_add_device_eth(1);
192
193 ar71xx_add_device_usb();
194
195 pb42_pci_init();
196
197 i2c_register_board_info(0, pb44_i2c_board_info,
198 ARRAY_SIZE(pb44_i2c_board_info));
199
200 platform_device_register(&pb44_i2c_gpio_device);
201
202 spi_register_board_info(pb44_spi_info, ARRAY_SIZE(pb44_spi_info));
203 platform_device_register(&pb44_spi_device);
204
205 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(pb44_leds_gpio),
206 pb44_leds_gpio);
207
208 ar71xx_register_gpio_keys_polled(-1, PB44_KEYS_POLL_INTERVAL,
209 ARRAY_SIZE(pb44_gpio_keys),
210 pb44_gpio_keys);
211 }
212
213 MIPS_MACHINE(AR71XX_MACH_PB44, "PB44", "Atheros PB44", pb44_init);