common: Move serial functions out of common.h
[platform/kernel/u-boot.git] / board / logicpd / omap3som / omap3logic.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
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>
12  */
13 #include <common.h>
14 #include <dm.h>
15 #include <ns16550.h>
16 #include <netdev.h>
17 #include <flash.h>
18 #include <nand.h>
19 #include <i2c.h>
20 #include <serial.h>
21 #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>
28 #include <asm/omap_mmc.h>
29 #include <asm/mach-types.h>
30 #include <linux/mtd/rawnand.h>
31 #include <asm/omap_musb.h>
32 #include <linux/errno.h>
33 #include <linux/usb/ch9.h>
34 #include <linux/usb/gadget.h>
35 #include <linux/usb/musb.h>
36 #include "omap3logic.h"
37 #ifdef CONFIG_USB_EHCI_HCD
38 #include <usb.h>
39 #include <asm/ehci-omap.h>
40 #endif
41
42 DECLARE_GLOBAL_DATA_PTR;
43
44 #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
60 #ifdef CONFIG_SPL_OS_BOOT
61 int spl_start_uboot(void)
62 {
63         /* break into full u-boot on 'c' */
64         return serial_tstc() && serial_getc() == 'c';
65 }
66 #endif
67
68 #if defined(CONFIG_SPL_BUILD)
69 /*
70  * Routine: get_board_mem_timings
71  * Description: If we use SPL then there is no x-loader nor config header
72  * so we have to setup the DDR timings ourself on the first bank.  This
73  * provides the timing values back to the function that configures
74  * the memory.
75  */
76 void get_board_mem_timings(struct board_sdrc_timings *timings)
77 {
78         timings->mr = MICRON_V_MR_165;
79
80         if (get_cpu_family() == CPU_OMAP36XX) {
81                 /* 200 MHz works for OMAP36/DM37 */
82                 /* 256MB DDR */
83                 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
84                 timings->ctrla = MICRON_V_ACTIMA_200;
85                 timings->ctrlb = MICRON_V_ACTIMB_200;
86                 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
87         } else {
88                 /* 165 MHz works for OMAP35 */
89                 timings->mcfg = MICRON_V_MCFG_165(256 << 20);
90                 timings->ctrla = MICRON_V_ACTIMA_165;
91                 timings->ctrlb = MICRON_V_ACTIMB_165;
92                 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
93         }
94 }
95
96 #define GPMC_NAND_COMMAND_0 (OMAP34XX_GPMC_BASE + 0x7c)
97 #define GPMC_NAND_DATA_0 (OMAP34XX_GPMC_BASE + 0x84)
98 #define GPMC_NAND_ADDRESS_0 (OMAP34XX_GPMC_BASE + 0x80)
99
100 void spl_board_prepare_for_linux(void)
101 {
102         /* The Micron NAND starts locked which
103          * prohibits mounting the NAND as RW
104          * The following commands are what unlocks
105          * the NAND to become RW Falcon Mode does not
106          * have as many smarts as U-Boot, but Logic PD
107          * only makes NAND with 512MB so these hard coded
108          * values should work for all current models
109          */
110
111         writeb(0x70, GPMC_NAND_COMMAND_0);
112         writeb(-1, GPMC_NAND_DATA_0);
113         writeb(0x7a, GPMC_NAND_COMMAND_0);
114         writeb(0x00, GPMC_NAND_ADDRESS_0);
115         writeb(0x00, GPMC_NAND_ADDRESS_0);
116         writeb(0x00, GPMC_NAND_ADDRESS_0);
117         writeb(-1, GPMC_NAND_COMMAND_0);
118
119         /* Begin address 0 */
120         writeb(NAND_CMD_UNLOCK1, 0x6e00007c);
121         writeb(0x00, GPMC_NAND_ADDRESS_0);
122         writeb(0x00, GPMC_NAND_ADDRESS_0);
123         writeb(0x00, GPMC_NAND_ADDRESS_0);
124         writeb(-1, GPMC_NAND_DATA_0);
125
126         /* Ending address at the end of Flash */
127         writeb(NAND_CMD_UNLOCK2, GPMC_NAND_COMMAND_0);
128         writeb(0xc0, GPMC_NAND_ADDRESS_0);
129         writeb(0xff, GPMC_NAND_ADDRESS_0);
130         writeb(0x03, GPMC_NAND_ADDRESS_0);
131         writeb(-1, GPMC_NAND_DATA_0);
132         writeb(0x79, GPMC_NAND_COMMAND_0);
133         writeb(-1, GPMC_NAND_DATA_0);
134         writeb(-1, GPMC_NAND_DATA_0);
135 }
136 #endif
137
138 /*
139  * Routine: misc_init_r
140  * Description: Configure board specific parts
141  */
142 int misc_init_r(void)
143 {
144         twl4030_power_init();
145         twl4030_power_mmc_init(0);
146         omap_die_id_display();
147         return 0;
148 }
149
150 #if defined(CONFIG_FLASH_CFI_DRIVER)
151 static const u32 gpmc_dm37_c2nor_config[] = {
152         LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG1,
153         LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG2,
154         LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG3,
155         LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG4,
156         LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG5,
157         LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG6,
158         LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG7
159 };
160
161 static const u32 gpmc_omap35_c2nor_config[] = {
162         LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG1,
163         LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG2,
164         LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG3,
165         LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG4,
166         LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG5,
167         LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG6,
168         LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG7
169 };
170 #endif
171
172 /*
173  * Routine: board_init
174  * Description: Early hardware init.
175  */
176 int board_init(void)
177 {
178         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
179
180         /* boot param addr */
181         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
182 #if defined(CONFIG_FLASH_CFI_DRIVER)
183         if (get_cpu_family() == CPU_OMAP36XX) {
184                 /* Enable CS2 for NOR Flash */
185                 enable_gpmc_cs_config(gpmc_dm37_c2nor_config, &gpmc_cfg->cs[2],
186                                       0x10000000, GPMC_SIZE_64M);
187         } else {
188                 enable_gpmc_cs_config(gpmc_omap35_c2nor_config, &gpmc_cfg->cs[2],
189                                       0x10000000, GPMC_SIZE_64M);
190         }
191 #endif
192         return 0;
193 }
194
195 #ifdef CONFIG_BOARD_LATE_INIT
196
197 static void unlock_nand(void)
198 {
199         int dev = nand_curr_device;
200         struct mtd_info *mtd;
201
202         mtd = get_nand_dev_by_index(dev);
203         nand_unlock(mtd, 0, mtd->size, 0);
204 }
205
206 int board_late_init(void)
207 {
208 #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
209         unlock_nand();
210 #endif
211         return 0;
212 }
213 #endif
214
215 #if defined(CONFIG_MMC)
216 void board_mmc_power_init(void)
217 {
218         twl4030_power_mmc_init(0);
219 }
220 #endif
221
222 #ifdef CONFIG_SMC911X
223 /* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */
224 static const u32 gpmc_lan92xx_config[] = {
225         NET_LAN92XX_GPMC_CONFIG1,
226         NET_LAN92XX_GPMC_CONFIG2,
227         NET_LAN92XX_GPMC_CONFIG3,
228         NET_LAN92XX_GPMC_CONFIG4,
229         NET_LAN92XX_GPMC_CONFIG5,
230         NET_LAN92XX_GPMC_CONFIG6,
231 };
232
233 int board_eth_init(bd_t *bis)
234 {
235         enable_gpmc_cs_config(gpmc_lan92xx_config, &gpmc_cfg->cs[1],
236                         CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
237
238         return smc911x_initialize(0, CONFIG_SMC911X_BASE);
239 }
240 #endif