blob: 21d8a21010e36c4b8a9b457129e7eda596e3d704 [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 <netdev.h>
18#include <flash.h>
19#include <nand.h>
20#include <i2c.h>
Simon Glass36736182019-11-14 12:57:24 -070021#include <serial.h>
Peter Baradae5b77e62011-12-19 19:54:51 +000022#include <twl4030.h>
23#include <asm/io.h>
24#include <asm/arch/mmc_host_def.h>
25#include <asm/arch/mux.h>
26#include <asm/arch/mem.h>
27#include <asm/arch/sys_proto.h>
28#include <asm/gpio.h>
Adam Ford39ce1252018-08-21 10:43:30 -050029#include <asm/omap_mmc.h>
Peter Baradae5b77e62011-12-19 19:54:51 +000030#include <asm/mach-types.h>
Masahiro Yamada2b7a8732017-11-30 13:45:24 +090031#include <linux/mtd/rawnand.h>
Adam Fordd76b69c2016-01-31 13:34:39 -060032#include <asm/omap_musb.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090033#include <linux/errno.h>
Adam Fordd76b69c2016-01-31 13:34:39 -060034#include <linux/usb/ch9.h>
35#include <linux/usb/gadget.h>
36#include <linux/usb/musb.h>
Peter Baradae5b77e62011-12-19 19:54:51 +000037#include "omap3logic.h"
Adam Ford0c5b44f2017-08-13 07:36:14 -050038#ifdef CONFIG_USB_EHCI_HCD
39#include <usb.h>
40#include <asm/ehci-omap.h>
41#endif
Peter Baradae5b77e62011-12-19 19:54:51 +000042
43DECLARE_GLOBAL_DATA_PTR;
44
Adam Ford726ab5d2018-10-14 15:53:17 -050045#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG1 0x00011203
46#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG2 0x000A1302
47#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG3 0x000F1302
48#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG4 0x0A021303
49#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG5 0x00120F18
50#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG6 0x0A030000
51#define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG7 0x00000C50
52
53#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG1 0x00011203
54#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG2 0x00091102
55#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG3 0x000D1102
56#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG4 0x09021103
57#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG5 0x00100D15
58#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG6 0x09030000
59#define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG7 0x00000C50
60
Adam Ford5326c292016-01-29 20:12:34 -060061#ifdef CONFIG_SPL_OS_BOOT
62int spl_start_uboot(void)
63{
64 /* break into full u-boot on 'c' */
65 return serial_tstc() && serial_getc() == 'c';
66}
67#endif
68
69#if defined(CONFIG_SPL_BUILD)
70/*
71 * Routine: get_board_mem_timings
72 * Description: If we use SPL then there is no x-loader nor config header
73 * so we have to setup the DDR timings ourself on the first bank. This
74 * provides the timing values back to the function that configures
75 * the memory.
76 */
77void get_board_mem_timings(struct board_sdrc_timings *timings)
78{
79 timings->mr = MICRON_V_MR_165;
Adam Fordc3696922018-10-07 09:20:45 -050080
81 if (get_cpu_family() == CPU_OMAP36XX) {
82 /* 200 MHz works for OMAP36/DM37 */
83 /* 256MB DDR */
84 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
85 timings->ctrla = MICRON_V_ACTIMA_200;
86 timings->ctrlb = MICRON_V_ACTIMB_200;
87 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
88 } else {
89 /* 165 MHz works for OMAP35 */
90 timings->mcfg = MICRON_V_MCFG_165(256 << 20);
91 timings->ctrla = MICRON_V_ACTIMA_165;
92 timings->ctrlb = MICRON_V_ACTIMB_165;
93 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
94 }
Adam Ford5326c292016-01-29 20:12:34 -060095}
Adam Ford9968e4a2017-12-04 17:54:50 -060096
97#define GPMC_NAND_COMMAND_0 (OMAP34XX_GPMC_BASE + 0x7c)
98#define GPMC_NAND_DATA_0 (OMAP34XX_GPMC_BASE + 0x84)
99#define GPMC_NAND_ADDRESS_0 (OMAP34XX_GPMC_BASE + 0x80)
100
101void spl_board_prepare_for_linux(void)
102{
103 /* The Micron NAND starts locked which
104 * prohibits mounting the NAND as RW
105 * The following commands are what unlocks
106 * the NAND to become RW Falcon Mode does not
107 * have as many smarts as U-Boot, but Logic PD
108 * only makes NAND with 512MB so these hard coded
109 * values should work for all current models
110 */
111
112 writeb(0x70, GPMC_NAND_COMMAND_0);
113 writeb(-1, GPMC_NAND_DATA_0);
114 writeb(0x7a, GPMC_NAND_COMMAND_0);
115 writeb(0x00, GPMC_NAND_ADDRESS_0);
116 writeb(0x00, GPMC_NAND_ADDRESS_0);
117 writeb(0x00, GPMC_NAND_ADDRESS_0);
118 writeb(-1, GPMC_NAND_COMMAND_0);
119
120 /* Begin address 0 */
121 writeb(NAND_CMD_UNLOCK1, 0x6e00007c);
122 writeb(0x00, GPMC_NAND_ADDRESS_0);
123 writeb(0x00, GPMC_NAND_ADDRESS_0);
124 writeb(0x00, GPMC_NAND_ADDRESS_0);
125 writeb(-1, GPMC_NAND_DATA_0);
126
127 /* Ending address at the end of Flash */
128 writeb(NAND_CMD_UNLOCK2, GPMC_NAND_COMMAND_0);
129 writeb(0xc0, GPMC_NAND_ADDRESS_0);
130 writeb(0xff, GPMC_NAND_ADDRESS_0);
131 writeb(0x03, GPMC_NAND_ADDRESS_0);
132 writeb(-1, GPMC_NAND_DATA_0);
133 writeb(0x79, GPMC_NAND_COMMAND_0);
134 writeb(-1, GPMC_NAND_DATA_0);
135 writeb(-1, GPMC_NAND_DATA_0);
136}
Adam Ford5326c292016-01-29 20:12:34 -0600137#endif
138
139/*
140 * Routine: misc_init_r
141 * Description: Configure board specific parts
142 */
143int misc_init_r(void)
144{
Adam Ford5326c292016-01-29 20:12:34 -0600145 twl4030_power_init();
Adam Fordce51e842019-11-03 16:18:27 -0600146 twl4030_power_mmc_init(0);
Adam Ford5326c292016-01-29 20:12:34 -0600147 omap_die_id_display();
Adam Ford5326c292016-01-29 20:12:34 -0600148 return 0;
149}
150
Adam Ford726ab5d2018-10-14 15:53:17 -0500151#if defined(CONFIG_FLASH_CFI_DRIVER)
152static const u32 gpmc_dm37_c2nor_config[] = {
153 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG1,
154 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG2,
155 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG3,
156 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG4,
157 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG5,
158 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG6,
159 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG7
160};
161
162static const u32 gpmc_omap35_c2nor_config[] = {
163 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG1,
164 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG2,
165 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG3,
166 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG4,
167 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG5,
168 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG6,
169 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG7
170};
171#endif
172
Peter Baradae5b77e62011-12-19 19:54:51 +0000173/*
Peter Baradae5b77e62011-12-19 19:54:51 +0000174 * Routine: board_init
175 * Description: Early hardware init.
176 */
177int board_init(void)
178{
Peter Baradae5b77e62011-12-19 19:54:51 +0000179 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
180
181 /* boot param addr */
182 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
Adam Ford726ab5d2018-10-14 15:53:17 -0500183#if defined(CONFIG_FLASH_CFI_DRIVER)
184 if (get_cpu_family() == CPU_OMAP36XX) {
185 /* Enable CS2 for NOR Flash */
186 enable_gpmc_cs_config(gpmc_dm37_c2nor_config, &gpmc_cfg->cs[2],
187 0x10000000, GPMC_SIZE_64M);
188 } else {
189 enable_gpmc_cs_config(gpmc_omap35_c2nor_config, &gpmc_cfg->cs[2],
190 0x10000000, GPMC_SIZE_64M);
191 }
192#endif
Tom Rini3a23c422017-01-10 17:22:05 -0500193 return 0;
194}
195
196#ifdef CONFIG_BOARD_LATE_INIT
Adam Fordc1769042017-12-03 06:24:53 -0600197
198static void unlock_nand(void)
199{
200 int dev = nand_curr_device;
201 struct mtd_info *mtd;
202
203 mtd = get_nand_dev_by_index(dev);
204 nand_unlock(mtd, 0, mtd->size, 0);
205}
206
Tom Rini3a23c422017-01-10 17:22:05 -0500207int board_late_init(void)
208{
Adam Fordc1769042017-12-03 06:24:53 -0600209#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
210 unlock_nand();
211#endif
Adam Ford60da8c32016-02-17 21:49:49 -0600212 return 0;
213}
214#endif
215
Masahiro Yamada0a780172017-05-09 20:31:39 +0900216#if defined(CONFIG_MMC)
Paul Kocialkowski69559892014-11-08 20:55:47 +0100217void board_mmc_power_init(void)
218{
219 twl4030_power_mmc_init(0);
220}
221#endif
222
Peter Baradae5b77e62011-12-19 19:54:51 +0000223#ifdef CONFIG_SMC911X
224/* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */
225static const u32 gpmc_lan92xx_config[] = {
226 NET_LAN92XX_GPMC_CONFIG1,
227 NET_LAN92XX_GPMC_CONFIG2,
228 NET_LAN92XX_GPMC_CONFIG3,
229 NET_LAN92XX_GPMC_CONFIG4,
230 NET_LAN92XX_GPMC_CONFIG5,
231 NET_LAN92XX_GPMC_CONFIG6,
232};
233
234int board_eth_init(bd_t *bis)
235{
236 enable_gpmc_cs_config(gpmc_lan92xx_config, &gpmc_cfg->cs[1],
237 CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
238
239 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
240}
241#endif