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