p2771-0000.c 3.5 KB

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