1 // SPDX-License-Identifier: GPL-2.0+
3 * Freescale i.MX28 Boot PMIC init
5 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
6 * on behalf of DENX Software Engineering GmbH
14 #include <asm/arch/imx-regs.h>
18 #ifdef CONFIG_SYS_MXS_VDD5V_ONLY
19 #define DCDC4P2_DROPOUT_CONFIG POWER_DCDC4P2_DROPOUT_CTRL_100MV | \
20 POWER_DCDC4P2_DROPOUT_CTRL_SRC_4P2
22 #define DCDC4P2_DROPOUT_CONFIG POWER_DCDC4P2_DROPOUT_CTRL_100MV | \
23 POWER_DCDC4P2_DROPOUT_CTRL_SRC_SEL
26 * mxs_power_clock2xtal() - Switch CPU core clock source to 24MHz XTAL
28 * This function switches the CPU core clock from PLL to 24MHz XTAL
29 * oscilator. This is necessary if the PLL is being reconfigured to
30 * prevent crash of the CPU core.
32 static void mxs_power_clock2xtal(void)
34 struct mxs_clkctrl_regs *clkctrl_regs =
35 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
37 debug("SPL: Switching CPU clock to 24MHz XTAL\n");
39 /* Set XTAL as CPU reference clock */
40 writel(CLKCTRL_CLKSEQ_BYPASS_CPU,
41 &clkctrl_regs->hw_clkctrl_clkseq_set);
44 static void mxs_power_regs_dump(void)
46 struct mxs_power_regs *power_regs =
47 (struct mxs_power_regs *)MXS_POWER_BASE;
49 debug("ctrl:\t\t 0x%x\n", readl(&power_regs->hw_power_ctrl));
50 debug("5vctrl:\t\t 0x%x\n", readl(&power_regs->hw_power_5vctrl));
51 debug("minpwr:\t\t 0x%x\n", readl(&power_regs->hw_power_minpwr));
52 debug("charge:\t\t 0x%x\n", readl(&power_regs->hw_power_charge));
53 debug("vddctrl:\t 0x%x\n", readl(&power_regs->hw_power_vdddctrl));
54 debug("vddactrl:\t 0x%x\n", readl(&power_regs->hw_power_vddactrl));
55 debug("vddioctrl:\t 0x%x\n", readl(&power_regs->hw_power_vddioctrl));
56 debug("vddmemctrl:\t 0x%x\n", readl(&power_regs->hw_power_vddmemctrl));
57 debug("dcdc4p2:\t 0x%x\n", readl(&power_regs->hw_power_dcdc4p2));
58 debug("misc:\t\t 0x%x\n", readl(&power_regs->hw_power_misc));
59 debug("dclimits:\t 0x%x\n", readl(&power_regs->hw_power_dclimits));
60 debug("loopctrl:\t 0x%x\n", readl(&power_regs->hw_power_loopctrl));
61 debug("sts:\t\t 0x%x\n", readl(&power_regs->hw_power_sts));
62 debug("speed:\t\t 0x%x\n", readl(&power_regs->hw_power_speed));
63 debug("battmonitor:\t 0x%x\n",
64 readl(&power_regs->hw_power_battmonitor));
68 * mxs_power_clock2pll() - Switch CPU core clock source to PLL
70 * This function switches the CPU core clock from 24MHz XTAL oscilator
71 * to PLL. This can only be called once the PLL has re-locked and once
72 * the PLL is stable after reconfiguration.
74 static void mxs_power_clock2pll(void)
76 struct mxs_clkctrl_regs *clkctrl_regs =
77 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
79 debug("SPL: Switching CPU core clock source to PLL\n");
82 * TODO: Are we really? It looks like we turn on PLL0, but we then
83 * set the CLKCTRL_CLKSEQ_BYPASS_CPU bit of the (which was already
84 * set by mxs_power_clock2xtal()). Clearing this bit here seems to
85 * introduce some instability (causing the CPU core to hang). Maybe
86 * we aren't giving PLL0 enough time to stabilise?
88 setbits_le32(&clkctrl_regs->hw_clkctrl_pll0ctrl0,
89 CLKCTRL_PLL0CTRL0_POWER);
93 * TODO: Should the PLL0 FORCE_LOCK bit be set here followed be a
94 * wait on the PLL0 LOCK bit?
96 setbits_le32(&clkctrl_regs->hw_clkctrl_clkseq,
97 CLKCTRL_CLKSEQ_BYPASS_CPU);
101 * mxs_power_set_auto_restart() - Set the auto-restart bit
103 * This function ungates the RTC block and sets the AUTO_RESTART
104 * bit to work around a design bug on MX28EVK Rev. A .
107 static void mxs_power_set_auto_restart(void)
109 struct mxs_rtc_regs *rtc_regs =
110 (struct mxs_rtc_regs *)MXS_RTC_BASE;
112 debug("SPL: Setting auto-restart bit\n");
114 writel(RTC_CTRL_SFTRST, &rtc_regs->hw_rtc_ctrl_clr);
115 while (readl(&rtc_regs->hw_rtc_ctrl) & RTC_CTRL_SFTRST)
118 writel(RTC_CTRL_CLKGATE, &rtc_regs->hw_rtc_ctrl_clr);
119 while (readl(&rtc_regs->hw_rtc_ctrl) & RTC_CTRL_CLKGATE)
122 /* Do nothing if flag already set */
123 if (readl(&rtc_regs->hw_rtc_persistent0) & RTC_PERSISTENT0_AUTO_RESTART)
126 while (readl(&rtc_regs->hw_rtc_stat) & RTC_STAT_NEW_REGS_MASK)
129 setbits_le32(&rtc_regs->hw_rtc_persistent0,
130 RTC_PERSISTENT0_AUTO_RESTART);
131 writel(RTC_CTRL_FORCE_UPDATE, &rtc_regs->hw_rtc_ctrl_set);
132 writel(RTC_CTRL_FORCE_UPDATE, &rtc_regs->hw_rtc_ctrl_clr);
133 while (readl(&rtc_regs->hw_rtc_stat) & RTC_STAT_NEW_REGS_MASK)
135 while (readl(&rtc_regs->hw_rtc_stat) & RTC_STAT_STALE_REGS_MASK)
140 * mxs_power_set_linreg() - Set linear regulators 25mV below DC-DC converter
142 * This function configures the VDDIO, VDDA and VDDD linear regulators output
143 * to be 25mV below the VDDIO, VDDA and VDDD output from the DC-DC switching
144 * converter. This is the recommended setting for the case where we use both
145 * linear regulators and DC-DC converter to power the VDDIO rail.
147 static void mxs_power_set_linreg(void)
149 struct mxs_power_regs *power_regs =
150 (struct mxs_power_regs *)MXS_POWER_BASE;
152 /* Set linear regulator 25mV below switching converter */
153 debug("SPL: Setting VDDD 25mV below DC-DC converters\n");
154 clrsetbits_le32(&power_regs->hw_power_vdddctrl,
155 POWER_VDDDCTRL_LINREG_OFFSET_MASK,
156 POWER_VDDDCTRL_LINREG_OFFSET_1STEPS_BELOW);
158 debug("SPL: Setting VDDA 25mV below DC-DC converters\n");
159 clrsetbits_le32(&power_regs->hw_power_vddactrl,
160 POWER_VDDACTRL_LINREG_OFFSET_MASK,
161 POWER_VDDACTRL_LINREG_OFFSET_1STEPS_BELOW);
163 debug("SPL: Setting VDDIO 25mV below DC-DC converters\n");
164 clrsetbits_le32(&power_regs->hw_power_vddioctrl,
165 POWER_VDDIOCTRL_LINREG_OFFSET_MASK,
166 POWER_VDDIOCTRL_LINREG_OFFSET_1STEPS_BELOW);
170 * mxs_get_batt_volt() - Measure battery input voltage
172 * This function retrieves the battery input voltage and returns it.
174 static int mxs_get_batt_volt(void)
176 struct mxs_power_regs *power_regs =
177 (struct mxs_power_regs *)MXS_POWER_BASE;
178 uint32_t volt = readl(&power_regs->hw_power_battmonitor);
179 volt &= POWER_BATTMONITOR_BATT_VAL_MASK;
180 volt >>= POWER_BATTMONITOR_BATT_VAL_OFFSET;
183 debug("SPL: Battery Voltage = %dmV\n", volt);
188 * mxs_is_batt_ready() - Test if the battery provides enough voltage to boot
190 * This function checks if the battery input voltage is higher than 3.6V and
191 * therefore allows the system to successfully boot using this power source.
193 static int mxs_is_batt_ready(void)
195 return (mxs_get_batt_volt() >= 3600);
199 * mxs_is_batt_good() - Test if battery is operational at all
201 * This function starts recharging the battery and tests if the input current
202 * provided by the 5V input recharging the battery is also sufficient to power
203 * the DC-DC converter.
205 static int mxs_is_batt_good(void)
207 struct mxs_power_regs *power_regs =
208 (struct mxs_power_regs *)MXS_POWER_BASE;
209 uint32_t volt = mxs_get_batt_volt();
211 if ((volt >= 2400) && (volt <= 4300)) {
212 debug("SPL: Battery is good\n");
216 clrsetbits_le32(&power_regs->hw_power_5vctrl,
217 POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK,
218 0x3 << POWER_5VCTRL_CHARGE_4P2_ILIMIT_OFFSET);
219 writel(POWER_5VCTRL_PWD_CHARGE_4P2_MASK,
220 &power_regs->hw_power_5vctrl_clr);
222 clrsetbits_le32(&power_regs->hw_power_charge,
223 POWER_CHARGE_STOP_ILIMIT_MASK | POWER_CHARGE_BATTCHRG_I_MASK,
224 POWER_CHARGE_STOP_ILIMIT_10MA | 0x3);
226 writel(POWER_CHARGE_PWD_BATTCHRG, &power_regs->hw_power_charge_clr);
227 writel(POWER_5VCTRL_PWD_CHARGE_4P2_MASK,
228 &power_regs->hw_power_5vctrl_clr);
232 volt = mxs_get_batt_volt();
235 debug("SPL: Battery Voltage too high\n");
240 debug("SPL: Battery is good\n");
244 writel(POWER_CHARGE_STOP_ILIMIT_MASK | POWER_CHARGE_BATTCHRG_I_MASK,
245 &power_regs->hw_power_charge_clr);
246 writel(POWER_CHARGE_PWD_BATTCHRG, &power_regs->hw_power_charge_set);
248 debug("SPL: Battery Voltage too low\n");
253 * mxs_power_setup_5v_detect() - Start the 5V input detection comparator
255 * This function enables the 5V detection comparator and sets the 5V valid
256 * threshold to 4.4V . We use 4.4V threshold here to make sure that even
257 * under high load, the voltage drop on the 5V input won't be so critical
258 * to cause undervolt on the 4P2 linear regulator supplying the DC-DC
259 * converter and thus making the system crash.
261 static void mxs_power_setup_5v_detect(void)
263 struct mxs_power_regs *power_regs =
264 (struct mxs_power_regs *)MXS_POWER_BASE;
266 /* Start 5V detection */
267 debug("SPL: Starting 5V input detection comparator\n");
268 clrsetbits_le32(&power_regs->hw_power_5vctrl,
269 POWER_5VCTRL_VBUSVALID_TRSH_MASK,
270 POWER_5VCTRL_VBUSVALID_TRSH_4V4 |
271 POWER_5VCTRL_PWRUP_VBUS_CMPS);
275 * mxs_power_switch_dcdc_clocksource() - Switch PLL clock for DC-DC converters
276 * @freqsel: One of the POWER_MISC_FREQSEL_xxx defines to select the clock
278 * This function configures and then enables an alternative PLL clock source
279 * for the DC-DC converters.
281 void mxs_power_switch_dcdc_clocksource(uint32_t freqsel)
283 struct mxs_power_regs *power_regs =
284 (struct mxs_power_regs *)MXS_POWER_BASE;
286 /* Select clocksource for DC-DC converters */
287 clrsetbits_le32(&power_regs->hw_power_misc,
288 POWER_MISC_FREQSEL_MASK,
290 setbits_le32(&power_regs->hw_power_misc,
291 POWER_MISC_SEL_PLLCLK);
295 * mxs_power_setup_dcdc_clocksource() - Setup PLL clock source for DC-DC converters
297 * Normally, there is no need to switch DC-DC clocksource. This is the reason,
298 * why this function is a stub and does nothing. However, boards can implement
299 * this function when required and call mxs_power_switch_dcdc_clocksource() to
300 * switch to an alternative clock source.
302 __weak void mxs_power_setup_dcdc_clocksource(void)
304 debug("SPL: Using default DC-DC clocksource\n");
308 * mxs_src_power_init() - Preconfigure the power block
310 * This function configures reasonable values for the DC-DC control loop
311 * and battery monitor.
313 static void mxs_src_power_init(void)
315 struct mxs_power_regs *power_regs =
316 (struct mxs_power_regs *)MXS_POWER_BASE;
318 debug("SPL: Pre-Configuring power block\n");
320 /* Improve efficieny and reduce transient ripple */
321 writel(POWER_LOOPCTRL_TOGGLE_DIF | POWER_LOOPCTRL_EN_CM_HYST |
322 POWER_LOOPCTRL_EN_DF_HYST, &power_regs->hw_power_loopctrl_set);
324 clrsetbits_le32(&power_regs->hw_power_dclimits,
325 POWER_DCLIMITS_POSLIMIT_BUCK_MASK,
326 0x30 << POWER_DCLIMITS_POSLIMIT_BUCK_OFFSET);
328 setbits_le32(&power_regs->hw_power_battmonitor,
329 POWER_BATTMONITOR_EN_BATADJ);
331 /* Increase the RCSCALE level for quick DCDC response to dynamic load */
332 clrsetbits_le32(&power_regs->hw_power_loopctrl,
333 POWER_LOOPCTRL_EN_RCSCALE_MASK,
334 POWER_LOOPCTRL_RCSCALE_THRESH |
335 POWER_LOOPCTRL_EN_RCSCALE_8X);
337 clrsetbits_le32(&power_regs->hw_power_minpwr,
338 POWER_MINPWR_HALFFETS, POWER_MINPWR_DOUBLE_FETS);
340 /* 5V to battery handoff ... FIXME */
341 setbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_DCDC_XFER);
343 clrbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_DCDC_XFER);
347 * mxs_power_init_4p2_params() - Configure the parameters of the 4P2 regulator
349 * This function configures the necessary parameters for the 4P2 linear
350 * regulator to supply the DC-DC converter from 5V input.
352 static void mxs_power_init_4p2_params(void)
354 struct mxs_power_regs *power_regs =
355 (struct mxs_power_regs *)MXS_POWER_BASE;
357 debug("SPL: Configuring common 4P2 regulator params\n");
359 /* Setup 4P2 parameters */
360 clrsetbits_le32(&power_regs->hw_power_dcdc4p2,
361 POWER_DCDC4P2_CMPTRIP_MASK | POWER_DCDC4P2_TRG_MASK,
362 POWER_DCDC4P2_TRG_4V2 | (31 << POWER_DCDC4P2_CMPTRIP_OFFSET));
364 clrsetbits_le32(&power_regs->hw_power_5vctrl,
365 POWER_5VCTRL_HEADROOM_ADJ_MASK,
366 0x4 << POWER_5VCTRL_HEADROOM_ADJ_OFFSET);
368 clrsetbits_le32(&power_regs->hw_power_dcdc4p2,
369 POWER_DCDC4P2_DROPOUT_CTRL_MASK,
370 DCDC4P2_DROPOUT_CONFIG);
372 clrsetbits_le32(&power_regs->hw_power_5vctrl,
373 POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK,
374 0x3f << POWER_5VCTRL_CHARGE_4P2_ILIMIT_OFFSET);
378 * mxs_enable_4p2_dcdc_input() - Enable or disable the DCDC input from 4P2
379 * @xfer: Select if the input shall be enabled or disabled
381 * This function enables or disables the 4P2 input into the DC-DC converter.
383 static void mxs_enable_4p2_dcdc_input(int xfer)
385 struct mxs_power_regs *power_regs =
386 (struct mxs_power_regs *)MXS_POWER_BASE;
387 uint32_t tmp, vbus_thresh, vbus_5vdetect, pwd_bo;
388 uint32_t prev_5v_brnout, prev_5v_droop;
390 debug("SPL: %s 4P2 DC-DC Input\n", xfer ? "Enabling" : "Disabling");
392 if (xfer && (readl(&power_regs->hw_power_5vctrl) &
393 POWER_5VCTRL_ENABLE_DCDC)) {
397 prev_5v_brnout = readl(&power_regs->hw_power_5vctrl) &
398 POWER_5VCTRL_PWDN_5VBRNOUT;
399 prev_5v_droop = readl(&power_regs->hw_power_ctrl) &
400 POWER_CTRL_ENIRQ_VDD5V_DROOP;
402 clrbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_PWDN_5VBRNOUT);
403 writel(POWER_RESET_UNLOCK_KEY | POWER_RESET_PWD_OFF,
404 &power_regs->hw_power_reset);
406 clrbits_le32(&power_regs->hw_power_ctrl, POWER_CTRL_ENIRQ_VDD5V_DROOP);
409 * Recording orignal values that will be modified temporarlily
410 * to handle a chip bug. See chip errata for CQ ENGR00115837
412 tmp = readl(&power_regs->hw_power_5vctrl);
413 vbus_thresh = tmp & POWER_5VCTRL_VBUSVALID_TRSH_MASK;
414 vbus_5vdetect = tmp & POWER_5VCTRL_VBUSVALID_5VDETECT;
416 pwd_bo = readl(&power_regs->hw_power_minpwr) & POWER_MINPWR_PWD_BO;
419 * Disable mechanisms that get erroneously tripped by when setting
420 * the DCDC4P2 EN_DCDC
422 clrbits_le32(&power_regs->hw_power_5vctrl,
423 POWER_5VCTRL_VBUSVALID_5VDETECT |
424 POWER_5VCTRL_VBUSVALID_TRSH_MASK);
426 writel(POWER_MINPWR_PWD_BO, &power_regs->hw_power_minpwr_set);
429 setbits_le32(&power_regs->hw_power_5vctrl,
430 POWER_5VCTRL_DCDC_XFER);
432 clrbits_le32(&power_regs->hw_power_5vctrl,
433 POWER_5VCTRL_DCDC_XFER);
435 setbits_le32(&power_regs->hw_power_5vctrl,
436 POWER_5VCTRL_ENABLE_DCDC);
438 setbits_le32(&power_regs->hw_power_dcdc4p2,
439 POWER_DCDC4P2_ENABLE_DCDC);
444 clrsetbits_le32(&power_regs->hw_power_5vctrl,
445 POWER_5VCTRL_VBUSVALID_TRSH_MASK, vbus_thresh);
448 writel(vbus_5vdetect, &power_regs->hw_power_5vctrl_set);
451 clrbits_le32(&power_regs->hw_power_minpwr, POWER_MINPWR_PWD_BO);
453 while (readl(&power_regs->hw_power_ctrl) & POWER_CTRL_VBUS_VALID_IRQ)
454 writel(POWER_CTRL_VBUS_VALID_IRQ,
455 &power_regs->hw_power_ctrl_clr);
457 if (prev_5v_brnout) {
458 writel(POWER_5VCTRL_PWDN_5VBRNOUT,
459 &power_regs->hw_power_5vctrl_set);
460 writel(POWER_RESET_UNLOCK_KEY,
461 &power_regs->hw_power_reset);
463 writel(POWER_5VCTRL_PWDN_5VBRNOUT,
464 &power_regs->hw_power_5vctrl_clr);
465 writel(POWER_RESET_UNLOCK_KEY | POWER_RESET_PWD_OFF,
466 &power_regs->hw_power_reset);
469 while (readl(&power_regs->hw_power_ctrl) & POWER_CTRL_VDD5V_DROOP_IRQ)
470 writel(POWER_CTRL_VDD5V_DROOP_IRQ,
471 &power_regs->hw_power_ctrl_clr);
474 clrbits_le32(&power_regs->hw_power_ctrl,
475 POWER_CTRL_ENIRQ_VDD5V_DROOP);
477 setbits_le32(&power_regs->hw_power_ctrl,
478 POWER_CTRL_ENIRQ_VDD5V_DROOP);
482 * mxs_power_init_4p2_regulator() - Start the 4P2 regulator
484 * This function enables the 4P2 regulator and switches the DC-DC converter
485 * to use the 4P2 input.
487 static void mxs_power_init_4p2_regulator(void)
489 struct mxs_power_regs *power_regs =
490 (struct mxs_power_regs *)MXS_POWER_BASE;
493 debug("SPL: Enabling 4P2 regulator\n");
495 setbits_le32(&power_regs->hw_power_dcdc4p2, POWER_DCDC4P2_ENABLE_4P2);
497 writel(POWER_CHARGE_ENABLE_LOAD, &power_regs->hw_power_charge_set);
499 writel(POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK,
500 &power_regs->hw_power_5vctrl_clr);
501 clrbits_le32(&power_regs->hw_power_dcdc4p2, POWER_DCDC4P2_TRG_MASK);
503 /* Power up the 4p2 rail and logic/control */
504 writel(POWER_5VCTRL_PWD_CHARGE_4P2_MASK,
505 &power_regs->hw_power_5vctrl_clr);
508 * Start charging up the 4p2 capacitor. We ramp of this charge
509 * gradually to avoid large inrush current from the 5V cable which can
510 * cause transients/problems
512 debug("SPL: Charging 4P2 capacitor\n");
513 mxs_enable_4p2_dcdc_input(0);
515 if (readl(&power_regs->hw_power_ctrl) & POWER_CTRL_VBUS_VALID_IRQ) {
517 * If we arrived here, we were unable to recover from mx23 chip
518 * errata 5837. 4P2 is disabled and sufficient battery power is
519 * not present. Exiting to not enable DCDC power during 5V
522 clrbits_le32(&power_regs->hw_power_dcdc4p2,
523 POWER_DCDC4P2_ENABLE_DCDC);
524 writel(POWER_5VCTRL_PWD_CHARGE_4P2_MASK,
525 &power_regs->hw_power_5vctrl_set);
527 debug("SPL: Unable to recover from mx23 errata 5837\n");
532 * Here we set the 4p2 brownout level to something very close to 4.2V.
533 * We then check the brownout status. If the brownout status is false,
534 * the voltage is already close to the target voltage of 4.2V so we
535 * can go ahead and set the 4P2 current limit to our max target limit.
536 * If the brownout status is true, we need to ramp us the current limit
537 * so that we don't cause large inrush current issues. We step up the
538 * current limit until the brownout status is false or until we've
539 * reached our maximum defined 4p2 current limit.
541 debug("SPL: Setting 4P2 brownout level\n");
542 clrsetbits_le32(&power_regs->hw_power_dcdc4p2,
543 POWER_DCDC4P2_BO_MASK,
544 22 << POWER_DCDC4P2_BO_OFFSET); /* 4.15V */
546 if (!(readl(&power_regs->hw_power_sts) & POWER_STS_DCDC_4P2_BO)) {
547 setbits_le32(&power_regs->hw_power_5vctrl,
548 0x3f << POWER_5VCTRL_CHARGE_4P2_ILIMIT_OFFSET);
550 tmp = (readl(&power_regs->hw_power_5vctrl) &
551 POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK) >>
552 POWER_5VCTRL_CHARGE_4P2_ILIMIT_OFFSET;
554 if (!(readl(&power_regs->hw_power_sts) &
555 POWER_STS_DCDC_4P2_BO)) {
556 tmp = readl(&power_regs->hw_power_5vctrl);
557 tmp |= POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK;
559 writel(tmp, &power_regs->hw_power_5vctrl);
563 tmp2 = readl(&power_regs->hw_power_5vctrl);
564 tmp2 &= ~POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK;
566 POWER_5VCTRL_CHARGE_4P2_ILIMIT_OFFSET;
567 writel(tmp2, &power_regs->hw_power_5vctrl);
573 clrbits_le32(&power_regs->hw_power_dcdc4p2, POWER_DCDC4P2_BO_MASK);
574 writel(POWER_CTRL_DCDC4P2_BO_IRQ, &power_regs->hw_power_ctrl_clr);
578 * mxs_power_init_dcdc_4p2_source() - Switch DC-DC converter to 4P2 source
580 * This function configures the DC-DC converter to be supplied from the 4P2
583 static void mxs_power_init_dcdc_4p2_source(void)
585 struct mxs_power_regs *power_regs =
586 (struct mxs_power_regs *)MXS_POWER_BASE;
588 debug("SPL: Switching DC-DC converters to 4P2\n");
590 if (!(readl(&power_regs->hw_power_dcdc4p2) &
591 POWER_DCDC4P2_ENABLE_DCDC)) {
592 debug("SPL: Already switched - aborting\n");
596 mxs_enable_4p2_dcdc_input(1);
598 if (readl(&power_regs->hw_power_ctrl) & POWER_CTRL_VBUS_VALID_IRQ) {
599 clrbits_le32(&power_regs->hw_power_dcdc4p2,
600 POWER_DCDC4P2_ENABLE_DCDC);
601 writel(POWER_5VCTRL_ENABLE_DCDC,
602 &power_regs->hw_power_5vctrl_clr);
603 writel(POWER_5VCTRL_PWD_CHARGE_4P2_MASK,
604 &power_regs->hw_power_5vctrl_set);
609 * mxs_power_enable_4p2() - Power up the 4P2 regulator
611 * This function drives the process of powering up the 4P2 linear regulator
612 * and switching the DC-DC converter input over to the 4P2 linear regulator.
614 static void mxs_power_enable_4p2(void)
616 struct mxs_power_regs *power_regs =
617 (struct mxs_power_regs *)MXS_POWER_BASE;
618 uint32_t vdddctrl, vddactrl, vddioctrl;
621 debug("SPL: Powering up 4P2 regulator\n");
623 vdddctrl = readl(&power_regs->hw_power_vdddctrl);
624 vddactrl = readl(&power_regs->hw_power_vddactrl);
625 vddioctrl = readl(&power_regs->hw_power_vddioctrl);
627 setbits_le32(&power_regs->hw_power_vdddctrl,
628 POWER_VDDDCTRL_DISABLE_FET | POWER_VDDDCTRL_ENABLE_LINREG |
629 POWER_VDDDCTRL_PWDN_BRNOUT);
631 setbits_le32(&power_regs->hw_power_vddactrl,
632 POWER_VDDACTRL_DISABLE_FET | POWER_VDDACTRL_ENABLE_LINREG |
633 POWER_VDDACTRL_PWDN_BRNOUT);
635 setbits_le32(&power_regs->hw_power_vddioctrl,
636 POWER_VDDIOCTRL_DISABLE_FET | POWER_VDDIOCTRL_PWDN_BRNOUT);
638 mxs_power_init_4p2_params();
639 mxs_power_init_4p2_regulator();
641 /* Shutdown battery (none present) */
642 if (!mxs_is_batt_ready()) {
643 clrbits_le32(&power_regs->hw_power_dcdc4p2,
644 POWER_DCDC4P2_BO_MASK);
645 writel(POWER_CTRL_DCDC4P2_BO_IRQ,
646 &power_regs->hw_power_ctrl_clr);
647 writel(POWER_CTRL_ENIRQ_DCDC4P2_BO,
648 &power_regs->hw_power_ctrl_clr);
651 mxs_power_init_dcdc_4p2_source();
653 writel(vddioctrl, &power_regs->hw_power_vddioctrl);
655 writel(vddactrl, &power_regs->hw_power_vddactrl);
657 writel(vdddctrl, &power_regs->hw_power_vdddctrl);
660 * Check if FET is enabled on either powerout and if so,
664 tmp |= !(readl(&power_regs->hw_power_vdddctrl) &
665 POWER_VDDDCTRL_DISABLE_FET);
666 tmp |= !(readl(&power_regs->hw_power_vddactrl) &
667 POWER_VDDACTRL_DISABLE_FET);
668 tmp |= !(readl(&power_regs->hw_power_vddioctrl) &
669 POWER_VDDIOCTRL_DISABLE_FET);
671 writel(POWER_CHARGE_ENABLE_LOAD,
672 &power_regs->hw_power_charge_clr);
674 debug("SPL: 4P2 regulator powered-up\n");
678 * mxs_boot_valid_5v() - Boot from 5V supply
680 * This function configures the power block to boot from valid 5V input.
681 * This is called only if the 5V is reliable and can properly supply the
682 * CPU. This function proceeds to configure the 4P2 converter to be supplied
685 static void mxs_boot_valid_5v(void)
687 struct mxs_power_regs *power_regs =
688 (struct mxs_power_regs *)MXS_POWER_BASE;
690 debug("SPL: Booting from 5V supply\n");
693 * Use VBUSVALID level instead of VDD5V_GT_VDDIO level to trigger a 5V
694 * disconnect event. FIXME
696 writel(POWER_5VCTRL_VBUSVALID_5VDETECT,
697 &power_regs->hw_power_5vctrl_set);
699 /* Configure polarity to check for 5V disconnection. */
700 writel(POWER_CTRL_POLARITY_VBUSVALID |
701 POWER_CTRL_POLARITY_VDD5V_GT_VDDIO,
702 &power_regs->hw_power_ctrl_clr);
704 writel(POWER_CTRL_VBUS_VALID_IRQ | POWER_CTRL_VDD5V_GT_VDDIO_IRQ,
705 &power_regs->hw_power_ctrl_clr);
707 mxs_power_enable_4p2();
711 * mxs_powerdown() - Shut down the system
713 * This function powers down the CPU completely.
715 static void mxs_powerdown(void)
717 struct mxs_power_regs *power_regs =
718 (struct mxs_power_regs *)MXS_POWER_BASE;
720 debug("Powering Down\n");
722 writel(POWER_RESET_UNLOCK_KEY, &power_regs->hw_power_reset);
723 writel(POWER_RESET_UNLOCK_KEY | POWER_RESET_PWD_OFF,
724 &power_regs->hw_power_reset);
728 * mxs_batt_boot() - Configure the power block to boot from battery input
730 * This function configures the power block to boot from the battery voltage
733 static void mxs_batt_boot(void)
735 struct mxs_power_regs *power_regs =
736 (struct mxs_power_regs *)MXS_POWER_BASE;
738 debug("SPL: Configuring power block to boot from battery\n");
740 clrbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_PWDN_5VBRNOUT);
741 clrbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_ENABLE_DCDC);
743 clrbits_le32(&power_regs->hw_power_dcdc4p2,
744 POWER_DCDC4P2_ENABLE_DCDC | POWER_DCDC4P2_ENABLE_4P2);
745 writel(POWER_CHARGE_ENABLE_LOAD, &power_regs->hw_power_charge_clr);
747 /* 5V to battery handoff. */
748 setbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_DCDC_XFER);
750 clrbits_le32(&power_regs->hw_power_5vctrl, POWER_5VCTRL_DCDC_XFER);
752 writel(POWER_CTRL_ENIRQ_DCDC4P2_BO, &power_regs->hw_power_ctrl_clr);
754 clrsetbits_le32(&power_regs->hw_power_minpwr,
755 POWER_MINPWR_HALFFETS, POWER_MINPWR_DOUBLE_FETS);
757 mxs_power_set_linreg();
759 clrbits_le32(&power_regs->hw_power_vdddctrl,
760 POWER_VDDDCTRL_DISABLE_FET | POWER_VDDDCTRL_ENABLE_LINREG);
762 clrbits_le32(&power_regs->hw_power_vddactrl,
763 POWER_VDDACTRL_DISABLE_FET | POWER_VDDACTRL_ENABLE_LINREG);
765 clrbits_le32(&power_regs->hw_power_vddioctrl,
766 POWER_VDDIOCTRL_DISABLE_FET);
768 setbits_le32(&power_regs->hw_power_5vctrl,
769 POWER_5VCTRL_PWD_CHARGE_4P2_MASK);
771 setbits_le32(&power_regs->hw_power_5vctrl,
772 POWER_5VCTRL_ENABLE_DCDC);
774 clrsetbits_le32(&power_regs->hw_power_5vctrl,
775 POWER_5VCTRL_CHARGE_4P2_ILIMIT_MASK,
776 0x8 << POWER_5VCTRL_CHARGE_4P2_ILIMIT_OFFSET);
778 if (CONFIG_IS_ENABLED(MXS_PMU_MINIMAL_VDD5V_CURRENT))
779 setbits_le32(&power_regs->hw_power_5vctrl,
780 POWER_5VCTRL_ILIMIT_EQ_ZERO);
782 if (CONFIG_IS_ENABLED(MXS_PMU_DISABLE_BATT_CHARGE)) {
783 writel(POWER_CHARGE_PWD_BATTCHRG,
784 &power_regs->hw_power_charge_set);
785 writel(POWER_5VCTRL_PWD_CHARGE_4P2_MASK,
786 &power_regs->hw_power_5vctrl_set);
789 if (CONFIG_IS_ENABLED(MXS_PMU_ENABLE_4P2_LINEAR_REGULATOR))
790 mxs_power_enable_4p2();
794 * mxs_handle_5v_conflict() - Test if the 5V input is reliable
796 * This function tests if the 5V input can reliably supply the system. If it
797 * can, then proceed to configuring the system to boot from 5V source, otherwise
798 * try booting from battery supply. If we can not boot from battery supply
799 * either, shut down the system.
801 static void mxs_handle_5v_conflict(void)
803 struct mxs_power_regs *power_regs =
804 (struct mxs_power_regs *)MXS_POWER_BASE;
807 debug("SPL: Resolving 5V conflict\n");
809 setbits_le32(&power_regs->hw_power_vddioctrl,
810 POWER_VDDIOCTRL_BO_OFFSET_MASK);
813 tmp = readl(&power_regs->hw_power_sts);
815 if (tmp & POWER_STS_VDDIO_BO) {
817 * VDDIO has a brownout, then the VDD5V_GT_VDDIO becomes
820 debug("SPL: VDDIO has a brownout\n");
825 if (tmp & POWER_STS_VDD5V_GT_VDDIO) {
826 debug("SPL: POWER_STS_VDD5V_GT_VDDIO is set\n");
830 debug("SPL: POWER_STS_VDD5V_GT_VDDIO is not set\n");
836 * TODO: I can't see this being reached. We'll either
837 * powerdown or boot from a stable 5V supply.
839 if (tmp & POWER_STS_PSWITCH_MASK) {
840 debug("SPL: POWER_STS_PSWITCH_MASK is set\n");
848 * mxs_5v_boot() - Configure the power block to boot from 5V input
850 * This function handles configuration of the power block when supplied by
853 static void mxs_5v_boot(void)
855 struct mxs_power_regs *power_regs =
856 (struct mxs_power_regs *)MXS_POWER_BASE;
858 debug("SPL: Configuring power block to boot from 5V input\n");
861 * NOTE: In original IMX-Bootlets, this also checks for VBUSVALID,
862 * but their implementation always returns 1 so we omit it here.
864 if (readl(&power_regs->hw_power_sts) & POWER_STS_VDD5V_GT_VDDIO) {
865 debug("SPL: 5V VDD good\n");
871 if (readl(&power_regs->hw_power_sts) & POWER_STS_VDD5V_GT_VDDIO) {
872 debug("SPL: 5V VDD good (after delay)\n");
877 debug("SPL: 5V VDD not good\n");
878 mxs_handle_5v_conflict();
882 * mxs_init_batt_bo() - Configure battery brownout threshold
884 * This function configures the battery input brownout threshold. The value
885 * at which the battery brownout happens is configured to 3.0V in the code.
887 static void mxs_init_batt_bo(void)
889 struct mxs_power_regs *power_regs =
890 (struct mxs_power_regs *)MXS_POWER_BASE;
892 debug("SPL: Initialising battery brown-out level to 3.0V\n");
895 clrsetbits_le32(&power_regs->hw_power_battmonitor,
896 POWER_BATTMONITOR_BRWNOUT_LVL_MASK,
897 15 << POWER_BATTMONITOR_BRWNOUT_LVL_OFFSET);
899 writel(POWER_CTRL_BATT_BO_IRQ, &power_regs->hw_power_ctrl_clr);
900 writel(POWER_CTRL_ENIRQ_BATT_BO, &power_regs->hw_power_ctrl_clr);
904 * mxs_switch_vddd_to_dcdc_source() - Switch VDDD rail to DC-DC converter
906 * This function turns off the VDDD linear regulator and therefore makes
907 * the VDDD rail be supplied only by the DC-DC converter.
909 static void mxs_switch_vddd_to_dcdc_source(void)
911 struct mxs_power_regs *power_regs =
912 (struct mxs_power_regs *)MXS_POWER_BASE;
914 debug("SPL: Switching VDDD to DC-DC converters\n");
916 clrsetbits_le32(&power_regs->hw_power_vdddctrl,
917 POWER_VDDDCTRL_LINREG_OFFSET_MASK,
918 POWER_VDDDCTRL_LINREG_OFFSET_1STEPS_BELOW);
920 clrbits_le32(&power_regs->hw_power_vdddctrl,
921 POWER_VDDDCTRL_DISABLE_FET | POWER_VDDDCTRL_ENABLE_LINREG |
922 POWER_VDDDCTRL_DISABLE_STEPPING);
926 * mxs_power_configure_power_source() - Configure power block source
928 * This function is the core of the power configuration logic. The function
929 * selects the power block input source and configures the whole power block
930 * accordingly. After the configuration is complete and the system is stable
931 * again, the function switches the CPU clock source back to PLL. Finally,
932 * the function switches the voltage rails to DC-DC converter.
934 static void mxs_power_configure_power_source(void)
936 int batt_ready, batt_good;
937 struct mxs_power_regs *power_regs =
938 (struct mxs_power_regs *)MXS_POWER_BASE;
939 struct mxs_lradc_regs *lradc_regs =
940 (struct mxs_lradc_regs *)MXS_LRADC_BASE;
942 debug("SPL: Configuring power source\n");
944 mxs_power_setup_dcdc_clocksource();
945 mxs_src_power_init();
947 if (readl(&power_regs->hw_power_sts) & POWER_STS_VDD5V_GT_VDDIO) {
948 batt_ready = mxs_is_batt_ready();
950 /* 5V source detected, good battery detected. */
953 batt_good = mxs_is_batt_good();
955 /* 5V source detected, bad battery detected. */
956 writel(LRADC_CONVERSION_AUTOMATIC,
957 &lradc_regs->hw_lradc_conversion_clr);
958 clrbits_le32(&power_regs->hw_power_battmonitor,
959 POWER_BATTMONITOR_BATT_VAL_MASK);
964 /* 5V not detected, booting from battery. */
969 * TODO: Do not switch CPU clock to PLL if we are VDD5V is sourced
972 mxs_power_clock2pll();
976 mxs_switch_vddd_to_dcdc_source();
979 /* Fire up the VDDMEM LinReg now that we're all set. */
980 debug("SPL: Enabling mx23 VDDMEM linear regulator\n");
981 writel(POWER_VDDMEMCTRL_ENABLE_LINREG | POWER_VDDMEMCTRL_ENABLE_ILIMIT,
982 &power_regs->hw_power_vddmemctrl);
987 * mxs_enable_output_rail_protection() - Enable power rail protection
989 * This function enables overload protection on the power rails. This is
990 * triggered if the power rails' voltage drops rapidly due to overload and
991 * in such case, the supply to the powerrail is cut-off, protecting the
992 * CPU from damage. Note that under such condition, the system will likely
993 * crash or misbehave.
995 static void mxs_enable_output_rail_protection(void)
997 struct mxs_power_regs *power_regs =
998 (struct mxs_power_regs *)MXS_POWER_BASE;
1000 debug("SPL: Enabling output rail protection\n");
1002 writel(POWER_CTRL_VDDD_BO_IRQ | POWER_CTRL_VDDA_BO_IRQ |
1003 POWER_CTRL_VDDIO_BO_IRQ, &power_regs->hw_power_ctrl_clr);
1005 setbits_le32(&power_regs->hw_power_vdddctrl,
1006 POWER_VDDDCTRL_PWDN_BRNOUT);
1008 setbits_le32(&power_regs->hw_power_vddactrl,
1009 POWER_VDDACTRL_PWDN_BRNOUT);
1011 setbits_le32(&power_regs->hw_power_vddioctrl,
1012 POWER_VDDIOCTRL_PWDN_BRNOUT);
1016 * mxs_get_vddio_power_source_off() - Get VDDIO rail power source
1018 * This function tests if the VDDIO rail is supplied by linear regulator
1019 * or by the DC-DC converter. Returns 1 if powered by linear regulator,
1020 * returns 0 if powered by the DC-DC converter.
1022 static int mxs_get_vddio_power_source_off(void)
1024 struct mxs_power_regs *power_regs =
1025 (struct mxs_power_regs *)MXS_POWER_BASE;
1028 if (readl(&power_regs->hw_power_sts) & POWER_STS_VDD5V_GT_VDDIO) {
1029 tmp = readl(&power_regs->hw_power_vddioctrl);
1030 if (tmp & POWER_VDDIOCTRL_DISABLE_FET) {
1031 if ((tmp & POWER_VDDIOCTRL_LINREG_OFFSET_MASK) ==
1032 POWER_VDDIOCTRL_LINREG_OFFSET_0STEPS) {
1037 if (!(readl(&power_regs->hw_power_5vctrl) &
1038 POWER_5VCTRL_ENABLE_DCDC)) {
1039 if ((tmp & POWER_VDDIOCTRL_LINREG_OFFSET_MASK) ==
1040 POWER_VDDIOCTRL_LINREG_OFFSET_0STEPS) {
1051 * mxs_get_vddd_power_source_off() - Get VDDD rail power source
1053 * This function tests if the VDDD rail is supplied by linear regulator
1054 * or by the DC-DC converter. Returns 1 if powered by linear regulator,
1055 * returns 0 if powered by the DC-DC converter.
1057 static int mxs_get_vddd_power_source_off(void)
1059 struct mxs_power_regs *power_regs =
1060 (struct mxs_power_regs *)MXS_POWER_BASE;
1063 tmp = readl(&power_regs->hw_power_vdddctrl);
1064 if (tmp & POWER_VDDDCTRL_DISABLE_FET) {
1065 if ((tmp & POWER_VDDDCTRL_LINREG_OFFSET_MASK) ==
1066 POWER_VDDDCTRL_LINREG_OFFSET_0STEPS) {
1071 if (readl(&power_regs->hw_power_sts) & POWER_STS_VDD5V_GT_VDDIO) {
1072 if (!(readl(&power_regs->hw_power_5vctrl) &
1073 POWER_5VCTRL_ENABLE_DCDC)) {
1078 if (!(tmp & POWER_VDDDCTRL_ENABLE_LINREG)) {
1079 if ((tmp & POWER_VDDDCTRL_LINREG_OFFSET_MASK) ==
1080 POWER_VDDDCTRL_LINREG_OFFSET_1STEPS_BELOW) {
1088 struct mxs_vddx_cfg {
1092 int (*powered_by_linreg)(void);
1096 uint32_t bo_offset_mask;
1097 uint32_t bo_offset_offset;
1100 static const struct mxs_vddx_cfg mxs_vddio_cfg = {
1101 .reg = &(((struct mxs_power_regs *)MXS_POWER_BASE)->
1102 hw_power_vddioctrl),
1103 #if defined(CONFIG_MX23)
1109 .powered_by_linreg = mxs_get_vddio_power_source_off,
1110 .trg_mask = POWER_VDDIOCTRL_TRG_MASK,
1111 .bo_irq = POWER_CTRL_VDDIO_BO_IRQ,
1112 .bo_enirq = POWER_CTRL_ENIRQ_VDDIO_BO,
1113 .bo_offset_mask = POWER_VDDIOCTRL_BO_OFFSET_MASK,
1114 .bo_offset_offset = POWER_VDDIOCTRL_BO_OFFSET_OFFSET,
1117 static const struct mxs_vddx_cfg mxs_vddd_cfg = {
1118 .reg = &(((struct mxs_power_regs *)MXS_POWER_BASE)->
1122 .powered_by_linreg = mxs_get_vddd_power_source_off,
1123 .trg_mask = POWER_VDDDCTRL_TRG_MASK,
1124 .bo_irq = POWER_CTRL_VDDD_BO_IRQ,
1125 .bo_enirq = POWER_CTRL_ENIRQ_VDDD_BO,
1126 .bo_offset_mask = POWER_VDDDCTRL_BO_OFFSET_MASK,
1127 .bo_offset_offset = POWER_VDDDCTRL_BO_OFFSET_OFFSET,
1131 static const struct mxs_vddx_cfg mxs_vddmem_cfg = {
1132 .reg = &(((struct mxs_power_regs *)MXS_POWER_BASE)->
1133 hw_power_vddmemctrl),
1136 .powered_by_linreg = NULL,
1137 .trg_mask = POWER_VDDMEMCTRL_TRG_MASK,
1140 .bo_offset_mask = 0,
1141 .bo_offset_offset = 0,
1146 * mxs_power_set_vddx() - Configure voltage on DC-DC converter rail
1147 * @cfg: Configuration data of the DC-DC converter rail
1148 * @new_target: New target voltage of the DC-DC converter rail
1149 * @new_brownout: New brownout trigger voltage
1151 * This function configures the output voltage on the DC-DC converter rail.
1152 * The rail is selected by the @cfg argument. The new voltage target is
1153 * selected by the @new_target and the voltage is specified in mV. The
1154 * new brownout value is selected by the @new_brownout argument and the
1155 * value is also in mV.
1157 static void mxs_power_set_vddx(const struct mxs_vddx_cfg *cfg,
1158 uint32_t new_target, uint32_t new_brownout)
1160 struct mxs_power_regs *power_regs =
1161 (struct mxs_power_regs *)MXS_POWER_BASE;
1162 uint32_t cur_target, diff, bo_int = 0;
1163 uint32_t powered_by_linreg = 0;
1166 new_brownout = DIV_ROUND_CLOSEST(new_target - new_brownout,
1169 cur_target = readl(cfg->reg);
1170 cur_target &= cfg->trg_mask;
1171 cur_target *= cfg->step_mV;
1172 cur_target += cfg->lowest_mV;
1174 adjust_up = new_target > cur_target;
1175 if (cfg->powered_by_linreg)
1176 powered_by_linreg = cfg->powered_by_linreg();
1178 if (adjust_up && cfg->bo_irq) {
1179 if (powered_by_linreg) {
1180 bo_int = readl(cfg->reg);
1181 clrbits_le32(cfg->reg, cfg->bo_enirq);
1183 setbits_le32(cfg->reg, cfg->bo_offset_mask);
1187 if (abs(new_target - cur_target) > 100) {
1189 diff = cur_target + 100;
1191 diff = cur_target - 100;
1196 diff -= cfg->lowest_mV;
1197 diff /= cfg->step_mV;
1199 clrsetbits_le32(cfg->reg, cfg->trg_mask, diff);
1201 if (powered_by_linreg ||
1202 (readl(&power_regs->hw_power_sts) &
1203 POWER_STS_VDD5V_GT_VDDIO))
1207 tmp = readl(&power_regs->hw_power_sts);
1208 if (tmp & POWER_STS_DC_OK)
1213 cur_target = readl(cfg->reg);
1214 cur_target &= cfg->trg_mask;
1215 cur_target *= cfg->step_mV;
1216 cur_target += cfg->lowest_mV;
1217 } while (new_target > cur_target);
1220 if (adjust_up && powered_by_linreg) {
1221 writel(cfg->bo_irq, &power_regs->hw_power_ctrl_clr);
1222 if (bo_int & cfg->bo_enirq)
1223 setbits_le32(cfg->reg, cfg->bo_enirq);
1226 clrsetbits_le32(cfg->reg, cfg->bo_offset_mask,
1227 new_brownout << cfg->bo_offset_offset);
1232 * mxs_setup_batt_detect() - Start the battery voltage measurement logic
1234 * This function starts and configures the LRADC block. This allows the
1235 * power initialization code to measure battery voltage and based on this
1236 * knowledge, decide whether to boot at all, boot from battery or boot
1239 static void mxs_setup_batt_detect(void)
1241 debug("SPL: Starting battery voltage measurement logic\n");
1244 mxs_lradc_enable_batt_measurement();
1249 * mxs_ungate_power() - Ungate the POWER block
1251 * This function ungates clock to the power block. In case the power block
1252 * was still gated at this point, it will not be possible to configure the
1253 * block and therefore the power initialization would fail. This function
1254 * is only needed on i.MX233, on i.MX28 the power block is always ungated.
1256 static void mxs_ungate_power(void)
1259 struct mxs_power_regs *power_regs =
1260 (struct mxs_power_regs *)MXS_POWER_BASE;
1262 writel(POWER_CTRL_CLKGATE, &power_regs->hw_power_ctrl_clr);
1267 * mxs_power_init() - The power block init main function
1269 * This function calls all the power block initialization functions in
1270 * proper sequence to start the power block.
1272 void mxs_power_init(void)
1274 struct mxs_power_regs *power_regs =
1275 (struct mxs_power_regs *)MXS_POWER_BASE;
1277 debug("SPL: Initialising Power Block\n");
1281 mxs_power_clock2xtal();
1282 mxs_power_set_auto_restart();
1283 mxs_power_set_linreg();
1284 mxs_power_setup_5v_detect();
1286 mxs_setup_batt_detect();
1288 mxs_power_configure_power_source();
1289 mxs_enable_output_rail_protection();
1291 debug("SPL: Setting VDDIO to 3V3 (brownout @ 3v15)\n");
1292 mxs_power_set_vddx(&mxs_vddio_cfg, 3300, 3150);
1294 debug("SPL: Setting VDDD to 1V55 (brownout @ 1v400)\n");
1295 mxs_power_set_vddx(&mxs_vddd_cfg, 1550, 1400);
1297 debug("SPL: Setting mx23 VDDMEM to 2V5 (brownout @ 1v7)\n");
1298 mxs_power_set_vddx(&mxs_vddmem_cfg, 2500, 1700);
1300 writel(POWER_CTRL_VDDD_BO_IRQ | POWER_CTRL_VDDA_BO_IRQ |
1301 POWER_CTRL_VDDIO_BO_IRQ | POWER_CTRL_VDD5V_DROOP_IRQ |
1302 POWER_CTRL_VBUS_VALID_IRQ | POWER_CTRL_BATT_BO_IRQ |
1303 POWER_CTRL_DCDC4P2_BO_IRQ, &power_regs->hw_power_ctrl_clr);
1305 writel(POWER_5VCTRL_PWDN_5VBRNOUT, &power_regs->hw_power_5vctrl_set);
1306 mxs_power_regs_dump();
1311 #ifdef CONFIG_SPL_MXS_PSWITCH_WAIT
1313 * mxs_power_wait_pswitch() - Wait for power switch to be pressed
1315 * This function waits until the power-switch was pressed to start booting
1318 void mxs_power_wait_pswitch(void)
1320 struct mxs_power_regs *power_regs =
1321 (struct mxs_power_regs *)MXS_POWER_BASE;
1323 debug("SPL: Waiting for power switch input\n");
1324 while (!(readl(&power_regs->hw_power_sts) & POWER_STS_PSWITCH_MASK))