2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/delay.h>
27 * d11 slow to fast clock transition time in slow clock cycles
29 #define D11SCC_SLOW2FAST_TRANSITION 2
32 * external LPO crystal frequency
34 #define EXT_ILP_HZ 32768
37 * Duration for ILP clock frequency measurment in milliseconds
39 * remark: 1000 must be an integer multiple of this duration
41 #define ILP_CALC_DUR 10
46 #define FVCO_880 880000 /* 880MHz */
47 #define FVCO_1760 1760000 /* 1760MHz */
48 #define FVCO_1440 1440000 /* 1440MHz */
49 #define FVCO_960 960000 /* 960MHz */
52 * PMU crystal table indices for 1440MHz fvco
54 #define PMU1_XTALTAB0_1440_12000K 0
55 #define PMU1_XTALTAB0_1440_13000K 1
56 #define PMU1_XTALTAB0_1440_14400K 2
57 #define PMU1_XTALTAB0_1440_15360K 3
58 #define PMU1_XTALTAB0_1440_16200K 4
59 #define PMU1_XTALTAB0_1440_16800K 5
60 #define PMU1_XTALTAB0_1440_19200K 6
61 #define PMU1_XTALTAB0_1440_19800K 7
62 #define PMU1_XTALTAB0_1440_20000K 8
63 #define PMU1_XTALTAB0_1440_25000K 9
64 #define PMU1_XTALTAB0_1440_26000K 10
65 #define PMU1_XTALTAB0_1440_30000K 11
66 #define PMU1_XTALTAB0_1440_37400K 12
67 #define PMU1_XTALTAB0_1440_38400K 13
68 #define PMU1_XTALTAB0_1440_40000K 14
69 #define PMU1_XTALTAB0_1440_48000K 15
72 * PMU crystal table indices for 960MHz fvco
74 #define PMU1_XTALTAB0_960_12000K 0
75 #define PMU1_XTALTAB0_960_13000K 1
76 #define PMU1_XTALTAB0_960_14400K 2
77 #define PMU1_XTALTAB0_960_15360K 3
78 #define PMU1_XTALTAB0_960_16200K 4
79 #define PMU1_XTALTAB0_960_16800K 5
80 #define PMU1_XTALTAB0_960_19200K 6
81 #define PMU1_XTALTAB0_960_19800K 7
82 #define PMU1_XTALTAB0_960_20000K 8
83 #define PMU1_XTALTAB0_960_25000K 9
84 #define PMU1_XTALTAB0_960_26000K 10
85 #define PMU1_XTALTAB0_960_30000K 11
86 #define PMU1_XTALTAB0_960_37400K 12
87 #define PMU1_XTALTAB0_960_38400K 13
88 #define PMU1_XTALTAB0_960_40000K 14
89 #define PMU1_XTALTAB0_960_48000K 15
92 * PMU crystal table indices for 880MHz fvco
94 #define PMU1_XTALTAB0_880_12000K 0
95 #define PMU1_XTALTAB0_880_13000K 1
96 #define PMU1_XTALTAB0_880_14400K 2
97 #define PMU1_XTALTAB0_880_15360K 3
98 #define PMU1_XTALTAB0_880_16200K 4
99 #define PMU1_XTALTAB0_880_16800K 5
100 #define PMU1_XTALTAB0_880_19200K 6
101 #define PMU1_XTALTAB0_880_19800K 7
102 #define PMU1_XTALTAB0_880_20000K 8
103 #define PMU1_XTALTAB0_880_24000K 9
104 #define PMU1_XTALTAB0_880_25000K 10
105 #define PMU1_XTALTAB0_880_26000K 11
106 #define PMU1_XTALTAB0_880_30000K 12
107 #define PMU1_XTALTAB0_880_37400K 13
108 #define PMU1_XTALTAB0_880_38400K 14
109 #define PMU1_XTALTAB0_880_40000K 15
112 * crystal frequency values
114 #define XTAL_FREQ_24000MHZ 24000
115 #define XTAL_FREQ_30000MHZ 30000
116 #define XTAL_FREQ_37400MHZ 37400
117 #define XTAL_FREQ_48000MHZ 48000
120 * Resource dependancies mask change action
122 * @RES_DEPEND_SET: Override the dependancies mask
123 * @RES_DEPEND_ADD: Add to the dependancies mask
124 * @RES_DEPEND_REMOVE: Remove from the dependancies mask
126 #define RES_DEPEND_SET 0
127 #define RES_DEPEND_ADD 1
128 #define RES_DEPEND_REMOVE -1
130 /* d11 slow to fast clock transition time in slow clock cycles */
131 #define D11SCC_SLOW2FAST_TRANSITION 2
133 /* Setup resource up/down timers */
139 /* Change resource dependancies masks */
141 u32 res_mask; /* resources (chip specific) */
142 s8 action; /* action */
143 u32 depend_mask; /* changes to the dependancies mask */
144 bool(*filter) (si_t *sih); /* action is taken when filter is NULL or return true */
147 /* setup pll and query clock speed */
158 * prototypes used in resource tables
160 static bool si_pmu_res_depfltr_bb(si_t *sih);
161 static bool si_pmu_res_depfltr_ncb(si_t *sih);
162 static bool si_pmu_res_depfltr_paldo(si_t *sih);
163 static bool si_pmu_res_depfltr_npaldo(si_t *sih);
165 static const pmu_res_updown_t bcm4328a0_res_updown[] = {
167 RES4328_EXT_SWITCHER_PWM, 0x0101}, {
168 RES4328_BB_SWITCHER_PWM, 0x1f01}, {
169 RES4328_BB_SWITCHER_BURST, 0x010f}, {
170 RES4328_BB_EXT_SWITCHER_BURST, 0x0101}, {
171 RES4328_ILP_REQUEST, 0x0202}, {
172 RES4328_RADIO_SWITCHER_PWM, 0x0f01}, {
173 RES4328_RADIO_SWITCHER_BURST, 0x0f01}, {
174 RES4328_ROM_SWITCH, 0x0101}, {
175 RES4328_PA_REF_LDO, 0x0f01}, {
176 RES4328_RADIO_LDO, 0x0f01}, {
177 RES4328_AFE_LDO, 0x0f01}, {
178 RES4328_PLL_LDO, 0x0f01}, {
179 RES4328_BG_FILTBYP, 0x0101}, {
180 RES4328_TX_FILTBYP, 0x0101}, {
181 RES4328_RX_FILTBYP, 0x0101}, {
182 RES4328_XTAL_PU, 0x0101}, {
183 RES4328_XTAL_EN, 0xa001}, {
184 RES4328_BB_PLL_FILTBYP, 0x0101}, {
185 RES4328_RF_PLL_FILTBYP, 0x0101}, {
186 RES4328_BB_PLL_PU, 0x0701}
189 static const pmu_res_depend_t bcm4328a0_res_depend[] = {
190 /* Adjust ILP request resource not to force ext/BB switchers into burst mode */
192 PMURES_BIT(RES4328_ILP_REQUEST),
194 PMURES_BIT(RES4328_EXT_SWITCHER_PWM) |
195 PMURES_BIT(RES4328_BB_SWITCHER_PWM), NULL}
198 static const pmu_res_updown_t bcm4325a0_res_updown_qt[] = {
200 RES4325_HT_AVAIL, 0x0300}, {
201 RES4325_BBPLL_PWRSW_PU, 0x0101}, {
202 RES4325_RFPLL_PWRSW_PU, 0x0101}, {
203 RES4325_ALP_AVAIL, 0x0100}, {
204 RES4325_XTAL_PU, 0x1000}, {
205 RES4325_LNLDO1_PU, 0x0800}, {
206 RES4325_CLDO_CBUCK_PWM, 0x0101}, {
207 RES4325_CBUCK_PWM, 0x0803}
210 static const pmu_res_updown_t bcm4325a0_res_updown[] = {
212 RES4325_XTAL_PU, 0x1501}
215 static const pmu_res_depend_t bcm4325a0_res_depend[] = {
216 /* Adjust OTP PU resource dependencies - remove BB BURST */
218 PMURES_BIT(RES4325_OTP_PU),
220 PMURES_BIT(RES4325_BUCK_BOOST_BURST), NULL},
221 /* Adjust ALP/HT Avail resource dependencies - bring up BB along if it is used. */
223 PMURES_BIT(RES4325_ALP_AVAIL) | PMURES_BIT(RES4325_HT_AVAIL),
225 PMURES_BIT(RES4325_BUCK_BOOST_BURST) |
226 PMURES_BIT(RES4325_BUCK_BOOST_PWM), si_pmu_res_depfltr_bb},
227 /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */
229 PMURES_BIT(RES4325_HT_AVAIL),
231 PMURES_BIT(RES4325_RX_PWRSW_PU) |
232 PMURES_BIT(RES4325_TX_PWRSW_PU) |
233 PMURES_BIT(RES4325_LOGEN_PWRSW_PU) |
234 PMURES_BIT(RES4325_AFE_PWRSW_PU), NULL},
235 /* Adjust ALL resource dependencies - remove CBUCK dependancies if it is not used. */
237 PMURES_BIT(RES4325_ILP_REQUEST) |
238 PMURES_BIT(RES4325_ABUCK_BURST) |
239 PMURES_BIT(RES4325_ABUCK_PWM) |
240 PMURES_BIT(RES4325_LNLDO1_PU) |
241 PMURES_BIT(RES4325C1_LNLDO2_PU) |
242 PMURES_BIT(RES4325_XTAL_PU) |
243 PMURES_BIT(RES4325_ALP_AVAIL) |
244 PMURES_BIT(RES4325_RX_PWRSW_PU) |
245 PMURES_BIT(RES4325_TX_PWRSW_PU) |
246 PMURES_BIT(RES4325_RFPLL_PWRSW_PU) |
247 PMURES_BIT(RES4325_LOGEN_PWRSW_PU) |
248 PMURES_BIT(RES4325_AFE_PWRSW_PU) |
249 PMURES_BIT(RES4325_BBPLL_PWRSW_PU) |
250 PMURES_BIT(RES4325_HT_AVAIL), RES_DEPEND_REMOVE,
251 PMURES_BIT(RES4325B0_CBUCK_LPOM) |
252 PMURES_BIT(RES4325B0_CBUCK_BURST) |
253 PMURES_BIT(RES4325B0_CBUCK_PWM), si_pmu_res_depfltr_ncb}
256 static const pmu_res_updown_t bcm4315a0_res_updown_qt[] = {
258 RES4315_HT_AVAIL, 0x0101}, {
259 RES4315_XTAL_PU, 0x0100}, {
260 RES4315_LNLDO1_PU, 0x0100}, {
261 RES4315_PALDO_PU, 0x0100}, {
262 RES4315_CLDO_PU, 0x0100}, {
263 RES4315_CBUCK_PWM, 0x0100}, {
264 RES4315_CBUCK_BURST, 0x0100}, {
265 RES4315_CBUCK_LPOM, 0x0100}
268 static const pmu_res_updown_t bcm4315a0_res_updown[] = {
270 RES4315_XTAL_PU, 0x2501}
273 static const pmu_res_depend_t bcm4315a0_res_depend[] = {
274 /* Adjust OTP PU resource dependencies - not need PALDO unless write */
276 PMURES_BIT(RES4315_OTP_PU),
278 PMURES_BIT(RES4315_PALDO_PU), si_pmu_res_depfltr_npaldo},
279 /* Adjust ALP/HT Avail resource dependencies - bring up PALDO along if it is used. */
281 PMURES_BIT(RES4315_ALP_AVAIL) | PMURES_BIT(RES4315_HT_AVAIL),
283 PMURES_BIT(RES4315_PALDO_PU), si_pmu_res_depfltr_paldo},
284 /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */
286 PMURES_BIT(RES4315_HT_AVAIL),
288 PMURES_BIT(RES4315_RX_PWRSW_PU) |
289 PMURES_BIT(RES4315_TX_PWRSW_PU) |
290 PMURES_BIT(RES4315_LOGEN_PWRSW_PU) |
291 PMURES_BIT(RES4315_AFE_PWRSW_PU), NULL},
292 /* Adjust ALL resource dependencies - remove CBUCK dependancies if it is not used. */
294 PMURES_BIT(RES4315_CLDO_PU) | PMURES_BIT(RES4315_ILP_REQUEST) |
295 PMURES_BIT(RES4315_LNLDO1_PU) |
296 PMURES_BIT(RES4315_OTP_PU) |
297 PMURES_BIT(RES4315_LNLDO2_PU) |
298 PMURES_BIT(RES4315_XTAL_PU) |
299 PMURES_BIT(RES4315_ALP_AVAIL) |
300 PMURES_BIT(RES4315_RX_PWRSW_PU) |
301 PMURES_BIT(RES4315_TX_PWRSW_PU) |
302 PMURES_BIT(RES4315_RFPLL_PWRSW_PU) |
303 PMURES_BIT(RES4315_LOGEN_PWRSW_PU) |
304 PMURES_BIT(RES4315_AFE_PWRSW_PU) |
305 PMURES_BIT(RES4315_BBPLL_PWRSW_PU) |
306 PMURES_BIT(RES4315_HT_AVAIL), RES_DEPEND_REMOVE,
307 PMURES_BIT(RES4315_CBUCK_LPOM) |
308 PMURES_BIT(RES4315_CBUCK_BURST) |
309 PMURES_BIT(RES4315_CBUCK_PWM), si_pmu_res_depfltr_ncb}
312 /* 4329 specific. needs to come back this issue later */
313 static const pmu_res_updown_t bcm4329_res_updown[] = {
315 RES4329_XTAL_PU, 0x1501}
318 static const pmu_res_depend_t bcm4329_res_depend[] = {
319 /* Adjust HT Avail resource dependencies */
321 PMURES_BIT(RES4329_HT_AVAIL),
323 PMURES_BIT(RES4329_CBUCK_LPOM) |
324 PMURES_BIT(RES4329_CBUCK_BURST) |
325 PMURES_BIT(RES4329_CBUCK_PWM) |
326 PMURES_BIT(RES4329_CLDO_PU) |
327 PMURES_BIT(RES4329_PALDO_PU) |
328 PMURES_BIT(RES4329_LNLDO1_PU) |
329 PMURES_BIT(RES4329_XTAL_PU) |
330 PMURES_BIT(RES4329_ALP_AVAIL) |
331 PMURES_BIT(RES4329_RX_PWRSW_PU) |
332 PMURES_BIT(RES4329_TX_PWRSW_PU) |
333 PMURES_BIT(RES4329_RFPLL_PWRSW_PU) |
334 PMURES_BIT(RES4329_LOGEN_PWRSW_PU) |
335 PMURES_BIT(RES4329_AFE_PWRSW_PU) |
336 PMURES_BIT(RES4329_BBPLL_PWRSW_PU), NULL}
339 static const pmu_res_updown_t bcm4319a0_res_updown_qt[] = {
341 RES4319_HT_AVAIL, 0x0101}, {
342 RES4319_XTAL_PU, 0x0100}, {
343 RES4319_LNLDO1_PU, 0x0100}, {
344 RES4319_PALDO_PU, 0x0100}, {
345 RES4319_CLDO_PU, 0x0100}, {
346 RES4319_CBUCK_PWM, 0x0100}, {
347 RES4319_CBUCK_BURST, 0x0100}, {
348 RES4319_CBUCK_LPOM, 0x0100}
351 static const pmu_res_updown_t bcm4319a0_res_updown[] = {
353 RES4319_XTAL_PU, 0x3f01}
356 static const pmu_res_depend_t bcm4319a0_res_depend[] = {
357 /* Adjust OTP PU resource dependencies - not need PALDO unless write */
359 PMURES_BIT(RES4319_OTP_PU),
361 PMURES_BIT(RES4319_PALDO_PU), si_pmu_res_depfltr_npaldo},
362 /* Adjust HT Avail resource dependencies - bring up PALDO along if it is used. */
364 PMURES_BIT(RES4319_HT_AVAIL),
366 PMURES_BIT(RES4319_PALDO_PU), si_pmu_res_depfltr_paldo},
367 /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */
369 PMURES_BIT(RES4319_HT_AVAIL),
371 PMURES_BIT(RES4319_RX_PWRSW_PU) |
372 PMURES_BIT(RES4319_TX_PWRSW_PU) |
373 PMURES_BIT(RES4319_RFPLL_PWRSW_PU) |
374 PMURES_BIT(RES4319_LOGEN_PWRSW_PU) |
375 PMURES_BIT(RES4319_AFE_PWRSW_PU), NULL}
378 static const pmu_res_updown_t bcm4336a0_res_updown_qt[] = {
380 RES4336_HT_AVAIL, 0x0101}, {
381 RES4336_XTAL_PU, 0x0100}, {
382 RES4336_CLDO_PU, 0x0100}, {
383 RES4336_CBUCK_PWM, 0x0100}, {
384 RES4336_CBUCK_BURST, 0x0100}, {
385 RES4336_CBUCK_LPOM, 0x0100}
388 static const pmu_res_updown_t bcm4336a0_res_updown[] = {
390 RES4336_HT_AVAIL, 0x0D01}
393 static const pmu_res_depend_t bcm4336a0_res_depend[] = {
394 /* Just a dummy entry for now */
396 PMURES_BIT(RES4336_RSVD), RES_DEPEND_ADD, 0, NULL}
399 static const pmu_res_updown_t bcm4330a0_res_updown_qt[] = {
401 RES4330_HT_AVAIL, 0x0101}, {
402 RES4330_XTAL_PU, 0x0100}, {
403 RES4330_CLDO_PU, 0x0100}, {
404 RES4330_CBUCK_PWM, 0x0100}, {
405 RES4330_CBUCK_BURST, 0x0100}, {
406 RES4330_CBUCK_LPOM, 0x0100}
409 static const pmu_res_updown_t bcm4330a0_res_updown[] = {
411 RES4330_HT_AVAIL, 0x0e02}
414 static const pmu_res_depend_t bcm4330a0_res_depend[] = {
415 /* Just a dummy entry for now */
417 PMURES_BIT(RES4330_HT_AVAIL), RES_DEPEND_ADD, 0, NULL}
420 /* the following table is based on 1440Mhz fvco */
421 static const pmu1_xtaltab0_t pmu1_xtaltab0_1440[] = {
423 12000, 1, 1, 1, 0x78, 0x0}, {
424 13000, 2, 1, 1, 0x6E, 0xC4EC4E}, {
425 14400, 3, 1, 1, 0x64, 0x0}, {
426 15360, 4, 1, 1, 0x5D, 0xC00000}, {
427 16200, 5, 1, 1, 0x58, 0xE38E38}, {
428 16800, 6, 1, 1, 0x55, 0xB6DB6D}, {
429 19200, 7, 1, 1, 0x4B, 0}, {
430 19800, 8, 1, 1, 0x48, 0xBA2E8B}, {
431 20000, 9, 1, 1, 0x48, 0x0}, {
432 25000, 10, 1, 1, 0x39, 0x999999}, {
433 26000, 11, 1, 1, 0x37, 0x627627}, {
434 30000, 12, 1, 1, 0x30, 0x0}, {
435 37400, 13, 2, 1, 0x4D, 0x15E76}, {
436 38400, 13, 2, 1, 0x4B, 0x0}, {
437 40000, 14, 2, 1, 0x48, 0x0}, {
438 48000, 15, 2, 1, 0x3c, 0x0}, {
442 static const pmu1_xtaltab0_t pmu1_xtaltab0_960[] = {
444 12000, 1, 1, 1, 0x50, 0x0}, {
445 13000, 2, 1, 1, 0x49, 0xD89D89}, {
446 14400, 3, 1, 1, 0x42, 0xAAAAAA}, {
447 15360, 4, 1, 1, 0x3E, 0x800000}, {
448 16200, 5, 1, 1, 0x39, 0x425ED0}, {
449 16800, 6, 1, 1, 0x39, 0x249249}, {
450 19200, 7, 1, 1, 0x32, 0x0}, {
451 19800, 8, 1, 1, 0x30, 0x7C1F07}, {
452 20000, 9, 1, 1, 0x30, 0x0}, {
453 25000, 10, 1, 1, 0x26, 0x666666}, {
454 26000, 11, 1, 1, 0x24, 0xEC4EC4}, {
455 30000, 12, 1, 1, 0x20, 0x0}, {
456 37400, 13, 2, 1, 0x33, 0x563EF9}, {
457 38400, 14, 2, 1, 0x32, 0x0}, {
458 40000, 15, 2, 1, 0x30, 0x0}, {
459 48000, 16, 2, 1, 0x28, 0x0}, {
463 static const pmu1_xtaltab0_t pmu1_xtaltab0_880_4329[] = {
465 12000, 1, 3, 22, 0x9, 0xFFFFEF}, {
466 13000, 2, 1, 6, 0xb, 0x483483}, {
467 14400, 3, 1, 10, 0xa, 0x1C71C7}, {
468 15360, 4, 1, 5, 0xb, 0x755555}, {
469 16200, 5, 1, 10, 0x5, 0x6E9E06}, {
470 16800, 6, 1, 10, 0x5, 0x3Cf3Cf}, {
471 19200, 7, 1, 4, 0xb, 0x755555}, {
472 19800, 8, 1, 11, 0x4, 0xA57EB}, {
473 20000, 9, 1, 11, 0x4, 0x0}, {
474 24000, 10, 3, 11, 0xa, 0x0}, {
475 25000, 11, 5, 16, 0xb, 0x0}, {
476 26000, 12, 1, 1, 0x21, 0xD89D89}, {
477 30000, 13, 3, 8, 0xb, 0x0}, {
478 37400, 14, 3, 1, 0x46, 0x969696}, {
479 38400, 15, 1, 1, 0x16, 0xEAAAAA}, {
480 40000, 16, 1, 2, 0xb, 0}, {
484 /* the following table is based on 880Mhz fvco */
485 static const pmu1_xtaltab0_t pmu1_xtaltab0_880[] = {
487 12000, 1, 3, 22, 0x9, 0xFFFFEF}, {
488 13000, 2, 1, 6, 0xb, 0x483483}, {
489 14400, 3, 1, 10, 0xa, 0x1C71C7}, {
490 15360, 4, 1, 5, 0xb, 0x755555}, {
491 16200, 5, 1, 10, 0x5, 0x6E9E06}, {
492 16800, 6, 1, 10, 0x5, 0x3Cf3Cf}, {
493 19200, 7, 1, 4, 0xb, 0x755555}, {
494 19800, 8, 1, 11, 0x4, 0xA57EB}, {
495 20000, 9, 1, 11, 0x4, 0x0}, {
496 24000, 10, 3, 11, 0xa, 0x0}, {
497 25000, 11, 5, 16, 0xb, 0x0}, {
498 26000, 12, 1, 2, 0x10, 0xEC4EC4}, {
499 30000, 13, 3, 8, 0xb, 0x0}, {
500 33600, 14, 1, 2, 0xd, 0x186186}, {
501 38400, 15, 1, 2, 0xb, 0x755555}, {
502 40000, 16, 1, 2, 0xb, 0}, {
506 /* true if the power topology uses the buck boost to provide 3.3V to VDDIO_RF and WLAN PA */
507 static bool si_pmu_res_depfltr_bb(si_t *sih)
509 return (sih->boardflags & BFL_BUCKBOOST) != 0;
512 /* true if the power topology doesn't use the cbuck. Key on chiprev also if the chip is BCM4325. */
513 static bool si_pmu_res_depfltr_ncb(si_t *sih)
516 return (sih->boardflags & BFL_NOCBUCK) != 0;
519 /* true if the power topology uses the PALDO */
520 static bool si_pmu_res_depfltr_paldo(si_t *sih)
522 return (sih->boardflags & BFL_PALDO) != 0;
525 /* true if the power topology doesn't use the PALDO */
526 static bool si_pmu_res_depfltr_npaldo(si_t *sih)
528 return (sih->boardflags & BFL_PALDO) == 0;
531 /* Return dependancies (direct or all/indirect) for the given resources */
533 si_pmu_res_deps(si_t *sih, chipcregs_t *cc, u32 rsrcs,
539 for (i = 0; i <= PMURES_MAX_RESNUM; i++) {
540 if (!(rsrcs & PMURES_BIT(i)))
542 W_REG(&cc->res_table_sel, i);
543 deps |= R_REG(&cc->res_dep_mask);
546 return !all ? deps : (deps
548 si_pmu_res_deps(sih, cc, deps,
552 /* Determine min/max rsrc masks. Value 0 leaves hardware at default. */
553 static void si_pmu_res_masks(si_t *sih, u32 * pmin, u32 * pmax)
555 u32 min_mask = 0, max_mask = 0;
560 rsrcs = (sih->pmucaps & PCAP_RC_MASK) >> PCAP_RC_SHIFT;
562 /* determine min/max rsrc masks */
564 case BCM43224_CHIP_ID:
565 case BCM43225_CHIP_ID:
566 case BCM43421_CHIP_ID:
567 case BCM43235_CHIP_ID:
568 case BCM43236_CHIP_ID:
569 case BCM43238_CHIP_ID:
570 case BCM4331_CHIP_ID:
571 case BCM6362_CHIP_ID:
575 case BCM4329_CHIP_ID:
576 /* 4329 spedific issue. Needs to come back this issue later */
577 /* Down to save the power. */
579 PMURES_BIT(RES4329_CBUCK_LPOM) |
580 PMURES_BIT(RES4329_CLDO_PU);
581 /* Allow (but don't require) PLL to turn on */
584 case BCM4319_CHIP_ID:
585 /* We only need a few resources to be kept on all the time */
586 min_mask = PMURES_BIT(RES4319_CBUCK_LPOM) |
587 PMURES_BIT(RES4319_CLDO_PU);
589 /* Allow everything else to be turned on upon requests */
590 max_mask = ~(~0 << rsrcs);
592 case BCM4336_CHIP_ID:
593 /* Down to save the power. */
595 PMURES_BIT(RES4336_CBUCK_LPOM) | PMURES_BIT(RES4336_CLDO_PU)
596 | PMURES_BIT(RES4336_LDO3P3_PU) | PMURES_BIT(RES4336_OTP_PU)
597 | PMURES_BIT(RES4336_DIS_INT_RESET_PD);
598 /* Allow (but don't require) PLL to turn on */
599 max_mask = 0x1ffffff;
602 case BCM4330_CHIP_ID:
603 /* Down to save the power. */
605 PMURES_BIT(RES4330_CBUCK_LPOM) | PMURES_BIT(RES4330_CLDO_PU)
606 | PMURES_BIT(RES4330_DIS_INT_RESET_PD) |
607 PMURES_BIT(RES4330_LDO3P3_PU) | PMURES_BIT(RES4330_OTP_PU);
608 /* Allow (but don't require) PLL to turn on */
609 max_mask = 0xfffffff;
612 case BCM4313_CHIP_ID:
613 min_mask = PMURES_BIT(RES4313_BB_PU_RSRC) |
614 PMURES_BIT(RES4313_XTAL_PU_RSRC) |
615 PMURES_BIT(RES4313_ALP_AVAIL_RSRC) |
616 PMURES_BIT(RES4313_BB_PLL_PWRSW_RSRC);
623 /* Apply nvram override to min mask */
624 val = getvar(NULL, "rmin");
626 min_mask = (u32) simple_strtoul(val, NULL, 0);
628 /* Apply nvram override to max mask */
629 val = getvar(NULL, "rmax");
631 max_mask = (u32) simple_strtoul(val, NULL, 0);
638 /* Return up time in ILP cycles for the given resource. */
640 si_pmu_res_uptime(si_t *sih, chipcregs_t *cc, u8 rsrc) {
642 uint up, i, dup, dmax;
643 u32 min_mask = 0, max_mask = 0;
645 /* uptime of resource 'rsrc' */
646 W_REG(&cc->res_table_sel, rsrc);
647 up = (R_REG(&cc->res_updn_timer) >> 8) & 0xff;
649 /* direct dependancies of resource 'rsrc' */
650 deps = si_pmu_res_deps(sih, cc, PMURES_BIT(rsrc), false);
651 for (i = 0; i <= PMURES_MAX_RESNUM; i++) {
652 if (!(deps & PMURES_BIT(i)))
654 deps &= ~si_pmu_res_deps(sih, cc, PMURES_BIT(i), true);
656 si_pmu_res_masks(sih, &min_mask, &max_mask);
659 /* max uptime of direct dependancies */
661 for (i = 0; i <= PMURES_MAX_RESNUM; i++) {
662 if (!(deps & PMURES_BIT(i)))
664 dup = si_pmu_res_uptime(sih, cc, (u8) i);
669 return up + dmax + PMURES_UP_TRANSITION;
673 si_pmu_spuravoid_pllupdate(si_t *sih, chipcregs_t *cc, u8 spuravoid)
676 u8 phypll_offset = 0;
677 u8 bcm5357_bcm43236_p1div[] = { 0x1, 0x5, 0x5 };
678 u8 bcm5357_bcm43236_ndiv[] = { 0x30, 0xf6, 0xfc };
681 case BCM5357_CHIP_ID:
682 case BCM43235_CHIP_ID:
683 case BCM43236_CHIP_ID:
684 case BCM43238_CHIP_ID:
687 * BCM5357 needs to touch PLL1_PLLCTL[02],
688 * so offset PLL0_PLLCTL[02] by 6
690 phypll_offset = (sih->chip == BCM5357_CHIP_ID) ? 6 : 0;
692 /* RMW only the P1 divider */
693 W_REG(&cc->pllcontrol_addr,
694 PMU1_PLL0_PLLCTL0 + phypll_offset);
695 tmp = R_REG(&cc->pllcontrol_data);
696 tmp &= (~(PMU1_PLL0_PC0_P1DIV_MASK));
698 (bcm5357_bcm43236_p1div[spuravoid] <<
699 PMU1_PLL0_PC0_P1DIV_SHIFT);
700 W_REG(&cc->pllcontrol_data, tmp);
702 /* RMW only the int feedback divider */
703 W_REG(&cc->pllcontrol_addr,
704 PMU1_PLL0_PLLCTL2 + phypll_offset);
705 tmp = R_REG(&cc->pllcontrol_data);
706 tmp &= ~(PMU1_PLL0_PC2_NDIV_INT_MASK);
708 (bcm5357_bcm43236_ndiv[spuravoid]) <<
709 PMU1_PLL0_PC2_NDIV_INT_SHIFT;
710 W_REG(&cc->pllcontrol_data, tmp);
715 case BCM4331_CHIP_ID:
716 if (spuravoid == 2) {
717 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
718 W_REG(&cc->pllcontrol_data, 0x11500014);
719 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
720 W_REG(&cc->pllcontrol_data, 0x0FC00a08);
721 } else if (spuravoid == 1) {
722 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
723 W_REG(&cc->pllcontrol_data, 0x11500014);
724 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
725 W_REG(&cc->pllcontrol_data, 0x0F600a08);
727 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
728 W_REG(&cc->pllcontrol_data, 0x11100014);
729 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
730 W_REG(&cc->pllcontrol_data, 0x03000a08);
735 case BCM43224_CHIP_ID:
736 case BCM43225_CHIP_ID:
737 case BCM43421_CHIP_ID:
738 case BCM6362_CHIP_ID:
739 if (spuravoid == 1) {
740 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
741 W_REG(&cc->pllcontrol_data, 0x11500010);
742 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
743 W_REG(&cc->pllcontrol_data, 0x000C0C06);
744 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
745 W_REG(&cc->pllcontrol_data, 0x0F600a08);
746 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
747 W_REG(&cc->pllcontrol_data, 0x00000000);
748 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
749 W_REG(&cc->pllcontrol_data, 0x2001E920);
750 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
751 W_REG(&cc->pllcontrol_data, 0x88888815);
753 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
754 W_REG(&cc->pllcontrol_data, 0x11100010);
755 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
756 W_REG(&cc->pllcontrol_data, 0x000c0c06);
757 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
758 W_REG(&cc->pllcontrol_data, 0x03000a08);
759 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
760 W_REG(&cc->pllcontrol_data, 0x00000000);
761 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
762 W_REG(&cc->pllcontrol_data, 0x200005c0);
763 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
764 W_REG(&cc->pllcontrol_data, 0x88888815);
769 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
770 W_REG(&cc->pllcontrol_data, 0x11100008);
771 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
772 W_REG(&cc->pllcontrol_data, 0x0c000c06);
773 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
774 W_REG(&cc->pllcontrol_data, 0x03000a08);
775 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
776 W_REG(&cc->pllcontrol_data, 0x00000000);
777 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
778 W_REG(&cc->pllcontrol_data, 0x200005c0);
779 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
780 W_REG(&cc->pllcontrol_data, 0x88888855);
785 case BCM4716_CHIP_ID:
786 case BCM4748_CHIP_ID:
787 case BCM47162_CHIP_ID:
788 if (spuravoid == 1) {
789 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
790 W_REG(&cc->pllcontrol_data, 0x11500060);
791 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
792 W_REG(&cc->pllcontrol_data, 0x080C0C06);
793 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
794 W_REG(&cc->pllcontrol_data, 0x0F600000);
795 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
796 W_REG(&cc->pllcontrol_data, 0x00000000);
797 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
798 W_REG(&cc->pllcontrol_data, 0x2001E924);
799 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
800 W_REG(&cc->pllcontrol_data, 0x88888815);
802 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
803 W_REG(&cc->pllcontrol_data, 0x11100060);
804 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
805 W_REG(&cc->pllcontrol_data, 0x080c0c06);
806 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
807 W_REG(&cc->pllcontrol_data, 0x03000000);
808 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
809 W_REG(&cc->pllcontrol_data, 0x00000000);
810 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
811 W_REG(&cc->pllcontrol_data, 0x200005c0);
812 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
813 W_REG(&cc->pllcontrol_data, 0x88888815);
819 case BCM4319_CHIP_ID:
820 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
821 W_REG(&cc->pllcontrol_data, 0x11100070);
822 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
823 W_REG(&cc->pllcontrol_data, 0x1014140a);
824 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
825 W_REG(&cc->pllcontrol_data, 0x88888854);
827 if (spuravoid == 1) {
828 /* spur_avoid ON, so enable 41/82/164Mhz clock mode */
829 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
830 W_REG(&cc->pllcontrol_data, 0x05201828);
832 /* enable 40/80/160Mhz clock mode */
833 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
834 W_REG(&cc->pllcontrol_data, 0x05001828);
837 case BCM4336_CHIP_ID:
838 /* Looks like these are only for default xtal freq 26MHz */
839 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
840 W_REG(&cc->pllcontrol_data, 0x02100020);
842 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
843 W_REG(&cc->pllcontrol_data, 0x0C0C0C0C);
845 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
846 W_REG(&cc->pllcontrol_data, 0x01240C0C);
848 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
849 W_REG(&cc->pllcontrol_data, 0x202C2820);
851 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
852 W_REG(&cc->pllcontrol_data, 0x88888825);
854 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
856 W_REG(&cc->pllcontrol_data, 0x00EC4EC4);
858 W_REG(&cc->pllcontrol_data, 0x00762762);
860 tmp = PCTL_PLL_PLLCTL_UPD;
868 tmp |= R_REG(&cc->pmucontrol);
869 W_REG(&cc->pmucontrol, tmp);
872 /* select default xtal frequency for each chip */
873 static const pmu1_xtaltab0_t *si_pmu1_xtaldef0(si_t *sih)
876 case BCM4329_CHIP_ID:
877 /* Default to 38400Khz */
878 return &pmu1_xtaltab0_880_4329[PMU1_XTALTAB0_880_38400K];
879 case BCM4319_CHIP_ID:
880 /* Default to 30000Khz */
881 return &pmu1_xtaltab0_1440[PMU1_XTALTAB0_1440_30000K];
882 case BCM4336_CHIP_ID:
883 /* Default to 26000Khz */
884 return &pmu1_xtaltab0_960[PMU1_XTALTAB0_960_26000K];
885 case BCM4330_CHIP_ID:
886 /* Default to 37400Khz */
887 if (CST4330_CHIPMODE_SDIOD(sih->chipst))
888 return &pmu1_xtaltab0_960[PMU1_XTALTAB0_960_37400K];
890 return &pmu1_xtaltab0_1440[PMU1_XTALTAB0_1440_37400K];
897 /* select xtal table for each chip */
898 static const pmu1_xtaltab0_t *si_pmu1_xtaltab0(si_t *sih)
901 case BCM4329_CHIP_ID:
902 return pmu1_xtaltab0_880_4329;
903 case BCM4319_CHIP_ID:
904 return pmu1_xtaltab0_1440;
905 case BCM4336_CHIP_ID:
906 return pmu1_xtaltab0_960;
907 case BCM4330_CHIP_ID:
908 if (CST4330_CHIPMODE_SDIOD(sih->chipst))
909 return pmu1_xtaltab0_960;
911 return pmu1_xtaltab0_1440;
918 /* query alp/xtal clock frequency */
920 si_pmu1_alpclk0(si_t *sih, chipcregs_t *cc)
922 const pmu1_xtaltab0_t *xt;
925 /* Find the frequency in the table */
926 xf = (R_REG(&cc->pmucontrol) & PCTL_XTALFREQ_MASK) >>
928 for (xt = si_pmu1_xtaltab0(sih); xt != NULL && xt->fref != 0; xt++)
931 /* Could not find it so assign a default value */
932 if (xt == NULL || xt->fref == 0)
933 xt = si_pmu1_xtaldef0(sih);
934 return xt->fref * 1000;
937 /* select default pll fvco for each chip */
938 static u32 si_pmu1_pllfvco0(si_t *sih)
941 case BCM4329_CHIP_ID:
943 case BCM4319_CHIP_ID:
945 case BCM4336_CHIP_ID:
947 case BCM4330_CHIP_ID:
948 if (CST4330_CHIPMODE_SDIOD(sih->chipst))
958 static void si_pmu_set_4330_plldivs(si_t *sih)
960 u32 FVCO = si_pmu1_pllfvco0(sih) / 1000;
961 u32 m1div, m2div, m3div, m4div, m5div, m6div;
964 m2div = m3div = m4div = m6div = FVCO / 80;
967 if (CST4330_CHIPMODE_SDIOD(sih->chipst))
972 (m1div << PMU1_PLL0_PC1_M1DIV_SHIFT) | (m2div <<
973 PMU1_PLL0_PC1_M2DIV_SHIFT) |
974 (m3div << PMU1_PLL0_PC1_M3DIV_SHIFT) | (m4div <<
975 PMU1_PLL0_PC1_M4DIV_SHIFT);
976 si_pmu_pllcontrol(sih, PMU1_PLL0_PLLCTL1, ~0, pllc1);
978 pllc2 = si_pmu_pllcontrol(sih, PMU1_PLL0_PLLCTL1, 0, 0);
979 pllc2 &= ~(PMU1_PLL0_PC2_M5DIV_MASK | PMU1_PLL0_PC2_M6DIV_MASK);
981 ((m5div << PMU1_PLL0_PC2_M5DIV_SHIFT) |
982 (m6div << PMU1_PLL0_PC2_M6DIV_SHIFT));
983 si_pmu_pllcontrol(sih, PMU1_PLL0_PLLCTL2, ~0, pllc2);
986 /* Set up PLL registers in the PMU as per the crystal speed.
987 * XtalFreq field in pmucontrol register being 0 indicates the PLL
988 * is not programmed and the h/w default is assumed to work, in which
989 * case the xtal frequency is unknown to the s/w so we need to call
990 * si_pmu1_xtaldef0() wherever it is needed to return a default value.
992 static void si_pmu1_pllinit0(si_t *sih, chipcregs_t *cc, u32 xtal)
994 const pmu1_xtaltab0_t *xt;
996 u32 buf_strength = 0;
999 /* Use h/w default PLL config */
1004 /* Find the frequency in the table */
1005 for (xt = si_pmu1_xtaltab0(sih); xt != NULL && xt->fref != 0; xt++)
1006 if (xt->fref == xtal)
1009 /* Check current PLL state, bail out if it has been programmed or
1010 * we don't know how to program it.
1012 if (xt == NULL || xt->fref == 0) {
1015 /* for 4319 bootloader already programs the PLL but bootloader does not
1016 * program the PLL4 and PLL5. So Skip this check for 4319
1018 if ((((R_REG(&cc->pmucontrol) & PCTL_XTALFREQ_MASK) >>
1019 PCTL_XTALFREQ_SHIFT) == xt->xf) &&
1020 !((sih->chip == BCM4319_CHIP_ID)
1021 || (sih->chip == BCM4330_CHIP_ID)))
1024 switch (sih->chip) {
1025 case BCM4329_CHIP_ID:
1026 /* Change the BBPLL drive strength to 8 for all channels */
1027 buf_strength = 0x888888;
1028 AND_REG(&cc->min_res_mask,
1029 ~(PMURES_BIT(RES4329_BBPLL_PWRSW_PU) |
1030 PMURES_BIT(RES4329_HT_AVAIL)));
1031 AND_REG(&cc->max_res_mask,
1032 ~(PMURES_BIT(RES4329_BBPLL_PWRSW_PU) |
1033 PMURES_BIT(RES4329_HT_AVAIL)));
1034 SPINWAIT(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL,
1035 PMU_MAX_TRANSITION_DLY);
1036 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
1037 if (xt->fref == 38400)
1039 else if (xt->fref == 37400)
1041 else if (xt->fref == 26000)
1044 tmp = 0x200005C0; /* Chip Dflt Settings */
1045 W_REG(&cc->pllcontrol_data, tmp);
1046 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
1048 R_REG(&cc->pllcontrol_data) & PMU1_PLL0_PC5_CLK_DRV_MASK;
1049 if ((xt->fref == 38400) || (xt->fref == 37400)
1050 || (xt->fref == 26000))
1053 tmp |= 0x25; /* Chip Dflt Settings */
1054 W_REG(&cc->pllcontrol_data, tmp);
1057 case BCM4319_CHIP_ID:
1058 /* Change the BBPLL drive strength to 2 for all channels */
1059 buf_strength = 0x222222;
1061 /* Make sure the PLL is off */
1062 /* WAR65104: Disable the HT_AVAIL resource first and then
1063 * after a delay (more than downtime for HT_AVAIL) remove the
1064 * BBPLL resource; backplane clock moves to ALP from HT.
1066 AND_REG(&cc->min_res_mask,
1067 ~(PMURES_BIT(RES4319_HT_AVAIL)));
1068 AND_REG(&cc->max_res_mask,
1069 ~(PMURES_BIT(RES4319_HT_AVAIL)));
1072 AND_REG(&cc->min_res_mask,
1073 ~(PMURES_BIT(RES4319_BBPLL_PWRSW_PU)));
1074 AND_REG(&cc->max_res_mask,
1075 ~(PMURES_BIT(RES4319_BBPLL_PWRSW_PU)));
1078 SPINWAIT(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL,
1079 PMU_MAX_TRANSITION_DLY);
1080 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
1082 W_REG(&cc->pllcontrol_data, tmp);
1085 case BCM4336_CHIP_ID:
1086 AND_REG(&cc->min_res_mask,
1087 ~(PMURES_BIT(RES4336_HT_AVAIL) |
1088 PMURES_BIT(RES4336_MACPHY_CLKAVAIL)));
1089 AND_REG(&cc->max_res_mask,
1090 ~(PMURES_BIT(RES4336_HT_AVAIL) |
1091 PMURES_BIT(RES4336_MACPHY_CLKAVAIL)));
1093 SPINWAIT(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL,
1094 PMU_MAX_TRANSITION_DLY);
1097 case BCM4330_CHIP_ID:
1098 AND_REG(&cc->min_res_mask,
1099 ~(PMURES_BIT(RES4330_HT_AVAIL) |
1100 PMURES_BIT(RES4330_MACPHY_CLKAVAIL)));
1101 AND_REG(&cc->max_res_mask,
1102 ~(PMURES_BIT(RES4330_HT_AVAIL) |
1103 PMURES_BIT(RES4330_MACPHY_CLKAVAIL)));
1105 SPINWAIT(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL,
1106 PMU_MAX_TRANSITION_DLY);
1113 /* Write p1div and p2div to pllcontrol[0] */
1114 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
1115 tmp = R_REG(&cc->pllcontrol_data) &
1116 ~(PMU1_PLL0_PC0_P1DIV_MASK | PMU1_PLL0_PC0_P2DIV_MASK);
1119 p1div << PMU1_PLL0_PC0_P1DIV_SHIFT) & PMU1_PLL0_PC0_P1DIV_MASK) |
1121 p2div << PMU1_PLL0_PC0_P2DIV_SHIFT) & PMU1_PLL0_PC0_P2DIV_MASK);
1122 W_REG(&cc->pllcontrol_data, tmp);
1124 if ((sih->chip == BCM4330_CHIP_ID))
1125 si_pmu_set_4330_plldivs(sih);
1127 if ((sih->chip == BCM4329_CHIP_ID)
1128 && (sih->chiprev == 0)) {
1130 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
1131 tmp = R_REG(&cc->pllcontrol_data);
1132 tmp = tmp & (~DOT11MAC_880MHZ_CLK_DIVISOR_MASK);
1133 tmp = tmp | DOT11MAC_880MHZ_CLK_DIVISOR_VAL;
1134 W_REG(&cc->pllcontrol_data, tmp);
1136 if ((sih->chip == BCM4319_CHIP_ID) ||
1137 (sih->chip == BCM4336_CHIP_ID) ||
1138 (sih->chip == BCM4330_CHIP_ID))
1139 ndiv_mode = PMU1_PLL0_PC2_NDIV_MODE_MFB;
1141 ndiv_mode = PMU1_PLL0_PC2_NDIV_MODE_MASH;
1143 /* Write ndiv_int and ndiv_mode to pllcontrol[2] */
1144 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
1145 tmp = R_REG(&cc->pllcontrol_data) &
1146 ~(PMU1_PLL0_PC2_NDIV_INT_MASK | PMU1_PLL0_PC2_NDIV_MODE_MASK);
1149 ndiv_int << PMU1_PLL0_PC2_NDIV_INT_SHIFT) &
1150 PMU1_PLL0_PC2_NDIV_INT_MASK) | ((ndiv_mode <<
1151 PMU1_PLL0_PC2_NDIV_MODE_SHIFT) &
1152 PMU1_PLL0_PC2_NDIV_MODE_MASK);
1153 W_REG(&cc->pllcontrol_data, tmp);
1155 /* Write ndiv_frac to pllcontrol[3] */
1156 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
1157 tmp = R_REG(&cc->pllcontrol_data) & ~PMU1_PLL0_PC3_NDIV_FRAC_MASK;
1158 tmp |= ((xt->ndiv_frac << PMU1_PLL0_PC3_NDIV_FRAC_SHIFT) &
1159 PMU1_PLL0_PC3_NDIV_FRAC_MASK);
1160 W_REG(&cc->pllcontrol_data, tmp);
1162 /* Write clock driving strength to pllcontrol[5] */
1164 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
1166 R_REG(&cc->pllcontrol_data) & ~PMU1_PLL0_PC5_CLK_DRV_MASK;
1167 tmp |= (buf_strength << PMU1_PLL0_PC5_CLK_DRV_SHIFT);
1168 W_REG(&cc->pllcontrol_data, tmp);
1171 /* to operate the 4319 usb in 24MHz/48MHz; chipcontrol[2][84:83] needs
1174 if ((sih->chip == BCM4319_CHIP_ID)
1175 && (xt->fref != XTAL_FREQ_30000MHZ)) {
1176 W_REG(&cc->chipcontrol_addr, PMU1_PLL0_CHIPCTL2);
1178 R_REG(&cc->chipcontrol_data) & ~CCTL_4319USB_XTAL_SEL_MASK;
1179 if (xt->fref == XTAL_FREQ_24000MHZ) {
1181 (CCTL_4319USB_24MHZ_PLL_SEL <<
1182 CCTL_4319USB_XTAL_SEL_SHIFT);
1183 } else if (xt->fref == XTAL_FREQ_48000MHZ) {
1185 (CCTL_4319USB_48MHZ_PLL_SEL <<
1186 CCTL_4319USB_XTAL_SEL_SHIFT);
1188 W_REG(&cc->chipcontrol_data, tmp);
1191 /* Flush deferred pll control registers writes */
1192 if (sih->pmurev >= 2)
1193 OR_REG(&cc->pmucontrol, PCTL_PLL_PLLCTL_UPD);
1195 /* Write XtalFreq. Set the divisor also. */
1196 tmp = R_REG(&cc->pmucontrol) &
1197 ~(PCTL_ILP_DIV_MASK | PCTL_XTALFREQ_MASK);
1198 tmp |= (((((xt->fref + 127) / 128) - 1) << PCTL_ILP_DIV_SHIFT) &
1199 PCTL_ILP_DIV_MASK) |
1200 ((xt->xf << PCTL_XTALFREQ_SHIFT) & PCTL_XTALFREQ_MASK);
1202 if ((sih->chip == BCM4329_CHIP_ID)
1203 && sih->chiprev == 0) {
1204 /* clear the htstretch before clearing HTReqEn */
1205 AND_REG(&cc->clkstretch, ~CSTRETCH_HT);
1206 tmp &= ~PCTL_HT_REQ_EN;
1209 W_REG(&cc->pmucontrol, tmp);
1212 u32 si_pmu_ilp_clock(si_t *sih)
1214 static u32 ilpcycles_per_sec;
1216 if (ISSIM_ENAB(sih))
1219 if (ilpcycles_per_sec == 0) {
1220 u32 start, end, delta;
1221 u32 origidx = ai_coreidx(sih);
1222 chipcregs_t *cc = si_setcoreidx(sih, SI_CC_IDX);
1224 start = R_REG(&cc->pmutimer);
1225 mdelay(ILP_CALC_DUR);
1226 end = R_REG(&cc->pmutimer);
1227 delta = end - start;
1228 ilpcycles_per_sec = delta * (1000 / ILP_CALC_DUR);
1229 si_setcoreidx(sih, origidx);
1232 return ilpcycles_per_sec;
1235 void si_pmu_set_ldo_voltage(si_t *sih, u8 ldo, u8 voltage)
1237 u8 sr_cntl_shift = 0, rc_shift = 0, shift = 0, mask = 0;
1240 switch (sih->chip) {
1241 case BCM4336_CHIP_ID:
1243 case SET_LDO_VOLTAGE_CLDO_PWM:
1248 case SET_LDO_VOLTAGE_CLDO_BURST:
1253 case SET_LDO_VOLTAGE_LNLDO1:
1262 case BCM4330_CHIP_ID:
1264 case SET_LDO_VOLTAGE_CBUCK_PWM:
1277 shift = sr_cntl_shift + rc_shift;
1279 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, regcontrol_addr),
1281 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, regcontrol_data),
1282 mask << shift, (voltage & mask) << shift);
1285 u16 si_pmu_fast_pwrup_delay(si_t *sih)
1287 uint delay = PMU_MAX_TRANSITION_DLY;
1292 chn[0] = 0; /* to suppress compile error */
1295 /* Remember original core before switch to chipc */
1296 origidx = ai_coreidx(sih);
1297 cc = si_setcoreidx(sih, SI_CC_IDX);
1299 switch (sih->chip) {
1300 case BCM43224_CHIP_ID:
1301 case BCM43225_CHIP_ID:
1302 case BCM43421_CHIP_ID:
1303 case BCM43235_CHIP_ID:
1304 case BCM43236_CHIP_ID:
1305 case BCM43238_CHIP_ID:
1306 case BCM4331_CHIP_ID:
1307 case BCM6362_CHIP_ID:
1308 case BCM4313_CHIP_ID:
1309 delay = ISSIM_ENAB(sih) ? 70 : 3700;
1311 case BCM4329_CHIP_ID:
1312 if (ISSIM_ENAB(sih))
1315 u32 ilp = si_ilp_clock(sih);
1317 (si_pmu_res_uptime(sih, cc, RES4329_HT_AVAIL) +
1318 D11SCC_SLOW2FAST_TRANSITION) * ((1000000 + ilp -
1320 delay = (11 * delay) / 10;
1323 case BCM4319_CHIP_ID:
1324 delay = ISSIM_ENAB(sih) ? 70 : 3700;
1326 case BCM4336_CHIP_ID:
1327 if (ISSIM_ENAB(sih))
1330 u32 ilp = si_ilp_clock(sih);
1332 (si_pmu_res_uptime(sih, cc, RES4336_HT_AVAIL) +
1333 D11SCC_SLOW2FAST_TRANSITION) * ((1000000 + ilp -
1335 delay = (11 * delay) / 10;
1338 case BCM4330_CHIP_ID:
1339 if (ISSIM_ENAB(sih))
1342 u32 ilp = si_ilp_clock(sih);
1344 (si_pmu_res_uptime(sih, cc, RES4330_HT_AVAIL) +
1345 D11SCC_SLOW2FAST_TRANSITION) * ((1000000 + ilp -
1347 delay = (11 * delay) / 10;
1353 /* Return to original core */
1354 si_setcoreidx(sih, origidx);
1359 void si_pmu_sprom_enable(si_t *sih, bool enable)
1364 /* Remember original core before switch to chipc */
1365 origidx = ai_coreidx(sih);
1366 cc = si_setcoreidx(sih, SI_CC_IDX);
1368 /* Return to original core */
1369 si_setcoreidx(sih, origidx);
1372 /* Read/write a chipcontrol reg */
1373 u32 si_pmu_chipcontrol(si_t *sih, uint reg, u32 mask, u32 val)
1375 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, chipcontrol_addr), ~0,
1377 return si_corereg(sih, SI_CC_IDX,
1378 offsetof(chipcregs_t, chipcontrol_data), mask, val);
1381 /* Read/write a regcontrol reg */
1382 u32 si_pmu_regcontrol(si_t *sih, uint reg, u32 mask, u32 val)
1384 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, regcontrol_addr), ~0,
1386 return si_corereg(sih, SI_CC_IDX,
1387 offsetof(chipcregs_t, regcontrol_data), mask, val);
1390 /* Read/write a pllcontrol reg */
1391 u32 si_pmu_pllcontrol(si_t *sih, uint reg, u32 mask, u32 val)
1393 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, pllcontrol_addr), ~0,
1395 return si_corereg(sih, SI_CC_IDX,
1396 offsetof(chipcregs_t, pllcontrol_data), mask, val);
1399 /* PMU PLL update */
1400 void si_pmu_pllupd(si_t *sih)
1402 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, pmucontrol),
1403 PCTL_PLL_PLLCTL_UPD, PCTL_PLL_PLLCTL_UPD);
1406 /* query alp/xtal clock frequency */
1407 u32 si_pmu_alp_clock(si_t *sih)
1411 u32 clock = ALP_CLOCK;
1413 /* bail out with default */
1414 if (!PMUCTL_ENAB(sih))
1417 /* Remember original core before switch to chipc */
1418 origidx = ai_coreidx(sih);
1419 cc = si_setcoreidx(sih, SI_CC_IDX);
1421 switch (sih->chip) {
1422 case BCM43224_CHIP_ID:
1423 case BCM43225_CHIP_ID:
1424 case BCM43421_CHIP_ID:
1425 case BCM43235_CHIP_ID:
1426 case BCM43236_CHIP_ID:
1427 case BCM43238_CHIP_ID:
1428 case BCM4331_CHIP_ID:
1429 case BCM6362_CHIP_ID:
1430 case BCM4716_CHIP_ID:
1431 case BCM4748_CHIP_ID:
1432 case BCM47162_CHIP_ID:
1433 case BCM4313_CHIP_ID:
1434 case BCM5357_CHIP_ID:
1436 clock = 20000 * 1000;
1438 case BCM4329_CHIP_ID:
1439 case BCM4319_CHIP_ID:
1440 case BCM4336_CHIP_ID:
1441 case BCM4330_CHIP_ID:
1443 clock = si_pmu1_alpclk0(sih, cc);
1445 case BCM5356_CHIP_ID:
1447 clock = 25000 * 1000;
1453 /* Return to original core */
1454 si_setcoreidx(sih, origidx);
1458 void si_pmu_spuravoid(si_t *sih, u8 spuravoid)
1461 uint origidx, intr_val;
1464 /* Remember original core before switch to chipc */
1465 cc = (chipcregs_t *) si_switch_core(sih, CC_CORE_ID, &origidx,
1468 /* force the HT off */
1469 if (sih->chip == BCM4336_CHIP_ID) {
1470 tmp = R_REG(&cc->max_res_mask);
1471 tmp &= ~RES4336_HT_AVAIL;
1472 W_REG(&cc->max_res_mask, tmp);
1473 /* wait for the ht to really go away */
1474 SPINWAIT(((R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL) == 0),
1476 ASSERT((R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL) == 0);
1479 /* update the pll changes */
1480 si_pmu_spuravoid_pllupdate(sih, cc, spuravoid);
1482 /* enable HT back on */
1483 if (sih->chip == BCM4336_CHIP_ID) {
1484 tmp = R_REG(&cc->max_res_mask);
1485 tmp |= RES4336_HT_AVAIL;
1486 W_REG(&cc->max_res_mask, tmp);
1489 /* Return to original core */
1490 si_restore_core(sih, origidx, intr_val);
1493 /* initialize PMU */
1494 void si_pmu_init(si_t *sih)
1499 /* Remember original core before switch to chipc */
1500 origidx = ai_coreidx(sih);
1501 cc = si_setcoreidx(sih, SI_CC_IDX);
1503 if (sih->pmurev == 1)
1504 AND_REG(&cc->pmucontrol, ~PCTL_NOILP_ON_WAIT);
1505 else if (sih->pmurev >= 2)
1506 OR_REG(&cc->pmucontrol, PCTL_NOILP_ON_WAIT);
1508 if ((sih->chip == BCM4329_CHIP_ID) && (sih->chiprev == 2)) {
1509 /* Fix for 4329b0 bad LPOM state. */
1510 W_REG(&cc->regcontrol_addr, 2);
1511 OR_REG(&cc->regcontrol_data, 0x100);
1513 W_REG(&cc->regcontrol_addr, 3);
1514 OR_REG(&cc->regcontrol_data, 0x4);
1517 /* Return to original core */
1518 si_setcoreidx(sih, origidx);
1521 /* initialize PMU chip controls and other chip level stuff */
1522 void si_pmu_chip_init(si_t *sih)
1527 /* Gate off SPROM clock and chip select signals */
1528 si_pmu_sprom_enable(sih, false);
1530 /* Remember original core */
1531 origidx = ai_coreidx(sih);
1533 /* Return to original core */
1534 si_setcoreidx(sih, origidx);
1537 /* initialize PMU switch/regulators */
1538 void si_pmu_swreg_init(si_t *sih)
1541 switch (sih->chip) {
1542 case BCM4336_CHIP_ID:
1543 /* Reduce CLDO PWM output voltage to 1.2V */
1544 si_pmu_set_ldo_voltage(sih, SET_LDO_VOLTAGE_CLDO_PWM, 0xe);
1545 /* Reduce CLDO BURST output voltage to 1.2V */
1546 si_pmu_set_ldo_voltage(sih, SET_LDO_VOLTAGE_CLDO_BURST,
1548 /* Reduce LNLDO1 output voltage to 1.2V */
1549 si_pmu_set_ldo_voltage(sih, SET_LDO_VOLTAGE_LNLDO1, 0xe);
1550 if (sih->chiprev == 0)
1551 si_pmu_regcontrol(sih, 2, 0x400000, 0x400000);
1554 case BCM4330_CHIP_ID:
1555 /* CBUCK Voltage is 1.8 by default and set that to 1.5 */
1556 si_pmu_set_ldo_voltage(sih, SET_LDO_VOLTAGE_CBUCK_PWM, 0);
1563 /* initialize PLL */
1564 void si_pmu_pll_init(si_t *sih, uint xtalfreq)
1570 /* Remember original core before switch to chipc */
1571 origidx = ai_coreidx(sih);
1572 cc = si_setcoreidx(sih, SI_CC_IDX);
1574 switch (sih->chip) {
1575 case BCM4329_CHIP_ID:
1578 si_pmu1_pllinit0(sih, cc, xtalfreq);
1580 case BCM4313_CHIP_ID:
1581 case BCM43224_CHIP_ID:
1582 case BCM43225_CHIP_ID:
1583 case BCM43421_CHIP_ID:
1584 case BCM43235_CHIP_ID:
1585 case BCM43236_CHIP_ID:
1586 case BCM43238_CHIP_ID:
1587 case BCM4331_CHIP_ID:
1588 case BCM6362_CHIP_ID:
1591 case BCM4319_CHIP_ID:
1592 case BCM4336_CHIP_ID:
1593 case BCM4330_CHIP_ID:
1594 si_pmu1_pllinit0(sih, cc, xtalfreq);
1600 /* Return to original core */
1601 si_setcoreidx(sih, origidx);
1604 /* initialize PMU resources */
1605 void si_pmu_res_init(si_t *sih)
1609 const pmu_res_updown_t *pmu_res_updown_table = NULL;
1610 uint pmu_res_updown_table_sz = 0;
1611 const pmu_res_depend_t *pmu_res_depend_table = NULL;
1612 uint pmu_res_depend_table_sz = 0;
1613 u32 min_mask = 0, max_mask = 0;
1617 /* Remember original core before switch to chipc */
1618 origidx = ai_coreidx(sih);
1619 cc = si_setcoreidx(sih, SI_CC_IDX);
1621 switch (sih->chip) {
1622 case BCM4329_CHIP_ID:
1623 /* Optimize resources up/down timers */
1624 if (ISSIM_ENAB(sih)) {
1625 pmu_res_updown_table = NULL;
1626 pmu_res_updown_table_sz = 0;
1628 pmu_res_updown_table = bcm4329_res_updown;
1629 pmu_res_updown_table_sz =
1630 ARRAY_SIZE(bcm4329_res_updown);
1632 /* Optimize resources dependencies */
1633 pmu_res_depend_table = bcm4329_res_depend;
1634 pmu_res_depend_table_sz = ARRAY_SIZE(bcm4329_res_depend);
1637 case BCM4319_CHIP_ID:
1638 /* Optimize resources up/down timers */
1639 if (ISSIM_ENAB(sih)) {
1640 pmu_res_updown_table = bcm4319a0_res_updown_qt;
1641 pmu_res_updown_table_sz =
1642 ARRAY_SIZE(bcm4319a0_res_updown_qt);
1644 pmu_res_updown_table = bcm4319a0_res_updown;
1645 pmu_res_updown_table_sz =
1646 ARRAY_SIZE(bcm4319a0_res_updown);
1648 /* Optimize resources dependancies masks */
1649 pmu_res_depend_table = bcm4319a0_res_depend;
1650 pmu_res_depend_table_sz = ARRAY_SIZE(bcm4319a0_res_depend);
1653 case BCM4336_CHIP_ID:
1654 /* Optimize resources up/down timers */
1655 if (ISSIM_ENAB(sih)) {
1656 pmu_res_updown_table = bcm4336a0_res_updown_qt;
1657 pmu_res_updown_table_sz =
1658 ARRAY_SIZE(bcm4336a0_res_updown_qt);
1660 pmu_res_updown_table = bcm4336a0_res_updown;
1661 pmu_res_updown_table_sz =
1662 ARRAY_SIZE(bcm4336a0_res_updown);
1664 /* Optimize resources dependancies masks */
1665 pmu_res_depend_table = bcm4336a0_res_depend;
1666 pmu_res_depend_table_sz = ARRAY_SIZE(bcm4336a0_res_depend);
1669 case BCM4330_CHIP_ID:
1670 /* Optimize resources up/down timers */
1671 if (ISSIM_ENAB(sih)) {
1672 pmu_res_updown_table = bcm4330a0_res_updown_qt;
1673 pmu_res_updown_table_sz =
1674 ARRAY_SIZE(bcm4330a0_res_updown_qt);
1676 pmu_res_updown_table = bcm4330a0_res_updown;
1677 pmu_res_updown_table_sz =
1678 ARRAY_SIZE(bcm4330a0_res_updown);
1680 /* Optimize resources dependancies masks */
1681 pmu_res_depend_table = bcm4330a0_res_depend;
1682 pmu_res_depend_table_sz = ARRAY_SIZE(bcm4330a0_res_depend);
1690 rsrcs = (sih->pmucaps & PCAP_RC_MASK) >> PCAP_RC_SHIFT;
1692 /* Program up/down timers */
1693 while (pmu_res_updown_table_sz--) {
1694 W_REG(&cc->res_table_sel,
1695 pmu_res_updown_table[pmu_res_updown_table_sz].resnum);
1696 W_REG(&cc->res_updn_timer,
1697 pmu_res_updown_table[pmu_res_updown_table_sz].updown);
1699 /* Apply nvram overrides to up/down timers */
1700 for (i = 0; i < rsrcs; i++) {
1701 snprintf(name, sizeof(name), "r%dt", i);
1702 val = getvar(NULL, name);
1705 W_REG(&cc->res_table_sel, (u32) i);
1706 W_REG(&cc->res_updn_timer,
1707 (u32) simple_strtoul(val, NULL, 0));
1710 /* Program resource dependencies table */
1711 while (pmu_res_depend_table_sz--) {
1712 if (pmu_res_depend_table[pmu_res_depend_table_sz].filter != NULL
1713 && !(pmu_res_depend_table[pmu_res_depend_table_sz].
1716 for (i = 0; i < rsrcs; i++) {
1717 if ((pmu_res_depend_table[pmu_res_depend_table_sz].
1718 res_mask & PMURES_BIT(i)) == 0)
1720 W_REG(&cc->res_table_sel, i);
1721 switch (pmu_res_depend_table[pmu_res_depend_table_sz].
1723 case RES_DEPEND_SET:
1724 W_REG(&cc->res_dep_mask,
1725 pmu_res_depend_table
1726 [pmu_res_depend_table_sz].depend_mask);
1728 case RES_DEPEND_ADD:
1729 OR_REG(&cc->res_dep_mask,
1730 pmu_res_depend_table
1731 [pmu_res_depend_table_sz].depend_mask);
1733 case RES_DEPEND_REMOVE:
1734 AND_REG(&cc->res_dep_mask,
1735 ~pmu_res_depend_table
1736 [pmu_res_depend_table_sz].depend_mask);
1744 /* Apply nvram overrides to dependancies masks */
1745 for (i = 0; i < rsrcs; i++) {
1746 snprintf(name, sizeof(name), "r%dd", i);
1747 val = getvar(NULL, name);
1750 W_REG(&cc->res_table_sel, (u32) i);
1751 W_REG(&cc->res_dep_mask,
1752 (u32) simple_strtoul(val, NULL, 0));
1755 /* Determine min/max rsrc masks */
1756 si_pmu_res_masks(sih, &min_mask, &max_mask);
1758 /* It is required to program max_mask first and then min_mask */
1760 /* Program max resource mask */
1763 W_REG(&cc->max_res_mask, max_mask);
1765 /* Program min resource mask */
1768 W_REG(&cc->min_res_mask, min_mask);
1770 /* Add some delay; allow resources to come up and settle. */
1773 /* Return to original core */
1774 si_setcoreidx(sih, origidx);
1777 u32 si_pmu_measure_alpclk(si_t *sih)
1783 if (sih->pmurev < 10)
1787 /* Remember original core before switch to chipc */
1788 origidx = ai_coreidx(sih);
1789 cc = si_setcoreidx(sih, SI_CC_IDX);
1792 if (R_REG(&cc->pmustatus) & PST_EXTLPOAVAIL) {
1793 u32 ilp_ctr, alp_hz;
1796 * Enable the reg to measure the freq,
1797 * in case it was disabled before
1799 W_REG(&cc->pmu_xtalfreq,
1800 1U << PMU_XTALFREQ_REG_MEASURE_SHIFT);
1802 /* Delay for well over 4 ILP clocks */
1805 /* Read the latched number of ALP ticks per 4 ILP ticks */
1807 R_REG(&cc->pmu_xtalfreq) & PMU_XTALFREQ_REG_ILPCTR_MASK;
1810 * Turn off the PMU_XTALFREQ_REG_MEASURE_SHIFT
1813 W_REG(&cc->pmu_xtalfreq, 0);
1815 /* Calculate ALP frequency */
1816 alp_hz = (ilp_ctr * EXT_ILP_HZ) / 4;
1819 * Round to nearest 100KHz, and at
1820 * the same time convert to KHz
1822 alp_khz = (alp_hz + 50000) / 100000 * 100;
1826 /* Return to original core */
1827 si_setcoreidx(sih, origidx);
1832 bool si_pmu_is_otp_powered(si_t *sih)
1838 /* Remember original core before switch to chipc */
1839 idx = ai_coreidx(sih);
1840 cc = si_setcoreidx(sih, SI_CC_IDX);
1842 switch (sih->chip) {
1843 case BCM4329_CHIP_ID:
1844 st = (R_REG(&cc->res_state) & PMURES_BIT(RES4329_OTP_PU))
1847 case BCM4319_CHIP_ID:
1848 st = (R_REG(&cc->res_state) & PMURES_BIT(RES4319_OTP_PU))
1851 case BCM4336_CHIP_ID:
1852 st = (R_REG(&cc->res_state) & PMURES_BIT(RES4336_OTP_PU))
1855 case BCM4330_CHIP_ID:
1856 st = (R_REG(&cc->res_state) & PMURES_BIT(RES4330_OTP_PU))
1860 /* These chip doesn't use PMU bit to power up/down OTP. OTP always on.
1861 * Use OTP_INIT command to reset/refresh state.
1863 case BCM43224_CHIP_ID:
1864 case BCM43225_CHIP_ID:
1865 case BCM43421_CHIP_ID:
1866 case BCM43236_CHIP_ID:
1867 case BCM43235_CHIP_ID:
1868 case BCM43238_CHIP_ID:
1876 /* Return to original core */
1877 si_setcoreidx(sih, idx);
1881 /* power up/down OTP through PMU resources */
1882 void si_pmu_otp_power(si_t *sih, bool on)
1886 u32 rsrcs = 0; /* rsrcs to turn on/off OTP power */
1888 /* Don't do anything if OTP is disabled */
1889 if (si_is_otp_disabled(sih)) {
1893 /* Remember original core before switch to chipc */
1894 origidx = ai_coreidx(sih);
1895 cc = si_setcoreidx(sih, SI_CC_IDX);
1897 switch (sih->chip) {
1898 case BCM4329_CHIP_ID:
1899 rsrcs = PMURES_BIT(RES4329_OTP_PU);
1901 case BCM4319_CHIP_ID:
1902 rsrcs = PMURES_BIT(RES4319_OTP_PU);
1904 case BCM4336_CHIP_ID:
1905 rsrcs = PMURES_BIT(RES4336_OTP_PU);
1907 case BCM4330_CHIP_ID:
1908 rsrcs = PMURES_BIT(RES4330_OTP_PU);
1917 /* Figure out the dependancies (exclude min_res_mask) */
1918 u32 deps = si_pmu_res_deps(sih, cc, rsrcs, true);
1919 u32 min_mask = 0, max_mask = 0;
1920 si_pmu_res_masks(sih, &min_mask, &max_mask);
1922 /* Turn on/off the power */
1924 OR_REG(&cc->min_res_mask, (rsrcs | deps));
1925 SPINWAIT(!(R_REG(&cc->res_state) & rsrcs),
1926 PMU_MAX_TRANSITION_DLY);
1928 AND_REG(&cc->min_res_mask, ~(rsrcs | deps));
1931 SPINWAIT((((otps = R_REG(&cc->otpstatus)) & OTPS_READY) !=
1932 (on ? OTPS_READY : 0)), 100);
1935 /* Return to original core */
1936 si_setcoreidx(sih, origidx);