pci-ath9k-fixup.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #include <linux/pci.h>
  11. #include <linux/delay.h>
  12. #include <asm/mach-ath79/ar71xx_regs.h>
  13. #include <asm/mach-ath79/ath79.h>
  14. struct ath9k_fixup {
  15. u16 *cal_data;
  16. unsigned slot;
  17. };
  18. static int ath9k_num_fixups;
  19. static struct ath9k_fixup ath9k_fixups[2];
  20. static void ath9k_pci_fixup(struct pci_dev *dev)
  21. {
  22. void __iomem *mem;
  23. u16 *cal_data = NULL;
  24. u16 cmd;
  25. u32 bar0;
  26. u32 val;
  27. unsigned i;
  28. for (i = 0; i < ath9k_num_fixups; i++) {
  29. if (ath9k_fixups[i].cal_data == NULL)
  30. continue;
  31. if (ath9k_fixups[i].slot != PCI_SLOT(dev->devfn))
  32. continue;
  33. cal_data = ath9k_fixups[i].cal_data;
  34. break;
  35. }
  36. if (cal_data == NULL)
  37. return;
  38. if (*cal_data != 0xa55a) {
  39. pr_err("pci %s: invalid calibration data\n", pci_name(dev));
  40. return;
  41. }
  42. pr_info("pci %s: fixup device configuration\n", pci_name(dev));
  43. mem = ioremap(AR71XX_PCI_MEM_BASE, 0x10000);
  44. if (!mem) {
  45. pr_err("pci %s: ioremap error\n", pci_name(dev));
  46. return;
  47. }
  48. pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &bar0);
  49. switch (ath79_soc) {
  50. case ATH79_SOC_AR7161:
  51. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
  52. AR71XX_PCI_MEM_BASE);
  53. break;
  54. case ATH79_SOC_AR7240:
  55. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0xffff);
  56. break;
  57. case ATH79_SOC_AR7241:
  58. case ATH79_SOC_AR7242:
  59. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0x1000ffff);
  60. break;
  61. default:
  62. BUG();
  63. }
  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);
  67. /* set pointer to first reg address */
  68. cal_data += 3;
  69. while (*cal_data != 0xffff) {
  70. u32 reg;
  71. reg = *cal_data++;
  72. val = *cal_data++;
  73. val |= (*cal_data++) << 16;
  74. __raw_writel(val, mem + reg);
  75. udelay(100);
  76. }
  77. pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
  78. dev->vendor = val & 0xffff;
  79. dev->device = (val >> 16) & 0xffff;
  80. pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
  81. dev->revision = val & 0xff;
  82. dev->class = val >> 8; /* upper 3 bytes */
  83. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  84. cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
  85. pci_write_config_word(dev, PCI_COMMAND, cmd);
  86. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
  87. iounmap(mem);
  88. }
  89. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID, ath9k_pci_fixup);
  90. void __init pci_enable_ath9k_fixup(unsigned slot, u16 *cal_data)
  91. {
  92. if (ath9k_num_fixups >= ARRAY_SIZE(ath9k_fixups))
  93. return;
  94. ath9k_fixups[ath9k_num_fixups].slot = slot;
  95. ath9k_fixups[ath9k_num_fixups].cal_data = cal_data;
  96. ath9k_num_fixups++;
  97. }