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