blob: 5f5e2eb544cc32645904ced6619da2b8d0c7af18 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocher499c4982013-08-19 16:39:01 +02002/*
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.
6 *
7 * Based on:
8 * U-Boot file:/board/ti/am335x/board.c
9 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
Heiko Schocher499c4982013-08-19 16:39:01 +020010 */
11
12#include <common.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060013#include <env.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020014#include <errno.h>
Simon Glass36736182019-11-14 12:57:24 -070015#include <serial.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020016#include <spl.h>
17#include <asm/arch/cpu.h>
18#include <asm/arch/hardware.h>
19#include <asm/arch/omap.h>
20#include <asm/arch/ddr_defs.h>
21#include <asm/arch/clock.h>
22#include <asm/arch/gpio.h>
23#include <asm/arch/mmc_host_def.h>
24#include <asm/arch/sys_proto.h>
25#include <asm/io.h>
26#include <asm/emif.h>
27#include <asm/gpio.h>
28#include <i2c.h>
29#include <miiphy.h>
30#include <cpsw.h>
31#include <watchdog.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060032#include <asm/mach-types.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020033#include "../common/factoryset.h"
34
35DECLARE_GLOBAL_DATA_PTR;
36
37#ifdef CONFIG_SPL_BUILD
38void set_uart_mux_conf(void)
39{
40 enable_uart0_pin_mux();
41}
42
43void set_mux_conf_regs(void)
44{
45 /* Initalize the board header */
46 enable_i2c0_pin_mux();
Heiko Schocherf53f2b82013-10-22 11:03:18 +020047 i2c_set_bus_num(0);
Heiko Schocherb5e7d372015-05-28 07:27:36 +020048
49 /* enable early the console */
50 gd->baudrate = CONFIG_BAUDRATE;
51 serial_init();
52 gd->have_console = 1;
Heiko Schocher499c4982013-08-19 16:39:01 +020053 if (read_eeprom() < 0)
54 puts("Could not get board ID.\n");
55
56 enable_board_pin_mux();
57}
58
59void sdram_init(void)
60{
61 spl_siemens_board_init();
62 board_init_ddr();
63
64 return;
65}
66#endif /* #ifdef CONFIG_SPL_BUILD */
67
68#ifndef CONFIG_SPL_BUILD
69/*
70 * Basic board specific setup. Pinmux has been handled already.
71 */
72int board_init(void)
73{
74#if defined(CONFIG_HW_WATCHDOG)
75 hw_watchdog_init();
76#endif /* defined(CONFIG_HW_WATCHDOG) */
Heiko Schocherf53f2b82013-10-22 11:03:18 +020077 i2c_set_bus_num(0);
Heiko Schocher499c4982013-08-19 16:39:01 +020078 if (read_eeprom() < 0)
79 puts("Could not get board ID.\n");
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020080#ifdef CONFIG_MACH_TYPE
Heiko Schocher499c4982013-08-19 16:39:01 +020081 gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020082#endif
Heiko Schocher499c4982013-08-19 16:39:01 +020083 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
84
85#ifdef CONFIG_FACTORYSET
86 factoryset_read_eeprom(CONFIG_SYS_I2C_EEPROM_ADDR);
87#endif
Heiko Schochercbec11a2016-06-07 08:55:45 +020088
Heiko Schocher499c4982013-08-19 16:39:01 +020089 gpmc_init();
90
Heiko Schochercbec11a2016-06-07 08:55:45 +020091#ifdef CONFIG_NAND_CS_INIT
92 board_nand_cs_init();
93#endif
Heiko Schocher499c4982013-08-19 16:39:01 +020094#ifdef CONFIG_VIDEO
95 board_video_init();
96#endif
97
98 return 0;
99}
100#endif /* #ifndef CONFIG_SPL_BUILD */
101
102#define OSC (V_OSCK/1000000)
103const struct dpll_params dpll_ddr = {
104 DDR_PLL_FREQ, OSC-1, 1, -1, -1, -1, -1};
105
106const struct dpll_params *get_dpll_ddr_params(void)
107{
108 return &dpll_ddr;
109}
110
Heiko Schocher499c4982013-08-19 16:39:01 +0200111#ifndef CONFIG_SPL_BUILD
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200112
113#define MAX_NR_LEDS 10
114#define MAX_PIN_NUMBER 128
115#define STARTUP 0
116
Heiko Schocher499c4982013-08-19 16:39:01 +0200117#if defined(BOARD_DFU_BUTTON_GPIO)
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200118unsigned char get_button_state(char * const envname, unsigned char def)
Heiko Schocher499c4982013-08-19 16:39:01 +0200119{
120 int button = 0;
121 int gpio;
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200122 char *ptr_env;
Heiko Schocher499c4982013-08-19 16:39:01 +0200123
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200124 /* If button is not found we take default */
Simon Glass64b723f2017-08-03 12:22:12 -0600125 ptr_env = env_get(envname);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200126 if (NULL == ptr_env) {
127 gpio = def;
128 } else {
129 gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0);
130 if (gpio > MAX_PIN_NUMBER)
131 gpio = def;
132 }
133
134 gpio_request(gpio, "");
Heiko Schocher499c4982013-08-19 16:39:01 +0200135 gpio_direction_input(gpio);
136 if (gpio_get_value(gpio))
137 button = 1;
138 else
139 button = 0;
140
141 gpio_free(gpio);
Heiko Schocher499c4982013-08-19 16:39:01 +0200142
143 return button;
144}
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200145/**
146 * This command returns the status of the user button on
147 * Input - none
148 * Returns - 1 if button is held down
149 * 0 if button is not held down
Egli, Samuelfdb5e262014-04-24 17:57:54 +0200150 */
151static int
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200152do_userbutton(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Egli, Samuelfdb5e262014-04-24 17:57:54 +0200153{
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200154 int button = 0;
155 button = get_button_state("button_dfu0", BOARD_DFU_BUTTON_GPIO);
156 button |= get_button_state("button_dfu1", BOARD_DFU_BUTTON_GPIO);
157 return button;
Egli, Samuelfdb5e262014-04-24 17:57:54 +0200158}
159
160U_BOOT_CMD(
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200161 dfubutton, CONFIG_SYS_MAXARGS, 1, do_userbutton,
162 "Return the status of the DFU button",
163 ""
Egli, Samuelfdb5e262014-04-24 17:57:54 +0200164);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200165#endif
Heiko Schocher499c4982013-08-19 16:39:01 +0200166
167static int
168do_usertestwdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
169{
170 printf("\n\n\n Go into infinite loop\n\n\n");
171 while (1)
172 ;
173 return 0;
174};
175
176U_BOOT_CMD(
177 testwdt, CONFIG_SYS_MAXARGS, 1, do_usertestwdt,
178 "Sends U-Boot into infinite loop",
179 ""
180);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200181
182/**
183 * Get led gpios from env and set them.
184 * The led define in environment need to need to be of the form ledN=NN,S0,S1
185 * where N is an unsigned integer from 0 to 9 and S0 and S1 is 0 or 1. S0
186 * defines the startup state of the led, S1 the special state of the led when
187 * it enters e.g. dfu mode.
188 */
189void set_env_gpios(unsigned char state)
190{
191 char *ptr_env;
192 char str_tmp[5]; /* must contain "ledX"*/
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200193 unsigned char i, idx, pos1, pos2, ccount;
194 unsigned char gpio_n, gpio_s0, gpio_s1;
195
196 for (i = 0; i < MAX_NR_LEDS; i++) {
Heinrich Schuchardt32c63b62019-08-22 21:58:26 +0200197 sprintf(str_tmp, "led%d", i);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200198
199 /* If env var is not found we stop */
Simon Glass64b723f2017-08-03 12:22:12 -0600200 ptr_env = env_get(str_tmp);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200201 if (NULL == ptr_env)
202 break;
203
204 /* Find sperators position */
205 pos1 = 0;
206 pos2 = 0;
207 ccount = 0;
208 for (idx = 0; ptr_env[idx] != '\0'; idx++) {
209 if (ptr_env[idx] == ',') {
210 if (ccount++ < 1)
211 pos1 = idx;
212 else
213 pos2 = idx;
214 }
215 }
216 /* Bad led description skip this definition */
217 if (pos2 <= pos1 || ccount > 2)
218 continue;
219
220 /* Get pin number and request gpio */
221 memset(str_tmp, 0, sizeof(str_tmp));
222 strncpy(str_tmp, ptr_env, pos1*sizeof(char));
223 gpio_n = (unsigned char)simple_strtoul(str_tmp, NULL, 0);
224
225 /* Invalid gpio number skip definition */
226 if (gpio_n > MAX_PIN_NUMBER)
227 continue;
228
229 gpio_request(gpio_n, "");
230
231 if (state == STARTUP) {
232 /* get pin state 0 and set */
233 memset(str_tmp, 0, sizeof(str_tmp));
234 strncpy(str_tmp, ptr_env+pos1+1,
235 (pos2-pos1-1)*sizeof(char));
236 gpio_s0 = (unsigned char)simple_strtoul(str_tmp, NULL,
237 0);
238
239 gpio_direction_output(gpio_n, gpio_s0);
240
241 } else {
242 /* get pin state 1 and set */
243 memset(str_tmp, 0, sizeof(str_tmp));
244 strcpy(str_tmp, ptr_env+pos2+1);
245 gpio_s1 = (unsigned char)simple_strtoul(str_tmp, NULL,
246 0);
247 gpio_direction_output(gpio_n, gpio_s1);
248 }
249 } /* loop through defined led in environment */
250}
251
252static int do_board_led(cmd_tbl_t *cmdtp, int flag, int argc,
253 char *const argv[])
254{
255 if (argc != 2)
256 return CMD_RET_USAGE;
257 if ((unsigned char)simple_strtoul(argv[1], NULL, 0) == STARTUP)
258 set_env_gpios(0);
259 else
260 set_env_gpios(1);
261 return 0;
262};
263
264U_BOOT_CMD(
265 draco_led, CONFIG_SYS_MAXARGS, 2, do_board_led,
266 "Set LEDs defined in environment",
267 "<0|1>"
268);
Heiko Schocher499c4982013-08-19 16:39:01 +0200269#endif /* !CONFIG_SPL_BUILD */