pcmcia.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #include <common.h>
  2. #include <mpc8xx.h>
  3. #include <pcmcia.h>
  4. #undef CONFIG_PCMCIA
  5. #if defined(CONFIG_CMD_PCMCIA)
  6. #define CONFIG_PCMCIA
  7. #endif
  8. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
  9. #define CONFIG_PCMCIA
  10. #endif
  11. #ifdef CONFIG_PCMCIA
  12. #define PCMCIA_BOARD_MSG "KUP"
  13. #define KUP4K_PCMCIA_B_3V3 (0x00020000)
  14. int pcmcia_hardware_enable(int slot)
  15. {
  16. volatile cpm8xx_t *cp;
  17. volatile pcmconf8xx_t *pcmp;
  18. volatile sysconf8xx_t *sysp;
  19. uint reg, mask;
  20. debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  21. udelay(10000);
  22. sysp = (sysconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_siu_conf));
  23. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  24. cp = (cpm8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_cpm));
  25. /*
  26. * Configure SIUMCR to enable PCMCIA port B
  27. * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
  28. */
  29. sysp->sc_siumcr &= ~SIUMCR_DBGC11; /* set DBGC to 00 */
  30. /* clear interrupt state, and disable interrupts */
  31. pcmp->pcmc_pscr = PCMCIA_MASK(slot);
  32. pcmp->pcmc_per &= ~PCMCIA_MASK(slot);
  33. /*
  34. * Disable interrupts, DMA, and PCMCIA buffers
  35. * (isolate the interface) and assert RESET signal
  36. */
  37. debug ("Disable PCMCIA buffers and assert RESET\n");
  38. reg = 0;
  39. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  40. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  41. PCMCIA_PGCRX(slot) = reg;
  42. udelay(2500);
  43. /*
  44. * Configure Port B pins for
  45. * 3 Volts enable
  46. */
  47. if (slot) { /* Slot A is built-in */
  48. cp->cp_pbdir |= KUP4K_PCMCIA_B_3V3;
  49. cp->cp_pbpar &= ~KUP4K_PCMCIA_B_3V3;
  50. /* remove all power */
  51. cp->cp_pbdat |= KUP4K_PCMCIA_B_3V3; /* active low */
  52. }
  53. /*
  54. * Make sure there is a card in the slot, then configure the interface.
  55. */
  56. udelay(10000);
  57. debug ("[%d] %s: PIPR(%p)=0x%x\n",
  58. __LINE__,__FUNCTION__,
  59. &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
  60. if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
  61. printf (" No Card found\n");
  62. return (1);
  63. }
  64. /*
  65. * Power On.
  66. */
  67. printf("%s Slot %c:", slot ? "" : "\n", 'A' + slot);
  68. mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
  69. reg = pcmp->pcmc_pipr;
  70. debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
  71. reg,
  72. (reg&PCMCIA_VS1(slot))?"n":"ff",
  73. (reg&PCMCIA_VS2(slot))?"n":"ff");
  74. if ((reg & mask) == mask) {
  75. puts (" 5.0V card found: NOT SUPPORTED !!!\n");
  76. } else {
  77. if(slot)
  78. cp->cp_pbdat &= ~KUP4K_PCMCIA_B_3V3;
  79. puts (" 3.3V card found: ");
  80. }
  81. #if 0
  82. /* VCC switch error flag, PCMCIA slot INPACK_ pin */
  83. cp->cp_pbdir &= ~(0x0020 | 0x0010);
  84. cp->cp_pbpar &= ~(0x0020 | 0x0010);
  85. udelay(500000);
  86. #endif
  87. debug ("Enable PCMCIA buffers and stop RESET\n");
  88. reg = PCMCIA_PGCRX(slot);
  89. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  90. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  91. PCMCIA_PGCRX(slot) = reg;
  92. udelay(250000); /* some cards need >150 ms to come up :-( */
  93. debug ("# hardware_enable done\n");
  94. return (0);
  95. }
  96. #if defined(CONFIG_CMD_PCMCIA)
  97. int pcmcia_hardware_disable(int slot)
  98. {
  99. volatile immap_t *immap;
  100. volatile cpm8xx_t *cp;
  101. volatile pcmconf8xx_t *pcmp;
  102. u_long reg;
  103. debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  104. immap = (immap_t *)CONFIG_SYS_IMMR;
  105. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  106. cp = (cpm8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_cpm));
  107. /* remove all power */
  108. if (slot)
  109. cp->cp_pbdat |= KUP4K_PCMCIA_B_3V3;
  110. /* Configure PCMCIA General Control Register */
  111. debug ("Disable PCMCIA buffers and assert RESET\n");
  112. reg = 0;
  113. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  114. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  115. PCMCIA_PGCRX(slot) = reg;
  116. udelay(10000);
  117. return (0);
  118. }
  119. #endif
  120. int pcmcia_voltage_set(int slot, int vcc, int vpp)
  121. {
  122. volatile cpm8xx_t *cp;
  123. volatile pcmconf8xx_t *pcmp;
  124. u_long reg;
  125. debug ("voltage_set: " \
  126. PCMCIA_BOARD_MSG \
  127. " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
  128. 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
  129. if (!slot) /* Slot A is not configurable */
  130. return 0;
  131. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  132. cp = (cpm8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_cpm));
  133. /*
  134. * Disable PCMCIA buffers (isolate the interface)
  135. * and assert RESET signal
  136. */
  137. debug ("Disable PCMCIA buffers and assert RESET\n");
  138. reg = PCMCIA_PGCRX(slot);
  139. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  140. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  141. PCMCIA_PGCRX(slot) = reg;
  142. udelay(500);
  143. debug ("PCMCIA power OFF\n");
  144. /*
  145. * Configure Port B pins for
  146. * 3 Volts enable
  147. */
  148. cp->cp_pbdir |= KUP4K_PCMCIA_B_3V3;
  149. cp->cp_pbpar &= ~KUP4K_PCMCIA_B_3V3;
  150. /* remove all power */
  151. cp->cp_pbdat |= KUP4K_PCMCIA_B_3V3; /* active low */
  152. switch(vcc) {
  153. case 0: break;
  154. case 33:
  155. cp->cp_pbdat &= ~KUP4K_PCMCIA_B_3V3;
  156. debug ("PCMCIA powered at 3.3V\n");
  157. break;
  158. case 50:
  159. debug ("PCMCIA: 5Volt vcc not supported\n");
  160. break;
  161. default:
  162. puts("PCMCIA: vcc not supported");
  163. break;
  164. }
  165. udelay(10000);
  166. /* Checking supported voltages */
  167. debug ("PIPR: 0x%x --> %s\n",
  168. pcmp->pcmc_pipr,
  169. (pcmp->pcmc_pipr & (0x80000000 >> (slot << 4)))
  170. ? "only 5 V --> NOT SUPPORTED"
  171. : "can do 3.3V");
  172. debug ("Enable PCMCIA buffers and stop RESET\n");
  173. reg = PCMCIA_PGCRX(slot);
  174. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  175. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  176. PCMCIA_PGCRX(slot) = reg;
  177. udelay(500);
  178. debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
  179. slot+'A');
  180. return (0);
  181. }
  182. #endif /* CONFIG_PCMCIA */