1 // SPDX-License-Identifier: GPL-2.0+
3 * Common board functions for siemens AM335X based boards
4 * (C) Copyright 2013 Siemens Schweiz AG
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>
35 #include <asm/mach-types.h>
36 #include "../common/factoryset.h"
38 DECLARE_GLOBAL_DATA_PTR;
40 #ifdef CONFIG_SPL_BUILD
41 void set_uart_mux_conf(void)
43 enable_uart0_pin_mux();
46 void set_mux_conf_regs(void)
48 /* Initalize the board header */
49 enable_i2c0_pin_mux();
52 /* enable early the console */
53 gd->baudrate = CONFIG_BAUDRATE;
56 if (read_eeprom() < 0)
57 puts("Could not get board ID.\n");
59 enable_board_pin_mux();
64 spl_siemens_board_init();
69 #endif /* #ifdef CONFIG_SPL_BUILD */
71 #ifndef CONFIG_SPL_BUILD
73 * Basic board specific setup. Pinmux has been handled already.
77 #if defined(CONFIG_HW_WATCHDOG)
79 #endif /* defined(CONFIG_HW_WATCHDOG) */
81 if (read_eeprom() < 0)
82 puts("Could not get board ID.\n");
83 #ifdef CONFIG_MACH_TYPE
84 gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
86 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
88 #ifdef CONFIG_FACTORYSET
89 factoryset_read_eeprom(CONFIG_SYS_I2C_EEPROM_ADDR);
94 #ifdef CONFIG_NAND_CS_INIT
103 #endif /* #ifndef CONFIG_SPL_BUILD */
105 #define OSC (V_OSCK/1000000)
106 const struct dpll_params dpll_ddr = {
107 DDR_PLL_FREQ, OSC-1, 1, -1, -1, -1, -1};
109 const struct dpll_params *get_dpll_ddr_params(void)
114 #ifndef CONFIG_SPL_BUILD
116 #define MAX_NR_LEDS 10
117 #define MAX_PIN_NUMBER 128
120 #if defined(BOARD_DFU_BUTTON_GPIO)
121 unsigned char get_button_state(char * const envname, unsigned char def)
127 /* If button is not found we take default */
128 ptr_env = env_get(envname);
129 if (NULL == ptr_env) {
132 gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0);
133 if (gpio > MAX_PIN_NUMBER)
137 gpio_request(gpio, "");
138 gpio_direction_input(gpio);
139 if (gpio_get_value(gpio))
149 * This command returns the status of the user button on
151 * Returns - 1 if button is held down
152 * 0 if button is not held down
155 do_userbutton(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
158 button = get_button_state("button_dfu0", BOARD_DFU_BUTTON_GPIO);
159 button |= get_button_state("button_dfu1", BOARD_DFU_BUTTON_GPIO);
164 dfubutton, CONFIG_SYS_MAXARGS, 1, do_userbutton,
165 "Return the status of the DFU button",
171 do_usertestwdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
173 printf("\n\n\n Go into infinite loop\n\n\n");
180 testwdt, CONFIG_SYS_MAXARGS, 1, do_usertestwdt,
181 "Sends U-Boot into infinite loop",
186 * Get led gpios from env and set them.
187 * The led define in environment need to need to be of the form ledN=NN,S0,S1
188 * where N is an unsigned integer from 0 to 9 and S0 and S1 is 0 or 1. S0
189 * defines the startup state of the led, S1 the special state of the led when
190 * it enters e.g. dfu mode.
192 void set_env_gpios(unsigned char state)
195 char str_tmp[5]; /* must contain "ledX"*/
196 unsigned char i, idx, pos1, pos2, ccount;
197 unsigned char gpio_n, gpio_s0, gpio_s1;
199 for (i = 0; i < MAX_NR_LEDS; i++) {
200 sprintf(str_tmp, "led%d", i);
202 /* If env var is not found we stop */
203 ptr_env = env_get(str_tmp);
207 /* Find sperators position */
211 for (idx = 0; ptr_env[idx] != '\0'; idx++) {
212 if (ptr_env[idx] == ',') {
219 /* Bad led description skip this definition */
220 if (pos2 <= pos1 || ccount > 2)
223 /* Get pin number and request gpio */
224 memset(str_tmp, 0, sizeof(str_tmp));
225 strncpy(str_tmp, ptr_env, pos1*sizeof(char));
226 gpio_n = (unsigned char)simple_strtoul(str_tmp, NULL, 0);
228 /* Invalid gpio number skip definition */
229 if (gpio_n > MAX_PIN_NUMBER)
232 gpio_request(gpio_n, "");
234 if (state == STARTUP) {
235 /* get pin state 0 and set */
236 memset(str_tmp, 0, sizeof(str_tmp));
237 strncpy(str_tmp, ptr_env+pos1+1,
238 (pos2-pos1-1)*sizeof(char));
239 gpio_s0 = (unsigned char)simple_strtoul(str_tmp, NULL,
242 gpio_direction_output(gpio_n, gpio_s0);
245 /* get pin state 1 and set */
246 memset(str_tmp, 0, sizeof(str_tmp));
247 strcpy(str_tmp, ptr_env+pos2+1);
248 gpio_s1 = (unsigned char)simple_strtoul(str_tmp, NULL,
250 gpio_direction_output(gpio_n, gpio_s1);
252 } /* loop through defined led in environment */
255 static int do_board_led(struct cmd_tbl *cmdtp, int flag, int argc,
259 return CMD_RET_USAGE;
260 if ((unsigned char)simple_strtoul(argv[1], NULL, 0) == STARTUP)
268 draco_led, CONFIG_SYS_MAXARGS, 2, do_board_led,
269 "Set LEDs defined in environment",
272 #endif /* !CONFIG_SPL_BUILD */