Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2012-2016 Toradex, Inc. |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 6 | #include <log.h> |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 7 | #include <asm/io.h> |
| 8 | #include <asm/arch-tegra/tegra_i2c.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 9 | #include <linux/delay.h> |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 10 | |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 11 | /* AS3722-PMIC-specific early init regs */ |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 12 | |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 13 | #define AS3722_I2C_ADDR 0x80 |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 14 | |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 15 | #define AS3722_SD0VOLTAGE_REG 0x00 /* CPU */ |
| 16 | #define AS3722_SD1VOLTAGE_REG 0x01 /* CORE, already set by OTP */ |
| 17 | #define AS3722_SD6VOLTAGE_REG 0x06 /* GPU */ |
| 18 | #define AS3722_SDCONTROL_REG 0x4D |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 19 | |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 20 | #define AS3722_LDO1VOLTAGE_REG 0x11 /* VDD_SDMMC1 */ |
| 21 | #define AS3722_LDO2VOLTAGE_REG 0x12 /* VPP_FUSE */ |
| 22 | #define AS3722_LDO6VOLTAGE_REG 0x16 /* VDD_SDMMC3 */ |
| 23 | #define AS3722_LDCONTROL_REG 0x4E |
| 24 | |
| 25 | #define AS3722_SD0VOLTAGE_DATA (0x3C00 | AS3722_SD0VOLTAGE_REG) |
| 26 | #define AS3722_SD0CONTROL_DATA (0x0100 | AS3722_SDCONTROL_REG) |
| 27 | |
| 28 | #define AS3722_SD1VOLTAGE_DATA (0x3200 | AS3722_SD1VOLTAGE_REG) |
| 29 | #define AS3722_SD1CONTROL_DATA (0x0200 | AS3722_SDCONTROL_REG) |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 30 | |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 31 | #define AS3722_SD6CONTROL_DATA (0x4000 | AS3722_SDCONTROL_REG) |
| 32 | #define AS3722_SD6VOLTAGE_DATA (0x2800 | AS3722_SD6VOLTAGE_REG) |
| 33 | |
| 34 | #define AS3722_LDO1CONTROL_DATA (0x0200 | AS3722_LDCONTROL_REG) |
| 35 | #define AS3722_LDO1VOLTAGE_DATA (0x7F00 | AS3722_LDO1VOLTAGE_REG) |
| 36 | |
| 37 | #define AS3722_LDO2CONTROL_DATA (0x0400 | AS3722_LDCONTROL_REG) |
| 38 | #define AS3722_LDO2VOLTAGE_DATA (0x1000 | AS3722_LDO2VOLTAGE_REG) |
| 39 | |
| 40 | #define AS3722_LDO6CONTROL_DATA (0x4000 | AS3722_LDCONTROL_REG) |
| 41 | #define AS3722_LDO6VOLTAGE_DATA (0x3F00 | AS3722_LDO6VOLTAGE_REG) |
| 42 | |
| 43 | /* AS3722-PMIC-specific early init code - get CPU rails up, etc */ |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 44 | |
| 45 | void pmic_enable_cpu_vdd(void) |
| 46 | { |
| 47 | debug("%s entry\n", __func__); |
| 48 | |
| 49 | #ifdef AS3722_SD1VOLTAGE_DATA |
| 50 | /* Set up VDD_CORE, for boards where OTP is incorrect*/ |
| 51 | debug("%s: Setting VDD_CORE via AS3722 reg 1\n", __func__); |
| 52 | /* Configure VDD_CORE via the AS3722 PMIC on the PWR I2C bus */ |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 53 | tegra_i2c_ll_write(AS3722_I2C_ADDR, |
| 54 | AS3722_SD1VOLTAGE_DATA); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 55 | /* |
| 56 | * Don't write SDCONTROL - it's already 0x7F, i.e. all SDs enabled. |
| 57 | * tegra_i2c_ll_write_data(AS3722_SD1CONTROL_DATA, I2C_SEND_2_BYTES); |
| 58 | */ |
| 59 | udelay(10 * 1000); |
| 60 | #endif |
| 61 | |
Dominik Sliwa | 3f6a2e2 | 2019-08-01 11:06:39 +0300 | [diff] [blame] | 62 | /* |
| 63 | * Make sure all non-fused regulators are down. |
| 64 | * That way we're in known state after software reboot from linux |
| 65 | */ |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 66 | tegra_i2c_ll_write(AS3722_I2C_ADDR, 0x0003); |
Dominik Sliwa | 3f6a2e2 | 2019-08-01 11:06:39 +0300 | [diff] [blame] | 67 | udelay(10 * 1000); |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 68 | tegra_i2c_ll_write(AS3722_I2C_ADDR, 0x0004); |
Dominik Sliwa | 3f6a2e2 | 2019-08-01 11:06:39 +0300 | [diff] [blame] | 69 | udelay(10 * 1000); |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 70 | tegra_i2c_ll_write(AS3722_I2C_ADDR, 0x001b); |
Dominik Sliwa | 3f6a2e2 | 2019-08-01 11:06:39 +0300 | [diff] [blame] | 71 | udelay(10 * 1000); |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 72 | tegra_i2c_ll_write(AS3722_I2C_ADDR, 0x0014); |
Dominik Sliwa | 3f6a2e2 | 2019-08-01 11:06:39 +0300 | [diff] [blame] | 73 | udelay(10 * 1000); |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 74 | tegra_i2c_ll_write(AS3722_I2C_ADDR, 0x001a); |
Dominik Sliwa | 3f6a2e2 | 2019-08-01 11:06:39 +0300 | [diff] [blame] | 75 | udelay(10 * 1000); |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 76 | tegra_i2c_ll_write(AS3722_I2C_ADDR, 0x0019); |
Dominik Sliwa | 3f6a2e2 | 2019-08-01 11:06:39 +0300 | [diff] [blame] | 77 | udelay(10 * 1000); |
| 78 | |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 79 | debug("%s: Setting VDD_CPU to 1.0V via AS3722 reg 0/4D\n", __func__); |
| 80 | /* |
| 81 | * Bring up VDD_CPU via the AS3722 PMIC on the PWR I2C bus. |
| 82 | * First set VDD to 1.0V, then enable the VDD regulator. |
| 83 | */ |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 84 | tegra_i2c_ll_write(AS3722_I2C_ADDR, |
| 85 | AS3722_SD0VOLTAGE_DATA); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 86 | /* |
| 87 | * Don't write SDCONTROL - it's already 0x7F, i.e. all SDs enabled. |
| 88 | * tegra_i2c_ll_write_data(AS3722_SD0CONTROL_DATA, I2C_SEND_2_BYTES); |
| 89 | */ |
| 90 | udelay(10 * 1000); |
| 91 | |
| 92 | debug("%s: Setting VDD_GPU to 1.0V via AS3722 reg 6/4D\n", __func__); |
| 93 | /* |
| 94 | * Bring up VDD_GPU via the AS3722 PMIC on the PWR I2C bus. |
| 95 | * First set VDD to 1.0V, then enable the VDD regulator. |
| 96 | */ |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 97 | tegra_i2c_ll_write(AS3722_I2C_ADDR, |
| 98 | AS3722_SD6VOLTAGE_DATA); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 99 | /* |
| 100 | * Don't write SDCONTROL - it's already 0x7F, i.e. all SDs enabled. |
| 101 | * tegra_i2c_ll_write_data(AS3722_SD6CONTROL_DATA, I2C_SEND_2_BYTES); |
| 102 | */ |
| 103 | udelay(10 * 1000); |
| 104 | |
| 105 | debug("%s: Set VPP_FUSE to 1.2V via AS3722 reg 0x12/4E\n", __func__); |
| 106 | /* |
| 107 | * Bring up VPP_FUSE via the AS3722 PMIC on the PWR I2C bus. |
| 108 | * First set VDD to 1.2V, then enable the VDD regulator. |
| 109 | */ |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 110 | tegra_i2c_ll_write(AS3722_I2C_ADDR, |
| 111 | AS3722_LDO2VOLTAGE_DATA); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 112 | /* |
| 113 | * Don't write LDCONTROL - it's already 0xFF, i.e. all LDOs enabled. |
| 114 | * tegra_i2c_ll_write_data(AS3722_LDO2CONTROL_DATA, I2C_SEND_2_BYTES); |
| 115 | */ |
| 116 | udelay(10 * 1000); |
| 117 | |
| 118 | debug("%s: Set VDD_SDMMC1 to 3.3V via AS3722 reg 0x11/4E\n", __func__); |
| 119 | /* |
| 120 | * Bring up VDD_SDMMC1 via the AS3722 PMIC on the PWR I2C bus. |
| 121 | * First set it to value closest to 3.3V, then enable the regulator |
| 122 | * |
| 123 | * NOTE: We do this early because doing it later seems to hose the CPU |
| 124 | * power rail/partition startup. Need to debug. |
| 125 | */ |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 126 | tegra_i2c_ll_write(AS3722_I2C_ADDR, |
| 127 | AS3722_LDO1VOLTAGE_DATA); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 128 | /* |
| 129 | * Don't write LDCONTROL - it's already 0xFF, i.e. all LDOs enabled. |
| 130 | * tegra_i2c_ll_write_data(AS3722_LDO1CONTROL_DATA, I2C_SEND_2_BYTES); |
| 131 | */ |
| 132 | udelay(10 * 1000); |
| 133 | |
| 134 | debug("%s: Set VDD_SDMMC3 to 3.3V via AS3722 reg 0x16/4E\n", __func__); |
| 135 | /* |
| 136 | * Bring up VDD_SDMMC3 via the AS3722 PMIC on the PWR I2C bus. |
| 137 | * First set it to bypass 3.3V straight thru, then enable the regulator |
| 138 | * |
| 139 | * NOTE: We do this early because doing it later seems to hose the CPU |
| 140 | * power rail/partition startup. Need to debug. |
| 141 | */ |
Svyatoslav Ryhel | 9e1ba0a | 2023-02-14 19:35:33 +0200 | [diff] [blame] | 142 | tegra_i2c_ll_write(AS3722_I2C_ADDR, |
| 143 | AS3722_LDO6VOLTAGE_DATA); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 144 | /* |
| 145 | * Don't write LDCONTROL - it's already 0xFF, i.e. all LDOs enabled. |
| 146 | * tegra_i2c_ll_write_data(AS3722_LDO6CONTROL_DATA, I2C_SEND_2_BYTES); |
| 147 | */ |
| 148 | udelay(10 * 1000); |
| 149 | } |