blob: dc35be4e2e37b34a15bbae7aaee01dabb5a7ac44 [file] [log] [blame]
Matthias Fuchs15a08bc2008-01-17 10:52:30 +01001/*
2 * (C) Copyright 2008
3 * Matthias Fuchs, esd gmbh, matthias.fuchs@esd-electronics.com
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Matthias Fuchs15a08bc2008-01-17 10:52:30 +01006 */
7
8#include <common.h>
9#include <asm/processor.h>
10#include <asm/io.h>
11#include <asm/bitops.h>
12#include <command.h>
13#include <i2c.h>
Stefan Roeseb36df562010-09-09 19:18:00 +020014#include <asm/ppc440.h>
Matthias Fuchs15a08bc2008-01-17 10:52:30 +010015#include "du440.h"
16
17DECLARE_GLOBAL_DATA_PTR;
18
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020019extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
Matthias Fuchs15a08bc2008-01-17 10:52:30 +010020extern ulong flash_get_size (ulong base, int banknum);
21
22int usbhub_init(void);
23int dvi_init(void);
24int eeprom_write_enable (unsigned dev_addr, int state);
25int board_revision(void);
26
27static int du440_post_errors;
28
29int board_early_init_f(void)
30{
31 u32 sdr0_cust0;
32 u32 sdr0_pfc1, sdr0_pfc2;
33 u32 reg;
34
Stefan Roesed1c3b272009-09-09 16:25:29 +020035 mtdcr(EBC0_CFGADDR, EBC0_CFG);
36 mtdcr(EBC0_CFGDATA, 0xb8400000);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +010037
38 /*
39 * Setup the GPIO pins
40 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020041 out_be32((void*)GPIO0_OR, 0x00000000 | CONFIG_SYS_GPIO0_EP_EEP);
42 out_be32((void*)GPIO0_TCR, 0x0000001f | CONFIG_SYS_GPIO0_EP_EEP);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +010043 out_be32((void*)GPIO0_OSRL, 0x50055400);
Matthias Fuchs6a133d62008-10-07 13:13:08 +020044 out_be32((void*)GPIO0_OSRH, 0x55005000);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +010045 out_be32((void*)GPIO0_TSRL, 0x50055400);
46 out_be32((void*)GPIO0_TSRH, 0x55005000);
47 out_be32((void*)GPIO0_ISR1L, 0x50000000);
48 out_be32((void*)GPIO0_ISR1H, 0x00000000);
49 out_be32((void*)GPIO0_ISR2L, 0x00000000);
Matthias Fuchs6a133d62008-10-07 13:13:08 +020050 out_be32((void*)GPIO0_ISR2H, 0x00000000);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +010051 out_be32((void*)GPIO0_ISR3L, 0x00000000);
52 out_be32((void*)GPIO0_ISR3H, 0x00000000);
53
54 out_be32((void*)GPIO1_OR, 0x00000000);
55 out_be32((void*)GPIO1_TCR, 0xc2000000 |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020056 CONFIG_SYS_GPIO1_IORSTN |
57 CONFIG_SYS_GPIO1_IORST2N |
58 CONFIG_SYS_GPIO1_LEDUSR1 |
59 CONFIG_SYS_GPIO1_LEDUSR2 |
60 CONFIG_SYS_GPIO1_LEDPOST |
61 CONFIG_SYS_GPIO1_LEDDU);
62 out_be32((void*)GPIO1_ODR, CONFIG_SYS_GPIO1_LEDDU);
Matthias Fuchs6a133d62008-10-07 13:13:08 +020063 out_be32((void*)GPIO1_OSRL, 0x0c280000);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +010064 out_be32((void*)GPIO1_OSRH, 0x00000000);
Matthias Fuchs6a133d62008-10-07 13:13:08 +020065 out_be32((void*)GPIO1_TSRL, 0xcc000000);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +010066 out_be32((void*)GPIO1_TSRH, 0x00000000);
67 out_be32((void*)GPIO1_ISR1L, 0x00005550);
68 out_be32((void*)GPIO1_ISR1H, 0x00000000);
69 out_be32((void*)GPIO1_ISR2L, 0x00050000);
70 out_be32((void*)GPIO1_ISR2H, 0x00000000);
71 out_be32((void*)GPIO1_ISR3L, 0x01400000);
72 out_be32((void*)GPIO1_ISR3H, 0x00000000);
73
74 /*
75 * Setup the interrupt controller polarities, triggers, etc.
76 */
Stefan Roese952e7762009-09-24 09:55:50 +020077 mtdcr(UIC0SR, 0xffffffff); /* clear all */
78 mtdcr(UIC0ER, 0x00000000); /* disable all */
79 mtdcr(UIC0CR, 0x00000005); /* ATI & UIC1 crit are critical */
80 mtdcr(UIC0PR, 0xfffff7ff); /* per ref-board manual */
81 mtdcr(UIC0TR, 0x00000000); /* per ref-board manual */
82 mtdcr(UIC0VR, 0x00000000); /* int31 highest, base=0x000 */
83 mtdcr(UIC0SR, 0xffffffff); /* clear all */
Matthias Fuchs15a08bc2008-01-17 10:52:30 +010084
85 /*
86 * UIC1:
87 * bit30: ext. Irq 1: PLD : int 32+30
88 */
Stefan Roese952e7762009-09-24 09:55:50 +020089 mtdcr(UIC1SR, 0xffffffff); /* clear all */
90 mtdcr(UIC1ER, 0x00000000); /* disable all */
91 mtdcr(UIC1CR, 0x00000000); /* all non-critical */
92 mtdcr(UIC1PR, 0xfffffffd);
93 mtdcr(UIC1TR, 0x00000000);
94 mtdcr(UIC1VR, 0x00000000); /* int31 highest, base=0x000 */
95 mtdcr(UIC1SR, 0xffffffff); /* clear all */
Matthias Fuchs15a08bc2008-01-17 10:52:30 +010096
97 /*
98 * UIC2
99 * bit3: ext. Irq 2: DCF77 : int 64+3
100 */
Stefan Roese952e7762009-09-24 09:55:50 +0200101 mtdcr(UIC2SR, 0xffffffff); /* clear all */
102 mtdcr(UIC2ER, 0x00000000); /* disable all */
103 mtdcr(UIC2CR, 0x00000000); /* all non-critical */
104 mtdcr(UIC2PR, 0xffffffff); /* per ref-board manual */
105 mtdcr(UIC2TR, 0x00000000); /* per ref-board manual */
106 mtdcr(UIC2VR, 0x00000000); /* int31 highest, base=0x000 */
107 mtdcr(UIC2SR, 0xffffffff); /* clear all */
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100108
109 /* select Ethernet pins */
110 mfsdr(SDR0_PFC1, sdr0_pfc1);
111 mfsdr(SDR0_PFC2, sdr0_pfc2);
112
113 /* setup EMAC bridge interface */
114 if (board_revision() == 0) {
115 /* 1 x MII */
116 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
117 SDR0_PFC1_SELECT_CONFIG_1_2;
118 sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
119 SDR0_PFC2_SELECT_CONFIG_1_2;
120 } else {
121 /* 2 x SMII */
122 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
123 SDR0_PFC1_SELECT_CONFIG_6;
124 sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
125 SDR0_PFC2_SELECT_CONFIG_6;
126 }
127
128 /* enable 2nd IIC */
129 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL;
130
131 mtsdr(SDR0_PFC2, sdr0_pfc2);
132 mtsdr(SDR0_PFC1, sdr0_pfc1);
133
134 /* PCI arbiter enabled */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200135 mfsdr(SDR0_PCI0, reg);
136 mtsdr(SDR0_PCI0, 0x80000000 | reg);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100137
138 /* setup NAND FLASH */
139 mfsdr(SDR0_CUST0, sdr0_cust0);
140 sdr0_cust0 = SDR0_CUST0_MUX_NDFC_SEL |
141 SDR0_CUST0_NDFC_ENABLE |
142 SDR0_CUST0_NDFC_BW_8_BIT |
143 SDR0_CUST0_NDFC_ARE_MASK |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200144 (0x80000000 >> (28 + CONFIG_SYS_NAND0_CS)) |
145 (0x80000000 >> (28 + CONFIG_SYS_NAND1_CS));
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100146 mtsdr(SDR0_CUST0, sdr0_cust0);
147
148 return 0;
149}
150
151int misc_init_r(void)
152{
153 uint pbcr;
154 int size_val = 0;
155 u32 reg;
156 unsigned long usb2d0cr = 0;
157 unsigned long usb2phy0cr, usb2h0cr = 0;
158 unsigned long sdr0_pfc1;
Matthias Fuchs542b3852008-10-07 13:13:10 +0200159 unsigned long sdr0_srst0, sdr0_srst1;
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100160 int i, j;
161
162 /* adjust flash start and offset */
163 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
164 gd->bd->bi_flashoffset = 0;
165
Stefan Roesed1c3b272009-09-09 16:25:29 +0200166 mtdcr(EBC0_CFGADDR, PB0CR);
167 pbcr = mfdcr(EBC0_CFGDATA);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100168 size_val = ffs(gd->bd->bi_flashsize) - 21;
169 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
Stefan Roesed1c3b272009-09-09 16:25:29 +0200170 mtdcr(EBC0_CFGADDR, PB0CR);
171 mtdcr(EBC0_CFGDATA, pbcr);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100172
173 /*
174 * Re-check to get correct base address
175 */
176 flash_get_size(gd->bd->bi_flashstart, 0);
177
178 /*
179 * USB suff...
180 */
181 /* SDR Setting */
182 mfsdr(SDR0_PFC1, sdr0_pfc1);
183 mfsdr(SDR0_USB0, usb2d0cr);
184 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
185 mfsdr(SDR0_USB2H0CR, usb2h0cr);
186
187 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
188 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
189 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
190 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
191 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
192 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
193 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
194 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
195 usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
196 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
197
198 /* An 8-bit/60MHz interface is the only possible alternative
199 when connecting the Device to the PHY */
200 usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
201 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
202
203 /* To enable the USB 2.0 Device function through the UTMI interface */
204 usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
205
206 sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
207 sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
208
209 mtsdr(SDR0_PFC1, sdr0_pfc1);
210 mtsdr(SDR0_USB0, usb2d0cr);
211 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
212 mtsdr(SDR0_USB2H0CR, usb2h0cr);
213
Matthias Fuchs542b3852008-10-07 13:13:10 +0200214 /*
215 * Take USB out of reset:
216 * -Initial status = all cores are in reset
217 * -deassert reset to OPB1, P4OPB0, OPB2, PLB42OPB1 OPB2PLB40 cores
218 * -wait 1 ms
219 * -deassert reset to PHY
220 * -wait 1 ms
221 * -deassert reset to HOST
222 * -wait 4 ms
223 * -deassert all other resets
224 */
225 mfsdr(SDR0_SRST1, sdr0_srst1);
226 sdr0_srst1 &= ~(SDR0_SRST1_OPBA1 | \
227 SDR0_SRST1_P4OPB0 | \
228 SDR0_SRST1_OPBA2 | \
229 SDR0_SRST1_PLB42OPB1 | \
230 SDR0_SRST1_OPB2PLB40);
231 mtsdr(SDR0_SRST1, sdr0_srst1);
232 udelay(1000);
233
234 mfsdr(SDR0_SRST1, sdr0_srst1);
235 sdr0_srst1 &= ~SDR0_SRST1_USB20PHY;
236 mtsdr(SDR0_SRST1, sdr0_srst1);
237 udelay(1000);
238
239 mfsdr(SDR0_SRST0, sdr0_srst0);
240 sdr0_srst0 &= ~SDR0_SRST0_USB2H;
241 mtsdr(SDR0_SRST0, sdr0_srst0);
242 udelay(4000);
243
244 /* finally all the other resets */
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100245 mtsdr(SDR0_SRST1, 0x00000000);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100246 mtsdr(SDR0_SRST0, 0x00000000);
247
248 printf("USB: Host(int phy)\n");
249
250 /*
251 * Clear PLB4A0_ACR[WRP]
252 * This fix will make the MAL burst disabling patch for the Linux
253 * EMAC driver obsolete.
254 */
Stefan Roese5e7abce2010-09-11 09:31:43 +0200255 reg = mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_WRP_MASK;
256 mtdcr(PLB4A0_ACR, reg);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100257
258 /*
259 * release IO-RST#
260 * We have to wait at least 560ms until we may call usbhub_init
261 */
Matthias Fuchs7c91f512008-03-30 18:01:15 +0200262 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200263 CONFIG_SYS_GPIO1_IORSTN | CONFIG_SYS_GPIO1_IORST2N);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100264
265 /*
266 * flash USR1/2 LEDs (600ms)
267 * This results in the necessary delay from IORST# until
268 * calling usbhub_init will succeed
269 */
270 for (j = 0; j < 3; j++) {
271 out_be32((void*)GPIO1_OR,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200272 (in_be32((void*)GPIO1_OR) & ~CONFIG_SYS_GPIO1_LEDUSR2) |
273 CONFIG_SYS_GPIO1_LEDUSR1);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100274
275 for (i = 0; i < 100; i++)
276 udelay(1000);
277
278 out_be32((void*)GPIO1_OR,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200279 (in_be32((void*)GPIO1_OR) & ~CONFIG_SYS_GPIO1_LEDUSR1) |
280 CONFIG_SYS_GPIO1_LEDUSR2);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100281
282 for (i = 0; i < 100; i++)
283 udelay(1000);
284 }
285
286 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) &
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200287 ~(CONFIG_SYS_GPIO1_LEDUSR1 | CONFIG_SYS_GPIO1_LEDUSR2));
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100288
289 if (usbhub_init())
290 du440_post_errors++;
291
292 if (dvi_init())
293 du440_post_errors++;
294
295 return 0;
296}
297
298int pld_revision(void)
299{
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100300 out_8((void *)CONFIG_SYS_CPLD_BASE, 0x00);
301 return (int)(in_8((void *)CONFIG_SYS_CPLD_BASE) & CPLD_VERSION_MASK);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100302}
303
304int board_revision(void)
305{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200306 int rpins = (int)((in_be32((void*)GPIO1_IR) & CONFIG_SYS_GPIO1_HWVER_MASK)
307 >> CONFIG_SYS_GPIO1_HWVER_SHIFT);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100308
309 return ((rpins & 1) << 3) | ((rpins & 2) << 1) |
310 ((rpins & 4) >> 1) | ((rpins & 8) >> 3);
311}
312
313#if defined(CONFIG_SHOW_ACTIVITY)
314void board_show_activity (ulong timestamp)
315{
316 if ((timestamp % 100) == 0)
317 out_be32((void*)GPIO1_OR,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200318 in_be32((void*)GPIO1_OR) ^ CONFIG_SYS_GPIO1_LEDUSR1);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100319}
320
321void show_activity(int arg)
322{
323}
324#endif /* CONFIG_SHOW_ACTIVITY */
325
326int du440_phy_addr(int devnum)
327{
328 if (board_revision() == 0)
329 return devnum;
330
331 return devnum + 1;
332}
333
334int checkboard(void)
335{
336 char serno[32];
337
338 puts("Board: DU440");
339
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200340 if (getenv_f("serial#", serno, sizeof(serno)) > 0) {
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100341 puts(", serial# ");
342 puts(serno);
343 }
344
345 printf(", HW-Rev. 1.%d, CPLD-Rev. 1.%d\n",
346 board_revision(), pld_revision());
347 return (0);
348}
349
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100350int last_stage_init(void)
351{
352 int e, i;
353
354 /* everyting is ok: turn on POST-LED */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200355 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) | CONFIG_SYS_GPIO1_LEDPOST);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100356
357 /* slowly blink on errors and finally keep LED off */
358 for (e = 0; e < du440_post_errors; e++) {
359 out_be32((void*)GPIO1_OR,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200360 in_be32((void*)GPIO1_OR) | CONFIG_SYS_GPIO1_LEDPOST);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100361
362 for (i = 0; i < 500; i++)
363 udelay(1000);
364
365 out_be32((void*)GPIO1_OR,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200366 in_be32((void*)GPIO1_OR) & ~CONFIG_SYS_GPIO1_LEDPOST);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100367
368 for (i = 0; i < 500; i++)
369 udelay(1000);
370 }
371
372 return 0;
373}
374
375#if defined(CONFIG_I2C_MULTI_BUS)
376/*
377 * read field strength from I2C ADC
378 */
379int dcf77_status(void)
380{
381 unsigned int oldbus;
382 uchar u[2];
383 int mv;
384
385 oldbus = I2C_GET_BUS();
386 I2C_SET_BUS(1);
387
388 if (i2c_read (IIC1_MCP3021_ADDR, 0, 0, u, 2)) {
389 I2C_SET_BUS(oldbus);
390 return -1;
391 }
392
393 mv = (int)(((u[0] << 8) | u[1]) >> 2) * 3300 / 1024;
394
395 I2C_SET_BUS(oldbus);
396 return mv;
397}
398
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200399int do_dcf77(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100400{
401 int mv;
402 u32 pin, pinold;
403 unsigned long long t1, t2;
404 bd_t *bd = gd->bd;
405
406 printf("DCF77: ");
407 mv = dcf77_status();
408 if (mv > 0)
409 printf("signal=%d mV\n", mv);
410 else
411 printf("ERROR - no signal\n");
412
413 t1 = t2 = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200414 pinold = in_be32((void*)GPIO1_IR) & CONFIG_SYS_GPIO1_DCF77;
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100415 while (!ctrlc()) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200416 pin = in_be32((void*)GPIO1_IR) & CONFIG_SYS_GPIO1_DCF77;
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100417 if (pin && !pinold) { /* bit start */
418 t1 = get_ticks();
419 if (t2 && ((unsigned int)(t1 - t2) /
420 (bd->bi_procfreq / 1000) >= 1800))
421 printf("Start of minute\n");
422
423 t2 = t1;
424 }
425 if (t1 && !pin && pinold) { /* bit end */
426 printf("%5d\n", (unsigned int)(get_ticks() - t1) /
427 (bd->bi_procfreq / 1000));
428 }
429 pinold = pin;
430 }
431
432 printf("Abort\n");
433 return 0;
434}
435U_BOOT_CMD(
436 dcf77, 1, 1, do_dcf77,
Peter Tyser2fb26042009-01-27 18:03:12 -0600437 "Check DCF77 receiver",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200438 ""
439);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100440
441/*
442 * initialize USB hub via I2C1
443 */
444int usbhub_init(void)
445{
446 int reg;
447 int ret = 0;
448 unsigned int oldbus;
449 uchar u[] = {0x04, 0x24, 0x04, 0x07, 0x25, 0x00, 0x00, 0xd3,
450 0x18, 0xe0, 0x00, 0x00, 0x01, 0x64, 0x01, 0x64,
451 0x32};
452 uchar stcd;
453
454 printf("Hub: ");
455
456 oldbus = I2C_GET_BUS();
457 I2C_SET_BUS(1);
458
459 for (reg = 0; reg < sizeof(u); reg++)
460 if (i2c_write (IIC1_USB2507_ADDR, reg, 1, &u[reg], 1)) {
461 ret = -1;
462 break;
463 }
464
465 if (ret == 0) {
466 stcd = 0x03;
467 if (i2c_write (IIC1_USB2507_ADDR, 0, 1, &stcd, 1))
468 ret = -1;
469 }
470
471 if (ret == 0)
472 printf("initialized\n");
473 else
474 printf("failed - cannot initialize USB hub\n");
475
476 I2C_SET_BUS(oldbus);
477 return ret;
478}
479
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200480int do_hubinit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100481{
482 usbhub_init();
483 return 0;
484}
485U_BOOT_CMD(
486 hubinit, 1, 1, do_hubinit,
Peter Tyser2fb26042009-01-27 18:03:12 -0600487 "Initialize USB hub",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200488 ""
489);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100490#endif /* CONFIG_I2C_MULTI_BUS */
491
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200492#define CONFIG_SYS_BOOT_EEPROM_PAGE_WRITE_BITS 3
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100493int boot_eeprom_write (unsigned dev_addr,
494 unsigned offset,
495 uchar *buffer,
496 unsigned cnt)
497{
498 unsigned end = offset + cnt;
499 unsigned blk_off;
500 int rcode = 0;
501
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200502#if defined(CONFIG_SYS_EEPROM_WREN)
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100503 eeprom_write_enable(dev_addr, 1);
504#endif
505 /*
506 * Write data until done or would cross a write page boundary.
507 * We must write the address again when changing pages
508 * because the address counter only increments within a page.
509 */
510
511 while (offset < end) {
512 unsigned alen, len;
513 unsigned maxlen;
514
515 uchar addr[2];
516
517 blk_off = offset & 0xFF; /* block offset */
518
519 addr[0] = offset >> 8; /* block number */
520 addr[1] = blk_off; /* block offset */
521 alen = 2;
522 addr[0] |= dev_addr; /* insert device address */
523
524 len = end - offset;
525
526 /*
527 * For a FRAM device there is no limit on the number of the
528 * bytes that can be ccessed with the single read or write
529 * operation.
530 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200531#if defined(CONFIG_SYS_BOOT_EEPROM_PAGE_WRITE_BITS)
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100532
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200533#define BOOT_EEPROM_PAGE_SIZE (1 << CONFIG_SYS_BOOT_EEPROM_PAGE_WRITE_BITS)
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100534#define BOOT_EEPROM_PAGE_OFFSET(x) ((x) & (BOOT_EEPROM_PAGE_SIZE - 1))
535
536 maxlen = BOOT_EEPROM_PAGE_SIZE -
537 BOOT_EEPROM_PAGE_OFFSET(blk_off);
538#else
539 maxlen = 0x100 - blk_off;
540#endif
541 if (maxlen > I2C_RXTX_LEN)
542 maxlen = I2C_RXTX_LEN;
543
544 if (len > maxlen)
545 len = maxlen;
546
547 if (i2c_write (addr[0], offset, alen - 1, buffer, len) != 0)
548 rcode = 1;
549
550 buffer += len;
551 offset += len;
552
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200553#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS)
554 udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100555#endif
556 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200557#if defined(CONFIG_SYS_EEPROM_WREN)
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100558 eeprom_write_enable(dev_addr, 0);
559#endif
560 return rcode;
561}
562
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200563int do_setup_boot_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100564{
565 ulong sdsdp[4];
566
567 if (argc > 1) {
568 if (!strcmp(argv[1], "533")) {
569 printf("Bootstrapping for 533MHz\n");
570 sdsdp[0] = 0x87788252;
571 /* PLB-PCI-divider = 3 : sync PCI clock=44MHz */
572 sdsdp[1] = 0x095fa030;
573 sdsdp[2] = 0x40082350;
574 sdsdp[3] = 0x0d050000;
575 } else if (!strcmp(argv[1], "533-66")) {
576 printf("Bootstrapping for 533MHz (66MHz PCI)\n");
577 sdsdp[0] = 0x87788252;
578 /* PLB-PCI-divider = 2 : sync PCI clock=66MHz */
579 sdsdp[1] = 0x0957a030;
580 sdsdp[2] = 0x40082350;
581 sdsdp[3] = 0x0d050000;
582 } else if (!strcmp(argv[1], "667")) {
583 printf("Bootstrapping for 667MHz\n");
584 sdsdp[0] = 0x8778a256;
585 /* PLB-PCI-divider = 4 : sync PCI clock=33MHz */
586 sdsdp[1] = 0x0947a030;
587 /* PLB-PCI-divider = 3 : sync PCI clock=44MHz
588 * -> not working when overclocking 533MHz chips
589 * -> untested on 667MHz chips */
590 /* sdsdp[1]=0x095fa030; */
591 sdsdp[2] = 0x40082350;
592 sdsdp[3] = 0x0d050000;
Matthias Fuchsdf8c1ce2008-10-07 13:13:09 +0200593 } else if (!strcmp(argv[1], "667-166")) {
594 printf("Bootstrapping for 667-166MHz\n");
595 sdsdp[0] = 0x8778a252;
596 sdsdp[1] = 0x09d7a030;
597 sdsdp[2] = 0x40082350;
598 sdsdp[3] = 0x0d050000;
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100599 }
600 } else {
601 printf("Bootstrapping for 533MHz (default)\n");
602 sdsdp[0] = 0x87788252;
603 /* PLB-PCI-divider = 3 : sync PCI clock=44MHz */
604 sdsdp[1] = 0x095fa030;
605 sdsdp[2] = 0x40082350;
606 sdsdp[3] = 0x0d050000;
607 }
608
609 printf("Writing boot EEPROM ...\n");
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200610 if (boot_eeprom_write(CONFIG_SYS_I2C_BOOT_EEPROM_ADDR,
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100611 0, (uchar*)sdsdp, 16) != 0)
612 printf("boot_eeprom_write failed\n");
613 else
614 printf("done (dump via 'i2c md 52 0.1 10')\n");
615
616 return 0;
617}
618U_BOOT_CMD(
619 sbe, 2, 0, do_setup_boot_eeprom,
Peter Tyser2fb26042009-01-27 18:03:12 -0600620 "setup boot eeprom",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200621 ""
622);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100623
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200624#if defined(CONFIG_SYS_EEPROM_WREN)
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100625/*
626 * Input: <dev_addr> I2C address of EEPROM device to enable.
627 * <state> -1: deliver current state
628 * 0: disable write
629 * 1: enable write
630 * Returns: -1: wrong device address
631 * 0: dis-/en- able done
632 * 0/1: current state if <state> was -1.
633 */
634int eeprom_write_enable (unsigned dev_addr, int state)
635{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200636 if ((CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) &&
637 (CONFIG_SYS_I2C_BOOT_EEPROM_ADDR != dev_addr))
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100638 return -1;
639 else {
640 switch (state) {
641 case 1:
642 /* Enable write access, clear bit GPIO_SINT2. */
643 out_be32((void*)GPIO0_OR,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200644 in_be32((void*)GPIO0_OR) & ~CONFIG_SYS_GPIO0_EP_EEP);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100645 state = 0;
646 break;
647 case 0:
648 /* Disable write access, set bit GPIO_SINT2. */
649 out_be32((void*)GPIO0_OR,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200650 in_be32((void*)GPIO0_OR) | CONFIG_SYS_GPIO0_EP_EEP);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100651 state = 0;
652 break;
653 default:
654 /* Read current status back. */
655 state = (0 == (in_be32((void*)GPIO0_OR) &
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200656 CONFIG_SYS_GPIO0_EP_EEP));
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100657 break;
658 }
659 }
660 return state;
661}
662
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200663int do_eep_wren (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100664{
665 int query = argc == 1;
666 int state = 0;
667
668 if (query) {
669 /* Query write access state. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200670 state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, -1);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100671 if (state < 0)
672 puts ("Query of write access state failed.\n");
673 else {
674 printf ("Write access for device 0x%0x is %sabled.\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200675 CONFIG_SYS_I2C_EEPROM_ADDR, state ? "en" : "dis");
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100676 state = 0;
677 }
678 } else {
679 if ('0' == argv[1][0]) {
680 /* Disable write access. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200681 state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, 0);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100682 } else {
683 /* Enable write access. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200684 state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, 1);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100685 }
686 if (state < 0)
687 puts ("Setup of write access state failed.\n");
688 }
689
690 return state;
691}
692
693U_BOOT_CMD(eepwren, 2, 0, do_eep_wren,
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200694 "Enable / disable / query EEPROM write access",
695 ""
696);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200697#endif /* #if defined(CONFIG_SYS_EEPROM_WREN) */
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100698
699static int got_pldirq;
700
701static int pld_interrupt(u32 arg)
702{
703 int rc = -1; /* not for us */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100704 u8 status = in_8((void *)CONFIG_SYS_CPLD_BASE);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100705
706 /* check for PLD interrupt */
707 if (status & PWR_INT_FLAG) {
708 /* reset this int */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100709 out_8((void *)CONFIG_SYS_CPLD_BASE, 0);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100710 rc = 0;
711 got_pldirq = 1; /* trigger backend */
712 }
713
714 return rc;
715}
716
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200717int do_waitpwrirq(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100718{
719 got_pldirq = 0;
720
721 /* clear any pending interrupt */
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100722 out_8((void *)CONFIG_SYS_CPLD_BASE, 0);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100723
724 irq_install_handler(CPLD_IRQ,
725 (interrupt_handler_t *)pld_interrupt, 0);
726
727 printf("Waiting ...\n");
728 while(!got_pldirq) {
729 /* Abort if ctrl-c was pressed */
730 if (ctrlc()) {
731 puts("\nAbort\n");
732 break;
733 }
734 }
735 if (got_pldirq) {
736 printf("Got interrupt!\n");
737 printf("Power %sready!\n",
Matthias Fuchsbb57ad42009-02-20 10:19:19 +0100738 in_8((void *)CONFIG_SYS_CPLD_BASE) &
739 PWR_RDY ? "":"NOT ");
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100740 }
741
742 irq_free_handler(CPLD_IRQ);
743 return 0;
744}
745U_BOOT_CMD(
746 wpi, 1, 1, do_waitpwrirq,
Peter Tyser2fb26042009-01-27 18:03:12 -0600747 "Wait for power change interrupt",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200748 ""
749);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100750
751/*
752 * initialize DVI panellink transmitter
753 */
754int dvi_init(void)
755{
756 int i;
757 int ret = 0;
758 unsigned int oldbus;
759 uchar u[] = {0x08, 0x34,
760 0x09, 0x20,
761 0x0a, 0x90,
762 0x0c, 0x89,
763 0x08, 0x35};
764
765 printf("DVI: ");
766
767 oldbus = I2C_GET_BUS();
768 I2C_SET_BUS(0);
769
770 for (i = 0; i < sizeof(u); i += 2)
771 if (i2c_write (0x38, u[i], 1, &u[i + 1], 1)) {
772 ret = -1;
773 break;
774 }
775
776 if (ret == 0)
777 printf("initialized\n");
778 else
779 printf("failed - cannot initialize DVI transmitter\n");
780
781 I2C_SET_BUS(oldbus);
782 return ret;
783}
784
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200785int do_dviinit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100786{
787 dvi_init();
788 return 0;
789}
790U_BOOT_CMD(
791 dviinit, 1, 1, do_dviinit,
Peter Tyser2fb26042009-01-27 18:03:12 -0600792 "Initialize DVI Panellink transmitter",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200793 ""
794);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100795
796/*
797 * TODO: 'time' command might be useful for others as well.
798 * Move to 'common' directory.
799 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200800int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100801{
802 unsigned long long start, end;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200803 char c, cmd[CONFIG_SYS_CBSIZE];
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100804 char *p, *d = cmd;
805 int ret, i;
806 ulong us;
807
808 for (i = 1; i < argc; i++) {
809 p = argv[i];
810
811 if (i > 1)
812 *d++ = ' ';
813
814 while ((c = *p++) != '\0') {
815 *d++ = c;
816 }
817 }
818 *d = '\0';
819
820 start = get_ticks();
Simon Glass53071532012-02-14 19:59:21 +0000821 ret = run_command(cmd, 0);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100822 end = get_ticks();
823
Stefan Roeseb0021442008-07-10 09:58:06 +0200824 printf("ticks=%ld\n", (ulong)(end - start));
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100825 us = (ulong)((1000L * (end - start)) / (get_tbclk() / 1000));
Stefan Roeseb0021442008-07-10 09:58:06 +0200826 printf("usec=%ld\n", us);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100827
828 return ret;
829}
830U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200831 time, CONFIG_SYS_MAXARGS, 1, do_time,
Peter Tyser2fb26042009-01-27 18:03:12 -0600832 "run command and output execution time",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200833 ""
834);
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100835
836extern void video_hw_rectfill (
837 unsigned int bpp, /* bytes per pixel */
838 unsigned int dst_x, /* dest pos x */
839 unsigned int dst_y, /* dest pos y */
840 unsigned int dim_x, /* frame width */
841 unsigned int dim_y, /* frame height */
842 unsigned int color /* fill color */
843 );
844
845/*
846 * graphics demo
847 * draw rectangles using pseudorandom number generator
848 * (see http://www.embedded.com/columns/technicalinsights/20900500)
849 */
850unsigned int rprime = 9972;
851static unsigned int r;
852static unsigned int Y;
853
854unsigned int prng(unsigned int max)
855{
856 if (r == 0 || r == 1 || r == -1)
857 r = rprime; /* keep from getting stuck */
858
859 r = (9973 * ~r) + ((Y) % 701); /* the actual algorithm */
860 Y = (r >> 16) % max; /* choose upper bits and reduce */
861 return Y;
862}
863
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200864int do_gfxdemo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Matthias Fuchs15a08bc2008-01-17 10:52:30 +0100865{
866 unsigned int color;
867 unsigned int x, y, dx, dy;
868
869 while (!ctrlc()) {
870 x = prng(1280 - 1);
871 y = prng(1024 - 1);
872 dx = prng(1280- x - 1);
873 dy = prng(1024 - y - 1);
874 color = prng(0x10000);
875 video_hw_rectfill(2, x, y, dx, dy, color);
876 }
877
878 return 0;
879}
880U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200881 gfxdemo, CONFIG_SYS_MAXARGS, 1, do_gfxdemo,
Peter Tyser2fb26042009-01-27 18:03:12 -0600882 "demo",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200883 ""
884);