blob: 5e70363588d75e591da971e2998255c819d1847f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
David Lechnera67f16f2016-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 Lechnera67f16f2016-02-26 00:46:07 -060013 */
14
15#include <common.h>
16#include <i2c.h>
17#include <net.h>
18#include <netdev.h>
19#include <spi.h>
20#include <spi_flash.h>
21#include <asm/arch/hardware.h>
22#include <asm/arch/pinmux_defs.h>
23#include <asm/io.h>
24#include <asm/arch/davinci_misc.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090025#include <linux/errno.h>
David Lechnera67f16f2016-02-26 00:46:07 -060026#include <hwconfig.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060027#include <asm/mach-types.h>
Simon Glassd9a766f2017-05-17 08:23:00 -060028#include <asm/setup.h>
David Lechnera67f16f2016-02-26 00:46:07 -060029
Masahiro Yamadab2c88682017-01-10 13:32:07 +090030#ifdef CONFIG_MMC_DAVINCI
David Lechnera67f16f2016-02-26 00:46:07 -060031#include <mmc.h>
32#include <asm/arch/sdmmc_defs.h>
33#endif
34
35DECLARE_GLOBAL_DATA_PTR;
36
37u8 board_rev;
38
39#define EEPROM_I2C_ADDR 0x50
40#define EEPROM_REV_OFFSET 0x3F00
41#define EEPROM_MAC_OFFSET 0x3F06
42
Masahiro Yamadab2c88682017-01-10 13:32:07 +090043#ifdef CONFIG_MMC_DAVINCI
David Lechnera67f16f2016-02-26 00:46:07 -060044static struct davinci_mmc mmc_sd0 = {
45 .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
46 .host_caps = MMC_MODE_4BIT, /* DA850 supports only 4-bit SD/MMC */
47 .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
48 .version = MMC_CTLR_VERSION_2,
49};
50
51int board_mmc_init(bd_t *bis)
52{
53 mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
54
55 /* Add slot-0 to mmc subsystem */
56 return davinci_mmc_init(bis, &mmc_sd0);
57}
58#endif
59
60const struct pinmux_resource pinmuxes[] = {
61 PINMUX_ITEM(spi0_pins_base),
62 PINMUX_ITEM(spi0_pins_scs0),
63 PINMUX_ITEM(uart1_pins_txrx),
64 PINMUX_ITEM(i2c0_pins),
65 PINMUX_ITEM(mmc0_pins),
66};
67
68const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
69
70const struct lpsc_resource lpsc[] = {
71 { DAVINCI_LPSC_SPI0 }, /* Serial Flash */
72 { DAVINCI_LPSC_UART1 }, /* console */
73 { DAVINCI_LPSC_MMC_SD },
74};
75
76const int lpsc_size = ARRAY_SIZE(lpsc);
77
78u32 get_board_rev(void)
79{
80 u8 buf[2];
81
82 if (!board_rev) {
83 if (i2c_read(EEPROM_I2C_ADDR, EEPROM_REV_OFFSET, 2, buf, 2)) {
84 printf("\nBoard revision read failed!\n");
85 } else {
86 /*
87 * Board rev 3 has MAC address at EEPROM_REV_OFFSET.
88 * Other revisions have checksum at EEPROM_REV_OFFSET+1
89 * to detect this.
90 */
91 if ((buf[0] ^ buf[1]) == 0xFF)
92 board_rev = buf[0];
93 else
94 board_rev = 3;
95 }
96 }
97
98 return board_rev;
99}
100
101/*
102 * The Bluetooth MAC address serves as the board serial number.
103 */
104void get_board_serial(struct tag_serialnr *serialnr)
105{
106 u32 offset;
107 u8 buf[6];
108
109 if (!board_rev)
110 board_rev = get_board_rev();
111
112 /* Board rev 3 has MAC address where rev should be */
113 offset = (board_rev == 3) ? EEPROM_REV_OFFSET : EEPROM_MAC_OFFSET;
114
115 if (i2c_read(EEPROM_I2C_ADDR, offset, 2, buf, 6)) {
116 printf("\nBoard serial read failed!\n");
117 } else {
118 u8 *nr;
119
120 nr = (u8 *)&serialnr->low;
121 nr[0] = buf[5];
122 nr[1] = buf[4];
123 nr[2] = buf[3];
124 nr[3] = buf[2];
125 nr = (u8 *)&serialnr->high;
126 nr[0] = buf[1];
127 nr[1] = buf[0];
128 nr[2] = 0;
129 nr[3] = 0;
130 }
131}
132
133int board_early_init_f(void)
134{
135 /*
136 * Power on required peripherals
137 * ARM does not have access by default to PSC0 and PSC1
138 * assuming here that the DSP bootloader has set the IOPU
139 * such that PSC access is available to ARM
140 */
141 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
142 return 1;
143
144 return 0;
145}
146
147int board_init(void)
148{
David Lechnera67f16f2016-02-26 00:46:07 -0600149 irq_init();
David Lechnera67f16f2016-02-26 00:46:07 -0600150
151 /* arch number of the board */
152 /* LEGO didn't register for a unique number and uses da850evm */
153 gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
154
155 /* address of boot parameters */
156 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
157
158 /* setup the SUSPSRC for ARM to control emulation suspend */
159 writel(readl(&davinci_syscfg_regs->suspsrc) &
160 ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
161 DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
162 DAVINCI_SYSCFG_SUSPSRC_UART1),
163 &davinci_syscfg_regs->suspsrc);
164
165 /* configure pinmux settings */
166 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
167 return 1;
168
169 /* enable the console UART */
170 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
171 DAVINCI_UART_PWREMU_MGMT_UTRST),
172 &davinci_uart1_ctrl_regs->pwremu_mgmt);
173
174 return 0;
175}