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