Revert "ar71xx: Allow to set the RXDV, RXD, TXD, TXE delays for QCA955x"
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ath79 / dev-ap9x-pci.c
1 /*
2  *  Atheros AP9X reference board PCI initialization
3  *
4  *  Copyright (C) 2009-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/pci.h>
12 #include <linux/ath9k_platform.h>
13 #include <linux/delay.h>
14
15 #include <asm/mach-ath79/ath79.h>
16
17 #include "dev-ap9x-pci.h"
18 #include "pci-ath9k-fixup.h"
19 #include "pci.h"
20
21 static struct ath9k_platform_data ap9x_wmac0_data = {
22         .led_pin = -1,
23 };
24 static struct ath9k_platform_data ap9x_wmac1_data = {
25         .led_pin = -1,
26 };
27 static char ap9x_wmac0_mac[6];
28 static char ap9x_wmac1_mac[6];
29
30 __init void ap9x_pci_setup_wmac_led_pin(unsigned wmac, int pin)
31 {
32         switch (wmac) {
33         case 0:
34                 ap9x_wmac0_data.led_pin = pin;
35                 break;
36         case 1:
37                 ap9x_wmac1_data.led_pin = pin;
38                 break;
39         }
40 }
41
42 __init void ap9x_pci_setup_wmac_led_name(unsigned wmac, const char *led_name)
43 {
44         switch (wmac) {
45         case 0:
46                 ap9x_wmac0_data.led_name = led_name;
47                 break;
48         case 1:
49                 ap9x_wmac1_data.led_name = led_name;
50                 break;
51         }
52 }
53
54 __init struct ath9k_platform_data *ap9x_pci_get_wmac_data(unsigned wmac)
55 {
56         switch (wmac) {
57         case 0:
58                 return &ap9x_wmac0_data;
59
60         case 1:
61                 return &ap9x_wmac1_data;
62         }
63
64         return NULL;
65 }
66
67 __init void ap9x_pci_setup_wmac_gpio(unsigned wmac, u32 mask, u32 val)
68 {
69         switch (wmac) {
70         case 0:
71                 ap9x_wmac0_data.gpio_mask = mask;
72                 ap9x_wmac0_data.gpio_val = val;
73                 break;
74         case 1:
75                 ap9x_wmac1_data.gpio_mask = mask;
76                 ap9x_wmac1_data.gpio_val = val;
77                 break;
78         }
79 }
80
81 __init void ap9x_pci_setup_wmac_leds(unsigned wmac, struct gpio_led *leds,
82                                      int num_leds)
83 {
84         switch (wmac) {
85         case 0:
86                 ap9x_wmac0_data.leds = leds;
87                 ap9x_wmac0_data.num_leds = num_leds;
88                 break;
89         case 1:
90                 ap9x_wmac1_data.leds = leds;
91                 ap9x_wmac1_data.num_leds = num_leds;
92                 break;
93         }
94 }
95
96 __init void ap9x_pci_setup_wmac_btns(unsigned wmac,
97                                      struct gpio_keys_button *btns,
98                                      unsigned num_btns, unsigned poll_interval)
99 {
100         struct ath9k_platform_data *ap9x_wmac_data;
101
102         if (!(ap9x_wmac_data = ap9x_pci_get_wmac_data(wmac)))
103                 return;
104
105         ap9x_wmac_data->btns = btns;
106         ap9x_wmac_data->num_btns = num_btns;
107         ap9x_wmac_data->btn_poll_interval = poll_interval;
108 }
109
110 static int ap91_pci_plat_dev_init(struct pci_dev *dev)
111 {
112         switch (PCI_SLOT(dev->devfn)) {
113         case 0:
114                 dev->dev.platform_data = &ap9x_wmac0_data;
115                 break;
116         }
117
118         return 0;
119 }
120
121 __init void ap91_pci_init(u8 *cal_data, u8 *mac_addr)
122 {
123         if (cal_data)
124                 memcpy(ap9x_wmac0_data.eeprom_data, cal_data,
125                        sizeof(ap9x_wmac0_data.eeprom_data));
126
127         if (mac_addr) {
128                 memcpy(ap9x_wmac0_mac, mac_addr, sizeof(ap9x_wmac0_mac));
129                 ap9x_wmac0_data.macaddr = ap9x_wmac0_mac;
130         }
131
132         ath79_pci_set_plat_dev_init(ap91_pci_plat_dev_init);
133         ath79_register_pci();
134
135         pci_enable_ath9k_fixup(0, ap9x_wmac0_data.eeprom_data);
136 }
137
138 __init void ap91_pci_init_simple(void)
139 {
140         ap91_pci_init(NULL, NULL);
141         ap9x_wmac0_data.eeprom_name = "pci_wmac0.eeprom";
142 }
143
144 static int ap94_pci_plat_dev_init(struct pci_dev *dev)
145 {
146         switch (PCI_SLOT(dev->devfn)) {
147         case 17:
148                 dev->dev.platform_data = &ap9x_wmac0_data;
149                 break;
150
151         case 18:
152                 dev->dev.platform_data = &ap9x_wmac1_data;
153                 break;
154         }
155
156         return 0;
157 }
158
159 __init void ap94_pci_init(u8 *cal_data0, u8 *mac_addr0,
160                           u8 *cal_data1, u8 *mac_addr1)
161 {
162         if (cal_data0)
163                 memcpy(ap9x_wmac0_data.eeprom_data, cal_data0,
164                        sizeof(ap9x_wmac0_data.eeprom_data));
165
166         if (cal_data1)
167                 memcpy(ap9x_wmac1_data.eeprom_data, cal_data1,
168                        sizeof(ap9x_wmac1_data.eeprom_data));
169
170         if (mac_addr0) {
171                 memcpy(ap9x_wmac0_mac, mac_addr0, sizeof(ap9x_wmac0_mac));
172                 ap9x_wmac0_data.macaddr = ap9x_wmac0_mac;
173         }
174
175         if (mac_addr1) {
176                 memcpy(ap9x_wmac1_mac, mac_addr1, sizeof(ap9x_wmac1_mac));
177                 ap9x_wmac1_data.macaddr = ap9x_wmac1_mac;
178         }
179
180         ath79_pci_set_plat_dev_init(ap94_pci_plat_dev_init);
181         ath79_register_pci();
182
183         pci_enable_ath9k_fixup(17, ap9x_wmac0_data.eeprom_data);
184         pci_enable_ath9k_fixup(18, ap9x_wmac1_data.eeprom_data);
185 }