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/
20 #include <asm/arch/cpu.h>
21 #include <asm/arch/hardware.h>
22 #include <asm/arch/omap.h>
23 #include <asm/arch/ddr_defs.h>
24 #include <asm/arch/clock.h>
25 #include <asm/arch/gpio.h>
26 #include <asm/arch/mmc_host_def.h>
27 #include <asm/arch/sys_proto.h>
28 #include <asm/global_data.h>
36 #include <asm/mach-types.h>
37 #include "../common/factoryset.h"
39 DECLARE_GLOBAL_DATA_PTR;
41 #ifdef CONFIG_SPL_BUILD
42 void set_uart_mux_conf(void)
44 enable_uart0_pin_mux();
47 void set_mux_conf_regs(void)
49 /* Initalize the board header */
50 enable_i2c0_pin_mux();
53 /* enable early the console */
54 gd->baudrate = CONFIG_BAUDRATE;
57 if (read_eeprom() < 0)
58 puts("Could not get board ID.\n");
60 enable_board_pin_mux();
65 spl_siemens_board_init();
70 #endif /* #ifdef CONFIG_SPL_BUILD */
72 #ifndef CONFIG_SPL_BUILD
74 * Basic board specific setup. Pinmux has been handled already.
78 #if defined(CONFIG_HW_WATCHDOG)
80 #endif /* defined(CONFIG_HW_WATCHDOG) */
82 if (read_eeprom() < 0)
83 puts("Could not get board ID.\n");
84 #ifdef CONFIG_MACH_TYPE
85 gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
87 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
89 #ifdef CONFIG_FACTORYSET
90 factoryset_read_eeprom(CONFIG_SYS_I2C_EEPROM_ADDR);
95 #ifdef CONFIG_NAND_CS_INIT
104 #endif /* #ifndef CONFIG_SPL_BUILD */
106 #define OSC (V_OSCK/1000000)
107 const struct dpll_params dpll_ddr = {
108 DDR_PLL_FREQ, OSC-1, 1, -1, -1, -1, -1};
110 const struct dpll_params *get_dpll_ddr_params(void)
115 #ifndef CONFIG_SPL_BUILD
117 #define MAX_NR_LEDS 10
118 #define MAX_PIN_NUMBER 128
121 #if defined(BOARD_DFU_BUTTON_GPIO)
122 unsigned char get_button_state(char * const envname, unsigned char def)
128 /* If button is not found we take default */
129 ptr_env = env_get(envname);
130 if (NULL == ptr_env) {
133 gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0);
134 if (gpio > MAX_PIN_NUMBER)
138 gpio_request(gpio, "");
139 gpio_direction_input(gpio);
140 if (gpio_get_value(gpio))
150 * This command returns the status of the user button on
152 * Returns - 1 if button is held down
153 * 0 if button is not held down
156 do_userbutton(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
159 button = get_button_state("button_dfu0", BOARD_DFU_BUTTON_GPIO);
160 button |= get_button_state("button_dfu1", BOARD_DFU_BUTTON_GPIO);
165 dfubutton, CONFIG_SYS_MAXARGS, 1, do_userbutton,
166 "Return the status of the DFU button",
172 do_usertestwdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
174 printf("\n\n\n Go into infinite loop\n\n\n");
181 testwdt, CONFIG_SYS_MAXARGS, 1, do_usertestwdt,
182 "Sends U-Boot into infinite loop",
187 * Get led gpios from env and set them.
188 * The led define in environment need to need to be of the form ledN=NN,S0,S1
189 * where N is an unsigned integer from 0 to 9 and S0 and S1 is 0 or 1. S0
190 * defines the startup state of the led, S1 the special state of the led when
191 * it enters e.g. dfu mode.
193 void set_env_gpios(unsigned char state)
196 char str_tmp[5]; /* must contain "ledX"*/
197 unsigned char i, idx, pos1, pos2, ccount;
198 unsigned char gpio_n, gpio_s0, gpio_s1;
200 for (i = 0; i < MAX_NR_LEDS; i++) {
201 sprintf(str_tmp, "led%d", i);
203 /* If env var is not found we stop */
204 ptr_env = env_get(str_tmp);
208 /* Find sperators position */
212 for (idx = 0; ptr_env[idx] != '\0'; idx++) {
213 if (ptr_env[idx] == ',') {
220 /* Bad led description skip this definition */
221 if (pos2 <= pos1 || ccount > 2)
224 /* Get pin number and request gpio */
225 memset(str_tmp, 0, sizeof(str_tmp));
226 strncpy(str_tmp, ptr_env, pos1*sizeof(char));
227 gpio_n = (unsigned char)simple_strtoul(str_tmp, NULL, 0);
229 /* Invalid gpio number skip definition */
230 if (gpio_n > MAX_PIN_NUMBER)
233 gpio_request(gpio_n, "");
235 if (state == STARTUP) {
236 /* get pin state 0 and set */
237 memset(str_tmp, 0, sizeof(str_tmp));
238 strncpy(str_tmp, ptr_env+pos1+1,
239 (pos2-pos1-1)*sizeof(char));
240 gpio_s0 = (unsigned char)simple_strtoul(str_tmp, NULL,
243 gpio_direction_output(gpio_n, gpio_s0);
246 /* get pin state 1 and set */
247 memset(str_tmp, 0, sizeof(str_tmp));
248 strcpy(str_tmp, ptr_env+pos2+1);
249 gpio_s1 = (unsigned char)simple_strtoul(str_tmp, NULL,
251 gpio_direction_output(gpio_n, gpio_s1);
253 } /* loop through defined led in environment */
256 static int do_board_led(struct cmd_tbl *cmdtp, int flag, int argc,
260 return CMD_RET_USAGE;
261 if ((unsigned char)simple_strtoul(argv[1], NULL, 0) == STARTUP)
269 draco_led, CONFIG_SYS_MAXARGS, 2, do_board_led,
270 "Set LEDs defined in environment",
273 #endif /* !CONFIG_SPL_BUILD */