blob: 2769313e681e4accd4c88981695432ae4fec4dda [file] [log] [blame]
Svyatoslav Ryhel88fd1562023-06-30 10:29:04 +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>
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-grouper.h"
23
24#define TPS65911_I2C_ADDRESS 0x2D
25
26#define TPS65911_REG_LDO1 0x30
27#define TPS65911_REG_DEVCTRL 0x3F
28#define DEVCTRL_PWR_OFF_MASK BIT(7)
29#define DEVCTRL_DEV_ON_MASK BIT(2)
30#define DEVCTRL_DEV_OFF_MASK BIT(0)
31
32#define MAX77663_I2C_ADDRESS 0x3C
33
34#define MAX77663_REG_SD2 0x18
35#define MAX77663_REG_LDO3 0x29
36#define MAX77663_REG_ONOFF_CFG1 0x41
37#define ONOFF_PWR_OFF BIT(1)
38
39#ifdef CONFIG_CMD_POWEROFF
40#ifdef CONFIG_GROUPER_TPS65911
41int do_poweroff(struct cmd_tbl *cmdtp,
42 int flag, int argc, char *const argv[])
43{
44 struct udevice *dev;
45 uchar data_buffer[1];
46 int ret;
47
48 ret = i2c_get_chip_for_busnum(0, TPS65911_I2C_ADDRESS, 1, &dev);
49 if (ret) {
50 log_debug("cannot find PMIC I2C chip\n");
51 return 0;
52 }
53
54 ret = dm_i2c_read(dev, TPS65911_REG_DEVCTRL, data_buffer, 1);
55 if (ret)
56 return ret;
57
58 data_buffer[0] |= DEVCTRL_PWR_OFF_MASK;
59
60 ret = dm_i2c_write(dev, TPS65911_REG_DEVCTRL, data_buffer, 1);
61 if (ret)
62 return ret;
63
64 data_buffer[0] |= DEVCTRL_DEV_OFF_MASK;
65 data_buffer[0] &= ~DEVCTRL_DEV_ON_MASK;
66
67 ret = dm_i2c_write(dev, TPS65911_REG_DEVCTRL, data_buffer, 1);
68 if (ret)
69 return ret;
70
71 // wait some time and then print error
72 mdelay(5000);
73
74 printf("Failed to power off!!!\n");
75 return 1;
76}
77#endif /* CONFIG_GROUPER_TPS65911 */
78
79#ifdef CONFIG_GROUPER_MAX77663
80int do_poweroff(struct cmd_tbl *cmdtp,
81 int flag, int argc, char *const argv[])
82{
83 struct udevice *dev;
84 uchar data_buffer[1];
85 int ret;
86
87 ret = i2c_get_chip_for_busnum(0, MAX77663_I2C_ADDRESS, 1, &dev);
88 if (ret) {
89 log_debug("cannot find PMIC I2C chip\n");
90 return 0;
91 }
92
93 ret = dm_i2c_read(dev, MAX77663_REG_ONOFF_CFG1, data_buffer, 1);
94 if (ret)
95 return ret;
96
97 data_buffer[0] |= ONOFF_PWR_OFF;
98
99 ret = dm_i2c_write(dev, MAX77663_REG_ONOFF_CFG1, data_buffer, 1);
100 if (ret)
101 return ret;
102
103 // wait some time and then print error
104 mdelay(5000);
105
106 printf("Failed to power off!!!\n");
107 return 1;
108}
109#endif /* CONFIG_GROUPER_MAX77663 */
110#endif /* CONFIG_CMD_POWEROFF */
111
112/*
113 * Routine: pinmux_init
114 * Description: Do individual peripheral pinmux configs
115 */
116void pinmux_init(void)
117{
118 pinmux_config_pingrp_table(grouper_pinmux_common,
119 ARRAY_SIZE(grouper_pinmux_common));
120
121 pinmux_config_drvgrp_table(grouper_padctrl,
122 ARRAY_SIZE(grouper_padctrl));
123}
124
125#ifdef CONFIG_MMC_SDHCI_TEGRA
126static void __maybe_unused tps65911_voltage_init(void)
127{
128 struct udevice *dev;
129 int ret;
130
131 ret = i2c_get_chip_for_busnum(0, TPS65911_I2C_ADDRESS, 1, &dev);
132 if (ret) {
133 log_debug("cannot find PMIC I2C chip\n");
134 return;
135 }
136
137 /* TPS659110: LDO1_REG = 3.3v, ACTIVE to SDMMC4 */
138 ret = dm_i2c_reg_write(dev, TPS65911_REG_LDO1, 0xC9);
139 if (ret)
140 log_debug("vcore_emmc set failed: %d\n", ret);
141}
142
143static void __maybe_unused max77663_voltage_init(void)
144{
145 struct udevice *dev;
146 int ret;
147
148 ret = i2c_get_chip_for_busnum(0, MAX77663_I2C_ADDRESS, 1, &dev);
149 if (ret) {
150 log_debug("cannot find PMIC I2C chip\n");
151 return;
152 }
153
154 /* 0x60 for 1.8v, bit7:0 = voltage */
155 ret = dm_i2c_reg_write(dev, MAX77663_REG_SD2, 0x60);
156 if (ret)
157 log_debug("vdd_1v8_vio set failed: %d\n", ret);
158
159 /* 0xEC for 3.00v, enabled: bit7:6 = 11 = enable, bit5:0 = voltage */
160 ret = dm_i2c_reg_write(dev, MAX77663_REG_LDO3, 0xEC);
161 if (ret)
162 log_debug("vcore_emmc set failed: %d\n", ret);
163}
164
165/*
166 * Routine: pin_mux_mmc
167 * Description: setup the MMC muxes, power rails, etc.
168 */
169void pin_mux_mmc(void)
170{
171#ifdef CONFIG_GROUPER_MAX77663
172 /* Bring up eMMC power on MAX PMIC */
173 max77663_voltage_init();
174#endif
175
176#ifdef CONFIG_GROUPER_TPS65911
177 /* Bring up eMMC power on TI PMIC */
178 tps65911_voltage_init();
179#endif
180}
181#endif /* MMC */
182
183#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
184int ft_board_setup(void *blob, struct bd_info *bd)
185{
186 /* Remove TrustZone nodes */
187 fdt_del_node_and_alias(blob, "/firmware");
188 fdt_del_node_and_alias(blob, "/reserved-memory/trustzone@bfe00000");
189
190 return 0;
191}
192#endif
193
194void nvidia_board_late_init(void)
195{
196 char serialno_str[17];
197
198 /* Set chip id as serialno */
199 sprintf(serialno_str, "%016llx", tegra_chip_uid());
200 env_set("serial#", serialno_str);
201 env_set("platform", "Tegra 3 T30");
202}