230bf78ed5a30efafe597ecdba850bf0dfedbc82
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-eap7660d.c
1 /*
2 * Senao EAP7660D board support
3 *
4 * Copyright (C) 2010 Daniel Golle <daniel.golle@gmail.com>
5 * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
6 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
11 */
12
13 #include <linux/pci.h>
14 #include <linux/ath5k_platform.h>
15 #include <linux/delay.h>
16 #include <asm/mach-ar71xx/ar71xx.h>
17 #include <asm/mach-ar71xx/pci.h>
18
19 #include "machtype.h"
20 #include "devices.h"
21 #include "dev-gpio-buttons.h"
22 #include "dev-leds-gpio.h"
23 #include "dev-m25p80.h"
24
25 #define EAP7660D_KEYS_POLL_INTERVAL 20 /* msecs */
26 #define EAP7660D_KEYS_DEBOUNCE_INTERVAL (3 * EAP7660D_KEYS_POLL_INTERVAL)
27
28 #define EAP7660D_GPIO_DS4 7
29 #define EAP7660D_GPIO_DS5 2
30 #define EAP7660D_GPIO_DS7 0
31 #define EAP7660D_GPIO_DS8 4
32 #define EAP7660D_GPIO_SW1 3
33 #define EAP7660D_GPIO_SW3 8
34 #define EAP7660D_PHYMASK BIT(20)
35 #define EAP7660D_BOARDCONFIG 0x1F7F0000
36 #define EAP7660D_GBIC_MAC_OFFSET 0x1000
37 #define EAP7660D_WMAC0_MAC_OFFSET 0x1010
38 #define EAP7660D_WMAC1_MAC_OFFSET 0x1016
39 #define EAP7660D_WMAC0_CALDATA_OFFSET 0x2000
40 #define EAP7660D_WMAC1_CALDATA_OFFSET 0x3000
41
42 static struct ath5k_platform_data eap7660d_wmac0_data;
43 static struct ath5k_platform_data eap7660d_wmac1_data;
44 static char eap7660d_wmac0_mac[6];
45 static char eap7660d_wmac1_mac[6];
46 static u16 eap7660d_wmac0_eeprom[ATH5K_PLAT_EEP_MAX_WORDS];
47 static u16 eap7660d_wmac1_eeprom[ATH5K_PLAT_EEP_MAX_WORDS];
48
49 #ifdef CONFIG_PCI
50 static struct ar71xx_pci_irq eap7660d_pci_irqs[] __initdata = {
51 {
52 .slot = 0,
53 .pin = 1,
54 .irq = AR71XX_PCI_IRQ_DEV0,
55 }, {
56 .slot = 1,
57 .pin = 1,
58 .irq = AR71XX_PCI_IRQ_DEV1,
59 }
60 };
61
62 static int eap7660d_pci_plat_dev_init(struct pci_dev *dev)
63 {
64 switch (PCI_SLOT(dev->devfn)) {
65 case 17:
66 dev->dev.platform_data = &eap7660d_wmac0_data;
67 break;
68
69 case 18:
70 dev->dev.platform_data = &eap7660d_wmac1_data;
71 break;
72 }
73
74 return 0;
75 }
76
77 void __init eap7660d_pci_init(u8 *cal_data0, u8 *mac_addr0,
78 u8 *cal_data1, u8 *mac_addr1)
79 {
80 if (cal_data0 && *cal_data0 == 0xa55a) {
81 memcpy(eap7660d_wmac0_eeprom, cal_data0,
82 ATH5K_PLAT_EEP_MAX_WORDS);
83 eap7660d_wmac0_data.eeprom_data = eap7660d_wmac0_eeprom;
84 }
85
86 if (cal_data1 && *cal_data1 == 0xa55a) {
87 memcpy(eap7660d_wmac1_eeprom, cal_data1,
88 ATH5K_PLAT_EEP_MAX_WORDS);
89 eap7660d_wmac1_data.eeprom_data = eap7660d_wmac1_eeprom;
90 }
91
92 if (mac_addr0) {
93 memcpy(eap7660d_wmac0_mac, mac_addr0,
94 sizeof(eap7660d_wmac0_mac));
95 eap7660d_wmac0_data.macaddr = eap7660d_wmac0_mac;
96 }
97
98 if (mac_addr1) {
99 memcpy(eap7660d_wmac1_mac, mac_addr1,
100 sizeof(eap7660d_wmac1_mac));
101 eap7660d_wmac1_data.macaddr = eap7660d_wmac1_mac;
102 }
103
104 ar71xx_pci_plat_dev_init = eap7660d_pci_plat_dev_init;
105 ar71xx_pci_init(ARRAY_SIZE(eap7660d_pci_irqs), eap7660d_pci_irqs);
106 }
107 #else
108 static inline void eap7660d_pci_init(u8 *cal_data0, u8 *mac_addr0,
109 u8 *cal_data1, u8 *mac_addr1)
110 {
111 }
112 #endif /* CONFIG_PCI */
113
114 static struct gpio_led eap7660d_leds_gpio[] __initdata = {
115 {
116 .name = "eap7660d:green:ds8",
117 .gpio = EAP7660D_GPIO_DS8,
118 .active_low = 0,
119 },
120 {
121 .name = "eap7660d:green:ds5",
122 .gpio = EAP7660D_GPIO_DS5,
123 .active_low = 0,
124 },
125 {
126 .name = "eap7660d:green:ds7",
127 .gpio = EAP7660D_GPIO_DS7,
128 .active_low = 0,
129 },
130 {
131 .name = "eap7660d:green:ds4",
132 .gpio = EAP7660D_GPIO_DS4,
133 .active_low = 0,
134 }
135 };
136
137 static struct gpio_keys_button eap7660d_gpio_keys[] __initdata = {
138 {
139 .desc = "reset",
140 .type = EV_KEY,
141 .code = KEY_RESTART,
142 .debounce_interval = EAP7660D_KEYS_DEBOUNCE_INTERVAL,
143 .gpio = EAP7660D_GPIO_SW1,
144 .active_low = 1,
145 },
146 {
147 .desc = "wps",
148 .type = EV_KEY,
149 .code = KEY_WPS_BUTTON,
150 .debounce_interval = EAP7660D_KEYS_DEBOUNCE_INTERVAL,
151 .gpio = EAP7660D_GPIO_SW3,
152 .active_low = 1,
153 }
154 };
155
156 static void __init eap7660d_setup(void)
157 {
158 u8 *boardconfig = (u8 *) KSEG1ADDR(EAP7660D_BOARDCONFIG);
159
160 ar71xx_add_device_mdio(0, ~EAP7660D_PHYMASK);
161
162 ar71xx_init_mac(ar71xx_eth0_data.mac_addr,
163 boardconfig + EAP7660D_GBIC_MAC_OFFSET, 0);
164 ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
165 ar71xx_eth0_data.phy_mask = EAP7660D_PHYMASK;
166 ar71xx_add_device_eth(0);
167 ar71xx_add_device_m25p80(NULL);
168 ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(eap7660d_leds_gpio),
169 eap7660d_leds_gpio);
170 ar71xx_register_gpio_keys_polled(-1, EAP7660D_KEYS_POLL_INTERVAL,
171 ARRAY_SIZE(eap7660d_gpio_keys),
172 eap7660d_gpio_keys);
173 eap7660d_pci_init(boardconfig + EAP7660D_WMAC0_CALDATA_OFFSET,
174 boardconfig + EAP7660D_WMAC0_MAC_OFFSET,
175 boardconfig + EAP7660D_WMAC1_CALDATA_OFFSET,
176 boardconfig + EAP7660D_WMAC1_MAC_OFFSET);
177 };
178
179 MIPS_MACHINE(AR71XX_MACH_EAP7660D, "EAP7660D", "Senao EAP7660D",
180 eap7660d_setup);