blob: 9ef3e12ce8c04729f8603f4eaeb897f7676ecc77 [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>
David Lechner68432b52021-01-11 13:24:44 -060016#include <env.h>
David Lechner2ac07f72016-02-26 00:46:07 -060017#include <i2c.h>
Simon Glass691d7192020-05-10 11:40:02 -060018#include <init.h>
David Lechner2ac07f72016-02-26 00:46:07 -060019#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 Yamada1221ce42016-09-21 11:28:55 +090025#include <linux/errno.h>
David Lechner2ac07f72016-02-26 00:46:07 -060026#include <hwconfig.h>
Simon Glassc62db352017-05-31 19:47:48 -060027#include <asm/mach-types.h>
Simon Glass5d982852017-05-17 08:23:00 -060028#include <asm/setup.h>
David Lechner2ac07f72016-02-26 00:46:07 -060029
David Lechner2ac07f72016-02-26 00:46:07 -060030DECLARE_GLOBAL_DATA_PTR;
31
David Lechner2ac07f72016-02-26 00:46:07 -060032#define EEPROM_I2C_ADDR 0x50
33#define EEPROM_REV_OFFSET 0x3F00
David Lechner68432b52021-01-11 13:24:44 -060034#define EEPROM_BDADDR_OFFSET 0x3F06
David Lechner2ac07f72016-02-26 00:46:07 -060035
David Lechner2ac07f72016-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
David Lechner2ac07f72016-02-26 00:46:07 -060054/*
David Lechner68432b52021-01-11 13:24:44 -060055 * The Bluetooth address serves as the board serial number.
David Lechner2ac07f72016-02-26 00:46:07 -060056 */
David Lechner68432b52021-01-11 13:24:44 -060057static void setup_serial_number(void)
David Lechner2ac07f72016-02-26 00:46:07 -060058{
59 u32 offset;
David Lechner68432b52021-01-11 13:24:44 -060060 char serial_number[13];
David Lechner2ac07f72016-02-26 00:46:07 -060061 u8 buf[6];
David Lechner68432b52021-01-11 13:24:44 -060062 u8 eeprom_rev;
David Lechner2ac07f72016-02-26 00:46:07 -060063
David Lechner68432b52021-01-11 13:24:44 -060064 if (env_get("serial#"))
65 return;
David Lechner2ac07f72016-02-26 00:46:07 -060066
David Lechner68432b52021-01-11 13:24:44 -060067 if (i2c_read(EEPROM_I2C_ADDR, EEPROM_REV_OFFSET, 2, buf, 2)) {
68 printf("\nEEPROM revision read failed!\n");
69 return;
70 }
71
72 /*
73 * EEPROM rev 3 has Bluetooth address at EEPROM_REV_OFFSET.
74 * Other revisions have checksum at EEPROM_REV_OFFSET+1
75 * to detect this.
76 */
77 if ((buf[0] ^ buf[1]) == 0xFF)
78 eeprom_rev = buf[0];
79 else
80 eeprom_rev = 3;
81
82 /* EEPROM rev 3 has Bluetooth address where rev should be */
83 offset = (eeprom_rev == 3) ? EEPROM_REV_OFFSET : EEPROM_BDADDR_OFFSET;
David Lechner2ac07f72016-02-26 00:46:07 -060084
85 if (i2c_read(EEPROM_I2C_ADDR, offset, 2, buf, 6)) {
David Lechner68432b52021-01-11 13:24:44 -060086 printf("\nEEPROM serial read failed!\n");
87 return;
David Lechner2ac07f72016-02-26 00:46:07 -060088 }
David Lechner68432b52021-01-11 13:24:44 -060089
90 sprintf(serial_number, "%02X%02X%02X%02X%02X%02X",
91 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
92
93 env_set("serial#", serial_number);
David Lechner2ac07f72016-02-26 00:46:07 -060094}
95
96int board_early_init_f(void)
97{
David Lechner648e87a2018-05-19 23:25:04 -050098 /* enable the console UART */
99 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
100 DAVINCI_UART_PWREMU_MGMT_UTRST),
101 &davinci_uart1_ctrl_regs->pwremu_mgmt);
102
David Lechner2ac07f72016-02-26 00:46:07 -0600103 /*
104 * Power on required peripherals
105 * ARM does not have access by default to PSC0 and PSC1
106 * assuming here that the DSP bootloader has set the IOPU
107 * such that PSC access is available to ARM
108 */
109 if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
110 return 1;
111
112 return 0;
113}
114
115int board_init(void)
116{
David Lechner2ac07f72016-02-26 00:46:07 -0600117 irq_init();
David Lechner2ac07f72016-02-26 00:46:07 -0600118
119 /* arch number of the board */
120 /* LEGO didn't register for a unique number and uses da850evm */
121 gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
122
123 /* address of boot parameters */
124 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
125
126 /* setup the SUSPSRC for ARM to control emulation suspend */
127 writel(readl(&davinci_syscfg_regs->suspsrc) &
David Lechner98ada4b2018-05-19 23:25:05 -0500128 ~(DAVINCI_SYSCFG_SUSPSRC_I2C |
David Lechner2ac07f72016-02-26 00:46:07 -0600129 DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
130 DAVINCI_SYSCFG_SUSPSRC_UART1),
131 &davinci_syscfg_regs->suspsrc);
132
133 /* configure pinmux settings */
134 if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
135 return 1;
136
David Lechner2ac07f72016-02-26 00:46:07 -0600137 return 0;
138}
David Lechner68432b52021-01-11 13:24:44 -0600139
140int board_late_init(void)
141{
142 setup_serial_number();
143
144 return 0;
145}