blob: cebb200c5ff8d2eabbebd85d092e7c2e947c2e38 [file] [log] [blame]
Peter Barada86887f82011-12-19 19:54:51 +00001/*
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 Denk1a459662013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
Peter Barada86887f82011-12-19 19:54:51 +000013 */
14#include <common.h>
Adam Ford7b77b1f2015-09-02 09:18:20 -050015#include <dm.h>
16#include <ns16550.h>
Peter Barada86887f82011-12-19 19:54:51 +000017#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 Yamada6ae39002017-11-30 13:45:24 +090029#include <linux/mtd/rawnand.h>
Adam Ford588e41d2016-01-31 13:34:39 -060030#include <asm/omap_musb.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090031#include <linux/errno.h>
Adam Ford588e41d2016-01-31 13:34:39 -060032#include <linux/usb/ch9.h>
33#include <linux/usb/gadget.h>
34#include <linux/usb/musb.h>
Peter Barada86887f82011-12-19 19:54:51 +000035#include "omap3logic.h"
Adam Ford74cd48e2017-08-13 07:36:14 -050036#ifdef CONFIG_USB_EHCI_HCD
37#include <usb.h>
38#include <asm/ehci-omap.h>
39#endif
Peter Barada86887f82011-12-19 19:54:51 +000040
41DECLARE_GLOBAL_DATA_PTR;
42
Adam Ford15fde732017-04-17 08:09:45 -050043/* This is only needed until SPL gets OF support */
44#ifdef CONFIG_SPL_BUILD
Adam Ford7b77b1f2015-09-02 09:18:20 -050045static const struct ns16550_platdata omap3logic_serial = {
Adam Ford2f6ed3b2016-03-07 21:08:49 -060046 .base = OMAP34XX_UART1,
47 .reg_shift = 2,
Heiko Schocher17fa0322017-01-18 08:05:49 +010048 .clock = V_NS16550_CLK,
49 .fcr = UART_FCR_DEFVAL,
Adam Ford7b77b1f2015-09-02 09:18:20 -050050};
51
52U_BOOT_DEVICE(omap3logic_uart) = {
Thomas Chouc7b96862015-11-19 21:48:12 +080053 "ns16550_serial",
Adam Ford7b77b1f2015-09-02 09:18:20 -050054 &omap3logic_serial
55};
Adam Ford15fde732017-04-17 08:09:45 -050056#endif
Adam Ford7b77b1f2015-09-02 09:18:20 -050057
Adam Ford15fde732017-04-17 08:09:45 -050058/*
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 Barada86887f82011-12-19 19:54:51 +000063static struct board_id {
64 char *name;
65 int machine_id;
Tom Rinic63d2702017-01-10 17:22:05 -050066 char *fdtfile;
Peter Barada86887f82011-12-19 19:54:51 +000067} boards[2][2] = {
68 {
69 {
70 .name = "OMAP35xx SOM LV",
71 .machine_id = MACH_TYPE_OMAP3530_LV_SOM,
Tom Rinic63d2702017-01-10 17:22:05 -050072 .fdtfile = "logicpd-som-lv-35xx-devkit.dtb",
Peter Barada86887f82011-12-19 19:54:51 +000073 },
74 {
75 .name = "OMAP35xx Torpedo",
76 .machine_id = MACH_TYPE_OMAP3_TORPEDO,
Tom Rinic63d2702017-01-10 17:22:05 -050077 .fdtfile = "logicpd-torpedo-35xx-devkit.dtb",
Peter Barada86887f82011-12-19 19:54:51 +000078 },
79 },
80 {
81 {
82 .name = "DM37xx SOM LV",
Tom Rinic63d2702017-01-10 17:22:05 -050083 .fdtfile = "logicpd-som-lv-37xx-devkit.dtb",
Peter Barada86887f82011-12-19 19:54:51 +000084 },
85 {
86 .name = "DM37xx Torpedo",
Tom Rinic63d2702017-01-10 17:22:05 -050087 .fdtfile = "logicpd-torpedo-37xx-devkit.dtb",
Peter Barada86887f82011-12-19 19:54:51 +000088 },
89 },
90};
91
Adam Ford49c73032016-01-29 20:12:34 -060092#ifdef CONFIG_SPL_OS_BOOT
93int 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 */
108void 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 Ford588e41d2016-01-31 13:34:39 -0600119#ifdef CONFIG_USB_MUSB_OMAP2PLUS
120static struct musb_hdrc_config musb_config = {
121 .multipoint = 1,
122 .dyn_fifo = 1,
123 .num_eps = 16,
124 .ram_bits = 12,
125};
126
127static struct omap_musb_board_data musb_board_data = {
128 .interface_type = MUSB_INTERFACE_ULPI,
129};
130
131static 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 Ford74cd48e2017-08-13 07:36:14 -0500146#if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
147/* Call usb_stop() before starting the kernel */
148void show_boot_progress(int val)
149{
150 if (val == BOOTSTAGE_ID_RUN_OS)
151 usb_stop();
152}
153
154static 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
160int 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
166int ehci_hcd_stop(int index)
167{
168 return omap_ehci_hcd_stop();
169}
170
171#endif /* CONFIG_USB_EHCI_HCD */
172
Adam Ford588e41d2016-01-31 13:34:39 -0600173
Adam Ford49c73032016-01-29 20:12:34 -0600174/*
175 * Routine: misc_init_r
176 * Description: Configure board specific parts
177 */
178int misc_init_r(void)
179{
Adam Ford49c73032016-01-29 20:12:34 -0600180 twl4030_power_init();
Adam Ford49c73032016-01-29 20:12:34 -0600181 omap_die_id_display();
Adam Ford49c73032016-01-29 20:12:34 -0600182
Adam Ford588e41d2016-01-31 13:34:39 -0600183#ifdef CONFIG_USB_MUSB_OMAP2PLUS
184 musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
185#endif
186
Adam Ford49c73032016-01-29 20:12:34 -0600187 return 0;
188}
189
Peter Barada86887f82011-12-19 19:54:51 +0000190/*
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 */
199int board_init(void)
200{
Peter Barada86887f82011-12-19 19:54:51 +0000201 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 Rinic63d2702017-01-10 17:22:05 -0500206 return 0;
207}
208
209#ifdef CONFIG_BOARD_LATE_INIT
Adam Ford157af4f2017-12-03 06:24:53 -0600210
211static 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 Rinic63d2702017-01-10 17:22:05 -0500220int board_late_init(void)
221{
222 struct board_id *board;
223 unsigned int val;
224
Peter Barada86887f82011-12-19 19:54:51 +0000225 /*
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 Rinic63d2702017-01-10 17:22:05 -0500259 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 Glass00caae62017-08-03 12:22:12 -0600263 if (!env_get("fdtimage"))
Simon Glass382bee52017-08-03 12:22:09 -0600264 env_set("fdtimage", board->fdtfile);
Peter Barada86887f82011-12-19 19:54:51 +0000265 }
266
267 /* restore hsusb0_data5 pin as hsusb0_data5 */
268 MUX_VAL(CP(HSUSB0_DATA5), (IEN | PTD | DIS | M0));
Adam Ford157af4f2017-12-03 06:24:53 -0600269
270#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
271 unlock_nand();
272#endif
Adam Ford26ef7a22016-02-17 21:49:49 -0600273 return 0;
274}
275#endif
276
Masahiro Yamada4aa2ba32017-05-09 20:31:39 +0900277#if defined(CONFIG_MMC)
Peter Barada86887f82011-12-19 19:54:51 +0000278int board_mmc_init(bd_t *bis)
279{
Nikita Kiryanove3913f52012-12-03 02:19:47 +0000280 return omap_mmc_init(0, 0, 0, -1, -1);
Peter Barada86887f82011-12-19 19:54:51 +0000281}
282#endif
283
Masahiro Yamada4aa2ba32017-05-09 20:31:39 +0900284#if defined(CONFIG_MMC)
Paul Kocialkowskiaac54502014-11-08 20:55:47 +0100285void board_mmc_power_init(void)
286{
287 twl4030_power_mmc_init(0);
288}
289#endif
290
Peter Barada86887f82011-12-19 19:54:51 +0000291#ifdef CONFIG_SMC911X
292/* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */
293static 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
302int 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 Barada86887f82011-12-19 19:54:51 +0000311