Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2011 |
| 4 | * Logic Product Development <www.logicpd.com> |
| 5 | * |
| 6 | * Author : |
| 7 | * Peter Barada <peter.barada@logicpd.com> |
| 8 | * |
| 9 | * Derived from Beagle Board and 3430 SDP code by |
| 10 | * Richard Woodruff <r-woodruff2@ti.com> |
| 11 | * Syed Mohammed Khasim <khasim@ti.com> |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 12 | */ |
| 13 | #include <common.h> |
Adam Ford | 04c848a | 2015-09-02 09:18:20 -0500 | [diff] [blame] | 14 | #include <dm.h> |
| 15 | #include <ns16550.h> |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 16 | #include <netdev.h> |
| 17 | #include <flash.h> |
| 18 | #include <nand.h> |
| 19 | #include <i2c.h> |
| 20 | #include <twl4030.h> |
| 21 | #include <asm/io.h> |
| 22 | #include <asm/arch/mmc_host_def.h> |
| 23 | #include <asm/arch/mux.h> |
| 24 | #include <asm/arch/mem.h> |
| 25 | #include <asm/arch/sys_proto.h> |
| 26 | #include <asm/gpio.h> |
Adam Ford | 39ce125 | 2018-08-21 10:43:30 -0500 | [diff] [blame] | 27 | #include <asm/omap_mmc.h> |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 28 | #include <asm/mach-types.h> |
Masahiro Yamada | 2b7a873 | 2017-11-30 13:45:24 +0900 | [diff] [blame] | 29 | #include <linux/mtd/rawnand.h> |
Adam Ford | d76b69c | 2016-01-31 13:34:39 -0600 | [diff] [blame] | 30 | #include <asm/omap_musb.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 31 | #include <linux/errno.h> |
Adam Ford | d76b69c | 2016-01-31 13:34:39 -0600 | [diff] [blame] | 32 | #include <linux/usb/ch9.h> |
| 33 | #include <linux/usb/gadget.h> |
| 34 | #include <linux/usb/musb.h> |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 35 | #include "omap3logic.h" |
Adam Ford | 0c5b44f | 2017-08-13 07:36:14 -0500 | [diff] [blame] | 36 | #ifdef CONFIG_USB_EHCI_HCD |
| 37 | #include <usb.h> |
| 38 | #include <asm/ehci-omap.h> |
| 39 | #endif |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 40 | |
| 41 | DECLARE_GLOBAL_DATA_PTR; |
| 42 | |
Adam Ford | 726ab5d | 2018-10-14 15:53:17 -0500 | [diff] [blame] | 43 | #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG1 0x00011203 |
| 44 | #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG2 0x000A1302 |
| 45 | #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG3 0x000F1302 |
| 46 | #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG4 0x0A021303 |
| 47 | #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG5 0x00120F18 |
| 48 | #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG6 0x0A030000 |
| 49 | #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG7 0x00000C50 |
| 50 | |
| 51 | #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG1 0x00011203 |
| 52 | #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG2 0x00091102 |
| 53 | #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG3 0x000D1102 |
| 54 | #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG4 0x09021103 |
| 55 | #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG5 0x00100D15 |
| 56 | #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG6 0x09030000 |
| 57 | #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG7 0x00000C50 |
| 58 | |
Adam Ford | 5326c29 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 59 | #ifdef CONFIG_SPL_OS_BOOT |
| 60 | int spl_start_uboot(void) |
| 61 | { |
| 62 | /* break into full u-boot on 'c' */ |
| 63 | return serial_tstc() && serial_getc() == 'c'; |
| 64 | } |
| 65 | #endif |
| 66 | |
| 67 | #if defined(CONFIG_SPL_BUILD) |
| 68 | /* |
| 69 | * Routine: get_board_mem_timings |
| 70 | * Description: If we use SPL then there is no x-loader nor config header |
| 71 | * so we have to setup the DDR timings ourself on the first bank. This |
| 72 | * provides the timing values back to the function that configures |
| 73 | * the memory. |
| 74 | */ |
| 75 | void get_board_mem_timings(struct board_sdrc_timings *timings) |
| 76 | { |
| 77 | timings->mr = MICRON_V_MR_165; |
Adam Ford | c369692 | 2018-10-07 09:20:45 -0500 | [diff] [blame] | 78 | |
| 79 | if (get_cpu_family() == CPU_OMAP36XX) { |
| 80 | /* 200 MHz works for OMAP36/DM37 */ |
| 81 | /* 256MB DDR */ |
| 82 | timings->mcfg = MICRON_V_MCFG_200(256 << 20); |
| 83 | timings->ctrla = MICRON_V_ACTIMA_200; |
| 84 | timings->ctrlb = MICRON_V_ACTIMB_200; |
| 85 | timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz; |
| 86 | } else { |
| 87 | /* 165 MHz works for OMAP35 */ |
| 88 | timings->mcfg = MICRON_V_MCFG_165(256 << 20); |
| 89 | timings->ctrla = MICRON_V_ACTIMA_165; |
| 90 | timings->ctrlb = MICRON_V_ACTIMB_165; |
| 91 | timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; |
| 92 | } |
Adam Ford | 5326c29 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 93 | } |
Adam Ford | 9968e4a | 2017-12-04 17:54:50 -0600 | [diff] [blame] | 94 | |
| 95 | #define GPMC_NAND_COMMAND_0 (OMAP34XX_GPMC_BASE + 0x7c) |
| 96 | #define GPMC_NAND_DATA_0 (OMAP34XX_GPMC_BASE + 0x84) |
| 97 | #define GPMC_NAND_ADDRESS_0 (OMAP34XX_GPMC_BASE + 0x80) |
| 98 | |
| 99 | void spl_board_prepare_for_linux(void) |
| 100 | { |
| 101 | /* The Micron NAND starts locked which |
| 102 | * prohibits mounting the NAND as RW |
| 103 | * The following commands are what unlocks |
| 104 | * the NAND to become RW Falcon Mode does not |
| 105 | * have as many smarts as U-Boot, but Logic PD |
| 106 | * only makes NAND with 512MB so these hard coded |
| 107 | * values should work for all current models |
| 108 | */ |
| 109 | |
| 110 | writeb(0x70, GPMC_NAND_COMMAND_0); |
| 111 | writeb(-1, GPMC_NAND_DATA_0); |
| 112 | writeb(0x7a, GPMC_NAND_COMMAND_0); |
| 113 | writeb(0x00, GPMC_NAND_ADDRESS_0); |
| 114 | writeb(0x00, GPMC_NAND_ADDRESS_0); |
| 115 | writeb(0x00, GPMC_NAND_ADDRESS_0); |
| 116 | writeb(-1, GPMC_NAND_COMMAND_0); |
| 117 | |
| 118 | /* Begin address 0 */ |
| 119 | writeb(NAND_CMD_UNLOCK1, 0x6e00007c); |
| 120 | writeb(0x00, GPMC_NAND_ADDRESS_0); |
| 121 | writeb(0x00, GPMC_NAND_ADDRESS_0); |
| 122 | writeb(0x00, GPMC_NAND_ADDRESS_0); |
| 123 | writeb(-1, GPMC_NAND_DATA_0); |
| 124 | |
| 125 | /* Ending address at the end of Flash */ |
| 126 | writeb(NAND_CMD_UNLOCK2, GPMC_NAND_COMMAND_0); |
| 127 | writeb(0xc0, GPMC_NAND_ADDRESS_0); |
| 128 | writeb(0xff, GPMC_NAND_ADDRESS_0); |
| 129 | writeb(0x03, GPMC_NAND_ADDRESS_0); |
| 130 | writeb(-1, GPMC_NAND_DATA_0); |
| 131 | writeb(0x79, GPMC_NAND_COMMAND_0); |
| 132 | writeb(-1, GPMC_NAND_DATA_0); |
| 133 | writeb(-1, GPMC_NAND_DATA_0); |
| 134 | } |
Adam Ford | 5326c29 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 135 | #endif |
| 136 | |
| 137 | /* |
| 138 | * Routine: misc_init_r |
| 139 | * Description: Configure board specific parts |
| 140 | */ |
| 141 | int misc_init_r(void) |
| 142 | { |
Adam Ford | 5326c29 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 143 | twl4030_power_init(); |
Adam Ford | ce51e84 | 2019-11-03 16:18:27 -0600 | [diff] [blame^] | 144 | twl4030_power_mmc_init(0); |
Adam Ford | 5326c29 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 145 | omap_die_id_display(); |
Adam Ford | 5326c29 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
Adam Ford | 726ab5d | 2018-10-14 15:53:17 -0500 | [diff] [blame] | 149 | #if defined(CONFIG_FLASH_CFI_DRIVER) |
| 150 | static const u32 gpmc_dm37_c2nor_config[] = { |
| 151 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG1, |
| 152 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG2, |
| 153 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG3, |
| 154 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG4, |
| 155 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG5, |
| 156 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG6, |
| 157 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG7 |
| 158 | }; |
| 159 | |
| 160 | static const u32 gpmc_omap35_c2nor_config[] = { |
| 161 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG1, |
| 162 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG2, |
| 163 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG3, |
| 164 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG4, |
| 165 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG5, |
| 166 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG6, |
| 167 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG7 |
| 168 | }; |
| 169 | #endif |
| 170 | |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 171 | /* |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 172 | * Routine: board_init |
| 173 | * Description: Early hardware init. |
| 174 | */ |
| 175 | int board_init(void) |
| 176 | { |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 177 | gpmc_init(); /* in SRAM or SDRAM, finish GPMC */ |
| 178 | |
| 179 | /* boot param addr */ |
| 180 | gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100); |
Adam Ford | 726ab5d | 2018-10-14 15:53:17 -0500 | [diff] [blame] | 181 | #if defined(CONFIG_FLASH_CFI_DRIVER) |
| 182 | if (get_cpu_family() == CPU_OMAP36XX) { |
| 183 | /* Enable CS2 for NOR Flash */ |
| 184 | enable_gpmc_cs_config(gpmc_dm37_c2nor_config, &gpmc_cfg->cs[2], |
| 185 | 0x10000000, GPMC_SIZE_64M); |
| 186 | } else { |
| 187 | enable_gpmc_cs_config(gpmc_omap35_c2nor_config, &gpmc_cfg->cs[2], |
| 188 | 0x10000000, GPMC_SIZE_64M); |
| 189 | } |
| 190 | #endif |
Tom Rini | 3a23c42 | 2017-01-10 17:22:05 -0500 | [diff] [blame] | 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | #ifdef CONFIG_BOARD_LATE_INIT |
Adam Ford | c176904 | 2017-12-03 06:24:53 -0600 | [diff] [blame] | 195 | |
| 196 | static void unlock_nand(void) |
| 197 | { |
| 198 | int dev = nand_curr_device; |
| 199 | struct mtd_info *mtd; |
| 200 | |
| 201 | mtd = get_nand_dev_by_index(dev); |
| 202 | nand_unlock(mtd, 0, mtd->size, 0); |
| 203 | } |
| 204 | |
Tom Rini | 3a23c42 | 2017-01-10 17:22:05 -0500 | [diff] [blame] | 205 | int board_late_init(void) |
| 206 | { |
Adam Ford | c176904 | 2017-12-03 06:24:53 -0600 | [diff] [blame] | 207 | #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK |
| 208 | unlock_nand(); |
| 209 | #endif |
Adam Ford | 60da8c3 | 2016-02-17 21:49:49 -0600 | [diff] [blame] | 210 | return 0; |
| 211 | } |
| 212 | #endif |
| 213 | |
Masahiro Yamada | 0a78017 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 214 | #if defined(CONFIG_MMC) |
Paul Kocialkowski | 6955989 | 2014-11-08 20:55:47 +0100 | [diff] [blame] | 215 | void board_mmc_power_init(void) |
| 216 | { |
| 217 | twl4030_power_mmc_init(0); |
| 218 | } |
| 219 | #endif |
| 220 | |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 221 | #ifdef CONFIG_SMC911X |
| 222 | /* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */ |
| 223 | static const u32 gpmc_lan92xx_config[] = { |
| 224 | NET_LAN92XX_GPMC_CONFIG1, |
| 225 | NET_LAN92XX_GPMC_CONFIG2, |
| 226 | NET_LAN92XX_GPMC_CONFIG3, |
| 227 | NET_LAN92XX_GPMC_CONFIG4, |
| 228 | NET_LAN92XX_GPMC_CONFIG5, |
| 229 | NET_LAN92XX_GPMC_CONFIG6, |
| 230 | }; |
| 231 | |
| 232 | int board_eth_init(bd_t *bis) |
| 233 | { |
| 234 | enable_gpmc_cs_config(gpmc_lan92xx_config, &gpmc_cfg->cs[1], |
| 235 | CONFIG_SMC911X_BASE, GPMC_SIZE_16M); |
| 236 | |
| 237 | return smc911x_initialize(0, CONFIG_SMC911X_BASE); |
| 238 | } |
| 239 | #endif |