driver_chipcommon_pmu.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * Broadcom specific AMBA
  3. * ChipCommon Power Management Unit driver
  4. *
  5. * Copyright 2009, Michael Buesch <m@bues.ch>
  6. * Copyright 2007, Broadcom Corporation
  7. *
  8. * Licensed under the GNU/GPL. See COPYING for details.
  9. */
  10. #include "bcma_private.h"
  11. #include <linux/export.h>
  12. #include <linux/bcma/bcma.h>
  13. static u32 bcma_chipco_pll_read(struct bcma_drv_cc *cc, u32 offset)
  14. {
  15. bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
  16. bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
  17. return bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA);
  18. }
  19. void bcma_chipco_pll_write(struct bcma_drv_cc *cc, u32 offset, u32 value)
  20. {
  21. bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
  22. bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
  23. bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, value);
  24. }
  25. EXPORT_SYMBOL_GPL(bcma_chipco_pll_write);
  26. void bcma_chipco_pll_maskset(struct bcma_drv_cc *cc, u32 offset, u32 mask,
  27. u32 set)
  28. {
  29. bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
  30. bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
  31. bcma_cc_maskset32(cc, BCMA_CC_PLLCTL_DATA, mask, set);
  32. }
  33. EXPORT_SYMBOL_GPL(bcma_chipco_pll_maskset);
  34. void bcma_chipco_chipctl_maskset(struct bcma_drv_cc *cc,
  35. u32 offset, u32 mask, u32 set)
  36. {
  37. bcma_cc_write32(cc, BCMA_CC_CHIPCTL_ADDR, offset);
  38. bcma_cc_read32(cc, BCMA_CC_CHIPCTL_ADDR);
  39. bcma_cc_maskset32(cc, BCMA_CC_CHIPCTL_DATA, mask, set);
  40. }
  41. EXPORT_SYMBOL_GPL(bcma_chipco_chipctl_maskset);
  42. void bcma_chipco_regctl_maskset(struct bcma_drv_cc *cc, u32 offset, u32 mask,
  43. u32 set)
  44. {
  45. bcma_cc_write32(cc, BCMA_CC_REGCTL_ADDR, offset);
  46. bcma_cc_read32(cc, BCMA_CC_REGCTL_ADDR);
  47. bcma_cc_maskset32(cc, BCMA_CC_REGCTL_DATA, mask, set);
  48. }
  49. EXPORT_SYMBOL_GPL(bcma_chipco_regctl_maskset);
  50. static void bcma_pmu_pll_init(struct bcma_drv_cc *cc)
  51. {
  52. struct bcma_bus *bus = cc->core->bus;
  53. switch (bus->chipinfo.id) {
  54. case 0x4313:
  55. case 0x4331:
  56. case 43224:
  57. case 43225:
  58. break;
  59. default:
  60. pr_err("PLL init unknown for device 0x%04X\n",
  61. bus->chipinfo.id);
  62. }
  63. }
  64. static void bcma_pmu_resources_init(struct bcma_drv_cc *cc)
  65. {
  66. struct bcma_bus *bus = cc->core->bus;
  67. u32 min_msk = 0, max_msk = 0;
  68. switch (bus->chipinfo.id) {
  69. case 0x4313:
  70. min_msk = 0x200D;
  71. max_msk = 0xFFFF;
  72. break;
  73. case 0x4331:
  74. case 43224:
  75. case 43225:
  76. break;
  77. default:
  78. pr_err("PMU resource config unknown for device 0x%04X\n",
  79. bus->chipinfo.id);
  80. }
  81. /* Set the resource masks. */
  82. if (min_msk)
  83. bcma_cc_write32(cc, BCMA_CC_PMU_MINRES_MSK, min_msk);
  84. if (max_msk)
  85. bcma_cc_write32(cc, BCMA_CC_PMU_MAXRES_MSK, max_msk);
  86. }
  87. void bcma_pmu_swreg_init(struct bcma_drv_cc *cc)
  88. {
  89. struct bcma_bus *bus = cc->core->bus;
  90. switch (bus->chipinfo.id) {
  91. case 0x4313:
  92. case 0x4331:
  93. case 43224:
  94. case 43225:
  95. break;
  96. default:
  97. pr_err("PMU switch/regulators init unknown for device "
  98. "0x%04X\n", bus->chipinfo.id);
  99. }
  100. }
  101. /* Disable to allow reading SPROM. Don't know the adventages of enabling it. */
  102. void bcma_chipco_bcm4331_ext_pa_lines_ctl(struct bcma_drv_cc *cc, bool enable)
  103. {
  104. struct bcma_bus *bus = cc->core->bus;
  105. u32 val;
  106. val = bcma_cc_read32(cc, BCMA_CC_CHIPCTL);
  107. if (enable) {
  108. val |= BCMA_CHIPCTL_4331_EXTPA_EN;
  109. if (bus->chipinfo.pkg == 9 || bus->chipinfo.pkg == 11)
  110. val |= BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5;
  111. } else {
  112. val &= ~BCMA_CHIPCTL_4331_EXTPA_EN;
  113. val &= ~BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5;
  114. }
  115. bcma_cc_write32(cc, BCMA_CC_CHIPCTL, val);
  116. }
  117. void bcma_pmu_workarounds(struct bcma_drv_cc *cc)
  118. {
  119. struct bcma_bus *bus = cc->core->bus;
  120. switch (bus->chipinfo.id) {
  121. case 0x4313:
  122. bcma_chipco_chipctl_maskset(cc, 0, ~0, 0x7);
  123. break;
  124. case 0x4331:
  125. case 43431:
  126. /* Ext PA lines must be enabled for tx on BCM4331 */
  127. bcma_chipco_bcm4331_ext_pa_lines_ctl(cc, true);
  128. break;
  129. case 43224:
  130. if (bus->chipinfo.rev == 0) {
  131. pr_err("Workarounds for 43224 rev 0 not fully "
  132. "implemented\n");
  133. bcma_chipco_chipctl_maskset(cc, 0, ~0, 0x00F000F0);
  134. } else {
  135. bcma_chipco_chipctl_maskset(cc, 0, ~0, 0xF0);
  136. }
  137. break;
  138. case 43225:
  139. break;
  140. default:
  141. pr_err("Workarounds unknown for device 0x%04X\n",
  142. bus->chipinfo.id);
  143. }
  144. }
  145. void bcma_pmu_init(struct bcma_drv_cc *cc)
  146. {
  147. u32 pmucap;
  148. pmucap = bcma_cc_read32(cc, BCMA_CC_PMU_CAP);
  149. cc->pmu.rev = (pmucap & BCMA_CC_PMU_CAP_REVISION);
  150. pr_debug("Found rev %u PMU (capabilities 0x%08X)\n", cc->pmu.rev,
  151. pmucap);
  152. if (cc->pmu.rev == 1)
  153. bcma_cc_mask32(cc, BCMA_CC_PMU_CTL,
  154. ~BCMA_CC_PMU_CTL_NOILPONW);
  155. else
  156. bcma_cc_set32(cc, BCMA_CC_PMU_CTL,
  157. BCMA_CC_PMU_CTL_NOILPONW);
  158. if (cc->core->id.id == 0x4329 && cc->core->id.rev == 2)
  159. pr_err("Fix for 4329b0 bad LPOM state not implemented!\n");
  160. bcma_pmu_pll_init(cc);
  161. bcma_pmu_resources_init(cc);
  162. bcma_pmu_swreg_init(cc);
  163. bcma_pmu_workarounds(cc);
  164. }
  165. u32 bcma_pmu_alp_clock(struct bcma_drv_cc *cc)
  166. {
  167. struct bcma_bus *bus = cc->core->bus;
  168. switch (bus->chipinfo.id) {
  169. case 0x4716:
  170. case 0x4748:
  171. case 47162:
  172. case 0x4313:
  173. case 0x5357:
  174. case 0x4749:
  175. case 53572:
  176. /* always 20Mhz */
  177. return 20000 * 1000;
  178. case 0x5356:
  179. case 0x5300:
  180. /* always 25Mhz */
  181. return 25000 * 1000;
  182. default:
  183. pr_warn("No ALP clock specified for %04X device, "
  184. "pmu rev. %d, using default %d Hz\n",
  185. bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_ALP_CLOCK);
  186. }
  187. return BCMA_CC_PMU_ALP_CLOCK;
  188. }
  189. /* Find the output of the "m" pll divider given pll controls that start with
  190. * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc.
  191. */
  192. static u32 bcma_pmu_clock(struct bcma_drv_cc *cc, u32 pll0, u32 m)
  193. {
  194. u32 tmp, div, ndiv, p1, p2, fc;
  195. struct bcma_bus *bus = cc->core->bus;
  196. BUG_ON((pll0 & 3) || (pll0 > BCMA_CC_PMU4716_MAINPLL_PLL0));
  197. BUG_ON(!m || m > 4);
  198. if (bus->chipinfo.id == 0x5357 || bus->chipinfo.id == 0x4749) {
  199. /* Detect failure in clock setting */
  200. tmp = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
  201. if (tmp & 0x40000)
  202. return 133 * 1000000;
  203. }
  204. tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_P1P2_OFF);
  205. p1 = (tmp & BCMA_CC_PPL_P1_MASK) >> BCMA_CC_PPL_P1_SHIFT;
  206. p2 = (tmp & BCMA_CC_PPL_P2_MASK) >> BCMA_CC_PPL_P2_SHIFT;
  207. tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_M14_OFF);
  208. div = (tmp >> ((m - 1) * BCMA_CC_PPL_MDIV_WIDTH)) &
  209. BCMA_CC_PPL_MDIV_MASK;
  210. tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_NM5_OFF);
  211. ndiv = (tmp & BCMA_CC_PPL_NDIV_MASK) >> BCMA_CC_PPL_NDIV_SHIFT;
  212. /* Do calculation in Mhz */
  213. fc = bcma_pmu_alp_clock(cc) / 1000000;
  214. fc = (p1 * ndiv * fc) / p2;
  215. /* Return clock in Hertz */
  216. return (fc / div) * 1000000;
  217. }
  218. /* query bus clock frequency for PMU-enabled chipcommon */
  219. u32 bcma_pmu_get_clockcontrol(struct bcma_drv_cc *cc)
  220. {
  221. struct bcma_bus *bus = cc->core->bus;
  222. switch (bus->chipinfo.id) {
  223. case 0x4716:
  224. case 0x4748:
  225. case 47162:
  226. return bcma_pmu_clock(cc, BCMA_CC_PMU4716_MAINPLL_PLL0,
  227. BCMA_CC_PMU5_MAINPLL_SSB);
  228. case 0x5356:
  229. return bcma_pmu_clock(cc, BCMA_CC_PMU5356_MAINPLL_PLL0,
  230. BCMA_CC_PMU5_MAINPLL_SSB);
  231. case 0x5357:
  232. case 0x4749:
  233. return bcma_pmu_clock(cc, BCMA_CC_PMU5357_MAINPLL_PLL0,
  234. BCMA_CC_PMU5_MAINPLL_SSB);
  235. case 0x5300:
  236. return bcma_pmu_clock(cc, BCMA_CC_PMU4706_MAINPLL_PLL0,
  237. BCMA_CC_PMU5_MAINPLL_SSB);
  238. case 53572:
  239. return 75000000;
  240. default:
  241. pr_warn("No backplane clock specified for %04X device, "
  242. "pmu rev. %d, using default %d Hz\n",
  243. bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_HT_CLOCK);
  244. }
  245. return BCMA_CC_PMU_HT_CLOCK;
  246. }
  247. /* query cpu clock frequency for PMU-enabled chipcommon */
  248. u32 bcma_pmu_get_clockcpu(struct bcma_drv_cc *cc)
  249. {
  250. struct bcma_bus *bus = cc->core->bus;
  251. if (bus->chipinfo.id == 53572)
  252. return 300000000;
  253. if (cc->pmu.rev >= 5) {
  254. u32 pll;
  255. switch (bus->chipinfo.id) {
  256. case 0x5356:
  257. pll = BCMA_CC_PMU5356_MAINPLL_PLL0;
  258. break;
  259. case 0x5357:
  260. case 0x4749:
  261. pll = BCMA_CC_PMU5357_MAINPLL_PLL0;
  262. break;
  263. default:
  264. pll = BCMA_CC_PMU4716_MAINPLL_PLL0;
  265. break;
  266. }
  267. /* TODO: if (bus->chipinfo.id == 0x5300)
  268. return si_4706_pmu_clock(sih, osh, cc, PMU4706_MAINPLL_PLL0, PMU5_MAINPLL_CPU); */
  269. return bcma_pmu_clock(cc, pll, BCMA_CC_PMU5_MAINPLL_CPU);
  270. }
  271. return bcma_pmu_get_clockcontrol(cc);
  272. }