ar71xx: merge files-3.2 to files
[openwrt/svn-archive/archive.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 void ap9x_pci_setup_wmac_gpio(unsigned wmac, u32 mask, u32 val)
44 {
45 switch (wmac) {
46 case 0:
47 ap9x_wmac0_data.gpio_mask = mask;
48 ap9x_wmac0_data.gpio_val = val;
49 break;
50 case 1:
51 ap9x_wmac1_data.gpio_mask = mask;
52 ap9x_wmac1_data.gpio_val = val;
53 break;
54 }
55 }
56
57 __init void ap9x_pci_setup_wmac_leds(unsigned wmac, struct gpio_led *leds,
58 int num_leds)
59 {
60 switch (wmac) {
61 case 0:
62 ap9x_wmac0_data.leds = leds;
63 ap9x_wmac0_data.num_leds = num_leds;
64 break;
65 case 1:
66 ap9x_wmac1_data.leds = leds;
67 ap9x_wmac1_data.num_leds = num_leds;
68 break;
69 }
70 }
71
72 static int ap91_pci_plat_dev_init(struct pci_dev *dev)
73 {
74 switch (PCI_SLOT(dev->devfn)) {
75 case 0:
76 dev->dev.platform_data = &ap9x_wmac0_data;
77 break;
78 }
79
80 return 0;
81 }
82
83 __init void ap91_pci_init(u8 *cal_data, u8 *mac_addr)
84 {
85 if (cal_data)
86 memcpy(ap9x_wmac0_data.eeprom_data, cal_data,
87 sizeof(ap9x_wmac0_data.eeprom_data));
88
89 if (mac_addr) {
90 memcpy(ap9x_wmac0_mac, mac_addr, sizeof(ap9x_wmac0_mac));
91 ap9x_wmac0_data.macaddr = ap9x_wmac0_mac;
92 }
93
94 ath79_pci_set_plat_dev_init(ap91_pci_plat_dev_init);
95 ath79_register_pci();
96
97 pci_enable_ath9k_fixup(0, ap9x_wmac0_data.eeprom_data);
98 }
99
100 static int ap94_pci_plat_dev_init(struct pci_dev *dev)
101 {
102 switch (PCI_SLOT(dev->devfn)) {
103 case 17:
104 dev->dev.platform_data = &ap9x_wmac0_data;
105 break;
106
107 case 18:
108 dev->dev.platform_data = &ap9x_wmac1_data;
109 break;
110 }
111
112 return 0;
113 }
114
115 __init void ap94_pci_init(u8 *cal_data0, u8 *mac_addr0,
116 u8 *cal_data1, u8 *mac_addr1)
117 {
118 if (cal_data0)
119 memcpy(ap9x_wmac0_data.eeprom_data, cal_data0,
120 sizeof(ap9x_wmac0_data.eeprom_data));
121
122 if (cal_data1)
123 memcpy(ap9x_wmac1_data.eeprom_data, cal_data1,
124 sizeof(ap9x_wmac1_data.eeprom_data));
125
126 if (mac_addr0) {
127 memcpy(ap9x_wmac0_mac, mac_addr0, sizeof(ap9x_wmac0_mac));
128 ap9x_wmac0_data.macaddr = ap9x_wmac0_mac;
129 }
130
131 if (mac_addr1) {
132 memcpy(ap9x_wmac1_mac, mac_addr1, sizeof(ap9x_wmac1_mac));
133 ap9x_wmac1_data.macaddr = ap9x_wmac1_mac;
134 }
135
136 ath79_pci_set_plat_dev_init(ap94_pci_plat_dev_init);
137 ath79_register_pci();
138
139 pci_enable_ath9k_fixup(17, ap9x_wmac0_data.eeprom_data);
140 pci_enable_ath9k_fixup(18, ap9x_wmac1_data.eeprom_data);
141 }