pcmcia.c 6.6 KB

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