cbd201994d92305b03ab05f581d648b821b7b9c1
[openwrt/openwrt.git] / target / linux / ar71xx / files-3.2 / arch / mips / ath79 / 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
17 #include <asm/mach-ath79/ath79.h>
18 #include <asm/mach-ath79/pci.h>
19
20 #include "dev-eth.h"
21 #include "dev-gpio-buttons.h"
22 #include "dev-leds-gpio.h"
23 #include "dev-m25p80.h"
24 #include "machtypes.h"
25 #include "pci.h"
26
27 #define EAP7660D_KEYS_POLL_INTERVAL 20 /* msecs */
28 #define EAP7660D_KEYS_DEBOUNCE_INTERVAL (3 * EAP7660D_KEYS_POLL_INTERVAL)
29
30 #define EAP7660D_GPIO_DS4 7
31 #define EAP7660D_GPIO_DS5 2
32 #define EAP7660D_GPIO_DS7 0
33 #define EAP7660D_GPIO_DS8 4
34 #define EAP7660D_GPIO_SW1 3
35 #define EAP7660D_GPIO_SW3 8
36 #define EAP7660D_PHYMASK BIT(20)
37 #define EAP7660D_BOARDCONFIG 0x1F7F0000
38 #define EAP7660D_GBIC_MAC_OFFSET 0x1000
39 #define EAP7660D_WMAC0_MAC_OFFSET 0x1010
40 #define EAP7660D_WMAC1_MAC_OFFSET 0x1016
41 #define EAP7660D_WMAC0_CALDATA_OFFSET 0x2000
42 #define EAP7660D_WMAC1_CALDATA_OFFSET 0x3000
43
44 #ifdef CONFIG_PCI
45 static struct ath5k_platform_data eap7660d_wmac0_data;
46 static struct ath5k_platform_data eap7660d_wmac1_data;
47 static char eap7660d_wmac0_mac[6];
48 static char eap7660d_wmac1_mac[6];
49 static u16 eap7660d_wmac0_eeprom[ATH5K_PLAT_EEP_MAX_WORDS];
50 static u16 eap7660d_wmac1_eeprom[ATH5K_PLAT_EEP_MAX_WORDS];
51
52 static int eap7660d_pci_plat_dev_init(struct pci_dev *dev)
53 {
54 switch (PCI_SLOT(dev->devfn)) {
55 case 17:
56 dev->dev.platform_data = &eap7660d_wmac0_data;
57 break;
58
59 case 18:
60 dev->dev.platform_data = &eap7660d_wmac1_data;
61 break;
62 }
63
64 return 0;
65 }
66
67 void __init eap7660d_pci_init(u8 *cal_data0, u8 *mac_addr0,
68 u8 *cal_data1, u8 *mac_addr1)
69 {
70 if (cal_data0 && *cal_data0 == 0xa55a) {
71 memcpy(eap7660d_wmac0_eeprom, cal_data0,
72 ATH5K_PLAT_EEP_MAX_WORDS);
73 eap7660d_wmac0_data.eeprom_data = eap7660d_wmac0_eeprom;
74 }
75
76 if (cal_data1 && *cal_data1 == 0xa55a) {
77 memcpy(eap7660d_wmac1_eeprom, cal_data1,
78 ATH5K_PLAT_EEP_MAX_WORDS);
79 eap7660d_wmac1_data.eeprom_data = eap7660d_wmac1_eeprom;
80 }
81
82 if (mac_addr0) {
83 memcpy(eap7660d_wmac0_mac, mac_addr0,
84 sizeof(eap7660d_wmac0_mac));
85 eap7660d_wmac0_data.macaddr = eap7660d_wmac0_mac;
86 }
87
88 if (mac_addr1) {
89 memcpy(eap7660d_wmac1_mac, mac_addr1,
90 sizeof(eap7660d_wmac1_mac));
91 eap7660d_wmac1_data.macaddr = eap7660d_wmac1_mac;
92 }
93
94 ath79_pci_set_plat_dev_init(eap7660d_pci_plat_dev_init);
95 ath79_register_pci();
96 }
97 #else
98 static inline void eap7660d_pci_init(u8 *cal_data0, u8 *mac_addr0,
99 u8 *cal_data1, u8 *mac_addr1)
100 {
101 }
102 #endif /* CONFIG_PCI */
103
104 static struct gpio_led eap7660d_leds_gpio[] __initdata = {
105 {
106 .name = "eap7660d:green:ds8",
107 .gpio = EAP7660D_GPIO_DS8,
108 .active_low = 0,
109 },
110 {
111 .name = "eap7660d:green:ds5",
112 .gpio = EAP7660D_GPIO_DS5,
113 .active_low = 0,
114 },
115 {
116 .name = "eap7660d:green:ds7",
117 .gpio = EAP7660D_GPIO_DS7,
118 .active_low = 0,
119 },
120 {
121 .name = "eap7660d:green:ds4",
122 .gpio = EAP7660D_GPIO_DS4,
123 .active_low = 0,
124 }
125 };
126
127 static struct gpio_keys_button eap7660d_gpio_keys[] __initdata = {
128 {
129 .desc = "reset",
130 .type = EV_KEY,
131 .code = KEY_RESTART,
132 .debounce_interval = EAP7660D_KEYS_DEBOUNCE_INTERVAL,
133 .gpio = EAP7660D_GPIO_SW1,
134 .active_low = 1,
135 },
136 {
137 .desc = "wps",
138 .type = EV_KEY,
139 .code = KEY_WPS_BUTTON,
140 .debounce_interval = EAP7660D_KEYS_DEBOUNCE_INTERVAL,
141 .gpio = EAP7660D_GPIO_SW3,
142 .active_low = 1,
143 }
144 };
145
146 static const char *eap7660d_part_probes[] = {
147 "RedBoot",
148 NULL,
149 };
150
151 static struct flash_platform_data eap7660d_flash_data = {
152 .part_probes = eap7660d_part_probes,
153 };
154
155 static void __init eap7660d_setup(void)
156 {
157 u8 *boardconfig = (u8 *) KSEG1ADDR(EAP7660D_BOARDCONFIG);
158
159 ath79_register_mdio(0, ~EAP7660D_PHYMASK);
160
161 ath79_init_mac(ath79_eth0_data.mac_addr,
162 boardconfig + EAP7660D_GBIC_MAC_OFFSET, 0);
163 ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
164 ath79_eth0_data.phy_mask = EAP7660D_PHYMASK;
165 ath79_register_eth(0);
166 ath79_register_m25p80(&eap7660d_flash_data);
167 ath79_register_leds_gpio(-1, ARRAY_SIZE(eap7660d_leds_gpio),
168 eap7660d_leds_gpio);
169 ath79_register_gpio_keys_polled(-1, EAP7660D_KEYS_POLL_INTERVAL,
170 ARRAY_SIZE(eap7660d_gpio_keys),
171 eap7660d_gpio_keys);
172 eap7660d_pci_init(boardconfig + EAP7660D_WMAC0_CALDATA_OFFSET,
173 boardconfig + EAP7660D_WMAC0_MAC_OFFSET,
174 boardconfig + EAP7660D_WMAC1_CALDATA_OFFSET,
175 boardconfig + EAP7660D_WMAC1_MAC_OFFSET);
176 };
177
178 MIPS_MACHINE(ATH79_MACH_EAP7660D, "EAP7660D", "Senao EAP7660D",
179 eap7660d_setup);