Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | 499c498 | 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 | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 13 | #include <env.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 14 | #include <errno.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 15 | #include <malloc.h> |
Simon Glass | 3673618 | 2019-11-14 12:57:24 -0700 | [diff] [blame] | 16 | #include <serial.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 17 | #include <spl.h> |
| 18 | #include <asm/arch/cpu.h> |
| 19 | #include <asm/arch/hardware.h> |
| 20 | #include <asm/arch/omap.h> |
| 21 | #include <asm/arch/ddr_defs.h> |
| 22 | #include <asm/arch/clock.h> |
| 23 | #include <asm/arch/gpio.h> |
| 24 | #include <asm/arch/mmc_host_def.h> |
| 25 | #include <asm/arch/sys_proto.h> |
| 26 | #include <asm/io.h> |
| 27 | #include <asm/emif.h> |
| 28 | #include <asm/gpio.h> |
| 29 | #include <i2c.h> |
| 30 | #include <miiphy.h> |
| 31 | #include <cpsw.h> |
| 32 | #include <watchdog.h> |
Simon Glass | 0ffb9d6 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 33 | #include <asm/mach-types.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 34 | #include "../common/factoryset.h" |
| 35 | |
| 36 | DECLARE_GLOBAL_DATA_PTR; |
| 37 | |
| 38 | #ifdef CONFIG_SPL_BUILD |
| 39 | void set_uart_mux_conf(void) |
| 40 | { |
| 41 | enable_uart0_pin_mux(); |
| 42 | } |
| 43 | |
| 44 | void set_mux_conf_regs(void) |
| 45 | { |
| 46 | /* Initalize the board header */ |
| 47 | enable_i2c0_pin_mux(); |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 48 | i2c_set_bus_num(0); |
Heiko Schocher | b5e7d37 | 2015-05-28 07:27:36 +0200 | [diff] [blame] | 49 | |
| 50 | /* enable early the console */ |
| 51 | gd->baudrate = CONFIG_BAUDRATE; |
| 52 | serial_init(); |
| 53 | gd->have_console = 1; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 54 | if (read_eeprom() < 0) |
| 55 | puts("Could not get board ID.\n"); |
| 56 | |
| 57 | enable_board_pin_mux(); |
| 58 | } |
| 59 | |
| 60 | void sdram_init(void) |
| 61 | { |
| 62 | spl_siemens_board_init(); |
| 63 | board_init_ddr(); |
| 64 | |
| 65 | return; |
| 66 | } |
| 67 | #endif /* #ifdef CONFIG_SPL_BUILD */ |
| 68 | |
| 69 | #ifndef CONFIG_SPL_BUILD |
| 70 | /* |
| 71 | * Basic board specific setup. Pinmux has been handled already. |
| 72 | */ |
| 73 | int board_init(void) |
| 74 | { |
| 75 | #if defined(CONFIG_HW_WATCHDOG) |
| 76 | hw_watchdog_init(); |
| 77 | #endif /* defined(CONFIG_HW_WATCHDOG) */ |
Heiko Schocher | f53f2b8 | 2013-10-22 11:03:18 +0200 | [diff] [blame] | 78 | i2c_set_bus_num(0); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 79 | if (read_eeprom() < 0) |
| 80 | puts("Could not get board ID.\n"); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 81 | #ifdef CONFIG_MACH_TYPE |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 82 | gd->bd->bi_arch_number = CONFIG_MACH_TYPE; |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 83 | #endif |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 84 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 85 | |
| 86 | #ifdef CONFIG_FACTORYSET |
| 87 | factoryset_read_eeprom(CONFIG_SYS_I2C_EEPROM_ADDR); |
| 88 | #endif |
Heiko Schocher | cbec11a | 2016-06-07 08:55:45 +0200 | [diff] [blame] | 89 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 90 | gpmc_init(); |
| 91 | |
Heiko Schocher | cbec11a | 2016-06-07 08:55:45 +0200 | [diff] [blame] | 92 | #ifdef CONFIG_NAND_CS_INIT |
| 93 | board_nand_cs_init(); |
| 94 | #endif |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 95 | #ifdef CONFIG_VIDEO |
| 96 | board_video_init(); |
| 97 | #endif |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | #endif /* #ifndef CONFIG_SPL_BUILD */ |
| 102 | |
| 103 | #define OSC (V_OSCK/1000000) |
| 104 | const struct dpll_params dpll_ddr = { |
| 105 | DDR_PLL_FREQ, OSC-1, 1, -1, -1, -1, -1}; |
| 106 | |
| 107 | const struct dpll_params *get_dpll_ddr_params(void) |
| 108 | { |
| 109 | return &dpll_ddr; |
| 110 | } |
| 111 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 112 | #ifndef CONFIG_SPL_BUILD |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 113 | |
| 114 | #define MAX_NR_LEDS 10 |
| 115 | #define MAX_PIN_NUMBER 128 |
| 116 | #define STARTUP 0 |
| 117 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 118 | #if defined(BOARD_DFU_BUTTON_GPIO) |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 119 | unsigned char get_button_state(char * const envname, unsigned char def) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 120 | { |
| 121 | int button = 0; |
| 122 | int gpio; |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 123 | char *ptr_env; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 124 | |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 125 | /* If button is not found we take default */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 126 | ptr_env = env_get(envname); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 127 | if (NULL == ptr_env) { |
| 128 | gpio = def; |
| 129 | } else { |
| 130 | gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0); |
| 131 | if (gpio > MAX_PIN_NUMBER) |
| 132 | gpio = def; |
| 133 | } |
| 134 | |
| 135 | gpio_request(gpio, ""); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 136 | gpio_direction_input(gpio); |
| 137 | if (gpio_get_value(gpio)) |
| 138 | button = 1; |
| 139 | else |
| 140 | button = 0; |
| 141 | |
| 142 | gpio_free(gpio); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 143 | |
| 144 | return button; |
| 145 | } |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 146 | /** |
| 147 | * This command returns the status of the user button on |
| 148 | * Input - none |
| 149 | * Returns - 1 if button is held down |
| 150 | * 0 if button is not held down |
Egli, Samuel | fdb5e26 | 2014-04-24 17:57:54 +0200 | [diff] [blame] | 151 | */ |
| 152 | static int |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 153 | do_userbutton(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Egli, Samuel | fdb5e26 | 2014-04-24 17:57:54 +0200 | [diff] [blame] | 154 | { |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 155 | int button = 0; |
| 156 | button = get_button_state("button_dfu0", BOARD_DFU_BUTTON_GPIO); |
| 157 | button |= get_button_state("button_dfu1", BOARD_DFU_BUTTON_GPIO); |
| 158 | return button; |
Egli, Samuel | fdb5e26 | 2014-04-24 17:57:54 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | U_BOOT_CMD( |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 162 | dfubutton, CONFIG_SYS_MAXARGS, 1, do_userbutton, |
| 163 | "Return the status of the DFU button", |
| 164 | "" |
Egli, Samuel | fdb5e26 | 2014-04-24 17:57:54 +0200 | [diff] [blame] | 165 | ); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 166 | #endif |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 167 | |
| 168 | static int |
| 169 | do_usertestwdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 170 | { |
| 171 | printf("\n\n\n Go into infinite loop\n\n\n"); |
| 172 | while (1) |
| 173 | ; |
| 174 | return 0; |
| 175 | }; |
| 176 | |
| 177 | U_BOOT_CMD( |
| 178 | testwdt, CONFIG_SYS_MAXARGS, 1, do_usertestwdt, |
| 179 | "Sends U-Boot into infinite loop", |
| 180 | "" |
| 181 | ); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 182 | |
| 183 | /** |
| 184 | * Get led gpios from env and set them. |
| 185 | * The led define in environment need to need to be of the form ledN=NN,S0,S1 |
| 186 | * where N is an unsigned integer from 0 to 9 and S0 and S1 is 0 or 1. S0 |
| 187 | * defines the startup state of the led, S1 the special state of the led when |
| 188 | * it enters e.g. dfu mode. |
| 189 | */ |
| 190 | void set_env_gpios(unsigned char state) |
| 191 | { |
| 192 | char *ptr_env; |
| 193 | char str_tmp[5]; /* must contain "ledX"*/ |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 194 | unsigned char i, idx, pos1, pos2, ccount; |
| 195 | unsigned char gpio_n, gpio_s0, gpio_s1; |
| 196 | |
| 197 | for (i = 0; i < MAX_NR_LEDS; i++) { |
Heinrich Schuchardt | 32c63b6 | 2019-08-22 21:58:26 +0200 | [diff] [blame] | 198 | sprintf(str_tmp, "led%d", i); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 199 | |
| 200 | /* If env var is not found we stop */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 201 | ptr_env = env_get(str_tmp); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 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 | |
| 253 | static 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 | |
| 265 | U_BOOT_CMD( |
| 266 | draco_led, CONFIG_SYS_MAXARGS, 2, do_board_led, |
| 267 | "Set LEDs defined in environment", |
| 268 | "<0|1>" |
| 269 | ); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 270 | #endif /* !CONFIG_SPL_BUILD */ |