blob: e9bd1028bed5013658aba7a871c81bf410876770 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -07002/*
3 * Copyright (c) 2012-2016 Toradex, Inc.
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -07004 */
5
6#include <common.h>
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -07008#include <asm/io.h>
9#include <asm/arch-tegra/tegra_i2c.h>
Simon Glassdbd79542020-05-10 11:40:11 -060010#include <linux/delay.h>
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070011
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020012/* AS3722-PMIC-specific early init regs */
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070013
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020014#define AS3722_I2C_ADDR 0x80
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070015
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020016#define AS3722_SD0VOLTAGE_REG 0x00 /* CPU */
17#define AS3722_SD1VOLTAGE_REG 0x01 /* CORE, already set by OTP */
18#define AS3722_SD6VOLTAGE_REG 0x06 /* GPU */
19#define AS3722_SDCONTROL_REG 0x4D
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070020
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020021#define AS3722_LDO1VOLTAGE_REG 0x11 /* VDD_SDMMC1 */
22#define AS3722_LDO2VOLTAGE_REG 0x12 /* VPP_FUSE */
23#define AS3722_LDO6VOLTAGE_REG 0x16 /* VDD_SDMMC3 */
24#define AS3722_LDCONTROL_REG 0x4E
25
26#define AS3722_SD0VOLTAGE_DATA (0x3C00 | AS3722_SD0VOLTAGE_REG)
27#define AS3722_SD0CONTROL_DATA (0x0100 | AS3722_SDCONTROL_REG)
28
29#define AS3722_SD1VOLTAGE_DATA (0x3200 | AS3722_SD1VOLTAGE_REG)
30#define AS3722_SD1CONTROL_DATA (0x0200 | AS3722_SDCONTROL_REG)
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070031
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020032#define AS3722_SD6CONTROL_DATA (0x4000 | AS3722_SDCONTROL_REG)
33#define AS3722_SD6VOLTAGE_DATA (0x2800 | AS3722_SD6VOLTAGE_REG)
34
35#define AS3722_LDO1CONTROL_DATA (0x0200 | AS3722_LDCONTROL_REG)
36#define AS3722_LDO1VOLTAGE_DATA (0x7F00 | AS3722_LDO1VOLTAGE_REG)
37
38#define AS3722_LDO2CONTROL_DATA (0x0400 | AS3722_LDCONTROL_REG)
39#define AS3722_LDO2VOLTAGE_DATA (0x1000 | AS3722_LDO2VOLTAGE_REG)
40
41#define AS3722_LDO6CONTROL_DATA (0x4000 | AS3722_LDCONTROL_REG)
42#define AS3722_LDO6VOLTAGE_DATA (0x3F00 | AS3722_LDO6VOLTAGE_REG)
43
44/* AS3722-PMIC-specific early init code - get CPU rails up, etc */
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070045
46void pmic_enable_cpu_vdd(void)
47{
48 debug("%s entry\n", __func__);
49
50#ifdef AS3722_SD1VOLTAGE_DATA
51 /* Set up VDD_CORE, for boards where OTP is incorrect*/
52 debug("%s: Setting VDD_CORE via AS3722 reg 1\n", __func__);
53 /* Configure VDD_CORE via the AS3722 PMIC on the PWR I2C bus */
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020054 tegra_i2c_ll_write(AS3722_I2C_ADDR,
55 AS3722_SD1VOLTAGE_DATA);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070056 /*
57 * Don't write SDCONTROL - it's already 0x7F, i.e. all SDs enabled.
58 * tegra_i2c_ll_write_data(AS3722_SD1CONTROL_DATA, I2C_SEND_2_BYTES);
59 */
60 udelay(10 * 1000);
61#endif
62
Dominik Sliwa3f6a2e22019-08-01 11:06:39 +030063 /*
64 * Make sure all non-fused regulators are down.
65 * That way we're in known state after software reboot from linux
66 */
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020067 tegra_i2c_ll_write(AS3722_I2C_ADDR, 0x0003);
Dominik Sliwa3f6a2e22019-08-01 11:06:39 +030068 udelay(10 * 1000);
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020069 tegra_i2c_ll_write(AS3722_I2C_ADDR, 0x0004);
Dominik Sliwa3f6a2e22019-08-01 11:06:39 +030070 udelay(10 * 1000);
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020071 tegra_i2c_ll_write(AS3722_I2C_ADDR, 0x001b);
Dominik Sliwa3f6a2e22019-08-01 11:06:39 +030072 udelay(10 * 1000);
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020073 tegra_i2c_ll_write(AS3722_I2C_ADDR, 0x0014);
Dominik Sliwa3f6a2e22019-08-01 11:06:39 +030074 udelay(10 * 1000);
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020075 tegra_i2c_ll_write(AS3722_I2C_ADDR, 0x001a);
Dominik Sliwa3f6a2e22019-08-01 11:06:39 +030076 udelay(10 * 1000);
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020077 tegra_i2c_ll_write(AS3722_I2C_ADDR, 0x0019);
Dominik Sliwa3f6a2e22019-08-01 11:06:39 +030078 udelay(10 * 1000);
79
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070080 debug("%s: Setting VDD_CPU to 1.0V via AS3722 reg 0/4D\n", __func__);
81 /*
82 * Bring up VDD_CPU via the AS3722 PMIC on the PWR I2C bus.
83 * First set VDD to 1.0V, then enable the VDD regulator.
84 */
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020085 tegra_i2c_ll_write(AS3722_I2C_ADDR,
86 AS3722_SD0VOLTAGE_DATA);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070087 /*
88 * Don't write SDCONTROL - it's already 0x7F, i.e. all SDs enabled.
89 * tegra_i2c_ll_write_data(AS3722_SD0CONTROL_DATA, I2C_SEND_2_BYTES);
90 */
91 udelay(10 * 1000);
92
93 debug("%s: Setting VDD_GPU to 1.0V via AS3722 reg 6/4D\n", __func__);
94 /*
95 * Bring up VDD_GPU via the AS3722 PMIC on the PWR I2C bus.
96 * First set VDD to 1.0V, then enable the VDD regulator.
97 */
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +020098 tegra_i2c_ll_write(AS3722_I2C_ADDR,
99 AS3722_SD6VOLTAGE_DATA);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700100 /*
101 * Don't write SDCONTROL - it's already 0x7F, i.e. all SDs enabled.
102 * tegra_i2c_ll_write_data(AS3722_SD6CONTROL_DATA, I2C_SEND_2_BYTES);
103 */
104 udelay(10 * 1000);
105
106 debug("%s: Set VPP_FUSE to 1.2V via AS3722 reg 0x12/4E\n", __func__);
107 /*
108 * Bring up VPP_FUSE via the AS3722 PMIC on the PWR I2C bus.
109 * First set VDD to 1.2V, then enable the VDD regulator.
110 */
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +0200111 tegra_i2c_ll_write(AS3722_I2C_ADDR,
112 AS3722_LDO2VOLTAGE_DATA);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700113 /*
114 * Don't write LDCONTROL - it's already 0xFF, i.e. all LDOs enabled.
115 * tegra_i2c_ll_write_data(AS3722_LDO2CONTROL_DATA, I2C_SEND_2_BYTES);
116 */
117 udelay(10 * 1000);
118
119 debug("%s: Set VDD_SDMMC1 to 3.3V via AS3722 reg 0x11/4E\n", __func__);
120 /*
121 * Bring up VDD_SDMMC1 via the AS3722 PMIC on the PWR I2C bus.
122 * First set it to value closest to 3.3V, then enable the regulator
123 *
124 * NOTE: We do this early because doing it later seems to hose the CPU
125 * power rail/partition startup. Need to debug.
126 */
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +0200127 tegra_i2c_ll_write(AS3722_I2C_ADDR,
128 AS3722_LDO1VOLTAGE_DATA);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700129 /*
130 * Don't write LDCONTROL - it's already 0xFF, i.e. all LDOs enabled.
131 * tegra_i2c_ll_write_data(AS3722_LDO1CONTROL_DATA, I2C_SEND_2_BYTES);
132 */
133 udelay(10 * 1000);
134
135 debug("%s: Set VDD_SDMMC3 to 3.3V via AS3722 reg 0x16/4E\n", __func__);
136 /*
137 * Bring up VDD_SDMMC3 via the AS3722 PMIC on the PWR I2C bus.
138 * First set it to bypass 3.3V straight thru, then enable the regulator
139 *
140 * NOTE: We do this early because doing it later seems to hose the CPU
141 * power rail/partition startup. Need to debug.
142 */
Svyatoslav Ryhel9e1ba0a2023-02-14 19:35:33 +0200143 tegra_i2c_ll_write(AS3722_I2C_ADDR,
144 AS3722_LDO6VOLTAGE_DATA);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700145 /*
146 * Don't write LDCONTROL - it's already 0xFF, i.e. all LDOs enabled.
147 * tegra_i2c_ll_write_data(AS3722_LDO6CONTROL_DATA, I2C_SEND_2_BYTES);
148 */
149 udelay(10 * 1000);
150}