pcmcia.c 6.5 KB

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