core.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. bool bcma_core_is_enabled(struct bcma_device *core)
  11. {
  12. if ((bcma_aread32(core, BCMA_IOCTL) & (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC))
  13. != BCMA_IOCTL_CLK)
  14. return false;
  15. if (bcma_aread32(core, BCMA_RESET_CTL) & BCMA_RESET_CTL_RESET)
  16. return false;
  17. return true;
  18. }
  19. EXPORT_SYMBOL_GPL(bcma_core_is_enabled);
  20. void bcma_core_disable(struct bcma_device *core, u32 flags)
  21. {
  22. if (bcma_aread32(core, BCMA_RESET_CTL) & BCMA_RESET_CTL_RESET)
  23. return;
  24. bcma_awrite32(core, BCMA_IOCTL, flags);
  25. bcma_aread32(core, BCMA_IOCTL);
  26. udelay(10);
  27. bcma_awrite32(core, BCMA_RESET_CTL, BCMA_RESET_CTL_RESET);
  28. udelay(1);
  29. }
  30. EXPORT_SYMBOL_GPL(bcma_core_disable);
  31. int bcma_core_enable(struct bcma_device *core, u32 flags)
  32. {
  33. bcma_core_disable(core, flags);
  34. bcma_awrite32(core, BCMA_IOCTL, (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC | flags));
  35. bcma_aread32(core, BCMA_IOCTL);
  36. bcma_awrite32(core, BCMA_RESET_CTL, 0);
  37. udelay(1);
  38. bcma_awrite32(core, BCMA_IOCTL, (BCMA_IOCTL_CLK | flags));
  39. bcma_aread32(core, BCMA_IOCTL);
  40. udelay(1);
  41. return 0;
  42. }
  43. EXPORT_SYMBOL_GPL(bcma_core_enable);
  44. void bcma_core_set_clockmode(struct bcma_device *core,
  45. enum bcma_clkmode clkmode)
  46. {
  47. u16 i;
  48. WARN_ON(core->id.id != BCMA_CORE_CHIPCOMMON &&
  49. core->id.id != BCMA_CORE_PCIE &&
  50. core->id.id != BCMA_CORE_80211);
  51. switch (clkmode) {
  52. case BCMA_CLKMODE_FAST:
  53. bcma_set32(core, BCMA_CLKCTLST, BCMA_CLKCTLST_FORCEHT);
  54. udelay(64);
  55. for (i = 0; i < 1500; i++) {
  56. if (bcma_read32(core, BCMA_CLKCTLST) &
  57. BCMA_CLKCTLST_HAVEHT) {
  58. i = 0;
  59. break;
  60. }
  61. udelay(10);
  62. }
  63. if (i)
  64. pr_err("HT force timeout\n");
  65. break;
  66. case BCMA_CLKMODE_DYNAMIC:
  67. pr_warn("Dynamic clockmode not supported yet!\n");
  68. break;
  69. }
  70. }
  71. EXPORT_SYMBOL_GPL(bcma_core_set_clockmode);
  72. void bcma_core_pll_ctl(struct bcma_device *core, u32 req, u32 status, bool on)
  73. {
  74. u16 i;
  75. WARN_ON(req & ~BCMA_CLKCTLST_EXTRESREQ);
  76. WARN_ON(status & ~BCMA_CLKCTLST_EXTRESST);
  77. if (on) {
  78. bcma_set32(core, BCMA_CLKCTLST, req);
  79. for (i = 0; i < 10000; i++) {
  80. if ((bcma_read32(core, BCMA_CLKCTLST) & status) ==
  81. status) {
  82. i = 0;
  83. break;
  84. }
  85. udelay(10);
  86. }
  87. if (i)
  88. pr_err("PLL enable timeout\n");
  89. } else {
  90. pr_warn("Disabling PLL not supported yet!\n");
  91. }
  92. }
  93. EXPORT_SYMBOL_GPL(bcma_core_pll_ctl);
  94. u32 bcma_core_dma_translation(struct bcma_device *core)
  95. {
  96. switch (core->bus->hosttype) {
  97. case BCMA_HOSTTYPE_SOC:
  98. return 0;
  99. case BCMA_HOSTTYPE_PCI:
  100. if (bcma_aread32(core, BCMA_IOST) & BCMA_IOST_DMA64)
  101. return BCMA_DMA_TRANSLATION_DMA64_CMT;
  102. else
  103. return BCMA_DMA_TRANSLATION_DMA32_CMT;
  104. default:
  105. pr_err("DMA translation unknown for host %d\n",
  106. core->bus->hosttype);
  107. }
  108. return BCMA_DMA_TRANSLATION_NONE;
  109. }
  110. EXPORT_SYMBOL(bcma_core_dma_translation);