Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peter Barada | 86887f8 | 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 | 86887f8 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 12 | */ |
| 13 | #include <common.h> |
Adam Ford | 7b77b1f | 2015-09-02 09:18:20 -0500 | [diff] [blame] | 14 | #include <dm.h> |
| 15 | #include <ns16550.h> |
Peter Barada | 86887f8 | 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 | 4869fa3 | 2018-08-21 10:43:30 -0500 | [diff] [blame] | 27 | #include <asm/omap_mmc.h> |
Peter Barada | 86887f8 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 28 | #include <asm/mach-types.h> |
Masahiro Yamada | 6ae3900 | 2017-11-30 13:45:24 +0900 | [diff] [blame] | 29 | #include <linux/mtd/rawnand.h> |
Adam Ford | 588e41d | 2016-01-31 13:34:39 -0600 | [diff] [blame] | 30 | #include <asm/omap_musb.h> |
Masahiro Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 31 | #include <linux/errno.h> |
Adam Ford | 588e41d | 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 | 86887f8 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 35 | #include "omap3logic.h" |
Adam Ford | 74cd48e | 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 | 86887f8 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 40 | |
| 41 | DECLARE_GLOBAL_DATA_PTR; |
| 42 | |
Adam Ford | 290097f | 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 | 4869fa3 | 2018-08-21 10:43:30 -0500 | [diff] [blame] | 59 | /* This is only needed until SPL gets OF support */ |
| 60 | #ifdef CONFIG_SPL_BUILD |
| 61 | static const struct ns16550_platdata omap3logic_serial = { |
| 62 | .base = OMAP34XX_UART1, |
| 63 | .reg_shift = 2, |
| 64 | .clock = V_NS16550_CLK, |
| 65 | .fcr = UART_FCR_DEFVAL, |
| 66 | }; |
| 67 | |
| 68 | U_BOOT_DEVICE(omap3logic_uart) = { |
Adam Ford | c3aa851 | 2018-10-07 17:42:42 -0500 | [diff] [blame] | 69 | "omap_serial", |
Adam Ford | 4869fa3 | 2018-08-21 10:43:30 -0500 | [diff] [blame] | 70 | &omap3logic_serial |
| 71 | }; |
| 72 | |
| 73 | static const struct omap_hsmmc_plat omap3_logic_mmc0_platdata = { |
| 74 | .base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE, |
| 75 | .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_4BIT, |
| 76 | .cfg.f_min = 400000, |
| 77 | .cfg.f_max = 52000000, |
| 78 | .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195, |
| 79 | .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT, |
| 80 | }; |
| 81 | |
Adam Ford | 6482095 | 2018-10-07 17:47:50 -0500 | [diff] [blame] | 82 | U_BOOT_DEVICE(omap3_logic_mmc0) = { |
Adam Ford | 4869fa3 | 2018-08-21 10:43:30 -0500 | [diff] [blame] | 83 | .name = "omap_hsmmc", |
| 84 | .platdata = &omap3_logic_mmc0_platdata, |
| 85 | }; |
| 86 | |
| 87 | #endif |
| 88 | |
Adam Ford | 49c7303 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 89 | #ifdef CONFIG_SPL_OS_BOOT |
| 90 | int spl_start_uboot(void) |
| 91 | { |
| 92 | /* break into full u-boot on 'c' */ |
| 93 | return serial_tstc() && serial_getc() == 'c'; |
| 94 | } |
| 95 | #endif |
| 96 | |
| 97 | #if defined(CONFIG_SPL_BUILD) |
| 98 | /* |
| 99 | * Routine: get_board_mem_timings |
| 100 | * Description: If we use SPL then there is no x-loader nor config header |
| 101 | * so we have to setup the DDR timings ourself on the first bank. This |
| 102 | * provides the timing values back to the function that configures |
| 103 | * the memory. |
| 104 | */ |
| 105 | void get_board_mem_timings(struct board_sdrc_timings *timings) |
| 106 | { |
| 107 | timings->mr = MICRON_V_MR_165; |
Adam Ford | 169eb19 | 2018-10-07 09:20:45 -0500 | [diff] [blame] | 108 | |
| 109 | if (get_cpu_family() == CPU_OMAP36XX) { |
| 110 | /* 200 MHz works for OMAP36/DM37 */ |
| 111 | /* 256MB DDR */ |
| 112 | timings->mcfg = MICRON_V_MCFG_200(256 << 20); |
| 113 | timings->ctrla = MICRON_V_ACTIMA_200; |
| 114 | timings->ctrlb = MICRON_V_ACTIMB_200; |
| 115 | timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz; |
| 116 | } else { |
| 117 | /* 165 MHz works for OMAP35 */ |
| 118 | timings->mcfg = MICRON_V_MCFG_165(256 << 20); |
| 119 | timings->ctrla = MICRON_V_ACTIMA_165; |
| 120 | timings->ctrlb = MICRON_V_ACTIMB_165; |
| 121 | timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; |
| 122 | } |
Adam Ford | 49c7303 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 123 | } |
Adam Ford | 6032c02 | 2017-12-04 17:54:50 -0600 | [diff] [blame] | 124 | |
| 125 | #define GPMC_NAND_COMMAND_0 (OMAP34XX_GPMC_BASE + 0x7c) |
| 126 | #define GPMC_NAND_DATA_0 (OMAP34XX_GPMC_BASE + 0x84) |
| 127 | #define GPMC_NAND_ADDRESS_0 (OMAP34XX_GPMC_BASE + 0x80) |
| 128 | |
| 129 | void spl_board_prepare_for_linux(void) |
| 130 | { |
| 131 | /* The Micron NAND starts locked which |
| 132 | * prohibits mounting the NAND as RW |
| 133 | * The following commands are what unlocks |
| 134 | * the NAND to become RW Falcon Mode does not |
| 135 | * have as many smarts as U-Boot, but Logic PD |
| 136 | * only makes NAND with 512MB so these hard coded |
| 137 | * values should work for all current models |
| 138 | */ |
| 139 | |
| 140 | writeb(0x70, GPMC_NAND_COMMAND_0); |
| 141 | writeb(-1, GPMC_NAND_DATA_0); |
| 142 | writeb(0x7a, GPMC_NAND_COMMAND_0); |
| 143 | writeb(0x00, GPMC_NAND_ADDRESS_0); |
| 144 | writeb(0x00, GPMC_NAND_ADDRESS_0); |
| 145 | writeb(0x00, GPMC_NAND_ADDRESS_0); |
| 146 | writeb(-1, GPMC_NAND_COMMAND_0); |
| 147 | |
| 148 | /* Begin address 0 */ |
| 149 | writeb(NAND_CMD_UNLOCK1, 0x6e00007c); |
| 150 | writeb(0x00, GPMC_NAND_ADDRESS_0); |
| 151 | writeb(0x00, GPMC_NAND_ADDRESS_0); |
| 152 | writeb(0x00, GPMC_NAND_ADDRESS_0); |
| 153 | writeb(-1, GPMC_NAND_DATA_0); |
| 154 | |
| 155 | /* Ending address at the end of Flash */ |
| 156 | writeb(NAND_CMD_UNLOCK2, GPMC_NAND_COMMAND_0); |
| 157 | writeb(0xc0, GPMC_NAND_ADDRESS_0); |
| 158 | writeb(0xff, GPMC_NAND_ADDRESS_0); |
| 159 | writeb(0x03, GPMC_NAND_ADDRESS_0); |
| 160 | writeb(-1, GPMC_NAND_DATA_0); |
| 161 | writeb(0x79, GPMC_NAND_COMMAND_0); |
| 162 | writeb(-1, GPMC_NAND_DATA_0); |
| 163 | writeb(-1, GPMC_NAND_DATA_0); |
| 164 | } |
Adam Ford | 49c7303 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 165 | #endif |
| 166 | |
Adam Ford | f4db3b6 | 2018-10-07 17:39:29 -0500 | [diff] [blame] | 167 | #if !CONFIG_IS_ENABLED(DM_USB) |
Adam Ford | 588e41d | 2016-01-31 13:34:39 -0600 | [diff] [blame] | 168 | #ifdef CONFIG_USB_MUSB_OMAP2PLUS |
| 169 | static struct musb_hdrc_config musb_config = { |
| 170 | .multipoint = 1, |
| 171 | .dyn_fifo = 1, |
| 172 | .num_eps = 16, |
| 173 | .ram_bits = 12, |
| 174 | }; |
| 175 | |
| 176 | static struct omap_musb_board_data musb_board_data = { |
| 177 | .interface_type = MUSB_INTERFACE_ULPI, |
| 178 | }; |
| 179 | |
| 180 | static struct musb_hdrc_platform_data musb_plat = { |
| 181 | #if defined(CONFIG_USB_MUSB_HOST) |
| 182 | .mode = MUSB_HOST, |
| 183 | #elif defined(CONFIG_USB_MUSB_GADGET) |
| 184 | .mode = MUSB_PERIPHERAL, |
| 185 | #else |
| 186 | #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET" |
| 187 | #endif |
| 188 | .config = &musb_config, |
| 189 | .power = 100, |
| 190 | .platform_ops = &omap2430_ops, |
| 191 | .board_data = &musb_board_data, |
| 192 | }; |
| 193 | #endif |
| 194 | |
Adam Ford | 74cd48e | 2017-08-13 07:36:14 -0500 | [diff] [blame] | 195 | #if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD) |
| 196 | /* Call usb_stop() before starting the kernel */ |
| 197 | void show_boot_progress(int val) |
| 198 | { |
| 199 | if (val == BOOTSTAGE_ID_RUN_OS) |
| 200 | usb_stop(); |
| 201 | } |
| 202 | |
| 203 | static struct omap_usbhs_board_data usbhs_bdata = { |
| 204 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
| 205 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
| 206 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED |
| 207 | }; |
| 208 | |
| 209 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 210 | struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
| 211 | { |
| 212 | return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor); |
| 213 | } |
| 214 | |
| 215 | int ehci_hcd_stop(int index) |
| 216 | { |
| 217 | return omap_ehci_hcd_stop(); |
| 218 | } |
| 219 | |
| 220 | #endif /* CONFIG_USB_EHCI_HCD */ |
Adam Ford | f4db3b6 | 2018-10-07 17:39:29 -0500 | [diff] [blame] | 221 | #endif /* !DM_USB*/ |
Adam Ford | 49c7303 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 222 | /* |
| 223 | * Routine: misc_init_r |
| 224 | * Description: Configure board specific parts |
| 225 | */ |
| 226 | int misc_init_r(void) |
| 227 | { |
Adam Ford | 49c7303 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 228 | twl4030_power_init(); |
Adam Ford | 49c7303 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 229 | omap_die_id_display(); |
Adam Ford | 49c7303 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 230 | |
Adam Ford | f4db3b6 | 2018-10-07 17:39:29 -0500 | [diff] [blame] | 231 | #if !CONFIG_IS_ENABLED(DM_USB) |
Adam Ford | 588e41d | 2016-01-31 13:34:39 -0600 | [diff] [blame] | 232 | #ifdef CONFIG_USB_MUSB_OMAP2PLUS |
| 233 | musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE); |
| 234 | #endif |
Adam Ford | f4db3b6 | 2018-10-07 17:39:29 -0500 | [diff] [blame] | 235 | #endif |
Adam Ford | 49c7303 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 236 | return 0; |
| 237 | } |
| 238 | |
Adam Ford | 290097f | 2018-10-14 15:53:17 -0500 | [diff] [blame] | 239 | #if defined(CONFIG_FLASH_CFI_DRIVER) |
| 240 | static const u32 gpmc_dm37_c2nor_config[] = { |
| 241 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG1, |
| 242 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG2, |
| 243 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG3, |
| 244 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG4, |
| 245 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG5, |
| 246 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG6, |
| 247 | LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG7 |
| 248 | }; |
| 249 | |
| 250 | static const u32 gpmc_omap35_c2nor_config[] = { |
| 251 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG1, |
| 252 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG2, |
| 253 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG3, |
| 254 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG4, |
| 255 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG5, |
| 256 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG6, |
| 257 | LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG7 |
| 258 | }; |
| 259 | #endif |
| 260 | |
Peter Barada | 86887f8 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 261 | /* |
Peter Barada | 86887f8 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 262 | * Routine: board_init |
| 263 | * Description: Early hardware init. |
| 264 | */ |
| 265 | int board_init(void) |
| 266 | { |
Peter Barada | 86887f8 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 267 | gpmc_init(); /* in SRAM or SDRAM, finish GPMC */ |
| 268 | |
| 269 | /* boot param addr */ |
| 270 | gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100); |
Adam Ford | 290097f | 2018-10-14 15:53:17 -0500 | [diff] [blame] | 271 | #if defined(CONFIG_FLASH_CFI_DRIVER) |
| 272 | if (get_cpu_family() == CPU_OMAP36XX) { |
| 273 | /* Enable CS2 for NOR Flash */ |
| 274 | enable_gpmc_cs_config(gpmc_dm37_c2nor_config, &gpmc_cfg->cs[2], |
| 275 | 0x10000000, GPMC_SIZE_64M); |
| 276 | } else { |
| 277 | enable_gpmc_cs_config(gpmc_omap35_c2nor_config, &gpmc_cfg->cs[2], |
| 278 | 0x10000000, GPMC_SIZE_64M); |
| 279 | } |
| 280 | #endif |
Tom Rini | c63d270 | 2017-01-10 17:22:05 -0500 | [diff] [blame] | 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | #ifdef CONFIG_BOARD_LATE_INIT |
Adam Ford | 157af4f | 2017-12-03 06:24:53 -0600 | [diff] [blame] | 285 | |
| 286 | static void unlock_nand(void) |
| 287 | { |
| 288 | int dev = nand_curr_device; |
| 289 | struct mtd_info *mtd; |
| 290 | |
| 291 | mtd = get_nand_dev_by_index(dev); |
| 292 | nand_unlock(mtd, 0, mtd->size, 0); |
| 293 | } |
| 294 | |
Tom Rini | c63d270 | 2017-01-10 17:22:05 -0500 | [diff] [blame] | 295 | int board_late_init(void) |
| 296 | { |
Adam Ford | 157af4f | 2017-12-03 06:24:53 -0600 | [diff] [blame] | 297 | #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK |
| 298 | unlock_nand(); |
| 299 | #endif |
Adam Ford | 26ef7a2 | 2016-02-17 21:49:49 -0600 | [diff] [blame] | 300 | return 0; |
| 301 | } |
| 302 | #endif |
| 303 | |
Masahiro Yamada | 4aa2ba3 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 304 | #if defined(CONFIG_MMC) |
Paul Kocialkowski | aac5450 | 2014-11-08 20:55:47 +0100 | [diff] [blame] | 305 | void board_mmc_power_init(void) |
| 306 | { |
| 307 | twl4030_power_mmc_init(0); |
| 308 | } |
| 309 | #endif |
| 310 | |
Peter Barada | 86887f8 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 311 | #ifdef CONFIG_SMC911X |
| 312 | /* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */ |
| 313 | static const u32 gpmc_lan92xx_config[] = { |
| 314 | NET_LAN92XX_GPMC_CONFIG1, |
| 315 | NET_LAN92XX_GPMC_CONFIG2, |
| 316 | NET_LAN92XX_GPMC_CONFIG3, |
| 317 | NET_LAN92XX_GPMC_CONFIG4, |
| 318 | NET_LAN92XX_GPMC_CONFIG5, |
| 319 | NET_LAN92XX_GPMC_CONFIG6, |
| 320 | }; |
| 321 | |
| 322 | int board_eth_init(bd_t *bis) |
| 323 | { |
| 324 | enable_gpmc_cs_config(gpmc_lan92xx_config, &gpmc_cfg->cs[1], |
| 325 | CONFIG_SMC911X_BASE, GPMC_SIZE_16M); |
| 326 | |
| 327 | return smc911x_initialize(0, CONFIG_SMC911X_BASE); |
| 328 | } |
| 329 | #endif |