driver_pcie2.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Broadcom specific AMBA
  3. * PCIe Gen 2 Core
  4. *
  5. * Copyright 2014, Broadcom Corporation
  6. * Copyright 2014, Rafał Miłecki <zajec5@gmail.com>
  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. #if 0
  16. static u32 bcma_core_pcie2_cfg_read(struct bcma_drv_pcie2 *pcie2, u32 addr)
  17. {
  18. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDADDR, addr);
  19. pcie2_read32(pcie2, BCMA_CORE_PCIE2_CONFIGINDADDR);
  20. return pcie2_read32(pcie2, BCMA_CORE_PCIE2_CONFIGINDDATA);
  21. }
  22. #endif
  23. static void bcma_core_pcie2_cfg_write(struct bcma_drv_pcie2 *pcie2, u32 addr,
  24. u32 val)
  25. {
  26. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDADDR, addr);
  27. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDDATA, val);
  28. }
  29. /**************************************************
  30. * Init.
  31. **************************************************/
  32. static u32 bcma_core_pcie2_war_delay_perst_enab(struct bcma_drv_pcie2 *pcie2,
  33. bool enable)
  34. {
  35. u32 val;
  36. /* restore back to default */
  37. val = pcie2_read32(pcie2, BCMA_CORE_PCIE2_CLK_CONTROL);
  38. val |= PCIE2_CLKC_DLYPERST;
  39. val &= ~PCIE2_CLKC_DISSPROMLD;
  40. if (enable) {
  41. val &= ~PCIE2_CLKC_DLYPERST;
  42. val |= PCIE2_CLKC_DISSPROMLD;
  43. }
  44. pcie2_write32(pcie2, (BCMA_CORE_PCIE2_CLK_CONTROL), val);
  45. /* flush */
  46. return pcie2_read32(pcie2, BCMA_CORE_PCIE2_CLK_CONTROL);
  47. }
  48. static void bcma_core_pcie2_set_ltr_vals(struct bcma_drv_pcie2 *pcie2)
  49. {
  50. /* LTR0 */
  51. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDADDR, 0x844);
  52. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDDATA, 0x883c883c);
  53. /* LTR1 */
  54. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDADDR, 0x848);
  55. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDDATA, 0x88648864);
  56. /* LTR2 */
  57. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDADDR, 0x84C);
  58. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDDATA, 0x90039003);
  59. }
  60. static void bcma_core_pcie2_hw_ltr_war(struct bcma_drv_pcie2 *pcie2)
  61. {
  62. u8 core_rev = pcie2->core->id.rev;
  63. u32 devstsctr2;
  64. if (core_rev < 2 || core_rev == 10 || core_rev > 13)
  65. return;
  66. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDADDR,
  67. PCIE2_CAP_DEVSTSCTRL2_OFFSET);
  68. devstsctr2 = pcie2_read32(pcie2, BCMA_CORE_PCIE2_CONFIGINDDATA);
  69. if (devstsctr2 & PCIE2_CAP_DEVSTSCTRL2_LTRENAB) {
  70. /* force the right LTR values */
  71. bcma_core_pcie2_set_ltr_vals(pcie2);
  72. /* TODO:
  73. si_core_wrapperreg(pcie2, 3, 0x60, 0x8080, 0); */
  74. /* enable the LTR */
  75. devstsctr2 |= PCIE2_CAP_DEVSTSCTRL2_LTRENAB;
  76. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDADDR,
  77. PCIE2_CAP_DEVSTSCTRL2_OFFSET);
  78. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDDATA, devstsctr2);
  79. /* set the LTR state to be active */
  80. pcie2_write32(pcie2, BCMA_CORE_PCIE2_LTR_STATE,
  81. PCIE2_LTR_ACTIVE);
  82. usleep_range(1000, 2000);
  83. /* set the LTR state to be sleep */
  84. pcie2_write32(pcie2, BCMA_CORE_PCIE2_LTR_STATE,
  85. PCIE2_LTR_SLEEP);
  86. usleep_range(1000, 2000);
  87. }
  88. }
  89. static void pciedev_crwlpciegen2(struct bcma_drv_pcie2 *pcie2)
  90. {
  91. u8 core_rev = pcie2->core->id.rev;
  92. bool pciewar160, pciewar162;
  93. pciewar160 = core_rev == 7 || core_rev == 9 || core_rev == 11;
  94. pciewar162 = core_rev == 5 || core_rev == 7 || core_rev == 8 ||
  95. core_rev == 9 || core_rev == 11;
  96. if (!pciewar160 && !pciewar162)
  97. return;
  98. /* TODO */
  99. #if 0
  100. pcie2_set32(pcie2, BCMA_CORE_PCIE2_CLK_CONTROL,
  101. PCIE_DISABLE_L1CLK_GATING);
  102. #if 0
  103. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDADDR,
  104. PCIEGEN2_COE_PVT_TL_CTRL_0);
  105. pcie2_mask32(pcie2, BCMA_CORE_PCIE2_CONFIGINDDATA,
  106. ~(1 << COE_PVT_TL_CTRL_0_PM_DIS_L1_REENTRY_BIT));
  107. #endif
  108. #endif
  109. }
  110. static void pciedev_crwlpciegen2_180(struct bcma_drv_pcie2 *pcie2)
  111. {
  112. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDADDR, PCIE2_PMCR_REFUP);
  113. pcie2_set32(pcie2, BCMA_CORE_PCIE2_CONFIGINDDATA, 0x1f);
  114. }
  115. static void pciedev_crwlpciegen2_182(struct bcma_drv_pcie2 *pcie2)
  116. {
  117. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDADDR, PCIE2_SBMBX);
  118. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDDATA, 1 << 0);
  119. }
  120. static void pciedev_reg_pm_clk_period(struct bcma_drv_pcie2 *pcie2)
  121. {
  122. struct bcma_drv_cc *drv_cc = &pcie2->core->bus->drv_cc;
  123. u8 core_rev = pcie2->core->id.rev;
  124. u32 alp_khz, pm_value;
  125. if (core_rev <= 13) {
  126. alp_khz = bcma_pmu_get_alp_clock(drv_cc) / 1000;
  127. pm_value = (1000000 * 2) / alp_khz;
  128. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDADDR,
  129. PCIE2_PVT_REG_PM_CLK_PERIOD);
  130. pcie2_write32(pcie2, BCMA_CORE_PCIE2_CONFIGINDDATA, pm_value);
  131. }
  132. }
  133. void bcma_core_pcie2_init(struct bcma_drv_pcie2 *pcie2)
  134. {
  135. struct bcma_chipinfo *ci = &pcie2->core->bus->chipinfo;
  136. u32 tmp;
  137. tmp = pcie2_read32(pcie2, BCMA_CORE_PCIE2_SPROM(54));
  138. if ((tmp & 0xe) >> 1 == 2)
  139. bcma_core_pcie2_cfg_write(pcie2, 0x4e0, 0x17);
  140. /* TODO: Do we need pcie_reqsize? */
  141. if (ci->id == BCMA_CHIP_ID_BCM4360 && ci->rev > 3)
  142. bcma_core_pcie2_war_delay_perst_enab(pcie2, true);
  143. bcma_core_pcie2_hw_ltr_war(pcie2);
  144. pciedev_crwlpciegen2(pcie2);
  145. pciedev_reg_pm_clk_period(pcie2);
  146. pciedev_crwlpciegen2_180(pcie2);
  147. pciedev_crwlpciegen2_182(pcie2);
  148. }