blob: fa099e95f5460761b3d37fc73680f2dbb083a715 [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>
David Lechnera67f16f2016-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 Yamada56a931c2016-09-21 11:28:55 +090023#include <linux/errno.h>
David Lechnera67f16f2016-02-26 00:46:07 -060024#include <hwconfig.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060025#include <asm/mach-types.h>
Simon Glassd9a766f2017-05-17 08:23:00 -060026#include <asm/setup.h>
David Lechnera67f16f2016-02-26 00:46:07 -060027
David Lechnera67f16f2016-02-26 00:46:07 -060028DECLARE_GLOBAL_DATA_PTR;
29
30u8 board_rev;
31
32#define EEPROM_I2C_ADDR 0x50
33#define EEPROM_REV_OFFSET 0x3F00
34#define EEPROM_MAC_OFFSET 0x3F06
35
David Lechnera67f16f2016-02-26 00:46:07 -060036const struct pinmux_resource pinmuxes[] = {
37 PINMUX_ITEM(spi0_pins_base),
38 PINMUX_ITEM(spi0_pins_scs0),
39 PINMUX_ITEM(uart1_pins_txrx),
40 PINMUX_ITEM(i2c0_pins),
41 PINMUX_ITEM(mmc0_pins),
42};
43
44const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
45
46const struct lpsc_resource lpsc[] = {
47 { DAVINCI_LPSC_SPI0 }, /* Serial Flash */
48 { DAVINCI_LPSC_UART1 }, /* console */
49 { DAVINCI_LPSC_MMC_SD },
50};
51
52const int lpsc_size = ARRAY_SIZE(lpsc);
53
54u32 get_board_rev(void)
55{
56 u8 buf[2];
57
58 if (!board_rev) {
59 if (i2c_read(EEPROM_I2C_ADDR, EEPROM_REV_OFFSET, 2, buf, 2)) {
60 printf("\nBoard revision read failed!\n");
61 } else {
62 /*
63 * Board rev 3 has MAC address at EEPROM_REV_OFFSET.
64 * Other revisions have checksum at EEPROM_REV_OFFSET+1
65 * to detect this.
66 */
67 if ((buf[0] ^ buf[1]) == 0xFF)
68 board_rev = buf[0];
69 else
70 board_rev = 3;
71 }
72 }
73
74 return board_rev;
75}
76
77/*
78 * The Bluetooth MAC address serves as the board serial number.
79 */
80void get_board_serial(struct tag_serialnr *serialnr)
81{
82 u32 offset;
83 u8 buf[6];
84
85 if (!board_rev)
86 board_rev = get_board_rev();
87
88 /* Board rev 3 has MAC address where rev should be */
89 offset = (board_rev == 3) ? EEPROM_REV_OFFSET : EEPROM_MAC_OFFSET;
90
91 if (i2c_read(EEPROM_I2C_ADDR, offset, 2, buf, 6)) {
92 printf("\nBoard serial read failed!\n");
93 } else {
94 u8 *nr;
95
96 nr = (u8 *)&serialnr->low;
97 nr[0] = buf[5];
98 nr[1] = buf[4];
99 nr[2] = buf[3];
100 nr[3] = buf[2];
101 nr = (u8 *)&serialnr->high;
102 nr[0] = buf[1];
103 nr[1] = buf[0];
104 nr[2] = 0;
105 nr[3] = 0;
106 }
107}
108
109int board_early_init_f(void)
110{
David Lechner2fde68f2018-05-19 23:25:04 -0500111 /* enable the console UART */
112 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
113 DAVINCI_UART_PWREMU_MGMT_UTRST),
114 &davinci_uart1_ctrl_regs->pwremu_mgmt);
115
David Lechnera67f16f2016-02-26 00:46:07 -0600116 /*
117 * Power on required peripherals
118 * ARM does not have access by default to PSC0 and PSC1
119 * assuming here that the DSP bootloader has set the IOPU
120 * such that PSC access is available to ARM
121 */
122 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
123 return 1;
124
125 return 0;
126}
127
128int board_init(void)
129{
David Lechnera67f16f2016-02-26 00:46:07 -0600130 irq_init();
David Lechnera67f16f2016-02-26 00:46:07 -0600131
132 /* arch number of the board */
133 /* LEGO didn't register for a unique number and uses da850evm */
134 gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
135
136 /* address of boot parameters */
137 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
138
139 /* setup the SUSPSRC for ARM to control emulation suspend */
140 writel(readl(&davinci_syscfg_regs->suspsrc) &
David Lechner4c50c8d2018-05-19 23:25:05 -0500141 ~(DAVINCI_SYSCFG_SUSPSRC_I2C |
David Lechnera67f16f2016-02-26 00:46:07 -0600142 DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
143 DAVINCI_SYSCFG_SUSPSRC_UART1),
144 &davinci_syscfg_regs->suspsrc);
145
146 /* configure pinmux settings */
147 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
148 return 1;
149
David Lechnera67f16f2016-02-26 00:46:07 -0600150 return 0;
151}