driver_chipcommon_pmu.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. /*
  2. * Sonics Silicon Backplane
  3. * Broadcom 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 <linux/ssb/ssb.h>
  11. #include <linux/ssb/ssb_regs.h>
  12. #include <linux/ssb/ssb_driver_chipcommon.h>
  13. #include <linux/delay.h>
  14. #include <linux/export.h>
  15. #ifdef CONFIG_BCM47XX
  16. #include <asm/mach-bcm47xx/nvram.h>
  17. #endif
  18. #include "ssb_private.h"
  19. static u32 ssb_chipco_pll_read(struct ssb_chipcommon *cc, u32 offset)
  20. {
  21. chipco_write32(cc, SSB_CHIPCO_PLLCTL_ADDR, offset);
  22. return chipco_read32(cc, SSB_CHIPCO_PLLCTL_DATA);
  23. }
  24. static void ssb_chipco_pll_write(struct ssb_chipcommon *cc,
  25. u32 offset, u32 value)
  26. {
  27. chipco_write32(cc, SSB_CHIPCO_PLLCTL_ADDR, offset);
  28. chipco_write32(cc, SSB_CHIPCO_PLLCTL_DATA, value);
  29. }
  30. static void ssb_chipco_regctl_maskset(struct ssb_chipcommon *cc,
  31. u32 offset, u32 mask, u32 set)
  32. {
  33. u32 value;
  34. chipco_read32(cc, SSB_CHIPCO_REGCTL_ADDR);
  35. chipco_write32(cc, SSB_CHIPCO_REGCTL_ADDR, offset);
  36. chipco_read32(cc, SSB_CHIPCO_REGCTL_ADDR);
  37. value = chipco_read32(cc, SSB_CHIPCO_REGCTL_DATA);
  38. value &= mask;
  39. value |= set;
  40. chipco_write32(cc, SSB_CHIPCO_REGCTL_DATA, value);
  41. chipco_read32(cc, SSB_CHIPCO_REGCTL_DATA);
  42. }
  43. struct pmu0_plltab_entry {
  44. u16 freq; /* Crystal frequency in kHz.*/
  45. u8 xf; /* Crystal frequency value for PMU control */
  46. u8 wb_int;
  47. u32 wb_frac;
  48. };
  49. static const struct pmu0_plltab_entry pmu0_plltab[] = {
  50. { .freq = 12000, .xf = 1, .wb_int = 73, .wb_frac = 349525, },
  51. { .freq = 13000, .xf = 2, .wb_int = 67, .wb_frac = 725937, },
  52. { .freq = 14400, .xf = 3, .wb_int = 61, .wb_frac = 116508, },
  53. { .freq = 15360, .xf = 4, .wb_int = 57, .wb_frac = 305834, },
  54. { .freq = 16200, .xf = 5, .wb_int = 54, .wb_frac = 336579, },
  55. { .freq = 16800, .xf = 6, .wb_int = 52, .wb_frac = 399457, },
  56. { .freq = 19200, .xf = 7, .wb_int = 45, .wb_frac = 873813, },
  57. { .freq = 19800, .xf = 8, .wb_int = 44, .wb_frac = 466033, },
  58. { .freq = 20000, .xf = 9, .wb_int = 44, .wb_frac = 0, },
  59. { .freq = 25000, .xf = 10, .wb_int = 70, .wb_frac = 419430, },
  60. { .freq = 26000, .xf = 11, .wb_int = 67, .wb_frac = 725937, },
  61. { .freq = 30000, .xf = 12, .wb_int = 58, .wb_frac = 699050, },
  62. { .freq = 38400, .xf = 13, .wb_int = 45, .wb_frac = 873813, },
  63. { .freq = 40000, .xf = 14, .wb_int = 45, .wb_frac = 0, },
  64. };
  65. #define SSB_PMU0_DEFAULT_XTALFREQ 20000
  66. static const struct pmu0_plltab_entry * pmu0_plltab_find_entry(u32 crystalfreq)
  67. {
  68. const struct pmu0_plltab_entry *e;
  69. unsigned int i;
  70. for (i = 0; i < ARRAY_SIZE(pmu0_plltab); i++) {
  71. e = &pmu0_plltab[i];
  72. if (e->freq == crystalfreq)
  73. return e;
  74. }
  75. return NULL;
  76. }
  77. /* Tune the PLL to the crystal speed. crystalfreq is in kHz. */
  78. static void ssb_pmu0_pllinit_r0(struct ssb_chipcommon *cc,
  79. u32 crystalfreq)
  80. {
  81. struct ssb_bus *bus = cc->dev->bus;
  82. const struct pmu0_plltab_entry *e = NULL;
  83. u32 pmuctl, tmp, pllctl;
  84. unsigned int i;
  85. if (crystalfreq)
  86. e = pmu0_plltab_find_entry(crystalfreq);
  87. if (!e)
  88. e = pmu0_plltab_find_entry(SSB_PMU0_DEFAULT_XTALFREQ);
  89. BUG_ON(!e);
  90. crystalfreq = e->freq;
  91. cc->pmu.crystalfreq = e->freq;
  92. /* Check if the PLL already is programmed to this frequency. */
  93. pmuctl = chipco_read32(cc, SSB_CHIPCO_PMU_CTL);
  94. if (((pmuctl & SSB_CHIPCO_PMU_CTL_XTALFREQ) >> SSB_CHIPCO_PMU_CTL_XTALFREQ_SHIFT) == e->xf) {
  95. /* We're already there... */
  96. return;
  97. }
  98. ssb_printk(KERN_INFO PFX "Programming PLL to %u.%03u MHz\n",
  99. (crystalfreq / 1000), (crystalfreq % 1000));
  100. /* First turn the PLL off. */
  101. switch (bus->chip_id) {
  102. case 0x4328:
  103. chipco_mask32(cc, SSB_CHIPCO_PMU_MINRES_MSK,
  104. ~(1 << SSB_PMURES_4328_BB_PLL_PU));
  105. chipco_mask32(cc, SSB_CHIPCO_PMU_MAXRES_MSK,
  106. ~(1 << SSB_PMURES_4328_BB_PLL_PU));
  107. break;
  108. case 0x5354:
  109. chipco_mask32(cc, SSB_CHIPCO_PMU_MINRES_MSK,
  110. ~(1 << SSB_PMURES_5354_BB_PLL_PU));
  111. chipco_mask32(cc, SSB_CHIPCO_PMU_MAXRES_MSK,
  112. ~(1 << SSB_PMURES_5354_BB_PLL_PU));
  113. break;
  114. default:
  115. SSB_WARN_ON(1);
  116. }
  117. for (i = 1500; i; i--) {
  118. tmp = chipco_read32(cc, SSB_CHIPCO_CLKCTLST);
  119. if (!(tmp & SSB_CHIPCO_CLKCTLST_HAVEHT))
  120. break;
  121. udelay(10);
  122. }
  123. tmp = chipco_read32(cc, SSB_CHIPCO_CLKCTLST);
  124. if (tmp & SSB_CHIPCO_CLKCTLST_HAVEHT)
  125. ssb_printk(KERN_EMERG PFX "Failed to turn the PLL off!\n");
  126. /* Set PDIV in PLL control 0. */
  127. pllctl = ssb_chipco_pll_read(cc, SSB_PMU0_PLLCTL0);
  128. if (crystalfreq >= SSB_PMU0_PLLCTL0_PDIV_FREQ)
  129. pllctl |= SSB_PMU0_PLLCTL0_PDIV_MSK;
  130. else
  131. pllctl &= ~SSB_PMU0_PLLCTL0_PDIV_MSK;
  132. ssb_chipco_pll_write(cc, SSB_PMU0_PLLCTL0, pllctl);
  133. /* Set WILD in PLL control 1. */
  134. pllctl = ssb_chipco_pll_read(cc, SSB_PMU0_PLLCTL1);
  135. pllctl &= ~SSB_PMU0_PLLCTL1_STOPMOD;
  136. pllctl &= ~(SSB_PMU0_PLLCTL1_WILD_IMSK | SSB_PMU0_PLLCTL1_WILD_FMSK);
  137. pllctl |= ((u32)e->wb_int << SSB_PMU0_PLLCTL1_WILD_IMSK_SHIFT) & SSB_PMU0_PLLCTL1_WILD_IMSK;
  138. pllctl |= ((u32)e->wb_frac << SSB_PMU0_PLLCTL1_WILD_FMSK_SHIFT) & SSB_PMU0_PLLCTL1_WILD_FMSK;
  139. if (e->wb_frac == 0)
  140. pllctl |= SSB_PMU0_PLLCTL1_STOPMOD;
  141. ssb_chipco_pll_write(cc, SSB_PMU0_PLLCTL1, pllctl);
  142. /* Set WILD in PLL control 2. */
  143. pllctl = ssb_chipco_pll_read(cc, SSB_PMU0_PLLCTL2);
  144. pllctl &= ~SSB_PMU0_PLLCTL2_WILD_IMSKHI;
  145. pllctl |= (((u32)e->wb_int >> 4) << SSB_PMU0_PLLCTL2_WILD_IMSKHI_SHIFT) & SSB_PMU0_PLLCTL2_WILD_IMSKHI;
  146. ssb_chipco_pll_write(cc, SSB_PMU0_PLLCTL2, pllctl);
  147. /* Set the crystalfrequency and the divisor. */
  148. pmuctl = chipco_read32(cc, SSB_CHIPCO_PMU_CTL);
  149. pmuctl &= ~SSB_CHIPCO_PMU_CTL_ILP_DIV;
  150. pmuctl |= (((crystalfreq + 127) / 128 - 1) << SSB_CHIPCO_PMU_CTL_ILP_DIV_SHIFT)
  151. & SSB_CHIPCO_PMU_CTL_ILP_DIV;
  152. pmuctl &= ~SSB_CHIPCO_PMU_CTL_XTALFREQ;
  153. pmuctl |= ((u32)e->xf << SSB_CHIPCO_PMU_CTL_XTALFREQ_SHIFT) & SSB_CHIPCO_PMU_CTL_XTALFREQ;
  154. chipco_write32(cc, SSB_CHIPCO_PMU_CTL, pmuctl);
  155. }
  156. struct pmu1_plltab_entry {
  157. u16 freq; /* Crystal frequency in kHz.*/
  158. u8 xf; /* Crystal frequency value for PMU control */
  159. u8 ndiv_int;
  160. u32 ndiv_frac;
  161. u8 p1div;
  162. u8 p2div;
  163. };
  164. static const struct pmu1_plltab_entry pmu1_plltab[] = {
  165. { .freq = 12000, .xf = 1, .p1div = 3, .p2div = 22, .ndiv_int = 0x9, .ndiv_frac = 0xFFFFEF, },
  166. { .freq = 13000, .xf = 2, .p1div = 1, .p2div = 6, .ndiv_int = 0xb, .ndiv_frac = 0x483483, },
  167. { .freq = 14400, .xf = 3, .p1div = 1, .p2div = 10, .ndiv_int = 0xa, .ndiv_frac = 0x1C71C7, },
  168. { .freq = 15360, .xf = 4, .p1div = 1, .p2div = 5, .ndiv_int = 0xb, .ndiv_frac = 0x755555, },
  169. { .freq = 16200, .xf = 5, .p1div = 1, .p2div = 10, .ndiv_int = 0x5, .ndiv_frac = 0x6E9E06, },
  170. { .freq = 16800, .xf = 6, .p1div = 1, .p2div = 10, .ndiv_int = 0x5, .ndiv_frac = 0x3CF3CF, },
  171. { .freq = 19200, .xf = 7, .p1div = 1, .p2div = 9, .ndiv_int = 0x5, .ndiv_frac = 0x17B425, },
  172. { .freq = 19800, .xf = 8, .p1div = 1, .p2div = 11, .ndiv_int = 0x4, .ndiv_frac = 0xA57EB, },
  173. { .freq = 20000, .xf = 9, .p1div = 1, .p2div = 11, .ndiv_int = 0x4, .ndiv_frac = 0, },
  174. { .freq = 24000, .xf = 10, .p1div = 3, .p2div = 11, .ndiv_int = 0xa, .ndiv_frac = 0, },
  175. { .freq = 25000, .xf = 11, .p1div = 5, .p2div = 16, .ndiv_int = 0xb, .ndiv_frac = 0, },
  176. { .freq = 26000, .xf = 12, .p1div = 1, .p2div = 2, .ndiv_int = 0x10, .ndiv_frac = 0xEC4EC4, },
  177. { .freq = 30000, .xf = 13, .p1div = 3, .p2div = 8, .ndiv_int = 0xb, .ndiv_frac = 0, },
  178. { .freq = 38400, .xf = 14, .p1div = 1, .p2div = 5, .ndiv_int = 0x4, .ndiv_frac = 0x955555, },
  179. { .freq = 40000, .xf = 15, .p1div = 1, .p2div = 2, .ndiv_int = 0xb, .ndiv_frac = 0, },
  180. };
  181. #define SSB_PMU1_DEFAULT_XTALFREQ 15360
  182. static const struct pmu1_plltab_entry * pmu1_plltab_find_entry(u32 crystalfreq)
  183. {
  184. const struct pmu1_plltab_entry *e;
  185. unsigned int i;
  186. for (i = 0; i < ARRAY_SIZE(pmu1_plltab); i++) {
  187. e = &pmu1_plltab[i];
  188. if (e->freq == crystalfreq)
  189. return e;
  190. }
  191. return NULL;
  192. }
  193. /* Tune the PLL to the crystal speed. crystalfreq is in kHz. */
  194. static void ssb_pmu1_pllinit_r0(struct ssb_chipcommon *cc,
  195. u32 crystalfreq)
  196. {
  197. struct ssb_bus *bus = cc->dev->bus;
  198. const struct pmu1_plltab_entry *e = NULL;
  199. u32 buffer_strength = 0;
  200. u32 tmp, pllctl, pmuctl;
  201. unsigned int i;
  202. if (bus->chip_id == 0x4312) {
  203. /* We do not touch the BCM4312 PLL and assume
  204. * the default crystal settings work out-of-the-box. */
  205. cc->pmu.crystalfreq = 20000;
  206. return;
  207. }
  208. if (crystalfreq)
  209. e = pmu1_plltab_find_entry(crystalfreq);
  210. if (!e)
  211. e = pmu1_plltab_find_entry(SSB_PMU1_DEFAULT_XTALFREQ);
  212. BUG_ON(!e);
  213. crystalfreq = e->freq;
  214. cc->pmu.crystalfreq = e->freq;
  215. /* Check if the PLL already is programmed to this frequency. */
  216. pmuctl = chipco_read32(cc, SSB_CHIPCO_PMU_CTL);
  217. if (((pmuctl & SSB_CHIPCO_PMU_CTL_XTALFREQ) >> SSB_CHIPCO_PMU_CTL_XTALFREQ_SHIFT) == e->xf) {
  218. /* We're already there... */
  219. return;
  220. }
  221. ssb_printk(KERN_INFO PFX "Programming PLL to %u.%03u MHz\n",
  222. (crystalfreq / 1000), (crystalfreq % 1000));
  223. /* First turn the PLL off. */
  224. switch (bus->chip_id) {
  225. case 0x4325:
  226. chipco_mask32(cc, SSB_CHIPCO_PMU_MINRES_MSK,
  227. ~((1 << SSB_PMURES_4325_BBPLL_PWRSW_PU) |
  228. (1 << SSB_PMURES_4325_HT_AVAIL)));
  229. chipco_mask32(cc, SSB_CHIPCO_PMU_MAXRES_MSK,
  230. ~((1 << SSB_PMURES_4325_BBPLL_PWRSW_PU) |
  231. (1 << SSB_PMURES_4325_HT_AVAIL)));
  232. /* Adjust the BBPLL to 2 on all channels later. */
  233. buffer_strength = 0x222222;
  234. break;
  235. default:
  236. SSB_WARN_ON(1);
  237. }
  238. for (i = 1500; i; i--) {
  239. tmp = chipco_read32(cc, SSB_CHIPCO_CLKCTLST);
  240. if (!(tmp & SSB_CHIPCO_CLKCTLST_HAVEHT))
  241. break;
  242. udelay(10);
  243. }
  244. tmp = chipco_read32(cc, SSB_CHIPCO_CLKCTLST);
  245. if (tmp & SSB_CHIPCO_CLKCTLST_HAVEHT)
  246. ssb_printk(KERN_EMERG PFX "Failed to turn the PLL off!\n");
  247. /* Set p1div and p2div. */
  248. pllctl = ssb_chipco_pll_read(cc, SSB_PMU1_PLLCTL0);
  249. pllctl &= ~(SSB_PMU1_PLLCTL0_P1DIV | SSB_PMU1_PLLCTL0_P2DIV);
  250. pllctl |= ((u32)e->p1div << SSB_PMU1_PLLCTL0_P1DIV_SHIFT) & SSB_PMU1_PLLCTL0_P1DIV;
  251. pllctl |= ((u32)e->p2div << SSB_PMU1_PLLCTL0_P2DIV_SHIFT) & SSB_PMU1_PLLCTL0_P2DIV;
  252. ssb_chipco_pll_write(cc, SSB_PMU1_PLLCTL0, pllctl);
  253. /* Set ndiv int and ndiv mode */
  254. pllctl = ssb_chipco_pll_read(cc, SSB_PMU1_PLLCTL2);
  255. pllctl &= ~(SSB_PMU1_PLLCTL2_NDIVINT | SSB_PMU1_PLLCTL2_NDIVMODE);
  256. pllctl |= ((u32)e->ndiv_int << SSB_PMU1_PLLCTL2_NDIVINT_SHIFT) & SSB_PMU1_PLLCTL2_NDIVINT;
  257. pllctl |= (1 << SSB_PMU1_PLLCTL2_NDIVMODE_SHIFT) & SSB_PMU1_PLLCTL2_NDIVMODE;
  258. ssb_chipco_pll_write(cc, SSB_PMU1_PLLCTL2, pllctl);
  259. /* Set ndiv frac */
  260. pllctl = ssb_chipco_pll_read(cc, SSB_PMU1_PLLCTL3);
  261. pllctl &= ~SSB_PMU1_PLLCTL3_NDIVFRAC;
  262. pllctl |= ((u32)e->ndiv_frac << SSB_PMU1_PLLCTL3_NDIVFRAC_SHIFT) & SSB_PMU1_PLLCTL3_NDIVFRAC;
  263. ssb_chipco_pll_write(cc, SSB_PMU1_PLLCTL3, pllctl);
  264. /* Change the drive strength, if required. */
  265. if (buffer_strength) {
  266. pllctl = ssb_chipco_pll_read(cc, SSB_PMU1_PLLCTL5);
  267. pllctl &= ~SSB_PMU1_PLLCTL5_CLKDRV;
  268. pllctl |= (buffer_strength << SSB_PMU1_PLLCTL5_CLKDRV_SHIFT) & SSB_PMU1_PLLCTL5_CLKDRV;
  269. ssb_chipco_pll_write(cc, SSB_PMU1_PLLCTL5, pllctl);
  270. }
  271. /* Tune the crystalfreq and the divisor. */
  272. pmuctl = chipco_read32(cc, SSB_CHIPCO_PMU_CTL);
  273. pmuctl &= ~(SSB_CHIPCO_PMU_CTL_ILP_DIV | SSB_CHIPCO_PMU_CTL_XTALFREQ);
  274. pmuctl |= ((((u32)e->freq + 127) / 128 - 1) << SSB_CHIPCO_PMU_CTL_ILP_DIV_SHIFT)
  275. & SSB_CHIPCO_PMU_CTL_ILP_DIV;
  276. pmuctl |= ((u32)e->xf << SSB_CHIPCO_PMU_CTL_XTALFREQ_SHIFT) & SSB_CHIPCO_PMU_CTL_XTALFREQ;
  277. chipco_write32(cc, SSB_CHIPCO_PMU_CTL, pmuctl);
  278. }
  279. static void ssb_pmu_pll_init(struct ssb_chipcommon *cc)
  280. {
  281. struct ssb_bus *bus = cc->dev->bus;
  282. u32 crystalfreq = 0; /* in kHz. 0 = keep default freq. */
  283. if (bus->bustype == SSB_BUSTYPE_SSB) {
  284. #ifdef CONFIG_BCM47XX
  285. char buf[20];
  286. if (nvram_getenv("xtalfreq", buf, sizeof(buf)) >= 0)
  287. crystalfreq = simple_strtoul(buf, NULL, 0);
  288. #endif
  289. }
  290. switch (bus->chip_id) {
  291. case 0x4312:
  292. case 0x4325:
  293. ssb_pmu1_pllinit_r0(cc, crystalfreq);
  294. break;
  295. case 0x4328:
  296. ssb_pmu0_pllinit_r0(cc, crystalfreq);
  297. break;
  298. case 0x5354:
  299. if (crystalfreq == 0)
  300. crystalfreq = 25000;
  301. ssb_pmu0_pllinit_r0(cc, crystalfreq);
  302. break;
  303. case 0x4322:
  304. if (cc->pmu.rev == 2) {
  305. chipco_write32(cc, SSB_CHIPCO_PLLCTL_ADDR, 0x0000000A);
  306. chipco_write32(cc, SSB_CHIPCO_PLLCTL_DATA, 0x380005C0);
  307. }
  308. break;
  309. default:
  310. ssb_printk(KERN_ERR PFX
  311. "ERROR: PLL init unknown for device %04X\n",
  312. bus->chip_id);
  313. }
  314. }
  315. struct pmu_res_updown_tab_entry {
  316. u8 resource; /* The resource number */
  317. u16 updown; /* The updown value */
  318. };
  319. enum pmu_res_depend_tab_task {
  320. PMU_RES_DEP_SET = 1,
  321. PMU_RES_DEP_ADD,
  322. PMU_RES_DEP_REMOVE,
  323. };
  324. struct pmu_res_depend_tab_entry {
  325. u8 resource; /* The resource number */
  326. u8 task; /* SET | ADD | REMOVE */
  327. u32 depend; /* The depend mask */
  328. };
  329. static const struct pmu_res_updown_tab_entry pmu_res_updown_tab_4328a0[] = {
  330. { .resource = SSB_PMURES_4328_EXT_SWITCHER_PWM, .updown = 0x0101, },
  331. { .resource = SSB_PMURES_4328_BB_SWITCHER_PWM, .updown = 0x1F01, },
  332. { .resource = SSB_PMURES_4328_BB_SWITCHER_BURST, .updown = 0x010F, },
  333. { .resource = SSB_PMURES_4328_BB_EXT_SWITCHER_BURST, .updown = 0x0101, },
  334. { .resource = SSB_PMURES_4328_ILP_REQUEST, .updown = 0x0202, },
  335. { .resource = SSB_PMURES_4328_RADIO_SWITCHER_PWM, .updown = 0x0F01, },
  336. { .resource = SSB_PMURES_4328_RADIO_SWITCHER_BURST, .updown = 0x0F01, },
  337. { .resource = SSB_PMURES_4328_ROM_SWITCH, .updown = 0x0101, },
  338. { .resource = SSB_PMURES_4328_PA_REF_LDO, .updown = 0x0F01, },
  339. { .resource = SSB_PMURES_4328_RADIO_LDO, .updown = 0x0F01, },
  340. { .resource = SSB_PMURES_4328_AFE_LDO, .updown = 0x0F01, },
  341. { .resource = SSB_PMURES_4328_PLL_LDO, .updown = 0x0F01, },
  342. { .resource = SSB_PMURES_4328_BG_FILTBYP, .updown = 0x0101, },
  343. { .resource = SSB_PMURES_4328_TX_FILTBYP, .updown = 0x0101, },
  344. { .resource = SSB_PMURES_4328_RX_FILTBYP, .updown = 0x0101, },
  345. { .resource = SSB_PMURES_4328_XTAL_PU, .updown = 0x0101, },
  346. { .resource = SSB_PMURES_4328_XTAL_EN, .updown = 0xA001, },
  347. { .resource = SSB_PMURES_4328_BB_PLL_FILTBYP, .updown = 0x0101, },
  348. { .resource = SSB_PMURES_4328_RF_PLL_FILTBYP, .updown = 0x0101, },
  349. { .resource = SSB_PMURES_4328_BB_PLL_PU, .updown = 0x0701, },
  350. };
  351. static const struct pmu_res_depend_tab_entry pmu_res_depend_tab_4328a0[] = {
  352. {
  353. /* Adjust ILP Request to avoid forcing EXT/BB into burst mode. */
  354. .resource = SSB_PMURES_4328_ILP_REQUEST,
  355. .task = PMU_RES_DEP_SET,
  356. .depend = ((1 << SSB_PMURES_4328_EXT_SWITCHER_PWM) |
  357. (1 << SSB_PMURES_4328_BB_SWITCHER_PWM)),
  358. },
  359. };
  360. static const struct pmu_res_updown_tab_entry pmu_res_updown_tab_4325a0[] = {
  361. { .resource = SSB_PMURES_4325_XTAL_PU, .updown = 0x1501, },
  362. };
  363. static const struct pmu_res_depend_tab_entry pmu_res_depend_tab_4325a0[] = {
  364. {
  365. /* Adjust HT-Available dependencies. */
  366. .resource = SSB_PMURES_4325_HT_AVAIL,
  367. .task = PMU_RES_DEP_ADD,
  368. .depend = ((1 << SSB_PMURES_4325_RX_PWRSW_PU) |
  369. (1 << SSB_PMURES_4325_TX_PWRSW_PU) |
  370. (1 << SSB_PMURES_4325_LOGEN_PWRSW_PU) |
  371. (1 << SSB_PMURES_4325_AFE_PWRSW_PU)),
  372. },
  373. };
  374. static void ssb_pmu_resources_init(struct ssb_chipcommon *cc)
  375. {
  376. struct ssb_bus *bus = cc->dev->bus;
  377. u32 min_msk = 0, max_msk = 0;
  378. unsigned int i;
  379. const struct pmu_res_updown_tab_entry *updown_tab = NULL;
  380. unsigned int updown_tab_size = 0;
  381. const struct pmu_res_depend_tab_entry *depend_tab = NULL;
  382. unsigned int depend_tab_size = 0;
  383. switch (bus->chip_id) {
  384. case 0x4312:
  385. min_msk = 0xCBB;
  386. break;
  387. case 0x4322:
  388. /* We keep the default settings:
  389. * min_msk = 0xCBB
  390. * max_msk = 0x7FFFF
  391. */
  392. break;
  393. case 0x4325:
  394. /* Power OTP down later. */
  395. min_msk = (1 << SSB_PMURES_4325_CBUCK_BURST) |
  396. (1 << SSB_PMURES_4325_LNLDO2_PU);
  397. if (chipco_read32(cc, SSB_CHIPCO_CHIPSTAT) &
  398. SSB_CHIPCO_CHST_4325_PMUTOP_2B)
  399. min_msk |= (1 << SSB_PMURES_4325_CLDO_CBUCK_BURST);
  400. /* The PLL may turn on, if it decides so. */
  401. max_msk = 0xFFFFF;
  402. updown_tab = pmu_res_updown_tab_4325a0;
  403. updown_tab_size = ARRAY_SIZE(pmu_res_updown_tab_4325a0);
  404. depend_tab = pmu_res_depend_tab_4325a0;
  405. depend_tab_size = ARRAY_SIZE(pmu_res_depend_tab_4325a0);
  406. break;
  407. case 0x4328:
  408. min_msk = (1 << SSB_PMURES_4328_EXT_SWITCHER_PWM) |
  409. (1 << SSB_PMURES_4328_BB_SWITCHER_PWM) |
  410. (1 << SSB_PMURES_4328_XTAL_EN);
  411. /* The PLL may turn on, if it decides so. */
  412. max_msk = 0xFFFFF;
  413. updown_tab = pmu_res_updown_tab_4328a0;
  414. updown_tab_size = ARRAY_SIZE(pmu_res_updown_tab_4328a0);
  415. depend_tab = pmu_res_depend_tab_4328a0;
  416. depend_tab_size = ARRAY_SIZE(pmu_res_depend_tab_4328a0);
  417. break;
  418. case 0x5354:
  419. /* The PLL may turn on, if it decides so. */
  420. max_msk = 0xFFFFF;
  421. break;
  422. default:
  423. ssb_printk(KERN_ERR PFX
  424. "ERROR: PMU resource config unknown for device %04X\n",
  425. bus->chip_id);
  426. }
  427. if (updown_tab) {
  428. for (i = 0; i < updown_tab_size; i++) {
  429. chipco_write32(cc, SSB_CHIPCO_PMU_RES_TABSEL,
  430. updown_tab[i].resource);
  431. chipco_write32(cc, SSB_CHIPCO_PMU_RES_UPDNTM,
  432. updown_tab[i].updown);
  433. }
  434. }
  435. if (depend_tab) {
  436. for (i = 0; i < depend_tab_size; i++) {
  437. chipco_write32(cc, SSB_CHIPCO_PMU_RES_TABSEL,
  438. depend_tab[i].resource);
  439. switch (depend_tab[i].task) {
  440. case PMU_RES_DEP_SET:
  441. chipco_write32(cc, SSB_CHIPCO_PMU_RES_DEPMSK,
  442. depend_tab[i].depend);
  443. break;
  444. case PMU_RES_DEP_ADD:
  445. chipco_set32(cc, SSB_CHIPCO_PMU_RES_DEPMSK,
  446. depend_tab[i].depend);
  447. break;
  448. case PMU_RES_DEP_REMOVE:
  449. chipco_mask32(cc, SSB_CHIPCO_PMU_RES_DEPMSK,
  450. ~(depend_tab[i].depend));
  451. break;
  452. default:
  453. SSB_WARN_ON(1);
  454. }
  455. }
  456. }
  457. /* Set the resource masks. */
  458. if (min_msk)
  459. chipco_write32(cc, SSB_CHIPCO_PMU_MINRES_MSK, min_msk);
  460. if (max_msk)
  461. chipco_write32(cc, SSB_CHIPCO_PMU_MAXRES_MSK, max_msk);
  462. }
  463. /* http://bcm-v4.sipsolutions.net/802.11/SSB/PmuInit */
  464. void ssb_pmu_init(struct ssb_chipcommon *cc)
  465. {
  466. u32 pmucap;
  467. if (!(cc->capabilities & SSB_CHIPCO_CAP_PMU))
  468. return;
  469. pmucap = chipco_read32(cc, SSB_CHIPCO_PMU_CAP);
  470. cc->pmu.rev = (pmucap & SSB_CHIPCO_PMU_CAP_REVISION);
  471. ssb_dprintk(KERN_DEBUG PFX "Found rev %u PMU (capabilities 0x%08X)\n",
  472. cc->pmu.rev, pmucap);
  473. if (cc->pmu.rev == 1)
  474. chipco_mask32(cc, SSB_CHIPCO_PMU_CTL,
  475. ~SSB_CHIPCO_PMU_CTL_NOILPONW);
  476. else
  477. chipco_set32(cc, SSB_CHIPCO_PMU_CTL,
  478. SSB_CHIPCO_PMU_CTL_NOILPONW);
  479. ssb_pmu_pll_init(cc);
  480. ssb_pmu_resources_init(cc);
  481. }
  482. void ssb_pmu_set_ldo_voltage(struct ssb_chipcommon *cc,
  483. enum ssb_pmu_ldo_volt_id id, u32 voltage)
  484. {
  485. struct ssb_bus *bus = cc->dev->bus;
  486. u32 addr, shift, mask;
  487. switch (bus->chip_id) {
  488. case 0x4328:
  489. case 0x5354:
  490. switch (id) {
  491. case LDO_VOLT1:
  492. addr = 2;
  493. shift = 25;
  494. mask = 0xF;
  495. break;
  496. case LDO_VOLT2:
  497. addr = 3;
  498. shift = 1;
  499. mask = 0xF;
  500. break;
  501. case LDO_VOLT3:
  502. addr = 3;
  503. shift = 9;
  504. mask = 0xF;
  505. break;
  506. case LDO_PAREF:
  507. addr = 3;
  508. shift = 17;
  509. mask = 0x3F;
  510. break;
  511. default:
  512. SSB_WARN_ON(1);
  513. return;
  514. }
  515. break;
  516. case 0x4312:
  517. if (SSB_WARN_ON(id != LDO_PAREF))
  518. return;
  519. addr = 0;
  520. shift = 21;
  521. mask = 0x3F;
  522. break;
  523. default:
  524. return;
  525. }
  526. ssb_chipco_regctl_maskset(cc, addr, ~(mask << shift),
  527. (voltage & mask) << shift);
  528. }
  529. void ssb_pmu_set_ldo_paref(struct ssb_chipcommon *cc, bool on)
  530. {
  531. struct ssb_bus *bus = cc->dev->bus;
  532. int ldo;
  533. switch (bus->chip_id) {
  534. case 0x4312:
  535. ldo = SSB_PMURES_4312_PA_REF_LDO;
  536. break;
  537. case 0x4328:
  538. ldo = SSB_PMURES_4328_PA_REF_LDO;
  539. break;
  540. case 0x5354:
  541. ldo = SSB_PMURES_5354_PA_REF_LDO;
  542. break;
  543. default:
  544. return;
  545. }
  546. if (on)
  547. chipco_set32(cc, SSB_CHIPCO_PMU_MINRES_MSK, 1 << ldo);
  548. else
  549. chipco_mask32(cc, SSB_CHIPCO_PMU_MINRES_MSK, ~(1 << ldo));
  550. chipco_read32(cc, SSB_CHIPCO_PMU_MINRES_MSK); //SPEC FIXME found via mmiotrace - dummy read?
  551. }
  552. EXPORT_SYMBOL(ssb_pmu_set_ldo_voltage);
  553. EXPORT_SYMBOL(ssb_pmu_set_ldo_paref);
  554. u32 ssb_pmu_get_cpu_clock(struct ssb_chipcommon *cc)
  555. {
  556. struct ssb_bus *bus = cc->dev->bus;
  557. switch (bus->chip_id) {
  558. case 0x5354:
  559. /* 5354 chip uses a non programmable PLL of frequency 240MHz */
  560. return 240000000;
  561. default:
  562. ssb_printk(KERN_ERR PFX
  563. "ERROR: PMU cpu clock unknown for device %04X\n",
  564. bus->chip_id);
  565. return 0;
  566. }
  567. }
  568. u32 ssb_pmu_get_controlclock(struct ssb_chipcommon *cc)
  569. {
  570. struct ssb_bus *bus = cc->dev->bus;
  571. switch (bus->chip_id) {
  572. case 0x5354:
  573. return 120000000;
  574. default:
  575. ssb_printk(KERN_ERR PFX
  576. "ERROR: PMU controlclock unknown for device %04X\n",
  577. bus->chip_id);
  578. return 0;
  579. }
  580. }
  581. void ssb_pmu_spuravoid_pllupdate(struct ssb_chipcommon *cc, int spuravoid)
  582. {
  583. u32 pmu_ctl = 0;
  584. switch (cc->dev->bus->chip_id) {
  585. case 0x4322:
  586. ssb_chipco_pll_write(cc, SSB_PMU1_PLLCTL0, 0x11100070);
  587. ssb_chipco_pll_write(cc, SSB_PMU1_PLLCTL1, 0x1014140a);
  588. ssb_chipco_pll_write(cc, SSB_PMU1_PLLCTL5, 0x88888854);
  589. if (spuravoid == 1)
  590. ssb_chipco_pll_write(cc, SSB_PMU1_PLLCTL2, 0x05201828);
  591. else
  592. ssb_chipco_pll_write(cc, SSB_PMU1_PLLCTL2, 0x05001828);
  593. pmu_ctl = SSB_CHIPCO_PMU_CTL_PLL_UPD;
  594. break;
  595. case 43222:
  596. /* TODO: BCM43222 requires updating PLLs too */
  597. return;
  598. default:
  599. ssb_printk(KERN_ERR PFX
  600. "Unknown spuravoidance settings for chip 0x%04X, not changing PLL\n",
  601. cc->dev->bus->chip_id);
  602. return;
  603. }
  604. chipco_set32(cc, SSB_CHIPCO_PMU_CTL, pmu_ctl);
  605. }
  606. EXPORT_SYMBOL_GPL(ssb_pmu_spuravoid_pllupdate);