Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 1ce3d54 | 2016-05-12 13:32:56 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION |
Stephen Warren | 1ce3d54 | 2016-05-12 13:32:56 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 7 | #include <env.h> |
Thierry Reding | f0112e4 | 2019-04-15 11:32:36 +0200 | [diff] [blame] | 8 | #include <fdtdec.h> |
Stephen Warren | 7f253c8 | 2016-07-29 13:15:05 -0600 | [diff] [blame] | 9 | #include <i2c.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 11 | #include <net.h> |
Thierry Reding | 92f9f8c | 2019-04-15 11:32:34 +0200 | [diff] [blame] | 12 | #include <linux/libfdt.h> |
| 13 | #include <asm/arch-tegra/cboot.h> |
Stephen Warren | 7f253c8 | 2016-07-29 13:15:05 -0600 | [diff] [blame] | 14 | #include "../p2571/max77620_init.h" |
| 15 | |
Thierry Reding | 7cef2b2 | 2019-04-15 11:32:28 +0200 | [diff] [blame] | 16 | void pin_mux_mmc(void) |
Stephen Warren | 7f253c8 | 2016-07-29 13:15:05 -0600 | [diff] [blame] | 17 | { |
| 18 | struct udevice *dev; |
| 19 | uchar val; |
| 20 | int ret; |
| 21 | |
| 22 | /* Turn on MAX77620 LDO3 to 3.3V for SD card power */ |
| 23 | debug("%s: Set LDO3 for VDDIO_SDMMC_AP power to 3.3V\n", __func__); |
| 24 | ret = i2c_get_chip_for_busnum(0, MAX77620_I2C_ADDR_7BIT, 1, &dev); |
| 25 | if (ret) { |
| 26 | printf("%s: Cannot find MAX77620 I2C chip\n", __func__); |
Thierry Reding | 7cef2b2 | 2019-04-15 11:32:28 +0200 | [diff] [blame] | 27 | return; |
Stephen Warren | 7f253c8 | 2016-07-29 13:15:05 -0600 | [diff] [blame] | 28 | } |
| 29 | /* 0xF2 for 3.3v, enabled: bit7:6 = 11 = enable, bit5:0 = voltage */ |
| 30 | val = 0xF2; |
| 31 | ret = dm_i2c_write(dev, MAX77620_CNFG1_L3_REG, &val, 1); |
| 32 | if (ret) { |
| 33 | printf("i2c_write 0 0x3c 0x27 failed: %d\n", ret); |
Thierry Reding | 7cef2b2 | 2019-04-15 11:32:28 +0200 | [diff] [blame] | 34 | return; |
Stephen Warren | 7f253c8 | 2016-07-29 13:15:05 -0600 | [diff] [blame] | 35 | } |
Stephen Warren | 7f253c8 | 2016-07-29 13:15:05 -0600 | [diff] [blame] | 36 | } |
Stephen Warren | 2f54650 | 2016-07-29 13:15:06 -0600 | [diff] [blame] | 37 | |
Thierry Reding | 7cef2b2 | 2019-04-15 11:32:28 +0200 | [diff] [blame] | 38 | #ifdef CONFIG_PCI_TEGRA |
Stephen Warren | 2f54650 | 2016-07-29 13:15:06 -0600 | [diff] [blame] | 39 | int tegra_pcie_board_init(void) |
| 40 | { |
| 41 | struct udevice *dev; |
| 42 | uchar val; |
| 43 | int ret; |
| 44 | |
| 45 | /* Turn on MAX77620 LDO7 to 1.05V for PEX power */ |
| 46 | debug("%s: Set LDO7 for PEX power to 1.05V\n", __func__); |
| 47 | ret = i2c_get_chip_for_busnum(0, MAX77620_I2C_ADDR_7BIT, 1, &dev); |
| 48 | if (ret) { |
| 49 | printf("%s: Cannot find MAX77620 I2C chip\n", __func__); |
| 50 | return -1; |
| 51 | } |
| 52 | /* 0xC5 for 1.05v, enabled: bit7:6 = 11 = enable, bit5:0 = voltage */ |
| 53 | val = 0xC5; |
| 54 | ret = dm_i2c_write(dev, MAX77620_CNFG1_L7_REG, &val, 1); |
| 55 | if (ret) |
| 56 | printf("i2c_write 0 0x3c 0x31 failed: %d\n", ret); |
| 57 | |
| 58 | return 0; |
| 59 | } |
Thierry Reding | 7cef2b2 | 2019-04-15 11:32:28 +0200 | [diff] [blame] | 60 | #endif |
Thierry Reding | 92f9f8c | 2019-04-15 11:32:34 +0200 | [diff] [blame] | 61 | |
Thierry Reding | f0112e4 | 2019-04-15 11:32:36 +0200 | [diff] [blame] | 62 | static void ft_mac_address_setup(void *fdt) |
Thierry Reding | 92f9f8c | 2019-04-15 11:32:34 +0200 | [diff] [blame] | 63 | { |
| 64 | const void *cboot_fdt = (const void *)cboot_boot_x0; |
| 65 | uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN]; |
| 66 | const char *path; |
| 67 | int offset, err; |
| 68 | |
| 69 | err = cboot_get_ethaddr(cboot_fdt, local_mac); |
| 70 | if (err < 0) |
| 71 | memset(local_mac, 0, ETH_ALEN); |
| 72 | |
| 73 | path = fdt_get_alias(fdt, "ethernet"); |
| 74 | if (!path) |
Thierry Reding | f0112e4 | 2019-04-15 11:32:36 +0200 | [diff] [blame] | 75 | return; |
Thierry Reding | 92f9f8c | 2019-04-15 11:32:34 +0200 | [diff] [blame] | 76 | |
| 77 | debug("ethernet alias found: %s\n", path); |
| 78 | |
| 79 | offset = fdt_path_offset(fdt, path); |
Thierry Reding | f0112e4 | 2019-04-15 11:32:36 +0200 | [diff] [blame] | 80 | if (offset < 0) { |
| 81 | printf("ethernet alias points to absent node %s\n", path); |
| 82 | return; |
| 83 | } |
Thierry Reding | 92f9f8c | 2019-04-15 11:32:34 +0200 | [diff] [blame] | 84 | |
| 85 | if (is_valid_ethaddr(local_mac)) { |
| 86 | err = fdt_setprop(fdt, offset, "local-mac-address", local_mac, |
| 87 | ETH_ALEN); |
| 88 | if (!err) |
| 89 | debug("Local MAC address set: %pM\n", local_mac); |
| 90 | } |
| 91 | |
| 92 | if (eth_env_get_enetaddr("ethaddr", mac)) { |
| 93 | if (memcmp(local_mac, mac, ETH_ALEN) != 0) { |
| 94 | err = fdt_setprop(fdt, offset, "mac-address", mac, |
| 95 | ETH_ALEN); |
| 96 | if (!err) |
| 97 | debug("MAC address set: %pM\n", mac); |
| 98 | } |
| 99 | } |
Thierry Reding | f0112e4 | 2019-04-15 11:32:36 +0200 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | static int ft_copy_carveout(void *dst, const void *src, const char *node) |
| 103 | { |
| 104 | struct fdt_memory fb; |
| 105 | int err; |
| 106 | |
| 107 | err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb); |
| 108 | if (err < 0) { |
| 109 | if (err != -FDT_ERR_NOTFOUND) |
| 110 | printf("failed to get carveout for %s: %d\n", node, |
| 111 | err); |
| 112 | |
| 113 | return err; |
| 114 | } |
Thierry Reding | 92f9f8c | 2019-04-15 11:32:34 +0200 | [diff] [blame] | 115 | |
Thierry Reding | f0112e4 | 2019-04-15 11:32:36 +0200 | [diff] [blame] | 116 | err = fdtdec_set_carveout(dst, node, "memory-region", 0, "framebuffer", |
| 117 | &fb); |
| 118 | if (err < 0) { |
| 119 | printf("failed to set carveout for %s: %d\n", node, err); |
| 120 | return err; |
| 121 | } |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static void ft_carveout_setup(void *fdt) |
| 127 | { |
| 128 | const void *cboot_fdt = (const void *)cboot_boot_x0; |
| 129 | static const char * const nodes[] = { |
| 130 | "/host1x@13e00000/display-hub@15200000/display@15200000", |
| 131 | "/host1x@13e00000/display-hub@15200000/display@15210000", |
| 132 | "/host1x@13e00000/display-hub@15200000/display@15220000", |
| 133 | }; |
| 134 | unsigned int i; |
| 135 | int err; |
| 136 | |
| 137 | for (i = 0; i < ARRAY_SIZE(nodes); i++) { |
| 138 | printf("copying carveout for %s...\n", nodes[i]); |
| 139 | |
| 140 | err = ft_copy_carveout(fdt, cboot_fdt, nodes[i]); |
| 141 | if (err < 0) { |
| 142 | if (err != -FDT_ERR_NOTFOUND) |
| 143 | printf("failed to copy carveout for %s: %d\n", |
| 144 | nodes[i], err); |
| 145 | |
| 146 | continue; |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | int ft_board_setup(void *fdt, bd_t *bd) |
| 152 | { |
| 153 | ft_mac_address_setup(fdt); |
| 154 | ft_carveout_setup(fdt); |
| 155 | |
Thierry Reding | 92f9f8c | 2019-04-15 11:32:34 +0200 | [diff] [blame] | 156 | return 0; |
| 157 | } |