pcmcia.c 5.4 KB

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