Svyatoslav Ryhel | 4c5fe37 | 2023-06-30 10:29:06 +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 | #include <common.h> |
| 11 | #include <dm.h> |
| 12 | #include <env.h> |
| 13 | #include <fdt_support.h> |
| 14 | #include <i2c.h> |
| 15 | #include <log.h> |
| 16 | #include <asm/arch/pinmux.h> |
| 17 | #include <asm/arch/gp_padctrl.h> |
| 18 | #include <asm/arch/gpio.h> |
| 19 | #include <asm/arch-tegra/fuse.h> |
| 20 | #include <asm/gpio.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include "pinmux-config-endeavoru.h" |
| 23 | |
| 24 | #define TPS80032_CTL1_I2C_ADDR 0x48 |
| 25 | #define TPS80032_PHOENIX_DEV_ON 0x25 |
| 26 | #define DEVOFF BIT(0) |
| 27 | #define TPS80032_LDO1_CFG_STATE 0x9E |
| 28 | #define TPS80032_LDO1_CFG_VOLTAGE 0x9F |
| 29 | |
| 30 | #ifdef CONFIG_CMD_POWEROFF |
| 31 | int do_poweroff(struct cmd_tbl *cmdtp, int flag, |
| 32 | int argc, char *const argv[]) |
| 33 | { |
| 34 | struct udevice *dev; |
| 35 | int ret; |
| 36 | |
| 37 | ret = i2c_get_chip_for_busnum(0, TPS80032_CTL1_I2C_ADDR, 1, &dev); |
| 38 | if (ret) { |
| 39 | log_debug("cannot find PMIC I2C chip\n"); |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | ret = dm_i2c_reg_write(dev, TPS80032_PHOENIX_DEV_ON, DEVOFF); |
| 44 | if (ret) |
| 45 | return ret; |
| 46 | |
| 47 | // wait some time and then print error |
| 48 | mdelay(5000); |
| 49 | |
| 50 | printf("Failed to power off!!!\n"); |
| 51 | return 1; |
| 52 | } |
| 53 | #endif |
| 54 | |
| 55 | /* |
| 56 | * Routine: pinmux_init |
| 57 | * Description: Do individual peripheral pinmux configs |
| 58 | */ |
| 59 | void pinmux_init(void) |
| 60 | { |
| 61 | pinmux_config_pingrp_table(endeavoru_pinmux_common, |
| 62 | ARRAY_SIZE(endeavoru_pinmux_common)); |
| 63 | } |
| 64 | |
| 65 | #ifdef CONFIG_MMC_SDHCI_TEGRA |
| 66 | static void tps80032_voltage_init(void) |
| 67 | { |
| 68 | struct udevice *dev; |
| 69 | int ret; |
| 70 | |
| 71 | ret = i2c_get_chip_for_busnum(0, TPS80032_CTL1_I2C_ADDR, 1, &dev); |
| 72 | if (ret) |
| 73 | log_debug("cannot find PMIC I2C chip\n"); |
| 74 | |
| 75 | /* TPS80032: LDO1_REG = 1.2v to DSI */ |
| 76 | ret = dm_i2c_reg_write(dev, TPS80032_LDO1_CFG_VOLTAGE, 0x03); |
| 77 | if (ret) |
| 78 | log_debug("avdd_dsi_csi voltage set failed: %d\n", ret); |
| 79 | |
| 80 | /* TPS80032: LDO1_REG enable */ |
| 81 | ret = dm_i2c_reg_write(dev, TPS80032_LDO1_CFG_STATE, 0x01); |
| 82 | if (ret) |
| 83 | log_debug("avdd_dsi_csi enable failed: %d\n", ret); |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * Routine: pin_mux_mmc |
| 88 | * Description: setup the MMC muxes, power rails, etc. |
| 89 | */ |
| 90 | void pin_mux_mmc(void) |
| 91 | { |
| 92 | /* Bring up DSI power */ |
| 93 | tps80032_voltage_init(); |
| 94 | } |
| 95 | #endif /* MMC */ |
| 96 | |
| 97 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 98 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 99 | { |
| 100 | /* Remove TrustZone nodes */ |
| 101 | fdt_del_node_and_alias(blob, "/firmware"); |
| 102 | fdt_del_node_and_alias(blob, "/reserved-memory/trustzone@bfe00000"); |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | #endif |
| 107 | |
| 108 | void nvidia_board_late_init(void) |
| 109 | { |
| 110 | char serialno_str[17]; |
| 111 | |
| 112 | /* Set chip id as serialno */ |
| 113 | sprintf(serialno_str, "%016llx", tegra_chip_uid()); |
| 114 | env_set("serial#", serialno_str); |
| 115 | env_set("platform", "Tegra 3 T30"); |
| 116 | } |