apalis-tk1.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2016-2018 Toradex, Inc.
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <env.h>
  8. #include <init.h>
  9. #include <log.h>
  10. #include <asm/arch-tegra/ap.h>
  11. #include <asm/gpio.h>
  12. #include <asm/io.h>
  13. #include <asm/arch/gpio.h>
  14. #include <asm/arch/pinmux.h>
  15. #include <env_internal.h>
  16. #include <pci_tegra.h>
  17. #include <linux/delay.h>
  18. #include <power/as3722.h>
  19. #include <power/pmic.h>
  20. #include "../common/tdx-common.h"
  21. #include "pinmux-config-apalis-tk1.h"
  22. #define LAN_DEV_OFF_N TEGRA_GPIO(O, 6)
  23. #define LAN_RESET_N TEGRA_GPIO(S, 2)
  24. #define FAN_EN TEGRA_GPIO(DD, 2)
  25. #define LAN_WAKE_N TEGRA_GPIO(O, 5)
  26. #ifdef CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT
  27. #define PEX_PERST_N TEGRA_GPIO(DD, 1) /* Apalis GPIO7 */
  28. #define RESET_MOCI_CTRL TEGRA_GPIO(U, 4)
  29. #endif /* CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT */
  30. #define VCC_USBH TEGRA_GPIO(T, 6)
  31. #define VCC_USBH_V1_0 TEGRA_GPIO(N, 5)
  32. #define VCC_USBO1 TEGRA_GPIO(T, 5)
  33. #define VCC_USBO1_V1_0 TEGRA_GPIO(N, 4)
  34. int arch_misc_init(void)
  35. {
  36. if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) ==
  37. NVBOOTTYPE_RECOVERY) {
  38. printf("USB recovery mode, attempting to boot Toradex Easy "
  39. "Installer\n");
  40. env_set("bootdelay", "-2");
  41. env_set("defargs", "pcie_aspm=off user_debug=30");
  42. env_set("fdt_high", "");
  43. env_set("initrd_high", "");
  44. env_set("setup", "env set setupargs igb_mac=${ethaddr} "
  45. "consoleblank=0 no_console_suspend=1 "
  46. "console=${console},${baudrate}n8 ${memargs}");
  47. env_set("teziargs", "rootfstype=squashfs root=/dev/ram quiet "
  48. "autoinstall");
  49. env_set("vidargs", "video=HDMI-A-1:640x480-16@60D");
  50. env_set("bootcmd", "run setup; env set bootargs ${defargs} "
  51. "${setupargs} ${vidargs} ${teziargs}; bootm 0x80208000"
  52. "#config@${soc}-${fdt_module}-${fdt_board}.dtb");
  53. }
  54. /* PCB Version Indication: V1.2 and later have GPIO_PV0 wired to GND */
  55. gpio_request(TEGRA_GPIO(V, 0), "PCB Version Indication");
  56. gpio_direction_input(TEGRA_GPIO(V, 0));
  57. if (gpio_get_value(TEGRA_GPIO(V, 0))) {
  58. /*
  59. * if using the default device tree for new V1.2 and later HW,
  60. * use version for older V1.0 and V1.1 HW
  61. */
  62. char *fdt_env = env_get("fdt_module");
  63. if (fdt_env && !strcmp(FDT_MODULE, fdt_env)) {
  64. env_set("fdt_module", FDT_MODULE_V1_0);
  65. printf("patching fdt_module to " FDT_MODULE_V1_0
  66. " for older V1.0 and V1.1 HW\n");
  67. #ifndef CONFIG_ENV_IS_NOWHERE
  68. env_save();
  69. #endif
  70. }
  71. /* activate USB power enable GPIOs */
  72. gpio_request(VCC_USBH_V1_0, "VCC_USBH");
  73. gpio_direction_output(VCC_USBH_V1_0, 1);
  74. gpio_request(VCC_USBO1_V1_0, "VCC_USBO1");
  75. gpio_direction_output(VCC_USBO1_V1_0, 1);
  76. } else {
  77. /* activate USB power enable GPIOs */
  78. gpio_request(VCC_USBH, "VCC_USBH");
  79. gpio_direction_output(VCC_USBH, 1);
  80. gpio_request(VCC_USBO1, "VCC_USBO1");
  81. gpio_direction_output(VCC_USBO1, 1);
  82. }
  83. return 0;
  84. }
  85. int checkboard(void)
  86. {
  87. puts("Model: Toradex Apalis TK1 2GB\n");
  88. return 0;
  89. }
  90. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  91. int ft_board_setup(void *blob, struct bd_info *bd)
  92. {
  93. return ft_common_board_setup(blob, bd);
  94. }
  95. #endif
  96. /*
  97. * Routine: pinmux_init
  98. * Description: Do individual peripheral pinmux configs
  99. */
  100. void pinmux_init(void)
  101. {
  102. pinmux_clear_tristate_input_clamping();
  103. gpio_config_table(apalis_tk1_gpio_inits,
  104. ARRAY_SIZE(apalis_tk1_gpio_inits));
  105. pinmux_config_pingrp_table(apalis_tk1_pingrps,
  106. ARRAY_SIZE(apalis_tk1_pingrps));
  107. pinmux_config_drvgrp_table(apalis_tk1_drvgrps,
  108. ARRAY_SIZE(apalis_tk1_drvgrps));
  109. }
  110. #ifdef CONFIG_PCI_TEGRA
  111. /* TODO: Convert to driver model */
  112. static int as3722_sd_enable(struct udevice *pmic, unsigned int sd)
  113. {
  114. int err;
  115. if (sd > 6)
  116. return -EINVAL;
  117. err = pmic_clrsetbits(pmic, AS3722_SD_CONTROL, 0, 1 << sd);
  118. if (err) {
  119. pr_err("failed to update SD control register: %d", err);
  120. return err;
  121. }
  122. return 0;
  123. }
  124. /* TODO: Convert to driver model */
  125. static int as3722_ldo_enable(struct udevice *pmic, unsigned int ldo)
  126. {
  127. int err;
  128. u8 ctrl_reg = AS3722_LDO_CONTROL0;
  129. if (ldo > 11)
  130. return -EINVAL;
  131. if (ldo > 7) {
  132. ctrl_reg = AS3722_LDO_CONTROL1;
  133. ldo -= 8;
  134. }
  135. err = pmic_clrsetbits(pmic, ctrl_reg, 0, 1 << ldo);
  136. if (err) {
  137. pr_err("failed to update LDO control register: %d", err);
  138. return err;
  139. }
  140. return 0;
  141. }
  142. int tegra_pcie_board_init(void)
  143. {
  144. struct udevice *dev;
  145. int ret;
  146. ret = uclass_get_device_by_driver(UCLASS_PMIC,
  147. DM_DRIVER_GET(pmic_as3722), &dev);
  148. if (ret) {
  149. pr_err("failed to find AS3722 PMIC: %d\n", ret);
  150. return ret;
  151. }
  152. ret = as3722_sd_enable(dev, 4);
  153. if (ret < 0) {
  154. pr_err("failed to enable SD4: %d\n", ret);
  155. return ret;
  156. }
  157. ret = as3722_sd_set_voltage(dev, 4, 0x24);
  158. if (ret < 0) {
  159. pr_err("failed to set SD4 voltage: %d\n", ret);
  160. return ret;
  161. }
  162. gpio_request(LAN_DEV_OFF_N, "LAN_DEV_OFF_N");
  163. gpio_request(LAN_RESET_N, "LAN_RESET_N");
  164. gpio_request(LAN_WAKE_N, "LAN_WAKE_N");
  165. #ifdef CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT
  166. gpio_request(PEX_PERST_N, "PEX_PERST_N");
  167. gpio_request(RESET_MOCI_CTRL, "RESET_MOCI_CTRL");
  168. #endif /* CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT */
  169. return 0;
  170. }
  171. void tegra_pcie_board_port_reset(struct tegra_pcie_port *port)
  172. {
  173. int index = tegra_pcie_port_index_of_port(port);
  174. if (index == 1) { /* I210 Gigabit Ethernet Controller (On-module) */
  175. struct udevice *dev;
  176. int ret;
  177. ret = uclass_get_device_by_driver(UCLASS_PMIC,
  178. DM_DRIVER_GET(pmic_as3722),
  179. &dev);
  180. if (ret) {
  181. debug("%s: Failed to find PMIC\n", __func__);
  182. return;
  183. }
  184. /* Reset I210 Gigabit Ethernet Controller */
  185. gpio_direction_output(LAN_RESET_N, 0);
  186. /*
  187. * Make sure we don't get any back feeding from DEV_OFF_N resp.
  188. * LAN_WAKE_N
  189. */
  190. gpio_direction_output(LAN_DEV_OFF_N, 0);
  191. gpio_direction_output(LAN_WAKE_N, 0);
  192. /* Make sure LDO9 and LDO10 are initially enabled @ 0V */
  193. ret = as3722_ldo_enable(dev, 9);
  194. if (ret < 0) {
  195. pr_err("failed to enable LDO9: %d\n", ret);
  196. return;
  197. }
  198. ret = as3722_ldo_enable(dev, 10);
  199. if (ret < 0) {
  200. pr_err("failed to enable LDO10: %d\n", ret);
  201. return;
  202. }
  203. ret = as3722_ldo_set_voltage(dev, 9, 0x80);
  204. if (ret < 0) {
  205. pr_err("failed to set LDO9 voltage: %d\n", ret);
  206. return;
  207. }
  208. ret = as3722_ldo_set_voltage(dev, 10, 0x80);
  209. if (ret < 0) {
  210. pr_err("failed to set LDO10 voltage: %d\n", ret);
  211. return;
  212. }
  213. /* Make sure controller gets enabled by disabling DEV_OFF_N */
  214. gpio_set_value(LAN_DEV_OFF_N, 1);
  215. /*
  216. * Enable LDO9 and LDO10 for +V3.3_ETH on patched prototype
  217. * V1.0A and sample V1.0B and newer modules
  218. */
  219. ret = as3722_ldo_set_voltage(dev, 9, 0xff);
  220. if (ret < 0) {
  221. pr_err("failed to set LDO9 voltage: %d\n", ret);
  222. return;
  223. }
  224. ret = as3722_ldo_set_voltage(dev, 10, 0xff);
  225. if (ret < 0) {
  226. pr_err("failed to set LDO10 voltage: %d\n", ret);
  227. return;
  228. }
  229. /*
  230. * Must be asserted for 100 ms after power and clocks are stable
  231. */
  232. mdelay(100);
  233. gpio_set_value(LAN_RESET_N, 1);
  234. } else if (index == 0) { /* Apalis PCIe */
  235. #ifdef CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT
  236. /*
  237. * Reset PLX PEX 8605 PCIe Switch plus PCIe devices on Apalis
  238. * Evaluation Board
  239. */
  240. gpio_direction_output(PEX_PERST_N, 0);
  241. gpio_direction_output(RESET_MOCI_CTRL, 0);
  242. /*
  243. * Must be asserted for 100 ms after power and clocks are stable
  244. */
  245. mdelay(100);
  246. gpio_set_value(PEX_PERST_N, 1);
  247. /*
  248. * Err_5: PEX_REFCLK_OUTpx/nx Clock Outputs is not Guaranteed
  249. * Until 900 us After PEX_PERST# De-assertion
  250. */
  251. mdelay(1);
  252. gpio_set_value(RESET_MOCI_CTRL, 1);
  253. #endif /* CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT */
  254. }
  255. }
  256. #endif /* CONFIG_PCI_TEGRA */
  257. /*
  258. * Enable/start PWM CPU fan
  259. */
  260. void start_cpu_fan(void)
  261. {
  262. gpio_request(FAN_EN, "FAN_EN");
  263. gpio_direction_output(FAN_EN, 1);
  264. }
  265. /*
  266. * Backlight off before OS handover
  267. */
  268. void board_preboot_os(void)
  269. {
  270. gpio_request(TEGRA_GPIO(BB, 5), "BL_ON");
  271. gpio_direction_output(TEGRA_GPIO(BB, 5), 0);
  272. }