1 // SPDX-License-Identifier: GPL-2.0+
6 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
9 * Board functions for TI AM335X based boards
11 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
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>
28 #include <asm/arch/mem.h>
35 #include <power/tps65217.h>
36 #include <env_internal.h>
41 DECLARE_GLOBAL_DATA_PTR;
43 static struct shc_eeprom __attribute__((section(".data"))) header;
44 static int shc_eeprom_valid;
47 * Read header information from EEPROM into global structure.
49 static int read_eeprom(void)
51 /* Check if baseboard eeprom is available */
52 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
53 puts("Could not probe the EEPROM; something fundamentally wrong on the I2C bus.\n");
57 /* read the eeprom using i2c */
58 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
60 puts("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\n");
64 if (header.magic != HDR_MAGIC) {
65 printf("Incorrect magic number (0x%x) in EEPROM\n",
75 static void shc_request_gpio(void)
77 gpio_request(LED_PWR_BL_GPIO, "LED PWR BL");
78 gpio_request(LED_PWR_RD_GPIO, "LED PWR RD");
79 gpio_request(RESET_GPIO, "reset");
80 gpio_request(WIFI_REGEN_GPIO, "WIFI REGEN");
81 gpio_request(WIFI_RST_GPIO, "WIFI rst");
82 gpio_request(ZIGBEE_RST_GPIO, "ZigBee rst");
83 gpio_request(BIDCOS_RST_GPIO, "BIDCOS rst");
84 gpio_request(ENOC_RST_GPIO, "ENOC rst");
85 #if defined CONFIG_B_SAMPLE
86 gpio_request(LED_PWR_GN_GPIO, "LED PWR GN");
87 gpio_request(LED_CONN_BL_GPIO, "LED CONN BL");
88 gpio_request(LED_CONN_RD_GPIO, "LED CONN RD");
89 gpio_request(LED_CONN_GN_GPIO, "LED CONN GN");
91 gpio_request(LED_LAN_BL_GPIO, "LED LAN BL");
92 gpio_request(LED_LAN_RD_GPIO, "LED LAN RD");
93 gpio_request(LED_CLOUD_BL_GPIO, "LED CLOUD BL");
94 gpio_request(LED_CLOUD_RD_GPIO, "LED CLOUD RD");
95 gpio_request(LED_PWM_GPIO, "LED PWM");
96 gpio_request(Z_WAVE_RST_GPIO, "Z WAVE rst");
98 gpio_request(BACK_BUTTON_GPIO, "Back button");
99 gpio_request(FRONT_BUTTON_GPIO, "Front button");
103 * Function which forces all installed modules into running state for ICT
104 * testing. Called by SPL.
106 static void __maybe_unused force_modules_running(void)
108 /* Wi-Fi power regulator enable - high = enabled */
109 gpio_direction_output(WIFI_REGEN_GPIO, 1);
111 * Wait for Wi-Fi power regulator to reach a stable voltage
112 * (soft-start time, max. 350 µs)
116 /* Wi-Fi module reset - high = running */
117 gpio_direction_output(WIFI_RST_GPIO, 1);
119 /* ZigBee reset - high = running */
120 gpio_direction_output(ZIGBEE_RST_GPIO, 1);
122 /* BidCos reset - high = running */
123 gpio_direction_output(BIDCOS_RST_GPIO, 1);
125 #if !defined(CONFIG_B_SAMPLE)
126 /* Z-Wave reset - high = running */
127 gpio_direction_output(Z_WAVE_RST_GPIO, 1);
130 /* EnOcean reset - low = running */
131 gpio_direction_output(ENOC_RST_GPIO, 0);
135 * Function which forces all installed modules into reset - to be released by
136 * the OS, called by SPL
138 static void __maybe_unused force_modules_reset(void)
140 /* Wi-Fi module reset - low = reset */
141 gpio_direction_output(WIFI_RST_GPIO, 0);
143 /* Wi-Fi power regulator enable - low = disabled */
144 gpio_direction_output(WIFI_REGEN_GPIO, 0);
146 /* ZigBee reset - low = reset */
147 gpio_direction_output(ZIGBEE_RST_GPIO, 0);
149 /* BidCos reset - low = reset */
150 /*gpio_direction_output(BIDCOS_RST_GPIO, 0);*/
152 #if !defined(CONFIG_B_SAMPLE)
153 /* Z-Wave reset - low = reset */
154 gpio_direction_output(Z_WAVE_RST_GPIO, 0);
157 /* EnOcean reset - high = reset*/
158 gpio_direction_output(ENOC_RST_GPIO, 1);
162 * Function to set the LEDs in the state "Bootloader booting"
164 static void __maybe_unused leds_set_booting(void)
166 #if defined(CONFIG_B_SAMPLE)
168 /* Turn all red LEDs on */
169 gpio_direction_output(LED_PWR_RD_GPIO, 1);
170 gpio_direction_output(LED_CONN_RD_GPIO, 1);
172 #else /* All other SHCs starting with B2-Sample */
173 /* Set the PWM GPIO */
174 gpio_direction_output(LED_PWM_GPIO, 1);
175 /* Turn all red LEDs on */
176 gpio_direction_output(LED_PWR_RD_GPIO, 1);
177 gpio_direction_output(LED_LAN_RD_GPIO, 1);
178 gpio_direction_output(LED_CLOUD_RD_GPIO, 1);
184 * Function to set the LEDs in the state "Bootloader error"
186 static void leds_set_failure(int state)
188 #if defined(CONFIG_B_SAMPLE)
189 /* Turn all blue and green LEDs off */
190 gpio_set_value(LED_PWR_BL_GPIO, 0);
191 gpio_set_value(LED_PWR_GN_GPIO, 0);
192 gpio_set_value(LED_CONN_BL_GPIO, 0);
193 gpio_set_value(LED_CONN_GN_GPIO, 0);
195 /* Turn all red LEDs to 'state' */
196 gpio_set_value(LED_PWR_RD_GPIO, state);
197 gpio_set_value(LED_CONN_RD_GPIO, state);
199 #else /* All other SHCs starting with B2-Sample */
200 /* Set the PWM GPIO */
201 gpio_direction_output(LED_PWM_GPIO, 1);
203 /* Turn all blue LEDs off */
204 gpio_set_value(LED_PWR_BL_GPIO, 0);
205 gpio_set_value(LED_LAN_BL_GPIO, 0);
206 gpio_set_value(LED_CLOUD_BL_GPIO, 0);
208 /* Turn all red LEDs to 'state' */
209 gpio_set_value(LED_PWR_RD_GPIO, state);
210 gpio_set_value(LED_LAN_RD_GPIO, state);
211 gpio_set_value(LED_CLOUD_RD_GPIO, state);
216 * Function to set the LEDs in the state "Bootloader finished"
218 static void leds_set_finish(void)
220 #if defined(CONFIG_B_SAMPLE)
221 /* Turn all LEDs off */
222 gpio_set_value(LED_PWR_BL_GPIO, 0);
223 gpio_set_value(LED_PWR_RD_GPIO, 0);
224 gpio_set_value(LED_PWR_GN_GPIO, 0);
225 gpio_set_value(LED_CONN_BL_GPIO, 0);
226 gpio_set_value(LED_CONN_RD_GPIO, 0);
227 gpio_set_value(LED_CONN_GN_GPIO, 0);
228 #else /* All other SHCs starting with B2-Sample */
229 /* Turn all LEDs off */
230 gpio_set_value(LED_PWR_BL_GPIO, 0);
231 gpio_set_value(LED_PWR_RD_GPIO, 0);
232 gpio_set_value(LED_LAN_BL_GPIO, 0);
233 gpio_set_value(LED_LAN_RD_GPIO, 0);
234 gpio_set_value(LED_CLOUD_BL_GPIO, 0);
235 gpio_set_value(LED_CLOUD_RD_GPIO, 0);
237 /* Turn off the PWM GPIO and mux it to EHRPWM */
238 gpio_set_value(LED_PWM_GPIO, 0);
239 enable_shc_board_pwm_pin_mux();
243 static void check_button_status(void)
246 gpio_direction_input(FRONT_BUTTON_GPIO);
247 value = gpio_get_value(FRONT_BUTTON_GPIO);
250 printf("front button activated !\n");
251 env_set("harakiri", "1");
255 #if defined(CONFIG_SPL_BUILD)
256 #ifdef CONFIG_SPL_OS_BOOT
257 int spl_start_uboot(void)
263 static void shc_board_early_init(void)
266 # ifdef CONFIG_SHC_ICT
267 /* Force all modules into enabled state for ICT testing */
268 force_modules_running();
270 /* Force all modules to enter Reset state until released by the OS */
271 force_modules_reset();
276 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
278 #define MPU_SPREADING_PERMILLE 18 /* Spread 1.8 percent */
279 #define OSC (V_OSCK/1000000)
280 /* Bosch: Predivider must be fixed to 4, so N = 4-1 */
281 #define MPUPLL_N (4-1)
282 /* Bosch: Fref = 24 MHz / (N+1) = 24 MHz / 4 = 6 MHz */
283 #define MPUPLL_FREF (OSC / (MPUPLL_N + 1))
285 const struct dpll_params dpll_ddr_shc = {
286 400, OSC-1, 1, -1, -1, -1, -1};
288 const struct dpll_params *get_dpll_ddr_params(void)
290 return &dpll_ddr_shc;
294 * As we enabled downspread SSC with 1.8%, the values needed to be corrected
295 * such that the 20% overshoot will not lead to too high frequencies.
296 * In all cases, this is achieved by subtracting one from M (6 MHz less).
297 * Example: 600 MHz CPU
298 * Step size: 24 MHz OSC, N = 4 (fix) --> Fref = 6 MHz
299 * 600 MHz - 6 MHz (1x Fref) = 594 MHz
300 * SSC: 594 MHz * 1.8% = 10.7 MHz SSC
301 * Overshoot: 10.7 MHz * 20 % = 2.2 MHz
302 * --> Fmax = 594 MHz + 2.2 MHz = 596.2 MHz, lower than 600 MHz --> OK!
304 const struct dpll_params dpll_mpu_shc_opp100 = {
305 99, MPUPLL_N, 1, -1, -1, -1, -1};
307 void am33xx_spl_board_init(void)
315 * Set CORE Frequency to OPP100
316 * Hint: DCDC3 (CORE) defaults to 1.100V (for OPP100)
318 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
320 sil_rev = readl(&cdev->deviceid) >> 28;
322 puts("We do not support Silicon Revisions below 2.0!\n");
326 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
327 if (i2c_probe(TPS65217_CHIP_PM))
331 * Retrieve the CPU max frequency by reading the efuse
332 * SHC-Default: 600 MHz
334 switch (dpll_mpu_opp100.m) {
336 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
339 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
342 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1200MV;
345 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1100MV;
348 mpu_vdd = TPS65217_DCDC_VOLT_SEL_950MV;
351 puts("Cannot determine the frequency, failing!\n");
355 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
356 puts("tps65217_voltage_update failure\n");
360 /* Set MPU Frequency to what we detected */
361 printf("MPU reference clock runs at %d MHz\n", MPUPLL_FREF);
362 printf("Setting MPU clock to %d MHz\n", MPUPLL_FREF *
363 dpll_mpu_shc_opp100.m);
364 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_shc_opp100);
366 /* Enable Spread Spectrum for this freq to be clean on EMI side */
367 set_mpu_spreadspectrum(MPU_SPREADING_PERMILLE);
370 * Using the default voltages for the PMIC (TPS65217D)
371 * LS1 = 1.8V (VDD_1V8)
372 * LS2 = 3.3V (VDD_3V3A)
373 * LDO1 = 1.8V (VIO and VRTC)
374 * LDO2 = 3.3V (VDD_3V3AUX)
376 shc_board_early_init();
379 void set_uart_mux_conf(void)
381 enable_uart0_pin_mux();
384 void set_mux_conf_regs(void)
386 enable_shc_board_pin_mux();
389 const struct ctrl_ioregs ioregs_evmsk = {
390 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
391 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
392 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
393 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
394 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
397 static const struct ddr_data ddr3_shc_data = {
398 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
399 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
400 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
401 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
404 static const struct cmd_control ddr3_shc_cmd_ctrl_data = {
405 .cmd0csratio = MT41K256M16HA125E_RATIO,
406 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
408 .cmd1csratio = MT41K256M16HA125E_RATIO,
409 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
411 .cmd2csratio = MT41K256M16HA125E_RATIO,
412 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
415 static struct emif_regs ddr3_shc_emif_reg_data = {
416 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
417 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
418 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
419 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
420 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
421 .zq_config = MT41K256M16HA125E_ZQ_CFG,
422 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY |
426 void sdram_init(void)
428 /* Configure the DDR3 RAM */
429 config_ddr(400, &ioregs_evmsk, &ddr3_shc_data,
430 &ddr3_shc_cmd_ctrl_data, &ddr3_shc_emif_reg_data, 0);
435 * Basic board specific setup. Pinmux has been handled already.
439 #if defined(CONFIG_HW_WATCHDOG)
442 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
443 if (read_eeprom() < 0)
444 puts("EEPROM Content Invalid.\n");
446 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
447 #if defined(CONFIG_NOR) || defined(CONFIG_NAND)
455 #ifdef CONFIG_BOARD_LATE_INIT
456 int board_late_init(void)
458 check_button_status();
459 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
460 if (shc_eeprom_valid)
461 if (is_valid_ethaddr(header.mac_addr))
462 eth_env_set_enetaddr("ethaddr", header.mac_addr);
469 #if defined(CONFIG_USB_ETHER) && \
470 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USB_ETHER))
471 int board_eth_init(bd_t *bis)
473 return usb_eth_initialize(bis);
477 #ifdef CONFIG_SHOW_BOOT_PROGRESS
478 static void bosch_check_reset_pin(void)
480 if (readl(GPIO1_BASE + OMAP_GPIO_IRQSTATUS_SET_0) & RESET_MASK) {
481 printf("Resetting ...\n");
482 writel(RESET_MASK, GPIO1_BASE + OMAP_GPIO_IRQSTATUS_SET_0);
483 disable_interrupts();
489 static void hang_bosch(const char *cause, int code)
493 gpio_direction_input(RESET_GPIO);
495 /* Enable reset pin interrupt on falling edge */
496 writel(RESET_MASK, GPIO1_BASE + OMAP_GPIO_IRQSTATUS_SET_0);
497 writel(RESET_MASK, GPIO1_BASE + OMAP_GPIO_FALLINGDETECT);
502 for (lv = 0; lv < code; lv++) {
503 bosch_check_reset_pin();
505 __udelay(150 * 1000);
507 __udelay(150 * 1000);
509 #if defined(BLINK_CODE)
510 __udelay(300 * 1000);
515 void show_boot_progress(int val)
518 case BOOTSTAGE_ID_NEED_RESET:
519 hang_bosch("need reset", 4);
524 void arch_preboot_os(void)