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