core.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Broadcom specific AMBA
  3. * Core ops
  4. *
  5. * Licensed under the GNU/GPL. See COPYING for details.
  6. */
  7. #include "bcma_private.h"
  8. #include <linux/export.h>
  9. #include <linux/bcma/bcma.h>
  10. static bool bcma_core_wait_value(struct bcma_device *core, u16 reg, u32 mask,
  11. u32 value, int timeout)
  12. {
  13. unsigned long deadline = jiffies + timeout;
  14. u32 val;
  15. do {
  16. val = bcma_aread32(core, reg);
  17. if ((val & mask) == value)
  18. return true;
  19. cpu_relax();
  20. udelay(10);
  21. } while (!time_after_eq(jiffies, deadline));
  22. bcma_warn(core->bus, "Timeout waiting for register 0x%04X!\n", reg);
  23. return false;
  24. }
  25. bool bcma_core_is_enabled(struct bcma_device *core)
  26. {
  27. if ((bcma_aread32(core, BCMA_IOCTL) & (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC))
  28. != BCMA_IOCTL_CLK)
  29. return false;
  30. if (bcma_aread32(core, BCMA_RESET_CTL) & BCMA_RESET_CTL_RESET)
  31. return false;
  32. return true;
  33. }
  34. EXPORT_SYMBOL_GPL(bcma_core_is_enabled);
  35. void bcma_core_disable(struct bcma_device *core, u32 flags)
  36. {
  37. if (bcma_aread32(core, BCMA_RESET_CTL) & BCMA_RESET_CTL_RESET)
  38. return;
  39. bcma_core_wait_value(core, BCMA_RESET_ST, ~0, 0, 300);
  40. bcma_awrite32(core, BCMA_RESET_CTL, BCMA_RESET_CTL_RESET);
  41. bcma_aread32(core, BCMA_RESET_CTL);
  42. udelay(1);
  43. bcma_awrite32(core, BCMA_IOCTL, flags);
  44. bcma_aread32(core, BCMA_IOCTL);
  45. udelay(10);
  46. }
  47. EXPORT_SYMBOL_GPL(bcma_core_disable);
  48. int bcma_core_enable(struct bcma_device *core, u32 flags)
  49. {
  50. bcma_core_disable(core, flags);
  51. bcma_awrite32(core, BCMA_IOCTL, (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC | flags));
  52. bcma_aread32(core, BCMA_IOCTL);
  53. bcma_awrite32(core, BCMA_RESET_CTL, 0);
  54. bcma_aread32(core, BCMA_RESET_CTL);
  55. udelay(1);
  56. bcma_awrite32(core, BCMA_IOCTL, (BCMA_IOCTL_CLK | flags));
  57. bcma_aread32(core, BCMA_IOCTL);
  58. udelay(1);
  59. return 0;
  60. }
  61. EXPORT_SYMBOL_GPL(bcma_core_enable);
  62. void bcma_core_set_clockmode(struct bcma_device *core,
  63. enum bcma_clkmode clkmode)
  64. {
  65. u16 i;
  66. WARN_ON(core->id.id != BCMA_CORE_CHIPCOMMON &&
  67. core->id.id != BCMA_CORE_PCIE &&
  68. core->id.id != BCMA_CORE_80211);
  69. switch (clkmode) {
  70. case BCMA_CLKMODE_FAST:
  71. bcma_set32(core, BCMA_CLKCTLST, BCMA_CLKCTLST_FORCEHT);
  72. usleep_range(64, 300);
  73. for (i = 0; i < 1500; i++) {
  74. if (bcma_read32(core, BCMA_CLKCTLST) &
  75. BCMA_CLKCTLST_HAVEHT) {
  76. i = 0;
  77. break;
  78. }
  79. udelay(10);
  80. }
  81. if (i)
  82. bcma_err(core->bus, "HT force timeout\n");
  83. break;
  84. case BCMA_CLKMODE_DYNAMIC:
  85. bcma_set32(core, BCMA_CLKCTLST, ~BCMA_CLKCTLST_FORCEHT);
  86. break;
  87. }
  88. }
  89. EXPORT_SYMBOL_GPL(bcma_core_set_clockmode);
  90. void bcma_core_pll_ctl(struct bcma_device *core, u32 req, u32 status, bool on)
  91. {
  92. u16 i;
  93. WARN_ON(req & ~BCMA_CLKCTLST_EXTRESREQ);
  94. WARN_ON(status & ~BCMA_CLKCTLST_EXTRESST);
  95. if (on) {
  96. bcma_set32(core, BCMA_CLKCTLST, req);
  97. for (i = 0; i < 10000; i++) {
  98. if ((bcma_read32(core, BCMA_CLKCTLST) & status) ==
  99. status) {
  100. i = 0;
  101. break;
  102. }
  103. udelay(10);
  104. }
  105. if (i)
  106. bcma_err(core->bus, "PLL enable timeout\n");
  107. } else {
  108. /*
  109. * Mask the PLL but don't wait for it to be disabled. PLL may be
  110. * shared between cores and will be still up if there is another
  111. * core using it.
  112. */
  113. bcma_mask32(core, BCMA_CLKCTLST, ~req);
  114. bcma_read32(core, BCMA_CLKCTLST);
  115. }
  116. }
  117. EXPORT_SYMBOL_GPL(bcma_core_pll_ctl);
  118. u32 bcma_core_dma_translation(struct bcma_device *core)
  119. {
  120. switch (core->bus->hosttype) {
  121. case BCMA_HOSTTYPE_SOC:
  122. return 0;
  123. case BCMA_HOSTTYPE_PCI:
  124. if (bcma_aread32(core, BCMA_IOST) & BCMA_IOST_DMA64)
  125. return BCMA_DMA_TRANSLATION_DMA64_CMT;
  126. else
  127. return BCMA_DMA_TRANSLATION_DMA32_CMT;
  128. default:
  129. bcma_err(core->bus, "DMA translation unknown for host %d\n",
  130. core->bus->hosttype);
  131. }
  132. return BCMA_DMA_TRANSLATION_NONE;
  133. }
  134. EXPORT_SYMBOL(bcma_core_dma_translation);