2 * Board functions for TI AM335X based rut board
3 * (C) Copyright 2013 Siemens Schweiz AG
7 * u-boot:/board/ti/am335x/board.c
9 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
11 * SPDX-License-Identifier: GPL-2.0+
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>
35 #include "../common/factoryset.h"
36 #include "../../../drivers/video/da8xx-fb.h"
38 DECLARE_GLOBAL_DATA_PTR;
41 * Read header information from EEPROM into global structure.
43 static int read_eeprom(void)
48 #ifdef CONFIG_SPL_BUILD
49 static void board_init_ddr(void)
51 struct emif_regs rut_ddr3_emif_reg_data = {
52 .sdram_config = 0x61C04AB2,
53 .sdram_tim1 = 0x0888A39B,
54 .sdram_tim2 = 0x26337FDA,
55 .sdram_tim3 = 0x501F830F,
56 .emif_ddr_phy_ctlr_1 = 0x6,
57 .zq_config = 0x50074BE4,
61 struct ddr_data rut_ddr3_data = {
62 .datardsratio0 = 0x3b,
63 .datawdsratio0 = 0x85,
64 .datafwsratio0 = 0x100,
65 .datawrsratio0 = 0xc1,
66 .datauserank0delay = 1,
67 .datadldiff0 = PHY_DLL_LOCK_DIFF,
70 struct cmd_control rut_ddr3_cmd_ctrl_data = {
82 config_ddr(DDR_PLL_FREQ, RUT_IOCTRL_VAL, &rut_ddr3_data,
83 &rut_ddr3_cmd_ctrl_data, &rut_ddr3_emif_reg_data, 0);
86 static int request_and_pulse_reset(int gpio, const char *name)
89 const int delay_us = 2000; /* 2ms */
91 ret = gpio_request(gpio, name);
93 printf("%s: Unable to request %s\n", __func__, name);
97 ret = gpio_direction_output(gpio, 0);
99 printf("%s: Unable to set %s as output\n", __func__, name);
105 gpio_set_value(gpio, 1);
115 #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
116 #define ETH_PHY_RESET_GPIO GPIO_TO_PIN(2, 18)
117 #define MAXTOUCH_RESET_GPIO GPIO_TO_PIN(3, 18)
118 #define DISPLAY_RESET_GPIO GPIO_TO_PIN(3, 19)
120 #define REQUEST_AND_PULSE_RESET(N) \
121 request_and_pulse_reset(N, #N);
123 static void spl_siemens_board_init(void)
125 REQUEST_AND_PULSE_RESET(ETH_PHY_RESET_GPIO);
126 REQUEST_AND_PULSE_RESET(MAXTOUCH_RESET_GPIO);
127 REQUEST_AND_PULSE_RESET(DISPLAY_RESET_GPIO);
129 #endif /* if def CONFIG_SPL_BUILD */
131 #if defined(CONFIG_DRIVER_TI_CPSW)
132 static void cpsw_control(int enabled)
134 /* VTP can be added here */
139 static struct cpsw_slave_data cpsw_slaves[] = {
141 .slave_reg_ofs = 0x208,
142 .sliver_reg_ofs = 0xd80,
144 .phy_if = PHY_INTERFACE_MODE_RMII,
147 .slave_reg_ofs = 0x308,
148 .sliver_reg_ofs = 0xdc0,
150 .phy_if = PHY_INTERFACE_MODE_RMII,
154 static struct cpsw_platform_data cpsw_data = {
155 .mdio_base = CPSW_MDIO_BASE,
156 .cpsw_base = CPSW_BASE,
159 .cpdma_reg_ofs = 0x800,
161 .slave_data = cpsw_slaves,
162 .ale_reg_ofs = 0xd00,
164 .host_port_reg_ofs = 0x108,
165 .hw_stats_reg_ofs = 0x900,
166 .bd_ram_ofs = 0x2000,
167 .mac_control = (1 << 5),
168 .control = cpsw_control,
170 .version = CPSW_CTRL_VERSION_2,
173 #if defined(CONFIG_DRIVER_TI_CPSW) || \
174 (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
175 int board_eth_init(bd_t *bis)
177 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
181 #ifndef CONFIG_SPL_BUILD
185 /* Set rgmii mode and enable rmii clock to be sourced from chip */
186 writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel);
188 rv = cpsw_register(&cpsw_data);
190 printf("Error %d registering CPSW switch\n", rv);
195 #endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
196 #endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
198 #if defined(CONFIG_HW_WATCHDOG)
199 static bool hw_watchdog_init_done;
200 static int hw_watchdog_trigger_level;
202 void hw_watchdog_reset(void)
204 if (!hw_watchdog_init_done)
207 hw_watchdog_trigger_level = hw_watchdog_trigger_level ? 0 : 1;
208 gpio_set_value(WATCHDOG_TRIGGER_GPIO, hw_watchdog_trigger_level);
211 void hw_watchdog_init(void)
213 gpio_request(WATCHDOG_TRIGGER_GPIO, "watchdog_trigger");
214 gpio_direction_output(WATCHDOG_TRIGGER_GPIO, hw_watchdog_trigger_level);
218 hw_watchdog_init_done = 1;
220 #endif /* defined(CONFIG_HW_WATCHDOG) */
222 #if defined(CONFIG_VIDEO) && !defined(CONFIG_SPL_BUILD)
223 static struct da8xx_panel lcd_panels[] = {
224 /* FORMIKE, 4.3", 480x800, KWH043MC17-F01 */
226 .name = "KWH043MC17-F01",
229 .hfp = 50, /* no spec, "don't care" values */
235 .pxl_clk = 35910000, /* tCYCD=20ns, max 50MHz, 60fps */
238 /* FORMIKE, 4.3", 480x800, KWH043ST20-F01 */
240 .name = "KWH043ST20-F01",
243 .hfp = 50, /* no spec, "don't care" values */
249 .pxl_clk = 35910000, /* tCYCD=20ns, max 50MHz, 60fps */
252 /* Multi-Inno, 4.3", 480x800, MI0430VT-1 */
254 .name = "MI0430VT-1",
257 .hfp = 50, /* no spec, "don't care" values */
263 .pxl_clk = 35910000, /* tCYCD=20ns, max 50MHz, 60fps */
268 static const struct display_panel disp_panels[] = {
289 static const struct lcd_ctrl_config lcd_cfgs[] = {
300 .invert_line_clock = 1,
301 .invert_frm_clock = 1,
316 .invert_line_clock = 1,
317 .invert_frm_clock = 1,
332 .invert_line_clock = 1,
333 .invert_frm_clock = 1,
341 /* no console on this board */
342 int board_cfb_skip(void)
347 #define PLL_GET_M(v) ((v >> 8) & 0x7ff)
348 #define PLL_GET_N(v) (v & 0x7f)
350 static struct dpll_regs dpll_lcd_regs = {
351 .cm_clkmode_dpll = CM_WKUP + 0x98,
352 .cm_idlest_dpll = CM_WKUP + 0x48,
353 .cm_clksel_dpll = CM_WKUP + 0x54,
356 static int get_clk(struct dpll_regs *dpll_regs)
362 val = readl(dpll_regs->cm_clksel_dpll);
365 f = (m * V_OSCK) / n;
372 return get_clk(&dpll_lcd_regs);
375 static int conf_disp_pll(int m, int n)
377 struct cm_perpll *cmper = (struct cm_perpll *)CM_PER;
378 struct dpll_params dpll_lcd = {m, n, -1, -1, -1, -1, -1};
379 #if defined(DISPL_PLL_SPREAD_SPECTRUM)
380 struct cm_wkuppll *cmwkup = (struct cm_wkuppll *)CM_WKUP;
383 u32 *const clk_domains[] = {
387 u32 *const clk_modules_explicit_en[] = {
389 &cmper->lcdcclkstctrl,
393 do_enable_clocks(clk_domains, clk_modules_explicit_en, 1);
395 do_setup_dpll(&dpll_lcd_regs, &dpll_lcd);
397 #if defined(DISPL_PLL_SPREAD_SPECTRUM)
398 writel(0x64, &cmwkup->resv6[3]); /* 0x50 */
399 writel(0x800, &cmwkup->resv6[2]); /* 0x4c */
400 writel(readl(&cmwkup->clkmoddplldisp) | (1 << 12),
401 &cmwkup->clkmoddplldisp); /* 0x98 */
406 static int set_gpio(int gpio, int state)
408 gpio_request(gpio, "temp");
409 gpio_direction_output(gpio, state);
410 gpio_set_value(gpio, state);
415 static int enable_lcd(void)
417 unsigned char buf[1];
419 set_gpio(BOARD_LCD_RESET, 0);
421 set_gpio(BOARD_LCD_RESET, 1);
425 kwh043st20_f01_spi_startup(1, 0, 5000000, SPI_MODE_0);
429 i2c_write(0x24, 0x7, 1, buf, 1);
431 i2c_write(0x24, 0x8, 1, buf, 1);
435 int arch_early_init_r(void)
441 static int board_video_init(void)
444 int anzdisp = ARRAY_SIZE(lcd_panels);
447 for (i = 0; i < anzdisp; i++) {
448 if (strncmp((const char *)factory_dat.disp_name,
450 strlen((const char *)factory_dat.disp_name)) == 0) {
451 printf("DISPLAY: %s\n", factory_dat.disp_name);
457 printf("%s: %s not found, using default %s\n", __func__,
458 factory_dat.disp_name, lcd_panels[i].name);
460 conf_disp_pll(24, 1);
461 da8xx_video_init(&lcd_panels[display], &lcd_cfgs[display],
462 lcd_cfgs[display].bpp);
466 #endif /* ifdef CONFIG_VIDEO */
467 #include "../common/board.c"