Root/target/linux/ar71xx/files/arch/mips/ar71xx/dev-ap94-pci.c

1/*
2 * Atheros AP94 reference board PCI initialization
3 *
4 * Copyright (C) 2009-2010 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-ar71xx/ar71xx.h>
16#include <asm/mach-ar71xx/pci.h>
17
18#include "dev-ap94-pci.h"
19
20static struct ath9k_platform_data ap94_wmac0_data = {
21    .led_pin = -1,
22};
23static struct ath9k_platform_data ap94_wmac1_data = {
24    .led_pin = -1,
25};
26static char ap94_wmac0_mac[6];
27static char ap94_wmac1_mac[6];
28static int ap94_pci_fixup_enabled;
29
30static struct ar71xx_pci_irq ap94_pci_irqs[] __initdata = {
31        {
32                .slot = 0,
33                .pin = 1,
34                .irq = AR71XX_PCI_IRQ_DEV0,
35        }, {
36                .slot = 1,
37                .pin = 1,
38                .irq = AR71XX_PCI_IRQ_DEV1,
39        }
40};
41
42static int ap94_pci_plat_dev_init(struct pci_dev *dev)
43{
44    switch(PCI_SLOT(dev->devfn)) {
45    case 17:
46        dev->dev.platform_data = &ap94_wmac0_data;
47        break;
48
49    case 18:
50        dev->dev.platform_data = &ap94_wmac1_data;
51        break;
52    }
53
54    return 0;
55}
56
57static void ap94_pci_fixup(struct pci_dev *dev)
58{
59    void __iomem *mem;
60    u16 *cal_data;
61    u16 cmd;
62    u32 bar0;
63    u32 val;
64
65    if (!ap94_pci_fixup_enabled)
66        return;
67
68    switch (PCI_SLOT(dev->devfn)) {
69    case 17:
70        cal_data = ap94_wmac0_data.eeprom_data;
71        break;
72    case 18:
73        cal_data = ap94_wmac1_data.eeprom_data;
74        break;
75    default:
76        return;
77    }
78
79    if (*cal_data != 0xa55a) {
80        printk(KERN_ERR "PCI: no calibration data found for %s\n",
81               pci_name(dev));
82        return;
83    }
84
85    mem = ioremap(AR71XX_PCI_MEM_BASE, 0x10000);
86    if (!mem) {
87        printk(KERN_ERR "PCI: ioremap error for device %s\n",
88               pci_name(dev));
89        return;
90    }
91
92    printk(KERN_INFO "PCI: fixup device %s\n", pci_name(dev));
93
94    pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar0);
95
96    /* Setup the PCI device to allow access to the internal registers */
97    pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, AR71XX_PCI_MEM_BASE);
98    pci_read_config_word(dev, PCI_COMMAND, &cmd);
99    cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
100    pci_write_config_word(dev, PCI_COMMAND, cmd);
101
102    /* set pointer to first reg address */
103    cal_data += 3;
104    while (*cal_data != 0xffff) {
105        u32 reg;
106        reg = *cal_data++;
107        val = *cal_data++;
108        val |= (*cal_data++) << 16;
109
110        __raw_writel(val, mem + reg);
111        udelay(100);
112    }
113
114    pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
115    dev->vendor = val & 0xffff;
116    dev->device = (val >> 16) & 0xffff;
117
118    pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
119    dev->revision = val & 0xff;
120    dev->class = val >> 8; /* upper 3 bytes */
121
122    pci_read_config_word(dev, PCI_COMMAND, &cmd);
123    cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
124    pci_write_config_word(dev, PCI_COMMAND, cmd);
125
126    pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
127
128    iounmap(mem);
129}
130DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID, ap94_pci_fixup);
131
132__init void ap94_pci_setup_wmac_led_pin(unsigned wmac, int pin)
133{
134    switch (wmac) {
135    case 0:
136        ap94_wmac0_data.led_pin = pin;
137        break;
138    case 1:
139        ap94_wmac1_data.led_pin = pin;
140        break;
141    }
142}
143
144__init void ap94_pci_setup_wmac_gpio(unsigned wmac, u32 mask, u32 val)
145{
146    switch (wmac) {
147    case 0:
148        ap94_wmac0_data.gpio_mask = mask;
149        ap94_wmac0_data.gpio_val = val;
150        break;
151    case 1:
152        ap94_wmac1_data.gpio_mask = mask;
153        ap94_wmac1_data.gpio_val = val;
154        break;
155    }
156}
157
158void __init ap94_pci_init(u8 *cal_data0, u8 *mac_addr0,
159              u8 *cal_data1, u8 *mac_addr1)
160{
161    if (cal_data0)
162        memcpy(ap94_wmac0_data.eeprom_data, cal_data0,
163               sizeof(ap94_wmac0_data.eeprom_data));
164
165    if (cal_data1)
166        memcpy(ap94_wmac1_data.eeprom_data, cal_data1,
167               sizeof(ap94_wmac1_data.eeprom_data));
168
169    if (mac_addr0) {
170        memcpy(ap94_wmac0_mac, mac_addr0, sizeof(ap94_wmac0_mac));
171        ap94_wmac0_data.macaddr = ap94_wmac0_mac;
172    }
173
174    if (mac_addr1) {
175        memcpy(ap94_wmac1_mac, mac_addr1, sizeof(ap94_wmac1_mac));
176        ap94_wmac1_data.macaddr = ap94_wmac1_mac;
177    }
178
179    ar71xx_pci_plat_dev_init = ap94_pci_plat_dev_init;
180    ar71xx_pci_init(ARRAY_SIZE(ap94_pci_irqs), ap94_pci_irqs);
181
182    ap94_pci_fixup_enabled = 1;
183}
184

Archive Download this file



interactive