cpci2dp.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * (C) Copyright 2005
  3. * Matthias Fuchs, esd gmbh germany, matthias.fuchs@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. DECLARE_GLOBAL_DATA_PTR;
  13. int board_early_init_f (void)
  14. {
  15. unsigned long CPC0_CR0Reg;
  16. /*
  17. * Setup GPIO pins
  18. */
  19. CPC0_CR0Reg = mfdcr(CPC0_CR0);
  20. mtdcr(CPC0_CR0, CPC0_CR0Reg |
  21. ((CONFIG_SYS_EEPROM_WP | CONFIG_SYS_PB_LED |
  22. CONFIG_SYS_SELF_RST | CONFIG_SYS_INTA_FAKE) << 5));
  23. /* set output pins to high */
  24. out_be32((void *)GPIO0_OR, CONFIG_SYS_EEPROM_WP);
  25. /* setup for output (LED=off) */
  26. out_be32((void *)GPIO0_TCR, CONFIG_SYS_EEPROM_WP | CONFIG_SYS_PB_LED);
  27. /*
  28. * IRQ 0-15 405GP internally generated; active high; level sensitive
  29. * IRQ 16 405GP internally generated; active low; level sensitive
  30. * IRQ 17-24 RESERVED
  31. * IRQ 25 (EXT IRQ 0) PB0; active low; level sensitive
  32. * IRQ 26 (EXT IRQ 1) PB1; active low; level sensitive
  33. * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive
  34. * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive
  35. * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
  36. * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive
  37. * IRQ 31 (EXT IRQ 6) unused
  38. */
  39. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  40. mtdcr(UIC0ER, 0x00000000); /* disable all ints */
  41. mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/
  42. mtdcr(UIC0PR, 0xFFFFFF81); /* set int polarities */
  43. mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
  44. mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority*/
  45. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  46. return 0;
  47. }
  48. int misc_init_r (void)
  49. {
  50. unsigned long CPC0_CR0Reg;
  51. /* adjust flash start and offset */
  52. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  53. gd->bd->bi_flashoffset = 0;
  54. /*
  55. * Select cts (and not dsr) on uart1
  56. */
  57. CPC0_CR0Reg = mfdcr(CPC0_CR0);
  58. mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00001000);
  59. return (0);
  60. }
  61. /*
  62. * Check Board Identity:
  63. */
  64. int checkboard (void)
  65. {
  66. char str[64];
  67. int i = getenv_f("serial#", str, sizeof(str));
  68. puts ("Board: ");
  69. if (i == -1) {
  70. puts ("### No HW ID - assuming CPCI2DP");
  71. } else {
  72. puts(str);
  73. }
  74. printf(" (Ver 1.0)");
  75. putc ('\n');
  76. return 0;
  77. }
  78. #if defined(CONFIG_SYS_EEPROM_WREN)
  79. /* Input: <dev_addr> I2C address of EEPROM device to enable.
  80. * <state> -1: deliver current state
  81. * 0: disable write
  82. * 1: enable write
  83. * Returns: -1: wrong device address
  84. * 0: dis-/en- able done
  85. * 0/1: current state if <state> was -1.
  86. */
  87. int eeprom_write_enable (unsigned dev_addr, int state) {
  88. if (CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) {
  89. return -1;
  90. } else {
  91. switch (state) {
  92. case 1:
  93. /* Enable write access, clear bit GPIO_SINT2. */
  94. out_be32((void *)GPIO0_OR,
  95. in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_EEPROM_WP);
  96. state = 0;
  97. break;
  98. case 0:
  99. /* Disable write access, set bit GPIO_SINT2. */
  100. out_be32((void *)GPIO0_OR,
  101. in_be32((void *)GPIO0_OR) | CONFIG_SYS_EEPROM_WP);
  102. state = 0;
  103. break;
  104. default:
  105. /* Read current status back. */
  106. state = (0 == (in_be32((void *)GPIO0_OR) &
  107. CONFIG_SYS_EEPROM_WP));
  108. break;
  109. }
  110. }
  111. return state;
  112. }
  113. #endif
  114. #if defined(CONFIG_SYS_EEPROM_WREN)
  115. int do_eep_wren (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  116. {
  117. int query = argc == 1;
  118. int state = 0;
  119. if (query) {
  120. /* Query write access state. */
  121. state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, -1);
  122. if (state < 0) {
  123. puts ("Query of write access state failed.\n");
  124. } else {
  125. printf ("Write access for device 0x%0x is %sabled.\n",
  126. CONFIG_SYS_I2C_EEPROM_ADDR, state ? "en" : "dis");
  127. state = 0;
  128. }
  129. } else {
  130. if ('0' == argv[1][0]) {
  131. /* Disable write access. */
  132. state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, 0);
  133. } else {
  134. /* Enable write access. */
  135. state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, 1);
  136. }
  137. if (state < 0) {
  138. puts ("Setup of write access state failed.\n");
  139. }
  140. }
  141. return state;
  142. }
  143. U_BOOT_CMD(
  144. eepwren, 2, 0, do_eep_wren,
  145. "Enable / disable / query EEPROM write access",
  146. ""
  147. );
  148. #endif /* #if defined(CONFIG_SYS_EEPROM_WREN) */