board.c 5.8 KB

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