Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 2 | /* |
| 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 Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <common.h> |
David Lechner | 68432b5 | 2021-01-11 13:24:44 -0600 | [diff] [blame] | 16 | #include <env.h> |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 17 | #include <i2c.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 18 | #include <init.h> |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 19 | #include <spi.h> |
| 20 | #include <spi_flash.h> |
| 21 | #include <asm/arch/hardware.h> |
| 22 | #include <asm/arch/pinmux_defs.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 23 | #include <asm/global_data.h> |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 24 | #include <asm/io.h> |
| 25 | #include <asm/arch/davinci_misc.h> |
Masahiro Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 26 | #include <linux/errno.h> |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 27 | #include <hwconfig.h> |
Simon Glass | c62db35 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 28 | #include <asm/mach-types.h> |
Simon Glass | 5d98285 | 2017-05-17 08:23:00 -0600 | [diff] [blame] | 29 | #include <asm/setup.h> |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 30 | |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 33 | #define EEPROM_I2C_ADDR 0x50 |
| 34 | #define EEPROM_REV_OFFSET 0x3F00 |
David Lechner | 68432b5 | 2021-01-11 13:24:44 -0600 | [diff] [blame] | 35 | #define EEPROM_BDADDR_OFFSET 0x3F06 |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 36 | |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 37 | const struct pinmux_resource pinmuxes[] = { |
| 38 | PINMUX_ITEM(spi0_pins_base), |
| 39 | PINMUX_ITEM(spi0_pins_scs0), |
| 40 | PINMUX_ITEM(uart1_pins_txrx), |
| 41 | PINMUX_ITEM(i2c0_pins), |
| 42 | PINMUX_ITEM(mmc0_pins), |
| 43 | }; |
| 44 | |
| 45 | const int pinmuxes_size = ARRAY_SIZE(pinmuxes); |
| 46 | |
| 47 | const struct lpsc_resource lpsc[] = { |
| 48 | { DAVINCI_LPSC_SPI0 }, /* Serial Flash */ |
| 49 | { DAVINCI_LPSC_UART1 }, /* console */ |
| 50 | { DAVINCI_LPSC_MMC_SD }, |
| 51 | }; |
| 52 | |
| 53 | const int lpsc_size = ARRAY_SIZE(lpsc); |
| 54 | |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 55 | /* |
David Lechner | 68432b5 | 2021-01-11 13:24:44 -0600 | [diff] [blame] | 56 | * The Bluetooth address serves as the board serial number. |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 57 | */ |
David Lechner | 68432b5 | 2021-01-11 13:24:44 -0600 | [diff] [blame] | 58 | static void setup_serial_number(void) |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 59 | { |
| 60 | u32 offset; |
David Lechner | 68432b5 | 2021-01-11 13:24:44 -0600 | [diff] [blame] | 61 | char serial_number[13]; |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 62 | u8 buf[6]; |
David Lechner | 68432b5 | 2021-01-11 13:24:44 -0600 | [diff] [blame] | 63 | u8 eeprom_rev; |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 64 | |
David Lechner | 68432b5 | 2021-01-11 13:24:44 -0600 | [diff] [blame] | 65 | if (env_get("serial#")) |
| 66 | return; |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 67 | |
David Lechner | 68432b5 | 2021-01-11 13:24:44 -0600 | [diff] [blame] | 68 | if (i2c_read(EEPROM_I2C_ADDR, EEPROM_REV_OFFSET, 2, buf, 2)) { |
| 69 | printf("\nEEPROM revision read failed!\n"); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | * EEPROM rev 3 has Bluetooth address at EEPROM_REV_OFFSET. |
| 75 | * Other revisions have checksum at EEPROM_REV_OFFSET+1 |
| 76 | * to detect this. |
| 77 | */ |
| 78 | if ((buf[0] ^ buf[1]) == 0xFF) |
| 79 | eeprom_rev = buf[0]; |
| 80 | else |
| 81 | eeprom_rev = 3; |
| 82 | |
| 83 | /* EEPROM rev 3 has Bluetooth address where rev should be */ |
| 84 | offset = (eeprom_rev == 3) ? EEPROM_REV_OFFSET : EEPROM_BDADDR_OFFSET; |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 85 | |
| 86 | if (i2c_read(EEPROM_I2C_ADDR, offset, 2, buf, 6)) { |
David Lechner | 68432b5 | 2021-01-11 13:24:44 -0600 | [diff] [blame] | 87 | printf("\nEEPROM serial read failed!\n"); |
| 88 | return; |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 89 | } |
David Lechner | 68432b5 | 2021-01-11 13:24:44 -0600 | [diff] [blame] | 90 | |
| 91 | sprintf(serial_number, "%02X%02X%02X%02X%02X%02X", |
| 92 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); |
| 93 | |
| 94 | env_set("serial#", serial_number); |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | int board_early_init_f(void) |
| 98 | { |
David Lechner | 648e87a | 2018-05-19 23:25:04 -0500 | [diff] [blame] | 99 | /* enable the console UART */ |
| 100 | writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST | |
| 101 | DAVINCI_UART_PWREMU_MGMT_UTRST), |
| 102 | &davinci_uart1_ctrl_regs->pwremu_mgmt); |
| 103 | |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 104 | /* |
| 105 | * Power on required peripherals |
| 106 | * ARM does not have access by default to PSC0 and PSC1 |
| 107 | * assuming here that the DSP bootloader has set the IOPU |
| 108 | * such that PSC access is available to ARM |
| 109 | */ |
| 110 | if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc))) |
| 111 | return 1; |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | int board_init(void) |
| 117 | { |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 118 | irq_init(); |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 119 | |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 120 | /* address of boot parameters */ |
| 121 | gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR; |
| 122 | |
| 123 | /* setup the SUSPSRC for ARM to control emulation suspend */ |
| 124 | writel(readl(&davinci_syscfg_regs->suspsrc) & |
David Lechner | 98ada4b | 2018-05-19 23:25:05 -0500 | [diff] [blame] | 125 | ~(DAVINCI_SYSCFG_SUSPSRC_I2C | |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 126 | DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 | |
| 127 | DAVINCI_SYSCFG_SUSPSRC_UART1), |
| 128 | &davinci_syscfg_regs->suspsrc); |
| 129 | |
| 130 | /* configure pinmux settings */ |
| 131 | if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes))) |
| 132 | return 1; |
| 133 | |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 134 | return 0; |
| 135 | } |
David Lechner | 68432b5 | 2021-01-11 13:24:44 -0600 | [diff] [blame] | 136 | |
| 137 | int board_late_init(void) |
| 138 | { |
| 139 | setup_serial_number(); |
| 140 | |
| 141 | return 0; |
| 142 | } |