1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <common.h>
22#include <command.h>
23#include <asm/ppc440.h>
24#include <asm/processor.h>
25#include <asm/ppc4xx-gpio.h>
26#include <asm/io.h>
27#include <post.h>
28#include <flash.h>
29#include <mtd/cfi_flash.h>
30
31DECLARE_GLOBAL_DATA_PTR;
32
33static phys_addr_t lwmon5_cfi_flash_bank_addr[2] = CONFIG_SYS_FLASH_BANKS_LIST;
34
35ulong flash_get_size(ulong base, int banknum);
36int misc_init_r_kbd(void);
37
38int board_early_init_f(void)
39{
40 u32 sdr0_pfc1, sdr0_pfc2;
41 u32 reg;
42
43
44 mtdcr(PLB4A0_ACR, 0xDE000000);
45 mtdcr(PLB4A1_ACR, 0xDE000000);
46
47
48
49
50 mtdcr(UIC0SR, 0xffffffff);
51 mtdcr(UIC0ER, 0x00000000);
52 mtdcr(UIC0CR, 0x00000000);
53 mtdcr(UIC0PR, 0xFFBFF1EF);
54 mtdcr(UIC0TR, 0x00000900);
55 mtdcr(UIC0VR, 0x00000000);
56 mtdcr(UIC0SR, 0xffffffff);
57
58 mtdcr(UIC1SR, 0xffffffff);
59 mtdcr(UIC1ER, 0x00000000);
60 mtdcr(UIC1CR, 0x00000000);
61 mtdcr(UIC1PR, 0xFFFFC6A5);
62 mtdcr(UIC1TR, 0x60000040);
63 mtdcr(UIC1VR, 0x00000000);
64 mtdcr(UIC1SR, 0xffffffff);
65
66 mtdcr(UIC2SR, 0xffffffff);
67 mtdcr(UIC2ER, 0x00000000);
68 mtdcr(UIC2CR, 0x00000000);
69 mtdcr(UIC2PR, 0x27C00000);
70 mtdcr(UIC2TR, 0x3C000000);
71 mtdcr(UIC2VR, 0x00000000);
72 mtdcr(UIC2SR, 0xffffffff);
73
74
75 mtsdr(SDR0_PFC0, 0x0);
76
77
78 mfsdr(SDR0_PFC1, sdr0_pfc1);
79
80 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
81 SDR0_PFC1_SELECT_CONFIG_6;
82 mfsdr(SDR0_PFC2, sdr0_pfc2);
83 sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
84 SDR0_PFC2_SELECT_CONFIG_6;
85
86
87 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_SCP_SEL;
88
89 mtsdr(SDR0_PFC2, sdr0_pfc2);
90 mtsdr(SDR0_PFC1, sdr0_pfc1);
91
92 mtsdr(SDR0_PFC4, 0x80000000);
93
94
95
96 mfsdr(SDR0_PCI0, reg);
97 reg = 0;
98 mtsdr(SDR0_PCI0, 0x00000000 | reg);
99
100 gpio_write_bit(CONFIG_SYS_GPIO_FLASH_WP, 1);
101
102#if CONFIG_POST & CONFIG_SYS_POST_BSPEC1
103
104 gpio_write_bit(CONFIG_SYS_GPIO_LSB_ENABLE, 1);
105
106 gpio_write_bit(CONFIG_SYS_GPIO_CAN_ENABLE, 1);
107
108 reg = 0;
109 out_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR,
110 in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR)
111 & ~CONFIG_SYS_DSPIC_TEST_MASK);
112 while (gpio_read_in_bit(CONFIG_SYS_GPIO_DSPIC_READY) && reg++ < 1000) {
113 udelay(1000);
114 }
115 if (gpio_read_in_bit(CONFIG_SYS_GPIO_DSPIC_READY)) {
116
117 out_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR,
118 in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) |
119 CONFIG_SYS_DSPIC_TEST_MASK);
120 }
121#endif
122
123
124
125
126
127
128
129
130
131 gpio_write_bit(CONFIG_SYS_GPIO_PHY0_RST, 1);
132 gpio_write_bit(CONFIG_SYS_GPIO_PHY1_RST, 1);
133 udelay(1000);
134 gpio_write_bit(CONFIG_SYS_GPIO_PHY0_RST, 0);
135 gpio_write_bit(CONFIG_SYS_GPIO_PHY1_RST, 0);
136 udelay(1000);
137 gpio_write_bit(CONFIG_SYS_GPIO_PHY0_RST, 1);
138 gpio_write_bit(CONFIG_SYS_GPIO_PHY1_RST, 1);
139
140 return 0;
141}
142
143
144
145
146phys_addr_t cfi_flash_bank_addr(int bank)
147{
148 return lwmon5_cfi_flash_bank_addr[bank];
149}
150
151
152
153
154u32 flash_get_bank_size(int cs, int idx)
155{
156 return flash_info[idx].size;
157}
158
159int board_early_init_r(void)
160{
161 u32 val0, val1;
162
163
164
165
166
167
168
169
170
171
172
173
174
175 out_be32((void *)CONFIG_SYS_FLASH0, 0x00980098);
176 val0 = in_be32((void *)CONFIG_SYS_FLASH0 + FLASH_OFFSET_CFI_RESP);
177 val1 = in_be32((void *)CONFIG_SYS_FLASH1 + FLASH_OFFSET_CFI_RESP);
178
179
180 out_be32((void *)CONFIG_SYS_FLASH0, 0x00f000f0);
181
182
183 if (val0 != val1)
184 return 0;
185
186
187
188
189
190
191
192 cfi_flash_num_flash_banks = 1;
193 lwmon5_cfi_flash_bank_addr[0] = CONFIG_SYS_FLASH0;
194
195 return 0;
196}
197
198int misc_init_r(void)
199{
200 u32 pbcr;
201 int size_val = 0;
202 u32 reg;
203 unsigned long usb2d0cr = 0;
204 unsigned long usb2phy0cr, usb2h0cr = 0;
205 unsigned long sdr0_pfc1, sdr0_srst;
206
207
208
209
210
211
212
213
214 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
215 gd->bd->bi_flashoffset = 0;
216
217 mfebc(PB0CR, pbcr);
218 size_val = ffs(gd->bd->bi_flashsize) - 21;
219 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
220 mtebc(PB0CR, pbcr);
221
222
223
224
225 flash_get_size(gd->bd->bi_flashstart, 0);
226
227
228 flash_protect(FLAG_PROTECT_SET, -CONFIG_SYS_MONITOR_LEN, 0xffffffff,
229 &flash_info[cfi_flash_num_flash_banks - 1]);
230
231
232 flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
233 CONFIG_ENV_ADDR_REDUND + 2 * CONFIG_ENV_SECT_SIZE - 1,
234 &flash_info[cfi_flash_num_flash_banks - 1]);
235
236
237
238
239
240
241
242 mtsdr(SDR0_SRST0, SDR0_SRST0_USB2H | SDR0_SRST0_USB2D);
243 udelay(2000);
244
245 mtsdr(SDR0_SRST1, SDR0_SRST1_USB20PHY | SDR0_SRST1_USB2HUTMI |
246 SDR0_SRST1_USB2HPHY | SDR0_SRST1_OPBA2 |
247 SDR0_SRST1_PLB42OPB1 | SDR0_SRST1_OPB2PLB40);
248 udelay(2000);
249
250
251
252
253
254 mfsdr(SDR0_PFC1, sdr0_pfc1);
255 mfsdr(SDR0_USB0, usb2d0cr);
256 mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
257 mfsdr(SDR0_USB2H0CR, usb2h0cr);
258
259 usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_XOCLK_MASK;
260 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
261 usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_WDINT_MASK;
262 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
263 usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DVBUS_MASK;
264 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN;
265 usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DWNSTR_MASK;
266 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
267 usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_UTMICN_MASK;
268 usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
269
270
271
272
273
274 usb2h0cr = usb2h0cr & ~SDR0_USB2H0CR_WDINT_MASK;
275 usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
276
277 mtsdr(SDR0_PFC1, sdr0_pfc1);
278 mtsdr(SDR0_USB0, usb2d0cr);
279 mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
280 mtsdr(SDR0_USB2H0CR, usb2h0cr);
281
282
283 mfsdr(SDR0_SRST1, sdr0_srst);
284 sdr0_srst = sdr0_srst & ~SDR0_SRST1_USB20PHY;
285 mtsdr(SDR0_SRST1, sdr0_srst);
286
287
288 udelay(2000);
289
290
291 mfsdr(SDR0_SRST0, sdr0_srst);
292 sdr0_srst = sdr0_srst &~ SDR0_SRST0_USB2H;
293 mtsdr(SDR0_SRST0, sdr0_srst);
294 udelay(1000);
295
296
297 mfsdr(SDR0_SRST1, sdr0_srst);
298 sdr0_srst = sdr0_srst &~ SDR0_SRST1_PLB42OPB1;
299 sdr0_srst = sdr0_srst &~ SDR0_SRST1_OPB2PLB40;
300 sdr0_srst = sdr0_srst &~ SDR0_SRST1_OPBA2;
301 mtsdr(SDR0_SRST1, sdr0_srst);
302 udelay(1000);
303
304
305
306
307 mtsdr(SDR0_SRST1, SDR0_SRST1_USB20PHY);
308 udelay(1000);
309
310
311
312
313 mtsdr(SDR0_SRST1, 0x00000000);
314 mtsdr(SDR0_SRST0, 0x00000000);
315
316 printf("USB: Host(int phy) Device(ext phy)\n");
317
318
319
320
321
322
323 reg = mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_WRP_MASK;
324 mtdcr(PLB4A0_ACR, reg);
325
326
327
328
329 misc_init_r_kbd();
330
331 return 0;
332}
333
334int checkboard(void)
335{
336 char buf[64];
337 int i = getenv_f("serial#", buf, sizeof(buf));
338
339 puts("Board: lwmon5");
340
341 if (i > 0) {
342 puts(", serial# ");
343 puts(buf);
344 }
345 putc('\n');
346
347 return (0);
348}
349
350void hw_watchdog_reset(void)
351{
352 int val;
353#if defined(CONFIG_WD_MAX_RATE)
354 unsigned long long ct = get_ticks();
355
356
357
358
359
360 if (ct >= gd->wdt_last) {
361 if ((ct - gd->wdt_last) < CONFIG_WD_MAX_RATE)
362 return;
363 } else {
364
365 if (((unsigned long long)(-1) - gd->wdt_last + ct) <
366 CONFIG_WD_MAX_RATE)
367 return;
368 }
369 gd->wdt_last = get_ticks();
370#endif
371
372
373
374
375 val = gpio_read_out_bit(CONFIG_SYS_GPIO_WATCHDOG) == 0 ? 1 : 0;
376 gpio_write_bit(CONFIG_SYS_GPIO_WATCHDOG, val);
377}
378
379int do_eeprom_wp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
380{
381 if (argc < 2)
382 return cmd_usage(cmdtp);
383
384 if ((strcmp(argv[1], "on") == 0))
385 gpio_write_bit(CONFIG_SYS_GPIO_EEPROM_EXT_WP, 1);
386 else if ((strcmp(argv[1], "off") == 0))
387 gpio_write_bit(CONFIG_SYS_GPIO_EEPROM_EXT_WP, 0);
388 else
389 return cmd_usage(cmdtp);
390
391 return 0;
392}
393
394U_BOOT_CMD(
395 eepromwp, 2, 0, do_eeprom_wp,
396 "eeprom write protect off/on",
397 "<on|off> - enable (on) or disable (off) I2C EEPROM write protect"
398);
399
400#if defined(CONFIG_VIDEO)
401#include <video_fb.h>
402#include <mb862xx.h>
403
404extern GraphicDevice mb862xx;
405
406static const gdc_regs init_regs [] = {
407 { 0x0100, 0x00000f00 },
408 { 0x0020, 0x801401df },
409 { 0x0024, 0x00000000 },
410 { 0x0028, 0x00000000 },
411 { 0x002c, 0x00000000 },
412 { 0x0110, 0x00000000 },
413 { 0x0114, 0x00000000 },
414 { 0x0118, 0x01df0280 },
415 { 0x0004, 0x031f0000 },
416 { 0x0008, 0x027f027f },
417 { 0x000c, 0x015f028f },
418 { 0x0010, 0x020c0000 },
419 { 0x0014, 0x01df01ea },
420 { 0x0018, 0x00000000 },
421 { 0x001c, 0x01e00280 },
422 { 0x0100, 0x80010f00 },
423 { 0x0, 0x0 }
424};
425
426const gdc_regs *board_get_regs(void)
427{
428 return init_regs;
429}
430
431
432unsigned int board_video_init(void)
433{
434
435
436
437 gpio_write_bit(CONFIG_SYS_GPIO_LIME_S, 1);
438 udelay(500);
439 gpio_write_bit(CONFIG_SYS_GPIO_LIME_RST, 1);
440
441 mb862xx.winSizeX = 640;
442 mb862xx.winSizeY = 480;
443 mb862xx.gdfBytesPP = 2;
444 mb862xx.gdfIndex = GDF_15BIT_555RGB;
445
446 return CONFIG_SYS_LIME_BASE_0;
447}
448
449#define DEFAULT_BRIGHTNESS 0x64
450
451static void board_backlight_brightness(int brightness)
452{
453 if (brightness > 0) {
454
455 out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000024), brightness);
456 out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000020), 0x701);
457 } else {
458
459 out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000024), 0x00);
460 out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000020), 0x00);
461 }
462}
463
464void board_backlight_switch(int flag)
465{
466 char * param;
467 int rc;
468
469 if (flag) {
470 param = getenv("brightness");
471 rc = param ? simple_strtol(param, NULL, 10) : -1;
472 if (rc < 0)
473 rc = DEFAULT_BRIGHTNESS;
474 } else {
475 rc = 0;
476 }
477 board_backlight_brightness(rc);
478}
479
480#if defined(CONFIG_CONSOLE_EXTRA_INFO)
481
482
483
484void video_get_info_str(int line_number, char *info)
485{
486 if (line_number == 1)
487 strcpy(info, " Board: Lwmon5 (Liebherr Elektronik GmbH)");
488 else
489 info [0] = '\0';
490}
491#endif
492#endif
493
494void board_reset(void)
495{
496 gpio_write_bit(CONFIG_SYS_GPIO_BOARD_RESET, 1);
497}
498