blob: 423c2fa44b95277e5af6844dca469ea47033308a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
David Lechner2ac07f72016-02-26 00:46:07 -06002/*
3 * Copyright (C) 2016 David Lechner <david@lechnology.com>
4 *
5 * Based on da850evm.c
6 *
7 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
8 *
9 * Based on da830evm.c. Original Copyrights follow:
10 *
11 * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
12 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
David Lechner2ac07f72016-02-26 00:46:07 -060013 */
14
15#include <common.h>
16#include <i2c.h>
David Lechner2ac07f72016-02-26 00:46:07 -060017#include <spi.h>
18#include <spi_flash.h>
19#include <asm/arch/hardware.h>
20#include <asm/arch/pinmux_defs.h>
21#include <asm/io.h>
22#include <asm/arch/davinci_misc.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090023#include <linux/errno.h>
David Lechner2ac07f72016-02-26 00:46:07 -060024#include <hwconfig.h>
Simon Glassc62db352017-05-31 19:47:48 -060025#include <asm/mach-types.h>
Simon Glass5d982852017-05-17 08:23:00 -060026#include <asm/setup.h>
David Lechner2ac07f72016-02-26 00:46:07 -060027
Masahiro Yamada1d2c0502017-01-10 13:32:07 +090028#ifdef CONFIG_MMC_DAVINCI
David Lechner2ac07f72016-02-26 00:46:07 -060029#include <mmc.h>
30#include <asm/arch/sdmmc_defs.h>
31#endif
32
33DECLARE_GLOBAL_DATA_PTR;
34
35u8 board_rev;
36
37#define EEPROM_I2C_ADDR 0x50
38#define EEPROM_REV_OFFSET 0x3F00
39#define EEPROM_MAC_OFFSET 0x3F06
40
Masahiro Yamada1d2c0502017-01-10 13:32:07 +090041#ifdef CONFIG_MMC_DAVINCI
David Lechner2ac07f72016-02-26 00:46:07 -060042static struct davinci_mmc mmc_sd0 = {
43 .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
44 .host_caps = MMC_MODE_4BIT, /* DA850 supports only 4-bit SD/MMC */
45 .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
46 .version = MMC_CTLR_VERSION_2,
47};
48
49int board_mmc_init(bd_t *bis)
50{
51 mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
52
53 /* Add slot-0 to mmc subsystem */
54 return davinci_mmc_init(bis, &mmc_sd0);
55}
56#endif
57
58const struct pinmux_resource pinmuxes[] = {
59 PINMUX_ITEM(spi0_pins_base),
60 PINMUX_ITEM(spi0_pins_scs0),
61 PINMUX_ITEM(uart1_pins_txrx),
62 PINMUX_ITEM(i2c0_pins),
63 PINMUX_ITEM(mmc0_pins),
64};
65
66const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
67
68const struct lpsc_resource lpsc[] = {
69 { DAVINCI_LPSC_SPI0 }, /* Serial Flash */
70 { DAVINCI_LPSC_UART1 }, /* console */
71 { DAVINCI_LPSC_MMC_SD },
72};
73
74const int lpsc_size = ARRAY_SIZE(lpsc);
75
76u32 get_board_rev(void)
77{
78 u8 buf[2];
79
80 if (!board_rev) {
81 if (i2c_read(EEPROM_I2C_ADDR, EEPROM_REV_OFFSET, 2, buf, 2)) {
82 printf("\nBoard revision read failed!\n");
83 } else {
84 /*
85 * Board rev 3 has MAC address at EEPROM_REV_OFFSET.
86 * Other revisions have checksum at EEPROM_REV_OFFSET+1
87 * to detect this.
88 */
89 if ((buf[0] ^ buf[1]) == 0xFF)
90 board_rev = buf[0];
91 else
92 board_rev = 3;
93 }
94 }
95
96 return board_rev;
97}
98
99/*
100 * The Bluetooth MAC address serves as the board serial number.
101 */
102void get_board_serial(struct tag_serialnr *serialnr)
103{
104 u32 offset;
105 u8 buf[6];
106
107 if (!board_rev)
108 board_rev = get_board_rev();
109
110 /* Board rev 3 has MAC address where rev should be */
111 offset = (board_rev == 3) ? EEPROM_REV_OFFSET : EEPROM_MAC_OFFSET;
112
113 if (i2c_read(EEPROM_I2C_ADDR, offset, 2, buf, 6)) {
114 printf("\nBoard serial read failed!\n");
115 } else {
116 u8 *nr;
117
118 nr = (u8 *)&serialnr->low;
119 nr[0] = buf[5];
120 nr[1] = buf[4];
121 nr[2] = buf[3];
122 nr[3] = buf[2];
123 nr = (u8 *)&serialnr->high;
124 nr[0] = buf[1];
125 nr[1] = buf[0];
126 nr[2] = 0;
127 nr[3] = 0;
128 }
129}
130
131int board_early_init_f(void)
132{
David Lechner648e87a2018-05-19 23:25:04 -0500133 /* enable the console UART */
134 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
135 DAVINCI_UART_PWREMU_MGMT_UTRST),
136 &davinci_uart1_ctrl_regs->pwremu_mgmt);
137
David Lechner2ac07f72016-02-26 00:46:07 -0600138 /*
139 * Power on required peripherals
140 * ARM does not have access by default to PSC0 and PSC1
141 * assuming here that the DSP bootloader has set the IOPU
142 * such that PSC access is available to ARM
143 */
144 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
145 return 1;
146
147 return 0;
148}
149
150int board_init(void)
151{
David Lechner2ac07f72016-02-26 00:46:07 -0600152 irq_init();
David Lechner2ac07f72016-02-26 00:46:07 -0600153
154 /* arch number of the board */
155 /* LEGO didn't register for a unique number and uses da850evm */
156 gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
157
158 /* address of boot parameters */
159 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
160
161 /* setup the SUSPSRC for ARM to control emulation suspend */
162 writel(readl(&davinci_syscfg_regs->suspsrc) &
David Lechner98ada4b2018-05-19 23:25:05 -0500163 ~(DAVINCI_SYSCFG_SUSPSRC_I2C |
David Lechner2ac07f72016-02-26 00:46:07 -0600164 DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
165 DAVINCI_SYSCFG_SUSPSRC_UART1),
166 &davinci_syscfg_regs->suspsrc);
167
168 /* configure pinmux settings */
169 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
170 return 1;
171
David Lechner2ac07f72016-02-26 00:46:07 -0600172 return 0;
173}