blob: 9cafcea53a3c7ea87d07cc8829710164e4f6af86 [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>
31#include "../common/factoryset.h"
32
33DECLARE_GLOBAL_DATA_PTR;
34
35#ifdef CONFIG_SPL_BUILD
36void set_uart_mux_conf(void)
37{
38 enable_uart0_pin_mux();
39}
40
41void set_mux_conf_regs(void)
42{
43 /* Initalize the board header */
44 enable_i2c0_pin_mux();
Heiko Schocherf53f2b82013-10-22 11:03:18 +020045 i2c_set_bus_num(0);
Heiko Schocherb5e7d372015-05-28 07:27:36 +020046
47 /* enable early the console */
48 gd->baudrate = CONFIG_BAUDRATE;
49 serial_init();
50 gd->have_console = 1;
Heiko Schocher499c4982013-08-19 16:39:01 +020051 if (read_eeprom() < 0)
52 puts("Could not get board ID.\n");
53
54 enable_board_pin_mux();
55}
56
57void sdram_init(void)
58{
59 spl_siemens_board_init();
60 board_init_ddr();
61
62 return;
63}
64#endif /* #ifdef CONFIG_SPL_BUILD */
65
66#ifndef CONFIG_SPL_BUILD
67/*
68 * Basic board specific setup. Pinmux has been handled already.
69 */
70int board_init(void)
71{
72#if defined(CONFIG_HW_WATCHDOG)
73 hw_watchdog_init();
74#endif /* defined(CONFIG_HW_WATCHDOG) */
Heiko Schocherf53f2b82013-10-22 11:03:18 +020075 i2c_set_bus_num(0);
Heiko Schocher499c4982013-08-19 16:39:01 +020076 if (read_eeprom() < 0)
77 puts("Could not get board ID.\n");
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020078#ifdef CONFIG_MACH_TYPE
Heiko Schocher499c4982013-08-19 16:39:01 +020079 gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
Heiko Schocherd17c3fc2015-06-16 14:59:34 +020080#endif
Heiko Schocher499c4982013-08-19 16:39:01 +020081 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
82
83#ifdef CONFIG_FACTORYSET
84 factoryset_read_eeprom(CONFIG_SYS_I2C_EEPROM_ADDR);
85#endif
Heiko Schochercbec11a2016-06-07 08:55:45 +020086
Heiko Schocher499c4982013-08-19 16:39:01 +020087 gpmc_init();
88
Heiko Schochercbec11a2016-06-07 08:55:45 +020089#ifdef CONFIG_NAND_CS_INIT
90 board_nand_cs_init();
91#endif
Heiko Schocher499c4982013-08-19 16:39:01 +020092#ifdef CONFIG_VIDEO
93 board_video_init();
94#endif
95
96 return 0;
97}
98#endif /* #ifndef CONFIG_SPL_BUILD */
99
100#define OSC (V_OSCK/1000000)
101const struct dpll_params dpll_ddr = {
102 DDR_PLL_FREQ, OSC-1, 1, -1, -1, -1, -1};
103
104const struct dpll_params *get_dpll_ddr_params(void)
105{
106 return &dpll_ddr;
107}
108
Heiko Schocher499c4982013-08-19 16:39:01 +0200109#ifndef CONFIG_SPL_BUILD
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200110
111#define MAX_NR_LEDS 10
112#define MAX_PIN_NUMBER 128
113#define STARTUP 0
114
Heiko Schocher499c4982013-08-19 16:39:01 +0200115#if defined(BOARD_DFU_BUTTON_GPIO)
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200116unsigned char get_button_state(char * const envname, unsigned char def)
Heiko Schocher499c4982013-08-19 16:39:01 +0200117{
118 int button = 0;
119 int gpio;
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200120 char *ptr_env;
Heiko Schocher499c4982013-08-19 16:39:01 +0200121
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200122 /* If button is not found we take default */
123 ptr_env = getenv(envname);
124 if (NULL == ptr_env) {
125 gpio = def;
126 } else {
127 gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0);
128 if (gpio > MAX_PIN_NUMBER)
129 gpio = def;
130 }
131
132 gpio_request(gpio, "");
Heiko Schocher499c4982013-08-19 16:39:01 +0200133 gpio_direction_input(gpio);
134 if (gpio_get_value(gpio))
135 button = 1;
136 else
137 button = 0;
138
139 gpio_free(gpio);
Heiko Schocher499c4982013-08-19 16:39:01 +0200140
141 return button;
142}
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200143/**
144 * This command returns the status of the user button on
145 * Input - none
146 * Returns - 1 if button is held down
147 * 0 if button is not held down
Egli, Samuelfdb5e262014-04-24 17:57:54 +0200148 */
149static int
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200150do_userbutton(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Egli, Samuelfdb5e262014-04-24 17:57:54 +0200151{
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200152 int button = 0;
153 button = get_button_state("button_dfu0", BOARD_DFU_BUTTON_GPIO);
154 button |= get_button_state("button_dfu1", BOARD_DFU_BUTTON_GPIO);
155 return button;
Egli, Samuelfdb5e262014-04-24 17:57:54 +0200156}
157
158U_BOOT_CMD(
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200159 dfubutton, CONFIG_SYS_MAXARGS, 1, do_userbutton,
160 "Return the status of the DFU button",
161 ""
Egli, Samuelfdb5e262014-04-24 17:57:54 +0200162);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200163#endif
Heiko Schocher499c4982013-08-19 16:39:01 +0200164
165static int
166do_usertestwdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
167{
168 printf("\n\n\n Go into infinite loop\n\n\n");
169 while (1)
170 ;
171 return 0;
172};
173
174U_BOOT_CMD(
175 testwdt, CONFIG_SYS_MAXARGS, 1, do_usertestwdt,
176 "Sends U-Boot into infinite loop",
177 ""
178);
Heiko Schocherd17c3fc2015-06-16 14:59:34 +0200179
180/**
181 * Get led gpios from env and set them.
182 * The led define in environment need to need to be of the form ledN=NN,S0,S1
183 * where N is an unsigned integer from 0 to 9 and S0 and S1 is 0 or 1. S0
184 * defines the startup state of the led, S1 the special state of the led when
185 * it enters e.g. dfu mode.
186 */
187void set_env_gpios(unsigned char state)
188{
189 char *ptr_env;
190 char str_tmp[5]; /* must contain "ledX"*/
191 char num[1];
192 unsigned char i, idx, pos1, pos2, ccount;
193 unsigned char gpio_n, gpio_s0, gpio_s1;
194
195 for (i = 0; i < MAX_NR_LEDS; i++) {
196 strcpy(str_tmp, "led");
197 sprintf(num, "%d", i);
198 strcat(str_tmp, num);
199
200 /* If env var is not found we stop */
201 ptr_env = getenv(str_tmp);
202 if (NULL == ptr_env)
203 break;
204
205 /* Find sperators position */
206 pos1 = 0;
207 pos2 = 0;
208 ccount = 0;
209 for (idx = 0; ptr_env[idx] != '\0'; idx++) {
210 if (ptr_env[idx] == ',') {
211 if (ccount++ < 1)
212 pos1 = idx;
213 else
214 pos2 = idx;
215 }
216 }
217 /* Bad led description skip this definition */
218 if (pos2 <= pos1 || ccount > 2)
219 continue;
220
221 /* Get pin number and request gpio */
222 memset(str_tmp, 0, sizeof(str_tmp));
223 strncpy(str_tmp, ptr_env, pos1*sizeof(char));
224 gpio_n = (unsigned char)simple_strtoul(str_tmp, NULL, 0);
225
226 /* Invalid gpio number skip definition */
227 if (gpio_n > MAX_PIN_NUMBER)
228 continue;
229
230 gpio_request(gpio_n, "");
231
232 if (state == STARTUP) {
233 /* get pin state 0 and set */
234 memset(str_tmp, 0, sizeof(str_tmp));
235 strncpy(str_tmp, ptr_env+pos1+1,
236 (pos2-pos1-1)*sizeof(char));
237 gpio_s0 = (unsigned char)simple_strtoul(str_tmp, NULL,
238 0);
239
240 gpio_direction_output(gpio_n, gpio_s0);
241
242 } else {
243 /* get pin state 1 and set */
244 memset(str_tmp, 0, sizeof(str_tmp));
245 strcpy(str_tmp, ptr_env+pos2+1);
246 gpio_s1 = (unsigned char)simple_strtoul(str_tmp, NULL,
247 0);
248 gpio_direction_output(gpio_n, gpio_s1);
249 }
250 } /* loop through defined led in environment */
251}
252
253static int do_board_led(cmd_tbl_t *cmdtp, int flag, int argc,
254 char *const argv[])
255{
256 if (argc != 2)
257 return CMD_RET_USAGE;
258 if ((unsigned char)simple_strtoul(argv[1], NULL, 0) == STARTUP)
259 set_env_gpios(0);
260 else
261 set_env_gpios(1);
262 return 0;
263};
264
265U_BOOT_CMD(
266 draco_led, CONFIG_SYS_MAXARGS, 2, do_board_led,
267 "Set LEDs defined in environment",
268 "<0|1>"
269);
Heiko Schocher499c4982013-08-19 16:39:01 +0200270#endif /* !CONFIG_SPL_BUILD */