driver_chipcommon_pmu.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /*
  2. * Broadcom specific AMBA
  3. * ChipCommon Power Management Unit driver
  4. *
  5. * Copyright 2009, Michael Buesch <m@bues.ch>
  6. * Copyright 2007, 2011, Broadcom Corporation
  7. * Copyright 2011, 2012, Hauke Mehrtens <hauke@hauke-m.de>
  8. *
  9. * Licensed under the GNU/GPL. See COPYING for details.
  10. */
  11. #include "bcma_private.h"
  12. #include <linux/export.h>
  13. #include <linux/bcma/bcma.h>
  14. u32 bcma_chipco_pll_read(struct bcma_drv_cc *cc, u32 offset)
  15. {
  16. bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
  17. bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
  18. return bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA);
  19. }
  20. EXPORT_SYMBOL_GPL(bcma_chipco_pll_read);
  21. void bcma_chipco_pll_write(struct bcma_drv_cc *cc, u32 offset, u32 value)
  22. {
  23. bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
  24. bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
  25. bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, value);
  26. }
  27. EXPORT_SYMBOL_GPL(bcma_chipco_pll_write);
  28. void bcma_chipco_pll_maskset(struct bcma_drv_cc *cc, u32 offset, u32 mask,
  29. u32 set)
  30. {
  31. bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
  32. bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
  33. bcma_cc_maskset32(cc, BCMA_CC_PLLCTL_DATA, mask, set);
  34. }
  35. EXPORT_SYMBOL_GPL(bcma_chipco_pll_maskset);
  36. void bcma_chipco_chipctl_maskset(struct bcma_drv_cc *cc,
  37. u32 offset, u32 mask, u32 set)
  38. {
  39. bcma_cc_write32(cc, BCMA_CC_CHIPCTL_ADDR, offset);
  40. bcma_cc_read32(cc, BCMA_CC_CHIPCTL_ADDR);
  41. bcma_cc_maskset32(cc, BCMA_CC_CHIPCTL_DATA, mask, set);
  42. }
  43. EXPORT_SYMBOL_GPL(bcma_chipco_chipctl_maskset);
  44. void bcma_chipco_regctl_maskset(struct bcma_drv_cc *cc, u32 offset, u32 mask,
  45. u32 set)
  46. {
  47. bcma_cc_write32(cc, BCMA_CC_REGCTL_ADDR, offset);
  48. bcma_cc_read32(cc, BCMA_CC_REGCTL_ADDR);
  49. bcma_cc_maskset32(cc, BCMA_CC_REGCTL_DATA, mask, set);
  50. }
  51. EXPORT_SYMBOL_GPL(bcma_chipco_regctl_maskset);
  52. static u32 bcma_pmu_xtalfreq(struct bcma_drv_cc *cc)
  53. {
  54. u32 ilp_ctl, alp_hz;
  55. if (!(bcma_cc_read32(cc, BCMA_CC_PMU_STAT) &
  56. BCMA_CC_PMU_STAT_EXT_LPO_AVAIL))
  57. return 0;
  58. bcma_cc_write32(cc, BCMA_CC_PMU_XTAL_FREQ,
  59. BIT(BCMA_CC_PMU_XTAL_FREQ_MEASURE_SHIFT));
  60. usleep_range(1000, 2000);
  61. ilp_ctl = bcma_cc_read32(cc, BCMA_CC_PMU_XTAL_FREQ);
  62. ilp_ctl &= BCMA_CC_PMU_XTAL_FREQ_ILPCTL_MASK;
  63. bcma_cc_write32(cc, BCMA_CC_PMU_XTAL_FREQ, 0);
  64. alp_hz = ilp_ctl * 32768 / 4;
  65. return (alp_hz + 50000) / 100000 * 100;
  66. }
  67. static void bcma_pmu2_pll_init0(struct bcma_drv_cc *cc, u32 xtalfreq)
  68. {
  69. struct bcma_bus *bus = cc->core->bus;
  70. u32 freq_tgt_target = 0, freq_tgt_current;
  71. u32 pll0, mask;
  72. switch (bus->chipinfo.id) {
  73. case BCMA_CHIP_ID_BCM43142:
  74. /* pmu2_xtaltab0_adfll_485 */
  75. switch (xtalfreq) {
  76. case 12000:
  77. freq_tgt_target = 0x50D52;
  78. break;
  79. case 20000:
  80. freq_tgt_target = 0x307FE;
  81. break;
  82. case 26000:
  83. freq_tgt_target = 0x254EA;
  84. break;
  85. case 37400:
  86. freq_tgt_target = 0x19EF8;
  87. break;
  88. case 52000:
  89. freq_tgt_target = 0x12A75;
  90. break;
  91. }
  92. break;
  93. }
  94. if (!freq_tgt_target) {
  95. bcma_err(bus, "Unknown TGT frequency for xtalfreq %d\n",
  96. xtalfreq);
  97. return;
  98. }
  99. pll0 = bcma_chipco_pll_read(cc, BCMA_CC_PMU15_PLL_PLLCTL0);
  100. freq_tgt_current = (pll0 & BCMA_CC_PMU15_PLL_PC0_FREQTGT_MASK) >>
  101. BCMA_CC_PMU15_PLL_PC0_FREQTGT_SHIFT;
  102. if (freq_tgt_current == freq_tgt_target) {
  103. bcma_debug(bus, "Target TGT frequency already set\n");
  104. return;
  105. }
  106. /* Turn off PLL */
  107. switch (bus->chipinfo.id) {
  108. case BCMA_CHIP_ID_BCM43142:
  109. mask = (u32)~(BCMA_RES_4314_HT_AVAIL |
  110. BCMA_RES_4314_MACPHY_CLK_AVAIL);
  111. bcma_cc_mask32(cc, BCMA_CC_PMU_MINRES_MSK, mask);
  112. bcma_cc_mask32(cc, BCMA_CC_PMU_MAXRES_MSK, mask);
  113. bcma_wait_value(cc->core, BCMA_CLKCTLST,
  114. BCMA_CLKCTLST_HAVEHT, 0, 20000);
  115. break;
  116. }
  117. pll0 &= ~BCMA_CC_PMU15_PLL_PC0_FREQTGT_MASK;
  118. pll0 |= freq_tgt_target << BCMA_CC_PMU15_PLL_PC0_FREQTGT_SHIFT;
  119. bcma_chipco_pll_write(cc, BCMA_CC_PMU15_PLL_PLLCTL0, pll0);
  120. /* Flush */
  121. if (cc->pmu.rev >= 2)
  122. bcma_cc_set32(cc, BCMA_CC_PMU_CTL, BCMA_CC_PMU_CTL_PLL_UPD);
  123. /* TODO: Do we need to update OTP? */
  124. }
  125. static void bcma_pmu_pll_init(struct bcma_drv_cc *cc)
  126. {
  127. struct bcma_bus *bus = cc->core->bus;
  128. u32 xtalfreq = bcma_pmu_xtalfreq(cc);
  129. switch (bus->chipinfo.id) {
  130. case BCMA_CHIP_ID_BCM43142:
  131. if (xtalfreq == 0)
  132. xtalfreq = 20000;
  133. bcma_pmu2_pll_init0(cc, xtalfreq);
  134. break;
  135. }
  136. }
  137. static void bcma_pmu_resources_init(struct bcma_drv_cc *cc)
  138. {
  139. struct bcma_bus *bus = cc->core->bus;
  140. u32 min_msk = 0, max_msk = 0;
  141. switch (bus->chipinfo.id) {
  142. case BCMA_CHIP_ID_BCM4313:
  143. min_msk = 0x200D;
  144. max_msk = 0xFFFF;
  145. break;
  146. case BCMA_CHIP_ID_BCM43142:
  147. min_msk = BCMA_RES_4314_LPLDO_PU |
  148. BCMA_RES_4314_PMU_SLEEP_DIS |
  149. BCMA_RES_4314_PMU_BG_PU |
  150. BCMA_RES_4314_CBUCK_LPOM_PU |
  151. BCMA_RES_4314_CBUCK_PFM_PU |
  152. BCMA_RES_4314_CLDO_PU |
  153. BCMA_RES_4314_LPLDO2_LVM |
  154. BCMA_RES_4314_WL_PMU_PU |
  155. BCMA_RES_4314_LDO3P3_PU |
  156. BCMA_RES_4314_OTP_PU |
  157. BCMA_RES_4314_WL_PWRSW_PU |
  158. BCMA_RES_4314_LQ_AVAIL |
  159. BCMA_RES_4314_LOGIC_RET |
  160. BCMA_RES_4314_MEM_SLEEP |
  161. BCMA_RES_4314_MACPHY_RET |
  162. BCMA_RES_4314_WL_CORE_READY;
  163. max_msk = 0x3FFFFFFF;
  164. break;
  165. default:
  166. bcma_debug(bus, "PMU resource config unknown or not needed for device 0x%04X\n",
  167. bus->chipinfo.id);
  168. }
  169. /* Set the resource masks. */
  170. if (min_msk)
  171. bcma_cc_write32(cc, BCMA_CC_PMU_MINRES_MSK, min_msk);
  172. if (max_msk)
  173. bcma_cc_write32(cc, BCMA_CC_PMU_MAXRES_MSK, max_msk);
  174. /*
  175. * Add some delay; allow resources to come up and settle.
  176. * Delay is required for SoC (early init).
  177. */
  178. mdelay(2);
  179. }
  180. /* Disable to allow reading SPROM. Don't know the adventages of enabling it. */
  181. void bcma_chipco_bcm4331_ext_pa_lines_ctl(struct bcma_drv_cc *cc, bool enable)
  182. {
  183. struct bcma_bus *bus = cc->core->bus;
  184. u32 val;
  185. val = bcma_cc_read32(cc, BCMA_CC_CHIPCTL);
  186. if (enable) {
  187. val |= BCMA_CHIPCTL_4331_EXTPA_EN;
  188. if (bus->chipinfo.pkg == 9 || bus->chipinfo.pkg == 11)
  189. val |= BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5;
  190. else if (bus->chipinfo.rev > 0)
  191. val |= BCMA_CHIPCTL_4331_EXTPA_EN2;
  192. } else {
  193. val &= ~BCMA_CHIPCTL_4331_EXTPA_EN;
  194. val &= ~BCMA_CHIPCTL_4331_EXTPA_EN2;
  195. val &= ~BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5;
  196. }
  197. bcma_cc_write32(cc, BCMA_CC_CHIPCTL, val);
  198. }
  199. static void bcma_pmu_workarounds(struct bcma_drv_cc *cc)
  200. {
  201. struct bcma_bus *bus = cc->core->bus;
  202. switch (bus->chipinfo.id) {
  203. case BCMA_CHIP_ID_BCM4313:
  204. /* enable 12 mA drive strenth for 4313 and set chipControl
  205. register bit 1 */
  206. bcma_chipco_chipctl_maskset(cc, 0,
  207. ~BCMA_CCTRL_4313_12MA_LED_DRIVE,
  208. BCMA_CCTRL_4313_12MA_LED_DRIVE);
  209. break;
  210. case BCMA_CHIP_ID_BCM4331:
  211. case BCMA_CHIP_ID_BCM43431:
  212. /* Ext PA lines must be enabled for tx on BCM4331 */
  213. bcma_chipco_bcm4331_ext_pa_lines_ctl(cc, true);
  214. break;
  215. case BCMA_CHIP_ID_BCM43224:
  216. case BCMA_CHIP_ID_BCM43421:
  217. /* enable 12 mA drive strenth for 43224 and set chipControl
  218. register bit 15 */
  219. if (bus->chipinfo.rev == 0) {
  220. bcma_cc_maskset32(cc, BCMA_CC_CHIPCTL,
  221. ~BCMA_CCTRL_43224_GPIO_TOGGLE,
  222. BCMA_CCTRL_43224_GPIO_TOGGLE);
  223. bcma_chipco_chipctl_maskset(cc, 0,
  224. ~BCMA_CCTRL_43224A0_12MA_LED_DRIVE,
  225. BCMA_CCTRL_43224A0_12MA_LED_DRIVE);
  226. } else {
  227. bcma_chipco_chipctl_maskset(cc, 0,
  228. ~BCMA_CCTRL_43224B0_12MA_LED_DRIVE,
  229. BCMA_CCTRL_43224B0_12MA_LED_DRIVE);
  230. }
  231. break;
  232. default:
  233. bcma_debug(bus, "Workarounds unknown or not needed for device 0x%04X\n",
  234. bus->chipinfo.id);
  235. }
  236. }
  237. void bcma_pmu_early_init(struct bcma_drv_cc *cc)
  238. {
  239. u32 pmucap;
  240. pmucap = bcma_cc_read32(cc, BCMA_CC_PMU_CAP);
  241. cc->pmu.rev = (pmucap & BCMA_CC_PMU_CAP_REVISION);
  242. bcma_debug(cc->core->bus, "Found rev %u PMU (capabilities 0x%08X)\n",
  243. cc->pmu.rev, pmucap);
  244. }
  245. void bcma_pmu_init(struct bcma_drv_cc *cc)
  246. {
  247. if (cc->pmu.rev == 1)
  248. bcma_cc_mask32(cc, BCMA_CC_PMU_CTL,
  249. ~BCMA_CC_PMU_CTL_NOILPONW);
  250. else
  251. bcma_cc_set32(cc, BCMA_CC_PMU_CTL,
  252. BCMA_CC_PMU_CTL_NOILPONW);
  253. bcma_pmu_pll_init(cc);
  254. bcma_pmu_resources_init(cc);
  255. bcma_pmu_workarounds(cc);
  256. }
  257. u32 bcma_pmu_get_alp_clock(struct bcma_drv_cc *cc)
  258. {
  259. struct bcma_bus *bus = cc->core->bus;
  260. switch (bus->chipinfo.id) {
  261. case BCMA_CHIP_ID_BCM4313:
  262. case BCMA_CHIP_ID_BCM43224:
  263. case BCMA_CHIP_ID_BCM43225:
  264. case BCMA_CHIP_ID_BCM43227:
  265. case BCMA_CHIP_ID_BCM43228:
  266. case BCMA_CHIP_ID_BCM4331:
  267. case BCMA_CHIP_ID_BCM43421:
  268. case BCMA_CHIP_ID_BCM43428:
  269. case BCMA_CHIP_ID_BCM43431:
  270. case BCMA_CHIP_ID_BCM4716:
  271. case BCMA_CHIP_ID_BCM47162:
  272. case BCMA_CHIP_ID_BCM4748:
  273. case BCMA_CHIP_ID_BCM4749:
  274. case BCMA_CHIP_ID_BCM5357:
  275. case BCMA_CHIP_ID_BCM53572:
  276. case BCMA_CHIP_ID_BCM6362:
  277. /* always 20Mhz */
  278. return 20000 * 1000;
  279. case BCMA_CHIP_ID_BCM4706:
  280. case BCMA_CHIP_ID_BCM5356:
  281. /* always 25Mhz */
  282. return 25000 * 1000;
  283. case BCMA_CHIP_ID_BCM43460:
  284. case BCMA_CHIP_ID_BCM4352:
  285. case BCMA_CHIP_ID_BCM4360:
  286. if (cc->status & BCMA_CC_CHIPST_4360_XTAL_40MZ)
  287. return 40000 * 1000;
  288. else
  289. return 20000 * 1000;
  290. default:
  291. bcma_warn(bus, "No ALP clock specified for %04X device, pmu rev. %d, using default %d Hz\n",
  292. bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_ALP_CLOCK);
  293. }
  294. return BCMA_CC_PMU_ALP_CLOCK;
  295. }
  296. /* Find the output of the "m" pll divider given pll controls that start with
  297. * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc.
  298. */
  299. static u32 bcma_pmu_pll_clock(struct bcma_drv_cc *cc, u32 pll0, u32 m)
  300. {
  301. u32 tmp, div, ndiv, p1, p2, fc;
  302. struct bcma_bus *bus = cc->core->bus;
  303. BUG_ON((pll0 & 3) || (pll0 > BCMA_CC_PMU4716_MAINPLL_PLL0));
  304. BUG_ON(!m || m > 4);
  305. if (bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
  306. bus->chipinfo.id == BCMA_CHIP_ID_BCM4749) {
  307. /* Detect failure in clock setting */
  308. tmp = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
  309. if (tmp & 0x40000)
  310. return 133 * 1000000;
  311. }
  312. tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_P1P2_OFF);
  313. p1 = (tmp & BCMA_CC_PPL_P1_MASK) >> BCMA_CC_PPL_P1_SHIFT;
  314. p2 = (tmp & BCMA_CC_PPL_P2_MASK) >> BCMA_CC_PPL_P2_SHIFT;
  315. tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_M14_OFF);
  316. div = (tmp >> ((m - 1) * BCMA_CC_PPL_MDIV_WIDTH)) &
  317. BCMA_CC_PPL_MDIV_MASK;
  318. tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_NM5_OFF);
  319. ndiv = (tmp & BCMA_CC_PPL_NDIV_MASK) >> BCMA_CC_PPL_NDIV_SHIFT;
  320. /* Do calculation in Mhz */
  321. fc = bcma_pmu_get_alp_clock(cc) / 1000000;
  322. fc = (p1 * ndiv * fc) / p2;
  323. /* Return clock in Hertz */
  324. return (fc / div) * 1000000;
  325. }
  326. static u32 bcma_pmu_pll_clock_bcm4706(struct bcma_drv_cc *cc, u32 pll0, u32 m)
  327. {
  328. u32 tmp, ndiv, p1div, p2div;
  329. u32 clock;
  330. BUG_ON(!m || m > 4);
  331. /* Get N, P1 and P2 dividers to determine CPU clock */
  332. tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PMU6_4706_PROCPLL_OFF);
  333. ndiv = (tmp & BCMA_CC_PMU6_4706_PROC_NDIV_INT_MASK)
  334. >> BCMA_CC_PMU6_4706_PROC_NDIV_INT_SHIFT;
  335. p1div = (tmp & BCMA_CC_PMU6_4706_PROC_P1DIV_MASK)
  336. >> BCMA_CC_PMU6_4706_PROC_P1DIV_SHIFT;
  337. p2div = (tmp & BCMA_CC_PMU6_4706_PROC_P2DIV_MASK)
  338. >> BCMA_CC_PMU6_4706_PROC_P2DIV_SHIFT;
  339. tmp = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
  340. if (tmp & BCMA_CC_CHIPST_4706_PKG_OPTION)
  341. /* Low cost bonding: Fixed reference clock 25MHz and m = 4 */
  342. clock = (25000000 / 4) * ndiv * p2div / p1div;
  343. else
  344. /* Fixed reference clock 25MHz and m = 2 */
  345. clock = (25000000 / 2) * ndiv * p2div / p1div;
  346. if (m == BCMA_CC_PMU5_MAINPLL_SSB)
  347. clock = clock / 4;
  348. return clock;
  349. }
  350. /* query bus clock frequency for PMU-enabled chipcommon */
  351. u32 bcma_pmu_get_bus_clock(struct bcma_drv_cc *cc)
  352. {
  353. struct bcma_bus *bus = cc->core->bus;
  354. switch (bus->chipinfo.id) {
  355. case BCMA_CHIP_ID_BCM4716:
  356. case BCMA_CHIP_ID_BCM4748:
  357. case BCMA_CHIP_ID_BCM47162:
  358. return bcma_pmu_pll_clock(cc, BCMA_CC_PMU4716_MAINPLL_PLL0,
  359. BCMA_CC_PMU5_MAINPLL_SSB);
  360. case BCMA_CHIP_ID_BCM5356:
  361. return bcma_pmu_pll_clock(cc, BCMA_CC_PMU5356_MAINPLL_PLL0,
  362. BCMA_CC_PMU5_MAINPLL_SSB);
  363. case BCMA_CHIP_ID_BCM5357:
  364. case BCMA_CHIP_ID_BCM4749:
  365. return bcma_pmu_pll_clock(cc, BCMA_CC_PMU5357_MAINPLL_PLL0,
  366. BCMA_CC_PMU5_MAINPLL_SSB);
  367. case BCMA_CHIP_ID_BCM4706:
  368. return bcma_pmu_pll_clock_bcm4706(cc,
  369. BCMA_CC_PMU4706_MAINPLL_PLL0,
  370. BCMA_CC_PMU5_MAINPLL_SSB);
  371. case BCMA_CHIP_ID_BCM53572:
  372. return 75000000;
  373. default:
  374. bcma_warn(bus, "No bus clock specified for %04X device, pmu rev. %d, using default %d Hz\n",
  375. bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_HT_CLOCK);
  376. }
  377. return BCMA_CC_PMU_HT_CLOCK;
  378. }
  379. EXPORT_SYMBOL_GPL(bcma_pmu_get_bus_clock);
  380. /* query cpu clock frequency for PMU-enabled chipcommon */
  381. u32 bcma_pmu_get_cpu_clock(struct bcma_drv_cc *cc)
  382. {
  383. struct bcma_bus *bus = cc->core->bus;
  384. if (bus->chipinfo.id == BCMA_CHIP_ID_BCM53572)
  385. return 300000000;
  386. /* New PMUs can have different clock for bus and CPU */
  387. if (cc->pmu.rev >= 5) {
  388. u32 pll;
  389. switch (bus->chipinfo.id) {
  390. case BCMA_CHIP_ID_BCM4706:
  391. return bcma_pmu_pll_clock_bcm4706(cc,
  392. BCMA_CC_PMU4706_MAINPLL_PLL0,
  393. BCMA_CC_PMU5_MAINPLL_CPU);
  394. case BCMA_CHIP_ID_BCM5356:
  395. pll = BCMA_CC_PMU5356_MAINPLL_PLL0;
  396. break;
  397. case BCMA_CHIP_ID_BCM5357:
  398. case BCMA_CHIP_ID_BCM4749:
  399. pll = BCMA_CC_PMU5357_MAINPLL_PLL0;
  400. break;
  401. default:
  402. pll = BCMA_CC_PMU4716_MAINPLL_PLL0;
  403. break;
  404. }
  405. return bcma_pmu_pll_clock(cc, pll, BCMA_CC_PMU5_MAINPLL_CPU);
  406. }
  407. /* On old PMUs CPU has the same clock as the bus */
  408. return bcma_pmu_get_bus_clock(cc);
  409. }
  410. static void bcma_pmu_spuravoid_pll_write(struct bcma_drv_cc *cc, u32 offset,
  411. u32 value)
  412. {
  413. bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
  414. bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, value);
  415. }
  416. void bcma_pmu_spuravoid_pllupdate(struct bcma_drv_cc *cc, int spuravoid)
  417. {
  418. u32 tmp = 0;
  419. u8 phypll_offset = 0;
  420. u8 bcm5357_bcm43236_p1div[] = {0x1, 0x5, 0x5};
  421. u8 bcm5357_bcm43236_ndiv[] = {0x30, 0xf6, 0xfc};
  422. struct bcma_bus *bus = cc->core->bus;
  423. switch (bus->chipinfo.id) {
  424. case BCMA_CHIP_ID_BCM5357:
  425. case BCMA_CHIP_ID_BCM4749:
  426. case BCMA_CHIP_ID_BCM53572:
  427. /* 5357[ab]0, 43236[ab]0, and 6362b0 */
  428. /* BCM5357 needs to touch PLL1_PLLCTL[02],
  429. so offset PLL0_PLLCTL[02] by 6 */
  430. phypll_offset = (bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
  431. bus->chipinfo.id == BCMA_CHIP_ID_BCM4749 ||
  432. bus->chipinfo.id == BCMA_CHIP_ID_BCM53572) ? 6 : 0;
  433. /* RMW only the P1 divider */
  434. bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR,
  435. BCMA_CC_PMU_PLL_CTL0 + phypll_offset);
  436. tmp = bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA);
  437. tmp &= (~(BCMA_CC_PMU1_PLL0_PC0_P1DIV_MASK));
  438. tmp |= (bcm5357_bcm43236_p1div[spuravoid] << BCMA_CC_PMU1_PLL0_PC0_P1DIV_SHIFT);
  439. bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, tmp);
  440. /* RMW only the int feedback divider */
  441. bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR,
  442. BCMA_CC_PMU_PLL_CTL2 + phypll_offset);
  443. tmp = bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA);
  444. tmp &= ~(BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_MASK);
  445. tmp |= (bcm5357_bcm43236_ndiv[spuravoid]) << BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_SHIFT;
  446. bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, tmp);
  447. tmp = BCMA_CC_PMU_CTL_PLL_UPD;
  448. break;
  449. case BCMA_CHIP_ID_BCM4331:
  450. case BCMA_CHIP_ID_BCM43431:
  451. if (spuravoid == 2) {
  452. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  453. 0x11500014);
  454. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  455. 0x0FC00a08);
  456. } else if (spuravoid == 1) {
  457. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  458. 0x11500014);
  459. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  460. 0x0F600a08);
  461. } else {
  462. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  463. 0x11100014);
  464. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  465. 0x03000a08);
  466. }
  467. tmp = BCMA_CC_PMU_CTL_PLL_UPD;
  468. break;
  469. case BCMA_CHIP_ID_BCM43224:
  470. case BCMA_CHIP_ID_BCM43225:
  471. case BCMA_CHIP_ID_BCM43421:
  472. if (spuravoid == 1) {
  473. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  474. 0x11500010);
  475. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
  476. 0x000C0C06);
  477. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  478. 0x0F600a08);
  479. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
  480. 0x00000000);
  481. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
  482. 0x2001E920);
  483. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
  484. 0x88888815);
  485. } else {
  486. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  487. 0x11100010);
  488. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
  489. 0x000c0c06);
  490. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  491. 0x03000a08);
  492. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
  493. 0x00000000);
  494. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
  495. 0x200005c0);
  496. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
  497. 0x88888815);
  498. }
  499. tmp = BCMA_CC_PMU_CTL_PLL_UPD;
  500. break;
  501. case BCMA_CHIP_ID_BCM4716:
  502. case BCMA_CHIP_ID_BCM4748:
  503. case BCMA_CHIP_ID_BCM47162:
  504. if (spuravoid == 1) {
  505. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  506. 0x11500060);
  507. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
  508. 0x080C0C06);
  509. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  510. 0x0F600000);
  511. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
  512. 0x00000000);
  513. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
  514. 0x2001E924);
  515. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
  516. 0x88888815);
  517. } else {
  518. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  519. 0x11100060);
  520. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
  521. 0x080c0c06);
  522. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  523. 0x03000000);
  524. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
  525. 0x00000000);
  526. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
  527. 0x200005c0);
  528. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
  529. 0x88888815);
  530. }
  531. tmp = BCMA_CC_PMU_CTL_PLL_UPD | BCMA_CC_PMU_CTL_NOILPONW;
  532. break;
  533. case BCMA_CHIP_ID_BCM43131:
  534. case BCMA_CHIP_ID_BCM43217:
  535. case BCMA_CHIP_ID_BCM43227:
  536. case BCMA_CHIP_ID_BCM43228:
  537. case BCMA_CHIP_ID_BCM43428:
  538. /* LCNXN */
  539. /* PLL Settings for spur avoidance on/off mode,
  540. no on2 support for 43228A0 */
  541. if (spuravoid == 1) {
  542. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  543. 0x01100014);
  544. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
  545. 0x040C0C06);
  546. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  547. 0x03140A08);
  548. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
  549. 0x00333333);
  550. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
  551. 0x202C2820);
  552. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
  553. 0x88888815);
  554. } else {
  555. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  556. 0x11100014);
  557. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
  558. 0x040c0c06);
  559. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  560. 0x03000a08);
  561. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
  562. 0x00000000);
  563. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
  564. 0x200005c0);
  565. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
  566. 0x88888815);
  567. }
  568. tmp = BCMA_CC_PMU_CTL_PLL_UPD;
  569. break;
  570. default:
  571. bcma_err(bus, "Unknown spuravoidance settings for chip 0x%04X, not changing PLL\n",
  572. bus->chipinfo.id);
  573. break;
  574. }
  575. tmp |= bcma_cc_read32(cc, BCMA_CC_PMU_CTL);
  576. bcma_cc_write32(cc, BCMA_CC_PMU_CTL, tmp);
  577. }
  578. EXPORT_SYMBOL_GPL(bcma_pmu_spuravoid_pllupdate);