ar71xx: in-flash macs and eeprom for mach-eap7660d
[openwrt.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_BUTTONS_POLL_INTERVAL  20
26 #define EAP7660D_GPIO_DS4               7
27 #define EAP7660D_GPIO_DS5               2
28 #define EAP7660D_GPIO_DS7               0
29 #define EAP7660D_GPIO_DS8               4
30 #define EAP7660D_GPIO_SW1               3
31 #define EAP7660D_GPIO_SW3               8
32 #define EAP7660D_PHYMASK                BIT(20)
33 #define EAP7660D_BOARDCONFIG            0x1F7F0000
34 #define EAP7660D_GBIC_MAC_OFFSET        0x1000
35 #define EAP7660D_WMAC0_MAC_OFFSET       0x1010
36 #define EAP7660D_WMAC1_MAC_OFFSET       0x1016
37 #define EAP7660D_WMAC0_CALDATA_OFFSET   0x2000
38 #define EAP7660D_WMAC1_CALDATA_OFFSET   0x3000
39
40 static struct ath5k_platform_data eap7660d_wmac0_data;
41 static struct ath5k_platform_data eap7660d_wmac1_data;
42 static char eap7660d_wmac0_mac[6];
43 static char eap7660d_wmac1_mac[6];
44 static u16 eap7660d_wmac0_eeprom[ATH5K_PLAT_EEP_MAX_WORDS];
45 static u16 eap7660d_wmac1_eeprom[ATH5K_PLAT_EEP_MAX_WORDS];
46
47 static struct ar71xx_pci_irq eap7660d_pci_irqs[] __initdata = {
48         {
49                 .slot   = 0,
50                 .pin    = 1,
51                 .irq    = AR71XX_PCI_IRQ_DEV0,
52         }, {
53                 .slot   = 1,
54                 .pin    = 1,
55                 .irq    = AR71XX_PCI_IRQ_DEV1,
56         }
57 };
58
59 static int eap7660d_pci_plat_dev_init(struct pci_dev *dev)
60 {
61         switch(PCI_SLOT(dev->devfn)) {
62         case 17:
63                 dev->dev.platform_data = &eap7660d_wmac0_data;
64                 break;
65
66         case 18:
67                 dev->dev.platform_data = &eap7660d_wmac1_data;
68                 break;
69         }
70
71         return 0;
72 }
73
74 void __init eap7660d_pci_init(u8 *cal_data0, u8 *mac_addr0,
75                           u8 *cal_data1, u8 *mac_addr1)
76 {
77         if (cal_data0 && *cal_data0 == 0xa55a) {
78                 memcpy(eap7660d_wmac0_eeprom, cal_data0,
79                         ATH5K_PLAT_EEP_MAX_WORDS);
80                 eap7660d_wmac0_data.eeprom_data = eap7660d_wmac0_eeprom;
81         }
82
83         if (cal_data1 && *cal_data1 == 0xa55a) {
84                 memcpy(eap7660d_wmac1_eeprom, cal_data1,
85                         ATH5K_PLAT_EEP_MAX_WORDS);
86                 eap7660d_wmac1_data.eeprom_data = eap7660d_wmac1_eeprom;
87         }
88
89         if (mac_addr0) {
90                 memcpy(eap7660d_wmac0_mac, mac_addr0, sizeof(eap7660d_wmac0_mac));
91                 eap7660d_wmac0_data.macaddr = eap7660d_wmac0_mac;
92         }
93
94         if (mac_addr1) {
95                 memcpy(eap7660d_wmac1_mac, mac_addr1, sizeof(eap7660d_wmac1_mac));
96                 eap7660d_wmac1_data.macaddr = eap7660d_wmac1_mac;
97         }
98
99         ar71xx_pci_plat_dev_init = eap7660d_pci_plat_dev_init;
100         ar71xx_pci_init(ARRAY_SIZE(eap7660d_pci_irqs), eap7660d_pci_irqs);
101 }
102
103 static struct gpio_led eap7660d_leds_gpio[] __initdata = {
104         {
105                 .name           = "eap7660d:green:ds8",
106                 .gpio           = EAP7660D_GPIO_DS8,
107                 .active_low     = 0,
108         },
109         {
110                 .name           = "eap7660d:green:ds5",
111                 .gpio           = EAP7660D_GPIO_DS5,
112                 .active_low     = 0,
113         },
114         {
115                 .name           = "eap7660d:green:ds7",
116                 .gpio           = EAP7660D_GPIO_DS7,
117                 .active_low     = 0,
118         },
119         {
120                 .name           = "eap7660d:green:ds4",
121                 .gpio           = EAP7660D_GPIO_DS4,
122                 .active_low     = 0,
123         }
124 };
125
126 static struct gpio_button eap7660d_gpio_buttons[] __initdata = {
127         {
128                 .desc           = "reset",
129                 .type           = EV_KEY,
130                 .code           = KEY_RESTART,
131                 .threshold      = 3,
132                 .gpio           = EAP7660D_GPIO_SW1,
133                 .active_low     = 1,
134         },
135         {
136                 .desc           = "wps",
137                 .type           = EV_KEY,
138                 .code           = KEY_WPS_BUTTON,
139                 .threshold      = 3,
140                 .gpio           = EAP7660D_GPIO_SW3,
141                 .active_low     = 1,
142         }
143 };
144
145 static void __init eap7660d_setup(void)
146 {
147         u8 *boardconfig = (u8 *) KSEG1ADDR(EAP7660D_BOARDCONFIG);
148         ar71xx_set_mac_base(boardconfig + EAP7660D_GBIC_MAC_OFFSET);
149         ar71xx_add_device_mdio(~EAP7660D_PHYMASK);
150         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
151         ar71xx_eth0_data.phy_mask = EAP7660D_PHYMASK;
152         ar71xx_add_device_eth(0);
153         ar71xx_add_device_m25p80(NULL);
154         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(eap7660d_leds_gpio),
155                                         eap7660d_leds_gpio);
156         ar71xx_add_device_gpio_buttons(-1, EAP7660D_BUTTONS_POLL_INTERVAL,
157                                         ARRAY_SIZE(eap7660d_gpio_buttons),
158                                         eap7660d_gpio_buttons);
159         eap7660d_pci_init(boardconfig + EAP7660D_WMAC0_CALDATA_OFFSET,
160                         boardconfig + EAP7660D_WMAC0_MAC_OFFSET,
161                         boardconfig + EAP7660D_WMAC1_CALDATA_OFFSET,
162                         boardconfig + EAP7660D_WMAC1_MAC_OFFSET);
163 };
164
165 MIPS_MACHINE(AR71XX_MACH_EAP7660D, "EAP7660D", "Senao EAP7660D",
166              eap7660d_setup);