pcmcia.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 "C2MON"
  13. static void cfg_ports (void)
  14. {
  15. volatile immap_t *immap;
  16. volatile cpm8xx_t *cp;
  17. ushort sreg;
  18. immap = (immap_t *)CFG_IMMR;
  19. cp = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
  20. /*
  21. * Configure Port C for TPS2211 PC-Card Power-Interface Switch
  22. *
  23. * Switch off all voltages, assert shutdown
  24. */
  25. sreg = immap->im_ioport.iop_pcdat;
  26. sreg |= (TPS2211_VPPD0 | TPS2211_VPPD1); /* VAVPP => Hi-Z */
  27. sreg &= ~(TPS2211_VCCD0 | TPS2211_VCCD1); /* 3V and 5V off */
  28. immap->im_ioport.iop_pcdat = sreg;
  29. immap->im_ioport.iop_pcpar &= ~(TPS2211_OUTPUTS);
  30. immap->im_ioport.iop_pcdir |= TPS2211_OUTPUTS;
  31. debug ("Set Port C: PAR: %04x DIR: %04x DAT: %04x\n",
  32. immap->im_ioport.iop_pcpar,
  33. immap->im_ioport.iop_pcdir,
  34. immap->im_ioport.iop_pcdat);
  35. /*
  36. * Configure Port B for TPS2211 PC-Card Power-Interface Switch
  37. *
  38. * Over-Current Input only
  39. */
  40. cp->cp_pbpar &= ~(TPS2211_INPUTS);
  41. cp->cp_pbdir &= ~(TPS2211_INPUTS);
  42. debug ("Set Port B: PAR: %08x DIR: %08x DAT: %08x\n",
  43. cp->cp_pbpar, cp->cp_pbdir, cp->cp_pbdat);
  44. }
  45. int pcmcia_hardware_enable(int slot)
  46. {
  47. volatile immap_t *immap;
  48. volatile cpm8xx_t *cp;
  49. volatile pcmconf8xx_t *pcmp;
  50. volatile sysconf8xx_t *sysp;
  51. uint reg, pipr, mask;
  52. ushort sreg;
  53. int i;
  54. debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  55. udelay(10000);
  56. immap = (immap_t *)CFG_IMMR;
  57. sysp = (sysconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_siu_conf));
  58. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
  59. cp = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
  60. /* Configure Ports for TPS2211A PC-Card Power-Interface Switch */
  61. cfg_ports ();
  62. /*
  63. * Configure SIUMCR to enable PCMCIA port B
  64. * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
  65. */
  66. sysp->sc_siumcr &= ~SIUMCR_DBGC11; /* set DBGC to 00 */
  67. /* clear interrupt state, and disable interrupts */
  68. pcmp->pcmc_pscr = PCMCIA_MASK(_slot_);
  69. pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_);
  70. /*
  71. * Disable interrupts, DMA, and PCMCIA buffers
  72. * (isolate the interface) and assert RESET signal
  73. */
  74. debug ("Disable PCMCIA buffers and assert RESET\n");
  75. reg = 0;
  76. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  77. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  78. PCMCIA_PGCRX(_slot_) = reg;
  79. udelay(500);
  80. /*
  81. * Make sure there is a card in the slot, then configure the interface.
  82. */
  83. udelay(10000);
  84. debug ("[%d] %s: PIPR(%p)=0x%x\n",
  85. __LINE__,__FUNCTION__,
  86. &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
  87. if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
  88. printf (" No Card found\n");
  89. return (1);
  90. }
  91. /*
  92. * Power On: Set VAVCC to 3.3V or 5V, set VAVPP to Hi-Z
  93. */
  94. mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
  95. pipr = pcmp->pcmc_pipr;
  96. debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
  97. pipr,
  98. (reg&PCMCIA_VS1(slot))?"n":"ff",
  99. (reg&PCMCIA_VS2(slot))?"n":"ff");
  100. sreg = immap->im_ioport.iop_pcdat;
  101. if ((pipr & mask) == mask) {
  102. sreg |= (TPS2211_VPPD0 | TPS2211_VPPD1 | /* VAVPP => Hi-Z */
  103. TPS2211_VCCD1); /* 5V on */
  104. sreg &= ~(TPS2211_VCCD0); /* 3V off */
  105. puts (" 5.0V card found: ");
  106. } else {
  107. sreg |= (TPS2211_VPPD0 | TPS2211_VPPD1 | /* VAVPP => Hi-Z */
  108. TPS2211_VCCD0); /* 3V on */
  109. sreg &= ~(TPS2211_VCCD1); /* 5V off */
  110. puts (" 3.3V card found: ");
  111. }
  112. debug ("\nPC DAT: %04x -> 3.3V %s 5.0V %s\n",
  113. sreg,
  114. ( (sreg & TPS2211_VCCD0) && !(sreg & TPS2211_VCCD1)) ? "on" : "off",
  115. (!(sreg & TPS2211_VCCD0) && (sreg & TPS2211_VCCD1)) ? "on" : "off"
  116. );
  117. immap->im_ioport.iop_pcdat = sreg;
  118. /* Wait 500 ms; use this to check for over-current */
  119. for (i=0; i<5000; ++i) {
  120. if ((cp->cp_pbdat & TPS2211_OC) == 0) {
  121. printf (" *** Overcurrent - Safety shutdown ***\n");
  122. immap->im_ioport.iop_pcdat &= ~(TPS2211_VCCD0|TPS2211_VCCD1);
  123. return (1);
  124. }
  125. udelay (100);
  126. }
  127. debug ("Enable PCMCIA buffers and stop RESET\n");
  128. reg = PCMCIA_PGCRX(_slot_);
  129. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  130. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  131. PCMCIA_PGCRX(_slot_) = reg;
  132. udelay(250000); /* some cards need >150 ms to come up :-( */
  133. debug ("# hardware_enable done\n");
  134. return (0);
  135. }
  136. #if defined(CONFIG_CMD_PCMCIA)
  137. int pcmcia_hardware_disable(int slot)
  138. {
  139. volatile immap_t *immap;
  140. volatile cpm8xx_t *cp;
  141. volatile pcmconf8xx_t *pcmp;
  142. u_long reg;
  143. debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  144. immap = (immap_t *)CFG_IMMR;
  145. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
  146. /* Configure PCMCIA General Control Register */
  147. debug ("Disable PCMCIA buffers and assert RESET\n");
  148. reg = 0;
  149. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  150. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  151. PCMCIA_PGCRX(_slot_) = reg;
  152. /* ALl voltages off / Hi-Z */
  153. immap->im_ioport.iop_pcdat |= (TPS2211_VPPD0 | TPS2211_VPPD1 |
  154. TPS2211_VCCD0 | TPS2211_VCCD1 );
  155. udelay(10000);
  156. return (0);
  157. }
  158. #endif
  159. int pcmcia_voltage_set(int slot, int vcc, int vpp)
  160. {
  161. volatile immap_t *immap;
  162. volatile cpm8xx_t *cp;
  163. volatile pcmconf8xx_t *pcmp;
  164. u_long reg;
  165. ushort sreg;
  166. debug ("voltage_set: "
  167. PCMCIA_BOARD_MSG
  168. " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
  169. 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
  170. immap = (immap_t *)CFG_IMMR;
  171. cp = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
  172. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
  173. /*
  174. * Disable PCMCIA buffers (isolate the interface)
  175. * and assert RESET signal
  176. */
  177. debug ("Disable PCMCIA buffers and assert RESET\n");
  178. reg = PCMCIA_PGCRX(_slot_);
  179. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  180. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  181. PCMCIA_PGCRX(_slot_) = reg;
  182. udelay(500);
  183. /*
  184. * Configure Port C pins for
  185. * 5 Volts Enable and 3 Volts enable,
  186. * Turn all power pins to Hi-Z
  187. */
  188. debug ("PCMCIA power OFF\n");
  189. cfg_ports (); /* Enables switch, but all in Hi-Z */
  190. sreg = immap->im_ioport.iop_pcdat;
  191. sreg |= TPS2211_VPPD0 | TPS2211_VPPD1; /* VAVPP always Hi-Z */
  192. switch(vcc) {
  193. case 0: break; /* Switch off */
  194. case 33: sreg |= TPS2211_VCCD0; /* Switch on 3.3V */
  195. sreg &= ~TPS2211_VCCD1;
  196. break;
  197. case 50: sreg &= ~TPS2211_VCCD0; /* Switch on 5.0V */
  198. sreg |= TPS2211_VCCD1;
  199. break;
  200. default: goto done;
  201. }
  202. /* Checking supported voltages */
  203. debug ("PIPR: 0x%x --> %s\n",
  204. pcmp->pcmc_pipr,
  205. (pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
  206. immap->im_ioport.iop_pcdat = sreg;
  207. #ifdef DEBUG
  208. {
  209. char *s;
  210. if ((sreg & TPS2211_VCCD0) && !(sreg & TPS2211_VCCD1)) {
  211. s = "at 3.3V";
  212. } else if (!(sreg & TPS2211_VCCD0) && (sreg & TPS2211_VCCD1)) {
  213. s = "at 5.0V";
  214. } else {
  215. s = "down";
  216. }
  217. printf ("PCMCIA powered %s\n", s);
  218. }
  219. #endif
  220. done:
  221. debug ("Enable PCMCIA buffers and stop RESET\n");
  222. reg = PCMCIA_PGCRX(_slot_);
  223. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  224. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  225. PCMCIA_PGCRX(_slot_) = reg;
  226. udelay(500);
  227. debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
  228. slot+'A');
  229. return (0);
  230. }
  231. #endif /* CONFIG_PCMCIA */