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> |
| 16 | #include <i2c.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 17 | #include <init.h> |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 18 | #include <spi.h> |
| 19 | #include <spi_flash.h> |
| 20 | #include <asm/arch/hardware.h> |
| 21 | #include <asm/arch/pinmux_defs.h> |
| 22 | #include <asm/io.h> |
| 23 | #include <asm/arch/davinci_misc.h> |
Masahiro Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 24 | #include <linux/errno.h> |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 25 | #include <hwconfig.h> |
Simon Glass | c62db35 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 26 | #include <asm/mach-types.h> |
Simon Glass | 5d98285 | 2017-05-17 08:23:00 -0600 | [diff] [blame] | 27 | #include <asm/setup.h> |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 28 | |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
| 31 | u8 board_rev; |
| 32 | |
| 33 | #define EEPROM_I2C_ADDR 0x50 |
| 34 | #define EEPROM_REV_OFFSET 0x3F00 |
| 35 | #define EEPROM_MAC_OFFSET 0x3F06 |
| 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 | |
| 55 | u32 get_board_rev(void) |
| 56 | { |
| 57 | u8 buf[2]; |
| 58 | |
| 59 | if (!board_rev) { |
| 60 | if (i2c_read(EEPROM_I2C_ADDR, EEPROM_REV_OFFSET, 2, buf, 2)) { |
| 61 | printf("\nBoard revision read failed!\n"); |
| 62 | } else { |
| 63 | /* |
| 64 | * Board rev 3 has MAC address at EEPROM_REV_OFFSET. |
| 65 | * Other revisions have checksum at EEPROM_REV_OFFSET+1 |
| 66 | * to detect this. |
| 67 | */ |
| 68 | if ((buf[0] ^ buf[1]) == 0xFF) |
| 69 | board_rev = buf[0]; |
| 70 | else |
| 71 | board_rev = 3; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return board_rev; |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * The Bluetooth MAC address serves as the board serial number. |
| 80 | */ |
| 81 | void get_board_serial(struct tag_serialnr *serialnr) |
| 82 | { |
| 83 | u32 offset; |
| 84 | u8 buf[6]; |
| 85 | |
| 86 | if (!board_rev) |
| 87 | board_rev = get_board_rev(); |
| 88 | |
| 89 | /* Board rev 3 has MAC address where rev should be */ |
| 90 | offset = (board_rev == 3) ? EEPROM_REV_OFFSET : EEPROM_MAC_OFFSET; |
| 91 | |
| 92 | if (i2c_read(EEPROM_I2C_ADDR, offset, 2, buf, 6)) { |
| 93 | printf("\nBoard serial read failed!\n"); |
| 94 | } else { |
| 95 | u8 *nr; |
| 96 | |
| 97 | nr = (u8 *)&serialnr->low; |
| 98 | nr[0] = buf[5]; |
| 99 | nr[1] = buf[4]; |
| 100 | nr[2] = buf[3]; |
| 101 | nr[3] = buf[2]; |
| 102 | nr = (u8 *)&serialnr->high; |
| 103 | nr[0] = buf[1]; |
| 104 | nr[1] = buf[0]; |
| 105 | nr[2] = 0; |
| 106 | nr[3] = 0; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | int board_early_init_f(void) |
| 111 | { |
David Lechner | 648e87a | 2018-05-19 23:25:04 -0500 | [diff] [blame] | 112 | /* enable the console UART */ |
| 113 | writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST | |
| 114 | DAVINCI_UART_PWREMU_MGMT_UTRST), |
| 115 | &davinci_uart1_ctrl_regs->pwremu_mgmt); |
| 116 | |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 117 | /* |
| 118 | * Power on required peripherals |
| 119 | * ARM does not have access by default to PSC0 and PSC1 |
| 120 | * assuming here that the DSP bootloader has set the IOPU |
| 121 | * such that PSC access is available to ARM |
| 122 | */ |
| 123 | if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc))) |
| 124 | return 1; |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | int board_init(void) |
| 130 | { |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 131 | irq_init(); |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 132 | |
| 133 | /* arch number of the board */ |
| 134 | /* LEGO didn't register for a unique number and uses da850evm */ |
| 135 | gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM; |
| 136 | |
| 137 | /* address of boot parameters */ |
| 138 | gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR; |
| 139 | |
| 140 | /* setup the SUSPSRC for ARM to control emulation suspend */ |
| 141 | writel(readl(&davinci_syscfg_regs->suspsrc) & |
David Lechner | 98ada4b | 2018-05-19 23:25:05 -0500 | [diff] [blame] | 142 | ~(DAVINCI_SYSCFG_SUSPSRC_I2C | |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 143 | DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 | |
| 144 | DAVINCI_SYSCFG_SUSPSRC_UART1), |
| 145 | &davinci_syscfg_regs->suspsrc); |
| 146 | |
| 147 | /* configure pinmux settings */ |
| 148 | if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes))) |
| 149 | return 1; |
| 150 | |
David Lechner | 2ac07f7 | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 151 | return 0; |
| 152 | } |