driver_pci.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Broadcom specific AMBA
  3. * PCI Core
  4. *
  5. * Copyright 2005, Broadcom Corporation
  6. * Copyright 2006, 2007, Michael Buesch <mb@bu3sch.de>
  7. *
  8. * Licensed under the GNU/GPL. See COPYING for details.
  9. */
  10. #include "bcma_private.h"
  11. #include <linux/bcma/bcma.h>
  12. /**************************************************
  13. * R/W ops.
  14. **************************************************/
  15. static u32 bcma_pcie_read(struct bcma_drv_pci *pc, u32 address)
  16. {
  17. pcicore_write32(pc, 0x130, address);
  18. pcicore_read32(pc, 0x130);
  19. return pcicore_read32(pc, 0x134);
  20. }
  21. #if 0
  22. static void bcma_pcie_write(struct bcma_drv_pci *pc, u32 address, u32 data)
  23. {
  24. pcicore_write32(pc, 0x130, address);
  25. pcicore_read32(pc, 0x130);
  26. pcicore_write32(pc, 0x134, data);
  27. }
  28. #endif
  29. static void bcma_pcie_mdio_set_phy(struct bcma_drv_pci *pc, u8 phy)
  30. {
  31. const u16 mdio_control = 0x128;
  32. const u16 mdio_data = 0x12C;
  33. u32 v;
  34. int i;
  35. v = (1 << 30); /* Start of Transaction */
  36. v |= (1 << 28); /* Write Transaction */
  37. v |= (1 << 17); /* Turnaround */
  38. v |= (0x1F << 18);
  39. v |= (phy << 4);
  40. pcicore_write32(pc, mdio_data, v);
  41. udelay(10);
  42. for (i = 0; i < 200; i++) {
  43. v = pcicore_read32(pc, mdio_control);
  44. if (v & 0x100 /* Trans complete */)
  45. break;
  46. msleep(1);
  47. }
  48. }
  49. static u16 bcma_pcie_mdio_read(struct bcma_drv_pci *pc, u8 device, u8 address)
  50. {
  51. const u16 mdio_control = 0x128;
  52. const u16 mdio_data = 0x12C;
  53. int max_retries = 10;
  54. u16 ret = 0;
  55. u32 v;
  56. int i;
  57. v = 0x80; /* Enable Preamble Sequence */
  58. v |= 0x2; /* MDIO Clock Divisor */
  59. pcicore_write32(pc, mdio_control, v);
  60. if (pc->core->id.rev >= 10) {
  61. max_retries = 200;
  62. bcma_pcie_mdio_set_phy(pc, device);
  63. }
  64. v = (1 << 30); /* Start of Transaction */
  65. v |= (1 << 29); /* Read Transaction */
  66. v |= (1 << 17); /* Turnaround */
  67. if (pc->core->id.rev < 10)
  68. v |= (u32)device << 22;
  69. v |= (u32)address << 18;
  70. pcicore_write32(pc, mdio_data, v);
  71. /* Wait for the device to complete the transaction */
  72. udelay(10);
  73. for (i = 0; i < max_retries; i++) {
  74. v = pcicore_read32(pc, mdio_control);
  75. if (v & 0x100 /* Trans complete */) {
  76. udelay(10);
  77. ret = pcicore_read32(pc, mdio_data);
  78. break;
  79. }
  80. msleep(1);
  81. }
  82. pcicore_write32(pc, mdio_control, 0);
  83. return ret;
  84. }
  85. static void bcma_pcie_mdio_write(struct bcma_drv_pci *pc, u8 device,
  86. u8 address, u16 data)
  87. {
  88. const u16 mdio_control = 0x128;
  89. const u16 mdio_data = 0x12C;
  90. int max_retries = 10;
  91. u32 v;
  92. int i;
  93. v = 0x80; /* Enable Preamble Sequence */
  94. v |= 0x2; /* MDIO Clock Divisor */
  95. pcicore_write32(pc, mdio_control, v);
  96. if (pc->core->id.rev >= 10) {
  97. max_retries = 200;
  98. bcma_pcie_mdio_set_phy(pc, device);
  99. }
  100. v = (1 << 30); /* Start of Transaction */
  101. v |= (1 << 28); /* Write Transaction */
  102. v |= (1 << 17); /* Turnaround */
  103. if (pc->core->id.rev < 10)
  104. v |= (u32)device << 22;
  105. v |= (u32)address << 18;
  106. v |= data;
  107. pcicore_write32(pc, mdio_data, v);
  108. /* Wait for the device to complete the transaction */
  109. udelay(10);
  110. for (i = 0; i < max_retries; i++) {
  111. v = pcicore_read32(pc, mdio_control);
  112. if (v & 0x100 /* Trans complete */)
  113. break;
  114. msleep(1);
  115. }
  116. pcicore_write32(pc, mdio_control, 0);
  117. }
  118. /**************************************************
  119. * Workarounds.
  120. **************************************************/
  121. static u8 bcma_pcicore_polarity_workaround(struct bcma_drv_pci *pc)
  122. {
  123. return (bcma_pcie_read(pc, 0x204) & 0x10) ? 0xC0 : 0x80;
  124. }
  125. static void bcma_pcicore_serdes_workaround(struct bcma_drv_pci *pc)
  126. {
  127. const u8 serdes_pll_device = 0x1D;
  128. const u8 serdes_rx_device = 0x1F;
  129. u16 tmp;
  130. bcma_pcie_mdio_write(pc, serdes_rx_device, 1 /* Control */,
  131. bcma_pcicore_polarity_workaround(pc));
  132. tmp = bcma_pcie_mdio_read(pc, serdes_pll_device, 1 /* Control */);
  133. if (tmp & 0x4000)
  134. bcma_pcie_mdio_write(pc, serdes_pll_device, 1, tmp & ~0x4000);
  135. }
  136. /**************************************************
  137. * Init.
  138. **************************************************/
  139. void bcma_core_pci_init(struct bcma_drv_pci *pc)
  140. {
  141. bcma_pcicore_serdes_workaround(pc);
  142. }