]> git.ipfire.org Git - thirdparty/u-boot.git/blob - board/nvidia/p2771-0000/p2771-0000.c
common: Drop net.h from common header
[thirdparty/u-boot.git] / board / nvidia / p2771-0000 / p2771-0000.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2016, NVIDIA CORPORATION
4 */
5
6 #include <common.h>
7 #include <env.h>
8 #include <fdtdec.h>
9 #include <i2c.h>
10 #include <net.h>
11 #include <linux/libfdt.h>
12 #include <asm/arch-tegra/cboot.h>
13 #include "../p2571/max77620_init.h"
14
15 void pin_mux_mmc(void)
16 {
17 struct udevice *dev;
18 uchar val;
19 int ret;
20
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);
24 if (ret) {
25 printf("%s: Cannot find MAX77620 I2C chip\n", __func__);
26 return;
27 }
28 /* 0xF2 for 3.3v, enabled: bit7:6 = 11 = enable, bit5:0 = voltage */
29 val = 0xF2;
30 ret = dm_i2c_write(dev, MAX77620_CNFG1_L3_REG, &val, 1);
31 if (ret) {
32 printf("i2c_write 0 0x3c 0x27 failed: %d\n", ret);
33 return;
34 }
35 }
36
37 #ifdef CONFIG_PCI_TEGRA
38 int tegra_pcie_board_init(void)
39 {
40 struct udevice *dev;
41 uchar val;
42 int ret;
43
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);
47 if (ret) {
48 printf("%s: Cannot find MAX77620 I2C chip\n", __func__);
49 return -1;
50 }
51 /* 0xC5 for 1.05v, enabled: bit7:6 = 11 = enable, bit5:0 = voltage */
52 val = 0xC5;
53 ret = dm_i2c_write(dev, MAX77620_CNFG1_L7_REG, &val, 1);
54 if (ret)
55 printf("i2c_write 0 0x3c 0x31 failed: %d\n", ret);
56
57 return 0;
58 }
59 #endif
60
61 static void ft_mac_address_setup(void *fdt)
62 {
63 const void *cboot_fdt = (const void *)cboot_boot_x0;
64 uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN];
65 const char *path;
66 int offset, err;
67
68 err = cboot_get_ethaddr(cboot_fdt, local_mac);
69 if (err < 0)
70 memset(local_mac, 0, ETH_ALEN);
71
72 path = fdt_get_alias(fdt, "ethernet");
73 if (!path)
74 return;
75
76 debug("ethernet alias found: %s\n", path);
77
78 offset = fdt_path_offset(fdt, path);
79 if (offset < 0) {
80 printf("ethernet alias points to absent node %s\n", path);
81 return;
82 }
83
84 if (is_valid_ethaddr(local_mac)) {
85 err = fdt_setprop(fdt, offset, "local-mac-address", local_mac,
86 ETH_ALEN);
87 if (!err)
88 debug("Local MAC address set: %pM\n", local_mac);
89 }
90
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,
94 ETH_ALEN);
95 if (!err)
96 debug("MAC address set: %pM\n", mac);
97 }
98 }
99 }
100
101 static int ft_copy_carveout(void *dst, const void *src, const char *node)
102 {
103 struct fdt_memory fb;
104 int err;
105
106 err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb);
107 if (err < 0) {
108 if (err != -FDT_ERR_NOTFOUND)
109 printf("failed to get carveout for %s: %d\n", node,
110 err);
111
112 return err;
113 }
114
115 err = fdtdec_set_carveout(dst, node, "memory-region", 0, "framebuffer",
116 &fb);
117 if (err < 0) {
118 printf("failed to set carveout for %s: %d\n", node, err);
119 return err;
120 }
121
122 return 0;
123 }
124
125 static void ft_carveout_setup(void *fdt)
126 {
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",
132 };
133 unsigned int i;
134 int err;
135
136 for (i = 0; i < ARRAY_SIZE(nodes); i++) {
137 printf("copying carveout for %s...\n", nodes[i]);
138
139 err = ft_copy_carveout(fdt, cboot_fdt, nodes[i]);
140 if (err < 0) {
141 if (err != -FDT_ERR_NOTFOUND)
142 printf("failed to copy carveout for %s: %d\n",
143 nodes[i], err);
144
145 continue;
146 }
147 }
148 }
149
150 int ft_board_setup(void *fdt, bd_t *bd)
151 {
152 ft_mac_address_setup(fdt);
153 ft_carveout_setup(fdt);
154
155 return 0;
156 }