blob: f4212ab8222f6932691ca396e923962f0b8889a2 [file] [log] [blame]
Tom Warren7c02bc92020-02-28 16:17:07 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2018-2019
4 * NVIDIA Corporation <www.nvidia.com>
5 *
6 */
7
8#include <common.h>
9#include <fdtdec.h>
10#include <i2c.h>
11#include <linux/libfdt.h>
12#include <pca953x.h>
13#include <asm/arch-tegra/cboot.h>
14#include <asm/arch/gpio.h>
15#include <asm/arch/pinmux.h>
16#include "../p2571/max77620_init.h"
17
18void pin_mux_mmc(void)
19{
20 struct udevice *dev;
21 uchar val;
22 int ret;
23
24 /* Turn on MAX77620 LDO2 to 3.3V for SD card power */
25 debug("%s: Set LDO2 for VDDIO_SDMMC_AP power to 3.3V\n", __func__);
26 ret = i2c_get_chip_for_busnum(0, MAX77620_I2C_ADDR_7BIT, 1, &dev);
27 if (ret) {
28 printf("%s: Cannot find MAX77620 I2C chip\n", __func__);
29 return;
30 }
31 /* 0xF2 for 3.3v, enabled: bit7:6 = 11 = enable, bit5:0 = voltage */
32 val = 0xF2;
33 ret = dm_i2c_write(dev, MAX77620_CNFG1_L2_REG, &val, 1);
34 if (ret)
35 printf("i2c_write 0 0x3c 0x27 failed: %d\n", ret);
36
37 /* Disable LDO4 discharge */
38 ret = dm_i2c_read(dev, MAX77620_CNFG2_L4_REG, &val, 1);
39 if (ret) {
40 printf("i2c_read 0 0x3c 0x2c failed: %d\n", ret);
41 } else {
42 val &= ~BIT(1); /* ADE */
43 ret = dm_i2c_write(dev, MAX77620_CNFG2_L4_REG, &val, 1);
44 if (ret)
45 printf("i2c_write 0 0x3c 0x2c failed: %d\n", ret);
46 }
47
48 /* Set MBLPD */
49 ret = dm_i2c_read(dev, MAX77620_CNFGGLBL1_REG, &val, 1);
50 if (ret) {
51 printf("i2c_write 0 0x3c 0x00 failed: %d\n", ret);
52 } else {
53 val |= BIT(6); /* MBLPD */
54 ret = dm_i2c_write(dev, MAX77620_CNFGGLBL1_REG, &val, 1);
55 if (ret)
56 printf("i2c_write 0 0x3c 0x00 failed: %d\n", ret);
57 }
58}
59
60#ifdef CONFIG_PCI_TEGRA
61int tegra_pcie_board_init(void)
62{
63 struct udevice *dev;
64 uchar val;
65 int ret;
66
67 /* Turn on MAX77620 LDO1 to 1.05V for PEX power */
68 debug("%s: Set LDO1 for PEX power to 1.05V\n", __func__);
69 ret = i2c_get_chip_for_busnum(0, MAX77620_I2C_ADDR_7BIT, 1, &dev);
70 if (ret) {
71 printf("%s: Cannot find MAX77620 I2C chip\n", __func__);
72 return -1;
73 }
74 /* 0xCA for 1.05v, enabled: bit7:6 = 11 = enable, bit5:0 = voltage */
75 val = 0xCA;
76 ret = dm_i2c_write(dev, MAX77620_CNFG1_L1_REG, &val, 1);
77 if (ret)
78 printf("i2c_write 0 0x3c 0x25 failed: %d\n", ret);
79
80 return 0;
81}
82#endif /* PCI */
83
84static void ft_mac_address_setup(void *fdt)
85{
86 const void *cboot_fdt = (const void *)cboot_boot_x0;
87 uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN];
88 const char *path;
89 int offset, err;
90
91 err = cboot_get_ethaddr(cboot_fdt, local_mac);
92 if (err < 0)
93 memset(local_mac, 0, ETH_ALEN);
94
95 path = fdt_get_alias(fdt, "ethernet");
96 if (!path)
97 return;
98
99 debug("ethernet alias found: %s\n", path);
100
101 offset = fdt_path_offset(fdt, path);
102 if (offset < 0) {
103 printf("ethernet alias points to absent node %s\n", path);
104 return;
105 }
106
107 if (is_valid_ethaddr(local_mac)) {
108 err = fdt_setprop(fdt, offset, "local-mac-address", local_mac,
109 ETH_ALEN);
110 if (!err)
111 debug("Local MAC address set: %pM\n", local_mac);
112 }
113
114 if (eth_env_get_enetaddr("ethaddr", mac)) {
115 if (memcmp(local_mac, mac, ETH_ALEN) != 0) {
116 err = fdt_setprop(fdt, offset, "mac-address", mac,
117 ETH_ALEN);
118 if (!err)
119 debug("MAC address set: %pM\n", mac);
120 }
121 }
122}
123
124static int ft_copy_carveout(void *dst, const void *src, const char *node)
125{
126 struct fdt_memory fb;
127 int err;
128
129 err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb);
130 if (err < 0) {
131 if (err != -FDT_ERR_NOTFOUND)
132 printf("failed to get carveout for %s: %d\n", node,
133 err);
134
135 return err;
136 }
137
138 err = fdtdec_set_carveout(dst, node, "memory-region", 0, "framebuffer",
139 &fb);
140 if (err < 0) {
141 printf("failed to set carveout for %s: %d\n", node, err);
142 return err;
143 }
144
145 return 0;
146}
147
148static void ft_carveout_setup(void *fdt)
149{
150 const void *cboot_fdt = (const void *)cboot_boot_x0;
151 static const char * const nodes[] = {
152 "/host1x@50000000/dc@54200000",
153 "/host1x@50000000/dc@54240000",
154 };
155 unsigned int i;
156 int err;
157
158 for (i = 0; i < ARRAY_SIZE(nodes); i++) {
159 printf("copying carveout for %s...\n", nodes[i]);
160
161 err = ft_copy_carveout(fdt, cboot_fdt, nodes[i]);
162 if (err < 0) {
163 if (err != -FDT_ERR_NOTFOUND)
164 printf("failed to copy carveout for %s: %d\n",
165 nodes[i], err);
166
167 continue;
168 }
169 }
170}
171
172int ft_board_setup(void *fdt, bd_t *bd)
173{
174 ft_mac_address_setup(fdt);
175 ft_carveout_setup(fdt);
176
177 return 0;
178}