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