blob: b9672274117d38574ca988e61504cfa94b920577 [file] [log] [blame]
Heiko Schocher499c4982013-08-19 16:39:01 +02001/*
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
13#include <common.h>
14#include <errno.h>
15#include <spl.h>
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>
24#include <asm/io.h>
25#include <asm/emif.h>
26#include <asm/gpio.h>
27#include <i2c.h>
28#include <miiphy.h>
29#include <cpsw.h>
30#include <watchdog.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060031#include <asm/mach-types.h>
Heiko Schocher499c4982013-08-19 16:39:01 +020032#include "../common/factoryset.h"
33
34DECLARE_GLOBAL_DATA_PTR;
35
36#ifdef CONFIG_SPL_BUILD
37void set_uart_mux_conf(void)
38{
39 enable_uart0_pin_mux();
40}
41
42void set_mux_conf_regs(void)
43{
44 /* Initalize the board header */
45 enable_i2c0_pin_mux();
Heiko Schocherf53f2b82013-10-22 11:03:18 +020046 i2c_set_bus_num(0);
Heiko Schocherb5e7d372015-05-28 07:27:36 +020047
48 /* enable early the console */
49 gd->baudrate = CONFIG_BAUDRATE;
50 serial_init();
51 gd->have_console = 1;
Heiko Schocher499c4982013-08-19 16:39:01 +020052 if (read_eeprom() < 0)
53 puts("Could not get board ID.\n");
54
55 enable_board_pin_mux();
56}
57
58void sdram_init(void)
59{
60 spl_siemens_board_init();
61 board_init_ddr();
62
63 return;
64}
65#endif /* #ifdef CONFIG_SPL_BUILD */
66
67#ifndef CONFIG_SPL_BUILD
68/*
69 * Basic board specific setup. Pinmux has been handled already.
70 */
71int board_init(void)
72{
73#if defined(CONFIG_HW_WATCHDOG)
74 hw_watchdog_init();
75#endif /* defined(CONFIG_HW_WATCHDOG) */
Heiko Schocherf53f2b82013-10-22 11:03:18 +020076 i2c_set_bus_num(0);
Heiko Schocher499c4982013-08-19 16:39:01 +020077 if (read_eeprom() < 0)
78 puts("Could not get board ID.\n");
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020079#ifdef CONFIG_MACH_TYPE
Heiko Schocher499c4982013-08-19 16:39:01 +020080 gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020081#endif
Heiko Schocher499c4982013-08-19 16:39:01 +020082 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
83
84#ifdef CONFIG_FACTORYSET
85 factoryset_read_eeprom(CONFIG_SYS_I2C_EEPROM_ADDR);
86#endif
Heiko Schochercbec11a2016-06-07 08:55:45 +020087
Heiko Schocher499c4982013-08-19 16:39:01 +020088 gpmc_init();
89
Heiko Schochercbec11a2016-06-07 08:55:45 +020090#ifdef CONFIG_NAND_CS_INIT
91 board_nand_cs_init();
92#endif
Heiko Schocher499c4982013-08-19 16:39:01 +020093#ifdef CONFIG_VIDEO
94 board_video_init();
95#endif
96
97 return 0;
98}
99#endif /* #ifndef CONFIG_SPL_BUILD */
100
101#define OSC (V_OSCK/1000000)
102const struct dpll_params dpll_ddr = {
103 DDR_PLL_FREQ, OSC-1, 1, -1, -1, -1, -1};
104
105const struct dpll_params *get_dpll_ddr_params(void)
106{
107 return &dpll_ddr;
108}
109
Heiko Schocher499c4982013-08-19 16:39:01 +0200110#ifndef CONFIG_SPL_BUILD
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200111
112#define MAX_NR_LEDS 10
113#define MAX_PIN_NUMBER 128
114#define STARTUP 0
115
Heiko Schocher499c4982013-08-19 16:39:01 +0200116#if defined(BOARD_DFU_BUTTON_GPIO)
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200117unsigned char get_button_state(char * const envname, unsigned char def)
Heiko Schocher499c4982013-08-19 16:39:01 +0200118{
119 int button = 0;
120 int gpio;
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200121 char *ptr_env;
Heiko Schocher499c4982013-08-19 16:39:01 +0200122
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200123 /* If button is not found we take default */
124 ptr_env = getenv(envname);
125 if (NULL == ptr_env) {
126 gpio = def;
127 } else {
128 gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0);
129 if (gpio > MAX_PIN_NUMBER)
130 gpio = def;
131 }
132
133 gpio_request(gpio, "");
Heiko Schocher499c4982013-08-19 16:39:01 +0200134 gpio_direction_input(gpio);
135 if (gpio_get_value(gpio))
136 button = 1;
137 else
138 button = 0;
139
140 gpio_free(gpio);
Heiko Schocher499c4982013-08-19 16:39:01 +0200141
142 return button;
143}
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200144/**
145 * This command returns the status of the user button on
146 * Input - none
147 * Returns - 1 if button is held down
148 * 0 if button is not held down
Egli, Samuelfdb5e262014-04-24 17:57:54 +0200149 */
150static int
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200151do_userbutton(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Egli, Samuelfdb5e262014-04-24 17:57:54 +0200152{
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200153 int button = 0;
154 button = get_button_state("button_dfu0", BOARD_DFU_BUTTON_GPIO);
155 button |= get_button_state("button_dfu1", BOARD_DFU_BUTTON_GPIO);
156 return button;
Egli, Samuelfdb5e262014-04-24 17:57:54 +0200157}
158
159U_BOOT_CMD(
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200160 dfubutton, CONFIG_SYS_MAXARGS, 1, do_userbutton,
161 "Return the status of the DFU button",
162 ""
Egli, Samuelfdb5e262014-04-24 17:57:54 +0200163);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200164#endif
Heiko Schocher499c4982013-08-19 16:39:01 +0200165
166static int
167do_usertestwdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
168{
169 printf("\n\n\n Go into infinite loop\n\n\n");
170 while (1)
171 ;
172 return 0;
173};
174
175U_BOOT_CMD(
176 testwdt, CONFIG_SYS_MAXARGS, 1, do_usertestwdt,
177 "Sends U-Boot into infinite loop",
178 ""
179);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200180
181/**
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.
187 */
188void set_env_gpios(unsigned char state)
189{
190 char *ptr_env;
191 char str_tmp[5]; /* must contain "ledX"*/
192 char num[1];
193 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++) {
197 strcpy(str_tmp, "led");
198 sprintf(num, "%d", i);
199 strcat(str_tmp, num);
200
201 /* If env var is not found we stop */
202 ptr_env = getenv(str_tmp);
203 if (NULL == ptr_env)
204 break;
205
206 /* Find sperators position */
207 pos1 = 0;
208 pos2 = 0;
209 ccount = 0;
210 for (idx = 0; ptr_env[idx] != '\0'; idx++) {
211 if (ptr_env[idx] == ',') {
212 if (ccount++ < 1)
213 pos1 = idx;
214 else
215 pos2 = idx;
216 }
217 }
218 /* Bad led description skip this definition */
219 if (pos2 <= pos1 || ccount > 2)
220 continue;
221
222 /* Get pin number and request gpio */
223 memset(str_tmp, 0, sizeof(str_tmp));
224 strncpy(str_tmp, ptr_env, pos1*sizeof(char));
225 gpio_n = (unsigned char)simple_strtoul(str_tmp, NULL, 0);
226
227 /* Invalid gpio number skip definition */
228 if (gpio_n > MAX_PIN_NUMBER)
229 continue;
230
231 gpio_request(gpio_n, "");
232
233 if (state == STARTUP) {
234 /* get pin state 0 and set */
235 memset(str_tmp, 0, sizeof(str_tmp));
236 strncpy(str_tmp, ptr_env+pos1+1,
237 (pos2-pos1-1)*sizeof(char));
238 gpio_s0 = (unsigned char)simple_strtoul(str_tmp, NULL,
239 0);
240
241 gpio_direction_output(gpio_n, gpio_s0);
242
243 } else {
244 /* get pin state 1 and set */
245 memset(str_tmp, 0, sizeof(str_tmp));
246 strcpy(str_tmp, ptr_env+pos2+1);
247 gpio_s1 = (unsigned char)simple_strtoul(str_tmp, NULL,
248 0);
249 gpio_direction_output(gpio_n, gpio_s1);
250 }
251 } /* loop through defined led in environment */
252}
253
254static int do_board_led(cmd_tbl_t *cmdtp, int flag, int argc,
255 char *const argv[])
256{
257 if (argc != 2)
258 return CMD_RET_USAGE;
259 if ((unsigned char)simple_strtoul(argv[1], NULL, 0) == STARTUP)
260 set_env_gpios(0);
261 else
262 set_env_gpios(1);
263 return 0;
264};
265
266U_BOOT_CMD(
267 draco_led, CONFIG_SYS_MAXARGS, 2, do_board_led,
268 "Set LEDs defined in environment",
269 "<0|1>"
270);
Heiko Schocher499c4982013-08-19 16:39:01 +0200271#endif /* !CONFIG_SPL_BUILD */