2 * Atheros AP94 reference board PCI initialization
4 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
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.
11 #include <linux/pci.h>
12 #include <linux/init.h>
13 #include <linux/delay.h>
14 #include <lantiq_soc.h>
16 #define LTQ_PCI_MEM_BASE 0x18000000
23 static int ath_num_fixups;
24 static struct ath_fixup ath_fixups[2];
26 static void ath_pci_fixup(struct pci_dev *dev)
35 for (i = 0; i < ath_num_fixups; i++) {
36 if (ath_fixups[i].cal_data == NULL)
39 if (ath_fixups[i].slot != PCI_SLOT(dev->devfn))
42 cal_data = ath_fixups[i].cal_data;
49 if (*cal_data != 0xa55a) {
50 pr_err("pci %s: invalid calibration data\n", pci_name(dev));
54 pr_info("pci %s: fixup device configuration\n", pci_name(dev));
56 mem = ioremap(LTQ_PCI_MEM_BASE, 0x10000);
58 pr_err("pci %s: ioremap error\n", pci_name(dev));
62 pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar0);
63 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, LTQ_PCI_MEM_BASE);
64 pci_read_config_word(dev, PCI_COMMAND, &cmd);
65 cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
66 pci_write_config_word(dev, PCI_COMMAND, cmd);
68 /* set pointer to first reg address */
70 while (*cal_data != 0xffff) {
74 val |= (*cal_data++) << 16;
76 ltq_w32(swab32(val), mem + reg);
80 pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
81 dev->vendor = val & 0xffff;
82 dev->device = (val >> 16) & 0xffff;
84 pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
85 dev->revision = val & 0xff;
86 dev->class = val >> 8; /* upper 3 bytes */
88 pr_info("pci %s: fixup info: [%04x:%04x] revision %02x class %#08x\n",
89 pci_name(dev), dev->vendor, dev->device, dev->revision, dev->class);
91 pci_read_config_word(dev, PCI_COMMAND, &cmd);
92 cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
93 pci_write_config_word(dev, PCI_COMMAND, cmd);
95 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
99 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID, ath_pci_fixup);
101 void __init ltq_pci_ath_fixup(unsigned slot, u16 *cal_data)
103 if (ath_num_fixups >= ARRAY_SIZE(ath_fixups))
106 ath_fixups[ath_num_fixups].slot = slot;
107 ath_fixups[ath_num_fixups].cal_data = cal_data;