1 // SPDX-License-Identifier: GPL-2.0+
3 * Common board functions for siemens AM335X based boards
4 * (C) Copyright 2013 Siemens Schweiz AG
5 * (C) Heiko Schocher, DENX Software Engineering, hs@denx.de.
8 * U-Boot file:/board/ti/am335x/board.c
9 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
16 #include <asm/arch/cpu.h>
17 #include <asm/arch/hardware.h>
18 #include <asm/arch/omap.h>
19 #include <asm/arch/ddr_defs.h>
20 #include <asm/arch/clock.h>
21 #include <asm/arch/gpio.h>
22 #include <asm/arch/mmc_host_def.h>
23 #include <asm/arch/sys_proto.h>
31 #include <asm/mach-types.h>
32 #include "../common/factoryset.h"
34 DECLARE_GLOBAL_DATA_PTR;
36 #ifdef CONFIG_SPL_BUILD
37 void set_uart_mux_conf(void)
39 enable_uart0_pin_mux();
42 void set_mux_conf_regs(void)
44 /* Initalize the board header */
45 enable_i2c0_pin_mux();
48 /* enable early the console */
49 gd->baudrate = CONFIG_BAUDRATE;
52 if (read_eeprom() < 0)
53 puts("Could not get board ID.\n");
55 enable_board_pin_mux();
60 spl_siemens_board_init();
65 #endif /* #ifdef CONFIG_SPL_BUILD */
67 #ifndef CONFIG_SPL_BUILD
69 * Basic board specific setup. Pinmux has been handled already.
73 #if defined(CONFIG_HW_WATCHDOG)
75 #endif /* defined(CONFIG_HW_WATCHDOG) */
77 if (read_eeprom() < 0)
78 puts("Could not get board ID.\n");
79 #ifdef CONFIG_MACH_TYPE
80 gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
82 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
84 #ifdef CONFIG_FACTORYSET
85 factoryset_read_eeprom(CONFIG_SYS_I2C_EEPROM_ADDR);
90 #ifdef CONFIG_NAND_CS_INIT
99 #endif /* #ifndef CONFIG_SPL_BUILD */
101 #define OSC (V_OSCK/1000000)
102 const struct dpll_params dpll_ddr = {
103 DDR_PLL_FREQ, OSC-1, 1, -1, -1, -1, -1};
105 const struct dpll_params *get_dpll_ddr_params(void)
110 #ifndef CONFIG_SPL_BUILD
112 #define MAX_NR_LEDS 10
113 #define MAX_PIN_NUMBER 128
116 #if defined(BOARD_DFU_BUTTON_GPIO)
117 unsigned char get_button_state(char * const envname, unsigned char def)
123 /* If button is not found we take default */
124 ptr_env = env_get(envname);
125 if (NULL == ptr_env) {
128 gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0);
129 if (gpio > MAX_PIN_NUMBER)
133 gpio_request(gpio, "");
134 gpio_direction_input(gpio);
135 if (gpio_get_value(gpio))
145 * This command returns the status of the user button on
147 * Returns - 1 if button is held down
148 * 0 if button is not held down
151 do_userbutton(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
154 button = get_button_state("button_dfu0", BOARD_DFU_BUTTON_GPIO);
155 button |= get_button_state("button_dfu1", BOARD_DFU_BUTTON_GPIO);
160 dfubutton, CONFIG_SYS_MAXARGS, 1, do_userbutton,
161 "Return the status of the DFU button",
167 do_usertestwdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
169 printf("\n\n\n Go into infinite loop\n\n\n");
176 testwdt, CONFIG_SYS_MAXARGS, 1, do_usertestwdt,
177 "Sends U-Boot into infinite loop",
182 * Get led gpios from env and set them.
183 * The led define in environment need to need to be of the form ledN=NN,S0,S1
184 * where N is an unsigned integer from 0 to 9 and S0 and S1 is 0 or 1. S0
185 * defines the startup state of the led, S1 the special state of the led when
186 * it enters e.g. dfu mode.
188 void set_env_gpios(unsigned char state)
191 char str_tmp[5]; /* must contain "ledX"*/
192 unsigned char i, idx, pos1, pos2, ccount;
193 unsigned char gpio_n, gpio_s0, gpio_s1;
195 for (i = 0; i < MAX_NR_LEDS; i++) {
196 sprintf(str_tmp, "led%d", i);
198 /* If env var is not found we stop */
199 ptr_env = env_get(str_tmp);
203 /* Find sperators position */
207 for (idx = 0; ptr_env[idx] != '\0'; idx++) {
208 if (ptr_env[idx] == ',') {
215 /* Bad led description skip this definition */
216 if (pos2 <= pos1 || ccount > 2)
219 /* Get pin number and request gpio */
220 memset(str_tmp, 0, sizeof(str_tmp));
221 strncpy(str_tmp, ptr_env, pos1*sizeof(char));
222 gpio_n = (unsigned char)simple_strtoul(str_tmp, NULL, 0);
224 /* Invalid gpio number skip definition */
225 if (gpio_n > MAX_PIN_NUMBER)
228 gpio_request(gpio_n, "");
230 if (state == STARTUP) {
231 /* get pin state 0 and set */
232 memset(str_tmp, 0, sizeof(str_tmp));
233 strncpy(str_tmp, ptr_env+pos1+1,
234 (pos2-pos1-1)*sizeof(char));
235 gpio_s0 = (unsigned char)simple_strtoul(str_tmp, NULL,
238 gpio_direction_output(gpio_n, gpio_s0);
241 /* get pin state 1 and set */
242 memset(str_tmp, 0, sizeof(str_tmp));
243 strcpy(str_tmp, ptr_env+pos2+1);
244 gpio_s1 = (unsigned char)simple_strtoul(str_tmp, NULL,
246 gpio_direction_output(gpio_n, gpio_s1);
248 } /* loop through defined led in environment */
251 static int do_board_led(cmd_tbl_t *cmdtp, int flag, int argc,
255 return CMD_RET_USAGE;
256 if ((unsigned char)simple_strtoul(argv[1], NULL, 0) == STARTUP)
264 draco_led, CONFIG_SYS_MAXARGS, 2, do_board_led,
265 "Set LEDs defined in environment",
268 #endif /* !CONFIG_SPL_BUILD */