blob: 691d38fdf277d1b0068d8e63aac9611d141c65ec [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peter Barada86887f82011-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 Barada86887f82011-12-19 19:54:51 +000012 */
13#include <common.h>
Adam Ford7b77b1f2015-09-02 09:18:20 -050014#include <dm.h>
15#include <ns16550.h>
Peter Barada86887f82011-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 Ford4869fa32018-08-21 10:43:30 -050027#include <asm/omap_mmc.h>
Peter Barada86887f82011-12-19 19:54:51 +000028#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 Ford290097f2018-10-14 15:53:17 -050043#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 Ford4869fa32018-08-21 10:43:30 -050059/* This is only needed until SPL gets OF support */
60#ifdef CONFIG_SPL_BUILD
61static 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
68U_BOOT_DEVICE(omap3logic_uart) = {
Adam Fordc3aa8512018-10-07 17:42:42 -050069 "omap_serial",
Adam Ford4869fa32018-08-21 10:43:30 -050070 &omap3logic_serial
71};
72
73static 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 Ford64820952018-10-07 17:47:50 -050082U_BOOT_DEVICE(omap3_logic_mmc0) = {
Adam Ford4869fa32018-08-21 10:43:30 -050083 .name = "omap_hsmmc",
84 .platdata = &omap3_logic_mmc0_platdata,
85};
86
87#endif
88
Adam Ford49c73032016-01-29 20:12:34 -060089#ifdef CONFIG_SPL_OS_BOOT
90int 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 */
105void get_board_mem_timings(struct board_sdrc_timings *timings)
106{
107 timings->mr = MICRON_V_MR_165;
Adam Ford169eb192018-10-07 09:20:45 -0500108
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 Ford49c73032016-01-29 20:12:34 -0600123}
Adam Ford6032c022017-12-04 17:54:50 -0600124
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
129void 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 Ford49c73032016-01-29 20:12:34 -0600165#endif
166
Adam Fordf4db3b62018-10-07 17:39:29 -0500167#if !CONFIG_IS_ENABLED(DM_USB)
Adam Ford588e41d2016-01-31 13:34:39 -0600168#ifdef CONFIG_USB_MUSB_OMAP2PLUS
169static struct musb_hdrc_config musb_config = {
170 .multipoint = 1,
171 .dyn_fifo = 1,
172 .num_eps = 16,
173 .ram_bits = 12,
174};
175
176static struct omap_musb_board_data musb_board_data = {
177 .interface_type = MUSB_INTERFACE_ULPI,
178};
179
180static 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 Ford74cd48e2017-08-13 07:36:14 -0500195#if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
196/* Call usb_stop() before starting the kernel */
197void show_boot_progress(int val)
198{
199 if (val == BOOTSTAGE_ID_RUN_OS)
200 usb_stop();
201}
202
203static 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
209int 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
215int ehci_hcd_stop(int index)
216{
217 return omap_ehci_hcd_stop();
218}
219
220#endif /* CONFIG_USB_EHCI_HCD */
Adam Fordf4db3b62018-10-07 17:39:29 -0500221#endif /* !DM_USB*/
Adam Ford49c73032016-01-29 20:12:34 -0600222/*
223 * Routine: misc_init_r
224 * Description: Configure board specific parts
225 */
226int misc_init_r(void)
227{
Adam Ford49c73032016-01-29 20:12:34 -0600228 twl4030_power_init();
Adam Ford49c73032016-01-29 20:12:34 -0600229 omap_die_id_display();
Adam Ford49c73032016-01-29 20:12:34 -0600230
Adam Fordf4db3b62018-10-07 17:39:29 -0500231#if !CONFIG_IS_ENABLED(DM_USB)
Adam Ford588e41d2016-01-31 13:34:39 -0600232#ifdef CONFIG_USB_MUSB_OMAP2PLUS
233 musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
234#endif
Adam Fordf4db3b62018-10-07 17:39:29 -0500235#endif
Adam Ford49c73032016-01-29 20:12:34 -0600236 return 0;
237}
238
Adam Ford290097f2018-10-14 15:53:17 -0500239#if defined(CONFIG_FLASH_CFI_DRIVER)
240static 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
250static 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 Barada86887f82011-12-19 19:54:51 +0000261/*
Peter Barada86887f82011-12-19 19:54:51 +0000262 * Routine: board_init
263 * Description: Early hardware init.
264 */
265int board_init(void)
266{
Peter Barada86887f82011-12-19 19:54:51 +0000267 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
268
269 /* boot param addr */
270 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
Adam Ford290097f2018-10-14 15:53:17 -0500271#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 Rinic63d2702017-01-10 17:22:05 -0500281 return 0;
282}
283
284#ifdef CONFIG_BOARD_LATE_INIT
Adam Ford157af4f2017-12-03 06:24:53 -0600285
286static 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 Rinic63d2702017-01-10 17:22:05 -0500295int board_late_init(void)
296{
Adam Ford157af4f2017-12-03 06:24:53 -0600297#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
298 unlock_nand();
299#endif
Adam Ford26ef7a22016-02-17 21:49:49 -0600300 return 0;
301}
302#endif
303
Masahiro Yamada4aa2ba32017-05-09 20:31:39 +0900304#if defined(CONFIG_MMC)
Paul Kocialkowskiaac54502014-11-08 20:55:47 +0100305void board_mmc_power_init(void)
306{
307 twl4030_power_mmc_init(0);
308}
309#endif
310
Peter Barada86887f82011-12-19 19:54:51 +0000311#ifdef CONFIG_SMC911X
312/* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */
313static 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
322int 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