pcmcia.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #include <common.h>
  2. #include <mpc8xx.h>
  3. #include <pcmcia.h>
  4. #include "csr.h"
  5. #undef CONFIG_PCMCIA
  6. #if defined(CONFIG_CMD_PCMCIA)
  7. #define CONFIG_PCMCIA
  8. #endif
  9. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
  10. #define CONFIG_PCMCIA
  11. #endif
  12. #ifdef CONFIG_PCMCIA
  13. /* A lot of this has been taken from the RPX code in this file it works from me.
  14. I have added the voltage selection for the MBX board. */
  15. /* MBX voltage bit in control register #2 */
  16. #define CR2_VPP12 ((uchar)0x10)
  17. #define CR2_VPPVDD ((uchar)0x20)
  18. #define CR2_VDD5 ((uchar)0x40)
  19. #define CR2_VDD3 ((uchar)0x80)
  20. #define PCMCIA_BOARD_MSG "MBX860"
  21. int pcmcia_voltage_set (int slot, int vcc, int vpp)
  22. {
  23. uchar reg = 0;
  24. debug ("voltage_set: PCMCIA_BOARD_MSG Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
  25. 'A' + slot, vcc / 10, vcc % 10, vpp / 10, vcc % 10);
  26. switch (vcc) {
  27. case 0:
  28. break;
  29. case 33:
  30. reg |= CR2_VDD3;
  31. break;
  32. case 50:
  33. reg |= CR2_VDD5;
  34. break;
  35. default:
  36. return 1;
  37. }
  38. switch (vpp) {
  39. case 0:
  40. break;
  41. case 33:
  42. case 50:
  43. if (vcc == vpp) {
  44. reg |= CR2_VPPVDD;
  45. } else {
  46. return 1;
  47. }
  48. break;
  49. case 120:
  50. reg |= CR2_VPP12;
  51. break;
  52. default:
  53. return 1;
  54. }
  55. /* first, turn off all power */
  56. MBX_CSR2 &= ~(CR2_VDDSEL | CR2_VPPSEL);
  57. /* enable new powersettings */
  58. MBX_CSR2 |= reg;
  59. debug ("MBX_CSR2 read = 0x%02x\n", MBX_CSR2);
  60. return (0);
  61. }
  62. int pcmcia_hardware_enable (int slot)
  63. {
  64. volatile immap_t *immap;
  65. volatile cpm8xx_t *cp;
  66. volatile pcmconf8xx_t *pcmp;
  67. volatile sysconf8xx_t *sysp;
  68. uint reg, mask;
  69. debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n",
  70. 'A' + slot);
  71. udelay (10000);
  72. immap = (immap_t *) CONFIG_SYS_IMMR;
  73. sysp = (sysconf8xx_t *) (&(((immap_t *) CONFIG_SYS_IMMR)->im_siu_conf));
  74. pcmp = (pcmconf8xx_t *) (&(((immap_t *) CONFIG_SYS_IMMR)->im_pcmcia));
  75. cp = (cpm8xx_t *) (&(((immap_t *) CONFIG_SYS_IMMR)->im_cpm));
  76. /* clear interrupt state, and disable interrupts */
  77. pcmp->pcmc_pscr = PCMCIA_MASK (_slot_);
  78. pcmp->pcmc_per &= ~PCMCIA_MASK (_slot_);
  79. /*
  80. * Disable interrupts, DMA, and PCMCIA buffers
  81. * (isolate the interface) and assert RESET signal
  82. */
  83. debug ("Disable PCMCIA buffers and assert RESET\n");
  84. reg = 0;
  85. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  86. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  87. PCMCIA_PGCRX (_slot_) = reg;
  88. udelay (500);
  89. /* remove all power */
  90. pcmcia_voltage_set (slot, 0, 0);
  91. /*
  92. * Make sure there is a card in the slot, then configure the interface.
  93. */
  94. udelay(10000);
  95. debug ("[%d] %s: PIPR(%p)=0x%x\n",
  96. __LINE__,__FUNCTION__,
  97. &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
  98. #ifndef CONFIG_HMI10
  99. if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
  100. #else
  101. if (pcmp->pcmc_pipr & (0x10000000 >> (slot << 4))) {
  102. #endif /* CONFIG_HMI10 */
  103. printf (" No Card found\n");
  104. return (1);
  105. }
  106. /*
  107. * Power On.
  108. */
  109. mask = PCMCIA_VS1 (_slot_) | PCMCIA_VS2 (_slot_);
  110. reg = pcmp->pcmc_pipr;
  111. debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n", reg,
  112. (reg & PCMCIA_VS1 (slot)) ? "n" : "ff",
  113. (reg & PCMCIA_VS2 (slot)) ? "n" : "ff");
  114. if ((reg & mask) == mask) {
  115. pcmcia_voltage_set (_slot_, 50, 0);
  116. printf (" 5.0V card found: ");
  117. } else {
  118. pcmcia_voltage_set (_slot_, 33, 0);
  119. printf (" 3.3V card found: ");
  120. }
  121. debug ("Enable PCMCIA buffers and stop RESET\n");
  122. reg = PCMCIA_PGCRX (_slot_);
  123. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  124. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  125. PCMCIA_PGCRX (_slot_) = reg;
  126. udelay (250000); /* some cards need >150 ms to come up :-( */
  127. debug ("# hardware_enable done\n");
  128. return (0);
  129. }
  130. #if defined(CONFIG_CMD_PCMCIA)
  131. int pcmcia_hardware_disable (int slot)
  132. {
  133. return 0; /* No hardware to disable */
  134. }
  135. #endif
  136. #endif /* CONFIG_PCMCIA */