pci-ath9k-fixup.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. case ATH79_SOC_AR9344:
  62. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0x1000ffff);
  63. break;
  64. default:
  65. BUG();
  66. }
  67. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  68. cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  69. pci_write_config_word(dev, PCI_COMMAND, cmd);
  70. /* set pointer to first reg address */
  71. cal_data += 3;
  72. while (*cal_data != 0xffff) {
  73. u32 reg;
  74. reg = *cal_data++;
  75. val = *cal_data++;
  76. val |= (*cal_data++) << 16;
  77. __raw_writel(val, mem + reg);
  78. udelay(100);
  79. }
  80. pci_read_config_dword(dev, PCI_VENDOR_ID, &val);
  81. dev->vendor = val & 0xffff;
  82. dev->device = (val >> 16) & 0xffff;
  83. pci_read_config_dword(dev, PCI_CLASS_REVISION, &val);
  84. dev->revision = val & 0xff;
  85. dev->class = val >> 8; /* upper 3 bytes */
  86. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  87. cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
  88. pci_write_config_word(dev, PCI_COMMAND, cmd);
  89. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
  90. iounmap(mem);
  91. }
  92. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATHEROS, PCI_ANY_ID, ath9k_pci_fixup);
  93. void __init pci_enable_ath9k_fixup(unsigned slot, u16 *cal_data)
  94. {
  95. if (ath9k_num_fixups >= ARRAY_SIZE(ath9k_fixups))
  96. return;
  97. ath9k_fixups[ath9k_num_fixups].slot = slot;
  98. ath9k_fixups[ath9k_num_fixups].cal_data = cal_data;
  99. ath9k_num_fixups++;
  100. }