canbt.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * (C) Copyright 2001
  3. * Matthias Fuchs, esd gmbh germany, matthias.fuchs@esd-electronics.com
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include "canbt.h"
  25. #include <asm/processor.h>
  26. #include <asm/io.h>
  27. #include <command.h>
  28. DECLARE_GLOBAL_DATA_PTR;
  29. /*cmd_boot.c*/
  30. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  31. /* ------------------------------------------------------------------------- */
  32. #if 0
  33. #define FPGA_DEBUG
  34. #endif
  35. /* fpga configuration data */
  36. const unsigned char fpgadata[] = {
  37. #include "fpgadata.c"
  38. };
  39. /*
  40. * include common fpga code (for esd boards)
  41. */
  42. #include "../common/fpga.c"
  43. int board_early_init_f (void)
  44. {
  45. unsigned long cntrl0Reg;
  46. int index, len, i;
  47. int status;
  48. /*
  49. * Setup GPIO pins
  50. */
  51. cntrl0Reg = mfdcr (cntrl0) & 0xf0001fff;
  52. cntrl0Reg |= 0x0070f000;
  53. mtdcr (cntrl0, cntrl0Reg);
  54. #ifdef FPGA_DEBUG
  55. /* set up serial port with default baudrate */
  56. (void) get_clocks ();
  57. gd->baudrate = CONFIG_BAUDRATE;
  58. serial_init ();
  59. console_init_f ();
  60. #endif
  61. /*
  62. * Boot onboard FPGA
  63. */
  64. status = fpga_boot ((unsigned char *) fpgadata, sizeof (fpgadata));
  65. if (status != 0) {
  66. /* booting FPGA failed */
  67. #ifndef FPGA_DEBUG
  68. /* set up serial port with default baudrate */
  69. (void) get_clocks ();
  70. gd->baudrate = CONFIG_BAUDRATE;
  71. serial_init ();
  72. console_init_f ();
  73. #endif
  74. printf ("\nFPGA: Booting failed ");
  75. switch (status) {
  76. case ERROR_FPGA_PRG_INIT_LOW:
  77. printf ("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  78. break;
  79. case ERROR_FPGA_PRG_INIT_HIGH:
  80. printf ("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  81. break;
  82. case ERROR_FPGA_PRG_DONE:
  83. printf ("(Timeout: DONE not high after programming FPGA)\n ");
  84. break;
  85. }
  86. /* display infos on fpgaimage */
  87. index = 15;
  88. for (i = 0; i < 4; i++) {
  89. len = fpgadata[index];
  90. printf ("FPGA: %s\n", &(fpgadata[index + 1]));
  91. index += len + 3;
  92. }
  93. putc ('\n');
  94. /* delayed reboot */
  95. for (i = 20; i > 0; i--) {
  96. printf ("Rebooting in %2d seconds \r", i);
  97. for (index = 0; index < 1000; index++)
  98. udelay (1000);
  99. }
  100. putc ('\n');
  101. do_reset (NULL, 0, 0, NULL);
  102. }
  103. /*
  104. * Setup port pins for normal operation
  105. */
  106. out_be32 ((void *)GPIO0_ODR, 0x00000000); /* no open drain pins */
  107. out_be32 ((void *)GPIO0_TCR, 0x07038100); /* setup for output */
  108. out_be32 ((void *)GPIO0_OR, 0x07030100); /* set output pins to high (default) */
  109. /*
  110. * IRQ 0-15 405GP internally generated; active high; level sensitive
  111. * IRQ 16 405GP internally generated; active low; level sensitive
  112. * IRQ 17-24 RESERVED
  113. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  114. * IRQ 26 (EXT IRQ 1) CAN1; active low; level sensitive
  115. * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive
  116. * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive
  117. * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
  118. * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive
  119. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  120. */
  121. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  122. mtdcr (uicer, 0x00000000); /* disable all ints */
  123. mtdcr (uiccr, 0x00000000); /* set all to be non-critical */
  124. mtdcr (uicpr, 0xFFFFFF81); /* set int polarities */
  125. mtdcr (uictr, 0x10000000); /* set int trigger levels */
  126. mtdcr (uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */
  127. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  128. return 0;
  129. }
  130. /* ------------------------------------------------------------------------- */
  131. /*
  132. * Check Board Identity:
  133. */
  134. int checkboard (void)
  135. {
  136. int index;
  137. int len;
  138. char str[64];
  139. int i = getenv_r ("serial#", str, sizeof (str));
  140. puts ("Board: ");
  141. if (!i || strncmp (str, "CANBT", 5)) {
  142. puts ("### No HW ID - assuming CANBT\n");
  143. return (0);
  144. }
  145. puts (str);
  146. puts ("\nFPGA: ");
  147. /* display infos on fpgaimage */
  148. index = 15;
  149. for (i = 0; i < 4; i++) {
  150. len = fpgadata[index];
  151. printf ("%s ", &(fpgadata[index + 1]));
  152. index += len + 3;
  153. }
  154. putc ('\n');
  155. return 0;
  156. }