Svyatoslav Ryhel | 7a25c38 | 2023-06-30 10:29:03 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2010-2013 |
| 4 | * NVIDIA Corporation <www.nvidia.com> |
| 5 | * |
| 6 | * (C) Copyright 2021 |
| 7 | * Svyatoslav Ryhel <clamor95@gmail.com> |
| 8 | */ |
| 9 | |
| 10 | /* T30 Transformers derive from Cardhu board */ |
| 11 | |
| 12 | #include <common.h> |
| 13 | #include <dm.h> |
| 14 | #include <env.h> |
| 15 | #include <fdt_support.h> |
| 16 | #include <i2c.h> |
| 17 | #include <log.h> |
| 18 | #include <asm/arch/pinmux.h> |
| 19 | #include <asm/arch/gp_padctrl.h> |
| 20 | #include <asm/arch/gpio.h> |
| 21 | #include <asm/arch-tegra/fuse.h> |
| 22 | #include <asm/gpio.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include "pinmux-config-transformer.h" |
| 25 | |
| 26 | #define TPS65911_I2C_ADDRESS 0x2D |
| 27 | |
| 28 | #define TPS65911_VDD1 0x21 |
| 29 | #define TPS65911_VDD1_OP 0x22 |
| 30 | #define TPS65911_LDO1 0x30 |
| 31 | #define TPS65911_LDO2 0x31 |
| 32 | #define TPS65911_LDO3 0x37 |
| 33 | #define TPS65911_LDO5 0x32 |
| 34 | #define TPS65911_LDO6 0x35 |
| 35 | |
| 36 | #define TPS65911_GPIO0 0x60 |
| 37 | #define TPS65911_GPIO6 0x66 |
| 38 | #define TPS65911_GPIO7 0x67 |
| 39 | #define TPS65911_GPIO8 0x68 |
| 40 | |
| 41 | #define TPS65911_DEVCTRL 0x3F |
| 42 | #define DEVCTRL_PWR_OFF_MASK BIT(7) |
| 43 | #define DEVCTRL_DEV_ON_MASK BIT(2) |
| 44 | #define DEVCTRL_DEV_OFF_MASK BIT(0) |
| 45 | |
| 46 | #ifdef CONFIG_CMD_POWEROFF |
| 47 | int do_poweroff(struct cmd_tbl *cmdtp, int flag, |
| 48 | int argc, char *const argv[]) |
| 49 | { |
| 50 | struct udevice *dev; |
| 51 | uchar data_buffer[1]; |
| 52 | int ret; |
| 53 | |
| 54 | ret = i2c_get_chip_for_busnum(0, TPS65911_I2C_ADDRESS, 1, &dev); |
| 55 | if (ret) { |
| 56 | log_debug("cannot find PMIC I2C chip\n"); |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | ret = dm_i2c_read(dev, TPS65911_DEVCTRL, data_buffer, 1); |
| 61 | if (ret) |
| 62 | return ret; |
| 63 | |
| 64 | data_buffer[0] |= DEVCTRL_PWR_OFF_MASK; |
| 65 | |
| 66 | ret = dm_i2c_write(dev, TPS65911_DEVCTRL, data_buffer, 1); |
| 67 | if (ret) |
| 68 | return ret; |
| 69 | |
| 70 | data_buffer[0] |= DEVCTRL_DEV_OFF_MASK; |
| 71 | data_buffer[0] &= ~DEVCTRL_DEV_ON_MASK; |
| 72 | |
| 73 | ret = dm_i2c_write(dev, TPS65911_DEVCTRL, data_buffer, 1); |
| 74 | if (ret) |
| 75 | return ret; |
| 76 | |
| 77 | // wait some time and then print error |
| 78 | mdelay(5000); |
| 79 | printf("Failed to power off!!!\n"); |
| 80 | return 1; |
| 81 | } |
| 82 | #endif |
| 83 | |
| 84 | /* |
| 85 | * Routine: pinmux_init |
| 86 | * Description: Do individual peripheral pinmux configs |
| 87 | */ |
| 88 | void pinmux_init(void) |
| 89 | { |
| 90 | pinmux_config_pingrp_table(transformer_pinmux_common, |
| 91 | ARRAY_SIZE(transformer_pinmux_common)); |
| 92 | |
| 93 | pinmux_config_drvgrp_table(transformer_padctrl, |
| 94 | ARRAY_SIZE(transformer_padctrl)); |
| 95 | |
| 96 | if (of_machine_is_compatible("asus,tf700t")) { |
| 97 | pinmux_config_pingrp_table(tf700t_mipi_pinmux, |
| 98 | ARRAY_SIZE(tf700t_mipi_pinmux)); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | #ifdef CONFIG_MMC_SDHCI_TEGRA |
| 103 | static void tps65911_voltage_init(void) |
| 104 | { |
| 105 | struct udevice *dev; |
| 106 | int ret; |
| 107 | |
| 108 | ret = i2c_get_chip_for_busnum(0, TPS65911_I2C_ADDRESS, 1, &dev); |
| 109 | if (ret) { |
| 110 | log_debug("cannot find PMIC I2C chip\n"); |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | /* TPS659110: LDO1_REG = 3.3v, ACTIVE to SDMMC4 */ |
| 115 | ret = dm_i2c_reg_write(dev, TPS65911_LDO1, 0xc9); |
| 116 | if (ret) |
| 117 | log_debug("vcore_emmc set failed: %d\n", ret); |
| 118 | |
| 119 | if (of_machine_is_compatible("asus,tf600t")) { |
| 120 | /* TPS659110: VDD1_REG = 1.2v, ACTIVE to backlight */ |
| 121 | ret = dm_i2c_reg_write(dev, TPS65911_VDD1_OP, 0x33); |
| 122 | if (ret) |
| 123 | log_debug("vdd_bl set failed: %d\n", ret); |
| 124 | |
| 125 | ret = dm_i2c_reg_write(dev, TPS65911_VDD1, 0x0d); |
| 126 | if (ret) |
| 127 | log_debug("vdd_bl enable failed: %d\n", ret); |
| 128 | |
| 129 | /* TPS659110: LDO5_REG = 3.3v, ACTIVE to SDMMC1 VIO */ |
| 130 | ret = dm_i2c_reg_write(dev, TPS65911_LDO5, 0x65); |
| 131 | if (ret) |
| 132 | log_debug("vdd_usd set failed: %d\n", ret); |
| 133 | |
| 134 | /* TPS659110: LDO6_REG = 1.2v, ACTIVE to MIPI */ |
| 135 | ret = dm_i2c_reg_write(dev, TPS65911_LDO6, 0x11); |
| 136 | if (ret) |
| 137 | log_debug("vdd_mipi set failed: %d\n", ret); |
| 138 | } else { |
| 139 | /* TPS659110: LDO2_REG = 3.1v, ACTIVE to SDMMC1 */ |
| 140 | ret = dm_i2c_reg_write(dev, TPS65911_LDO2, 0xb9); |
| 141 | if (ret) |
| 142 | log_debug("vdd_usd set failed: %d\n", ret); |
| 143 | |
| 144 | /* TPS659110: LDO3_REG = 3.1v, ACTIVE to SDMMC1 VIO */ |
| 145 | ret = dm_i2c_reg_write(dev, TPS65911_LDO3, 0x5d); |
| 146 | if (ret) |
| 147 | log_debug("vddio_usd set failed: %d\n", ret); |
| 148 | } |
| 149 | |
| 150 | /* TPS659110: GPIO0_REG output high to VDD_5V0_SBY */ |
| 151 | ret = dm_i2c_reg_write(dev, TPS65911_GPIO0, 0x07); |
| 152 | if (ret) |
| 153 | log_debug("vdd_5v0_sby set failed: %d\n", ret); |
| 154 | |
| 155 | /* TPS659110: GPIO6_REG output high to VDD_3V3_SYS */ |
| 156 | ret = dm_i2c_reg_write(dev, TPS65911_GPIO6, 0x07); |
| 157 | if (ret) |
| 158 | log_debug("vdd_3v3_sys set failed: %d\n", ret); |
| 159 | |
| 160 | /* TPS659110: GPIO7_REG output high to VDD_1V5_DDR */ |
| 161 | ret = dm_i2c_reg_write(dev, TPS65911_GPIO7, 0x07); |
| 162 | if (ret) |
| 163 | log_debug("vdd_1v5_ddr set failed: %d\n", ret); |
| 164 | |
| 165 | /* TPS659110: GPIO8_REG pull_down output high to VDD_5V0_SYS */ |
| 166 | ret = dm_i2c_reg_write(dev, TPS65911_GPIO8, 0x0f); |
| 167 | if (ret) |
| 168 | log_debug("vdd_5v0_sys set failed: %d\n", ret); |
| 169 | } |
| 170 | |
| 171 | /* |
| 172 | * Routine: pin_mux_mmc |
| 173 | * Description: setup the MMC muxes, power rails, etc. |
| 174 | */ |
| 175 | void pin_mux_mmc(void) |
| 176 | { |
| 177 | /* Bring up uSD and eMMC power */ |
| 178 | tps65911_voltage_init(); |
| 179 | } |
| 180 | #endif /* MMC */ |
| 181 | |
| 182 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 183 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 184 | { |
| 185 | /* Remove TrustZone nodes */ |
| 186 | fdt_del_node_and_alias(blob, "/firmware"); |
| 187 | fdt_del_node_and_alias(blob, "/reserved-memory/trustzone@bfe00000"); |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | #endif |
| 192 | |
| 193 | void nvidia_board_late_init(void) |
| 194 | { |
| 195 | char serialno_str[17]; |
| 196 | |
| 197 | /* Set chip id as serialno */ |
| 198 | sprintf(serialno_str, "%016llx", tegra_chip_uid()); |
| 199 | env_set("serial#", serialno_str); |
| 200 | env_set("platform", "Tegra 3 T30"); |
| 201 | } |