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