1 // SPDX-License-Identifier: GPL-2.0+
5 * Board functions for Birdland Audio BAV335x Network Processor
7 * Copyright (c) 2012-2014 Birdland Audio - http://birdland.com/oem
14 #include <asm/arch/cpu.h>
15 #include <asm/arch/hardware.h>
16 #include <asm/arch/omap.h>
17 #include <asm/arch/ddr_defs.h>
18 #include <asm/arch/clock.h>
19 #include <asm/arch/gpio.h>
20 #include <asm/arch/mmc_host_def.h>
21 #include <asm/arch/sys_proto.h>
22 #include <asm/arch/mem.h>
29 #include <power/tps65217.h>
30 #include <power/tps65910.h>
31 #include <env_internal.h>
35 DECLARE_GLOBAL_DATA_PTR;
37 /* GPIO that controls power to DDR on EVM-SK */
38 #define GPIO_DDR_VTT_EN 7
40 static __maybe_unused struct ctrl_dev *cdev =
41 (struct ctrl_dev *)CTRL_DEVICE_BASE;
46 * Read header information from EEPROM into global structure.
48 static int read_eeprom(struct board_eeconfig *header)
50 /* Check if baseboard eeprom is available */
51 if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR))
54 /* read the eeprom using i2c */
55 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)header,
56 sizeof(struct board_eeconfig)))
59 if (header->magic != BOARD_MAGIC) {
60 /* read the i2c eeprom again using only a 1 byte address */
61 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1, (uchar *)header,
62 sizeof(struct board_eeconfig)))
65 if (header->magic != BOARD_MAGIC)
74 enum board_type get_board_type(bool debug)
77 struct board_eeconfig header;
79 ecode = read_eeprom(&header);
81 if (header.version[1] == 'A') {
83 puts("=== Detected Board model BAV335x Rev.A");
85 } else if (header.version[1] == 'B') {
87 puts("=== Detected Board model BAV335x Rev.B");
90 puts("### Un-known board model in serial-EE\n");
95 puts("### Board doesn't have a serial-EE\n");
98 puts("### Board serial-EE signature is incorrect.\n");
101 puts("### IO Error reading serial-EE.\n");
106 #if (CONFIG_BAV_VERSION == 1)
108 puts("### Selecting BAV335A as per config\n");
110 #elif (CONFIG_BAV_VERSION == 2)
112 puts("### Selecting BAV335B as per config\n");
115 #if (NOT_DEFINED == 2)
116 #error "SHOULD NEVER DISPLAY THIS"
120 puts("### Defaulting to model BAV335x Rev.B\n");
126 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
127 static const struct ddr_data ddr3_bav335x_data = {
128 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
129 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
130 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
131 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
134 static const struct cmd_control ddr3_bav335x_cmd_ctrl_data = {
135 .cmd0csratio = MT41K256M16HA125E_RATIO,
136 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
137 .cmd1csratio = MT41K256M16HA125E_RATIO,
138 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
139 .cmd2csratio = MT41K256M16HA125E_RATIO,
140 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
144 static struct emif_regs ddr3_bav335x_emif_reg_data = {
145 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
146 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
147 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
148 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
149 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
150 .zq_config = MT41K256M16HA125E_ZQ_CFG,
151 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
155 #ifdef CONFIG_SPL_OS_BOOT
156 int spl_start_uboot(void)
158 /* break into full u-boot on 'c' */
159 if (serial_tstc() && serial_getc() == 'c')
162 #ifdef CONFIG_SPL_ENV_SUPPORT
165 if (env_get_yesno("boot_os") != 1)
173 #define OSC (V_OSCK/1000000)
174 const struct dpll_params dpll_ddr = {
175 266, OSC-1, 1, -1, -1, -1, -1};
176 const struct dpll_params dpll_ddr_evm_sk = {
177 303, OSC-1, 1, -1, -1, -1, -1};
178 const struct dpll_params dpll_ddr_bone_black = {
179 400, OSC-1, 1, -1, -1, -1, -1};
181 void am33xx_spl_board_init(void)
183 /* debug print detect status */
184 (void)get_board_type(true);
186 /* Get the frequency */
187 /* dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev); */
188 dpll_mpu_opp100.m = MPUPLL_M_1000;
190 if (i2c_probe(TPS65217_CHIP_PM))
193 /* Set the USB Current Limit */
194 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, TPS65217_POWER_PATH,
195 TPS65217_USB_INPUT_CUR_LIMIT_1800MA,
196 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
197 puts("! tps65217_reg_write: could not set USB limit\n");
199 /* Set the Core Voltage (DCDC3) to 1.125V */
200 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
201 TPS65217_DCDC_VOLT_SEL_1125MV)) {
202 puts("! tps65217_reg_write: could not set Core Voltage\n");
206 /* Set CORE Frequencies to OPP100 */
207 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
209 /* Set the MPU Voltage (DCDC2) */
210 if (tps65217_voltage_update(TPS65217_DEFDCDC2,
211 TPS65217_DCDC_VOLT_SEL_1325MV)) {
212 puts("! tps65217_reg_write: could not set MPU Voltage\n");
217 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
218 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
220 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, TPS65217_DEFLS1,
221 TPS65217_LDO_VOLTAGE_OUT_1_8, TPS65217_LDO_MASK))
222 puts("! tps65217_reg_write: could not set LDO3\n");
224 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, TPS65217_DEFLS2,
225 TPS65217_LDO_VOLTAGE_OUT_3_3, TPS65217_LDO_MASK))
226 puts("! tps65217_reg_write: could not set LDO4\n");
228 /* Set MPU Frequency to what we detected now that voltages are set */
229 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
232 const struct dpll_params *get_dpll_ddr_params(void)
234 enable_i2c0_pin_mux();
235 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
237 return &dpll_ddr_bone_black;
240 void set_uart_mux_conf(void)
242 #if CONFIG_CONS_INDEX == 1
243 enable_uart0_pin_mux();
244 #elif CONFIG_CONS_INDEX == 2
245 enable_uart1_pin_mux();
246 #elif CONFIG_CONS_INDEX == 3
247 enable_uart2_pin_mux();
248 #elif CONFIG_CONS_INDEX == 4
249 enable_uart3_pin_mux();
250 #elif CONFIG_CONS_INDEX == 5
251 enable_uart4_pin_mux();
252 #elif CONFIG_CONS_INDEX == 6
253 enable_uart5_pin_mux();
257 void set_mux_conf_regs(void)
259 enum board_type board;
261 board = get_board_type(false);
262 enable_board_pin_mux(board);
265 const struct ctrl_ioregs ioregs_bonelt = {
266 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
267 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
268 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
269 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
270 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
274 void sdram_init(void)
276 config_ddr(400, &ioregs_bonelt,
278 &ddr3_bav335x_cmd_ctrl_data,
279 &ddr3_bav335x_emif_reg_data, 0);
284 * Basic board specific setup. Pinmux has been handled already.
288 #if defined(CONFIG_HW_WATCHDOG)
292 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
293 #if defined(CONFIG_NOR) || defined(CONFIG_NAND)
299 #ifdef CONFIG_BOARD_LATE_INIT
300 int board_late_init(void)
302 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
303 env_set("board_name", "BAV335xB");
304 env_set("board_rev", "B"); /* Fix me, but why bother.. */
311 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
312 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
313 static void cpsw_control(int enabled)
315 /* VTP can be added here */
319 static struct cpsw_slave_data cpsw_slaves[] = {
321 .slave_reg_ofs = 0x208,
322 .sliver_reg_ofs = 0xd80,
326 .slave_reg_ofs = 0x308,
327 .sliver_reg_ofs = 0xdc0,
332 static struct cpsw_platform_data cpsw_data = {
333 .mdio_base = CPSW_MDIO_BASE,
334 .cpsw_base = CPSW_BASE,
337 .cpdma_reg_ofs = 0x800,
339 .slave_data = cpsw_slaves,
340 .ale_reg_ofs = 0xd00,
342 .host_port_reg_ofs = 0x108,
343 .hw_stats_reg_ofs = 0x900,
344 .bd_ram_ofs = 0x2000,
345 .mac_control = (1 << 5),
346 .control = cpsw_control,
348 .version = CPSW_CTRL_VERSION_2,
354 * This function will:
355 * Perform fixups to the PHY present on certain boards. We only need this
357 * - SPL with either CPSW or USB ethernet support
358 * - Full U-Boot, with either CPSW or USB ethernet
359 * Build in only these cases to avoid warnings about unused variables
360 * when we build an SPL that has neither option but full U-Boot will.
362 #if ((defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USB_ETHER)) &&\
363 defined(CONFIG_SPL_BUILD)) || \
364 ((defined(CONFIG_DRIVER_TI_CPSW) || \
365 defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)) && \
366 !defined(CONFIG_SPL_BUILD))
367 int board_eth_init(bd_t *bis)
371 struct board_eeconfig header;
372 __maybe_unused enum board_type board;
374 /* Default manufacturing address; used when no EE or invalid */
383 ecode = read_eeprom(&header);
384 /* if we have a valid EE, get mac address from there */
386 is_valid_ethaddr((const u8 *)&header.mac_addr[0][0])) {
387 memcpy(mac_addr, (const void *)&header.mac_addr[0][0], 6);
391 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
392 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
394 if (!env_get("ethaddr")) {
395 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
397 if (is_valid_ethaddr(mac_addr))
398 eth_env_set_enetaddr("ethaddr", mac_addr);
401 #ifdef CONFIG_DRIVER_TI_CPSW
403 board = get_board_type(false);
405 /* Rev.A uses 10/100 PHY in mii mode */
406 if (board == BAV335A) {
407 writel(MII_MODE_ENABLE, &cdev->miisel);
408 cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_MII;
409 cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_MII;
411 /* Rev.B (default) uses GB PHY in rmii mode */
413 writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel);
414 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if
415 = PHY_INTERFACE_MODE_RGMII;
418 rv = cpsw_register(&cpsw_data);
420 printf("Error %d registering CPSW switch\n", rv);