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