1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016, NVIDIA CORPORATION
11 #include <linux/libfdt.h>
12 #include <asm/arch-tegra/cboot.h>
13 #include "../p2571/max77620_init.h"
15 void pin_mux_mmc(void)
21 /* Turn on MAX77620 LDO3 to 3.3V for SD card power */
22 debug("%s: Set LDO3 for VDDIO_SDMMC_AP power to 3.3V\n", __func__);
23 ret = i2c_get_chip_for_busnum(0, MAX77620_I2C_ADDR_7BIT, 1, &dev);
25 printf("%s: Cannot find MAX77620 I2C chip\n", __func__);
28 /* 0xF2 for 3.3v, enabled: bit7:6 = 11 = enable, bit5:0 = voltage */
30 ret = dm_i2c_write(dev, MAX77620_CNFG1_L3_REG, &val, 1);
32 printf("i2c_write 0 0x3c 0x27 failed: %d\n", ret);
37 #ifdef CONFIG_PCI_TEGRA
38 int tegra_pcie_board_init(void)
44 /* Turn on MAX77620 LDO7 to 1.05V for PEX power */
45 debug("%s: Set LDO7 for PEX power to 1.05V\n", __func__);
46 ret = i2c_get_chip_for_busnum(0, MAX77620_I2C_ADDR_7BIT, 1, &dev);
48 printf("%s: Cannot find MAX77620 I2C chip\n", __func__);
51 /* 0xC5 for 1.05v, enabled: bit7:6 = 11 = enable, bit5:0 = voltage */
53 ret = dm_i2c_write(dev, MAX77620_CNFG1_L7_REG, &val, 1);
55 printf("i2c_write 0 0x3c 0x31 failed: %d\n", ret);
61 static void ft_mac_address_setup(void *fdt)
63 const void *cboot_fdt = (const void *)cboot_boot_x0;
64 uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN];
68 err = cboot_get_ethaddr(cboot_fdt, local_mac);
70 memset(local_mac, 0, ETH_ALEN);
72 path = fdt_get_alias(fdt, "ethernet");
76 debug("ethernet alias found: %s\n", path);
78 offset = fdt_path_offset(fdt, path);
80 printf("ethernet alias points to absent node %s\n", path);
84 if (is_valid_ethaddr(local_mac)) {
85 err = fdt_setprop(fdt, offset, "local-mac-address", local_mac,
88 debug("Local MAC address set: %pM\n", local_mac);
91 if (eth_env_get_enetaddr("ethaddr", mac)) {
92 if (memcmp(local_mac, mac, ETH_ALEN) != 0) {
93 err = fdt_setprop(fdt, offset, "mac-address", mac,
96 debug("MAC address set: %pM\n", mac);
101 static int ft_copy_carveout(void *dst, const void *src, const char *node)
103 struct fdt_memory fb;
106 err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb);
108 if (err != -FDT_ERR_NOTFOUND)
109 printf("failed to get carveout for %s: %d\n", node,
115 err = fdtdec_set_carveout(dst, node, "memory-region", 0, "framebuffer",
118 printf("failed to set carveout for %s: %d\n", node, err);
125 static void ft_carveout_setup(void *fdt)
127 const void *cboot_fdt = (const void *)cboot_boot_x0;
128 static const char * const nodes[] = {
129 "/host1x@13e00000/display-hub@15200000/display@15200000",
130 "/host1x@13e00000/display-hub@15200000/display@15210000",
131 "/host1x@13e00000/display-hub@15200000/display@15220000",
136 for (i = 0; i < ARRAY_SIZE(nodes); i++) {
137 printf("copying carveout for %s...\n", nodes[i]);
139 err = ft_copy_carveout(fdt, cboot_fdt, nodes[i]);
141 if (err != -FDT_ERR_NOTFOUND)
142 printf("failed to copy carveout for %s: %d\n",
150 int ft_board_setup(void *fdt, bd_t *bd)
152 ft_mac_address_setup(fdt);
153 ft_carveout_setup(fdt);