vom405.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * (C) Copyright 2001-2004
  3. * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <asm/processor.h>
  9. #include <asm/io.h>
  10. #include <command.h>
  11. #include <malloc.h>
  12. #include <sja1000.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. extern void lxt971_no_sleep(void);
  15. /*
  16. * generate a short spike on the CAN tx line
  17. * to bring the couplers in sync
  18. */
  19. void init_coupler(u32 addr)
  20. {
  21. struct sja1000_basic_s *ctrl = (struct sja1000_basic_s *)addr;
  22. /* reset */
  23. out_8(&ctrl->cr, CR_RR);
  24. /* dominant */
  25. out_8(&ctrl->btr0, 0x00); /* btr setup is required */
  26. out_8(&ctrl->btr1, 0x14); /* we use 1Mbit/s */
  27. out_8(&ctrl->oc, OC_TP1 | OC_TN1 | OC_POL1 |
  28. OC_TP0 | OC_TN0 | OC_POL0 | OC_MODE1);
  29. out_8(&ctrl->cr, 0x00);
  30. /* delay */
  31. in_8(&ctrl->cr);
  32. in_8(&ctrl->cr);
  33. in_8(&ctrl->cr);
  34. in_8(&ctrl->cr);
  35. /* reset */
  36. out_8(&ctrl->cr, CR_RR);
  37. }
  38. int board_early_init_f (void)
  39. {
  40. /*
  41. * IRQ 0-15 405GP internally generated; active high; level sensitive
  42. * IRQ 16 405GP internally generated; active low; level sensitive
  43. * IRQ 17-24 RESERVED
  44. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  45. * IRQ 26 (EXT IRQ 1) SER0 ; active low; level sensitive
  46. * IRQ 27 (EXT IRQ 2) SER1; active low; level sensitive
  47. * IRQ 28 (EXT IRQ 3) FPGA 0; active low; level sensitive
  48. * IRQ 29 (EXT IRQ 4) FPGA 1; active low; level sensitive
  49. * IRQ 30 (EXT IRQ 5) PCI INTA; active low; level sensitive
  50. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  51. */
  52. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  53. mtdcr(UIC0ER, 0x00000000); /* disable all ints */
  54. mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/
  55. mtdcr(UIC0PR, 0xFFFFFF80); /* set int polarities */
  56. mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
  57. mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority*/
  58. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  59. /*
  60. * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 15 us
  61. */
  62. mtebc (EBC0_CFG, 0xa8400000); /* ebc always driven */
  63. /*
  64. * Reset CPLD via GPIO12 (CS3) pin
  65. */
  66. out_be32((void *)GPIO0_OR,
  67. in_be32((void *)GPIO0_OR) & ~(0x80000000 >> 12));
  68. udelay(1000); /* wait 1ms */
  69. out_be32((void *)GPIO0_OR,
  70. in_be32((void *)GPIO0_OR) | (0x80000000 >> 12));
  71. udelay(1000); /* wait 1ms */
  72. return 0;
  73. }
  74. int misc_init_r (void)
  75. {
  76. /* adjust flash start and offset */
  77. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  78. gd->bd->bi_flashoffset = 0;
  79. /*
  80. * Init magnetic coupler
  81. */
  82. if (!getenv("noinitcoupler"))
  83. init_coupler(CAN_BA);
  84. return (0);
  85. }
  86. /*
  87. * Check Board Identity:
  88. */
  89. int checkboard (void)
  90. {
  91. char str[64];
  92. int i = getenv_f("serial#", str, sizeof(str));
  93. int flashcnt;
  94. int delay;
  95. u8 *led_reg = (u8 *)(CAN_BA + 0x1000);
  96. puts ("Board: ");
  97. if (i == -1) {
  98. puts ("### No HW ID - assuming VOM405");
  99. } else {
  100. puts(str);
  101. }
  102. printf(" (PLD-Version=%02d)\n", in_8(led_reg));
  103. /*
  104. * Flash LEDs
  105. */
  106. for (flashcnt = 0; flashcnt < 3; flashcnt++) {
  107. out_8(led_reg, 0x40); /* LED_B..D off */
  108. for (delay = 0; delay < 100; delay++)
  109. udelay(1000);
  110. out_8(led_reg, 0x47); /* LED_B..D on */
  111. for (delay = 0; delay < 50; delay++)
  112. udelay(1000);
  113. }
  114. out_8(led_reg, 0x40);
  115. return 0;
  116. }
  117. void reset_phy(void)
  118. {
  119. #ifdef CONFIG_LXT971_NO_SLEEP
  120. /*
  121. * Disable sleep mode in LXT971
  122. */
  123. lxt971_no_sleep();
  124. #endif
  125. }