1 // SPDX-License-Identifier: GPL-2.0+
3 * Board functions for TI AM335X based pxm2 board
4 * (C) Copyright 2013 Siemens Schweiz AG
8 * u-boot:/board/ti/am335x/board.c
10 * Board functions for TI AM335X based boards
12 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
22 #include <asm/arch/cpu.h>
23 #include <asm/arch/hardware.h>
24 #include <asm/arch/omap.h>
25 #include <asm/arch/ddr_defs.h>
26 #include <asm/arch/clock.h>
27 #include <asm/arch/gpio.h>
28 #include <asm/arch/mmc_host_def.h>
29 #include <asm/arch/sys_proto.h>
30 #include "../../../drivers/video/da8xx-fb.h"
39 #include "../common/factoryset.h"
42 #include <bmp_layout.h>
44 #ifdef CONFIG_SPL_BUILD
45 static void board_init_ddr(void)
47 struct emif_regs pxm2_ddr3_emif_reg_data = {
48 .sdram_config = 0x41805332,
49 .sdram_tim1 = 0x666b3c9,
50 .sdram_tim2 = 0x243631ca,
52 .emif_ddr_phy_ctlr_1 = 0x100005,
57 struct ddr_data pxm2_ddr3_data = {
58 .datardsratio0 = 0x81204812,
60 .datafwsratio0 = 0x8020080,
61 .datawrsratio0 = 0x4010040,
64 struct cmd_control pxm2_ddr3_cmd_ctrl_data = {
73 const struct ctrl_ioregs ioregs = {
74 .cm0ioctl = DDR_IOCTRL_VAL,
75 .cm1ioctl = DDR_IOCTRL_VAL,
76 .cm2ioctl = DDR_IOCTRL_VAL,
77 .dt0ioctl = DDR_IOCTRL_VAL,
78 .dt1ioctl = DDR_IOCTRL_VAL,
81 config_ddr(DDR_PLL_FREQ, &ioregs, &pxm2_ddr3_data,
82 &pxm2_ddr3_cmd_ctrl_data, &pxm2_ddr3_emif_reg_data, 0);
86 * voltage switching for MPU frequency switching.
87 * @module = mpu - 0, core - 1
88 * @vddx_op_vol_sel = vdd voltage to set
94 int voltage_update(unsigned int module, unsigned char vddx_op_vol_sel)
97 unsigned int reg_offset;
100 reg_offset = PMIC_VDD1_OP_REG;
102 reg_offset = PMIC_VDD2_OP_REG;
105 if (i2c_read(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
108 buf[0] &= ~PMIC_OP_REG_CMD_MASK;
110 if (i2c_write(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
113 /* Configure VDDx OP Voltage */
114 if (i2c_read(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
117 buf[0] &= ~PMIC_OP_REG_SEL_MASK;
118 buf[0] |= vddx_op_vol_sel;
120 if (i2c_write(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
123 if (i2c_read(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
126 if ((buf[0] & PMIC_OP_REG_SEL_MASK) != vddx_op_vol_sel)
132 #define OSC (V_OSCK/1000000)
134 const struct dpll_params dpll_mpu_pxm2 = {
135 720, OSC-1, 1, -1, -1, -1, -1};
137 void spl_siemens_board_init(void)
141 * pxm2 PMIC code. All boards currently want an MPU voltage
142 * of 1.2625V and CORE voltage of 1.1375V to operate at
145 if (i2c_probe(PMIC_CTRL_I2C_ADDR))
148 /* VDD1/2 voltage selection register access by control i/f */
149 if (i2c_read(PMIC_CTRL_I2C_ADDR, PMIC_DEVCTRL_REG, 1, buf, 1))
152 buf[0] |= PMIC_DEVCTRL_REG_SR_CTL_I2C_SEL_CTL_I2C;
154 if (i2c_write(PMIC_CTRL_I2C_ADDR, PMIC_DEVCTRL_REG, 1, buf, 1))
157 /* Frequency switching for OPP 120 */
158 if (voltage_update(MPU, PMIC_OP_REG_SEL_1_2_6) ||
159 voltage_update(CORE, PMIC_OP_REG_SEL_1_1_3)) {
160 printf("voltage update failed\n");
163 #endif /* if def CONFIG_SPL_BUILD */
165 int read_eeprom(void)
167 /* nothing ToDo here for this board */
172 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
173 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
174 static void cpsw_control(int enabled)
176 /* VTP can be added here */
181 static struct cpsw_slave_data cpsw_slaves[] = {
183 .slave_reg_ofs = 0x208,
184 .sliver_reg_ofs = 0xd80,
186 .phy_if = PHY_INTERFACE_MODE_RMII,
189 .slave_reg_ofs = 0x308,
190 .sliver_reg_ofs = 0xdc0,
192 .phy_if = PHY_INTERFACE_MODE_RMII,
196 static struct cpsw_platform_data cpsw_data = {
197 .mdio_base = CPSW_MDIO_BASE,
198 .cpsw_base = CPSW_BASE,
201 .cpdma_reg_ofs = 0x800,
203 .slave_data = cpsw_slaves,
204 .ale_reg_ofs = 0xd00,
206 .host_port_reg_ofs = 0x108,
207 .hw_stats_reg_ofs = 0x900,
208 .bd_ram_ofs = 0x2000,
209 .mac_control = (1 << 5),
210 .control = cpsw_control,
212 .version = CPSW_CTRL_VERSION_2,
214 #endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
216 #if defined(CONFIG_DRIVER_TI_CPSW) || \
217 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
218 int board_eth_init(bd_t *bis)
221 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
222 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
223 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
224 #ifdef CONFIG_FACTORYSET
226 if (!is_valid_ethaddr(factory_dat.mac))
227 printf("Error: no valid mac address\n");
229 eth_env_set_enetaddr("ethaddr", factory_dat.mac);
230 #endif /* #ifdef CONFIG_FACTORYSET */
232 /* Set rgmii mode and enable rmii clock to be sourced from chip */
233 writel(RGMII_MODE_ENABLE | RGMII_INT_DELAY, &cdev->miisel);
235 rv = cpsw_register(&cpsw_data);
237 printf("Error %d registering CPSW switch\n", rv);
243 #endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
245 #if defined(CONFIG_VIDEO) && !defined(CONFIG_SPL_BUILD)
246 static struct da8xx_panel lcd_panels[] = {
247 /* AUO G156XW01 V1 */
249 .name = "AUO_G156XW01_V1",
261 /* AUO B101EVN06 V0 */
263 .name = "AUO_B101EVN06_V0",
276 * Settings from factoryset
280 .name = "factoryset",
294 static const struct display_panel disp_panel = {
301 static const struct lcd_ctrl_config lcd_cfg = {
311 .invert_line_clock = 1,
312 .invert_frm_clock = 1,
318 static int set_gpio(int gpio, int state)
320 gpio_request(gpio, "temp");
321 gpio_direction_output(gpio, state);
322 gpio_set_value(gpio, state);
327 static int enable_backlight(void)
329 set_gpio(BOARD_LCD_POWER, 1);
330 set_gpio(BOARD_BACK_LIGHT, 1);
331 set_gpio(BOARD_TOUCH_POWER, 1);
335 static int enable_pwm(void)
337 struct pwmss_regs *pwmss = (struct pwmss_regs *)PWMSS0_BASE;
338 struct pwmss_ecap_regs *ecap;
339 int ticks = PWM_TICKS;
342 ecap = (struct pwmss_ecap_regs *)AM33XX_ECAP0_BASE;
344 setbits_le32(&pwmss->clkconfig, ECAP_CLK_EN);
345 /* TimeStam Counter register */
346 writel(0xdb9, &ecap->tsctr);
348 writel(ticks - 1, &ecap->cap3);
349 writel(ticks - 1, &ecap->cap1);
350 setbits_le16(&ecap->ecctl2,
351 (ECTRL2_MDSL_ECAP | ECTRL2_SYNCOSEL_MASK | 0xd0));
353 writel(duty, &ecap->cap2);
354 writel(duty, &ecap->cap4);
356 setbits_le16(&ecap->ecctl2, ECTRL2_CTRSTP_FREERUN);
360 static struct dpll_regs dpll_lcd_regs = {
361 .cm_clkmode_dpll = CM_WKUP + 0x98,
362 .cm_idlest_dpll = CM_WKUP + 0x48,
363 .cm_clksel_dpll = CM_WKUP + 0x54,
366 /* no console on this board */
367 int board_cfb_skip(void)
372 #define PLL_GET_M(v) ((v >> 8) & 0x7ff)
373 #define PLL_GET_N(v) (v & 0x7f)
375 static int get_clk(struct dpll_regs *dpll_regs)
381 val = readl(dpll_regs->cm_clksel_dpll);
384 f = (m * V_OSCK) / n;
391 return get_clk(&dpll_lcd_regs);
394 static int conf_disp_pll(int m, int n)
396 struct cm_perpll *cmper = (struct cm_perpll *)CM_PER;
397 struct cm_dpll *cmdpll = (struct cm_dpll *)CM_DPLL;
398 struct dpll_params dpll_lcd = {m, n, -1, -1, -1, -1, -1};
400 u32 *const clk_domains[] = {
404 u32 *const clk_modules_explicit_en[] = {
406 &cmper->lcdcclkstctrl,
407 &cmper->epwmss0clkctrl,
410 do_enable_clocks(clk_domains, clk_modules_explicit_en, 1);
411 writel(0x0, &cmdpll->clklcdcpixelclk);
413 do_setup_dpll(&dpll_lcd_regs, &dpll_lcd);
418 static int board_video_init(void)
420 conf_disp_pll(24, 1);
421 if (factory_dat.pxm50)
422 da8xx_video_init(&lcd_panels[0], &lcd_cfg, lcd_cfg.bpp);
424 da8xx_video_init(&lcd_panels[1], &lcd_cfg, lcd_cfg.bpp);
433 #ifdef CONFIG_BOARD_LATE_INIT
434 int board_late_init(void)
438 omap_nand_switch_ecc(1, 8);
440 #ifdef CONFIG_FACTORYSET
441 if (factory_dat.asn[0] != 0) {
442 char tmp[2 * MAX_STRING_LENGTH + 2];
444 if (strncmp((const char *)factory_dat.asn, "PXM50", 5) == 0)
445 factory_dat.pxm50 = 1;
447 factory_dat.pxm50 = 0;
448 sprintf(tmp, "%s_%s", factory_dat.asn,
449 factory_dat.comp_version);
450 ret = env_set("boardid", tmp);
452 printf("error setting board id\n");
454 factory_dat.pxm50 = 1;
455 ret = env_set("boardid", "PXM50_1.0");
457 printf("error setting board id\n");
459 debug("PXM50: %d\n", factory_dat.pxm50);
466 #include "../common/board.c"