blob: 144e6f68a483bde5a1d9e7b058b02e510ba6f716 [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 Ford726ab5d2018-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 Ford39ce1252018-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 Ford29e6e452018-10-07 17:42:42 -050069 "omap_serial",
Adam Ford39ce1252018-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 Fordc54e0872018-10-07 17:47:50 -050082U_BOOT_DEVICE(omap3_logic_mmc0) = {
Adam Ford39ce1252018-08-21 10:43:30 -050083 .name = "omap_hsmmc",
84 .platdata = &omap3_logic_mmc0_platdata,
85};
86
87#endif
88
Adam Ford5326c292016-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 Fordc3696922018-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 Ford5326c292016-01-29 20:12:34 -0600123}
Adam Ford9968e4a2017-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 Ford5326c292016-01-29 20:12:34 -0600165#endif
166
167/*
168 * Routine: misc_init_r
169 * Description: Configure board specific parts
170 */
171int misc_init_r(void)
172{
Adam Ford5326c292016-01-29 20:12:34 -0600173 twl4030_power_init();
Adam Ford5326c292016-01-29 20:12:34 -0600174 omap_die_id_display();
Adam Ford5326c292016-01-29 20:12:34 -0600175 return 0;
176}
177
Adam Ford726ab5d2018-10-14 15:53:17 -0500178#if defined(CONFIG_FLASH_CFI_DRIVER)
179static const u32 gpmc_dm37_c2nor_config[] = {
180 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG1,
181 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG2,
182 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG3,
183 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG4,
184 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG5,
185 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG6,
186 LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG7
187};
188
189static const u32 gpmc_omap35_c2nor_config[] = {
190 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG1,
191 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG2,
192 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG3,
193 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG4,
194 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG5,
195 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG6,
196 LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG7
197};
198#endif
199
Peter Baradae5b77e62011-12-19 19:54:51 +0000200/*
Peter Baradae5b77e62011-12-19 19:54:51 +0000201 * Routine: board_init
202 * Description: Early hardware init.
203 */
204int board_init(void)
205{
Peter Baradae5b77e62011-12-19 19:54:51 +0000206 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
207
208 /* boot param addr */
209 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
Adam Ford726ab5d2018-10-14 15:53:17 -0500210#if defined(CONFIG_FLASH_CFI_DRIVER)
211 if (get_cpu_family() == CPU_OMAP36XX) {
212 /* Enable CS2 for NOR Flash */
213 enable_gpmc_cs_config(gpmc_dm37_c2nor_config, &gpmc_cfg->cs[2],
214 0x10000000, GPMC_SIZE_64M);
215 } else {
216 enable_gpmc_cs_config(gpmc_omap35_c2nor_config, &gpmc_cfg->cs[2],
217 0x10000000, GPMC_SIZE_64M);
218 }
219#endif
Tom Rini3a23c422017-01-10 17:22:05 -0500220 return 0;
221}
222
223#ifdef CONFIG_BOARD_LATE_INIT
Adam Fordc1769042017-12-03 06:24:53 -0600224
225static void unlock_nand(void)
226{
227 int dev = nand_curr_device;
228 struct mtd_info *mtd;
229
230 mtd = get_nand_dev_by_index(dev);
231 nand_unlock(mtd, 0, mtd->size, 0);
232}
233
Tom Rini3a23c422017-01-10 17:22:05 -0500234int board_late_init(void)
235{
Adam Fordc1769042017-12-03 06:24:53 -0600236#ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
237 unlock_nand();
238#endif
Adam Ford60da8c32016-02-17 21:49:49 -0600239 return 0;
240}
241#endif
242
Masahiro Yamada0a780172017-05-09 20:31:39 +0900243#if defined(CONFIG_MMC)
Paul Kocialkowski69559892014-11-08 20:55:47 +0100244void board_mmc_power_init(void)
245{
246 twl4030_power_mmc_init(0);
247}
248#endif
249
Peter Baradae5b77e62011-12-19 19:54:51 +0000250#ifdef CONFIG_SMC911X
251/* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */
252static const u32 gpmc_lan92xx_config[] = {
253 NET_LAN92XX_GPMC_CONFIG1,
254 NET_LAN92XX_GPMC_CONFIG2,
255 NET_LAN92XX_GPMC_CONFIG3,
256 NET_LAN92XX_GPMC_CONFIG4,
257 NET_LAN92XX_GPMC_CONFIG5,
258 NET_LAN92XX_GPMC_CONFIG6,
259};
260
261int board_eth_init(bd_t *bis)
262{
263 enable_gpmc_cs_config(gpmc_lan92xx_config, &gpmc_cfg->cs[1],
264 CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
265
266 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
267}
268#endif