driver_chipcommon_pmu.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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_pmu_write32(cc, BCMA_CC_PMU_PLLCTL_ADDR, offset);
  17. bcma_pmu_read32(cc, BCMA_CC_PMU_PLLCTL_ADDR);
  18. return bcma_pmu_read32(cc, BCMA_CC_PMU_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_pmu_write32(cc, BCMA_CC_PMU_PLLCTL_ADDR, offset);
  24. bcma_pmu_read32(cc, BCMA_CC_PMU_PLLCTL_ADDR);
  25. bcma_pmu_write32(cc, BCMA_CC_PMU_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_pmu_write32(cc, BCMA_CC_PMU_PLLCTL_ADDR, offset);
  32. bcma_pmu_read32(cc, BCMA_CC_PMU_PLLCTL_ADDR);
  33. bcma_pmu_maskset32(cc, BCMA_CC_PMU_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_pmu_write32(cc, BCMA_CC_PMU_CHIPCTL_ADDR, offset);
  40. bcma_pmu_read32(cc, BCMA_CC_PMU_CHIPCTL_ADDR);
  41. bcma_pmu_maskset32(cc, BCMA_CC_PMU_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_pmu_write32(cc, BCMA_CC_PMU_REGCTL_ADDR, offset);
  48. bcma_pmu_read32(cc, BCMA_CC_PMU_REGCTL_ADDR);
  49. bcma_pmu_maskset32(cc, BCMA_CC_PMU_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_pmu_read32(cc, BCMA_CC_PMU_STAT) &
  56. BCMA_CC_PMU_STAT_EXT_LPO_AVAIL))
  57. return 0;
  58. bcma_pmu_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_pmu_read32(cc, BCMA_CC_PMU_XTAL_FREQ);
  62. ilp_ctl &= BCMA_CC_PMU_XTAL_FREQ_ILPCTL_MASK;
  63. bcma_pmu_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_pmu_mask32(cc, BCMA_CC_PMU_MINRES_MSK, mask);
  112. bcma_pmu_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_pmu_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_pmu_write32(cc, BCMA_CC_PMU_MINRES_MSK, min_msk);
  172. if (max_msk)
  173. bcma_pmu_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. struct bcma_bus *bus = cc->core->bus;
  240. u32 pmucap;
  241. if (cc->core->id.rev >= 35 &&
  242. cc->capabilities_ext & BCMA_CC_CAP_EXT_AOB_PRESENT) {
  243. cc->pmu.core = bcma_find_core(bus, BCMA_CORE_PMU);
  244. if (!cc->pmu.core)
  245. bcma_warn(bus, "Couldn't find expected PMU core");
  246. }
  247. if (!cc->pmu.core)
  248. cc->pmu.core = cc->core;
  249. pmucap = bcma_pmu_read32(cc, BCMA_CC_PMU_CAP);
  250. cc->pmu.rev = (pmucap & BCMA_CC_PMU_CAP_REVISION);
  251. bcma_debug(bus, "Found rev %u PMU (capabilities 0x%08X)\n", cc->pmu.rev,
  252. pmucap);
  253. }
  254. void bcma_pmu_init(struct bcma_drv_cc *cc)
  255. {
  256. if (cc->pmu.rev == 1)
  257. bcma_pmu_mask32(cc, BCMA_CC_PMU_CTL,
  258. ~BCMA_CC_PMU_CTL_NOILPONW);
  259. else
  260. bcma_pmu_set32(cc, BCMA_CC_PMU_CTL,
  261. BCMA_CC_PMU_CTL_NOILPONW);
  262. bcma_pmu_pll_init(cc);
  263. bcma_pmu_resources_init(cc);
  264. bcma_pmu_workarounds(cc);
  265. }
  266. u32 bcma_pmu_get_alp_clock(struct bcma_drv_cc *cc)
  267. {
  268. struct bcma_bus *bus = cc->core->bus;
  269. switch (bus->chipinfo.id) {
  270. case BCMA_CHIP_ID_BCM4313:
  271. case BCMA_CHIP_ID_BCM43224:
  272. case BCMA_CHIP_ID_BCM43225:
  273. case BCMA_CHIP_ID_BCM43227:
  274. case BCMA_CHIP_ID_BCM43228:
  275. case BCMA_CHIP_ID_BCM4331:
  276. case BCMA_CHIP_ID_BCM43421:
  277. case BCMA_CHIP_ID_BCM43428:
  278. case BCMA_CHIP_ID_BCM43431:
  279. case BCMA_CHIP_ID_BCM4716:
  280. case BCMA_CHIP_ID_BCM47162:
  281. case BCMA_CHIP_ID_BCM4748:
  282. case BCMA_CHIP_ID_BCM4749:
  283. case BCMA_CHIP_ID_BCM5357:
  284. case BCMA_CHIP_ID_BCM53572:
  285. case BCMA_CHIP_ID_BCM6362:
  286. /* always 20Mhz */
  287. return 20000 * 1000;
  288. case BCMA_CHIP_ID_BCM4706:
  289. case BCMA_CHIP_ID_BCM5356:
  290. /* always 25Mhz */
  291. return 25000 * 1000;
  292. case BCMA_CHIP_ID_BCM43460:
  293. case BCMA_CHIP_ID_BCM4352:
  294. case BCMA_CHIP_ID_BCM4360:
  295. if (cc->status & BCMA_CC_CHIPST_4360_XTAL_40MZ)
  296. return 40000 * 1000;
  297. else
  298. return 20000 * 1000;
  299. default:
  300. bcma_warn(bus, "No ALP clock specified for %04X device, pmu rev. %d, using default %d Hz\n",
  301. bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_ALP_CLOCK);
  302. }
  303. return BCMA_CC_PMU_ALP_CLOCK;
  304. }
  305. /* Find the output of the "m" pll divider given pll controls that start with
  306. * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc.
  307. */
  308. static u32 bcma_pmu_pll_clock(struct bcma_drv_cc *cc, u32 pll0, u32 m)
  309. {
  310. u32 tmp, div, ndiv, p1, p2, fc;
  311. struct bcma_bus *bus = cc->core->bus;
  312. BUG_ON((pll0 & 3) || (pll0 > BCMA_CC_PMU4716_MAINPLL_PLL0));
  313. BUG_ON(!m || m > 4);
  314. if (bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
  315. bus->chipinfo.id == BCMA_CHIP_ID_BCM4749) {
  316. /* Detect failure in clock setting */
  317. tmp = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
  318. if (tmp & 0x40000)
  319. return 133 * 1000000;
  320. }
  321. tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_P1P2_OFF);
  322. p1 = (tmp & BCMA_CC_PPL_P1_MASK) >> BCMA_CC_PPL_P1_SHIFT;
  323. p2 = (tmp & BCMA_CC_PPL_P2_MASK) >> BCMA_CC_PPL_P2_SHIFT;
  324. tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_M14_OFF);
  325. div = (tmp >> ((m - 1) * BCMA_CC_PPL_MDIV_WIDTH)) &
  326. BCMA_CC_PPL_MDIV_MASK;
  327. tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_NM5_OFF);
  328. ndiv = (tmp & BCMA_CC_PPL_NDIV_MASK) >> BCMA_CC_PPL_NDIV_SHIFT;
  329. /* Do calculation in Mhz */
  330. fc = bcma_pmu_get_alp_clock(cc) / 1000000;
  331. fc = (p1 * ndiv * fc) / p2;
  332. /* Return clock in Hertz */
  333. return (fc / div) * 1000000;
  334. }
  335. static u32 bcma_pmu_pll_clock_bcm4706(struct bcma_drv_cc *cc, u32 pll0, u32 m)
  336. {
  337. u32 tmp, ndiv, p1div, p2div;
  338. u32 clock;
  339. BUG_ON(!m || m > 4);
  340. /* Get N, P1 and P2 dividers to determine CPU clock */
  341. tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PMU6_4706_PROCPLL_OFF);
  342. ndiv = (tmp & BCMA_CC_PMU6_4706_PROC_NDIV_INT_MASK)
  343. >> BCMA_CC_PMU6_4706_PROC_NDIV_INT_SHIFT;
  344. p1div = (tmp & BCMA_CC_PMU6_4706_PROC_P1DIV_MASK)
  345. >> BCMA_CC_PMU6_4706_PROC_P1DIV_SHIFT;
  346. p2div = (tmp & BCMA_CC_PMU6_4706_PROC_P2DIV_MASK)
  347. >> BCMA_CC_PMU6_4706_PROC_P2DIV_SHIFT;
  348. tmp = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
  349. if (tmp & BCMA_CC_CHIPST_4706_PKG_OPTION)
  350. /* Low cost bonding: Fixed reference clock 25MHz and m = 4 */
  351. clock = (25000000 / 4) * ndiv * p2div / p1div;
  352. else
  353. /* Fixed reference clock 25MHz and m = 2 */
  354. clock = (25000000 / 2) * ndiv * p2div / p1div;
  355. if (m == BCMA_CC_PMU5_MAINPLL_SSB)
  356. clock = clock / 4;
  357. return clock;
  358. }
  359. /* query bus clock frequency for PMU-enabled chipcommon */
  360. u32 bcma_pmu_get_bus_clock(struct bcma_drv_cc *cc)
  361. {
  362. struct bcma_bus *bus = cc->core->bus;
  363. switch (bus->chipinfo.id) {
  364. case BCMA_CHIP_ID_BCM4716:
  365. case BCMA_CHIP_ID_BCM4748:
  366. case BCMA_CHIP_ID_BCM47162:
  367. return bcma_pmu_pll_clock(cc, BCMA_CC_PMU4716_MAINPLL_PLL0,
  368. BCMA_CC_PMU5_MAINPLL_SSB);
  369. case BCMA_CHIP_ID_BCM5356:
  370. return bcma_pmu_pll_clock(cc, BCMA_CC_PMU5356_MAINPLL_PLL0,
  371. BCMA_CC_PMU5_MAINPLL_SSB);
  372. case BCMA_CHIP_ID_BCM5357:
  373. case BCMA_CHIP_ID_BCM4749:
  374. return bcma_pmu_pll_clock(cc, BCMA_CC_PMU5357_MAINPLL_PLL0,
  375. BCMA_CC_PMU5_MAINPLL_SSB);
  376. case BCMA_CHIP_ID_BCM4706:
  377. return bcma_pmu_pll_clock_bcm4706(cc,
  378. BCMA_CC_PMU4706_MAINPLL_PLL0,
  379. BCMA_CC_PMU5_MAINPLL_SSB);
  380. case BCMA_CHIP_ID_BCM53572:
  381. return 75000000;
  382. default:
  383. bcma_warn(bus, "No bus clock specified for %04X device, pmu rev. %d, using default %d Hz\n",
  384. bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_HT_CLOCK);
  385. }
  386. return BCMA_CC_PMU_HT_CLOCK;
  387. }
  388. EXPORT_SYMBOL_GPL(bcma_pmu_get_bus_clock);
  389. /* query cpu clock frequency for PMU-enabled chipcommon */
  390. u32 bcma_pmu_get_cpu_clock(struct bcma_drv_cc *cc)
  391. {
  392. struct bcma_bus *bus = cc->core->bus;
  393. if (bus->chipinfo.id == BCMA_CHIP_ID_BCM53572)
  394. return 300000000;
  395. /* New PMUs can have different clock for bus and CPU */
  396. if (cc->pmu.rev >= 5) {
  397. u32 pll;
  398. switch (bus->chipinfo.id) {
  399. case BCMA_CHIP_ID_BCM4706:
  400. return bcma_pmu_pll_clock_bcm4706(cc,
  401. BCMA_CC_PMU4706_MAINPLL_PLL0,
  402. BCMA_CC_PMU5_MAINPLL_CPU);
  403. case BCMA_CHIP_ID_BCM5356:
  404. pll = BCMA_CC_PMU5356_MAINPLL_PLL0;
  405. break;
  406. case BCMA_CHIP_ID_BCM5357:
  407. case BCMA_CHIP_ID_BCM4749:
  408. pll = BCMA_CC_PMU5357_MAINPLL_PLL0;
  409. break;
  410. default:
  411. pll = BCMA_CC_PMU4716_MAINPLL_PLL0;
  412. break;
  413. }
  414. return bcma_pmu_pll_clock(cc, pll, BCMA_CC_PMU5_MAINPLL_CPU);
  415. }
  416. /* On old PMUs CPU has the same clock as the bus */
  417. return bcma_pmu_get_bus_clock(cc);
  418. }
  419. static void bcma_pmu_spuravoid_pll_write(struct bcma_drv_cc *cc, u32 offset,
  420. u32 value)
  421. {
  422. bcma_pmu_write32(cc, BCMA_CC_PMU_PLLCTL_ADDR, offset);
  423. bcma_pmu_write32(cc, BCMA_CC_PMU_PLLCTL_DATA, value);
  424. }
  425. void bcma_pmu_spuravoid_pllupdate(struct bcma_drv_cc *cc, int spuravoid)
  426. {
  427. u32 tmp = 0;
  428. u8 phypll_offset = 0;
  429. u8 bcm5357_bcm43236_p1div[] = {0x1, 0x5, 0x5};
  430. u8 bcm5357_bcm43236_ndiv[] = {0x30, 0xf6, 0xfc};
  431. struct bcma_bus *bus = cc->core->bus;
  432. switch (bus->chipinfo.id) {
  433. case BCMA_CHIP_ID_BCM5357:
  434. case BCMA_CHIP_ID_BCM4749:
  435. case BCMA_CHIP_ID_BCM53572:
  436. /* 5357[ab]0, 43236[ab]0, and 6362b0 */
  437. /* BCM5357 needs to touch PLL1_PLLCTL[02],
  438. so offset PLL0_PLLCTL[02] by 6 */
  439. phypll_offset = (bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
  440. bus->chipinfo.id == BCMA_CHIP_ID_BCM4749 ||
  441. bus->chipinfo.id == BCMA_CHIP_ID_BCM53572) ? 6 : 0;
  442. /* RMW only the P1 divider */
  443. bcma_pmu_write32(cc, BCMA_CC_PMU_PLLCTL_ADDR,
  444. BCMA_CC_PMU_PLL_CTL0 + phypll_offset);
  445. tmp = bcma_pmu_read32(cc, BCMA_CC_PMU_PLLCTL_DATA);
  446. tmp &= (~(BCMA_CC_PMU1_PLL0_PC0_P1DIV_MASK));
  447. tmp |= (bcm5357_bcm43236_p1div[spuravoid] << BCMA_CC_PMU1_PLL0_PC0_P1DIV_SHIFT);
  448. bcma_pmu_write32(cc, BCMA_CC_PMU_PLLCTL_DATA, tmp);
  449. /* RMW only the int feedback divider */
  450. bcma_pmu_write32(cc, BCMA_CC_PMU_PLLCTL_ADDR,
  451. BCMA_CC_PMU_PLL_CTL2 + phypll_offset);
  452. tmp = bcma_pmu_read32(cc, BCMA_CC_PMU_PLLCTL_DATA);
  453. tmp &= ~(BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_MASK);
  454. tmp |= (bcm5357_bcm43236_ndiv[spuravoid]) << BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_SHIFT;
  455. bcma_pmu_write32(cc, BCMA_CC_PMU_PLLCTL_DATA, tmp);
  456. tmp = BCMA_CC_PMU_CTL_PLL_UPD;
  457. break;
  458. case BCMA_CHIP_ID_BCM4331:
  459. case BCMA_CHIP_ID_BCM43431:
  460. if (spuravoid == 2) {
  461. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  462. 0x11500014);
  463. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  464. 0x0FC00a08);
  465. } else if (spuravoid == 1) {
  466. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  467. 0x11500014);
  468. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  469. 0x0F600a08);
  470. } else {
  471. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  472. 0x11100014);
  473. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  474. 0x03000a08);
  475. }
  476. tmp = BCMA_CC_PMU_CTL_PLL_UPD;
  477. break;
  478. case BCMA_CHIP_ID_BCM43224:
  479. case BCMA_CHIP_ID_BCM43225:
  480. case BCMA_CHIP_ID_BCM43421:
  481. if (spuravoid == 1) {
  482. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  483. 0x11500010);
  484. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
  485. 0x000C0C06);
  486. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  487. 0x0F600a08);
  488. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
  489. 0x00000000);
  490. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
  491. 0x2001E920);
  492. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
  493. 0x88888815);
  494. } else {
  495. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  496. 0x11100010);
  497. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
  498. 0x000c0c06);
  499. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  500. 0x03000a08);
  501. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
  502. 0x00000000);
  503. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
  504. 0x200005c0);
  505. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
  506. 0x88888815);
  507. }
  508. tmp = BCMA_CC_PMU_CTL_PLL_UPD;
  509. break;
  510. case BCMA_CHIP_ID_BCM4716:
  511. case BCMA_CHIP_ID_BCM4748:
  512. case BCMA_CHIP_ID_BCM47162:
  513. if (spuravoid == 1) {
  514. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  515. 0x11500060);
  516. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
  517. 0x080C0C06);
  518. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  519. 0x0F600000);
  520. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
  521. 0x00000000);
  522. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
  523. 0x2001E924);
  524. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
  525. 0x88888815);
  526. } else {
  527. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  528. 0x11100060);
  529. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
  530. 0x080c0c06);
  531. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  532. 0x03000000);
  533. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
  534. 0x00000000);
  535. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
  536. 0x200005c0);
  537. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
  538. 0x88888815);
  539. }
  540. tmp = BCMA_CC_PMU_CTL_PLL_UPD | BCMA_CC_PMU_CTL_NOILPONW;
  541. break;
  542. case BCMA_CHIP_ID_BCM43131:
  543. case BCMA_CHIP_ID_BCM43217:
  544. case BCMA_CHIP_ID_BCM43227:
  545. case BCMA_CHIP_ID_BCM43228:
  546. case BCMA_CHIP_ID_BCM43428:
  547. /* LCNXN */
  548. /* PLL Settings for spur avoidance on/off mode,
  549. no on2 support for 43228A0 */
  550. if (spuravoid == 1) {
  551. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  552. 0x01100014);
  553. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
  554. 0x040C0C06);
  555. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  556. 0x03140A08);
  557. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
  558. 0x00333333);
  559. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
  560. 0x202C2820);
  561. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
  562. 0x88888815);
  563. } else {
  564. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
  565. 0x11100014);
  566. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
  567. 0x040c0c06);
  568. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
  569. 0x03000a08);
  570. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
  571. 0x00000000);
  572. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
  573. 0x200005c0);
  574. bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
  575. 0x88888815);
  576. }
  577. tmp = BCMA_CC_PMU_CTL_PLL_UPD;
  578. break;
  579. default:
  580. bcma_err(bus, "Unknown spuravoidance settings for chip 0x%04X, not changing PLL\n",
  581. bus->chipinfo.id);
  582. break;
  583. }
  584. tmp |= bcma_pmu_read32(cc, BCMA_CC_PMU_CTL);
  585. bcma_pmu_write32(cc, BCMA_CC_PMU_CTL, tmp);
  586. }
  587. EXPORT_SYMBOL_GPL(bcma_pmu_spuravoid_pllupdate);