board.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Common board functions for siemens AM335X based boards
  3. * (C) Copyright 2013 Siemens Schweiz AG
  4. * (C) Heiko Schocher, DENX Software Engineering, hs@denx.de.
  5. *
  6. * Based on:
  7. * U-Boot file:/board/ti/am335x/board.c
  8. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  9. *
  10. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <common.h>
  13. #include <errno.h>
  14. #include <spl.h>
  15. #include <asm/arch/cpu.h>
  16. #include <asm/arch/hardware.h>
  17. #include <asm/arch/omap.h>
  18. #include <asm/arch/ddr_defs.h>
  19. #include <asm/arch/clock.h>
  20. #include <asm/arch/gpio.h>
  21. #include <asm/arch/mmc_host_def.h>
  22. #include <asm/arch/sys_proto.h>
  23. #include <asm/io.h>
  24. #include <asm/emif.h>
  25. #include <asm/gpio.h>
  26. #include <i2c.h>
  27. #include <miiphy.h>
  28. #include <cpsw.h>
  29. #include <watchdog.h>
  30. #include "../common/factoryset.h"
  31. DECLARE_GLOBAL_DATA_PTR;
  32. #ifdef CONFIG_SPL_BUILD
  33. void set_uart_mux_conf(void)
  34. {
  35. enable_uart0_pin_mux();
  36. }
  37. void set_mux_conf_regs(void)
  38. {
  39. /* Initalize the board header */
  40. enable_i2c0_pin_mux();
  41. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  42. if (read_eeprom() < 0)
  43. puts("Could not get board ID.\n");
  44. enable_board_pin_mux();
  45. }
  46. void sdram_init(void)
  47. {
  48. spl_siemens_board_init();
  49. board_init_ddr();
  50. return;
  51. }
  52. #endif /* #ifdef CONFIG_SPL_BUILD */
  53. #ifndef CONFIG_SPL_BUILD
  54. /*
  55. * Basic board specific setup. Pinmux has been handled already.
  56. */
  57. int board_init(void)
  58. {
  59. #if defined(CONFIG_HW_WATCHDOG)
  60. hw_watchdog_init();
  61. #endif /* defined(CONFIG_HW_WATCHDOG) */
  62. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  63. if (read_eeprom() < 0)
  64. puts("Could not get board ID.\n");
  65. gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
  66. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  67. #ifdef CONFIG_FACTORYSET
  68. factoryset_read_eeprom(CONFIG_SYS_I2C_EEPROM_ADDR);
  69. #endif
  70. gpmc_init();
  71. #ifdef CONFIG_VIDEO
  72. board_video_init();
  73. #endif
  74. return 0;
  75. }
  76. #endif /* #ifndef CONFIG_SPL_BUILD */
  77. #define OSC (V_OSCK/1000000)
  78. const struct dpll_params dpll_ddr = {
  79. DDR_PLL_FREQ, OSC-1, 1, -1, -1, -1, -1};
  80. const struct dpll_params *get_dpll_ddr_params(void)
  81. {
  82. return &dpll_ddr;
  83. }
  84. #ifdef CONFIG_BOARD_LATE_INIT
  85. int board_late_init(void)
  86. {
  87. omap_nand_switch_ecc(1, 8);
  88. return 0;
  89. }
  90. #endif
  91. #ifndef CONFIG_SPL_BUILD
  92. #if defined(BOARD_DFU_BUTTON_GPIO)
  93. /*
  94. * This command returns the status of the user button on
  95. * Input - none
  96. * Returns - 1 if button is held down
  97. * 0 if button is not held down
  98. */
  99. static int
  100. do_userbutton(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  101. {
  102. int button = 0;
  103. int gpio;
  104. gpio = BOARD_DFU_BUTTON_GPIO;
  105. gpio_request(gpio, "DFU");
  106. gpio_direction_input(gpio);
  107. if (gpio_get_value(gpio))
  108. button = 1;
  109. else
  110. button = 0;
  111. gpio_free(gpio);
  112. if (!button) {
  113. /* LED0 - RED=1: GPIO2_0 2*32 = 64 */
  114. gpio_request(BOARD_DFU_BUTTON_LED, "");
  115. gpio_direction_output(BOARD_DFU_BUTTON_LED, 1);
  116. gpio_set_value(BOARD_DFU_BUTTON_LED, 1);
  117. }
  118. return button;
  119. }
  120. U_BOOT_CMD(
  121. dfubutton, CONFIG_SYS_MAXARGS, 1, do_userbutton,
  122. "Return the status of the DFU button",
  123. ""
  124. );
  125. #endif
  126. static int
  127. do_usertestwdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  128. {
  129. printf("\n\n\n Go into infinite loop\n\n\n");
  130. while (1)
  131. ;
  132. return 0;
  133. };
  134. U_BOOT_CMD(
  135. testwdt, CONFIG_SYS_MAXARGS, 1, do_usertestwdt,
  136. "Sends U-Boot into infinite loop",
  137. ""
  138. );
  139. #ifndef CONFIG_SYS_DCACHE_OFF
  140. void enable_caches(void)
  141. {
  142. printf("Enable d-cache\n");
  143. /* Enable D-cache. I-cache is already enabled in start.S */
  144. dcache_enable();
  145. }
  146. #endif /* CONFIG_SYS_DCACHE_OFF */
  147. #endif /* !CONFIG_SPL_BUILD */