1 // SPDX-License-Identifier: GPL-2.0+
3 * Board functions for TI AM335X based pxm2 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 * Board functions for TI AM335X based boards
12 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
16 #include <environment.h>
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>
27 #include "../../../drivers/video/da8xx-fb.h"
36 #include "../common/factoryset.h"
39 #include <bmp_layout.h>
41 #ifdef CONFIG_SPL_BUILD
42 static void board_init_ddr(void)
44 struct emif_regs pxm2_ddr3_emif_reg_data = {
45 .sdram_config = 0x41805332,
46 .sdram_tim1 = 0x666b3c9,
47 .sdram_tim2 = 0x243631ca,
49 .emif_ddr_phy_ctlr_1 = 0x100005,
54 struct ddr_data pxm2_ddr3_data = {
55 .datardsratio0 = 0x81204812,
57 .datafwsratio0 = 0x8020080,
58 .datawrsratio0 = 0x4010040,
61 struct cmd_control pxm2_ddr3_cmd_ctrl_data = {
70 const struct ctrl_ioregs ioregs = {
71 .cm0ioctl = DDR_IOCTRL_VAL,
72 .cm1ioctl = DDR_IOCTRL_VAL,
73 .cm2ioctl = DDR_IOCTRL_VAL,
74 .dt0ioctl = DDR_IOCTRL_VAL,
75 .dt1ioctl = DDR_IOCTRL_VAL,
78 config_ddr(DDR_PLL_FREQ, &ioregs, &pxm2_ddr3_data,
79 &pxm2_ddr3_cmd_ctrl_data, &pxm2_ddr3_emif_reg_data, 0);
83 * voltage switching for MPU frequency switching.
84 * @module = mpu - 0, core - 1
85 * @vddx_op_vol_sel = vdd voltage to set
91 int voltage_update(unsigned int module, unsigned char vddx_op_vol_sel)
94 unsigned int reg_offset;
97 reg_offset = PMIC_VDD1_OP_REG;
99 reg_offset = PMIC_VDD2_OP_REG;
102 if (i2c_read(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
105 buf[0] &= ~PMIC_OP_REG_CMD_MASK;
107 if (i2c_write(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
110 /* Configure VDDx OP Voltage */
111 if (i2c_read(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
114 buf[0] &= ~PMIC_OP_REG_SEL_MASK;
115 buf[0] |= vddx_op_vol_sel;
117 if (i2c_write(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
120 if (i2c_read(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
123 if ((buf[0] & PMIC_OP_REG_SEL_MASK) != vddx_op_vol_sel)
129 #define OSC (V_OSCK/1000000)
131 const struct dpll_params dpll_mpu_pxm2 = {
132 720, OSC-1, 1, -1, -1, -1, -1};
134 void spl_siemens_board_init(void)
138 * pxm2 PMIC code. All boards currently want an MPU voltage
139 * of 1.2625V and CORE voltage of 1.1375V to operate at
142 if (i2c_probe(PMIC_CTRL_I2C_ADDR))
145 /* VDD1/2 voltage selection register access by control i/f */
146 if (i2c_read(PMIC_CTRL_I2C_ADDR, PMIC_DEVCTRL_REG, 1, buf, 1))
149 buf[0] |= PMIC_DEVCTRL_REG_SR_CTL_I2C_SEL_CTL_I2C;
151 if (i2c_write(PMIC_CTRL_I2C_ADDR, PMIC_DEVCTRL_REG, 1, buf, 1))
154 /* Frequency switching for OPP 120 */
155 if (voltage_update(MPU, PMIC_OP_REG_SEL_1_2_6) ||
156 voltage_update(CORE, PMIC_OP_REG_SEL_1_1_3)) {
157 printf("voltage update failed\n");
160 #endif /* if def CONFIG_SPL_BUILD */
162 int read_eeprom(void)
164 /* nothing ToDo here for this board */
169 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
170 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
171 static void cpsw_control(int enabled)
173 /* VTP can be added here */
178 static struct cpsw_slave_data cpsw_slaves[] = {
180 .slave_reg_ofs = 0x208,
181 .sliver_reg_ofs = 0xd80,
183 .phy_if = PHY_INTERFACE_MODE_RMII,
186 .slave_reg_ofs = 0x308,
187 .sliver_reg_ofs = 0xdc0,
189 .phy_if = PHY_INTERFACE_MODE_RMII,
193 static struct cpsw_platform_data cpsw_data = {
194 .mdio_base = CPSW_MDIO_BASE,
195 .cpsw_base = CPSW_BASE,
198 .cpdma_reg_ofs = 0x800,
200 .slave_data = cpsw_slaves,
201 .ale_reg_ofs = 0xd00,
203 .host_port_reg_ofs = 0x108,
204 .hw_stats_reg_ofs = 0x900,
205 .bd_ram_ofs = 0x2000,
206 .mac_control = (1 << 5),
207 .control = cpsw_control,
209 .version = CPSW_CTRL_VERSION_2,
211 #endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
213 #if defined(CONFIG_DRIVER_TI_CPSW) || \
214 (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
215 int board_eth_init(bd_t *bis)
218 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
219 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
220 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
221 #ifdef CONFIG_FACTORYSET
223 if (!is_valid_ethaddr(factory_dat.mac))
224 printf("Error: no valid mac address\n");
226 eth_env_set_enetaddr("ethaddr", factory_dat.mac);
227 #endif /* #ifdef CONFIG_FACTORYSET */
229 /* Set rgmii mode and enable rmii clock to be sourced from chip */
230 writel(RGMII_MODE_ENABLE | RGMII_INT_DELAY, &cdev->miisel);
232 rv = cpsw_register(&cpsw_data);
234 printf("Error %d registering CPSW switch\n", rv);
240 #endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
242 #if defined(CONFIG_VIDEO) && !defined(CONFIG_SPL_BUILD)
243 static struct da8xx_panel lcd_panels[] = {
244 /* AUO G156XW01 V1 */
246 .name = "AUO_G156XW01_V1",
258 /* AUO B101EVN06 V0 */
260 .name = "AUO_B101EVN06_V0",
273 * Settings from factoryset
277 .name = "factoryset",
291 static const struct display_panel disp_panel = {
298 static const struct lcd_ctrl_config lcd_cfg = {
308 .invert_line_clock = 1,
309 .invert_frm_clock = 1,
315 static int set_gpio(int gpio, int state)
317 gpio_request(gpio, "temp");
318 gpio_direction_output(gpio, state);
319 gpio_set_value(gpio, state);
324 static int enable_backlight(void)
326 set_gpio(BOARD_LCD_POWER, 1);
327 set_gpio(BOARD_BACK_LIGHT, 1);
328 set_gpio(BOARD_TOUCH_POWER, 1);
332 static int enable_pwm(void)
334 struct pwmss_regs *pwmss = (struct pwmss_regs *)PWMSS0_BASE;
335 struct pwmss_ecap_regs *ecap;
336 int ticks = PWM_TICKS;
339 ecap = (struct pwmss_ecap_regs *)AM33XX_ECAP0_BASE;
341 setbits_le32(&pwmss->clkconfig, ECAP_CLK_EN);
342 /* TimeStam Counter register */
343 writel(0xdb9, &ecap->tsctr);
345 writel(ticks - 1, &ecap->cap3);
346 writel(ticks - 1, &ecap->cap1);
347 setbits_le16(&ecap->ecctl2,
348 (ECTRL2_MDSL_ECAP | ECTRL2_SYNCOSEL_MASK | 0xd0));
350 writel(duty, &ecap->cap2);
351 writel(duty, &ecap->cap4);
353 setbits_le16(&ecap->ecctl2, ECTRL2_CTRSTP_FREERUN);
357 static struct dpll_regs dpll_lcd_regs = {
358 .cm_clkmode_dpll = CM_WKUP + 0x98,
359 .cm_idlest_dpll = CM_WKUP + 0x48,
360 .cm_clksel_dpll = CM_WKUP + 0x54,
363 /* no console on this board */
364 int board_cfb_skip(void)
369 #define PLL_GET_M(v) ((v >> 8) & 0x7ff)
370 #define PLL_GET_N(v) (v & 0x7f)
372 static int get_clk(struct dpll_regs *dpll_regs)
378 val = readl(dpll_regs->cm_clksel_dpll);
381 f = (m * V_OSCK) / n;
388 return get_clk(&dpll_lcd_regs);
391 static int conf_disp_pll(int m, int n)
393 struct cm_perpll *cmper = (struct cm_perpll *)CM_PER;
394 struct cm_dpll *cmdpll = (struct cm_dpll *)CM_DPLL;
395 struct dpll_params dpll_lcd = {m, n, -1, -1, -1, -1, -1};
397 u32 *const clk_domains[] = {
401 u32 *const clk_modules_explicit_en[] = {
403 &cmper->lcdcclkstctrl,
404 &cmper->epwmss0clkctrl,
407 do_enable_clocks(clk_domains, clk_modules_explicit_en, 1);
408 writel(0x0, &cmdpll->clklcdcpixelclk);
410 do_setup_dpll(&dpll_lcd_regs, &dpll_lcd);
415 static int board_video_init(void)
417 conf_disp_pll(24, 1);
418 if (factory_dat.pxm50)
419 da8xx_video_init(&lcd_panels[0], &lcd_cfg, lcd_cfg.bpp);
421 da8xx_video_init(&lcd_panels[1], &lcd_cfg, lcd_cfg.bpp);
430 #ifdef CONFIG_BOARD_LATE_INIT
431 int board_late_init(void)
435 omap_nand_switch_ecc(1, 8);
437 #ifdef CONFIG_FACTORYSET
438 if (factory_dat.asn[0] != 0) {
439 char tmp[2 * MAX_STRING_LENGTH + 2];
441 if (strncmp((const char *)factory_dat.asn, "PXM50", 5) == 0)
442 factory_dat.pxm50 = 1;
444 factory_dat.pxm50 = 0;
445 sprintf(tmp, "%s_%s", factory_dat.asn,
446 factory_dat.comp_version);
447 ret = env_set("boardid", tmp);
449 printf("error setting board id\n");
451 factory_dat.pxm50 = 1;
452 ret = env_set("boardid", "PXM50_1.0");
454 printf("error setting board id\n");
456 debug("PXM50: %d\n", factory_dat.pxm50);
463 #include "../common/board.c"