David Lechner | a67f16f | 2016-02-26 00:46:07 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 David Lechner <david@lechnology.com> |
| 3 | * |
| 4 | * Based on da850evm.c |
| 5 | * |
| 6 | * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ |
| 7 | * |
| 8 | * Based on da830evm.c. Original Copyrights follow: |
| 9 | * |
| 10 | * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com> |
| 11 | * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net> |
| 12 | * |
| 13 | * SPDX-License-Identifier: GPL-2.0+ |
| 14 | */ |
| 15 | |
| 16 | #include <common.h> |
| 17 | #include <i2c.h> |
| 18 | #include <net.h> |
| 19 | #include <netdev.h> |
| 20 | #include <spi.h> |
| 21 | #include <spi_flash.h> |
| 22 | #include <asm/arch/hardware.h> |
| 23 | #include <asm/arch/pinmux_defs.h> |
| 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> |
| 28 | |
| 29 | #ifdef CONFIG_DAVINCI_MMC |
| 30 | #include <mmc.h> |
| 31 | #include <asm/arch/sdmmc_defs.h> |
| 32 | #endif |
| 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
| 36 | u8 board_rev; |
| 37 | |
| 38 | #define EEPROM_I2C_ADDR 0x50 |
| 39 | #define EEPROM_REV_OFFSET 0x3F00 |
| 40 | #define EEPROM_MAC_OFFSET 0x3F06 |
| 41 | |
| 42 | #ifdef CONFIG_DAVINCI_MMC |
| 43 | static struct davinci_mmc mmc_sd0 = { |
| 44 | .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE, |
| 45 | .host_caps = MMC_MODE_4BIT, /* DA850 supports only 4-bit SD/MMC */ |
| 46 | .voltages = MMC_VDD_32_33 | MMC_VDD_33_34, |
| 47 | .version = MMC_CTLR_VERSION_2, |
| 48 | }; |
| 49 | |
| 50 | int board_mmc_init(bd_t *bis) |
| 51 | { |
| 52 | mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID); |
| 53 | |
| 54 | /* Add slot-0 to mmc subsystem */ |
| 55 | return davinci_mmc_init(bis, &mmc_sd0); |
| 56 | } |
| 57 | #endif |
| 58 | |
| 59 | const struct pinmux_resource pinmuxes[] = { |
| 60 | PINMUX_ITEM(spi0_pins_base), |
| 61 | PINMUX_ITEM(spi0_pins_scs0), |
| 62 | PINMUX_ITEM(uart1_pins_txrx), |
| 63 | PINMUX_ITEM(i2c0_pins), |
| 64 | PINMUX_ITEM(mmc0_pins), |
| 65 | }; |
| 66 | |
| 67 | const int pinmuxes_size = ARRAY_SIZE(pinmuxes); |
| 68 | |
| 69 | const struct lpsc_resource lpsc[] = { |
| 70 | { DAVINCI_LPSC_SPI0 }, /* Serial Flash */ |
| 71 | { DAVINCI_LPSC_UART1 }, /* console */ |
| 72 | { DAVINCI_LPSC_MMC_SD }, |
| 73 | }; |
| 74 | |
| 75 | const int lpsc_size = ARRAY_SIZE(lpsc); |
| 76 | |
| 77 | u32 get_board_rev(void) |
| 78 | { |
| 79 | u8 buf[2]; |
| 80 | |
| 81 | if (!board_rev) { |
| 82 | if (i2c_read(EEPROM_I2C_ADDR, EEPROM_REV_OFFSET, 2, buf, 2)) { |
| 83 | printf("\nBoard revision read failed!\n"); |
| 84 | } else { |
| 85 | /* |
| 86 | * Board rev 3 has MAC address at EEPROM_REV_OFFSET. |
| 87 | * Other revisions have checksum at EEPROM_REV_OFFSET+1 |
| 88 | * to detect this. |
| 89 | */ |
| 90 | if ((buf[0] ^ buf[1]) == 0xFF) |
| 91 | board_rev = buf[0]; |
| 92 | else |
| 93 | board_rev = 3; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return board_rev; |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * The Bluetooth MAC address serves as the board serial number. |
| 102 | */ |
| 103 | void get_board_serial(struct tag_serialnr *serialnr) |
| 104 | { |
| 105 | u32 offset; |
| 106 | u8 buf[6]; |
| 107 | |
| 108 | if (!board_rev) |
| 109 | board_rev = get_board_rev(); |
| 110 | |
| 111 | /* Board rev 3 has MAC address where rev should be */ |
| 112 | offset = (board_rev == 3) ? EEPROM_REV_OFFSET : EEPROM_MAC_OFFSET; |
| 113 | |
| 114 | if (i2c_read(EEPROM_I2C_ADDR, offset, 2, buf, 6)) { |
| 115 | printf("\nBoard serial read failed!\n"); |
| 116 | } else { |
| 117 | u8 *nr; |
| 118 | |
| 119 | nr = (u8 *)&serialnr->low; |
| 120 | nr[0] = buf[5]; |
| 121 | nr[1] = buf[4]; |
| 122 | nr[2] = buf[3]; |
| 123 | nr[3] = buf[2]; |
| 124 | nr = (u8 *)&serialnr->high; |
| 125 | nr[0] = buf[1]; |
| 126 | nr[1] = buf[0]; |
| 127 | nr[2] = 0; |
| 128 | nr[3] = 0; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | int board_early_init_f(void) |
| 133 | { |
| 134 | /* |
| 135 | * Power on required peripherals |
| 136 | * ARM does not have access by default to PSC0 and PSC1 |
| 137 | * assuming here that the DSP bootloader has set the IOPU |
| 138 | * such that PSC access is available to ARM |
| 139 | */ |
| 140 | if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc))) |
| 141 | return 1; |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | int board_init(void) |
| 147 | { |
| 148 | #ifndef CONFIG_USE_IRQ |
| 149 | irq_init(); |
| 150 | #endif |
| 151 | |
| 152 | /* arch number of the board */ |
| 153 | /* LEGO didn't register for a unique number and uses da850evm */ |
| 154 | gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM; |
| 155 | |
| 156 | /* address of boot parameters */ |
| 157 | gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR; |
| 158 | |
| 159 | /* setup the SUSPSRC for ARM to control emulation suspend */ |
| 160 | writel(readl(&davinci_syscfg_regs->suspsrc) & |
| 161 | ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C | |
| 162 | DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 | |
| 163 | DAVINCI_SYSCFG_SUSPSRC_UART1), |
| 164 | &davinci_syscfg_regs->suspsrc); |
| 165 | |
| 166 | /* configure pinmux settings */ |
| 167 | if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes))) |
| 168 | return 1; |
| 169 | |
| 170 | /* enable the console UART */ |
| 171 | writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST | |
| 172 | DAVINCI_UART_PWREMU_MGMT_UTRST), |
| 173 | &davinci_uart1_ctrl_regs->pwremu_mgmt); |
| 174 | |
| 175 | return 0; |
| 176 | } |