xref: /rk3399_rockchip-uboot/board/lego/ev3/legoev3.c (revision 5d9828563f80a1319e793166974dd6003dc1d941)
12ac07f75SDavid Lechner /*
22ac07f75SDavid Lechner  * Copyright (C) 2016 David Lechner <david@lechnology.com>
32ac07f75SDavid Lechner  *
42ac07f75SDavid Lechner  * Based on da850evm.c
52ac07f75SDavid Lechner  *
62ac07f75SDavid Lechner  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
72ac07f75SDavid Lechner  *
82ac07f75SDavid Lechner  * Based on da830evm.c. Original Copyrights follow:
92ac07f75SDavid Lechner  *
102ac07f75SDavid Lechner  * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
112ac07f75SDavid Lechner  * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
122ac07f75SDavid Lechner  *
132ac07f75SDavid Lechner  * SPDX-License-Identifier:	GPL-2.0+
142ac07f75SDavid Lechner  */
152ac07f75SDavid Lechner 
162ac07f75SDavid Lechner #include <common.h>
172ac07f75SDavid Lechner #include <i2c.h>
182ac07f75SDavid Lechner #include <net.h>
192ac07f75SDavid Lechner #include <netdev.h>
202ac07f75SDavid Lechner #include <spi.h>
212ac07f75SDavid Lechner #include <spi_flash.h>
222ac07f75SDavid Lechner #include <asm/arch/hardware.h>
232ac07f75SDavid Lechner #include <asm/arch/pinmux_defs.h>
242ac07f75SDavid Lechner #include <asm/io.h>
252ac07f75SDavid Lechner #include <asm/arch/davinci_misc.h>
261221ce45SMasahiro Yamada #include <linux/errno.h>
272ac07f75SDavid Lechner #include <hwconfig.h>
28c62db35dSSimon Glass #include <asm/mach-types.h>
29*5d982856SSimon Glass #include <asm/setup.h>
302ac07f75SDavid Lechner 
311d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
322ac07f75SDavid Lechner #include <mmc.h>
332ac07f75SDavid Lechner #include <asm/arch/sdmmc_defs.h>
342ac07f75SDavid Lechner #endif
352ac07f75SDavid Lechner 
362ac07f75SDavid Lechner DECLARE_GLOBAL_DATA_PTR;
372ac07f75SDavid Lechner 
382ac07f75SDavid Lechner u8 board_rev;
392ac07f75SDavid Lechner 
402ac07f75SDavid Lechner #define EEPROM_I2C_ADDR		0x50
412ac07f75SDavid Lechner #define EEPROM_REV_OFFSET	0x3F00
422ac07f75SDavid Lechner #define EEPROM_MAC_OFFSET	0x3F06
432ac07f75SDavid Lechner 
441d2c0506SMasahiro Yamada #ifdef CONFIG_MMC_DAVINCI
452ac07f75SDavid Lechner static struct davinci_mmc mmc_sd0 = {
462ac07f75SDavid Lechner 	.reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
472ac07f75SDavid Lechner 	.host_caps = MMC_MODE_4BIT,     /* DA850 supports only 4-bit SD/MMC */
482ac07f75SDavid Lechner 	.voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
492ac07f75SDavid Lechner 	.version = MMC_CTLR_VERSION_2,
502ac07f75SDavid Lechner };
512ac07f75SDavid Lechner 
board_mmc_init(bd_t * bis)522ac07f75SDavid Lechner int board_mmc_init(bd_t *bis)
532ac07f75SDavid Lechner {
542ac07f75SDavid Lechner 	mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
552ac07f75SDavid Lechner 
562ac07f75SDavid Lechner 	/* Add slot-0 to mmc subsystem */
572ac07f75SDavid Lechner 	return davinci_mmc_init(bis, &mmc_sd0);
582ac07f75SDavid Lechner }
592ac07f75SDavid Lechner #endif
602ac07f75SDavid Lechner 
612ac07f75SDavid Lechner const struct pinmux_resource pinmuxes[] = {
622ac07f75SDavid Lechner 	PINMUX_ITEM(spi0_pins_base),
632ac07f75SDavid Lechner 	PINMUX_ITEM(spi0_pins_scs0),
642ac07f75SDavid Lechner 	PINMUX_ITEM(uart1_pins_txrx),
652ac07f75SDavid Lechner 	PINMUX_ITEM(i2c0_pins),
662ac07f75SDavid Lechner 	PINMUX_ITEM(mmc0_pins),
672ac07f75SDavid Lechner };
682ac07f75SDavid Lechner 
692ac07f75SDavid Lechner const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
702ac07f75SDavid Lechner 
712ac07f75SDavid Lechner const struct lpsc_resource lpsc[] = {
722ac07f75SDavid Lechner 	{ DAVINCI_LPSC_SPI0 },	/* Serial Flash */
732ac07f75SDavid Lechner 	{ DAVINCI_LPSC_UART1 },	/* console */
742ac07f75SDavid Lechner 	{ DAVINCI_LPSC_MMC_SD },
752ac07f75SDavid Lechner };
762ac07f75SDavid Lechner 
772ac07f75SDavid Lechner const int lpsc_size = ARRAY_SIZE(lpsc);
782ac07f75SDavid Lechner 
get_board_rev(void)792ac07f75SDavid Lechner u32 get_board_rev(void)
802ac07f75SDavid Lechner {
812ac07f75SDavid Lechner 	u8 buf[2];
822ac07f75SDavid Lechner 
832ac07f75SDavid Lechner 	if (!board_rev) {
842ac07f75SDavid Lechner 		if (i2c_read(EEPROM_I2C_ADDR, EEPROM_REV_OFFSET, 2, buf, 2)) {
852ac07f75SDavid Lechner 			printf("\nBoard revision read failed!\n");
862ac07f75SDavid Lechner 		} else {
872ac07f75SDavid Lechner 			/*
882ac07f75SDavid Lechner 			 * Board rev 3 has MAC address at EEPROM_REV_OFFSET.
892ac07f75SDavid Lechner 			 * Other revisions have checksum at EEPROM_REV_OFFSET+1
902ac07f75SDavid Lechner 			 * to detect this.
912ac07f75SDavid Lechner 			 */
922ac07f75SDavid Lechner 			if ((buf[0] ^ buf[1]) == 0xFF)
932ac07f75SDavid Lechner 				board_rev = buf[0];
942ac07f75SDavid Lechner 			else
952ac07f75SDavid Lechner 				board_rev = 3;
962ac07f75SDavid Lechner 		}
972ac07f75SDavid Lechner 	}
982ac07f75SDavid Lechner 
992ac07f75SDavid Lechner 	return board_rev;
1002ac07f75SDavid Lechner }
1012ac07f75SDavid Lechner 
1022ac07f75SDavid Lechner /*
1032ac07f75SDavid Lechner  * The Bluetooth MAC address serves as the board serial number.
1042ac07f75SDavid Lechner  */
get_board_serial(struct tag_serialnr * serialnr)1052ac07f75SDavid Lechner void get_board_serial(struct tag_serialnr *serialnr)
1062ac07f75SDavid Lechner {
1072ac07f75SDavid Lechner 	u32 offset;
1082ac07f75SDavid Lechner 	u8 buf[6];
1092ac07f75SDavid Lechner 
1102ac07f75SDavid Lechner 	if (!board_rev)
1112ac07f75SDavid Lechner 		board_rev = get_board_rev();
1122ac07f75SDavid Lechner 
1132ac07f75SDavid Lechner 	/* Board rev 3 has MAC address where rev should be */
1142ac07f75SDavid Lechner 	offset = (board_rev == 3) ? EEPROM_REV_OFFSET : EEPROM_MAC_OFFSET;
1152ac07f75SDavid Lechner 
1162ac07f75SDavid Lechner 	if (i2c_read(EEPROM_I2C_ADDR, offset, 2, buf, 6)) {
1172ac07f75SDavid Lechner 		printf("\nBoard serial read failed!\n");
1182ac07f75SDavid Lechner 	} else {
1192ac07f75SDavid Lechner 		u8 *nr;
1202ac07f75SDavid Lechner 
1212ac07f75SDavid Lechner 		nr = (u8 *)&serialnr->low;
1222ac07f75SDavid Lechner 		nr[0] = buf[5];
1232ac07f75SDavid Lechner 		nr[1] = buf[4];
1242ac07f75SDavid Lechner 		nr[2] = buf[3];
1252ac07f75SDavid Lechner 		nr[3] = buf[2];
1262ac07f75SDavid Lechner 		nr = (u8 *)&serialnr->high;
1272ac07f75SDavid Lechner 		nr[0] = buf[1];
1282ac07f75SDavid Lechner 		nr[1] = buf[0];
1292ac07f75SDavid Lechner 		nr[2] = 0;
1302ac07f75SDavid Lechner 		nr[3] = 0;
1312ac07f75SDavid Lechner 	}
1322ac07f75SDavid Lechner }
1332ac07f75SDavid Lechner 
board_early_init_f(void)1342ac07f75SDavid Lechner int board_early_init_f(void)
1352ac07f75SDavid Lechner {
1362ac07f75SDavid Lechner 	/*
1372ac07f75SDavid Lechner 	 * Power on required peripherals
1382ac07f75SDavid Lechner 	 * ARM does not have access by default to PSC0 and PSC1
1392ac07f75SDavid Lechner 	 * assuming here that the DSP bootloader has set the IOPU
1402ac07f75SDavid Lechner 	 * such that PSC access is available to ARM
1412ac07f75SDavid Lechner 	 */
1422ac07f75SDavid Lechner 	if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
1432ac07f75SDavid Lechner 		return 1;
1442ac07f75SDavid Lechner 
1452ac07f75SDavid Lechner 	return 0;
1462ac07f75SDavid Lechner }
1472ac07f75SDavid Lechner 
board_init(void)1482ac07f75SDavid Lechner int board_init(void)
1492ac07f75SDavid Lechner {
1502ac07f75SDavid Lechner 	irq_init();
1512ac07f75SDavid Lechner 
1522ac07f75SDavid Lechner 	/* arch number of the board */
1532ac07f75SDavid Lechner 	/* LEGO didn't register for a unique number and uses da850evm */
1542ac07f75SDavid Lechner 	gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
1552ac07f75SDavid Lechner 
1562ac07f75SDavid Lechner 	/* address of boot parameters */
1572ac07f75SDavid Lechner 	gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
1582ac07f75SDavid Lechner 
1592ac07f75SDavid Lechner 	/* setup the SUSPSRC for ARM to control emulation suspend */
1602ac07f75SDavid Lechner 	writel(readl(&davinci_syscfg_regs->suspsrc) &
1612ac07f75SDavid Lechner 	       ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
1622ac07f75SDavid Lechner 		 DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
1632ac07f75SDavid Lechner 		 DAVINCI_SYSCFG_SUSPSRC_UART1),
1642ac07f75SDavid Lechner 	       &davinci_syscfg_regs->suspsrc);
1652ac07f75SDavid Lechner 
1662ac07f75SDavid Lechner 	/* configure pinmux settings */
1672ac07f75SDavid Lechner 	if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
1682ac07f75SDavid Lechner 		return 1;
1692ac07f75SDavid Lechner 
1702ac07f75SDavid Lechner 	/* enable the console UART */
1712ac07f75SDavid Lechner 	writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
1722ac07f75SDavid Lechner 		DAVINCI_UART_PWREMU_MGMT_UTRST),
1732ac07f75SDavid Lechner 	       &davinci_uart1_ctrl_regs->pwremu_mgmt);
1742ac07f75SDavid Lechner 
1752ac07f75SDavid Lechner 	return 0;
1762ac07f75SDavid Lechner }
177