]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - board/siemens/common/board.c
am33xx, spl, siemens: enable debug uart output again
[karo-tx-uboot.git] / board / siemens / common / board.c
1 /*
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
33 DECLARE_GLOBAL_DATA_PTR;
34
35 #ifdef CONFIG_SPL_BUILD
36 void set_uart_mux_conf(void)
37 {
38         enable_uart0_pin_mux();
39 }
40
41 void set_mux_conf_regs(void)
42 {
43         /* Initalize the board header */
44         enable_i2c0_pin_mux();
45         i2c_set_bus_num(0);
46
47         /* enable early the console */
48         gd->baudrate = CONFIG_BAUDRATE;
49         serial_init();
50         gd->have_console = 1;
51         if (read_eeprom() < 0)
52                 puts("Could not get board ID.\n");
53
54         enable_board_pin_mux();
55 }
56
57 void 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  */
70 int board_init(void)
71 {
72 #if defined(CONFIG_HW_WATCHDOG)
73         hw_watchdog_init();
74 #endif /* defined(CONFIG_HW_WATCHDOG) */
75         i2c_set_bus_num(0);
76         if (read_eeprom() < 0)
77                 puts("Could not get board ID.\n");
78
79         gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
80         gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
81
82 #ifdef CONFIG_FACTORYSET
83         factoryset_read_eeprom(CONFIG_SYS_I2C_EEPROM_ADDR);
84 #endif
85         gpmc_init();
86
87 #ifdef CONFIG_VIDEO
88         board_video_init();
89 #endif
90
91         return 0;
92 }
93 #endif /* #ifndef CONFIG_SPL_BUILD */
94
95 #define OSC     (V_OSCK/1000000)
96 const struct dpll_params dpll_ddr = {
97                 DDR_PLL_FREQ, OSC-1, 1, -1, -1, -1, -1};
98
99 const struct dpll_params *get_dpll_ddr_params(void)
100 {
101         return &dpll_ddr;
102 }
103
104 #ifndef CONFIG_SPL_BUILD
105 #if defined(BOARD_DFU_BUTTON_GPIO)
106 /*
107  * This command returns the status of the user button on
108  * Input - none
109  * Returns -    1 if button is held down
110  *              0 if button is not held down
111  */
112 static int
113 do_userbutton(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
114 {
115         int button = 0;
116         int gpio;
117
118         gpio = BOARD_DFU_BUTTON_GPIO;
119         gpio_request(gpio, "DFU");
120         gpio_direction_input(gpio);
121         if (gpio_get_value(gpio))
122                 button = 1;
123         else
124                 button = 0;
125
126         gpio_free(gpio);
127
128         return button;
129 }
130
131 U_BOOT_CMD(
132         dfubutton, CONFIG_SYS_MAXARGS, 1, do_userbutton,
133         "Return the status of the DFU button",
134         ""
135 );
136 #endif
137 /*
138  * This command sets led
139  * Input -      name of led
140  *              value of led
141  * Returns -    1 if input does not match
142  *              0 if led was set
143  */
144 static int
145 do_setled(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
146 {
147         int gpio = 0;
148         if (argc != 3)
149                 goto exit;
150 #if defined(BOARD_STATUS_LED)
151         if (!strcmp(argv[1], "stat"))
152                 gpio = BOARD_STATUS_LED;
153 #endif
154 #if defined(BOARD_DFU_BUTTON_LED)
155         if (!strcmp(argv[1], "dfu"))
156                 gpio = BOARD_DFU_BUTTON_LED;
157 #endif
158         /* If argument does not mach exit */
159         if (gpio == 0)
160                 goto exit;
161         gpio_request(gpio, "");
162         gpio_direction_output(gpio, 1);
163         if (!strcmp(argv[2], "1"))
164                 gpio_set_value(gpio, 1);
165         else
166                 gpio_set_value(gpio, 0);
167         return 0;
168 exit:
169         return 1;
170 }
171
172 U_BOOT_CMD(
173         led, CONFIG_SYS_MAXARGS, 2, do_setled,
174         "Set led on or off",
175         "dfu val - set dfu led\nled stat val - set status led"
176 );
177
178 static int
179 do_usertestwdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
180 {
181         printf("\n\n\n Go into infinite loop\n\n\n");
182         while (1)
183                 ;
184         return 0;
185 };
186
187 U_BOOT_CMD(
188         testwdt, CONFIG_SYS_MAXARGS, 1, do_usertestwdt,
189         "Sends U-Boot into infinite loop",
190         ""
191 );
192 #endif /* !CONFIG_SPL_BUILD */