2 * Freescale i.MX28 Boot PMIC init
4 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
5 * on behalf of DENX Software Engineering GmbH
7 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm/arch/imx-regs.h>
17 #ifdef CONFIG_SYS_MXS_VDD5V_ONLY
18 #define DCDC4P2_DROPOUT_CONFIG POWER_DCDC4P2_DROPOUT_CTRL_100MV | \
19 POWER_DCDC4P2_DROPOUT_CTRL_SRC_4P2
21 #define DCDC4P2_DROPOUT_CONFIG POWER_DCDC4P2_DROPOUT_CTRL_100MV | \
22 POWER_DCDC4P2_DROPOUT_CTRL_SRC_SEL
25 * mxs_power_clock2xtal() - Switch CPU core clock source to 24MHz XTAL
27 * This function switches the CPU core clock from PLL to 24MHz XTAL
28 * oscilator. This is necessary if the PLL is being reconfigured to
29 * prevent crash of the CPU core.
31 static void mxs_power_clock2xtal(void)
33 struct mxs_clkctrl_regs *clkctrl_regs =
34 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
36 debug("SPL: Switching CPU clock to 24MHz XTAL\n");
38 /* Set XTAL as CPU reference clock */
39 writel(CLKCTRL_CLKSEQ_BYPASS_CPU,
40 &clkctrl_regs->hw_clkctrl_clkseq_set);
44 * mxs_power_clock2pll() - Switch CPU core clock source to PLL
46 * This function switches the CPU core clock from 24MHz XTAL oscilator
47 * to PLL. This can only be called once the PLL has re-locked and once
48 * the PLL is stable after reconfiguration.
50 static void mxs_power_clock2pll(void)
52 struct mxs_clkctrl_regs *clkctrl_regs =
53 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
55 debug("SPL: Switching CPU core clock source to PLL\n");
58 * TODO: Are we really? It looks like we turn on PLL0, but we then
59 * set the CLKCTRL_CLKSEQ_BYPASS_CPU bit of the (which was already
60 * set by mxs_power_clock2xtal()). Clearing this bit here seems to
61 * introduce some instability (causing the CPU core to hang). Maybe
62 * we aren't giving PLL0 enough time to stabilise?
64 setbits_le32(&clkctrl_regs->hw_clkctrl_pll0ctrl0,
65 CLKCTRL_PLL0CTRL0_POWER);
69 * TODO: Should the PLL0 FORCE_LOCK bit be set here followed be a
70 * wait on the PLL0 LOCK bit?
72 setbits_le32(&clkctrl_regs->hw_clkctrl_clkseq,
73 CLKCTRL_CLKSEQ_BYPASS_CPU);
77 * mxs_power_set_auto_restart() - Set the auto-restart bit
79 * This function ungates the RTC block and sets the AUTO_RESTART
80 * bit to work around a design bug on MX28EVK Rev. A .
83 static void mxs_power_set_auto_restart(void)
85 struct mxs_rtc_regs *rtc_regs =
86 (struct mxs_rtc_regs *)MXS_RTC_BASE;
88 debug("SPL: Setting auto-restart bit\n");
90 writel(RTC_CTRL_SFTRST, &rtc_regs->hw_rtc_ctrl_clr);
91 while (readl(&rtc_regs->hw_rtc_ctrl) & RTC_CTRL_SFTRST)
94 writel(RTC_CTRL_CLKGATE, &rtc_regs->hw_rtc_ctrl_clr);
95 while (readl(&rtc_regs->hw_rtc_ctrl) & RTC_CTRL_CLKGATE)
98 /* Do nothing if flag already set */
99 if (readl(&rtc_regs->hw_rtc_persistent0) & RTC_PERSISTENT0_AUTO_RESTART)
102 while (readl(&rtc_regs->hw_rtc_stat) & RTC_STAT_NEW_REGS_MASK)
105 setbits_le32(&rtc_regs->hw_rtc_persistent0,
106 RTC_PERSISTENT0_AUTO_RESTART);
107 writel(RTC_CTRL_FORCE_UPDATE, &rtc_regs->hw_rtc_ctrl_set);
108 writel(RTC_CTRL_FORCE_UPDATE, &rtc_regs->hw_rtc_ctrl_clr);
109 while (readl(&rtc_regs->hw_rtc_stat) & RTC_STAT_NEW_REGS_MASK)
111 while (readl(&rtc_regs->hw_rtc_stat) & RTC_STAT_STALE_REGS_MASK)
116 * mxs_power_set_linreg() - Set linear regulators 25mV below DC-DC converter
118 * This function configures the VDDIO, VDDA and VDDD linear regulators output
119 * to be 25mV below the VDDIO, VDDA and VDDD output from the DC-DC switching
120 * converter. This is the recommended setting for the case where we use both
121 * linear regulators and DC-DC converter to power the VDDIO rail.
123 static void mxs_power_set_linreg(void)
125 struct mxs_power_regs *power_regs =
126 (struct mxs_power_regs *)MXS_POWER_BASE;
128 /* Set linear regulator 25mV below switching converter */
129 debug("SPL: Setting VDDD 25mV below DC-DC converters\n");
130 clrsetbits_le32(&power_regs->hw_power_vdddctrl,
131 POWER_VDDDCTRL_LINREG_OFFSET_MASK,
132 POWER_VDDDCTRL_LINREG_OFFSET_1STEPS_BELOW);
134 debug("SPL: Setting VDDA 25mV below DC-DC converters\n");
135 clrsetbits_le32(&power_regs->hw_power_vddactrl,
136 POWER_VDDACTRL_LINREG_OFFSET_MASK,
137 POWER_VDDACTRL_LINREG_OFFSET_1STEPS_BELOW);
139 debug("SPL: Setting VDDIO 25mV below DC-DC converters\n");
140 clrsetbits_le32(&power_regs->hw_power_vddioctrl,
141 POWER_VDDIOCTRL_LINREG_OFFSET_MASK,
142 POWER_VDDIOCTRL_LINREG_OFFSET_1STEPS_BELOW);
146 * mxs_get_batt_volt() - Measure battery input voltage
148 * This function retrieves the battery input voltage and returns it.
150 static int mxs_get_batt_volt(void)
152 struct mxs_power_regs *power_regs =
153 (struct mxs_power_regs *)MXS_POWER_BASE;
154 uint32_t volt = readl(&power_regs->hw_power_battmonitor);
155 volt &= POWER_BATTMONITOR_BATT_VAL_MASK;
156 volt >>= POWER_BATTMONITOR_BATT_VAL_OFFSET;
159 debug("SPL: Battery Voltage = %dmV\n", volt);
164 * mxs_is_batt_ready() - Test if the battery provides enough voltage to boot
166 * This function checks if the battery input voltage is higher than 3.6V and
167 * therefore allows the system to successfully boot using this power source.
169 static int mxs_is_batt_ready(void)
171 return (mxs_get_batt_volt() >= 3600);
175 * mxs_is_batt_good() - Test if battery is operational at all
177 * This function starts recharging the battery and tests if the input current
178 * provided by the 5V input recharging the battery is also sufficient to power
179 * the DC-DC converter.
181 static int mxs_is_batt_good(void)
183 struct mxs_power_regs *power_regs =
184 (struct mxs_power_regs *)MXS_POWER_BASE;
185 uint32_t volt = mxs_get_batt_volt();
187 if ((volt >= 2400) && (volt <= 4300)) {
188 debug("SPL: Battery is good\n");
192 clrsetbits_le32(&power_regs->hw_power_5vctrl,
193 POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK,
194 0x3 << POWER_5VCTRL_CHARGE_4P2_ILIMIT_OFFSET);
195 writel(POWER_5VCTRL_PWD_CHARGE_4P2_MASK,
196 &power_regs->hw_power_5vctrl_clr);
198 clrsetbits_le32(&power_regs->hw_power_charge,
199 POWER_CHARGE_STOP_ILIMIT_MASK | POWER_CHARGE_BATTCHRG_I_MASK,
200 POWER_CHARGE_STOP_ILIMIT_10MA | 0x3);
202 writel(POWER_CHARGE_PWD_BATTCHRG, &power_regs->hw_power_charge_clr);
203 writel(POWER_5VCTRL_PWD_CHARGE_4P2_MASK,
204 &power_regs->hw_power_5vctrl_clr);
208 volt = mxs_get_batt_volt();
211 debug("SPL: Battery Voltage too high\n");
216 debug("SPL: Battery is good\n");
220 writel(POWER_CHARGE_STOP_ILIMIT_MASK | POWER_CHARGE_BATTCHRG_I_MASK,
221 &power_regs->hw_power_charge_clr);
222 writel(POWER_CHARGE_PWD_BATTCHRG, &power_regs->hw_power_charge_set);
224 debug("SPL: Battery Voltage too low\n");
229 * mxs_power_setup_5v_detect() - Start the 5V input detection comparator
231 * This function enables the 5V detection comparator and sets the 5V valid
232 * threshold to 4.4V . We use 4.4V threshold here to make sure that even
233 * under high load, the voltage drop on the 5V input won't be so critical
234 * to cause undervolt on the 4P2 linear regulator supplying the DC-DC
235 * converter and thus making the system crash.
237 static void mxs_power_setup_5v_detect(void)
239 struct mxs_power_regs *power_regs =
240 (struct mxs_power_regs *)MXS_POWER_BASE;
242 /* Start 5V detection */
243 debug("SPL: Starting 5V input detection comparator\n");
244 clrsetbits_le32(&power_regs->hw_power_5vctrl,
245 POWER_5VCTRL_VBUSVALID_TRSH_MASK,
246 POWER_5VCTRL_VBUSVALID_TRSH_4V4 |
247 POWER_5VCTRL_PWRUP_VBUS_CMPS);
251 * mxs_power_switch_dcdc_clocksource() - Switch PLL clock for DC-DC converters
252 * @freqsel: One of the POWER_MISC_FREQSEL_xxx defines to select the clock
254 * This function configures and then enables an alternative PLL clock source
255 * for the DC-DC converters.
257 void mxs_power_switch_dcdc_clocksource(uint32_t freqsel)
259 struct mxs_power_regs *power_regs =
260 (struct mxs_power_regs *)MXS_POWER_BASE;
262 /* Select clocksource for DC-DC converters */
263 clrsetbits_le32(&power_regs->hw_power_misc,
264 POWER_MISC_FREQSEL_MASK,
266 setbits_le32(&power_regs->hw_power_misc,
267 POWER_MISC_SEL_PLLCLK);
271 * mxs_power_setup_dcdc_clocksource() - Setup PLL clock source for DC-DC converters
273 * Normally, there is no need to switch DC-DC clocksource. This is the reason,
274 * why this function is a stub and does nothing. However, boards can implement
275 * this function when required and call mxs_power_switch_dcdc_clocksource() to
276 * switch to an alternative clock source.
278 __weak void mxs_power_setup_dcdc_clocksource(void)
280 debug("SPL: Using default DC-DC clocksource\n");
284 * mxs_src_power_init() - Preconfigure the power block
286 * This function configures reasonable values for the DC-DC control loop
287 * and battery monitor.
289 static void mxs_src_power_init(void)
291 struct mxs_power_regs *power_regs =
292 (struct mxs_power_regs *)MXS_POWER_BASE;
294 debug("SPL: Pre-Configuring power block\n");
296 /* Improve efficieny and reduce transient ripple */
297 writel(POWER_LOOPCTRL_TOGGLE_DIF | POWER_LOOPCTRL_EN_CM_HYST |
298 POWER_LOOPCTRL_EN_DF_HYST, &power_regs->hw_power_loopctrl_set);
300 clrsetbits_le32(&power_regs->hw_power_dclimits,
301 POWER_DCLIMITS_POSLIMIT_BUCK_MASK,
302 0x30 << POWER_DCLIMITS_POSLIMIT_BUCK_OFFSET);
304 setbits_le32(&power_regs->hw_power_battmonitor,
305 POWER_BATTMONITOR_EN_BATADJ);
307 /* Increase the RCSCALE level for quick DCDC response to dynamic load */
308 clrsetbits_le32(&power_regs->hw_power_loopctrl,
309 POWER_LOOPCTRL_EN_RCSCALE_MASK,
310 POWER_LOOPCTRL_RCSCALE_THRESH |
311 POWER_LOOPCTRL_EN_RCSCALE_8X);
313 clrsetbits_le32(&power_regs->hw_power_minpwr,
314 POWER_MINPWR_HALFFETS, POWER_MINPWR_DOUBLE_FETS);
316 /* 5V to battery handoff ... FIXME */
317 setbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_DCDC_XFER);
319 clrbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_DCDC_XFER);
323 * mxs_power_init_4p2_params() - Configure the parameters of the 4P2 regulator
325 * This function configures the necessary parameters for the 4P2 linear
326 * regulator to supply the DC-DC converter from 5V input.
328 static void mxs_power_init_4p2_params(void)
330 struct mxs_power_regs *power_regs =
331 (struct mxs_power_regs *)MXS_POWER_BASE;
333 debug("SPL: Configuring common 4P2 regulator params\n");
335 /* Setup 4P2 parameters */
336 clrsetbits_le32(&power_regs->hw_power_dcdc4p2,
337 POWER_DCDC4P2_CMPTRIP_MASK | POWER_DCDC4P2_TRG_MASK,
338 POWER_DCDC4P2_TRG_4V2 | (31 << POWER_DCDC4P2_CMPTRIP_OFFSET));
340 clrsetbits_le32(&power_regs->hw_power_5vctrl,
341 POWER_5VCTRL_HEADROOM_ADJ_MASK,
342 0x4 << POWER_5VCTRL_HEADROOM_ADJ_OFFSET);
344 clrsetbits_le32(&power_regs->hw_power_dcdc4p2,
345 POWER_DCDC4P2_DROPOUT_CTRL_MASK,
346 DCDC4P2_DROPOUT_CONFIG);
348 clrsetbits_le32(&power_regs->hw_power_5vctrl,
349 POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK,
350 0x3f << POWER_5VCTRL_CHARGE_4P2_ILIMIT_OFFSET);
354 * mxs_enable_4p2_dcdc_input() - Enable or disable the DCDC input from 4P2
355 * @xfer: Select if the input shall be enabled or disabled
357 * This function enables or disables the 4P2 input into the DC-DC converter.
359 static void mxs_enable_4p2_dcdc_input(int xfer)
361 struct mxs_power_regs *power_regs =
362 (struct mxs_power_regs *)MXS_POWER_BASE;
363 uint32_t tmp, vbus_thresh, vbus_5vdetect, pwd_bo;
364 uint32_t prev_5v_brnout, prev_5v_droop;
366 debug("SPL: %s 4P2 DC-DC Input\n", xfer ? "Enabling" : "Disabling");
368 if (xfer && (readl(&power_regs->hw_power_5vctrl) &
369 POWER_5VCTRL_ENABLE_DCDC)) {
373 prev_5v_brnout = readl(&power_regs->hw_power_5vctrl) &
374 POWER_5VCTRL_PWDN_5VBRNOUT;
375 prev_5v_droop = readl(&power_regs->hw_power_ctrl) &
376 POWER_CTRL_ENIRQ_VDD5V_DROOP;
378 clrbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_PWDN_5VBRNOUT);
379 writel(POWER_RESET_UNLOCK_KEY | POWER_RESET_PWD_OFF,
380 &power_regs->hw_power_reset);
382 clrbits_le32(&power_regs->hw_power_ctrl, POWER_CTRL_ENIRQ_VDD5V_DROOP);
385 * Recording orignal values that will be modified temporarlily
386 * to handle a chip bug. See chip errata for CQ ENGR00115837
388 tmp = readl(&power_regs->hw_power_5vctrl);
389 vbus_thresh = tmp & POWER_5VCTRL_VBUSVALID_TRSH_MASK;
390 vbus_5vdetect = tmp & POWER_5VCTRL_VBUSVALID_5VDETECT;
392 pwd_bo = readl(&power_regs->hw_power_minpwr) & POWER_MINPWR_PWD_BO;
395 * Disable mechanisms that get erroneously tripped by when setting
396 * the DCDC4P2 EN_DCDC
398 clrbits_le32(&power_regs->hw_power_5vctrl,
399 POWER_5VCTRL_VBUSVALID_5VDETECT |
400 POWER_5VCTRL_VBUSVALID_TRSH_MASK);
402 writel(POWER_MINPWR_PWD_BO, &power_regs->hw_power_minpwr_set);
405 setbits_le32(&power_regs->hw_power_5vctrl,
406 POWER_5VCTRL_DCDC_XFER);
408 clrbits_le32(&power_regs->hw_power_5vctrl,
409 POWER_5VCTRL_DCDC_XFER);
411 setbits_le32(&power_regs->hw_power_5vctrl,
412 POWER_5VCTRL_ENABLE_DCDC);
414 setbits_le32(&power_regs->hw_power_dcdc4p2,
415 POWER_DCDC4P2_ENABLE_DCDC);
420 clrsetbits_le32(&power_regs->hw_power_5vctrl,
421 POWER_5VCTRL_VBUSVALID_TRSH_MASK, vbus_thresh);
424 writel(vbus_5vdetect, &power_regs->hw_power_5vctrl_set);
427 clrbits_le32(&power_regs->hw_power_minpwr, POWER_MINPWR_PWD_BO);
429 while (readl(&power_regs->hw_power_ctrl) & POWER_CTRL_VBUS_VALID_IRQ)
430 writel(POWER_CTRL_VBUS_VALID_IRQ,
431 &power_regs->hw_power_ctrl_clr);
433 if (prev_5v_brnout) {
434 writel(POWER_5VCTRL_PWDN_5VBRNOUT,
435 &power_regs->hw_power_5vctrl_set);
436 writel(POWER_RESET_UNLOCK_KEY,
437 &power_regs->hw_power_reset);
439 writel(POWER_5VCTRL_PWDN_5VBRNOUT,
440 &power_regs->hw_power_5vctrl_clr);
441 writel(POWER_RESET_UNLOCK_KEY | POWER_RESET_PWD_OFF,
442 &power_regs->hw_power_reset);
445 while (readl(&power_regs->hw_power_ctrl) & POWER_CTRL_VDD5V_DROOP_IRQ)
446 writel(POWER_CTRL_VDD5V_DROOP_IRQ,
447 &power_regs->hw_power_ctrl_clr);
450 clrbits_le32(&power_regs->hw_power_ctrl,
451 POWER_CTRL_ENIRQ_VDD5V_DROOP);
453 setbits_le32(&power_regs->hw_power_ctrl,
454 POWER_CTRL_ENIRQ_VDD5V_DROOP);
458 * mxs_power_init_4p2_regulator() - Start the 4P2 regulator
460 * This function enables the 4P2 regulator and switches the DC-DC converter
461 * to use the 4P2 input.
463 static void mxs_power_init_4p2_regulator(void)
465 struct mxs_power_regs *power_regs =
466 (struct mxs_power_regs *)MXS_POWER_BASE;
469 debug("SPL: Enabling 4P2 regulator\n");
471 setbits_le32(&power_regs->hw_power_dcdc4p2, POWER_DCDC4P2_ENABLE_4P2);
473 writel(POWER_CHARGE_ENABLE_LOAD, &power_regs->hw_power_charge_set);
475 writel(POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK,
476 &power_regs->hw_power_5vctrl_clr);
477 clrbits_le32(&power_regs->hw_power_dcdc4p2, POWER_DCDC4P2_TRG_MASK);
479 /* Power up the 4p2 rail and logic/control */
480 writel(POWER_5VCTRL_PWD_CHARGE_4P2_MASK,
481 &power_regs->hw_power_5vctrl_clr);
484 * Start charging up the 4p2 capacitor. We ramp of this charge
485 * gradually to avoid large inrush current from the 5V cable which can
486 * cause transients/problems
488 debug("SPL: Charging 4P2 capacitor\n");
489 mxs_enable_4p2_dcdc_input(0);
491 if (readl(&power_regs->hw_power_ctrl) & POWER_CTRL_VBUS_VALID_IRQ) {
493 * If we arrived here, we were unable to recover from mx23 chip
494 * errata 5837. 4P2 is disabled and sufficient battery power is
495 * not present. Exiting to not enable DCDC power during 5V
498 clrbits_le32(&power_regs->hw_power_dcdc4p2,
499 POWER_DCDC4P2_ENABLE_DCDC);
500 writel(POWER_5VCTRL_PWD_CHARGE_4P2_MASK,
501 &power_regs->hw_power_5vctrl_set);
503 debug("SPL: Unable to recover from mx23 errata 5837\n");
508 * Here we set the 4p2 brownout level to something very close to 4.2V.
509 * We then check the brownout status. If the brownout status is false,
510 * the voltage is already close to the target voltage of 4.2V so we
511 * can go ahead and set the 4P2 current limit to our max target limit.
512 * If the brownout status is true, we need to ramp us the current limit
513 * so that we don't cause large inrush current issues. We step up the
514 * current limit until the brownout status is false or until we've
515 * reached our maximum defined 4p2 current limit.
517 debug("SPL: Setting 4P2 brownout level\n");
518 clrsetbits_le32(&power_regs->hw_power_dcdc4p2,
519 POWER_DCDC4P2_BO_MASK,
520 22 << POWER_DCDC4P2_BO_OFFSET); /* 4.15V */
522 if (!(readl(&power_regs->hw_power_sts) & POWER_STS_DCDC_4P2_BO)) {
523 setbits_le32(&power_regs->hw_power_5vctrl,
524 0x3f << POWER_5VCTRL_CHARGE_4P2_ILIMIT_OFFSET);
526 tmp = (readl(&power_regs->hw_power_5vctrl) &
527 POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK) >>
528 POWER_5VCTRL_CHARGE_4P2_ILIMIT_OFFSET;
530 if (!(readl(&power_regs->hw_power_sts) &
531 POWER_STS_DCDC_4P2_BO)) {
532 tmp = readl(&power_regs->hw_power_5vctrl);
533 tmp |= POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK;
535 writel(tmp, &power_regs->hw_power_5vctrl);
539 tmp2 = readl(&power_regs->hw_power_5vctrl);
540 tmp2 &= ~POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK;
542 POWER_5VCTRL_CHARGE_4P2_ILIMIT_OFFSET;
543 writel(tmp2, &power_regs->hw_power_5vctrl);
549 clrbits_le32(&power_regs->hw_power_dcdc4p2, POWER_DCDC4P2_BO_MASK);
550 writel(POWER_CTRL_DCDC4P2_BO_IRQ, &power_regs->hw_power_ctrl_clr);
554 * mxs_power_init_dcdc_4p2_source() - Switch DC-DC converter to 4P2 source
556 * This function configures the DC-DC converter to be supplied from the 4P2
559 static void mxs_power_init_dcdc_4p2_source(void)
561 struct mxs_power_regs *power_regs =
562 (struct mxs_power_regs *)MXS_POWER_BASE;
564 debug("SPL: Switching DC-DC converters to 4P2\n");
566 if (!(readl(&power_regs->hw_power_dcdc4p2) &
567 POWER_DCDC4P2_ENABLE_DCDC)) {
568 debug("SPL: Already switched - aborting\n");
572 mxs_enable_4p2_dcdc_input(1);
574 if (readl(&power_regs->hw_power_ctrl) & POWER_CTRL_VBUS_VALID_IRQ) {
575 clrbits_le32(&power_regs->hw_power_dcdc4p2,
576 POWER_DCDC4P2_ENABLE_DCDC);
577 writel(POWER_5VCTRL_ENABLE_DCDC,
578 &power_regs->hw_power_5vctrl_clr);
579 writel(POWER_5VCTRL_PWD_CHARGE_4P2_MASK,
580 &power_regs->hw_power_5vctrl_set);
585 * mxs_power_enable_4p2() - Power up the 4P2 regulator
587 * This function drives the process of powering up the 4P2 linear regulator
588 * and switching the DC-DC converter input over to the 4P2 linear regulator.
590 static void mxs_power_enable_4p2(void)
592 struct mxs_power_regs *power_regs =
593 (struct mxs_power_regs *)MXS_POWER_BASE;
594 uint32_t vdddctrl, vddactrl, vddioctrl;
597 debug("SPL: Powering up 4P2 regulator\n");
599 vdddctrl = readl(&power_regs->hw_power_vdddctrl);
600 vddactrl = readl(&power_regs->hw_power_vddactrl);
601 vddioctrl = readl(&power_regs->hw_power_vddioctrl);
603 setbits_le32(&power_regs->hw_power_vdddctrl,
604 POWER_VDDDCTRL_DISABLE_FET | POWER_VDDDCTRL_ENABLE_LINREG |
605 POWER_VDDDCTRL_PWDN_BRNOUT);
607 setbits_le32(&power_regs->hw_power_vddactrl,
608 POWER_VDDACTRL_DISABLE_FET | POWER_VDDACTRL_ENABLE_LINREG |
609 POWER_VDDACTRL_PWDN_BRNOUT);
611 setbits_le32(&power_regs->hw_power_vddioctrl,
612 POWER_VDDIOCTRL_DISABLE_FET | POWER_VDDIOCTRL_PWDN_BRNOUT);
614 mxs_power_init_4p2_params();
615 mxs_power_init_4p2_regulator();
617 /* Shutdown battery (none present) */
618 if (!mxs_is_batt_ready()) {
619 clrbits_le32(&power_regs->hw_power_dcdc4p2,
620 POWER_DCDC4P2_BO_MASK);
621 writel(POWER_CTRL_DCDC4P2_BO_IRQ,
622 &power_regs->hw_power_ctrl_clr);
623 writel(POWER_CTRL_ENIRQ_DCDC4P2_BO,
624 &power_regs->hw_power_ctrl_clr);
627 mxs_power_init_dcdc_4p2_source();
629 writel(vdddctrl, &power_regs->hw_power_vdddctrl);
631 writel(vddactrl, &power_regs->hw_power_vddactrl);
633 writel(vddioctrl, &power_regs->hw_power_vddioctrl);
636 * Check if FET is enabled on either powerout and if so,
640 tmp |= !(readl(&power_regs->hw_power_vdddctrl) &
641 POWER_VDDDCTRL_DISABLE_FET);
642 tmp |= !(readl(&power_regs->hw_power_vddactrl) &
643 POWER_VDDACTRL_DISABLE_FET);
644 tmp |= !(readl(&power_regs->hw_power_vddioctrl) &
645 POWER_VDDIOCTRL_DISABLE_FET);
647 writel(POWER_CHARGE_ENABLE_LOAD,
648 &power_regs->hw_power_charge_clr);
650 debug("SPL: 4P2 regulator powered-up\n");
654 * mxs_boot_valid_5v() - Boot from 5V supply
656 * This function configures the power block to boot from valid 5V input.
657 * This is called only if the 5V is reliable and can properly supply the
658 * CPU. This function proceeds to configure the 4P2 converter to be supplied
661 static void mxs_boot_valid_5v(void)
663 struct mxs_power_regs *power_regs =
664 (struct mxs_power_regs *)MXS_POWER_BASE;
666 debug("SPL: Booting from 5V supply\n");
669 * Use VBUSVALID level instead of VDD5V_GT_VDDIO level to trigger a 5V
670 * disconnect event. FIXME
672 writel(POWER_5VCTRL_VBUSVALID_5VDETECT,
673 &power_regs->hw_power_5vctrl_set);
675 /* Configure polarity to check for 5V disconnection. */
676 writel(POWER_CTRL_POLARITY_VBUSVALID |
677 POWER_CTRL_POLARITY_VDD5V_GT_VDDIO,
678 &power_regs->hw_power_ctrl_clr);
680 writel(POWER_CTRL_VBUS_VALID_IRQ | POWER_CTRL_VDD5V_GT_VDDIO_IRQ,
681 &power_regs->hw_power_ctrl_clr);
683 mxs_power_enable_4p2();
687 * mxs_powerdown() - Shut down the system
689 * This function powers down the CPU completely.
691 static void mxs_powerdown(void)
693 struct mxs_power_regs *power_regs =
694 (struct mxs_power_regs *)MXS_POWER_BASE;
696 debug("Powering Down\n");
698 writel(POWER_RESET_UNLOCK_KEY, &power_regs->hw_power_reset);
699 writel(POWER_RESET_UNLOCK_KEY | POWER_RESET_PWD_OFF,
700 &power_regs->hw_power_reset);
704 * mxs_batt_boot() - Configure the power block to boot from battery input
706 * This function configures the power block to boot from the battery voltage
709 static void mxs_batt_boot(void)
711 struct mxs_power_regs *power_regs =
712 (struct mxs_power_regs *)MXS_POWER_BASE;
714 debug("SPL: Configuring power block to boot from battery\n");
716 clrbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_PWDN_5VBRNOUT);
717 clrbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_ENABLE_DCDC);
719 clrbits_le32(&power_regs->hw_power_dcdc4p2,
720 POWER_DCDC4P2_ENABLE_DCDC | POWER_DCDC4P2_ENABLE_4P2);
721 writel(POWER_CHARGE_ENABLE_LOAD, &power_regs->hw_power_charge_clr);
723 /* 5V to battery handoff. */
724 setbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_DCDC_XFER);
726 clrbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_DCDC_XFER);
728 writel(POWER_CTRL_ENIRQ_DCDC4P2_BO, &power_regs->hw_power_ctrl_clr);
730 clrsetbits_le32(&power_regs->hw_power_minpwr,
731 POWER_MINPWR_HALFFETS, POWER_MINPWR_DOUBLE_FETS);
733 mxs_power_set_linreg();
735 clrbits_le32(&power_regs->hw_power_vdddctrl,
736 POWER_VDDDCTRL_DISABLE_FET | POWER_VDDDCTRL_ENABLE_LINREG);
738 clrbits_le32(&power_regs->hw_power_vddactrl,
739 POWER_VDDACTRL_DISABLE_FET | POWER_VDDACTRL_ENABLE_LINREG);
741 clrbits_le32(&power_regs->hw_power_vddioctrl,
742 POWER_VDDIOCTRL_DISABLE_FET);
744 setbits_le32(&power_regs->hw_power_5vctrl,
745 POWER_5VCTRL_PWD_CHARGE_4P2_MASK);
747 setbits_le32(&power_regs->hw_power_5vctrl,
748 POWER_5VCTRL_ENABLE_DCDC);
750 clrsetbits_le32(&power_regs->hw_power_5vctrl,
751 POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK,
752 0x8 << POWER_5VCTRL_CHARGE_4P2_ILIMIT_OFFSET);
754 mxs_power_enable_4p2();
758 * mxs_handle_5v_conflict() - Test if the 5V input is reliable
760 * This function tests if the 5V input can reliably supply the system. If it
761 * can, then proceed to configuring the system to boot from 5V source, otherwise
762 * try booting from battery supply. If we can not boot from battery supply
763 * either, shut down the system.
765 static void mxs_handle_5v_conflict(void)
767 struct mxs_power_regs *power_regs =
768 (struct mxs_power_regs *)MXS_POWER_BASE;
771 debug("SPL: Resolving 5V conflict\n");
773 setbits_le32(&power_regs->hw_power_vddioctrl,
774 POWER_VDDIOCTRL_BO_OFFSET_MASK);
777 tmp = readl(&power_regs->hw_power_sts);
779 if (tmp & POWER_STS_VDDIO_BO) {
781 * VDDIO has a brownout, then the VDD5V_GT_VDDIO becomes
784 debug("SPL: VDDIO has a brownout\n");
789 if (tmp & POWER_STS_VDD5V_GT_VDDIO) {
790 debug("SPL: POWER_STS_VDD5V_GT_VDDIO is set\n");
794 debug("SPL: POWER_STS_VDD5V_GT_VDDIO is not set\n");
800 * TODO: I can't see this being reached. We'll either
801 * powerdown or boot from a stable 5V supply.
803 if (tmp & POWER_STS_PSWITCH_MASK) {
804 debug("SPL: POWER_STS_PSWITCH_MASK is set\n");
812 * mxs_5v_boot() - Configure the power block to boot from 5V input
814 * This function handles configuration of the power block when supplied by
817 static void mxs_5v_boot(void)
819 struct mxs_power_regs *power_regs =
820 (struct mxs_power_regs *)MXS_POWER_BASE;
822 debug("SPL: Configuring power block to boot from 5V input\n");
825 * NOTE: In original IMX-Bootlets, this also checks for VBUSVALID,
826 * but their implementation always returns 1 so we omit it here.
828 if (readl(&power_regs->hw_power_sts) & POWER_STS_VDD5V_GT_VDDIO) {
829 debug("SPL: 5V VDD good\n");
835 if (readl(&power_regs->hw_power_sts) & POWER_STS_VDD5V_GT_VDDIO) {
836 debug("SPL: 5V VDD good (after delay)\n");
841 debug("SPL: 5V VDD not good\n");
842 mxs_handle_5v_conflict();
846 * mxs_init_batt_bo() - Configure battery brownout threshold
848 * This function configures the battery input brownout threshold. The value
849 * at which the battery brownout happens is configured to 3.0V in the code.
851 static void mxs_init_batt_bo(void)
853 struct mxs_power_regs *power_regs =
854 (struct mxs_power_regs *)MXS_POWER_BASE;
856 debug("SPL: Initialising battery brown-out level to 3.0V\n");
859 clrsetbits_le32(&power_regs->hw_power_battmonitor,
860 POWER_BATTMONITOR_BRWNOUT_LVL_MASK,
861 15 << POWER_BATTMONITOR_BRWNOUT_LVL_OFFSET);
863 writel(POWER_CTRL_BATT_BO_IRQ, &power_regs->hw_power_ctrl_clr);
864 writel(POWER_CTRL_ENIRQ_BATT_BO, &power_regs->hw_power_ctrl_clr);
868 * mxs_switch_vddd_to_dcdc_source() - Switch VDDD rail to DC-DC converter
870 * This function turns off the VDDD linear regulator and therefore makes
871 * the VDDD rail be supplied only by the DC-DC converter.
873 static void mxs_switch_vddd_to_dcdc_source(void)
875 struct mxs_power_regs *power_regs =
876 (struct mxs_power_regs *)MXS_POWER_BASE;
878 debug("SPL: Switching VDDD to DC-DC converters\n");
880 clrsetbits_le32(&power_regs->hw_power_vdddctrl,
881 POWER_VDDDCTRL_LINREG_OFFSET_MASK,
882 POWER_VDDDCTRL_LINREG_OFFSET_1STEPS_BELOW);
884 clrbits_le32(&power_regs->hw_power_vdddctrl,
885 POWER_VDDDCTRL_DISABLE_FET | POWER_VDDDCTRL_ENABLE_LINREG |
886 POWER_VDDDCTRL_DISABLE_STEPPING);
890 * mxs_power_configure_power_source() - Configure power block source
892 * This function is the core of the power configuration logic. The function
893 * selects the power block input source and configures the whole power block
894 * accordingly. After the configuration is complete and the system is stable
895 * again, the function switches the CPU clock source back to PLL. Finally,
896 * the function switches the voltage rails to DC-DC converter.
898 static void mxs_power_configure_power_source(void)
900 int batt_ready, batt_good;
901 struct mxs_power_regs *power_regs =
902 (struct mxs_power_regs *)MXS_POWER_BASE;
903 struct mxs_lradc_regs *lradc_regs =
904 (struct mxs_lradc_regs *)MXS_LRADC_BASE;
906 debug("SPL: Configuring power source\n");
908 mxs_power_setup_dcdc_clocksource();
909 mxs_src_power_init();
911 if (readl(&power_regs->hw_power_sts) & POWER_STS_VDD5V_GT_VDDIO) {
912 batt_ready = mxs_is_batt_ready();
914 /* 5V source detected, good battery detected. */
917 batt_good = mxs_is_batt_good();
919 /* 5V source detected, bad battery detected. */
920 writel(LRADC_CONVERSION_AUTOMATIC,
921 &lradc_regs->hw_lradc_conversion_clr);
922 clrbits_le32(&power_regs->hw_power_battmonitor,
923 POWER_BATTMONITOR_BATT_VAL_MASK);
928 /* 5V not detected, booting from battery. */
933 * TODO: Do not switch CPU clock to PLL if we are VDD5V is sourced
936 mxs_power_clock2pll();
940 mxs_switch_vddd_to_dcdc_source();
943 /* Fire up the VDDMEM LinReg now that we're all set. */
944 debug("SPL: Enabling mx23 VDDMEM linear regulator\n");
945 writel(POWER_VDDMEMCTRL_ENABLE_LINREG | POWER_VDDMEMCTRL_ENABLE_ILIMIT,
946 &power_regs->hw_power_vddmemctrl);
951 * mxs_enable_output_rail_protection() - Enable power rail protection
953 * This function enables overload protection on the power rails. This is
954 * triggered if the power rails' voltage drops rapidly due to overload and
955 * in such case, the supply to the powerrail is cut-off, protecting the
956 * CPU from damage. Note that under such condition, the system will likely
957 * crash or misbehave.
959 static void mxs_enable_output_rail_protection(void)
961 struct mxs_power_regs *power_regs =
962 (struct mxs_power_regs *)MXS_POWER_BASE;
964 debug("SPL: Enabling output rail protection\n");
966 writel(POWER_CTRL_VDDD_BO_IRQ | POWER_CTRL_VDDA_BO_IRQ |
967 POWER_CTRL_VDDIO_BO_IRQ, &power_regs->hw_power_ctrl_clr);
969 setbits_le32(&power_regs->hw_power_vdddctrl,
970 POWER_VDDDCTRL_PWDN_BRNOUT);
972 setbits_le32(&power_regs->hw_power_vddactrl,
973 POWER_VDDACTRL_PWDN_BRNOUT);
975 setbits_le32(&power_regs->hw_power_vddioctrl,
976 POWER_VDDIOCTRL_PWDN_BRNOUT);
980 * mxs_get_vddio_power_source_off() - Get VDDIO rail power source
982 * This function tests if the VDDIO rail is supplied by linear regulator
983 * or by the DC-DC converter. Returns 1 if powered by linear regulator,
984 * returns 0 if powered by the DC-DC converter.
986 static int mxs_get_vddio_power_source_off(void)
988 struct mxs_power_regs *power_regs =
989 (struct mxs_power_regs *)MXS_POWER_BASE;
992 if (readl(&power_regs->hw_power_sts) & POWER_STS_VDD5V_GT_VDDIO) {
993 tmp = readl(&power_regs->hw_power_vddioctrl);
994 if (tmp & POWER_VDDIOCTRL_DISABLE_FET) {
995 if ((tmp & POWER_VDDIOCTRL_LINREG_OFFSET_MASK) ==
996 POWER_VDDIOCTRL_LINREG_OFFSET_0STEPS) {
1001 if (!(readl(&power_regs->hw_power_5vctrl) &
1002 POWER_5VCTRL_ENABLE_DCDC)) {
1003 if ((tmp & POWER_VDDIOCTRL_LINREG_OFFSET_MASK) ==
1004 POWER_VDDIOCTRL_LINREG_OFFSET_0STEPS) {
1015 * mxs_get_vddd_power_source_off() - Get VDDD rail power source
1017 * This function tests if the VDDD rail is supplied by linear regulator
1018 * or by the DC-DC converter. Returns 1 if powered by linear regulator,
1019 * returns 0 if powered by the DC-DC converter.
1021 static int mxs_get_vddd_power_source_off(void)
1023 struct mxs_power_regs *power_regs =
1024 (struct mxs_power_regs *)MXS_POWER_BASE;
1027 tmp = readl(&power_regs->hw_power_vdddctrl);
1028 if (tmp & POWER_VDDDCTRL_DISABLE_FET) {
1029 if ((tmp & POWER_VDDDCTRL_LINREG_OFFSET_MASK) ==
1030 POWER_VDDDCTRL_LINREG_OFFSET_0STEPS) {
1035 if (readl(&power_regs->hw_power_sts) & POWER_STS_VDD5V_GT_VDDIO) {
1036 if (!(readl(&power_regs->hw_power_5vctrl) &
1037 POWER_5VCTRL_ENABLE_DCDC)) {
1042 if (!(tmp & POWER_VDDDCTRL_ENABLE_LINREG)) {
1043 if ((tmp & POWER_VDDDCTRL_LINREG_OFFSET_MASK) ==
1044 POWER_VDDDCTRL_LINREG_OFFSET_1STEPS_BELOW) {
1052 struct mxs_vddx_cfg {
1056 int (*powered_by_linreg)(void);
1060 uint32_t bo_offset_mask;
1061 uint32_t bo_offset_offset;
1064 static const struct mxs_vddx_cfg mxs_vddio_cfg = {
1065 .reg = &(((struct mxs_power_regs *)MXS_POWER_BASE)->
1066 hw_power_vddioctrl),
1067 #if defined(CONFIG_MX23)
1073 .powered_by_linreg = mxs_get_vddio_power_source_off,
1074 .trg_mask = POWER_VDDIOCTRL_TRG_MASK,
1075 .bo_irq = POWER_CTRL_VDDIO_BO_IRQ,
1076 .bo_enirq = POWER_CTRL_ENIRQ_VDDIO_BO,
1077 .bo_offset_mask = POWER_VDDIOCTRL_BO_OFFSET_MASK,
1078 .bo_offset_offset = POWER_VDDIOCTRL_BO_OFFSET_OFFSET,
1081 static const struct mxs_vddx_cfg mxs_vddd_cfg = {
1082 .reg = &(((struct mxs_power_regs *)MXS_POWER_BASE)->
1086 .powered_by_linreg = mxs_get_vddd_power_source_off,
1087 .trg_mask = POWER_VDDDCTRL_TRG_MASK,
1088 .bo_irq = POWER_CTRL_VDDD_BO_IRQ,
1089 .bo_enirq = POWER_CTRL_ENIRQ_VDDD_BO,
1090 .bo_offset_mask = POWER_VDDDCTRL_BO_OFFSET_MASK,
1091 .bo_offset_offset = POWER_VDDDCTRL_BO_OFFSET_OFFSET,
1095 static const struct mxs_vddx_cfg mxs_vddmem_cfg = {
1096 .reg = &(((struct mxs_power_regs *)MXS_POWER_BASE)->
1097 hw_power_vddmemctrl),
1100 .powered_by_linreg = NULL,
1101 .trg_mask = POWER_VDDMEMCTRL_TRG_MASK,
1104 .bo_offset_mask = 0,
1105 .bo_offset_offset = 0,
1110 * mxs_power_set_vddx() - Configure voltage on DC-DC converter rail
1111 * @cfg: Configuration data of the DC-DC converter rail
1112 * @new_target: New target voltage of the DC-DC converter rail
1113 * @new_brownout: New brownout trigger voltage
1115 * This function configures the output voltage on the DC-DC converter rail.
1116 * The rail is selected by the @cfg argument. The new voltage target is
1117 * selected by the @new_target and the voltage is specified in mV. The
1118 * new brownout value is selected by the @new_brownout argument and the
1119 * value is also in mV.
1121 static void mxs_power_set_vddx(const struct mxs_vddx_cfg *cfg,
1122 uint32_t new_target, uint32_t new_brownout)
1124 struct mxs_power_regs *power_regs =
1125 (struct mxs_power_regs *)MXS_POWER_BASE;
1126 uint32_t cur_target, diff, bo_int = 0;
1127 uint32_t powered_by_linreg = 0;
1130 new_brownout = DIV_ROUND_CLOSEST(new_target - new_brownout,
1133 cur_target = readl(cfg->reg);
1134 cur_target &= cfg->trg_mask;
1135 cur_target *= cfg->step_mV;
1136 cur_target += cfg->lowest_mV;
1138 adjust_up = new_target > cur_target;
1139 if (cfg->powered_by_linreg)
1140 powered_by_linreg = cfg->powered_by_linreg();
1142 if (adjust_up && cfg->bo_irq) {
1143 if (powered_by_linreg) {
1144 bo_int = readl(cfg->reg);
1145 clrbits_le32(cfg->reg, cfg->bo_enirq);
1147 setbits_le32(cfg->reg, cfg->bo_offset_mask);
1151 if (abs(new_target - cur_target) > 100) {
1153 diff = cur_target + 100;
1155 diff = cur_target - 100;
1160 diff -= cfg->lowest_mV;
1161 diff /= cfg->step_mV;
1163 clrsetbits_le32(cfg->reg, cfg->trg_mask, diff);
1165 if (powered_by_linreg ||
1166 (readl(&power_regs->hw_power_sts) &
1167 POWER_STS_VDD5V_GT_VDDIO))
1171 tmp = readl(&power_regs->hw_power_sts);
1172 if (tmp & POWER_STS_DC_OK)
1177 cur_target = readl(cfg->reg);
1178 cur_target &= cfg->trg_mask;
1179 cur_target *= cfg->step_mV;
1180 cur_target += cfg->lowest_mV;
1181 } while (new_target > cur_target);
1184 if (adjust_up && powered_by_linreg) {
1185 writel(cfg->bo_irq, &power_regs->hw_power_ctrl_clr);
1186 if (bo_int & cfg->bo_enirq)
1187 setbits_le32(cfg->reg, cfg->bo_enirq);
1190 clrsetbits_le32(cfg->reg, cfg->bo_offset_mask,
1191 new_brownout << cfg->bo_offset_offset);
1196 * mxs_setup_batt_detect() - Start the battery voltage measurement logic
1198 * This function starts and configures the LRADC block. This allows the
1199 * power initialization code to measure battery voltage and based on this
1200 * knowledge, decide whether to boot at all, boot from battery or boot
1203 static void mxs_setup_batt_detect(void)
1205 debug("SPL: Starting battery voltage measurement logic\n");
1208 mxs_lradc_enable_batt_measurement();
1213 * mxs_ungate_power() - Ungate the POWER block
1215 * This function ungates clock to the power block. In case the power block
1216 * was still gated at this point, it will not be possible to configure the
1217 * block and therefore the power initialization would fail. This function
1218 * is only needed on i.MX233, on i.MX28 the power block is always ungated.
1220 static void mxs_ungate_power(void)
1223 struct mxs_power_regs *power_regs =
1224 (struct mxs_power_regs *)MXS_POWER_BASE;
1226 writel(POWER_CTRL_CLKGATE, &power_regs->hw_power_ctrl_clr);
1231 * mxs_power_init() - The power block init main function
1233 * This function calls all the power block initialization functions in
1234 * proper sequence to start the power block.
1236 void mxs_power_init(void)
1238 struct mxs_power_regs *power_regs =
1239 (struct mxs_power_regs *)MXS_POWER_BASE;
1241 debug("SPL: Initialising Power Block\n");
1245 mxs_power_clock2xtal();
1246 mxs_power_set_auto_restart();
1247 mxs_power_set_linreg();
1248 mxs_power_setup_5v_detect();
1250 mxs_setup_batt_detect();
1252 mxs_power_configure_power_source();
1253 mxs_enable_output_rail_protection();
1255 debug("SPL: Setting VDDIO to 3V3 (brownout @ 3v15)\n");
1256 mxs_power_set_vddx(&mxs_vddio_cfg, 3300, 3150);
1258 debug("SPL: Setting VDDD to 1V5 (brownout @ 1v315)\n");
1259 mxs_power_set_vddx(&mxs_vddd_cfg, 1500, 1315);
1261 debug("SPL: Setting mx23 VDDMEM to 2V5 (brownout @ 1v7)\n");
1262 mxs_power_set_vddx(&mxs_vddmem_cfg, 2500, 1700);
1264 writel(POWER_CTRL_VDDD_BO_IRQ | POWER_CTRL_VDDA_BO_IRQ |
1265 POWER_CTRL_VDDIO_BO_IRQ | POWER_CTRL_VDD5V_DROOP_IRQ |
1266 POWER_CTRL_VBUS_VALID_IRQ | POWER_CTRL_BATT_BO_IRQ |
1267 POWER_CTRL_DCDC4P2_BO_IRQ, &power_regs->hw_power_ctrl_clr);
1269 writel(POWER_5VCTRL_PWDN_5VBRNOUT, &power_regs->hw_power_5vctrl_set);
1274 #ifdef CONFIG_SPL_MXS_PSWITCH_WAIT
1276 * mxs_power_wait_pswitch() - Wait for power switch to be pressed
1278 * This function waits until the power-switch was pressed to start booting
1281 void mxs_power_wait_pswitch(void)
1283 struct mxs_power_regs *power_regs =
1284 (struct mxs_power_regs *)MXS_POWER_BASE;
1286 debug("SPL: Waiting for power switch input\n");
1287 while (!(readl(&power_regs->hw_power_sts) & POWER_STS_PSWITCH_MASK))