stm32f746-disco.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016, STMicroelectronics - All Rights Reserved
  4. * Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics.
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <lcd.h>
  9. #include <miiphy.h>
  10. #include <phy_interface.h>
  11. #include <ram.h>
  12. #include <serial.h>
  13. #include <spl.h>
  14. #include <splash.h>
  15. #include <st_logo_data.h>
  16. #include <video.h>
  17. #include <asm/io.h>
  18. #include <asm/armv7m.h>
  19. #include <asm/arch/stm32.h>
  20. #include <asm/arch/gpio.h>
  21. #include <asm/arch/syscfg.h>
  22. #include <asm/gpio.h>
  23. DECLARE_GLOBAL_DATA_PTR;
  24. int dram_init(void)
  25. {
  26. #ifndef CONFIG_SUPPORT_SPL
  27. int rv;
  28. struct udevice *dev;
  29. rv = uclass_get_device(UCLASS_RAM, 0, &dev);
  30. if (rv) {
  31. debug("DRAM init failed: %d\n", rv);
  32. return rv;
  33. }
  34. #endif
  35. return fdtdec_setup_mem_size_base();
  36. }
  37. int dram_init_banksize(void)
  38. {
  39. return fdtdec_setup_memory_banksize();
  40. }
  41. int board_early_init_f(void)
  42. {
  43. return 0;
  44. }
  45. #ifdef CONFIG_SPL_BUILD
  46. #ifdef CONFIG_SPL_OS_BOOT
  47. int spl_start_uboot(void)
  48. {
  49. debug("SPL: booting kernel\n");
  50. /* break into full u-boot on 'c' */
  51. return serial_tstc() && serial_getc() == 'c';
  52. }
  53. #endif
  54. int spl_dram_init(void)
  55. {
  56. struct udevice *dev;
  57. int rv;
  58. rv = uclass_get_device(UCLASS_RAM, 0, &dev);
  59. if (rv)
  60. debug("DRAM init failed: %d\n", rv);
  61. return rv;
  62. }
  63. void spl_board_init(void)
  64. {
  65. spl_dram_init();
  66. preloader_console_init();
  67. arch_cpu_init(); /* to configure mpu for sdram rw permissions */
  68. }
  69. u32 spl_boot_device(void)
  70. {
  71. return BOOT_DEVICE_XIP;
  72. }
  73. #endif
  74. u32 get_board_rev(void)
  75. {
  76. return 0;
  77. }
  78. int board_late_init(void)
  79. {
  80. struct gpio_desc gpio = {};
  81. int node;
  82. node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,led1");
  83. if (node < 0)
  84. return -1;
  85. gpio_request_by_name_nodev(offset_to_ofnode(node), "led-gpio", 0, &gpio,
  86. GPIOD_IS_OUT);
  87. if (dm_gpio_is_valid(&gpio)) {
  88. dm_gpio_set_value(&gpio, 0);
  89. mdelay(10);
  90. dm_gpio_set_value(&gpio, 1);
  91. }
  92. /* read button 1*/
  93. node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,button1");
  94. if (node < 0)
  95. return -1;
  96. gpio_request_by_name_nodev(offset_to_ofnode(node), "button-gpio", 0,
  97. &gpio, GPIOD_IS_IN);
  98. if (dm_gpio_is_valid(&gpio)) {
  99. if (dm_gpio_get_value(&gpio))
  100. puts("usr button is at HIGH LEVEL\n");
  101. else
  102. puts("usr button is at LOW LEVEL\n");
  103. }
  104. return 0;
  105. }
  106. int board_init(void)
  107. {
  108. gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
  109. #ifdef CONFIG_ETH_DESIGNWARE
  110. const char *phy_mode;
  111. int node;
  112. node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,stm32-dwmac");
  113. if (node < 0)
  114. return -1;
  115. phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL);
  116. switch (phy_get_interface_by_name(phy_mode)) {
  117. case PHY_INTERFACE_MODE_RMII:
  118. STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL;
  119. break;
  120. case PHY_INTERFACE_MODE_MII:
  121. STM32_SYSCFG->pmc &= ~SYSCFG_PMC_MII_RMII_SEL;
  122. break;
  123. default:
  124. printf("PHY interface %s not supported !\n", phy_mode);
  125. }
  126. #endif
  127. #if defined(CONFIG_CMD_BMP)
  128. bmp_display((ulong)stmicroelectronics_uboot_logo_8bit_rle,
  129. BMP_ALIGN_CENTER, BMP_ALIGN_CENTER);
  130. #endif /* CONFIG_CMD_BMP */
  131. return 0;
  132. }