pcmcia.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 pcmconf8xx_t *pcmp;
  65. uint reg, mask;
  66. debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n",
  67. 'A' + slot);
  68. udelay (10000);
  69. pcmp = (pcmconf8xx_t *) (&(((immap_t *) CONFIG_SYS_IMMR)->im_pcmcia));
  70. /* clear interrupt state, and disable interrupts */
  71. pcmp->pcmc_pscr = PCMCIA_MASK (_slot_);
  72. pcmp->pcmc_per &= ~PCMCIA_MASK (_slot_);
  73. /*
  74. * Disable interrupts, DMA, and PCMCIA buffers
  75. * (isolate the interface) and assert RESET signal
  76. */
  77. debug ("Disable PCMCIA buffers and assert RESET\n");
  78. reg = 0;
  79. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  80. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  81. PCMCIA_PGCRX (_slot_) = reg;
  82. udelay (500);
  83. /* remove all power */
  84. pcmcia_voltage_set (slot, 0, 0);
  85. /*
  86. * Make sure there is a card in the slot, then configure the interface.
  87. */
  88. udelay(10000);
  89. debug ("[%d] %s: PIPR(%p)=0x%x\n",
  90. __LINE__,__FUNCTION__,
  91. &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
  92. if (pcmp->pcmc_pipr & (0x10000000 >> (slot << 4))) {
  93. printf (" No Card found\n");
  94. return (1);
  95. }
  96. /*
  97. * Power On.
  98. */
  99. mask = PCMCIA_VS1 (_slot_) | PCMCIA_VS2 (_slot_);
  100. reg = pcmp->pcmc_pipr;
  101. debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n", reg,
  102. (reg & PCMCIA_VS1 (slot)) ? "n" : "ff",
  103. (reg & PCMCIA_VS2 (slot)) ? "n" : "ff");
  104. if ((reg & mask) == mask) {
  105. pcmcia_voltage_set (_slot_, 50, 0);
  106. printf (" 5.0V card found: ");
  107. } else {
  108. pcmcia_voltage_set (_slot_, 33, 0);
  109. printf (" 3.3V card found: ");
  110. }
  111. debug ("Enable PCMCIA buffers and stop RESET\n");
  112. reg = PCMCIA_PGCRX (_slot_);
  113. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  114. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  115. PCMCIA_PGCRX (_slot_) = reg;
  116. udelay (250000); /* some cards need >150 ms to come up :-( */
  117. debug ("# hardware_enable done\n");
  118. return (0);
  119. }
  120. #if defined(CONFIG_CMD_PCMCIA)
  121. int pcmcia_hardware_disable (int slot)
  122. {
  123. return 0; /* No hardware to disable */
  124. }
  125. #endif
  126. #endif /* CONFIG_PCMCIA */