b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From bbebbf735a02b6d044ed928978ab4bd5f1833364 Mon Sep 17 00:00:00 2001 |
| 2 | From: Jonas Gorski <jonas.gorski@gmail.com> |
| 3 | Date: Thu, 3 May 2012 14:36:11 +0200 |
| 4 | Subject: [PATCH 61/72] BCM63XX: add a fixup for ath9k devices |
| 5 | |
| 6 | --- |
| 7 | arch/mips/bcm63xx/Makefile | 3 +- |
| 8 | arch/mips/bcm63xx/pci-ath9k-fixup.c | 190 ++++++++++++++++++++ |
| 9 | .../include/asm/mach-bcm63xx/pci_ath9k_fixup.h | 7 + |
| 10 | 3 files changed, 199 insertions(+), 1 deletion(-) |
| 11 | create mode 100644 arch/mips/bcm63xx/pci-ath9k-fixup.c |
| 12 | create mode 100644 arch/mips/include/asm/mach-bcm63xx/pci_ath9k_fixup.h |
| 13 | |
| 14 | --- a/arch/mips/bcm63xx/Makefile |
| 15 | +++ b/arch/mips/bcm63xx/Makefile |
| 16 | @@ -3,7 +3,7 @@ obj-y += clk.o cpu.o cs.o gpio.o irq.o |
| 17 | setup.o timer.o dev-enet.o dev-flash.o dev-pcmcia.o \ |
| 18 | dev-rng.o dev-wdt.o \ |
| 19 | dev-usb-ehci.o dev-usb-ohci.o dev-usb-usbd.o usb-common.o \ |
| 20 | - sprom.o |
| 21 | + pci-ath9k-fixup.o sprom.o |
| 22 | obj-$(CONFIG_EARLY_PRINTK) += early_printk.o |
| 23 | |
| 24 | obj-y += boards/ |
| 25 | --- /dev/null |
| 26 | +++ b/arch/mips/bcm63xx/pci-ath9k-fixup.c |
| 27 | @@ -0,0 +1,201 @@ |
| 28 | +/* |
| 29 | + * Broadcom BCM63XX Ath9k EEPROM fixup helper. |
| 30 | + * |
| 31 | + * Copytight (C) 2012 Jonas Gorski <jonas.gorski@gmail.com> |
| 32 | + * |
| 33 | + * Based on |
| 34 | + * |
| 35 | + * Atheros AP94 reference board PCI initialization |
| 36 | + * |
| 37 | + * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org> |
| 38 | + * |
| 39 | + * This program is free software; you can redistribute it and/or modify it |
| 40 | + * under the terms of the GNU General Public License version 2 as published |
| 41 | + * by the Free Software Foundation. |
| 42 | + */ |
| 43 | + |
| 44 | +#include <linux/if_ether.h> |
| 45 | +#include <linux/pci.h> |
| 46 | +#include <linux/delay.h> |
| 47 | +#include <linux/ath9k_platform.h> |
| 48 | + |
| 49 | +#include <bcm63xx_cpu.h> |
| 50 | +#include <bcm63xx_regs.h> |
| 51 | +#include <bcm63xx_io.h> |
| 52 | +#include <bcm63xx_nvram.h> |
| 53 | +#include <bcm63xx_dev_pci.h> |
| 54 | +#include <bcm63xx_dev_flash.h> |
| 55 | +#include <pci_ath9k_fixup.h> |
| 56 | + |
| 57 | +#define bcm_hsspi_writel(v, o) bcm_rset_writel(RSET_HSSPI, (v), (o)) |
| 58 | + |
| 59 | +struct ath9k_fixup { |
| 60 | + unsigned slot; |
| 61 | + u8 mac[ETH_ALEN]; |
| 62 | + struct ath9k_platform_data pdata; |
| 63 | +}; |
| 64 | + |
| 65 | +static int ath9k_num_fixups; |
| 66 | +static struct ath9k_fixup ath9k_fixups[2] = { |
| 67 | + { |
| 68 | + .slot = 255, |
| 69 | + .pdata = { |
| 70 | + .led_pin = -1, |
| 71 | + }, |
| 72 | + }, |
| 73 | + { |
| 74 | + .slot = 255, |
| 75 | + .pdata = { |
| 76 | + .led_pin = -1, |
| 77 | + }, |
| 78 | + }, |
| 79 | +}; |
| 80 | + |
| 81 | +static u16 *bcm63xx_read_eeprom(u16 *eeprom, u32 offset) |
| 82 | +{ |
| 83 | + u32 addr; |
| 84 | + |
| 85 | + if (BCMCPU_IS_6328()) { |
| 86 | + addr = 0x18000000; |
| 87 | + } else { |
| 88 | + addr = bcm_mpi_readl(MPI_CSBASE_REG(0)); |
| 89 | + addr &= MPI_CSBASE_BASE_MASK; |
| 90 | + } |
| 91 | + |
| 92 | + switch (bcm63xx_flash_get_type()) { |
| 93 | + case BCM63XX_FLASH_TYPE_PARALLEL: |
| 94 | + memcpy(eeprom, (void *)KSEG1ADDR(addr + offset), ATH9K_PLAT_EEP_MAX_WORDS * sizeof(u16)); |
| 95 | + return eeprom; |
| 96 | + case BCM63XX_FLASH_TYPE_SERIAL: |
| 97 | + /* the first megabyte is memory mapped */ |
| 98 | + if (offset < 0x100000) { |
| 99 | + memcpy(eeprom, (void *)KSEG1ADDR(addr + offset), ATH9K_PLAT_EEP_MAX_WORDS * sizeof(u16)); |
| 100 | + return eeprom; |
| 101 | + } |
| 102 | + |
| 103 | + if (BCMCPU_IS_6328()) { |
| 104 | + /* we can change the memory mapped megabyte */ |
| 105 | + bcm_hsspi_writel(offset & 0xf00000, 0x18); |
| 106 | + memcpy(eeprom, (void *)KSEG1ADDR(addr + (offset & 0xfffff)), ATH9K_PLAT_EEP_MAX_WORDS * sizeof(u16)); |
| 107 | + bcm_hsspi_writel(0, 0x18); |
| 108 | + return eeprom; |
| 109 | + } |
| 110 | + /* can't do anything here without talking to the SPI controller. */ |
| 111 | + /* Fall through */ |
| 112 | + case BCM63XX_FLASH_TYPE_NAND: |
| 113 | + default: |
| 114 | + return NULL; |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +static void ath9k_pci_fixup(struct pci_dev *dev) |
| 119 | +{ |
| 120 | + void __iomem *mem; |
| 121 | + struct ath9k_platform_data *pdata = NULL; |
| 122 | + struct pci_dev *bridge = pci_upstream_bridge(dev); |
| 123 | + u16 *cal_data = NULL; |
| 124 | + u16 cmd; |
| 125 | + u32 bar0; |
| 126 | + u32 val; |
| 127 | + unsigned i; |
| 128 | + |
| 129 | + for (i = 0; i < ath9k_num_fixups; i++) { |
| 130 | + if (ath9k_fixups[i].slot != PCI_SLOT(dev->devfn)) |
| 131 | + continue; |
| 132 | + |
| 133 | + cal_data = ath9k_fixups[i].pdata.eeprom_data; |
| 134 | + pdata = &ath9k_fixups[i].pdata; |
| 135 | + break; |
| 136 | + } |
| 137 | + |
| 138 | + if (cal_data == NULL) |
| 139 | + return; |
| 140 | + |
| 141 | + if (*cal_data != 0xa55a) { |
| 142 | + pr_err("pci %s: invalid calibration data\n", pci_name(dev)); |
| 143 | + return; |
| 144 | + } |
| 145 | + |
| 146 | + pr_info("pci %s: fixup device configuration\n", pci_name(dev)); |
| 147 | + |
| 148 | + switch (bcm63xx_get_cpu_id()) { |
| 149 | + case BCM6328_CPU_ID: |
| 150 | + val = BCM_PCIE_MEM_BASE_PA_6328; |
| 151 | + break; |
| 152 | + case BCM6348_CPU_ID: |
| 153 | + case BCM6358_CPU_ID: |
| 154 | + case BCM6368_CPU_ID: |
| 155 | + val = BCM_PCI_MEM_BASE_PA; |
| 156 | + break; |
| 157 | + default: |
| 158 | + BUG(); |
| 159 | + } |
| 160 | + |
| 161 | + mem = ioremap(val, 0x10000); |
| 162 | + if (!mem) { |
| 163 | + pr_err("pci %s: ioremap error\n", pci_name(dev)); |
| 164 | + return; |
| 165 | + } |
| 166 | + |
| 167 | + if (bridge) |
| 168 | + pci_enable_device(bridge); |
| 169 | + |
| 170 | + pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar0); |
| 171 | + pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar0); |
| 172 | + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, val); |
| 173 | + |
| 174 | + pci_read_config_word(dev, PCI_COMMAND, &cmd); |
| 175 | + cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
| 176 | + pci_write_config_word(dev, PCI_COMMAND, cmd); |
| 177 | + |
| 178 | + /* set offset to first reg address */ |
| 179 | + cal_data += 3; |
| 180 | + while(*cal_data != 0xffff) { |
| 181 | + u32 reg; |
| 182 | + reg = *cal_data++; |
| 183 | + val = *cal_data++; |
| 184 | + val |= (*cal_data++) << 16; |
| 185 | + |
| 186 | + writel(val, mem + reg); |
| 187 | + udelay(100); |
| 188 | + } |
| 189 | + |
| 190 | + pci_read_config_dword(dev, PCI_VENDOR_ID, &val); |
| 191 | + dev->vendor = val & 0xffff; |
| 192 | + dev->device = (val >> 16) & 0xffff; |
| 193 | + |
| 194 | + pci_read_config_dword(dev, PCI_CLASS_REVISION, &val); |
| 195 | + dev->revision = val & 0xff; |
| 196 | + dev->class = val >> 8; /* upper 3 bytes */ |
| 197 | + |
| 198 | + pci_read_config_word(dev, PCI_COMMAND, &cmd); |
| 199 | + cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); |
| 200 | + pci_write_config_word(dev, PCI_COMMAND, cmd); |
| 201 | + |
| 202 | + pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0); |
| 203 | + |
| 204 | + if (bridge) |
| 205 | + pci_disable_device(bridge); |
| 206 | + |
| 207 | + iounmap(mem); |
| 208 | + |
| 209 | + dev->dev.platform_data = pdata; |
| 210 | +} |
| 211 | +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID, ath9k_pci_fixup); |
| 212 | + |
| 213 | +void __init pci_enable_ath9k_fixup(unsigned slot, u32 offset) |
| 214 | +{ |
| 215 | + if (ath9k_num_fixups >= ARRAY_SIZE(ath9k_fixups)) |
| 216 | + return; |
| 217 | + |
| 218 | + ath9k_fixups[ath9k_num_fixups].slot = slot; |
| 219 | + |
| 220 | + if (!bcm63xx_read_eeprom(ath9k_fixups[ath9k_num_fixups].pdata.eeprom_data, offset)) |
| 221 | + return; |
| 222 | + |
| 223 | + if (bcm63xx_nvram_get_mac_address(ath9k_fixups[ath9k_num_fixups].mac)) |
| 224 | + return; |
| 225 | + |
| 226 | + ath9k_fixups[ath9k_num_fixups].pdata.macaddr = ath9k_fixups[ath9k_num_fixups].mac; |
| 227 | + ath9k_num_fixups++; |
| 228 | +} |
| 229 | --- /dev/null |
| 230 | +++ b/arch/mips/include/asm/mach-bcm63xx/pci_ath9k_fixup.h |
| 231 | @@ -0,0 +1,7 @@ |
| 232 | +#ifndef _PCI_ATH9K_FIXUP |
| 233 | +#define _PCI_ATH9K_FIXUP |
| 234 | + |
| 235 | + |
| 236 | +void pci_enable_ath9k_fixup(unsigned slot, u32 offset) __init; |
| 237 | + |
| 238 | +#endif /* _PCI_ATH9K_FIXUP */ |