blob: 620423bbc8b3cbc872f1fcb2d4e0f9bc2398ada9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peter Baradae5b77e62011-12-19 19:54:51 +00002/*
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 Baradae5b77e62011-12-19 19:54:51 +000012 */
13#include <common.h>
Adam Ford04c848a2015-09-02 09:18:20 -050014#include <dm.h>
15#include <ns16550.h>
Peter Baradae5b77e62011-12-19 19:54:51 +000016#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 Ford39ce1252018-08-21 10:43:30 -050027#include <asm/omap_mmc.h>
Peter Baradae5b77e62011-12-19 19:54:51 +000028#include <asm/mach-types.h>
Masahiro Yamada2b7a8732017-11-30 13:45:24 +090029#include <linux/mtd/rawnand.h>
Adam Fordd76b69c2016-01-31 13:34:39 -060030#include <asm/omap_musb.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090031#include <linux/errno.h>
Adam Fordd76b69c2016-01-31 13:34:39 -060032#include <linux/usb/ch9.h>
33#include <linux/usb/gadget.h>
34#include <linux/usb/musb.h>
Peter Baradae5b77e62011-12-19 19:54:51 +000035#include "omap3logic.h"
Adam Ford0c5b44f2017-08-13 07:36:14 -050036#ifdef CONFIG_USB_EHCI_HCD
37#include <usb.h>
38#include <asm/ehci-omap.h>
39#endif
Peter Baradae5b77e62011-12-19 19:54:51 +000040
41DECLARE_GLOBAL_DATA_PTR;
42
Adam Ford39ce1252018-08-21 10:43:30 -050043/* This is only needed until SPL gets OF support */
44#ifdef CONFIG_SPL_BUILD
45static const struct ns16550_platdata omap3logic_serial = {
46 .base = OMAP34XX_UART1,
47 .reg_shift = 2,
48 .clock = V_NS16550_CLK,
49 .fcr = UART_FCR_DEFVAL,
50};
51
52U_BOOT_DEVICE(omap3logic_uart) = {
53 "ns16550_serial",
54 &omap3logic_serial
55};
56
57static const struct omap_hsmmc_plat omap3_logic_mmc0_platdata = {
58 .base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE,
59 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_4BIT,
60 .cfg.f_min = 400000,
61 .cfg.f_max = 52000000,
62 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
63 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
64};
65
66U_BOOT_DEVICE(am335x_mmc0) = {
67 .name = "omap_hsmmc",
68 .platdata = &omap3_logic_mmc0_platdata,
69};
70
71#endif
72
Adam Ford55bdf922017-04-17 08:09:45 -050073/*
74 * two dimensional array of strucures containining board name and Linux
75 * machine IDs; row it selected based on CPU column is slected based
76 * on hsusb0_data5 pin having a pulldown resistor
77 */
Peter Baradae5b77e62011-12-19 19:54:51 +000078static struct board_id {
79 char *name;
80 int machine_id;
Tom Rini3a23c422017-01-10 17:22:05 -050081 char *fdtfile;
Peter Baradae5b77e62011-12-19 19:54:51 +000082} boards[2][2] = {
83 {
84 {
85 .name = "OMAP35xx SOM LV",
86 .machine_id = MACH_TYPE_OMAP3530_LV_SOM,
Tom Rini3a23c422017-01-10 17:22:05 -050087 .fdtfile = "logicpd-som-lv-35xx-devkit.dtb",
Peter Baradae5b77e62011-12-19 19:54:51 +000088 },
89 {
90 .name = "OMAP35xx Torpedo",
91 .machine_id = MACH_TYPE_OMAP3_TORPEDO,
Tom Rini3a23c422017-01-10 17:22:05 -050092 .fdtfile = "logicpd-torpedo-35xx-devkit.dtb",
Peter Baradae5b77e62011-12-19 19:54:51 +000093 },
94 },
95 {
96 {
97 .name = "DM37xx SOM LV",
Tom Rini3a23c422017-01-10 17:22:05 -050098 .fdtfile = "logicpd-som-lv-37xx-devkit.dtb",
Peter Baradae5b77e62011-12-19 19:54:51 +000099 },
100 {
101 .name = "DM37xx Torpedo",
Tom Rini3a23c422017-01-10 17:22:05 -0500102 .fdtfile = "logicpd-torpedo-37xx-devkit.dtb",
Peter Baradae5b77e62011-12-19 19:54:51 +0000103 },
104 },
105};
106
Adam Ford5326c292016-01-29 20:12:34 -0600107#ifdef CONFIG_SPL_OS_BOOT
108int spl_start_uboot(void)
109{
110 /* break into full u-boot on 'c' */
111 return serial_tstc() && serial_getc() == 'c';
112}
113#endif
114
115#if defined(CONFIG_SPL_BUILD)
116/*
117 * Routine: get_board_mem_timings
118 * Description: If we use SPL then there is no x-loader nor config header
119 * so we have to setup the DDR timings ourself on the first bank. This
120 * provides the timing values back to the function that configures
121 * the memory.
122 */
123void get_board_mem_timings(struct board_sdrc_timings *timings)
124{
125 timings->mr = MICRON_V_MR_165;
126 /* 256MB DDR */
127 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
128 timings->ctrla = MICRON_V_ACTIMA_200;
129 timings->ctrlb = MICRON_V_ACTIMB_200;
130 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
131}
Adam Ford9968e4a2017-12-04 17:54:50 -0600132
133#define GPMC_NAND_COMMAND_0 (OMAP34XX_GPMC_BASE + 0x7c)
134#define GPMC_NAND_DATA_0 (OMAP34XX_GPMC_BASE + 0x84)
135#define GPMC_NAND_ADDRESS_0 (OMAP34XX_GPMC_BASE + 0x80)
136
137void spl_board_prepare_for_linux(void)
138{
139 /* The Micron NAND starts locked which
140 * prohibits mounting the NAND as RW
141 * The following commands are what unlocks
142 * the NAND to become RW Falcon Mode does not
143 * have as many smarts as U-Boot, but Logic PD
144 * only makes NAND with 512MB so these hard coded
145 * values should work for all current models
146 */
147
148 writeb(0x70, GPMC_NAND_COMMAND_0);
149 writeb(-1, GPMC_NAND_DATA_0);
150 writeb(0x7a, GPMC_NAND_COMMAND_0);
151 writeb(0x00, GPMC_NAND_ADDRESS_0);
152 writeb(0x00, GPMC_NAND_ADDRESS_0);
153 writeb(0x00, GPMC_NAND_ADDRESS_0);
154 writeb(-1, GPMC_NAND_COMMAND_0);
155
156 /* Begin address 0 */
157 writeb(NAND_CMD_UNLOCK1, 0x6e00007c);
158 writeb(0x00, GPMC_NAND_ADDRESS_0);
159 writeb(0x00, GPMC_NAND_ADDRESS_0);
160 writeb(0x00, GPMC_NAND_ADDRESS_0);
161 writeb(-1, GPMC_NAND_DATA_0);
162
163 /* Ending address at the end of Flash */
164 writeb(NAND_CMD_UNLOCK2, GPMC_NAND_COMMAND_0);
165 writeb(0xc0, GPMC_NAND_ADDRESS_0);
166 writeb(0xff, GPMC_NAND_ADDRESS_0);
167 writeb(0x03, GPMC_NAND_ADDRESS_0);
168 writeb(-1, GPMC_NAND_DATA_0);
169 writeb(0x79, GPMC_NAND_COMMAND_0);
170 writeb(-1, GPMC_NAND_DATA_0);
171 writeb(-1, GPMC_NAND_DATA_0);
172}
Adam Ford5326c292016-01-29 20:12:34 -0600173#endif
174
Adam Fordd76b69c2016-01-31 13:34:39 -0600175#ifdef CONFIG_USB_MUSB_OMAP2PLUS
176static struct musb_hdrc_config musb_config = {
177 .multipoint = 1,
178 .dyn_fifo = 1,
179 .num_eps = 16,
180 .ram_bits = 12,
181};
182
183static struct omap_musb_board_data musb_board_data = {
184 .interface_type = MUSB_INTERFACE_ULPI,
185};
186
187static struct musb_hdrc_platform_data musb_plat = {
188#if defined(CONFIG_USB_MUSB_HOST)
189 .mode = MUSB_HOST,
190#elif defined(CONFIG_USB_MUSB_GADGET)
191 .mode = MUSB_PERIPHERAL,
192#else
193#error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
194#endif
195 .config = &musb_config,
196 .power = 100,
197 .platform_ops = &omap2430_ops,
198 .board_data = &musb_board_data,
199};
200#endif
201
Adam Ford0c5b44f2017-08-13 07:36:14 -0500202#if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
203/* Call usb_stop() before starting the kernel */
204void show_boot_progress(int val)
205{
206 if (val == BOOTSTAGE_ID_RUN_OS)
207 usb_stop();
208}
209
210static struct omap_usbhs_board_data usbhs_bdata = {
211 .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
212 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
213 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
214};
215
216int ehci_hcd_init(int index, enum usb_init_type init,
217 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
218{
219 return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
220}
221
222int ehci_hcd_stop(int index)
223{
224 return omap_ehci_hcd_stop();
225}
226
227#endif /* CONFIG_USB_EHCI_HCD */
228
Adam Fordd76b69c2016-01-31 13:34:39 -0600229
Adam Ford5326c292016-01-29 20:12:34 -0600230/*
231 * Routine: misc_init_r
232 * Description: Configure board specific parts
233 */
234int misc_init_r(void)
235{
Adam Ford5326c292016-01-29 20:12:34 -0600236 twl4030_power_init();
Adam Ford5326c292016-01-29 20:12:34 -0600237 omap_die_id_display();
Adam Ford5326c292016-01-29 20:12:34 -0600238
Adam Fordd76b69c2016-01-31 13:34:39 -0600239#ifdef CONFIG_USB_MUSB_OMAP2PLUS
240 musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
241#endif
242
Adam Ford5326c292016-01-29 20:12:34 -0600243 return 0;
244}
245
Peter Baradae5b77e62011-12-19 19:54:51 +0000246/*
247 * BOARD_ID_GPIO - GPIO of pin with optional pulldown resistor on SOM LV
248 */
249#define BOARD_ID_GPIO 189 /* hsusb0_data5 pin */
250
251/*
252 * Routine: board_init
253 * Description: Early hardware init.
254 */
255int board_init(void)
256{
Peter Baradae5b77e62011-12-19 19:54:51 +0000257 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
258
259 /* boot param addr */
260 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
261
Tom Rini3a23c422017-01-10 17:22:05 -0500262 return 0;
263}
264
265#ifdef CONFIG_BOARD_LATE_INIT
Adam Fordc1769042017-12-03 06:24:53 -0600266
267static void unlock_nand(void)
268{
269 int dev = nand_curr_device;
270 struct mtd_info *mtd;
271
272 mtd = get_nand_dev_by_index(dev);
273 nand_unlock(mtd, 0, mtd->size, 0);
274}
275
Tom Rini3a23c422017-01-10 17:22:05 -0500276int board_late_init(void)
277{
278 struct board_id *board;
279 unsigned int val;
280
Peter Baradae5b77e62011-12-19 19:54:51 +0000281 /*
282 * To identify between a SOM LV and Torpedo module,
283 * a pulldown resistor is on hsusb0_data5 for the SOM LV module.
284 * Drive the pin (and let it soak), then read it back.
285 * If the pin is still high its a Torpedo. If low its a SOM LV
286 */
287
288 /* Mux hsusb0_data5 as a GPIO */
289 MUX_VAL(CP(HSUSB0_DATA5), (IEN | PTD | DIS | M4));
290
291 if (gpio_request(BOARD_ID_GPIO, "husb0_data5.gpio_189") == 0) {
292
293 /*
294 * Drive BOARD_ID_GPIO - the pulldown resistor on the SOM LV
295 * will drain the voltage.
296 */
297 gpio_direction_output(BOARD_ID_GPIO, 0);
298 gpio_set_value(BOARD_ID_GPIO, 1);
299
300 /* Let it soak for a bit */
301 sdelay(0x100);
302
303 /*
304 * Read state of BOARD_ID_GPIO as an input and if its set.
305 * If so the board is a Torpedo
306 */
307 gpio_direction_input(BOARD_ID_GPIO);
308 val = gpio_get_value(BOARD_ID_GPIO);
309 gpio_free(BOARD_ID_GPIO);
310
311 board = &boards[!!(get_cpu_family() == CPU_OMAP36XX)][!!val];
312 printf("Board: %s\n", board->name);
313
314 /* Set the machine_id passed to Linux */
Tom Rini3a23c422017-01-10 17:22:05 -0500315 if (board->machine_id)
316 gd->bd->bi_arch_number = board->machine_id;
317
318 /* If the user has not set fdtimage, set the default */
Simon Glass64b723f2017-08-03 12:22:12 -0600319 if (!env_get("fdtimage"))
Simon Glass6a38e412017-08-03 12:22:09 -0600320 env_set("fdtimage", board->fdtfile);
Peter Baradae5b77e62011-12-19 19:54:51 +0000321 }
322
323 /* restore hsusb0_data5 pin as hsusb0_data5 */
324 MUX_VAL(CP(HSUSB0_DATA5), (IEN | PTD | DIS | M0));
Adam Fordc1769042017-12-03 06:24:53 -0600325
326#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
327 unlock_nand();
328#endif
Adam Ford60da8c32016-02-17 21:49:49 -0600329 return 0;
330}
331#endif
332
Masahiro Yamada0a780172017-05-09 20:31:39 +0900333#if defined(CONFIG_MMC)
Peter Baradae5b77e62011-12-19 19:54:51 +0000334int board_mmc_init(bd_t *bis)
335{
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +0000336 return omap_mmc_init(0, 0, 0, -1, -1);
Peter Baradae5b77e62011-12-19 19:54:51 +0000337}
338#endif
339
Masahiro Yamada0a780172017-05-09 20:31:39 +0900340#if defined(CONFIG_MMC)
Paul Kocialkowski69559892014-11-08 20:55:47 +0100341void board_mmc_power_init(void)
342{
343 twl4030_power_mmc_init(0);
344}
345#endif
346
Peter Baradae5b77e62011-12-19 19:54:51 +0000347#ifdef CONFIG_SMC911X
348/* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */
349static const u32 gpmc_lan92xx_config[] = {
350 NET_LAN92XX_GPMC_CONFIG1,
351 NET_LAN92XX_GPMC_CONFIG2,
352 NET_LAN92XX_GPMC_CONFIG3,
353 NET_LAN92XX_GPMC_CONFIG4,
354 NET_LAN92XX_GPMC_CONFIG5,
355 NET_LAN92XX_GPMC_CONFIG6,
356};
357
358int board_eth_init(bd_t *bis)
359{
360 enable_gpmc_cs_config(gpmc_lan92xx_config, &gpmc_cfg->cs[1],
361 CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
362
363 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
364}
365#endif
366
Peter Baradae5b77e62011-12-19 19:54:51 +0000367