blob: 50572c6a71dd0b51e132bb6f2a61cc6209d1b848 [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>
Simon Glassa7b51302019-11-14 12:57:46 -070015#include <init.h>
Adam Ford04c848a2015-09-02 09:18:20 -050016#include <ns16550.h>
Peter Baradae5b77e62011-12-19 19:54:51 +000017#include <flash.h>
18#include <nand.h>
19#include <i2c.h>
Simon Glass36736182019-11-14 12:57:24 -070020#include <serial.h>
Peter Baradae5b77e62011-12-19 19:54:51 +000021#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>
Adam Ford39ce1252018-08-21 10:43:30 -050028#include <asm/omap_mmc.h>
Peter Baradae5b77e62011-12-19 19:54:51 +000029#include <asm/mach-types.h>
Masahiro Yamada2b7a8732017-11-30 13:45:24 +090030#include <linux/mtd/rawnand.h>
Adam Fordd76b69c2016-01-31 13:34:39 -060031#include <asm/omap_musb.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090032#include <linux/errno.h>
Adam Fordd76b69c2016-01-31 13:34:39 -060033#include <linux/usb/ch9.h>
34#include <linux/usb/gadget.h>
35#include <linux/usb/musb.h>
Peter Baradae5b77e62011-12-19 19:54:51 +000036#include "omap3logic.h"
Adam Ford0c5b44f2017-08-13 07:36:14 -050037#ifdef CONFIG_USB_EHCI_HCD
38#include <usb.h>
39#include <asm/ehci-omap.h>
40#endif
Peter Baradae5b77e62011-12-19 19:54:51 +000041
42DECLARE_GLOBAL_DATA_PTR;
43
Adam Ford726ab5d2018-10-14 15:53:17 -050044#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG1 0x00011203
45#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG2 0x000A1302
46#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG3 0x000F1302
47#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG4 0x0A021303
48#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG5 0x00120F18
49#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG6 0x0A030000
50#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG7 0x00000C50
51
52#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG1 0x00011203
53#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG2 0x00091102
54#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG3 0x000D1102
55#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG4 0x09021103
56#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG5 0x00100D15
57#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG6 0x09030000
58#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG7 0x00000C50
59
Adam Ford76b60422020-05-09 05:48:06 -050060#define CONFIG_SMC911X_BASE 0x08000000
61
Adam Ford5326c292016-01-29 20:12:34 -060062#ifdef CONFIG_SPL_OS_BOOT
63int spl_start_uboot(void)
64{
65 /* break into full u-boot on 'c' */
66 return serial_tstc() && serial_getc() == 'c';
67}
68#endif
69
70#if defined(CONFIG_SPL_BUILD)
71/*
72 * Routine: get_board_mem_timings
73 * Description: If we use SPL then there is no x-loader nor config header
74 * so we have to setup the DDR timings ourself on the first bank. This
75 * provides the timing values back to the function that configures
76 * the memory.
77 */
78void get_board_mem_timings(struct board_sdrc_timings *timings)
79{
80 timings->mr = MICRON_V_MR_165;
Adam Fordc3696922018-10-07 09:20:45 -050081
82 if (get_cpu_family() == CPU_OMAP36XX) {
83 /* 200 MHz works for OMAP36/DM37 */
84 /* 256MB DDR */
85 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
86 timings->ctrla = MICRON_V_ACTIMA_200;
87 timings->ctrlb = MICRON_V_ACTIMB_200;
88 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
89 } else {
90 /* 165 MHz works for OMAP35 */
91 timings->mcfg = MICRON_V_MCFG_165(256 << 20);
92 timings->ctrla = MICRON_V_ACTIMA_165;
93 timings->ctrlb = MICRON_V_ACTIMB_165;
94 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
95 }
Adam Ford5326c292016-01-29 20:12:34 -060096}
Adam Ford9968e4a2017-12-04 17:54:50 -060097
98#define GPMC_NAND_COMMAND_0 (OMAP34XX_GPMC_BASE + 0x7c)
99#define GPMC_NAND_DATA_0 (OMAP34XX_GPMC_BASE + 0x84)
100#define GPMC_NAND_ADDRESS_0 (OMAP34XX_GPMC_BASE + 0x80)
101
102void spl_board_prepare_for_linux(void)
103{
104 /* The Micron NAND starts locked which
105 * prohibits mounting the NAND as RW
106 * The following commands are what unlocks
107 * the NAND to become RW Falcon Mode does not
108 * have as many smarts as U-Boot, but Logic PD
109 * only makes NAND with 512MB so these hard coded
110 * values should work for all current models
111 */
112
113 writeb(0x70, GPMC_NAND_COMMAND_0);
114 writeb(-1, GPMC_NAND_DATA_0);
115 writeb(0x7a, GPMC_NAND_COMMAND_0);
116 writeb(0x00, GPMC_NAND_ADDRESS_0);
117 writeb(0x00, GPMC_NAND_ADDRESS_0);
118 writeb(0x00, GPMC_NAND_ADDRESS_0);
119 writeb(-1, GPMC_NAND_COMMAND_0);
120
121 /* Begin address 0 */
122 writeb(NAND_CMD_UNLOCK1, 0x6e00007c);
123 writeb(0x00, GPMC_NAND_ADDRESS_0);
124 writeb(0x00, GPMC_NAND_ADDRESS_0);
125 writeb(0x00, GPMC_NAND_ADDRESS_0);
126 writeb(-1, GPMC_NAND_DATA_0);
127
128 /* Ending address at the end of Flash */
129 writeb(NAND_CMD_UNLOCK2, GPMC_NAND_COMMAND_0);
130 writeb(0xc0, GPMC_NAND_ADDRESS_0);
131 writeb(0xff, GPMC_NAND_ADDRESS_0);
132 writeb(0x03, GPMC_NAND_ADDRESS_0);
133 writeb(-1, GPMC_NAND_DATA_0);
134 writeb(0x79, GPMC_NAND_COMMAND_0);
135 writeb(-1, GPMC_NAND_DATA_0);
136 writeb(-1, GPMC_NAND_DATA_0);
137}
Adam Ford5326c292016-01-29 20:12:34 -0600138#endif
139
140/*
141 * Routine: misc_init_r
142 * Description: Configure board specific parts
143 */
144int misc_init_r(void)
145{
Adam Ford5326c292016-01-29 20:12:34 -0600146 twl4030_power_init();
Adam Fordce51e842019-11-03 16:18:27 -0600147 twl4030_power_mmc_init(0);
Adam Ford5326c292016-01-29 20:12:34 -0600148 omap_die_id_display();
Adam Ford5326c292016-01-29 20:12:34 -0600149 return 0;
150}
151
Adam Ford726ab5d2018-10-14 15:53:17 -0500152#if defined(CONFIG_FLASH_CFI_DRIVER)
153static const u32 gpmc_dm37_c2nor_config[] = {
154 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG1,
155 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG2,
156 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG3,
157 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG4,
158 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG5,
159 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG6,
160 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG7
161};
162
163static const u32 gpmc_omap35_c2nor_config[] = {
164 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG1,
165 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG2,
166 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG3,
167 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG4,
168 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG5,
169 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG6,
170 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG7
171};
172#endif
173
Peter Baradae5b77e62011-12-19 19:54:51 +0000174/*
Peter Baradae5b77e62011-12-19 19:54:51 +0000175 * Routine: board_init
176 * Description: Early hardware init.
177 */
178int board_init(void)
179{
Peter Baradae5b77e62011-12-19 19:54:51 +0000180 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
181
182 /* boot param addr */
183 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
Adam Ford726ab5d2018-10-14 15:53:17 -0500184#if defined(CONFIG_FLASH_CFI_DRIVER)
185 if (get_cpu_family() == CPU_OMAP36XX) {
186 /* Enable CS2 for NOR Flash */
187 enable_gpmc_cs_config(gpmc_dm37_c2nor_config, &gpmc_cfg->cs[2],
188 0x10000000, GPMC_SIZE_64M);
189 } else {
190 enable_gpmc_cs_config(gpmc_omap35_c2nor_config, &gpmc_cfg->cs[2],
191 0x10000000, GPMC_SIZE_64M);
192 }
193#endif
Tom Rini3a23c422017-01-10 17:22:05 -0500194 return 0;
195}
196
197#ifdef CONFIG_BOARD_LATE_INIT
Adam Fordc1769042017-12-03 06:24:53 -0600198
199static void unlock_nand(void)
200{
201 int dev = nand_curr_device;
202 struct mtd_info *mtd;
203
204 mtd = get_nand_dev_by_index(dev);
205 nand_unlock(mtd, 0, mtd->size, 0);
206}
Paul Kocialkowski69559892014-11-08 20:55:47 +0100207
Peter Baradae5b77e62011-12-19 19:54:51 +0000208#ifdef CONFIG_SMC911X
209/* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */
210static const u32 gpmc_lan92xx_config[] = {
211 NET_LAN92XX_GPMC_CONFIG1,
212 NET_LAN92XX_GPMC_CONFIG2,
213 NET_LAN92XX_GPMC_CONFIG3,
214 NET_LAN92XX_GPMC_CONFIG4,
215 NET_LAN92XX_GPMC_CONFIG5,
216 NET_LAN92XX_GPMC_CONFIG6,
217};
Adam Ford76b60422020-05-09 05:48:06 -0500218#endif
Peter Baradae5b77e62011-12-19 19:54:51 +0000219
Adam Ford76b60422020-05-09 05:48:06 -0500220int board_late_init(void)
Peter Baradae5b77e62011-12-19 19:54:51 +0000221{
Adam Ford76b60422020-05-09 05:48:06 -0500222#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
223 unlock_nand();
224#endif
225
226#ifdef CONFIG_SMC911X
Peter Baradae5b77e62011-12-19 19:54:51 +0000227 enable_gpmc_cs_config(gpmc_lan92xx_config, &gpmc_cfg->cs[1],
228 CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
Adam Ford76b60422020-05-09 05:48:06 -0500229#endif
230 return 0;
231}
232#endif
Peter Baradae5b77e62011-12-19 19:54:51 +0000233
Adam Ford76b60422020-05-09 05:48:06 -0500234#if defined(CONFIG_MMC)
235void board_mmc_power_init(void)
236{
237 twl4030_power_mmc_init(0);
Peter Baradae5b77e62011-12-19 19:54:51 +0000238}
239#endif