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 |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 9 | * Copyright (C) 2011, Texas Instruments, Incorporated - https://www.ti.com/ |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 12 | #include <command.h> |
Simon Glass | 3673618 | 2019-11-14 12:57:24 -0700 | [diff] [blame] | 13 | #include <serial.h> |
Enrico Leto | fce9179 | 2024-01-24 15:43:54 +0100 | [diff] [blame] | 14 | #include <watchdog.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 15 | #include <asm/arch/clock.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 16 | #include <asm/arch/sys_proto.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 17 | #include <asm/gpio.h> |
Simon Glass | 0ffb9d6 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 18 | #include <asm/mach-types.h> |
Enrico Leto | 2e74050 | 2024-01-24 15:43:53 +0100 | [diff] [blame] | 19 | #include "board_am335x.h" |
Enrico Leto | 096bfdc | 2024-01-24 15:43:49 +0100 | [diff] [blame] | 20 | #include "eeprom.h" |
| 21 | #include "factoryset.h" |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Enrico Leto | 32f433f | 2024-01-24 15:43:50 +0100 | [diff] [blame] | 25 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 26 | #ifdef CONFIG_SPL_BUILD |
| 27 | void set_uart_mux_conf(void) |
| 28 | { |
| 29 | enable_uart0_pin_mux(); |
| 30 | } |
| 31 | |
| 32 | void set_mux_conf_regs(void) |
| 33 | { |
| 34 | /* Initalize the board header */ |
| 35 | enable_i2c0_pin_mux(); |
Heiko Schocher | b5e7d37 | 2015-05-28 07:27:36 +0200 | [diff] [blame] | 36 | |
| 37 | /* enable early the console */ |
| 38 | gd->baudrate = CONFIG_BAUDRATE; |
| 39 | serial_init(); |
| 40 | gd->have_console = 1; |
Enrico Leto | 32f433f | 2024-01-24 15:43:50 +0100 | [diff] [blame] | 41 | |
| 42 | siemens_ee_setup(); |
Enrico Leto | 2e74050 | 2024-01-24 15:43:53 +0100 | [diff] [blame] | 43 | if (draco_read_eeprom() < 0) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 44 | puts("Could not get board ID.\n"); |
| 45 | |
| 46 | enable_board_pin_mux(); |
| 47 | } |
| 48 | |
| 49 | void sdram_init(void) |
| 50 | { |
Enrico Leto | 2e74050 | 2024-01-24 15:43:53 +0100 | [diff] [blame] | 51 | spl_draco_board_init(); |
| 52 | draco_init_ddr(); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 53 | |
| 54 | return; |
| 55 | } |
| 56 | #endif /* #ifdef CONFIG_SPL_BUILD */ |
| 57 | |
| 58 | #ifndef CONFIG_SPL_BUILD |
| 59 | /* |
| 60 | * Basic board specific setup. Pinmux has been handled already. |
| 61 | */ |
| 62 | int board_init(void) |
| 63 | { |
| 64 | #if defined(CONFIG_HW_WATCHDOG) |
| 65 | hw_watchdog_init(); |
| 66 | #endif /* defined(CONFIG_HW_WATCHDOG) */ |
Enrico Leto | 32f433f | 2024-01-24 15:43:50 +0100 | [diff] [blame] | 67 | if (siemens_ee_setup() < 0) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 68 | puts("Could not get board ID.\n"); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 69 | #ifdef CONFIG_MACH_TYPE |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 70 | gd->bd->bi_arch_number = CONFIG_MACH_TYPE; |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 71 | #endif |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 72 | gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 73 | |
| 74 | #ifdef CONFIG_FACTORYSET |
Enrico Leto | 096bfdc | 2024-01-24 15:43:49 +0100 | [diff] [blame] | 75 | factoryset_read_eeprom(SIEMENS_EE_I2C_ADDR); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 76 | #endif |
Heiko Schocher | cbec11a | 2016-06-07 08:55:45 +0200 | [diff] [blame] | 77 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 78 | gpmc_init(); |
| 79 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | #endif /* #ifndef CONFIG_SPL_BUILD */ |
| 83 | |
| 84 | #define OSC (V_OSCK/1000000) |
| 85 | const struct dpll_params dpll_ddr = { |
| 86 | DDR_PLL_FREQ, OSC-1, 1, -1, -1, -1, -1}; |
| 87 | |
| 88 | const struct dpll_params *get_dpll_ddr_params(void) |
| 89 | { |
| 90 | return &dpll_ddr; |
| 91 | } |
| 92 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 93 | #ifndef CONFIG_SPL_BUILD |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 94 | |
| 95 | #define MAX_NR_LEDS 10 |
| 96 | #define MAX_PIN_NUMBER 128 |
| 97 | #define STARTUP 0 |
| 98 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 99 | #if defined(BOARD_DFU_BUTTON_GPIO) |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 100 | unsigned char get_button_state(char * const envname, unsigned char def) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 101 | { |
| 102 | int button = 0; |
| 103 | int gpio; |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 104 | char *ptr_env; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 105 | |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 106 | /* If button is not found we take default */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 107 | ptr_env = env_get(envname); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 108 | if (NULL == ptr_env) { |
| 109 | gpio = def; |
| 110 | } else { |
| 111 | gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0); |
| 112 | if (gpio > MAX_PIN_NUMBER) |
| 113 | gpio = def; |
| 114 | } |
| 115 | |
| 116 | gpio_request(gpio, ""); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 117 | gpio_direction_input(gpio); |
| 118 | if (gpio_get_value(gpio)) |
| 119 | button = 1; |
| 120 | else |
| 121 | button = 0; |
| 122 | |
| 123 | gpio_free(gpio); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 124 | |
| 125 | return button; |
| 126 | } |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 127 | /** |
| 128 | * This command returns the status of the user button on |
| 129 | * Input - none |
| 130 | * Returns - 1 if button is held down |
| 131 | * 0 if button is not held down |
Egli, Samuel | fdb5e26 | 2014-04-24 17:57:54 +0200 | [diff] [blame] | 132 | */ |
| 133 | static int |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 134 | 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] | 135 | { |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 136 | int button = 0; |
| 137 | button = get_button_state("button_dfu0", BOARD_DFU_BUTTON_GPIO); |
| 138 | button |= get_button_state("button_dfu1", BOARD_DFU_BUTTON_GPIO); |
| 139 | return button; |
Egli, Samuel | fdb5e26 | 2014-04-24 17:57:54 +0200 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | U_BOOT_CMD( |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 143 | dfubutton, CONFIG_SYS_MAXARGS, 1, do_userbutton, |
| 144 | "Return the status of the DFU button", |
| 145 | "" |
Egli, Samuel | fdb5e26 | 2014-04-24 17:57:54 +0200 | [diff] [blame] | 146 | ); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 147 | #endif |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 148 | |
| 149 | static int |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 150 | 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] | 151 | { |
| 152 | printf("\n\n\n Go into infinite loop\n\n\n"); |
| 153 | while (1) |
| 154 | ; |
| 155 | return 0; |
| 156 | }; |
| 157 | |
| 158 | U_BOOT_CMD( |
| 159 | testwdt, CONFIG_SYS_MAXARGS, 1, do_usertestwdt, |
| 160 | "Sends U-Boot into infinite loop", |
| 161 | "" |
| 162 | ); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 163 | |
| 164 | /** |
| 165 | * Get led gpios from env and set them. |
| 166 | * The led define in environment need to need to be of the form ledN=NN,S0,S1 |
| 167 | * where N is an unsigned integer from 0 to 9 and S0 and S1 is 0 or 1. S0 |
| 168 | * defines the startup state of the led, S1 the special state of the led when |
| 169 | * it enters e.g. dfu mode. |
| 170 | */ |
| 171 | void set_env_gpios(unsigned char state) |
| 172 | { |
| 173 | char *ptr_env; |
| 174 | char str_tmp[5]; /* must contain "ledX"*/ |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 175 | unsigned char i, idx, pos1, pos2, ccount; |
| 176 | unsigned char gpio_n, gpio_s0, gpio_s1; |
| 177 | |
| 178 | for (i = 0; i < MAX_NR_LEDS; i++) { |
Heinrich Schuchardt | 32c63b6 | 2019-08-22 21:58:26 +0200 | [diff] [blame] | 179 | sprintf(str_tmp, "led%d", i); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 180 | |
| 181 | /* If env var is not found we stop */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 182 | ptr_env = env_get(str_tmp); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 183 | if (NULL == ptr_env) |
| 184 | break; |
| 185 | |
| 186 | /* Find sperators position */ |
| 187 | pos1 = 0; |
| 188 | pos2 = 0; |
| 189 | ccount = 0; |
| 190 | for (idx = 0; ptr_env[idx] != '\0'; idx++) { |
| 191 | if (ptr_env[idx] == ',') { |
| 192 | if (ccount++ < 1) |
| 193 | pos1 = idx; |
| 194 | else |
| 195 | pos2 = idx; |
| 196 | } |
| 197 | } |
| 198 | /* Bad led description skip this definition */ |
| 199 | if (pos2 <= pos1 || ccount > 2) |
| 200 | continue; |
| 201 | |
| 202 | /* Get pin number and request gpio */ |
| 203 | memset(str_tmp, 0, sizeof(str_tmp)); |
| 204 | strncpy(str_tmp, ptr_env, pos1*sizeof(char)); |
| 205 | gpio_n = (unsigned char)simple_strtoul(str_tmp, NULL, 0); |
| 206 | |
| 207 | /* Invalid gpio number skip definition */ |
| 208 | if (gpio_n > MAX_PIN_NUMBER) |
| 209 | continue; |
| 210 | |
| 211 | gpio_request(gpio_n, ""); |
| 212 | |
| 213 | if (state == STARTUP) { |
| 214 | /* get pin state 0 and set */ |
| 215 | memset(str_tmp, 0, sizeof(str_tmp)); |
| 216 | strncpy(str_tmp, ptr_env+pos1+1, |
| 217 | (pos2-pos1-1)*sizeof(char)); |
| 218 | gpio_s0 = (unsigned char)simple_strtoul(str_tmp, NULL, |
| 219 | 0); |
| 220 | |
| 221 | gpio_direction_output(gpio_n, gpio_s0); |
| 222 | |
| 223 | } else { |
| 224 | /* get pin state 1 and set */ |
| 225 | memset(str_tmp, 0, sizeof(str_tmp)); |
| 226 | strcpy(str_tmp, ptr_env+pos2+1); |
| 227 | gpio_s1 = (unsigned char)simple_strtoul(str_tmp, NULL, |
| 228 | 0); |
| 229 | gpio_direction_output(gpio_n, gpio_s1); |
| 230 | } |
| 231 | } /* loop through defined led in environment */ |
| 232 | } |
| 233 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 234 | static int do_board_led(struct cmd_tbl *cmdtp, int flag, int argc, |
| 235 | char *const argv[]) |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 236 | { |
| 237 | if (argc != 2) |
| 238 | return CMD_RET_USAGE; |
| 239 | if ((unsigned char)simple_strtoul(argv[1], NULL, 0) == STARTUP) |
| 240 | set_env_gpios(0); |
| 241 | else |
| 242 | set_env_gpios(1); |
| 243 | return 0; |
| 244 | }; |
| 245 | |
| 246 | U_BOOT_CMD( |
| 247 | draco_led, CONFIG_SYS_MAXARGS, 2, do_board_led, |
| 248 | "Set LEDs defined in environment", |
| 249 | "<0|1>" |
| 250 | ); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 251 | #endif /* !CONFIG_SPL_BUILD */ |