p3450-0000.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2018-2019
  4. * NVIDIA Corporation <www.nvidia.com>
  5. *
  6. */
  7. #include <common.h>
  8. #include <fdtdec.h>
  9. #include <i2c.h>
  10. #include <linux/bitops.h>
  11. #include <linux/libfdt.h>
  12. #include <pca953x.h>
  13. #include <asm/arch-tegra/cboot.h>
  14. #include <asm/arch/gpio.h>
  15. #include <asm/arch/pinmux.h>
  16. #include "../p2571/max77620_init.h"
  17. void pin_mux_mmc(void)
  18. {
  19. struct udevice *dev;
  20. uchar val;
  21. int ret;
  22. /* Turn on MAX77620 LDO2 to 3.3V for SD card power */
  23. debug("%s: Set LDO2 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__);
  27. return;
  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_L2_REG, &val, 1);
  32. if (ret)
  33. printf("i2c_write 0 0x3c 0x27 failed: %d\n", ret);
  34. /* Disable LDO4 discharge */
  35. ret = dm_i2c_read(dev, MAX77620_CNFG2_L4_REG, &val, 1);
  36. if (ret) {
  37. printf("i2c_read 0 0x3c 0x2c failed: %d\n", ret);
  38. } else {
  39. val &= ~BIT(1); /* ADE */
  40. ret = dm_i2c_write(dev, MAX77620_CNFG2_L4_REG, &val, 1);
  41. if (ret)
  42. printf("i2c_write 0 0x3c 0x2c failed: %d\n", ret);
  43. }
  44. /* Set MBLPD */
  45. ret = dm_i2c_read(dev, MAX77620_CNFGGLBL1_REG, &val, 1);
  46. if (ret) {
  47. printf("i2c_write 0 0x3c 0x00 failed: %d\n", ret);
  48. } else {
  49. val |= BIT(6); /* MBLPD */
  50. ret = dm_i2c_write(dev, MAX77620_CNFGGLBL1_REG, &val, 1);
  51. if (ret)
  52. printf("i2c_write 0 0x3c 0x00 failed: %d\n", ret);
  53. }
  54. }
  55. #ifdef CONFIG_PCI_TEGRA
  56. int tegra_pcie_board_init(void)
  57. {
  58. struct udevice *dev;
  59. uchar val;
  60. int ret;
  61. /* Turn on MAX77620 LDO1 to 1.05V for PEX power */
  62. debug("%s: Set LDO1 for PEX power to 1.05V\n", __func__);
  63. ret = i2c_get_chip_for_busnum(0, MAX77620_I2C_ADDR_7BIT, 1, &dev);
  64. if (ret) {
  65. printf("%s: Cannot find MAX77620 I2C chip\n", __func__);
  66. return -1;
  67. }
  68. /* 0xCA for 1.05v, enabled: bit7:6 = 11 = enable, bit5:0 = voltage */
  69. val = 0xCA;
  70. ret = dm_i2c_write(dev, MAX77620_CNFG1_L1_REG, &val, 1);
  71. if (ret)
  72. printf("i2c_write 0 0x3c 0x25 failed: %d\n", ret);
  73. return 0;
  74. }
  75. #endif /* PCI */
  76. static void ft_mac_address_setup(void *fdt)
  77. {
  78. const void *cboot_fdt = (const void *)cboot_boot_x0;
  79. uint8_t mac[ETH_ALEN], local_mac[ETH_ALEN];
  80. const char *path;
  81. int offset, err;
  82. err = cboot_get_ethaddr(cboot_fdt, local_mac);
  83. if (err < 0)
  84. memset(local_mac, 0, ETH_ALEN);
  85. path = fdt_get_alias(fdt, "ethernet");
  86. if (!path)
  87. return;
  88. debug("ethernet alias found: %s\n", path);
  89. offset = fdt_path_offset(fdt, path);
  90. if (offset < 0) {
  91. printf("ethernet alias points to absent node %s\n", path);
  92. return;
  93. }
  94. if (is_valid_ethaddr(local_mac)) {
  95. err = fdt_setprop(fdt, offset, "local-mac-address", local_mac,
  96. ETH_ALEN);
  97. if (!err)
  98. debug("Local MAC address set: %pM\n", local_mac);
  99. }
  100. if (eth_env_get_enetaddr("ethaddr", mac)) {
  101. if (memcmp(local_mac, mac, ETH_ALEN) != 0) {
  102. err = fdt_setprop(fdt, offset, "mac-address", mac,
  103. ETH_ALEN);
  104. if (!err)
  105. debug("MAC address set: %pM\n", mac);
  106. }
  107. }
  108. }
  109. static int ft_copy_carveout(void *dst, const void *src, const char *node)
  110. {
  111. struct fdt_memory fb;
  112. int err;
  113. err = fdtdec_get_carveout(src, node, "memory-region", 0, &fb);
  114. if (err < 0) {
  115. if (err != -FDT_ERR_NOTFOUND)
  116. printf("failed to get carveout for %s: %d\n", node,
  117. err);
  118. return err;
  119. }
  120. err = fdtdec_set_carveout(dst, node, "memory-region", 0, "framebuffer",
  121. &fb);
  122. if (err < 0) {
  123. printf("failed to set carveout for %s: %d\n", node, err);
  124. return err;
  125. }
  126. return 0;
  127. }
  128. static void ft_carveout_setup(void *fdt)
  129. {
  130. const void *cboot_fdt = (const void *)cboot_boot_x0;
  131. static const char * const nodes[] = {
  132. "/host1x@50000000/dc@54200000",
  133. "/host1x@50000000/dc@54240000",
  134. };
  135. unsigned int i;
  136. int err;
  137. for (i = 0; i < ARRAY_SIZE(nodes); i++) {
  138. printf("copying carveout for %s...\n", nodes[i]);
  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. continue;
  145. }
  146. }
  147. }
  148. int ft_board_setup(void *fdt, struct bd_info *bd)
  149. {
  150. ft_mac_address_setup(fdt);
  151. ft_carveout_setup(fdt);
  152. return 0;
  153. }