Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2011 |
| 3 | * Logic Product Development <www.logicpd.com> |
| 4 | * |
| 5 | * Author : |
| 6 | * Peter Barada <peter.barada@logicpd.com> |
| 7 | * |
| 8 | * Derived from Beagle Board and 3430 SDP code by |
| 9 | * Richard Woodruff <r-woodruff2@ti.com> |
| 10 | * Syed Mohammed Khasim <khasim@ti.com> |
| 11 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 12 | * SPDX-License-Identifier: GPL-2.0+ |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 13 | */ |
| 14 | #include <common.h> |
Adam Ford | 04c848a | 2015-09-02 09:18:20 -0500 | [diff] [blame] | 15 | #include <dm.h> |
| 16 | #include <ns16550.h> |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 17 | #include <netdev.h> |
| 18 | #include <flash.h> |
| 19 | #include <nand.h> |
| 20 | #include <i2c.h> |
| 21 | #include <twl4030.h> |
| 22 | #include <asm/io.h> |
| 23 | #include <asm/arch/mmc_host_def.h> |
| 24 | #include <asm/arch/mux.h> |
| 25 | #include <asm/arch/mem.h> |
| 26 | #include <asm/arch/sys_proto.h> |
| 27 | #include <asm/gpio.h> |
| 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 | 55bdf92 | 2017-04-17 08:09:45 -0500 | [diff] [blame] | 43 | /* This is only needed until SPL gets OF support */ |
| 44 | #ifdef CONFIG_SPL_BUILD |
Adam Ford | 04c848a | 2015-09-02 09:18:20 -0500 | [diff] [blame] | 45 | static const struct ns16550_platdata omap3logic_serial = { |
Adam Ford | d1e22fa | 2016-03-07 21:08:49 -0600 | [diff] [blame] | 46 | .base = OMAP34XX_UART1, |
| 47 | .reg_shift = 2, |
Heiko Schocher | 06f108e | 2017-01-18 08:05:49 +0100 | [diff] [blame] | 48 | .clock = V_NS16550_CLK, |
| 49 | .fcr = UART_FCR_DEFVAL, |
Adam Ford | 04c848a | 2015-09-02 09:18:20 -0500 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | U_BOOT_DEVICE(omap3logic_uart) = { |
Thomas Chou | 52ac443 | 2015-11-19 21:48:12 +0800 | [diff] [blame] | 53 | "ns16550_serial", |
Adam Ford | 04c848a | 2015-09-02 09:18:20 -0500 | [diff] [blame] | 54 | &omap3logic_serial |
| 55 | }; |
Adam Ford | 55bdf92 | 2017-04-17 08:09:45 -0500 | [diff] [blame] | 56 | #endif |
Adam Ford | 04c848a | 2015-09-02 09:18:20 -0500 | [diff] [blame] | 57 | |
Adam Ford | 55bdf92 | 2017-04-17 08:09:45 -0500 | [diff] [blame] | 58 | /* |
| 59 | * two dimensional array of strucures containining board name and Linux |
| 60 | * machine IDs; row it selected based on CPU column is slected based |
| 61 | * on hsusb0_data5 pin having a pulldown resistor |
| 62 | */ |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 63 | static struct board_id { |
| 64 | char *name; |
| 65 | int machine_id; |
Tom Rini | 3a23c42 | 2017-01-10 17:22:05 -0500 | [diff] [blame] | 66 | char *fdtfile; |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 67 | } boards[2][2] = { |
| 68 | { |
| 69 | { |
| 70 | .name = "OMAP35xx SOM LV", |
| 71 | .machine_id = MACH_TYPE_OMAP3530_LV_SOM, |
Tom Rini | 3a23c42 | 2017-01-10 17:22:05 -0500 | [diff] [blame] | 72 | .fdtfile = "logicpd-som-lv-35xx-devkit.dtb", |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 73 | }, |
| 74 | { |
| 75 | .name = "OMAP35xx Torpedo", |
| 76 | .machine_id = MACH_TYPE_OMAP3_TORPEDO, |
Tom Rini | 3a23c42 | 2017-01-10 17:22:05 -0500 | [diff] [blame] | 77 | .fdtfile = "logicpd-torpedo-35xx-devkit.dtb", |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 78 | }, |
| 79 | }, |
| 80 | { |
| 81 | { |
| 82 | .name = "DM37xx SOM LV", |
Tom Rini | 3a23c42 | 2017-01-10 17:22:05 -0500 | [diff] [blame] | 83 | .fdtfile = "logicpd-som-lv-37xx-devkit.dtb", |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 84 | }, |
| 85 | { |
| 86 | .name = "DM37xx Torpedo", |
Tom Rini | 3a23c42 | 2017-01-10 17:22:05 -0500 | [diff] [blame] | 87 | .fdtfile = "logicpd-torpedo-37xx-devkit.dtb", |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 88 | }, |
| 89 | }, |
| 90 | }; |
| 91 | |
Adam Ford | 5326c29 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 92 | #ifdef CONFIG_SPL_OS_BOOT |
| 93 | int spl_start_uboot(void) |
| 94 | { |
| 95 | /* break into full u-boot on 'c' */ |
| 96 | return serial_tstc() && serial_getc() == 'c'; |
| 97 | } |
| 98 | #endif |
| 99 | |
| 100 | #if defined(CONFIG_SPL_BUILD) |
| 101 | /* |
| 102 | * Routine: get_board_mem_timings |
| 103 | * Description: If we use SPL then there is no x-loader nor config header |
| 104 | * so we have to setup the DDR timings ourself on the first bank. This |
| 105 | * provides the timing values back to the function that configures |
| 106 | * the memory. |
| 107 | */ |
| 108 | void get_board_mem_timings(struct board_sdrc_timings *timings) |
| 109 | { |
| 110 | timings->mr = MICRON_V_MR_165; |
| 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 | } |
| 117 | #endif |
| 118 | |
Adam Ford | d76b69c | 2016-01-31 13:34:39 -0600 | [diff] [blame] | 119 | #ifdef CONFIG_USB_MUSB_OMAP2PLUS |
| 120 | static struct musb_hdrc_config musb_config = { |
| 121 | .multipoint = 1, |
| 122 | .dyn_fifo = 1, |
| 123 | .num_eps = 16, |
| 124 | .ram_bits = 12, |
| 125 | }; |
| 126 | |
| 127 | static struct omap_musb_board_data musb_board_data = { |
| 128 | .interface_type = MUSB_INTERFACE_ULPI, |
| 129 | }; |
| 130 | |
| 131 | static struct musb_hdrc_platform_data musb_plat = { |
| 132 | #if defined(CONFIG_USB_MUSB_HOST) |
| 133 | .mode = MUSB_HOST, |
| 134 | #elif defined(CONFIG_USB_MUSB_GADGET) |
| 135 | .mode = MUSB_PERIPHERAL, |
| 136 | #else |
| 137 | #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET" |
| 138 | #endif |
| 139 | .config = &musb_config, |
| 140 | .power = 100, |
| 141 | .platform_ops = &omap2430_ops, |
| 142 | .board_data = &musb_board_data, |
| 143 | }; |
| 144 | #endif |
| 145 | |
Adam Ford | 0c5b44f | 2017-08-13 07:36:14 -0500 | [diff] [blame] | 146 | #if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD) |
| 147 | /* Call usb_stop() before starting the kernel */ |
| 148 | void show_boot_progress(int val) |
| 149 | { |
| 150 | if (val == BOOTSTAGE_ID_RUN_OS) |
| 151 | usb_stop(); |
| 152 | } |
| 153 | |
| 154 | static struct omap_usbhs_board_data usbhs_bdata = { |
| 155 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
| 156 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
| 157 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED |
| 158 | }; |
| 159 | |
| 160 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 161 | struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
| 162 | { |
| 163 | return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor); |
| 164 | } |
| 165 | |
| 166 | int ehci_hcd_stop(int index) |
| 167 | { |
| 168 | return omap_ehci_hcd_stop(); |
| 169 | } |
| 170 | |
| 171 | #endif /* CONFIG_USB_EHCI_HCD */ |
| 172 | |
Adam Ford | d76b69c | 2016-01-31 13:34:39 -0600 | [diff] [blame] | 173 | |
Adam Ford | 5326c29 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 174 | /* |
| 175 | * Routine: misc_init_r |
| 176 | * Description: Configure board specific parts |
| 177 | */ |
| 178 | int misc_init_r(void) |
| 179 | { |
Adam Ford | 5326c29 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 180 | twl4030_power_init(); |
Adam Ford | 5326c29 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 181 | omap_die_id_display(); |
Adam Ford | 5326c29 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 182 | |
Adam Ford | d76b69c | 2016-01-31 13:34:39 -0600 | [diff] [blame] | 183 | #ifdef CONFIG_USB_MUSB_OMAP2PLUS |
| 184 | musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE); |
| 185 | #endif |
| 186 | |
Adam Ford | 5326c29 | 2016-01-29 20:12:34 -0600 | [diff] [blame] | 187 | return 0; |
| 188 | } |
| 189 | |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 190 | /* |
| 191 | * BOARD_ID_GPIO - GPIO of pin with optional pulldown resistor on SOM LV |
| 192 | */ |
| 193 | #define BOARD_ID_GPIO 189 /* hsusb0_data5 pin */ |
| 194 | |
| 195 | /* |
| 196 | * Routine: board_init |
| 197 | * Description: Early hardware init. |
| 198 | */ |
| 199 | int board_init(void) |
| 200 | { |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 201 | gpmc_init(); /* in SRAM or SDRAM, finish GPMC */ |
| 202 | |
| 203 | /* boot param addr */ |
| 204 | gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100); |
| 205 | |
Tom Rini | 3a23c42 | 2017-01-10 17:22:05 -0500 | [diff] [blame] | 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | #ifdef CONFIG_BOARD_LATE_INIT |
Adam Ford | c176904 | 2017-12-03 06:24:53 -0600 | [diff] [blame^] | 210 | |
| 211 | static void unlock_nand(void) |
| 212 | { |
| 213 | int dev = nand_curr_device; |
| 214 | struct mtd_info *mtd; |
| 215 | |
| 216 | mtd = get_nand_dev_by_index(dev); |
| 217 | nand_unlock(mtd, 0, mtd->size, 0); |
| 218 | } |
| 219 | |
Tom Rini | 3a23c42 | 2017-01-10 17:22:05 -0500 | [diff] [blame] | 220 | int board_late_init(void) |
| 221 | { |
| 222 | struct board_id *board; |
| 223 | unsigned int val; |
| 224 | |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 225 | /* |
| 226 | * To identify between a SOM LV and Torpedo module, |
| 227 | * a pulldown resistor is on hsusb0_data5 for the SOM LV module. |
| 228 | * Drive the pin (and let it soak), then read it back. |
| 229 | * If the pin is still high its a Torpedo. If low its a SOM LV |
| 230 | */ |
| 231 | |
| 232 | /* Mux hsusb0_data5 as a GPIO */ |
| 233 | MUX_VAL(CP(HSUSB0_DATA5), (IEN | PTD | DIS | M4)); |
| 234 | |
| 235 | if (gpio_request(BOARD_ID_GPIO, "husb0_data5.gpio_189") == 0) { |
| 236 | |
| 237 | /* |
| 238 | * Drive BOARD_ID_GPIO - the pulldown resistor on the SOM LV |
| 239 | * will drain the voltage. |
| 240 | */ |
| 241 | gpio_direction_output(BOARD_ID_GPIO, 0); |
| 242 | gpio_set_value(BOARD_ID_GPIO, 1); |
| 243 | |
| 244 | /* Let it soak for a bit */ |
| 245 | sdelay(0x100); |
| 246 | |
| 247 | /* |
| 248 | * Read state of BOARD_ID_GPIO as an input and if its set. |
| 249 | * If so the board is a Torpedo |
| 250 | */ |
| 251 | gpio_direction_input(BOARD_ID_GPIO); |
| 252 | val = gpio_get_value(BOARD_ID_GPIO); |
| 253 | gpio_free(BOARD_ID_GPIO); |
| 254 | |
| 255 | board = &boards[!!(get_cpu_family() == CPU_OMAP36XX)][!!val]; |
| 256 | printf("Board: %s\n", board->name); |
| 257 | |
| 258 | /* Set the machine_id passed to Linux */ |
Tom Rini | 3a23c42 | 2017-01-10 17:22:05 -0500 | [diff] [blame] | 259 | if (board->machine_id) |
| 260 | gd->bd->bi_arch_number = board->machine_id; |
| 261 | |
| 262 | /* If the user has not set fdtimage, set the default */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 263 | if (!env_get("fdtimage")) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 264 | env_set("fdtimage", board->fdtfile); |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /* restore hsusb0_data5 pin as hsusb0_data5 */ |
| 268 | MUX_VAL(CP(HSUSB0_DATA5), (IEN | PTD | DIS | M0)); |
Adam Ford | c176904 | 2017-12-03 06:24:53 -0600 | [diff] [blame^] | 269 | |
| 270 | #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK |
| 271 | unlock_nand(); |
| 272 | #endif |
Adam Ford | 60da8c3 | 2016-02-17 21:49:49 -0600 | [diff] [blame] | 273 | return 0; |
| 274 | } |
| 275 | #endif |
| 276 | |
Masahiro Yamada | 0a78017 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 277 | #if defined(CONFIG_MMC) |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 278 | int board_mmc_init(bd_t *bis) |
| 279 | { |
Nikita Kiryanov | 4be9dbc | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 280 | return omap_mmc_init(0, 0, 0, -1, -1); |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 281 | } |
| 282 | #endif |
| 283 | |
Masahiro Yamada | 0a78017 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 284 | #if defined(CONFIG_MMC) |
Paul Kocialkowski | 6955989 | 2014-11-08 20:55:47 +0100 | [diff] [blame] | 285 | void board_mmc_power_init(void) |
| 286 | { |
| 287 | twl4030_power_mmc_init(0); |
| 288 | } |
| 289 | #endif |
| 290 | |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 291 | #ifdef CONFIG_SMC911X |
| 292 | /* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */ |
| 293 | static const u32 gpmc_lan92xx_config[] = { |
| 294 | NET_LAN92XX_GPMC_CONFIG1, |
| 295 | NET_LAN92XX_GPMC_CONFIG2, |
| 296 | NET_LAN92XX_GPMC_CONFIG3, |
| 297 | NET_LAN92XX_GPMC_CONFIG4, |
| 298 | NET_LAN92XX_GPMC_CONFIG5, |
| 299 | NET_LAN92XX_GPMC_CONFIG6, |
| 300 | }; |
| 301 | |
| 302 | int board_eth_init(bd_t *bis) |
| 303 | { |
| 304 | enable_gpmc_cs_config(gpmc_lan92xx_config, &gpmc_cfg->cs[1], |
| 305 | CONFIG_SMC911X_BASE, GPMC_SIZE_16M); |
| 306 | |
| 307 | return smc911x_initialize(0, CONFIG_SMC911X_BASE); |
| 308 | } |
| 309 | #endif |
| 310 | |
Peter Barada | e5b77e6 | 2011-12-19 19:54:51 +0000 | [diff] [blame] | 311 | |