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