Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 2 | /* |
| 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 Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 13 | #include <command.h> |
Simon Glass | 7b51b57 | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 14 | #include <env.h> |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 15 | #include <errno.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 16 | #include <init.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 17 | #include <malloc.h> |
Simon Glass | b03e051 | 2019-11-14 12:57:24 -0700 | [diff] [blame] | 18 | #include <serial.h> |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 19 | #include <spl.h> |
| 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> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 28 | #include <asm/global_data.h> |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 29 | #include <asm/io.h> |
| 30 | #include <asm/emif.h> |
| 31 | #include <asm/gpio.h> |
| 32 | #include <i2c.h> |
| 33 | #include <miiphy.h> |
| 34 | #include <cpsw.h> |
| 35 | #include <watchdog.h> |
Simon Glass | c62db35 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 36 | #include <asm/mach-types.h> |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 37 | #include "../common/factoryset.h" |
| 38 | |
| 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
| 41 | #ifdef CONFIG_SPL_BUILD |
| 42 | void set_uart_mux_conf(void) |
| 43 | { |
| 44 | enable_uart0_pin_mux(); |
| 45 | } |
| 46 | |
| 47 | void set_mux_conf_regs(void) |
| 48 | { |
| 49 | /* Initalize the board header */ |
| 50 | enable_i2c0_pin_mux(); |
Heiko Schocher | 6789e84 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 51 | i2c_set_bus_num(0); |
Heiko Schocher | 012681b | 2015-05-28 07:27:36 +0200 | [diff] [blame] | 52 | |
| 53 | /* enable early the console */ |
| 54 | gd->baudrate = CONFIG_BAUDRATE; |
| 55 | serial_init(); |
| 56 | gd->have_console = 1; |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 57 | if (read_eeprom() < 0) |
| 58 | puts("Could not get board ID.\n"); |
| 59 | |
| 60 | enable_board_pin_mux(); |
| 61 | } |
| 62 | |
| 63 | void sdram_init(void) |
| 64 | { |
| 65 | spl_siemens_board_init(); |
| 66 | board_init_ddr(); |
| 67 | |
| 68 | return; |
| 69 | } |
| 70 | #endif /* #ifdef CONFIG_SPL_BUILD */ |
| 71 | |
| 72 | #ifndef CONFIG_SPL_BUILD |
Tom Rini | 433eb4a | 2021-08-17 17:59:40 -0400 | [diff] [blame] | 73 | #define FACTORYSET_EEPROM_ADDR 0x50 |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 74 | /* |
| 75 | * Basic board specific setup. Pinmux has been handled already. |
| 76 | */ |
| 77 | int board_init(void) |
| 78 | { |
| 79 | #if defined(CONFIG_HW_WATCHDOG) |
| 80 | hw_watchdog_init(); |
| 81 | #endif /* defined(CONFIG_HW_WATCHDOG) */ |
Heiko Schocher | 6789e84 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 82 | i2c_set_bus_num(0); |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 83 | if (read_eeprom() < 0) |
| 84 | puts("Could not get board ID.\n"); |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 85 | #ifdef CONFIG_MACH_TYPE |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 86 | gd->bd->bi_arch_number = CONFIG_MACH_TYPE; |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 87 | #endif |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 88 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 89 | |
| 90 | #ifdef CONFIG_FACTORYSET |
Tom Rini | 433eb4a | 2021-08-17 17:59:40 -0400 | [diff] [blame] | 91 | factoryset_read_eeprom(FACTORYSET_EEPROM_ADDR); |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 92 | #endif |
Heiko Schocher | 6b3943f | 2016-06-07 08:55:45 +0200 | [diff] [blame] | 93 | |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 94 | gpmc_init(); |
| 95 | |
Heiko Schocher | 6b3943f | 2016-06-07 08:55:45 +0200 | [diff] [blame] | 96 | #ifdef CONFIG_NAND_CS_INIT |
| 97 | board_nand_cs_init(); |
| 98 | #endif |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 99 | #ifdef CONFIG_VIDEO |
| 100 | board_video_init(); |
| 101 | #endif |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | #endif /* #ifndef CONFIG_SPL_BUILD */ |
| 106 | |
| 107 | #define OSC (V_OSCK/1000000) |
| 108 | const struct dpll_params dpll_ddr = { |
| 109 | DDR_PLL_FREQ, OSC-1, 1, -1, -1, -1, -1}; |
| 110 | |
| 111 | const struct dpll_params *get_dpll_ddr_params(void) |
| 112 | { |
| 113 | return &dpll_ddr; |
| 114 | } |
| 115 | |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 116 | #ifndef CONFIG_SPL_BUILD |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 117 | |
| 118 | #define MAX_NR_LEDS 10 |
| 119 | #define MAX_PIN_NUMBER 128 |
| 120 | #define STARTUP 0 |
| 121 | |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 122 | #if defined(BOARD_DFU_BUTTON_GPIO) |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 123 | unsigned char get_button_state(char * const envname, unsigned char def) |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 124 | { |
| 125 | int button = 0; |
| 126 | int gpio; |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 127 | char *ptr_env; |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 128 | |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 129 | /* If button is not found we take default */ |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 130 | ptr_env = env_get(envname); |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 131 | if (NULL == ptr_env) { |
| 132 | gpio = def; |
| 133 | } else { |
| 134 | gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0); |
| 135 | if (gpio > MAX_PIN_NUMBER) |
| 136 | gpio = def; |
| 137 | } |
| 138 | |
| 139 | gpio_request(gpio, ""); |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 140 | gpio_direction_input(gpio); |
| 141 | if (gpio_get_value(gpio)) |
| 142 | button = 1; |
| 143 | else |
| 144 | button = 0; |
| 145 | |
| 146 | gpio_free(gpio); |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 147 | |
| 148 | return button; |
| 149 | } |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 150 | /** |
| 151 | * This command returns the status of the user button on |
| 152 | * Input - none |
| 153 | * Returns - 1 if button is held down |
| 154 | * 0 if button is not held down |
| 155 | */ |
| 156 | static int |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 157 | do_userbutton(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 158 | { |
| 159 | int button = 0; |
| 160 | button = get_button_state("button_dfu0", BOARD_DFU_BUTTON_GPIO); |
| 161 | button |= get_button_state("button_dfu1", BOARD_DFU_BUTTON_GPIO); |
| 162 | return button; |
| 163 | } |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 164 | |
| 165 | U_BOOT_CMD( |
| 166 | dfubutton, CONFIG_SYS_MAXARGS, 1, do_userbutton, |
| 167 | "Return the status of the DFU button", |
| 168 | "" |
| 169 | ); |
| 170 | #endif |
| 171 | |
| 172 | static int |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 173 | do_usertestwdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 174 | { |
| 175 | printf("\n\n\n Go into infinite loop\n\n\n"); |
| 176 | while (1) |
| 177 | ; |
| 178 | return 0; |
| 179 | }; |
| 180 | |
| 181 | U_BOOT_CMD( |
| 182 | testwdt, CONFIG_SYS_MAXARGS, 1, do_usertestwdt, |
| 183 | "Sends U-Boot into infinite loop", |
| 184 | "" |
| 185 | ); |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 186 | |
| 187 | /** |
| 188 | * Get led gpios from env and set them. |
| 189 | * The led define in environment need to need to be of the form ledN=NN,S0,S1 |
| 190 | * where N is an unsigned integer from 0 to 9 and S0 and S1 is 0 or 1. S0 |
| 191 | * defines the startup state of the led, S1 the special state of the led when |
| 192 | * it enters e.g. dfu mode. |
| 193 | */ |
| 194 | void set_env_gpios(unsigned char state) |
| 195 | { |
| 196 | char *ptr_env; |
| 197 | char str_tmp[5]; /* must contain "ledX"*/ |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 198 | unsigned char i, idx, pos1, pos2, ccount; |
| 199 | unsigned char gpio_n, gpio_s0, gpio_s1; |
| 200 | |
| 201 | for (i = 0; i < MAX_NR_LEDS; i++) { |
Heinrich Schuchardt | 3c7166d | 2019-08-22 21:58:26 +0200 | [diff] [blame] | 202 | sprintf(str_tmp, "led%d", i); |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 203 | |
| 204 | /* If env var is not found we stop */ |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 205 | ptr_env = env_get(str_tmp); |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 206 | if (NULL == ptr_env) |
| 207 | break; |
| 208 | |
| 209 | /* Find sperators position */ |
| 210 | pos1 = 0; |
| 211 | pos2 = 0; |
| 212 | ccount = 0; |
| 213 | for (idx = 0; ptr_env[idx] != '\0'; idx++) { |
| 214 | if (ptr_env[idx] == ',') { |
| 215 | if (ccount++ < 1) |
| 216 | pos1 = idx; |
| 217 | else |
| 218 | pos2 = idx; |
| 219 | } |
| 220 | } |
| 221 | /* Bad led description skip this definition */ |
| 222 | if (pos2 <= pos1 || ccount > 2) |
| 223 | continue; |
| 224 | |
| 225 | /* Get pin number and request gpio */ |
| 226 | memset(str_tmp, 0, sizeof(str_tmp)); |
| 227 | strncpy(str_tmp, ptr_env, pos1*sizeof(char)); |
| 228 | gpio_n = (unsigned char)simple_strtoul(str_tmp, NULL, 0); |
| 229 | |
| 230 | /* Invalid gpio number skip definition */ |
| 231 | if (gpio_n > MAX_PIN_NUMBER) |
| 232 | continue; |
| 233 | |
| 234 | gpio_request(gpio_n, ""); |
| 235 | |
| 236 | if (state == STARTUP) { |
| 237 | /* get pin state 0 and set */ |
| 238 | memset(str_tmp, 0, sizeof(str_tmp)); |
| 239 | strncpy(str_tmp, ptr_env+pos1+1, |
| 240 | (pos2-pos1-1)*sizeof(char)); |
| 241 | gpio_s0 = (unsigned char)simple_strtoul(str_tmp, NULL, |
| 242 | 0); |
| 243 | |
| 244 | gpio_direction_output(gpio_n, gpio_s0); |
| 245 | |
| 246 | } else { |
| 247 | /* get pin state 1 and set */ |
| 248 | memset(str_tmp, 0, sizeof(str_tmp)); |
| 249 | strcpy(str_tmp, ptr_env+pos2+1); |
| 250 | gpio_s1 = (unsigned char)simple_strtoul(str_tmp, NULL, |
| 251 | 0); |
| 252 | gpio_direction_output(gpio_n, gpio_s1); |
| 253 | } |
| 254 | } /* loop through defined led in environment */ |
| 255 | } |
| 256 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 257 | static int do_board_led(struct cmd_tbl *cmdtp, int flag, int argc, |
| 258 | char *const argv[]) |
Heiko Schocher | 61159b7 | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 259 | { |
| 260 | if (argc != 2) |
| 261 | return CMD_RET_USAGE; |
| 262 | if ((unsigned char)simple_strtoul(argv[1], NULL, 0) == STARTUP) |
| 263 | set_env_gpios(0); |
| 264 | else |
| 265 | set_env_gpios(1); |
| 266 | return 0; |
| 267 | }; |
| 268 | |
| 269 | U_BOOT_CMD( |
| 270 | draco_led, CONFIG_SYS_MAXARGS, 2, do_board_led, |
| 271 | "Set LEDs defined in environment", |
| 272 | "<0|1>" |
| 273 | ); |
Heiko Schocher | c0dcece | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 274 | #endif /* !CONFIG_SPL_BUILD */ |