blob: 8bd4223b2bb11e8f75c0f0bf605440c23cb4a9b9 [file] [log] [blame]
stroese1f54ce62004-12-16 18:23:14 +00001/*
2 * (C) Copyright 2001-2004
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4 *
Stefan Roese98f4a3d2005-09-22 09:04:17 +02005 * (C) Copyright 2005
6 * Stefan Roese, DENX Software Engineering, sr@denx.de.
7 *
Matthias Fuchsbd84ee42007-07-09 10:10:06 +02008 * (C) Copyright 2006-2007
Stefan Roese48a05a52006-02-07 16:51:04 +01009 * Matthias Fuchs, esd GmbH, matthias.fuchs@esd-electronics.com
10 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020011 * SPDX-License-Identifier: GPL-2.0+
stroese1f54ce62004-12-16 18:23:14 +000012 */
13
14#include <common.h>
15#include <asm/processor.h>
Matthias Fuchsbb57ad42009-02-20 10:19:19 +010016#include <asm/io.h>
stroese1f54ce62004-12-16 18:23:14 +000017#include <command.h>
18#include <malloc.h>
Stefan Roese98f4a3d2005-09-22 09:04:17 +020019#include <pci.h>
20#include <sm501.h>
stroese1f54ce62004-12-16 18:23:14 +000021
Wolfgang Denkd87080b2006-03-31 18:32:53 +020022DECLARE_GLOBAL_DATA_PTR;
23
Matthias Fuchsbb57ad42009-02-20 10:19:19 +010024/* FPGA internal regs */
25#define FPGA_CTRL ((u16 *)(CONFIG_SYS_FPGA_BASE_ADDR + 0x000))
26#define FPGA_STATUS ((u16 *)(CONFIG_SYS_FPGA_BASE_ADDR + 0x002))
27#define FPGA_CTR ((u16 *)(CONFIG_SYS_FPGA_BASE_ADDR + 0x004))
28#define FPGA_BL ((u16 *)(CONFIG_SYS_FPGA_BASE_ADDR + 0x006))
29
30/* FPGA Control Reg */
31#define FPGA_CTRL_REV0 0x0001
32#define FPGA_CTRL_REV1 0x0002
33#define FPGA_CTRL_VGA0_BL 0x0004
34#define FPGA_CTRL_VGA0_BL_MODE 0x0008
35#define FPGA_CTRL_CF_RESET 0x0040
36#define FPGA_CTRL_PS2_PWR 0x0080
37#define FPGA_CTRL_CF_PWRN 0x0100 /* low active */
38#define FPGA_CTRL_CF_BUS_EN 0x0200
39#define FPGA_CTRL_LCD_CLK 0x7000 /* mask for lcd clock */
40#define FPGA_CTRL_OW_ENABLE 0x8000
41
42#define FPGA_STATUS_CF_DETECT 0x8000
43
Stefan Roese98f4a3d2005-09-22 09:04:17 +020044#ifdef CONFIG_VIDEO_SM501
45
46#define SWAP32(x) ((((x) & 0x000000ff) << 24) | (((x) & 0x0000ff00) << 8)|\
47 (((x) & 0x00ff0000) >> 8) | (((x) & 0xff000000) >> 24) )
48
49#ifdef CONFIG_VIDEO_SM501_8BPP
50#error CONFIG_VIDEO_SM501_8BPP not supported.
51#endif /* CONFIG_VIDEO_SM501_8BPP */
52
53#ifdef CONFIG_VIDEO_SM501_16BPP
54#define BPP 16
55
56/*
57 * 800x600 display B084SN03: PCLK = 40MHz
58 * => 2*PCLK = 80MHz
59 * 336/4 = 84MHz
60 * => PCLK = 84MHz
61 */
62static const SMI_REGS init_regs_800x600 [] =
63{
64#if 1 /* test-only */
65 {0x0005c, SWAP32(0xffffffff)}, /* set endianess to big endian */
66#else
67 {0x0005c, SWAP32(0x00000000)}, /* set endianess to little endian */
68#endif
69 {0x00004, SWAP32(0x00000000)},
70 /* clocks for pm1... */
71 {0x00048, SWAP32(0x00021807)},
72 {0x0004C, SWAP32(0x221a0a01)},
73 {0x00054, SWAP32(0x00000001)},
74 /* clocks for pm0... */
75 {0x00040, SWAP32(0x00021807)},
76 {0x00044, SWAP32(0x221a0a01)},
77 {0x00054, SWAP32(0x00000000)},
Stefan Roese48a05a52006-02-07 16:51:04 +010078 /* GPIO */
79 {0x1000c, SWAP32(0xfffffff0)}, /* GPIO32..63 direction */
Stefan Roese98f4a3d2005-09-22 09:04:17 +020080 /* panel control regs... */
81 {0x80000, SWAP32(0x0f013105)}, /* panel display control: 16-bit RGB 5:6:5 mode */
82 {0x80004, SWAP32(0xc428bb17)}, /* panel panning control ??? */
Stefan Roese48a05a52006-02-07 16:51:04 +010083 {0x8000C, SWAP32(0x00010000)}, /* panel fb address */
Stefan Roese98f4a3d2005-09-22 09:04:17 +020084 {0x80010, SWAP32(0x06400640)}, /* panel fb offset/window width */
85 {0x80014, SWAP32(0x03200000)}, /* panel fb width (0x320=800) */
86 {0x80018, SWAP32(0x02580000)}, /* panel fb height (0x258=600) */
87 {0x8001C, SWAP32(0x00000000)}, /* panel plane tl location */
88 {0x80020, SWAP32(0x02580320)}, /* panel plane br location */
89 {0x80024, SWAP32(0x041f031f)}, /* panel horizontal total */
90 {0x80028, SWAP32(0x00800347)}, /* panel horizontal sync */
91 {0x8002C, SWAP32(0x02730257)}, /* panel vertical total */
92 {0x80030, SWAP32(0x00040258)}, /* panel vertical sync */
93 {0x80200, SWAP32(0x00010000)}, /* crt display control */
94 {0, 0}
95};
96
97/*
98 * 1024x768 display G150XG02: PCLK = 65MHz
99 * => 2*PCLK = 130MHz
100 * 288/2 = 144MHz
101 * => PCLK = 72MHz
102 */
103static const SMI_REGS init_regs_1024x768 [] =
104{
105 {0x00004, SWAP32(0x00000000)},
106 /* clocks for pm1... */
107 {0x00048, SWAP32(0x00021807)},
108 {0x0004C, SWAP32(0x011a0a01)},
109 {0x00054, SWAP32(0x00000001)},
110 /* clocks for pm0... */
111 {0x00040, SWAP32(0x00021807)},
112 {0x00044, SWAP32(0x011a0a01)},
113 {0x00054, SWAP32(0x00000000)},
Stefan Roese48a05a52006-02-07 16:51:04 +0100114 /* GPIO */
115 {0x1000c, SWAP32(0xfffffff0)}, /* GPIO32..63 direction */
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200116 /* panel control regs... */
117 {0x80000, SWAP32(0x0f013105)}, /* panel display control: 16-bit RGB 5:6:5 mode */
118 {0x80004, SWAP32(0xc428bb17)}, /* panel panning control ??? */
Stefan Roese48a05a52006-02-07 16:51:04 +0100119 {0x8000C, SWAP32(0x00010000)}, /* panel fb address */
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200120 {0x80010, SWAP32(0x08000800)}, /* panel fb offset/window width */
121 {0x80014, SWAP32(0x04000000)}, /* panel fb width (0x400=1024) */
122 {0x80018, SWAP32(0x03000000)}, /* panel fb height (0x300=768) */
123 {0x8001C, SWAP32(0x00000000)}, /* panel plane tl location */
124 {0x80020, SWAP32(0x03000400)}, /* panel plane br location */
125 {0x80024, SWAP32(0x053f03ff)}, /* panel horizontal total */
126 {0x80028, SWAP32(0x0140040f)}, /* panel horizontal sync */
127 {0x8002C, SWAP32(0x032502ff)}, /* panel vertical total */
128 {0x80030, SWAP32(0x00260301)}, /* panel vertical sync */
129 {0x80200, SWAP32(0x00010000)}, /* crt display control */
130 {0, 0}
131};
132
133#endif /* CONFIG_VIDEO_SM501_16BPP */
134
135#ifdef CONFIG_VIDEO_SM501_32BPP
136#define BPP 32
137
138/*
139 * 800x600 display B084SN03: PCLK = 40MHz
140 * => 2*PCLK = 80MHz
141 * 336/4 = 84MHz
142 * => PCLK = 84MHz
143 */
144static const SMI_REGS init_regs_800x600 [] =
145{
146#if 0 /* test-only */
147 {0x0005c, SWAP32(0xffffffff)}, /* set endianess to big endian */
148#else
149 {0x0005c, SWAP32(0x00000000)}, /* set endianess to little endian */
150#endif
151 {0x00004, SWAP32(0x00000000)},
152 /* clocks for pm1... */
153 {0x00048, SWAP32(0x00021807)},
154 {0x0004C, SWAP32(0x221a0a01)},
155 {0x00054, SWAP32(0x00000001)},
156 /* clocks for pm0... */
157 {0x00040, SWAP32(0x00021807)},
158 {0x00044, SWAP32(0x221a0a01)},
159 {0x00054, SWAP32(0x00000000)},
Stefan Roese48a05a52006-02-07 16:51:04 +0100160 /* GPIO */
161 {0x1000c, SWAP32(0xfffffff0)}, /* GPIO32..63 direction */
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200162 /* panel control regs... */
163 {0x80000, SWAP32(0x0f013106)}, /* panel display control: 32-bit RGB 8:8:8 mode */
164 {0x80004, SWAP32(0xc428bb17)}, /* panel panning control ??? */
Stefan Roese48a05a52006-02-07 16:51:04 +0100165 {0x8000C, SWAP32(0x00010000)}, /* panel fb address */
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200166 {0x80010, SWAP32(0x0c800c80)}, /* panel fb offset/window width */
167 {0x80014, SWAP32(0x03200000)}, /* panel fb width (0x320=800) */
168 {0x80018, SWAP32(0x02580000)}, /* panel fb height (0x258=600) */
169 {0x8001C, SWAP32(0x00000000)}, /* panel plane tl location */
170 {0x80020, SWAP32(0x02580320)}, /* panel plane br location */
171 {0x80024, SWAP32(0x041f031f)}, /* panel horizontal total */
172 {0x80028, SWAP32(0x00800347)}, /* panel horizontal sync */
173 {0x8002C, SWAP32(0x02730257)}, /* panel vertical total */
174 {0x80030, SWAP32(0x00040258)}, /* panel vertical sync */
175 {0x80200, SWAP32(0x00010000)}, /* crt display control */
176 {0, 0}
177};
178
179/*
180 * 1024x768 display G150XG02: PCLK = 65MHz
181 * => 2*PCLK = 130MHz
182 * 288/2 = 144MHz
183 * => PCLK = 72MHz
184 */
185static const SMI_REGS init_regs_1024x768 [] =
186{
187 {0x00004, SWAP32(0x00000000)},
188 /* clocks for pm1... */
189 {0x00048, SWAP32(0x00021807)},
190 {0x0004C, SWAP32(0x011a0a01)},
191 {0x00054, SWAP32(0x00000001)},
192 /* clocks for pm0... */
193 {0x00040, SWAP32(0x00021807)},
194 {0x00044, SWAP32(0x011a0a01)},
195 {0x00054, SWAP32(0x00000000)},
Stefan Roese48a05a52006-02-07 16:51:04 +0100196 /* GPIO */
197 {0x1000c, SWAP32(0xfffffff0)}, /* GPIO32..63 direction */
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200198 /* panel control regs... */
199 {0x80000, SWAP32(0x0f013106)}, /* panel display control: 32-bit RGB 8:8:8 mode */
200 {0x80004, SWAP32(0xc428bb17)}, /* panel panning control ??? */
Stefan Roese48a05a52006-02-07 16:51:04 +0100201 {0x8000C, SWAP32(0x00010000)}, /* panel fb address */
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200202 {0x80010, SWAP32(0x10001000)}, /* panel fb offset/window width */
203 {0x80014, SWAP32(0x04000000)}, /* panel fb width (0x400=1024) */
204 {0x80018, SWAP32(0x03000000)}, /* panel fb height (0x300=768) */
205 {0x8001C, SWAP32(0x00000000)}, /* panel plane tl location */
206 {0x80020, SWAP32(0x03000400)}, /* panel plane br location */
207 {0x80024, SWAP32(0x053f03ff)}, /* panel horizontal total */
208 {0x80028, SWAP32(0x0140040f)}, /* panel horizontal sync */
209 {0x8002C, SWAP32(0x032502ff)}, /* panel vertical total */
210 {0x80030, SWAP32(0x00260301)}, /* panel vertical sync */
211 {0x80200, SWAP32(0x00010000)}, /* crt display control */
212 {0, 0}
213};
214
215#endif /* CONFIG_VIDEO_SM501_32BPP */
216
217#endif /* CONFIG_VIDEO_SM501 */
stroese1f54ce62004-12-16 18:23:14 +0000218
219#if 0
220#define FPGA_DEBUG
221#endif
222
stroese1f54ce62004-12-16 18:23:14 +0000223extern void lxt971_no_sleep(void);
224
225/* fpga configuration data - gzip compressed and generated by bin2c */
226const unsigned char fpgadata[] =
227{
228#include "fpgadata.c"
229};
230
231/*
232 * include common fpga code (for esd boards)
233 */
234#include "../common/fpga.c"
235
236
stroese1f54ce62004-12-16 18:23:14 +0000237/* logo bitmap data - gzip compressed and generated by bin2c */
238unsigned char logo_bmp_320[] =
239{
240#include "logo_320_240_4bpp.c"
241};
242
243unsigned char logo_bmp_320_8bpp[] =
244{
245#include "logo_320_240_8bpp.c"
246};
247
248unsigned char logo_bmp_640[] =
249{
250#include "logo_640_480_24bpp.c"
251};
252
253unsigned char logo_bmp_1024[] =
254{
255#include "logo_1024_768_8bpp.c"
256};
257
258
259/*
260 * include common lcd code (for esd boards)
261 */
262#include "../common/lcd.c"
263
264#include "../common/s1d13704_320_240_4bpp.h"
265#include "../common/s1d13705_320_240_8bpp.h"
266#include "../common/s1d13806_640_480_16bpp.h"
267#include "../common/s1d13806_1024_768_8bpp.h"
268
269
270/*
271 * include common auto-update code (for esd boards)
272 */
273#include "../common/auto_update.h"
274
275au_image_t au_image[] = {
276 {"hh405/preinst.img", 0, -1, AU_SCRIPT},
277 {"hh405/u-boot.img", 0xfff80000, 0x00080000, AU_FIRMWARE},
Wolfgang Denkfe126d82005-11-20 21:40:11 +0100278 {"hh405/pImage_${bd_type}", 0x00000000, 0x00100000, AU_NAND},
stroese1f54ce62004-12-16 18:23:14 +0000279 {"hh405/pImage.initrd", 0x00100000, 0x00200000, AU_NAND},
280 {"hh405/yaffsmt2.img", 0x00300000, 0x01c00000, AU_NAND},
281 {"hh405/postinst.img", 0, 0, AU_SCRIPT},
282};
283
284int N_AU_IMAGES = (sizeof(au_image) / sizeof(au_image[0]));
285
286
Stefan Roese48a05a52006-02-07 16:51:04 +0100287/*
288 * Get version of HH405 board from GPIO's
289 */
stroese1f54ce62004-12-16 18:23:14 +0000290int board_revision(void)
291{
292 unsigned long osrh_reg;
293 unsigned long isr1h_reg;
294 unsigned long tcr_reg;
295 unsigned long value;
296
297 /*
stroese1f54ce62004-12-16 18:23:14 +0000298 * Setup GPIO pins (BLAST/GPIO0 and GPIO9 as GPIO)
299 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100300 osrh_reg = in_be32((void *)GPIO0_OSRH);
301 isr1h_reg = in_be32((void *)GPIO0_ISR1H);
302 tcr_reg = in_be32((void *)GPIO0_TCR);
303 out_be32((void *)GPIO0_OSRH, osrh_reg & ~0xC0003000); /* output select */
304 out_be32((void *)GPIO0_ISR1H, isr1h_reg | 0xC0003000); /* input select */
305 out_be32((void *)GPIO0_TCR, tcr_reg & ~0x80400000); /* select input */
stroese1f54ce62004-12-16 18:23:14 +0000306
307 udelay(1000); /* wait some time before reading input */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100308 value = in_be32((void *)GPIO0_IR) & 0x80400000; /* get config bits */
stroese1f54ce62004-12-16 18:23:14 +0000309
310 /*
311 * Restore GPIO settings
312 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100313 out_be32((void *)GPIO0_OSRH, osrh_reg); /* output select */
314 out_be32((void *)GPIO0_ISR1H, isr1h_reg); /* input select */
315 out_be32((void *)GPIO0_TCR, tcr_reg); /* enable output driver for outputs */
stroese1f54ce62004-12-16 18:23:14 +0000316
317 if (value & 0x80000000) {
318 /* Revision 1.0 or 1.1 detected */
Stefan Roese48a05a52006-02-07 16:51:04 +0100319 return 1;
stroese1f54ce62004-12-16 18:23:14 +0000320 } else {
321 if (value & 0x00400000) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200322 /* unused */
Stefan Roese48a05a52006-02-07 16:51:04 +0100323 return 3;
stroese1f54ce62004-12-16 18:23:14 +0000324 } else {
Stefan Roese48a05a52006-02-07 16:51:04 +0100325 return 2;
stroese1f54ce62004-12-16 18:23:14 +0000326 }
327 }
328}
329
330
331int board_early_init_f (void)
332{
333 /*
334 * IRQ 0-15 405GP internally generated; active high; level sensitive
335 * IRQ 16 405GP internally generated; active low; level sensitive
336 * IRQ 17-24 RESERVED
337 * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
338 * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
339 * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
340 * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
341 * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
342 * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
343 * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
344 */
Stefan Roese952e7762009-09-24 09:55:50 +0200345 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
346 mtdcr(UIC0ER, 0x00000000); /* disable all ints */
347 mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/
348 mtdcr(UIC0PR, CONFIG_SYS_UIC0_POLARITY);/* set int polarities */
349 mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
350 mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority*/
351 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
stroese1f54ce62004-12-16 18:23:14 +0000352
353 /*
354 * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
355 */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200356 mtebc(EBC0_CFG, 0xa8400000); /* ebc always driven */
stroese1f54ce62004-12-16 18:23:14 +0000357
358 return 0;
359}
360
Stefan Roese48a05a52006-02-07 16:51:04 +0100361int cf_enable(void)
362{
Stefan Roese48a05a52006-02-07 16:51:04 +0100363 int i;
364
Stefan Roese48a05a52006-02-07 16:51:04 +0100365 if (gd->board_type >= 2) {
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100366 if (in_be16(FPGA_STATUS) & FPGA_STATUS_CF_DETECT) {
367 if (!(in_be16(FPGA_CTRL) & FPGA_CTRL_CF_BUS_EN)) {
368 out_be16(FPGA_CTRL,
369 in_be16(FPGA_CTRL) & ~FPGA_CTRL_CF_PWRN);
Stefan Roese48a05a52006-02-07 16:51:04 +0100370
371 for (i=0; i<300; i++)
372 udelay(1000);
373
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100374 out_be16(FPGA_CTRL,
375 in_be16(FPGA_CTRL) | FPGA_CTRL_CF_BUS_EN);
Stefan Roese48a05a52006-02-07 16:51:04 +0100376
377 for (i=0; i<20; i++)
378 udelay(1000);
379 }
380 } else {
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100381 out_be16(FPGA_CTRL,
382 in_be16(FPGA_CTRL) & ~FPGA_CTRL_CF_BUS_EN);
383 out_be16(FPGA_CTRL,
384 in_be16(FPGA_CTRL) | FPGA_CTRL_CF_PWRN);
Stefan Roese48a05a52006-02-07 16:51:04 +0100385 }
386 }
387
388 return 0;
389}
stroese1f54ce62004-12-16 18:23:14 +0000390
391int misc_init_r (void)
392{
stroese1f54ce62004-12-16 18:23:14 +0000393 unsigned char *dst;
394 ulong len = sizeof(fpgadata);
395 int status;
396 int index;
397 int i;
398 char *str;
399 unsigned long contrast0 = 0xffffffff;
400
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200401 dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
402 if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
stroese1f54ce62004-12-16 18:23:14 +0000403 printf ("GUNZIP ERROR - must RESET board to recover\n");
404 do_reset (NULL, 0, 0, NULL);
405 }
406
407 status = fpga_boot(dst, len);
408 if (status != 0) {
409 printf("\nFPGA: Booting failed ");
410 switch (status) {
411 case ERROR_FPGA_PRG_INIT_LOW:
412 printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
413 break;
414 case ERROR_FPGA_PRG_INIT_HIGH:
415 printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
416 break;
417 case ERROR_FPGA_PRG_DONE:
418 printf("(Timeout: DONE not high after programming FPGA)\n ");
419 break;
420 }
421
422 /* display infos on fpgaimage */
423 index = 15;
424 for (i=0; i<4; i++) {
425 len = dst[index];
426 printf("FPGA: %s\n", &(dst[index+1]));
427 index += len+3;
428 }
429 putc ('\n');
430 /* delayed reboot */
431 for (i=20; i>0; i--) {
432 printf("Rebooting in %2d seconds \r",i);
433 for (index=0;index<1000;index++)
434 udelay(1000);
435 }
436 putc ('\n');
437 do_reset(NULL, 0, 0, NULL);
438 }
439
440 puts("FPGA: ");
441
442 /* display infos on fpgaimage */
443 index = 15;
444 for (i=0; i<4; i++) {
445 len = dst[index];
446 printf("%s ", &(dst[index+1]));
447 index += len+3;
448 }
449 putc ('\n');
450
451 free(dst);
452
453 /*
454 * Reset FPGA via FPGA_INIT pin
455 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100456 /* setup FPGA_INIT as output */
457 out_be32((void *)GPIO0_TCR,
458 in_be32((void *)GPIO0_TCR) | FPGA_INIT);
459 out_be32((void *)GPIO0_OR,
460 in_be32((void *)GPIO0_OR) & ~FPGA_INIT); /* reset low */
stroese1f54ce62004-12-16 18:23:14 +0000461 udelay(1000); /* wait 1ms */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100462 out_be32((void *)GPIO0_OR,
463 in_be32((void *)GPIO0_OR) | FPGA_INIT); /* reset high */
stroese1f54ce62004-12-16 18:23:14 +0000464 udelay(1000); /* wait 1ms */
465
466 /*
467 * Write Board revision into FPGA
468 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100469 out_be16(FPGA_CTRL, in_be16(FPGA_CTRL) | (gd->board_type & 0x0003));
stroese1f54ce62004-12-16 18:23:14 +0000470
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200471 /*
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200472 * Setup and enable EEPROM write protection
473 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100474 out_be32((void *)GPIO0_OR,
475 in_be32((void *)GPIO0_OR) | CONFIG_SYS_EEPROM_WP);
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200476
stroese1f54ce62004-12-16 18:23:14 +0000477 /*
stroese1f54ce62004-12-16 18:23:14 +0000478 * Reset touch-screen controller
479 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100480 out_be32((void *)GPIO0_OR,
481 in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_TOUCH_RST);
stroese1f54ce62004-12-16 18:23:14 +0000482 udelay(1000);
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100483 out_be32((void *)GPIO0_OR,
484 in_be32((void *)GPIO0_OR) | CONFIG_SYS_TOUCH_RST);
stroese1f54ce62004-12-16 18:23:14 +0000485
wdenkefe2a4d2004-12-16 21:44:03 +0000486 /*
487 * Enable power on PS/2 interface (with reset)
488 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100489 out_be16(FPGA_CTRL, in_be16(FPGA_CTRL) & ~FPGA_CTRL_PS2_PWR);
wdenkefe2a4d2004-12-16 21:44:03 +0000490 for (i=0;i<500;i++)
491 udelay(1000);
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100492 out_be16(FPGA_CTRL, in_be16(FPGA_CTRL) | FPGA_CTRL_PS2_PWR);
stroese1f54ce62004-12-16 18:23:14 +0000493
494 /*
495 * Get contrast value from environment variable
496 */
497 str = getenv("contrast0");
498 if (str) {
499 contrast0 = simple_strtol(str, NULL, 16);
500 if (contrast0 > 255) {
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100501 printf("ERROR: contrast0 value too high (0x%lx)!\n",
502 contrast0);
Stefan Roese48a05a52006-02-07 16:51:04 +0100503 contrast0 = 0xffffffff;
stroese1f54ce62004-12-16 18:23:14 +0000504 }
505 }
506
507 /*
508 * Init lcd interface and display logo
509 */
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200510
stroese1f54ce62004-12-16 18:23:14 +0000511 str = getenv("bd_type");
512 if (strcmp(str, "ppc230") == 0) {
513 /*
514 * Switch backlight on
515 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100516 out_be16(FPGA_CTRL,
517 in_be16(FPGA_CTRL) | FPGA_CTRL_VGA0_BL);
518 out_be16(FPGA_BL, 0x0000);
stroese1f54ce62004-12-16 18:23:14 +0000519
520 lcd_setup(1, 0);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200521 lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG, (uchar *)CONFIG_SYS_LCD_BIG_MEM,
stroese1f54ce62004-12-16 18:23:14 +0000522 regs_13806_1024_768_8bpp,
523 sizeof(regs_13806_1024_768_8bpp)/sizeof(regs_13806_1024_768_8bpp[0]),
524 logo_bmp_1024, sizeof(logo_bmp_1024));
525 } else if (strcmp(str, "ppc220") == 0) {
526 /*
527 * Switch backlight on
528 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100529 out_be16(FPGA_CTRL,
530 in_be16(FPGA_CTRL) & ~FPGA_CTRL_VGA0_BL);
531 out_be16(FPGA_BL, 0x0000);
stroese1f54ce62004-12-16 18:23:14 +0000532
533 lcd_setup(1, 0);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200534 lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG, (uchar *)CONFIG_SYS_LCD_BIG_MEM,
stroese1f54ce62004-12-16 18:23:14 +0000535 regs_13806_640_480_16bpp,
536 sizeof(regs_13806_640_480_16bpp)/sizeof(regs_13806_640_480_16bpp[0]),
537 logo_bmp_640, sizeof(logo_bmp_640));
538 } else if (strcmp(str, "ppc215") == 0) {
539 /*
540 * Set default display contrast voltage
541 */
542 if (contrast0 == 0xffffffff) {
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100543 out_be16(FPGA_CTR, 0x0082);
stroese1f54ce62004-12-16 18:23:14 +0000544 } else {
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100545 out_be16(FPGA_CTR, contrast0);
stroese1f54ce62004-12-16 18:23:14 +0000546 }
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100547 out_be16(FPGA_BL, 0xffff);
stroese1f54ce62004-12-16 18:23:14 +0000548 /*
549 * Switch backlight on
550 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100551 out_be16(FPGA_CTRL,
552 in_be16(FPGA_CTRL) |
553 FPGA_CTRL_VGA0_BL |
554 FPGA_CTRL_VGA0_BL_MODE);
stroese1f54ce62004-12-16 18:23:14 +0000555 /*
556 * Set lcd clock (small epson)
557 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100558 out_be16(FPGA_CTRL, in_be16(FPGA_CTRL) | LCD_CLK_06250);
stroese1f54ce62004-12-16 18:23:14 +0000559 udelay(100); /* wait for 100 us */
560
561 lcd_setup(0, 1);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200562 lcd_init((uchar *)CONFIG_SYS_LCD_SMALL_REG, (uchar *)CONFIG_SYS_LCD_SMALL_MEM,
stroese1f54ce62004-12-16 18:23:14 +0000563 regs_13705_320_240_8bpp,
564 sizeof(regs_13705_320_240_8bpp)/sizeof(regs_13705_320_240_8bpp[0]),
565 logo_bmp_320_8bpp, sizeof(logo_bmp_320_8bpp));
566 } else if (strcmp(str, "ppc210") == 0) {
567 /*
568 * Set default display contrast voltage
569 */
570 if (contrast0 == 0xffffffff) {
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100571 out_be16(FPGA_CTR, 0x0060);
stroese1f54ce62004-12-16 18:23:14 +0000572 } else {
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100573 out_be16(FPGA_CTR, contrast0);
stroese1f54ce62004-12-16 18:23:14 +0000574 }
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100575 out_be16(FPGA_BL, 0xffff);
stroese1f54ce62004-12-16 18:23:14 +0000576 /*
577 * Switch backlight on
578 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100579 out_be16(FPGA_CTRL,
580 in_be16(FPGA_CTRL) |
581 FPGA_CTRL_VGA0_BL |
582 FPGA_CTRL_VGA0_BL_MODE);
stroese1f54ce62004-12-16 18:23:14 +0000583 /*
Stefan Roese48a05a52006-02-07 16:51:04 +0100584 * Set lcd clock (small epson), enable 1-wire interface
stroese1f54ce62004-12-16 18:23:14 +0000585 */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100586 out_be16(FPGA_CTRL,
587 in_be16(FPGA_CTRL) |
588 LCD_CLK_08330 |
589 FPGA_CTRL_OW_ENABLE);
stroese1f54ce62004-12-16 18:23:14 +0000590
591 lcd_setup(0, 1);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200592 lcd_init((uchar *)CONFIG_SYS_LCD_SMALL_REG, (uchar *)CONFIG_SYS_LCD_SMALL_MEM,
stroese1f54ce62004-12-16 18:23:14 +0000593 regs_13704_320_240_4bpp,
594 sizeof(regs_13704_320_240_4bpp)/sizeof(regs_13704_320_240_4bpp[0]),
595 logo_bmp_320, sizeof(logo_bmp_320));
Stefan Roese2c7b2ab2005-09-30 16:41:12 +0200596#ifdef CONFIG_VIDEO_SM501
stroese1f54ce62004-12-16 18:23:14 +0000597 } else {
Stefan Roese2c7b2ab2005-09-30 16:41:12 +0200598 pci_dev_t devbusfn;
599
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200600 /*
601 * Is SM501 connected (ppc221/ppc231)?
602 */
603 devbusfn = pci_find_device(PCI_VENDOR_SM, PCI_DEVICE_SM501, 0);
604 if (devbusfn != -1) {
605 puts("VGA: SM501 with 8 MB ");
606 if (strcmp(str, "ppc221") == 0) {
607 printf("(800*600, %dbpp)\n", BPP);
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100608 out_be16(FPGA_BL, 0x002d); /* max. allowed brightness */
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200609 } else if (strcmp(str, "ppc231") == 0) {
610 printf("(1024*768, %dbpp)\n", BPP);
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100611 out_be16(FPGA_BL, 0x0000);
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200612 } else {
613 printf("Unsupported bd_type defined (%s) -> No display configured!\n", str);
614 return 0;
615 }
616 } else {
617 printf("Unsupported bd_type defined (%s) -> No display configured!\n", str);
618 return 0;
619 }
Stefan Roese2c7b2ab2005-09-30 16:41:12 +0200620#endif /* CONFIG_VIDEO_SM501 */
stroese1f54ce62004-12-16 18:23:14 +0000621 }
622
Stefan Roese48a05a52006-02-07 16:51:04 +0100623 cf_enable();
624
stroese1f54ce62004-12-16 18:23:14 +0000625 return (0);
626}
627
628
629/*
630 * Check Board Identity:
631 */
632
633int checkboard (void)
634{
Stefan Roese18c5e642006-01-18 20:06:44 +0100635 char str[64];
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200636 int i = getenv_f("serial#", str, sizeof(str));
stroese1f54ce62004-12-16 18:23:14 +0000637
638 puts ("Board: ");
639
640 if (i == -1) {
641 puts ("### No HW ID - assuming HH405");
642 } else {
643 puts(str);
644 }
645
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200646 if (getenv_f("bd_type", str, sizeof(str)) != -1) {
stroese1f54ce62004-12-16 18:23:14 +0000647 printf(" (%s", str);
648 } else {
649 puts(" (Missing bd_type!");
650 }
651
652 gd->board_type = board_revision();
Stefan Roese48a05a52006-02-07 16:51:04 +0100653 printf(", Rev %ld.x)\n", gd->board_type);
stroese1f54ce62004-12-16 18:23:14 +0000654
655 return 0;
656}
657
stroese1f54ce62004-12-16 18:23:14 +0000658#ifdef CONFIG_IDE_RESET
659void ide_set_reset(int on)
660{
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100661 if (((gd->board_type >= 2) &&
662 (in_be16(FPGA_STATUS) & FPGA_STATUS_CF_DETECT)) ||
Stefan Roese48a05a52006-02-07 16:51:04 +0100663 (gd->board_type < 2)) {
664 /*
665 * Assert or deassert CompactFlash Reset Pin
666 */
667 if (on) { /* assert RESET */
668 cf_enable();
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100669 out_be16(FPGA_CTRL,
670 in_be16(FPGA_CTRL) &
671 ~FPGA_CTRL_CF_RESET);
Stefan Roese48a05a52006-02-07 16:51:04 +0100672 } else { /* release RESET */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100673 out_be16(FPGA_CTRL,
674 in_be16(FPGA_CTRL) |
675 FPGA_CTRL_CF_RESET);
Stefan Roese48a05a52006-02-07 16:51:04 +0100676 }
stroese1f54ce62004-12-16 18:23:14 +0000677 }
678}
679#endif /* CONFIG_IDE_RESET */
680
681
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200682#if defined(CONFIG_SYS_EEPROM_WREN)
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200683/* Input: <dev_addr> I2C address of EEPROM device to enable.
684 * <state> -1: deliver current state
685 * 0: disable write
686 * 1: enable write
687 * Returns: -1: wrong device address
688 * 0: dis-/en- able done
689 * 0/1: current state if <state> was -1.
690 */
691int eeprom_write_enable (unsigned dev_addr, int state)
692{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200693 if (CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200694 return -1;
695 } else {
696 switch (state) {
697 case 1:
698 /* Enable write access, clear bit GPIO_SINT2. */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100699 out_be32((void *)GPIO0_OR,
700 in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_EEPROM_WP);
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200701 state = 0;
702 break;
703 case 0:
704 /* Disable write access, set bit GPIO_SINT2. */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100705 out_be32((void *)GPIO0_OR,
706 in_be32((void *)GPIO0_OR) | CONFIG_SYS_EEPROM_WP);
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200707 state = 0;
708 break;
709 default:
710 /* Read current status back. */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100711 state = (0 == (in_be32((void *)GPIO0_OR) &
712 CONFIG_SYS_EEPROM_WP));
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200713 break;
714 }
715 }
716 return state;
717}
718
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200719int do_eep_wren (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200720{
721 int query = argc == 1;
722 int state = 0;
723
724 if (query) {
725 /* Query write access state. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200726 state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, -1);
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200727 if (state < 0) {
728 puts ("Query of write access state failed.\n");
729 } else {
730 printf ("Write access for device 0x%0x is %sabled.\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200731 CONFIG_SYS_I2C_EEPROM_ADDR, state ? "en" : "dis");
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200732 state = 0;
733 }
734 } else {
735 if ('0' == argv[1][0]) {
736 /* Disable write access. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200737 state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, 0);
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200738 } else {
739 /* Enable write access. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200740 state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, 1);
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200741 }
742 if (state < 0) {
743 puts ("Setup of write access state failed.\n");
744 }
745 }
746
747 return state;
748}
749
750U_BOOT_CMD(eepwren, 2, 0, do_eep_wren,
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200751 "Enable / disable / query EEPROM write access",
752 ""
753);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200754#endif /* #if defined(CONFIG_SYS_EEPROM_WREN) */
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200755
756
757#ifdef CONFIG_VIDEO_SM501
758#ifdef CONFIG_CONSOLE_EXTRA_INFO
759/*
760 * Return text to be printed besides the logo.
761 */
762void video_get_info_str (int line_number, char *info)
763{
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200764 char str[64];
765 char str2[64];
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200766 int i = getenv_f("serial#", str2, sizeof(str));
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200767
768 if (line_number == 1) {
769 sprintf(str, " Board: ");
770
771 if (i == -1) {
772 strcat(str, "### No HW ID - assuming HH405");
773 } else {
774 strcat(str, str2);
775 }
776
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200777 if (getenv_f("bd_type", str2, sizeof(str2)) != -1) {
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200778 strcat(str, " (");
779 strcat(str, str2);
780 } else {
781 strcat(str, " (Missing bd_type!");
782 }
783
Stefan Roese48a05a52006-02-07 16:51:04 +0100784 sprintf(str2, ", Rev %ld.x)", gd->board_type);
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200785 strcat(str, str2);
786 strcpy(info, str);
787 } else {
788 info [0] = '\0';
789 }
790}
791#endif /* CONFIG_CONSOLE_EXTRA_INFO */
792
793/*
794 * Returns SM501 register base address. First thing called in the driver.
795 */
796unsigned int board_video_init (void)
797{
798 pci_dev_t devbusfn;
799 u32 addr;
800
801 /*
802 * Is SM501 connected (ppc221/ppc231)?
803 */
804 devbusfn = pci_find_device(PCI_VENDOR_SM, PCI_DEVICE_SM501, 0);
805 if (devbusfn != -1) {
806 pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_1, (u32 *)&addr);
807 return (addr & 0xfffffffe);
808 }
809
810 return 0;
811}
812
813/*
814 * Returns SM501 framebuffer address
815 */
816unsigned int board_video_get_fb (void)
817{
818 pci_dev_t devbusfn;
819 u32 addr;
820
821 /*
822 * Is SM501 connected (ppc221/ppc231)?
823 */
824 devbusfn = pci_find_device(PCI_VENDOR_SM, PCI_DEVICE_SM501, 0);
825 if (devbusfn != -1) {
826 pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_0, (u32 *)&addr);
Stefan Roese48a05a52006-02-07 16:51:04 +0100827 addr &= 0xfffffffe;
828#ifdef CONFIG_VIDEO_SM501_FBMEM_OFFSET
829 addr += CONFIG_VIDEO_SM501_FBMEM_OFFSET;
830#endif
831 return addr;
Stefan Roese98f4a3d2005-09-22 09:04:17 +0200832 }
833
834 return 0;
835}
836
837/*
838 * Called after initializing the SM501 and before clearing the screen.
839 */
840void board_validate_screen (unsigned int base)
841{
842}
843
844/*
845 * Return a pointer to the initialization sequence.
846 */
847const SMI_REGS *board_get_regs (void)
848{
849 char *str;
850
851 str = getenv("bd_type");
852 if (strcmp(str, "ppc221") == 0) {
853 return init_regs_800x600;
854 } else {
855 return init_regs_1024x768;
856 }
857}
858
859int board_get_width (void)
860{
861 char *str;
862
863 str = getenv("bd_type");
864 if (strcmp(str, "ppc221") == 0) {
865 return 800;
866 } else {
867 return 1024;
868 }
869}
870
871int board_get_height (void)
872{
873 char *str;
874
875 str = getenv("bd_type");
876 if (strcmp(str, "ppc221") == 0) {
877 return 600;
878 } else {
879 return 768;
880 }
881}
882
883#endif /* CONFIG_VIDEO_SM501 */
Stefan Roese48a05a52006-02-07 16:51:04 +0100884
885
886void reset_phy(void)
887{
888#ifdef CONFIG_LXT971_NO_SLEEP
889
890 /*
891 * Disable sleep mode in LXT971
892 */
893 lxt971_no_sleep();
894#endif
895}