1 // SPDX-License-Identifier: GPL-2.0+
3 * Board functions for TI AM335X based rut board
4 * (C) Copyright 2013 Siemens Schweiz AG
5 * (C) Heiko Schocher, DENX Software Engineering, hs@denx.de.
8 * u-boot:/board/ti/am335x/board.c
10 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
19 #include <asm/arch/cpu.h>
20 #include <asm/arch/hardware.h>
21 #include <asm/arch/omap.h>
22 #include <asm/arch/ddr_defs.h>
23 #include <asm/arch/clock.h>
24 #include <asm/arch/gpio.h>
25 #include <asm/arch/mmc_host_def.h>
26 #include <asm/arch/sys_proto.h>
36 #include "../common/factoryset.h"
37 #include "../../../drivers/video/da8xx-fb.h"
40 * Read header information from EEPROM into global structure.
42 static int read_eeprom(void)
47 #ifdef CONFIG_SPL_BUILD
48 static void board_init_ddr(void)
50 struct emif_regs rut_ddr3_emif_reg_data = {
51 .sdram_config = 0x61C04AB2,
52 .sdram_tim1 = 0x0888A39B,
53 .sdram_tim2 = 0x26337FDA,
54 .sdram_tim3 = 0x501F830F,
55 .emif_ddr_phy_ctlr_1 = 0x6,
56 .zq_config = 0x50074BE4,
60 struct ddr_data rut_ddr3_data = {
61 .datardsratio0 = 0x3b,
62 .datawdsratio0 = 0x85,
63 .datafwsratio0 = 0x100,
64 .datawrsratio0 = 0xc1,
67 struct cmd_control rut_ddr3_cmd_ctrl_data = {
76 const struct ctrl_ioregs ioregs = {
77 .cm0ioctl = RUT_IOCTRL_VAL,
78 .cm1ioctl = RUT_IOCTRL_VAL,
79 .cm2ioctl = RUT_IOCTRL_VAL,
80 .dt0ioctl = RUT_IOCTRL_VAL,
81 .dt1ioctl = RUT_IOCTRL_VAL,
84 config_ddr(DDR_PLL_FREQ, &ioregs, &rut_ddr3_data,
85 &rut_ddr3_cmd_ctrl_data, &rut_ddr3_emif_reg_data, 0);
88 static int request_and_pulse_reset(int gpio, const char *name)
91 const int delay_us = 2000; /* 2ms */
93 ret = gpio_request(gpio, name);
95 printf("%s: Unable to request %s\n", __func__, name);
99 ret = gpio_direction_output(gpio, 0);
101 printf("%s: Unable to set %s as output\n", __func__, name);
107 gpio_set_value(gpio, 1);
117 #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
118 #define ETH_PHY_RESET_GPIO GPIO_TO_PIN(2, 18)
119 #define MAXTOUCH_RESET_GPIO GPIO_TO_PIN(3, 18)
120 #define DISPLAY_RESET_GPIO GPIO_TO_PIN(3, 19)
122 #define REQUEST_AND_PULSE_RESET(N) \
123 request_and_pulse_reset(N, #N);
125 static void spl_siemens_board_init(void)
127 REQUEST_AND_PULSE_RESET(ETH_PHY_RESET_GPIO);
128 REQUEST_AND_PULSE_RESET(MAXTOUCH_RESET_GPIO);
129 REQUEST_AND_PULSE_RESET(DISPLAY_RESET_GPIO);
131 #endif /* if def CONFIG_SPL_BUILD */
133 #if defined(CONFIG_DRIVER_TI_CPSW)
134 static void cpsw_control(int enabled)
136 /* VTP can be added here */
141 static struct cpsw_slave_data cpsw_slaves[] = {
143 .slave_reg_ofs = 0x208,
144 .sliver_reg_ofs = 0xd80,
146 .phy_if = PHY_INTERFACE_MODE_RMII,
149 .slave_reg_ofs = 0x308,
150 .sliver_reg_ofs = 0xdc0,
152 .phy_if = PHY_INTERFACE_MODE_RMII,
156 static struct cpsw_platform_data cpsw_data = {
157 .mdio_base = CPSW_MDIO_BASE,
158 .cpsw_base = CPSW_BASE,
161 .cpdma_reg_ofs = 0x800,
163 .slave_data = cpsw_slaves,
164 .ale_reg_ofs = 0xd00,
166 .host_port_reg_ofs = 0x108,
167 .hw_stats_reg_ofs = 0x900,
168 .bd_ram_ofs = 0x2000,
169 .mac_control = (1 << 5),
170 .control = cpsw_control,
172 .version = CPSW_CTRL_VERSION_2,
175 #if defined(CONFIG_DRIVER_TI_CPSW) || \
176 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
177 int board_eth_init(bd_t *bis)
179 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
183 #ifndef CONFIG_SPL_BUILD
184 factoryset_env_set();
187 /* Set rgmii mode and enable rmii clock to be sourced from chip */
188 writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel);
190 rv = cpsw_register(&cpsw_data);
192 printf("Error %d registering CPSW switch\n", rv);
197 #endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
198 #endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
200 #if defined(CONFIG_HW_WATCHDOG)
201 static bool hw_watchdog_init_done;
202 static int hw_watchdog_trigger_level;
204 void hw_watchdog_reset(void)
206 if (!hw_watchdog_init_done)
209 hw_watchdog_trigger_level = hw_watchdog_trigger_level ? 0 : 1;
210 gpio_set_value(WATCHDOG_TRIGGER_GPIO, hw_watchdog_trigger_level);
213 void hw_watchdog_init(void)
215 gpio_request(WATCHDOG_TRIGGER_GPIO, "watchdog_trigger");
216 gpio_direction_output(WATCHDOG_TRIGGER_GPIO, hw_watchdog_trigger_level);
220 hw_watchdog_init_done = 1;
222 #endif /* defined(CONFIG_HW_WATCHDOG) */
224 #if defined(CONFIG_VIDEO) && !defined(CONFIG_SPL_BUILD)
225 static struct da8xx_panel lcd_panels[] = {
226 /* FORMIKE, 4.3", 480x800, KWH043MC17-F01 */
228 .name = "KWH043MC17-F01",
231 .hfp = 50, /* no spec, "don't care" values */
237 .pxl_clk = 35910000, /* tCYCD=20ns, max 50MHz, 60fps */
240 /* FORMIKE, 4.3", 480x800, KWH043ST20-F01 */
242 .name = "KWH043ST20-F01",
245 .hfp = 50, /* no spec, "don't care" values */
251 .pxl_clk = 35910000, /* tCYCD=20ns, max 50MHz, 60fps */
254 /* Multi-Inno, 4.3", 480x800, MI0430VT-1 */
256 .name = "MI0430VT-1",
259 .hfp = 50, /* no spec, "don't care" values */
265 .pxl_clk = 35910000, /* tCYCD=20ns, max 50MHz, 60fps */
270 static const struct display_panel disp_panels[] = {
291 static const struct lcd_ctrl_config lcd_cfgs[] = {
302 .invert_line_clock = 1,
303 .invert_frm_clock = 1,
318 .invert_line_clock = 1,
319 .invert_frm_clock = 1,
334 .invert_line_clock = 1,
335 .invert_frm_clock = 1,
343 /* no console on this board */
344 int board_cfb_skip(void)
349 #define PLL_GET_M(v) ((v >> 8) & 0x7ff)
350 #define PLL_GET_N(v) (v & 0x7f)
352 static struct dpll_regs dpll_lcd_regs = {
353 .cm_clkmode_dpll = CM_WKUP + 0x98,
354 .cm_idlest_dpll = CM_WKUP + 0x48,
355 .cm_clksel_dpll = CM_WKUP + 0x54,
358 static int get_clk(struct dpll_regs *dpll_regs)
364 val = readl(dpll_regs->cm_clksel_dpll);
367 f = (m * V_OSCK) / n;
374 return get_clk(&dpll_lcd_regs);
377 static int conf_disp_pll(int m, int n)
379 struct cm_perpll *cmper = (struct cm_perpll *)CM_PER;
380 struct dpll_params dpll_lcd = {m, n, -1, -1, -1, -1, -1};
381 #if defined(DISPL_PLL_SPREAD_SPECTRUM)
382 struct cm_wkuppll *cmwkup = (struct cm_wkuppll *)CM_WKUP;
385 u32 *const clk_domains[] = {
389 u32 *const clk_modules_explicit_en[] = {
391 &cmper->lcdcclkstctrl,
395 do_enable_clocks(clk_domains, clk_modules_explicit_en, 1);
397 do_setup_dpll(&dpll_lcd_regs, &dpll_lcd);
399 #if defined(DISPL_PLL_SPREAD_SPECTRUM)
400 writel(0x64, &cmwkup->resv6[3]); /* 0x50 */
401 writel(0x800, &cmwkup->resv6[2]); /* 0x4c */
402 writel(readl(&cmwkup->clkmoddplldisp) | CM_CLKMODE_DPLL_SSC_EN_MASK,
403 &cmwkup->clkmoddplldisp); /* 0x98 */
408 static int set_gpio(int gpio, int state)
410 gpio_request(gpio, "temp");
411 gpio_direction_output(gpio, state);
412 gpio_set_value(gpio, state);
417 static int enable_lcd(void)
419 unsigned char buf[1];
421 set_gpio(BOARD_LCD_RESET, 0);
423 set_gpio(BOARD_LCD_RESET, 1);
427 kwh043st20_f01_spi_startup(1, 0, 5000000, SPI_MODE_0);
431 i2c_write(0x24, 0x7, 1, buf, 1);
433 i2c_write(0x24, 0x8, 1, buf, 1);
437 int arch_early_init_r(void)
443 static int board_video_init(void)
446 int anzdisp = ARRAY_SIZE(lcd_panels);
449 for (i = 0; i < anzdisp; i++) {
450 if (strncmp((const char *)factory_dat.disp_name,
452 strlen((const char *)factory_dat.disp_name)) == 0) {
453 printf("DISPLAY: %s\n", factory_dat.disp_name);
459 printf("%s: %s not found, using default %s\n", __func__,
460 factory_dat.disp_name, lcd_panels[i].name);
462 conf_disp_pll(24, 1);
463 da8xx_video_init(&lcd_panels[display], &lcd_cfgs[display],
464 lcd_cfgs[display].bpp);
468 #endif /* ifdef CONFIG_VIDEO */
470 #ifdef CONFIG_BOARD_LATE_INIT
471 int board_late_init(void)
474 char tmp[2 * MAX_STRING_LENGTH + 2];
476 omap_nand_switch_ecc(1, 8);
478 if (factory_dat.asn[0] != 0)
479 sprintf(tmp, "%s_%s", factory_dat.asn,
480 factory_dat.comp_version);
482 strcpy(tmp, "QMX7.E38_4.0");
484 ret = env_set("boardid", tmp);
486 printf("error setting board id\n");
492 #include "../common/board.c"