ar71xx: add ap9x_pci_get_wmac_data helper
[oweals/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 #include <asm/mach-ath79/pci.h>
17
18 #include "dev-ap9x-pci.h"
19 #include "pci-ath9k-fixup.h"
20 #include "pci.h"
21
22 static struct ath9k_platform_data ap9x_wmac0_data = {
23         .led_pin = -1,
24 };
25 static struct ath9k_platform_data ap9x_wmac1_data = {
26         .led_pin = -1,
27 };
28 static char ap9x_wmac0_mac[6];
29 static char ap9x_wmac1_mac[6];
30
31 __init void ap9x_pci_setup_wmac_led_pin(unsigned wmac, int pin)
32 {
33         switch (wmac) {
34         case 0:
35                 ap9x_wmac0_data.led_pin = pin;
36                 break;
37         case 1:
38                 ap9x_wmac1_data.led_pin = pin;
39                 break;
40         }
41 }
42
43 __init struct ath9k_platform_data *ap9x_pci_get_wmac_data(unsigned wmac)
44 {
45         switch (wmac) {
46         case 0:
47                 return &ap9x_wmac0_data;
48
49         case 1:
50                 return &ap9x_wmac1_data;
51         }
52
53         return NULL;
54 }
55
56 __init void ap9x_pci_setup_wmac_gpio(unsigned wmac, u32 mask, u32 val)
57 {
58         switch (wmac) {
59         case 0:
60                 ap9x_wmac0_data.gpio_mask = mask;
61                 ap9x_wmac0_data.gpio_val = val;
62                 break;
63         case 1:
64                 ap9x_wmac1_data.gpio_mask = mask;
65                 ap9x_wmac1_data.gpio_val = val;
66                 break;
67         }
68 }
69
70 __init void ap9x_pci_setup_wmac_leds(unsigned wmac, struct gpio_led *leds,
71                                      int num_leds)
72 {
73         switch (wmac) {
74         case 0:
75                 ap9x_wmac0_data.leds = leds;
76                 ap9x_wmac0_data.num_leds = num_leds;
77                 break;
78         case 1:
79                 ap9x_wmac1_data.leds = leds;
80                 ap9x_wmac1_data.num_leds = num_leds;
81                 break;
82         }
83 }
84
85 static int ap91_pci_plat_dev_init(struct pci_dev *dev)
86 {
87         switch (PCI_SLOT(dev->devfn)) {
88         case 0:
89                 dev->dev.platform_data = &ap9x_wmac0_data;
90                 break;
91         }
92
93         return 0;
94 }
95
96 __init void ap91_pci_init(u8 *cal_data, u8 *mac_addr)
97 {
98         if (cal_data)
99                 memcpy(ap9x_wmac0_data.eeprom_data, cal_data,
100                        sizeof(ap9x_wmac0_data.eeprom_data));
101
102         if (mac_addr) {
103                 memcpy(ap9x_wmac0_mac, mac_addr, sizeof(ap9x_wmac0_mac));
104                 ap9x_wmac0_data.macaddr = ap9x_wmac0_mac;
105         }
106
107         ath79_pci_set_plat_dev_init(ap91_pci_plat_dev_init);
108         ath79_register_pci();
109
110         pci_enable_ath9k_fixup(0, ap9x_wmac0_data.eeprom_data);
111 }
112
113 static int ap94_pci_plat_dev_init(struct pci_dev *dev)
114 {
115         switch (PCI_SLOT(dev->devfn)) {
116         case 17:
117                 dev->dev.platform_data = &ap9x_wmac0_data;
118                 break;
119
120         case 18:
121                 dev->dev.platform_data = &ap9x_wmac1_data;
122                 break;
123         }
124
125         return 0;
126 }
127
128 __init void ap94_pci_init(u8 *cal_data0, u8 *mac_addr0,
129                           u8 *cal_data1, u8 *mac_addr1)
130 {
131         if (cal_data0)
132                 memcpy(ap9x_wmac0_data.eeprom_data, cal_data0,
133                        sizeof(ap9x_wmac0_data.eeprom_data));
134
135         if (cal_data1)
136                 memcpy(ap9x_wmac1_data.eeprom_data, cal_data1,
137                        sizeof(ap9x_wmac1_data.eeprom_data));
138
139         if (mac_addr0) {
140                 memcpy(ap9x_wmac0_mac, mac_addr0, sizeof(ap9x_wmac0_mac));
141                 ap9x_wmac0_data.macaddr = ap9x_wmac0_mac;
142         }
143
144         if (mac_addr1) {
145                 memcpy(ap9x_wmac1_mac, mac_addr1, sizeof(ap9x_wmac1_mac));
146                 ap9x_wmac1_data.macaddr = ap9x_wmac1_mac;
147         }
148
149         ath79_pci_set_plat_dev_init(ap94_pci_plat_dev_init);
150         ath79_register_pci();
151
152         pci_enable_ath9k_fixup(17, ap9x_wmac0_data.eeprom_data);
153         pci_enable_ath9k_fixup(18, ap9x_wmac1_data.eeprom_data);
154 }