blob: 8347cf9ce942c86870cfe02905dab1f74f63dd64 [file] [log] [blame]
Stefano Babic18db74a2012-02-07 23:29:34 +00001/*
2 * Copyright (C) 2011
3 * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
4 *
5 * Copyright (C) 2009 TechNexion Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc.
20 */
21
22#include <common.h>
23#include <netdev.h>
Stefano Babicb6320932012-08-29 01:22:07 +000024#include <malloc.h>
Stefano Babic18db74a2012-02-07 23:29:34 +000025#include <fpga.h>
Stefano Babicb6320932012-08-29 01:22:07 +000026#include <video_fb.h>
Stefano Babic18db74a2012-02-07 23:29:34 +000027#include <asm/io.h>
28#include <asm/arch/mem.h>
29#include <asm/arch/mux.h>
30#include <asm/arch/sys_proto.h>
31#include <asm/omap_gpio.h>
32#include <asm/arch/mmc_host_def.h>
Stefano Babicb6320932012-08-29 01:22:07 +000033#include <asm/arch/dss.h>
34#include <asm/arch/clocks.h>
Stefano Babic18db74a2012-02-07 23:29:34 +000035#include <i2c.h>
36#include <spartan3.h>
37#include <asm/gpio.h>
38#ifdef CONFIG_USB_EHCI
39#include <usb.h>
40#include <asm/ehci-omap.h>
41#endif
42#include "mt_ventoux.h"
43
44DECLARE_GLOBAL_DATA_PTR;
45
Stefano Babic63f93152012-08-29 01:22:04 +000046#define BUZZER 140
47#define SPEAKER 141
Stefano Babic3cfc22c2012-10-16 04:02:20 +000048#define USB1_PWR 127
49#define USB2_PWR 149
Stefano Babic63f93152012-08-29 01:22:04 +000050
Stefano Babic18db74a2012-02-07 23:29:34 +000051#ifndef CONFIG_FPGA
52#error "The Teejet mt_ventoux must have CONFIG_FPGA enabled"
53#endif
54
55#define FPGA_RESET 62
56#define FPGA_PROG 116
57#define FPGA_CCLK 117
58#define FPGA_DIN 118
59#define FPGA_INIT 119
60#define FPGA_DONE 154
61
Stefano Babicb6320932012-08-29 01:22:07 +000062#define LCD_PWR 138
63#define LCD_PON_PIN 139
64
65#if defined(CONFIG_VIDEO) && !defined(CONFIG_SPL_BUILD)
66static struct {
67 u32 xres;
68 u32 yres;
69} panel_resolution[] = {
70 { 480, 272 },
71 { 800, 480 }
72};
73
74static struct panel_config lcd_cfg[] = {
75 {
Stefano Babic15bd9962012-11-23 05:19:24 +000076 .timing_h = PANEL_TIMING_H(40, 5, 2),
77 .timing_v = PANEL_TIMING_V(8, 8, 2),
78 .pol_freq = 0x00003000, /* Pol Freq */
79 .divisor = 0x00010033, /* 9 Mhz Pixel Clock */
Stefano Babicb6320932012-08-29 01:22:07 +000080 .panel_type = 0x01, /* TFT */
81 .data_lines = 0x03, /* 24 Bit RGB */
82 .load_mode = 0x02, /* Frame Mode */
83 .panel_color = 0,
Nikita Kiryanov65bd0af2013-01-30 21:39:55 +000084 .gfx_format = GFXFORMAT_RGB24_UNPACKED,
Stefano Babicb6320932012-08-29 01:22:07 +000085 },
86 {
87 .timing_h = PANEL_TIMING_H(20, 192, 4),
88 .timing_v = PANEL_TIMING_V(2, 20, 10),
89 .pol_freq = 0x00004000, /* Pol Freq */
90 .divisor = 0x0001000E, /* 36Mhz Pixel Clock */
91 .panel_type = 0x01, /* TFT */
92 .data_lines = 0x03, /* 24 Bit RGB */
93 .load_mode = 0x02, /* Frame Mode */
94 .panel_color = 0,
Nikita Kiryanov65bd0af2013-01-30 21:39:55 +000095 .gfx_format = GFXFORMAT_RGB24_UNPACKED,
Stefano Babicb6320932012-08-29 01:22:07 +000096 }
97};
98#endif
99
Stefano Babic18db74a2012-02-07 23:29:34 +0000100/* Timing definitions for FPGA */
101static const u32 gpmc_fpga[] = {
102 FPGA_GPMC_CONFIG1,
103 FPGA_GPMC_CONFIG2,
104 FPGA_GPMC_CONFIG3,
105 FPGA_GPMC_CONFIG4,
106 FPGA_GPMC_CONFIG5,
107 FPGA_GPMC_CONFIG6,
108};
109
110#ifdef CONFIG_USB_EHCI
111static struct omap_usbhs_board_data usbhs_bdata = {
112 .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
113 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
114 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
115};
116
Lucas Stach3494a4c2012-09-26 00:14:35 +0200117int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Stefano Babic18db74a2012-02-07 23:29:34 +0000118{
Lucas Stach3494a4c2012-09-26 00:14:35 +0200119 return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
Stefano Babic18db74a2012-02-07 23:29:34 +0000120}
121
Lucas Stach3494a4c2012-09-26 00:14:35 +0200122int ehci_hcd_stop(int index)
Stefano Babic18db74a2012-02-07 23:29:34 +0000123{
124 return omap_ehci_hcd_stop();
125}
126#endif
127
128
129static inline void fpga_reset(int nassert)
130{
131 gpio_set_value(FPGA_RESET, !nassert);
132}
133
134int fpga_pgm_fn(int nassert, int nflush, int cookie)
135{
136 debug("%s:%d: FPGA PROGRAM ", __func__, __LINE__);
137
138 gpio_set_value(FPGA_PROG, !nassert);
139
140 return nassert;
141}
142
143int fpga_init_fn(int cookie)
144{
145 return !gpio_get_value(FPGA_INIT);
146}
147
148int fpga_done_fn(int cookie)
149{
150 return gpio_get_value(FPGA_DONE);
151}
152
153int fpga_pre_config_fn(int cookie)
154{
155 debug("%s:%d: FPGA pre-configuration\n", __func__, __LINE__);
156
157 /* Setting GPIOs for programming Mode */
158 gpio_request(FPGA_RESET, "FPGA_RESET");
159 gpio_direction_output(FPGA_RESET, 1);
160 gpio_request(FPGA_PROG, "FPGA_PROG");
161 gpio_direction_output(FPGA_PROG, 1);
162 gpio_request(FPGA_CCLK, "FPGA_CCLK");
163 gpio_direction_output(FPGA_CCLK, 1);
164 gpio_request(FPGA_DIN, "FPGA_DIN");
165 gpio_direction_output(FPGA_DIN, 0);
166 gpio_request(FPGA_INIT, "FPGA_INIT");
167 gpio_direction_input(FPGA_INIT);
168 gpio_request(FPGA_DONE, "FPGA_DONE");
169 gpio_direction_input(FPGA_DONE);
170
171 /* Be sure that signal are deasserted */
172 gpio_set_value(FPGA_RESET, 1);
173 gpio_set_value(FPGA_PROG, 1);
174
175 return 0;
176}
177
178int fpga_post_config_fn(int cookie)
179{
180 debug("%s:%d: FPGA post-configuration\n", __func__, __LINE__);
181
York Sun4a598092013-04-01 11:29:11 -0700182 fpga_reset(true);
Stefano Babic18db74a2012-02-07 23:29:34 +0000183 udelay(100);
York Sun4a598092013-04-01 11:29:11 -0700184 fpga_reset(false);
Stefano Babic18db74a2012-02-07 23:29:34 +0000185
186 return 0;
187}
188
189/* Write program to the FPGA */
190int fpga_wr_fn(int nassert_write, int flush, int cookie)
191{
192 gpio_set_value(FPGA_DIN, nassert_write);
193
194 return nassert_write;
195}
196
197int fpga_clk_fn(int assert_clk, int flush, int cookie)
198{
199 gpio_set_value(FPGA_CCLK, assert_clk);
200
201 return assert_clk;
202}
203
204Xilinx_Spartan3_Slave_Serial_fns mt_ventoux_fpga_fns = {
205 fpga_pre_config_fn,
206 fpga_pgm_fn,
207 fpga_clk_fn,
208 fpga_init_fn,
209 fpga_done_fn,
210 fpga_wr_fn,
211 fpga_post_config_fn,
212};
213
214Xilinx_desc fpga = XILINX_XC6SLX4_DESC(slave_serial,
215 (void *)&mt_ventoux_fpga_fns, 0);
216
217/* Initialize the FPGA */
218static void mt_ventoux_init_fpga(void)
219{
220 fpga_pre_config_fn(0);
221
222 /* Setting CS1 for FPGA access */
223 enable_gpmc_cs_config(gpmc_fpga, &gpmc_cfg->cs[1],
224 FPGA_BASE_ADDR, GPMC_SIZE_128M);
225
226 fpga_init();
227 fpga_add(fpga_xilinx, &fpga);
228}
229
230/*
231 * Routine: board_init
232 * Description: Early hardware init.
233 */
234int board_init(void)
235{
236 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
237
238 /* boot param addr */
239 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
240
241 mt_ventoux_init_fpga();
242
Stefano Babic63f93152012-08-29 01:22:04 +0000243 /* GPIO_140: speaker #mute */
244 MUX_VAL(CP(MCBSP3_DX), (IEN | PTU | EN | M4))
245 /* GPIO_141: Buzz Hi */
246 MUX_VAL(CP(MCBSP3_DR), (IEN | PTU | EN | M4))
247
248 /* Turning off the buzzer */
249 gpio_request(BUZZER, "BUZZER_MUTE");
250 gpio_request(SPEAKER, "SPEAKER");
251 gpio_direction_output(BUZZER, 0);
252 gpio_direction_output(SPEAKER, 0);
253
Stefano Babic3cfc22c2012-10-16 04:02:20 +0000254 /* Activate USB power */
255 gpio_request(USB1_PWR, "USB1_PWR");
256 gpio_request(USB2_PWR, "USB2_PWR");
257 gpio_direction_output(USB1_PWR, 1);
258 gpio_direction_output(USB2_PWR, 1);
259
Stefano Babic18db74a2012-02-07 23:29:34 +0000260 return 0;
261}
262
Stefano Babic0a152e62012-11-23 05:19:25 +0000263#ifndef CONFIG_SPL_BUILD
Stefano Babic85d9c7a2012-08-29 01:22:03 +0000264int misc_init_r(void)
265{
266 char *eth_addr;
Stefano Babic0a152e62012-11-23 05:19:25 +0000267 struct tam3517_module_info info;
268 int ret;
Stefano Babic85d9c7a2012-08-29 01:22:03 +0000269
Stefano Babic0a152e62012-11-23 05:19:25 +0000270 TAM3517_READ_EEPROM(&info, ret);
Stefano Babic85d9c7a2012-08-29 01:22:03 +0000271 dieid_num_r();
272
Stefano Babic0a152e62012-11-23 05:19:25 +0000273 if (ret)
Stefano Babic85d9c7a2012-08-29 01:22:03 +0000274 return 0;
Stefano Babic0a152e62012-11-23 05:19:25 +0000275 eth_addr = getenv("ethaddr");
276 if (!eth_addr)
277 TAM3517_READ_MAC_FROM_EEPROM(&info);
Stefano Babic85d9c7a2012-08-29 01:22:03 +0000278
Stefano Babic0a152e62012-11-23 05:19:25 +0000279 TAM3517_PRINT_SOM_INFO(&info);
Stefano Babic85d9c7a2012-08-29 01:22:03 +0000280 return 0;
281}
Stefano Babic0a152e62012-11-23 05:19:25 +0000282#endif
Stefano Babic85d9c7a2012-08-29 01:22:03 +0000283
Stefano Babic18db74a2012-02-07 23:29:34 +0000284/*
285 * Routine: set_muxconf_regs
286 * Description: Setting up the configuration Mux registers specific to the
287 * hardware. Many pins need to be moved from protect to primary
288 * mode.
289 */
290void set_muxconf_regs(void)
291{
292 MUX_MT_VENTOUX();
293}
294
295/*
296 * Initializes on-chip ethernet controllers.
297 * to override, implement board_eth_init()
298 */
299int board_eth_init(bd_t *bis)
300{
301 davinci_emac_initialize();
302 return 0;
303}
304
305#if defined(CONFIG_OMAP_HSMMC) && \
306 !defined(CONFIG_SPL_BUILD)
307int board_mmc_init(bd_t *bis)
308{
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +0000309 return omap_mmc_init(0, 0, 0, -1, -1);
Stefano Babic18db74a2012-02-07 23:29:34 +0000310}
311#endif
Stefano Babicb6320932012-08-29 01:22:07 +0000312
313#if defined(CONFIG_VIDEO) && !defined(CONFIG_SPL_BUILD)
314int board_video_init(void)
315{
316 struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
317 struct panel_config *panel = &lcd_cfg[0];
318 char *s;
319 u32 index = 0;
320
321 void *fb;
322
323 fb = (void *)0x88000000;
324
325 s = getenv("panel");
326 if (s) {
327 index = simple_strtoul(s, NULL, 10);
328 if (index < ARRAY_SIZE(lcd_cfg))
329 panel = &lcd_cfg[index];
330 else
331 return 0;
332 }
333
334 panel->frame_buffer = fb;
335 printf("Panel: %dx%d\n", panel_resolution[index].xres,
336 panel_resolution[index].yres);
337 panel->lcd_size = (panel_resolution[index].yres - 1) << 16 |
338 (panel_resolution[index].xres - 1);
339
340 gpio_request(LCD_PWR, "LCD Power");
341 gpio_request(LCD_PON_PIN, "LCD Pon");
342 gpio_direction_output(LCD_PWR, 0);
343 gpio_direction_output(LCD_PON_PIN, 1);
344
345
346 setbits_le32(&prcm_base->fclken_dss, FCK_DSS_ON);
347 setbits_le32(&prcm_base->iclken_dss, ICK_DSS_ON);
348
349 omap3_dss_panel_config(panel);
350 omap3_dss_enable();
351
352 return 0;
353}
354#endif