pmu.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (c) 2011 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/delay.h>
  17. #include <linux/io.h>
  18. #include <brcm_hw_ids.h>
  19. #include <chipcommon.h>
  20. #include <brcmu_utils.h>
  21. #include "pub.h"
  22. #include "aiutils.h"
  23. #include "pmu.h"
  24. #include "soc.h"
  25. /*
  26. * external LPO crystal frequency
  27. */
  28. #define EXT_ILP_HZ 32768
  29. /*
  30. * Duration for ILP clock frequency measurment in milliseconds
  31. *
  32. * remark: 1000 must be an integer multiple of this duration
  33. */
  34. #define ILP_CALC_DUR 10
  35. /* Fields in pmucontrol */
  36. #define PCTL_ILP_DIV_MASK 0xffff0000
  37. #define PCTL_ILP_DIV_SHIFT 16
  38. #define PCTL_PLL_PLLCTL_UPD 0x00000400 /* rev 2 */
  39. #define PCTL_NOILP_ON_WAIT 0x00000200 /* rev 1 */
  40. #define PCTL_HT_REQ_EN 0x00000100
  41. #define PCTL_ALP_REQ_EN 0x00000080
  42. #define PCTL_XTALFREQ_MASK 0x0000007c
  43. #define PCTL_XTALFREQ_SHIFT 2
  44. #define PCTL_ILP_DIV_EN 0x00000002
  45. #define PCTL_LPO_SEL 0x00000001
  46. /* ILP clock */
  47. #define ILP_CLOCK 32000
  48. /* ALP clock on pre-PMU chips */
  49. #define ALP_CLOCK 20000000
  50. /* pmustatus */
  51. #define PST_EXTLPOAVAIL 0x0100
  52. #define PST_WDRESET 0x0080
  53. #define PST_INTPEND 0x0040
  54. #define PST_SBCLKST 0x0030
  55. #define PST_SBCLKST_ILP 0x0010
  56. #define PST_SBCLKST_ALP 0x0020
  57. #define PST_SBCLKST_HT 0x0030
  58. #define PST_ALPAVAIL 0x0008
  59. #define PST_HTAVAIL 0x0004
  60. #define PST_RESINIT 0x0003
  61. /* PMU resource bit position */
  62. #define PMURES_BIT(bit) (1 << (bit))
  63. /* PMU corerev and chip specific PLL controls.
  64. * PMU<rev>_PLL<num>_XX where <rev> is PMU corerev and <num> is an arbitrary
  65. * number to differentiate different PLLs controlled by the same PMU rev.
  66. */
  67. /* pmu XtalFreqRatio */
  68. #define PMU_XTALFREQ_REG_ILPCTR_MASK 0x00001FFF
  69. #define PMU_XTALFREQ_REG_MEASURE_MASK 0x80000000
  70. #define PMU_XTALFREQ_REG_MEASURE_SHIFT 31
  71. /* 4313 resources */
  72. #define RES4313_BB_PU_RSRC 0
  73. #define RES4313_ILP_REQ_RSRC 1
  74. #define RES4313_XTAL_PU_RSRC 2
  75. #define RES4313_ALP_AVAIL_RSRC 3
  76. #define RES4313_RADIO_PU_RSRC 4
  77. #define RES4313_BG_PU_RSRC 5
  78. #define RES4313_VREG1P4_PU_RSRC 6
  79. #define RES4313_AFE_PWRSW_RSRC 7
  80. #define RES4313_RX_PWRSW_RSRC 8
  81. #define RES4313_TX_PWRSW_RSRC 9
  82. #define RES4313_BB_PWRSW_RSRC 10
  83. #define RES4313_SYNTH_PWRSW_RSRC 11
  84. #define RES4313_MISC_PWRSW_RSRC 12
  85. #define RES4313_BB_PLL_PWRSW_RSRC 13
  86. #define RES4313_HT_AVAIL_RSRC 14
  87. #define RES4313_MACPHY_CLK_AVAIL_RSRC 15
  88. u16 si_pmu_fast_pwrup_delay(struct si_pub *sih)
  89. {
  90. uint delay = PMU_MAX_TRANSITION_DLY;
  91. switch (ai_get_chip_id(sih)) {
  92. case BCMA_CHIP_ID_BCM43224:
  93. case BCMA_CHIP_ID_BCM43225:
  94. case BCMA_CHIP_ID_BCM4313:
  95. delay = 3700;
  96. break;
  97. default:
  98. break;
  99. }
  100. return (u16) delay;
  101. }
  102. u32 si_pmu_measure_alpclk(struct si_pub *sih)
  103. {
  104. struct si_info *sii = container_of(sih, struct si_info, pub);
  105. struct bcma_device *core;
  106. u32 alp_khz;
  107. if (ai_get_pmurev(sih) < 10)
  108. return 0;
  109. /* Remember original core before switch to chipc */
  110. core = sii->icbus->drv_cc.core;
  111. if (bcma_read32(core, CHIPCREGOFFS(pmustatus)) & PST_EXTLPOAVAIL) {
  112. u32 ilp_ctr, alp_hz;
  113. /*
  114. * Enable the reg to measure the freq,
  115. * in case it was disabled before
  116. */
  117. bcma_write32(core, CHIPCREGOFFS(pmu_xtalfreq),
  118. 1U << PMU_XTALFREQ_REG_MEASURE_SHIFT);
  119. /* Delay for well over 4 ILP clocks */
  120. udelay(1000);
  121. /* Read the latched number of ALP ticks per 4 ILP ticks */
  122. ilp_ctr = bcma_read32(core, CHIPCREGOFFS(pmu_xtalfreq)) &
  123. PMU_XTALFREQ_REG_ILPCTR_MASK;
  124. /*
  125. * Turn off the PMU_XTALFREQ_REG_MEASURE_SHIFT
  126. * bit to save power
  127. */
  128. bcma_write32(core, CHIPCREGOFFS(pmu_xtalfreq), 0);
  129. /* Calculate ALP frequency */
  130. alp_hz = (ilp_ctr * EXT_ILP_HZ) / 4;
  131. /*
  132. * Round to nearest 100KHz, and at
  133. * the same time convert to KHz
  134. */
  135. alp_khz = (alp_hz + 50000) / 100000 * 100;
  136. } else
  137. alp_khz = 0;
  138. return alp_khz;
  139. }