blob: ba795a802eb1d8b9a2d52141dc8ba5f38921d3ef [file] [log] [blame]
Svyatoslav Ryhel7a25c382023-06-30 10:29:03 +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/* T30 Transformers derive from Cardhu board */
11
12#include <common.h>
13#include <dm.h>
Svyatoslav Ryhel7a25c382023-06-30 10:29:03 +030014#include <fdt_support.h>
15#include <i2c.h>
16#include <log.h>
17#include <asm/arch/pinmux.h>
18#include <asm/arch/gp_padctrl.h>
19#include <asm/arch/gpio.h>
Svyatoslav Ryhel7a25c382023-06-30 10:29:03 +030020#include <asm/gpio.h>
21#include <linux/delay.h>
22#include "pinmux-config-transformer.h"
23
24#define TPS65911_I2C_ADDRESS 0x2D
25
26#define TPS65911_VDD1 0x21
27#define TPS65911_VDD1_OP 0x22
28#define TPS65911_LDO1 0x30
29#define TPS65911_LDO2 0x31
30#define TPS65911_LDO3 0x37
31#define TPS65911_LDO5 0x32
32#define TPS65911_LDO6 0x35
33
Svyatoslav Ryhel7a25c382023-06-30 10:29:03 +030034#define TPS65911_DEVCTRL 0x3F
35#define DEVCTRL_PWR_OFF_MASK BIT(7)
36#define DEVCTRL_DEV_ON_MASK BIT(2)
37#define DEVCTRL_DEV_OFF_MASK BIT(0)
38
39#ifdef CONFIG_CMD_POWEROFF
40int do_poweroff(struct cmd_tbl *cmdtp, int flag,
41 int argc, char *const argv[])
42{
43 struct udevice *dev;
44 uchar data_buffer[1];
45 int ret;
46
47 ret = i2c_get_chip_for_busnum(0, TPS65911_I2C_ADDRESS, 1, &dev);
48 if (ret) {
49 log_debug("cannot find PMIC I2C chip\n");
50 return 0;
51 }
52
53 ret = dm_i2c_read(dev, TPS65911_DEVCTRL, data_buffer, 1);
54 if (ret)
55 return ret;
56
57 data_buffer[0] |= DEVCTRL_PWR_OFF_MASK;
58
59 ret = dm_i2c_write(dev, TPS65911_DEVCTRL, data_buffer, 1);
60 if (ret)
61 return ret;
62
63 data_buffer[0] |= DEVCTRL_DEV_OFF_MASK;
64 data_buffer[0] &= ~DEVCTRL_DEV_ON_MASK;
65
66 ret = dm_i2c_write(dev, TPS65911_DEVCTRL, data_buffer, 1);
67 if (ret)
68 return ret;
69
70 // wait some time and then print error
71 mdelay(5000);
72 printf("Failed to power off!!!\n");
73 return 1;
74}
75#endif
76
77/*
78 * Routine: pinmux_init
79 * Description: Do individual peripheral pinmux configs
80 */
81void pinmux_init(void)
82{
83 pinmux_config_pingrp_table(transformer_pinmux_common,
84 ARRAY_SIZE(transformer_pinmux_common));
85
86 pinmux_config_drvgrp_table(transformer_padctrl,
87 ARRAY_SIZE(transformer_padctrl));
88
89 if (of_machine_is_compatible("asus,tf700t")) {
90 pinmux_config_pingrp_table(tf700t_mipi_pinmux,
91 ARRAY_SIZE(tf700t_mipi_pinmux));
92 }
93}
94
95#ifdef CONFIG_MMC_SDHCI_TEGRA
96static void tps65911_voltage_init(void)
97{
98 struct udevice *dev;
99 int ret;
100
101 ret = i2c_get_chip_for_busnum(0, TPS65911_I2C_ADDRESS, 1, &dev);
102 if (ret) {
103 log_debug("cannot find PMIC I2C chip\n");
104 return;
105 }
106
107 /* TPS659110: LDO1_REG = 3.3v, ACTIVE to SDMMC4 */
108 ret = dm_i2c_reg_write(dev, TPS65911_LDO1, 0xc9);
109 if (ret)
110 log_debug("vcore_emmc set failed: %d\n", ret);
111
112 if (of_machine_is_compatible("asus,tf600t")) {
113 /* TPS659110: VDD1_REG = 1.2v, ACTIVE to backlight */
114 ret = dm_i2c_reg_write(dev, TPS65911_VDD1_OP, 0x33);
115 if (ret)
116 log_debug("vdd_bl set failed: %d\n", ret);
117
118 ret = dm_i2c_reg_write(dev, TPS65911_VDD1, 0x0d);
119 if (ret)
120 log_debug("vdd_bl enable failed: %d\n", ret);
121
122 /* TPS659110: LDO5_REG = 3.3v, ACTIVE to SDMMC1 VIO */
123 ret = dm_i2c_reg_write(dev, TPS65911_LDO5, 0x65);
124 if (ret)
125 log_debug("vdd_usd set failed: %d\n", ret);
126
127 /* TPS659110: LDO6_REG = 1.2v, ACTIVE to MIPI */
128 ret = dm_i2c_reg_write(dev, TPS65911_LDO6, 0x11);
129 if (ret)
130 log_debug("vdd_mipi set failed: %d\n", ret);
131 } else {
132 /* TPS659110: LDO2_REG = 3.1v, ACTIVE to SDMMC1 */
133 ret = dm_i2c_reg_write(dev, TPS65911_LDO2, 0xb9);
134 if (ret)
135 log_debug("vdd_usd set failed: %d\n", ret);
136
137 /* TPS659110: LDO3_REG = 3.1v, ACTIVE to SDMMC1 VIO */
138 ret = dm_i2c_reg_write(dev, TPS65911_LDO3, 0x5d);
139 if (ret)
140 log_debug("vddio_usd set failed: %d\n", ret);
141 }
Svyatoslav Ryhel7a25c382023-06-30 10:29:03 +0300142}
143
144/*
145 * Routine: pin_mux_mmc
146 * Description: setup the MMC muxes, power rails, etc.
147 */
148void pin_mux_mmc(void)
149{
150 /* Bring up uSD and eMMC power */
151 tps65911_voltage_init();
152}
153#endif /* MMC */
154
155#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
156int ft_board_setup(void *blob, struct bd_info *bd)
157{
158 /* Remove TrustZone nodes */
159 fdt_del_node_and_alias(blob, "/firmware");
160 fdt_del_node_and_alias(blob, "/reserved-memory/trustzone@bfe00000");
161
162 return 0;
163}
164#endif