ar71xx: switch to 3.2.5
[openwrt.git] / target / linux / ar71xx / files-2.6.39 / arch / mips / ar71xx / mach-alfa-ap96.c
1 /*
2  *  ALFA Network AP96 board support
3  *
4  *  Copyright (C) 2012 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/gpio.h>
14 #include <linux/platform_device.h>
15 #include <linux/mmc/host.h>
16 #include <linux/spi/spi.h>
17 #include <linux/spi/mmc_spi.h>
18
19 #include <asm/mach-ar71xx/ar71xx.h>
20
21 #include "machtype.h"
22 #include "devices.h"
23 #include "dev-pb42-pci.h"
24 #include "dev-gpio-buttons.h"
25 #include "dev-usb.h"
26
27 #define ALFA_AP96_GPIO_MICROSD_CS       0
28 #define ALFA_AP96_GPIO_RTC_CS           1
29 #define ALFA_AP96_GPIO_PCIE_RESET       2
30 #define ALFA_AP96_GPIO_SIM_DETECT       3
31 #define ALFA_AP96_GPIO_MICROSD_CD       4
32 #define ALFA_AP96_GPIO_PCIE_W_DISABLE   5
33
34 #define ALFA_AP96_GPIO_BUTTON_RESET     11
35
36 #define ALFA_AP96_KEYS_POLL_INTERVAL            20      /* msecs */
37 #define ALFA_AP96_KEYS_DEBOUNCE_INTERVAL        (3 * ALFA_AP96_KEYS_POLL_INTERVAL)
38
39 static struct gpio_keys_button alfa_ap96_gpio_keys[] __initdata = {
40         {
41                 .desc           = "Reset button",
42                 .type           = EV_KEY,
43                 .code           = KEY_RESTART,
44                 .debounce_interval = ALFA_AP96_KEYS_DEBOUNCE_INTERVAL,
45                 .gpio           = ALFA_AP96_GPIO_BUTTON_RESET,
46                 .active_low     = 1,
47         }
48 };
49
50 static int alfa_ap96_mmc_get_cd(struct device *dev)
51 {
52         return !gpio_get_value(ALFA_AP96_GPIO_MICROSD_CD);
53 }
54
55 static struct mmc_spi_platform_data alfa_ap96_mmc_data = {
56         .get_cd         = alfa_ap96_mmc_get_cd,
57         .caps           = MMC_CAP_NEEDS_POLL,
58         .ocr_mask       = MMC_VDD_32_33 | MMC_VDD_33_34,
59 };
60
61 static struct spi_board_info alfa_ap96_spi_info[] = {
62         {
63                 .bus_num        = 0,
64                 .chip_select    = 0,
65                 .max_speed_hz   = 25000000,
66                 .modalias       = "m25p80",
67         }, {
68                 .bus_num        = 0,
69                 .chip_select    = 1,
70                 .max_speed_hz   = 25000000,
71                 .modalias       = "mmc_spi",
72                 .platform_data  = &alfa_ap96_mmc_data,
73                 .controller_data = (void *) ALFA_AP96_GPIO_MICROSD_CS,
74         }, {
75                 .bus_num        = 0,
76                 .chip_select    = 2,
77                 .max_speed_hz   = 6250000,
78                 .modalias       = "rtc-pcf2123",
79                 .controller_data = (void *) ALFA_AP96_GPIO_RTC_CS,
80         },
81 };
82
83 static struct resource alfa_ap96_spi_resources[] = {
84         [0] = {
85                 .start  = AR71XX_SPI_BASE,
86                 .end    = AR71XX_SPI_BASE + AR71XX_SPI_SIZE - 1,
87                 .flags  = IORESOURCE_MEM,
88         },
89 };
90
91 static struct ar71xx_spi_platform_data alfa_ap96_spi_data = {
92         .bus_num                = 0,
93         .num_chipselect         = 3,
94 };
95
96 static struct platform_device alfa_ap96_spi_device = {
97         .name           = "pb44-spi",
98         .id             = -1,
99         .resource       = alfa_ap96_spi_resources,
100         .num_resources  = ARRAY_SIZE(alfa_ap96_spi_resources),
101         .dev = {
102                 .platform_data = &alfa_ap96_spi_data,
103         },
104 };
105
106 static void __init alfa_ap96_gpio_setup(void)
107 {
108         ar71xx_gpio_function_disable(AR71XX_GPIO_FUNC_SPI_CS1_EN |
109                                      AR71XX_GPIO_FUNC_SPI_CS2_EN);
110
111         gpio_request(ALFA_AP96_GPIO_MICROSD_CD, "microSD CD");
112         gpio_direction_input(ALFA_AP96_GPIO_MICROSD_CD);
113         gpio_request(ALFA_AP96_GPIO_PCIE_RESET, "PCIe reset");
114         gpio_direction_output(ALFA_AP96_GPIO_PCIE_RESET, 1);
115         gpio_request(ALFA_AP96_GPIO_PCIE_W_DISABLE, "PCIe write disable");
116         gpio_direction_output(ALFA_AP96_GPIO_PCIE_W_DISABLE, 1);
117 }
118
119 #define ALFA_AP96_WAN_PHYMASK   BIT(4)
120 #define ALFA_AP96_LAN_PHYMASK   BIT(5)
121 #define ALFA_AP96_MDIO_PHYMASK  (ALFA_AP96_LAN_PHYMASK | ALFA_AP96_WAN_PHYMASK)
122
123 static void __init alfa_ap96_init(void)
124 {
125         alfa_ap96_gpio_setup();
126
127         ar71xx_add_device_mdio(0, ~ALFA_AP96_MDIO_PHYMASK);
128
129         ar71xx_init_mac(ar71xx_eth0_data.mac_addr, ar71xx_mac_base, 0);
130         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
131         ar71xx_eth0_data.phy_mask = ALFA_AP96_WAN_PHYMASK;
132         ar71xx_eth1_pll_data.pll_1000 = 0x110000;
133
134         ar71xx_add_device_eth(0);
135
136         ar71xx_init_mac(ar71xx_eth1_data.mac_addr, ar71xx_mac_base, 1);
137         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
138         ar71xx_eth1_data.phy_mask = ALFA_AP96_LAN_PHYMASK;
139         ar71xx_eth1_pll_data.pll_1000 = 0x110000;
140
141         ar71xx_add_device_eth(1);
142
143         pb42_pci_init();
144
145         spi_register_board_info(alfa_ap96_spi_info,
146                                 ARRAY_SIZE(alfa_ap96_spi_info));
147         platform_device_register(&alfa_ap96_spi_device);
148
149         ar71xx_register_gpio_keys_polled(-1, ALFA_AP96_KEYS_POLL_INTERVAL,
150                                          ARRAY_SIZE(alfa_ap96_gpio_keys),
151                                          alfa_ap96_gpio_keys);
152         ar71xx_add_device_usb();
153 }
154
155 MIPS_MACHINE(AR71XX_MACH_ALFA_AP96, "ALFA-AP96", "ALFA Network AP96",
156              alfa_ap96_init);