]> git.sur5r.net Git - u-boot/blob - board/logicpd/omap3som/omap3logic.c
Merge git://git.denx.de/u-boot-uniphier
[u-boot] / board / logicpd / omap3som / omap3logic.c
1 /*
2  * (C) Copyright 2011
3  * Logic Product Development <www.logicpd.com>
4  *
5  * Author :
6  *      Peter Barada <peter.barada@logicpd.com>
7  *
8  * Derived from Beagle Board and 3430 SDP code by
9  *      Richard Woodruff <r-woodruff2@ti.com>
10  *      Syed Mohammed Khasim <khasim@ti.com>
11  *
12  * SPDX-License-Identifier:     GPL-2.0+
13  */
14 #include <common.h>
15 #include <dm.h>
16 #include <ns16550.h>
17 #include <netdev.h>
18 #include <flash.h>
19 #include <nand.h>
20 #include <i2c.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/mach-types.h>
29 #include <linux/mtd/rawnand.h>
30 #include <asm/omap_musb.h>
31 #include <linux/errno.h>
32 #include <linux/usb/ch9.h>
33 #include <linux/usb/gadget.h>
34 #include <linux/usb/musb.h>
35 #include "omap3logic.h"
36 #ifdef CONFIG_USB_EHCI_HCD
37 #include <usb.h>
38 #include <asm/ehci-omap.h>
39 #endif
40
41 DECLARE_GLOBAL_DATA_PTR;
42
43 /* This is only needed until SPL gets OF support */
44 #ifdef CONFIG_SPL_BUILD
45 static const struct ns16550_platdata omap3logic_serial = {
46         .base = OMAP34XX_UART1,
47         .reg_shift = 2,
48         .clock = V_NS16550_CLK,
49         .fcr = UART_FCR_DEFVAL,
50 };
51
52 U_BOOT_DEVICE(omap3logic_uart) = {
53         "ns16550_serial",
54         &omap3logic_serial
55 };
56 #endif
57
58 /*
59  * two dimensional array of strucures containining board name and Linux
60  * machine IDs; row it selected based on CPU column is slected based
61  * on hsusb0_data5 pin having a pulldown resistor
62  */
63 static struct board_id {
64         char *name;
65         int machine_id;
66         char *fdtfile;
67 } boards[2][2] = {
68         {
69                 {
70                         .name           = "OMAP35xx SOM LV",
71                         .machine_id     = MACH_TYPE_OMAP3530_LV_SOM,
72                         .fdtfile        = "logicpd-som-lv-35xx-devkit.dtb",
73                 },
74                 {
75                         .name           = "OMAP35xx Torpedo",
76                         .machine_id     = MACH_TYPE_OMAP3_TORPEDO,
77                         .fdtfile        = "logicpd-torpedo-35xx-devkit.dtb",
78                 },
79         },
80         {
81                 {
82                         .name           = "DM37xx SOM LV",
83                         .fdtfile        = "logicpd-som-lv-37xx-devkit.dtb",
84                 },
85                 {
86                         .name           = "DM37xx Torpedo",
87                         .fdtfile        = "logicpd-torpedo-37xx-devkit.dtb",
88                 },
89         },
90 };
91
92 #ifdef CONFIG_SPL_OS_BOOT
93 int spl_start_uboot(void)
94 {
95         /* break into full u-boot on 'c' */
96         return serial_tstc() && serial_getc() == 'c';
97 }
98 #endif
99
100 #if defined(CONFIG_SPL_BUILD)
101 /*
102  * Routine: get_board_mem_timings
103  * Description: If we use SPL then there is no x-loader nor config header
104  * so we have to setup the DDR timings ourself on the first bank.  This
105  * provides the timing values back to the function that configures
106  * the memory.
107  */
108 void get_board_mem_timings(struct board_sdrc_timings *timings)
109 {
110         timings->mr = MICRON_V_MR_165;
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 }
117 #endif
118
119 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
120 static struct musb_hdrc_config musb_config = {
121         .multipoint     = 1,
122         .dyn_fifo       = 1,
123         .num_eps        = 16,
124         .ram_bits       = 12,
125 };
126
127 static struct omap_musb_board_data musb_board_data = {
128         .interface_type = MUSB_INTERFACE_ULPI,
129 };
130
131 static struct musb_hdrc_platform_data musb_plat = {
132 #if defined(CONFIG_USB_MUSB_HOST)
133         .mode           = MUSB_HOST,
134 #elif defined(CONFIG_USB_MUSB_GADGET)
135         .mode           = MUSB_PERIPHERAL,
136 #else
137 #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
138 #endif
139         .config         = &musb_config,
140         .power          = 100,
141         .platform_ops   = &omap2430_ops,
142         .board_data     = &musb_board_data,
143 };
144 #endif
145
146 #if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
147 /* Call usb_stop() before starting the kernel */
148 void show_boot_progress(int val)
149 {
150         if (val == BOOTSTAGE_ID_RUN_OS)
151                 usb_stop();
152 }
153
154 static struct omap_usbhs_board_data usbhs_bdata = {
155         .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
156         .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
157         .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
158 };
159
160 int ehci_hcd_init(int index, enum usb_init_type init,
161                 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
162 {
163         return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
164 }
165
166 int ehci_hcd_stop(int index)
167 {
168         return omap_ehci_hcd_stop();
169 }
170
171 #endif /* CONFIG_USB_EHCI_HCD */
172
173
174 /*
175  * Routine: misc_init_r
176  * Description: Configure board specific parts
177  */
178 int misc_init_r(void)
179 {
180         twl4030_power_init();
181         omap_die_id_display();
182
183 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
184         musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
185 #endif
186
187         return 0;
188 }
189
190 /*
191  * BOARD_ID_GPIO - GPIO of pin with optional pulldown resistor on SOM LV
192  */
193 #define BOARD_ID_GPIO   189 /* hsusb0_data5 pin */
194
195 /*
196  * Routine: board_init
197  * Description: Early hardware init.
198  */
199 int board_init(void)
200 {
201         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
202
203         /* boot param addr */
204         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
205
206         return 0;
207 }
208
209 #ifdef CONFIG_BOARD_LATE_INIT
210 int board_late_init(void)
211 {
212         struct board_id *board;
213         unsigned int val;
214
215         /*
216          * To identify between a SOM LV and Torpedo module,
217          * a pulldown resistor is on hsusb0_data5 for the SOM LV module.
218          * Drive the pin (and let it soak), then read it back.
219          * If the pin is still high its a Torpedo.  If low its a SOM LV
220          */
221
222         /* Mux hsusb0_data5 as a GPIO */
223         MUX_VAL(CP(HSUSB0_DATA5),       (IEN  | PTD | DIS | M4));
224
225         if (gpio_request(BOARD_ID_GPIO, "husb0_data5.gpio_189") == 0) {
226
227                 /*
228                  * Drive BOARD_ID_GPIO - the pulldown resistor on the SOM LV
229                  * will drain the voltage.
230                  */
231                 gpio_direction_output(BOARD_ID_GPIO, 0);
232                 gpio_set_value(BOARD_ID_GPIO, 1);
233
234                 /* Let it soak for a bit */
235                 sdelay(0x100);
236
237                 /*
238                  * Read state of BOARD_ID_GPIO as an input and if its set.
239                  * If so the board is a Torpedo
240                  */
241                 gpio_direction_input(BOARD_ID_GPIO);
242                 val = gpio_get_value(BOARD_ID_GPIO);
243                 gpio_free(BOARD_ID_GPIO);
244
245                 board = &boards[!!(get_cpu_family() == CPU_OMAP36XX)][!!val];
246                 printf("Board: %s\n", board->name);
247
248                 /* Set the machine_id passed to Linux */
249                 if (board->machine_id)
250                         gd->bd->bi_arch_number = board->machine_id;
251
252                 /* If the user has not set fdtimage, set the default */
253                 if (!env_get("fdtimage"))
254                         env_set("fdtimage", board->fdtfile);
255         }
256
257         /* restore hsusb0_data5 pin as hsusb0_data5 */
258         MUX_VAL(CP(HSUSB0_DATA5),       (IEN  | PTD | DIS | M0));
259         return 0;
260 }
261 #endif
262
263 #if defined(CONFIG_MMC)
264 int board_mmc_init(bd_t *bis)
265 {
266         return omap_mmc_init(0, 0, 0, -1, -1);
267 }
268 #endif
269
270 #if defined(CONFIG_MMC)
271 void board_mmc_power_init(void)
272 {
273         twl4030_power_mmc_init(0);
274 }
275 #endif
276
277 #ifdef CONFIG_SMC911X
278 /* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */
279 static const u32 gpmc_lan92xx_config[] = {
280         NET_LAN92XX_GPMC_CONFIG1,
281         NET_LAN92XX_GPMC_CONFIG2,
282         NET_LAN92XX_GPMC_CONFIG3,
283         NET_LAN92XX_GPMC_CONFIG4,
284         NET_LAN92XX_GPMC_CONFIG5,
285         NET_LAN92XX_GPMC_CONFIG6,
286 };
287
288 int board_eth_init(bd_t *bis)
289 {
290         enable_gpmc_cs_config(gpmc_lan92xx_config, &gpmc_cfg->cs[1],
291                         CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
292
293         return smc911x_initialize(0, CONFIG_SMC911X_BASE);
294 }
295 #endif
296
297