board.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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_set_bus_num(0);
  42. /* enable early the console */
  43. gd->baudrate = CONFIG_BAUDRATE;
  44. serial_init();
  45. gd->have_console = 1;
  46. if (read_eeprom() < 0)
  47. puts("Could not get board ID.\n");
  48. enable_board_pin_mux();
  49. }
  50. void sdram_init(void)
  51. {
  52. spl_siemens_board_init();
  53. board_init_ddr();
  54. return;
  55. }
  56. #endif /* #ifdef CONFIG_SPL_BUILD */
  57. #ifndef CONFIG_SPL_BUILD
  58. /*
  59. * Basic board specific setup. Pinmux has been handled already.
  60. */
  61. int board_init(void)
  62. {
  63. #if defined(CONFIG_HW_WATCHDOG)
  64. hw_watchdog_init();
  65. #endif /* defined(CONFIG_HW_WATCHDOG) */
  66. i2c_set_bus_num(0);
  67. if (read_eeprom() < 0)
  68. puts("Could not get board ID.\n");
  69. #ifdef CONFIG_MACH_TYPE
  70. gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
  71. #endif
  72. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  73. #ifdef CONFIG_FACTORYSET
  74. factoryset_read_eeprom(CONFIG_SYS_I2C_EEPROM_ADDR);
  75. #endif
  76. gpmc_init();
  77. #ifdef CONFIG_NAND_CS_INIT
  78. board_nand_cs_init();
  79. #endif
  80. #ifdef CONFIG_VIDEO
  81. board_video_init();
  82. #endif
  83. return 0;
  84. }
  85. #endif /* #ifndef CONFIG_SPL_BUILD */
  86. #define OSC (V_OSCK/1000000)
  87. const struct dpll_params dpll_ddr = {
  88. DDR_PLL_FREQ, OSC-1, 1, -1, -1, -1, -1};
  89. const struct dpll_params *get_dpll_ddr_params(void)
  90. {
  91. return &dpll_ddr;
  92. }
  93. #ifndef CONFIG_SPL_BUILD
  94. #define MAX_NR_LEDS 10
  95. #define MAX_PIN_NUMBER 128
  96. #define STARTUP 0
  97. #if defined(BOARD_DFU_BUTTON_GPIO)
  98. unsigned char get_button_state(char * const envname, unsigned char def)
  99. {
  100. int button = 0;
  101. int gpio;
  102. char *ptr_env;
  103. /* If button is not found we take default */
  104. ptr_env = getenv(envname);
  105. if (NULL == ptr_env) {
  106. gpio = def;
  107. } else {
  108. gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0);
  109. if (gpio > MAX_PIN_NUMBER)
  110. gpio = def;
  111. }
  112. gpio_request(gpio, "");
  113. gpio_direction_input(gpio);
  114. if (gpio_get_value(gpio))
  115. button = 1;
  116. else
  117. button = 0;
  118. gpio_free(gpio);
  119. return button;
  120. }
  121. /**
  122. * This command returns the status of the user button on
  123. * Input - none
  124. * Returns - 1 if button is held down
  125. * 0 if button is not held down
  126. */
  127. static int
  128. do_userbutton(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  129. {
  130. int button = 0;
  131. button = get_button_state("button_dfu0", BOARD_DFU_BUTTON_GPIO);
  132. button |= get_button_state("button_dfu1", BOARD_DFU_BUTTON_GPIO);
  133. return button;
  134. }
  135. U_BOOT_CMD(
  136. dfubutton, CONFIG_SYS_MAXARGS, 1, do_userbutton,
  137. "Return the status of the DFU button",
  138. ""
  139. );
  140. #endif
  141. static int
  142. do_usertestwdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  143. {
  144. printf("\n\n\n Go into infinite loop\n\n\n");
  145. while (1)
  146. ;
  147. return 0;
  148. };
  149. U_BOOT_CMD(
  150. testwdt, CONFIG_SYS_MAXARGS, 1, do_usertestwdt,
  151. "Sends U-Boot into infinite loop",
  152. ""
  153. );
  154. /**
  155. * Get led gpios from env and set them.
  156. * The led define in environment need to need to be of the form ledN=NN,S0,S1
  157. * where N is an unsigned integer from 0 to 9 and S0 and S1 is 0 or 1. S0
  158. * defines the startup state of the led, S1 the special state of the led when
  159. * it enters e.g. dfu mode.
  160. */
  161. void set_env_gpios(unsigned char state)
  162. {
  163. char *ptr_env;
  164. char str_tmp[5]; /* must contain "ledX"*/
  165. char num[1];
  166. unsigned char i, idx, pos1, pos2, ccount;
  167. unsigned char gpio_n, gpio_s0, gpio_s1;
  168. for (i = 0; i < MAX_NR_LEDS; i++) {
  169. strcpy(str_tmp, "led");
  170. sprintf(num, "%d", i);
  171. strcat(str_tmp, num);
  172. /* If env var is not found we stop */
  173. ptr_env = getenv(str_tmp);
  174. if (NULL == ptr_env)
  175. break;
  176. /* Find sperators position */
  177. pos1 = 0;
  178. pos2 = 0;
  179. ccount = 0;
  180. for (idx = 0; ptr_env[idx] != '\0'; idx++) {
  181. if (ptr_env[idx] == ',') {
  182. if (ccount++ < 1)
  183. pos1 = idx;
  184. else
  185. pos2 = idx;
  186. }
  187. }
  188. /* Bad led description skip this definition */
  189. if (pos2 <= pos1 || ccount > 2)
  190. continue;
  191. /* Get pin number and request gpio */
  192. memset(str_tmp, 0, sizeof(str_tmp));
  193. strncpy(str_tmp, ptr_env, pos1*sizeof(char));
  194. gpio_n = (unsigned char)simple_strtoul(str_tmp, NULL, 0);
  195. /* Invalid gpio number skip definition */
  196. if (gpio_n > MAX_PIN_NUMBER)
  197. continue;
  198. gpio_request(gpio_n, "");
  199. if (state == STARTUP) {
  200. /* get pin state 0 and set */
  201. memset(str_tmp, 0, sizeof(str_tmp));
  202. strncpy(str_tmp, ptr_env+pos1+1,
  203. (pos2-pos1-1)*sizeof(char));
  204. gpio_s0 = (unsigned char)simple_strtoul(str_tmp, NULL,
  205. 0);
  206. gpio_direction_output(gpio_n, gpio_s0);
  207. } else {
  208. /* get pin state 1 and set */
  209. memset(str_tmp, 0, sizeof(str_tmp));
  210. strcpy(str_tmp, ptr_env+pos2+1);
  211. gpio_s1 = (unsigned char)simple_strtoul(str_tmp, NULL,
  212. 0);
  213. gpio_direction_output(gpio_n, gpio_s1);
  214. }
  215. } /* loop through defined led in environment */
  216. }
  217. static int do_board_led(cmd_tbl_t *cmdtp, int flag, int argc,
  218. char *const argv[])
  219. {
  220. if (argc != 2)
  221. return CMD_RET_USAGE;
  222. if ((unsigned char)simple_strtoul(argv[1], NULL, 0) == STARTUP)
  223. set_env_gpios(0);
  224. else
  225. set_env_gpios(1);
  226. return 0;
  227. };
  228. U_BOOT_CMD(
  229. draco_led, CONFIG_SYS_MAXARGS, 2, do_board_led,
  230. "Set LEDs defined in environment",
  231. "<0|1>"
  232. );
  233. #endif /* !CONFIG_SPL_BUILD */