apalis_t30.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2014-2018
  4. * Marcel Ziswiler <marcel@ziswiler.com>
  5. */
  6. #include <common.h>
  7. #include <asm/arch/gp_padctrl.h>
  8. #include <asm/arch/pinmux.h>
  9. #include <asm/arch-tegra/ap.h>
  10. #include <asm/arch-tegra/tegra.h>
  11. #include <asm/gpio.h>
  12. #include <asm/io.h>
  13. #include <dm.h>
  14. #include <i2c.h>
  15. #include <pci_tegra.h>
  16. #include "../common/tdx-common.h"
  17. #include "pinmux-config-apalis_t30.h"
  18. DECLARE_GLOBAL_DATA_PTR;
  19. #define PMU_I2C_ADDRESS 0x2D
  20. #define MAX_I2C_RETRY 3
  21. #ifdef CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT
  22. #define PEX_PERST_N TEGRA_GPIO(S, 7) /* Apalis GPIO7 */
  23. #define RESET_MOCI_CTRL TEGRA_GPIO(I, 4)
  24. static int pci_reset_status;
  25. #endif /* CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT */
  26. int arch_misc_init(void)
  27. {
  28. if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) ==
  29. NVBOOTTYPE_RECOVERY)
  30. printf("USB recovery mode\n");
  31. return 0;
  32. }
  33. int checkboard(void)
  34. {
  35. printf("Model: Toradex Apalis T30 %dGB\n",
  36. (gd->ram_size == 0x40000000) ? 1 : 2);
  37. return 0;
  38. }
  39. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  40. int ft_board_setup(void *blob, bd_t *bd)
  41. {
  42. return ft_common_board_setup(blob, bd);
  43. }
  44. #endif
  45. /*
  46. * Routine: pinmux_init
  47. * Description: Do individual peripheral pinmux configs
  48. */
  49. void pinmux_init(void)
  50. {
  51. pinmux_config_pingrp_table(tegra3_pinmux_common,
  52. ARRAY_SIZE(tegra3_pinmux_common));
  53. pinmux_config_pingrp_table(unused_pins_lowpower,
  54. ARRAY_SIZE(unused_pins_lowpower));
  55. /* Initialize any non-default pad configs (APB_MISC_GP regs) */
  56. pinmux_config_drvgrp_table(apalis_t30_padctrl,
  57. ARRAY_SIZE(apalis_t30_padctrl));
  58. }
  59. #ifdef CONFIG_PCI_TEGRA
  60. int tegra_pcie_board_init(void)
  61. {
  62. struct udevice *dev;
  63. u8 addr, data[1];
  64. int err;
  65. err = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, 1, &dev);
  66. if (err) {
  67. debug("%s: Cannot find PMIC I2C chip\n", __func__);
  68. return err;
  69. }
  70. /* TPS659110: VDD2_OP_REG = 1.05V */
  71. data[0] = 0x27;
  72. addr = 0x25;
  73. err = dm_i2c_write(dev, addr, data, 1);
  74. if (err) {
  75. debug("failed to set VDD supply\n");
  76. return err;
  77. }
  78. /* TPS659110: VDD2_REG 7.5 mV/us, ACTIVE */
  79. data[0] = 0x0D;
  80. addr = 0x24;
  81. err = dm_i2c_write(dev, addr, data, 1);
  82. if (err) {
  83. debug("failed to enable VDD supply\n");
  84. return err;
  85. }
  86. /* TPS659110: LDO6_REG = 1.1V, ACTIVE */
  87. data[0] = 0x0D;
  88. addr = 0x35;
  89. err = dm_i2c_write(dev, addr, data, 1);
  90. if (err) {
  91. debug("failed to set AVDD supply\n");
  92. return err;
  93. }
  94. #ifdef CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT
  95. gpio_request(PEX_PERST_N, "PEX_PERST_N");
  96. gpio_request(RESET_MOCI_CTRL, "RESET_MOCI_CTRL");
  97. #endif /* CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT */
  98. return 0;
  99. }
  100. void tegra_pcie_board_port_reset(struct tegra_pcie_port *port)
  101. {
  102. int index = tegra_pcie_port_index_of_port(port);
  103. if (index == 2) { /* I210 Gigabit Ethernet Controller (On-module) */
  104. tegra_pcie_port_reset(port);
  105. }
  106. #ifdef CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT
  107. /*
  108. * Apalis PCIe aka port 1 and Apalis Type Specific 4 Lane PCIe aka port
  109. * 0 share the same RESET_MOCI therefore only assert it once for both
  110. * ports to avoid losing the previously brought up port again.
  111. */
  112. else if ((index == 1) || (index == 0)) {
  113. /* only do it once per init cycle */
  114. if (pci_reset_status % 2 == 0) {
  115. /*
  116. * Reset PLX PEX 8605 PCIe Switch plus PCIe devices on
  117. * Apalis Evaluation Board
  118. */
  119. gpio_direction_output(PEX_PERST_N, 0);
  120. gpio_direction_output(RESET_MOCI_CTRL, 0);
  121. /*
  122. * Must be asserted for 100 ms after power and clocks
  123. * are stable
  124. */
  125. mdelay(100);
  126. gpio_set_value(PEX_PERST_N, 1);
  127. /*
  128. * Err_5: PEX_REFCLK_OUTpx/nx Clock Outputs is not
  129. * Guaranteed Until 900 us After PEX_PERST# De-assertion
  130. */
  131. mdelay(1);
  132. gpio_set_value(RESET_MOCI_CTRL, 1);
  133. }
  134. pci_reset_status++;
  135. }
  136. #endif /* CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT */
  137. }
  138. #endif /* CONFIG_PCI_TEGRA */