tqm8xx_pcmcia.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /* -------------------------------------------------------------------- */
  2. /* TQM8xxL Boards by TQ Components */
  3. /* SC8xx Boards by SinoVee Microsystems */
  4. /* -------------------------------------------------------------------- */
  5. #include <common.h>
  6. #include <asm/io.h>
  7. #ifdef CONFIG_8xx
  8. #include <mpc8xx.h>
  9. #endif
  10. #include <pcmcia.h>
  11. #undef CONFIG_PCMCIA
  12. #if defined(CONFIG_CMD_PCMCIA)
  13. #define CONFIG_PCMCIA
  14. #endif
  15. #if defined(CONFIG_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
  16. #define CONFIG_PCMCIA
  17. #endif
  18. #if defined(CONFIG_PCMCIA) \
  19. && defined(CONFIG_TQM8xxL)
  20. #if defined(CONFIG_TQM8xxL)
  21. #define PCMCIA_BOARD_MSG "TQM8xxL"
  22. #endif
  23. static inline void power_config(int slot)
  24. {
  25. immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  26. /*
  27. * Configure Port C pins for
  28. * 5 Volts Enable and 3 Volts enable
  29. */
  30. clrbits_be16(&immap->im_ioport.iop_pcpar, 0x0002 | 0x0004);
  31. clrbits_be16(&immap->im_ioport.iop_pcso, 0x0002 | 0x0004);
  32. }
  33. static inline void power_off(int slot)
  34. {
  35. immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  36. clrbits_be16(&immap->im_ioport.iop_pcdat, 0x0002 | 0x0004);
  37. }
  38. static inline void power_on_5_0(int slot)
  39. {
  40. immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  41. setbits_be16(&immap->im_ioport.iop_pcdat, 0x0004);
  42. setbits_be16(&immap->im_ioport.iop_pcdir, 0x0002 | 0x0004);
  43. }
  44. static inline void power_on_3_3(int slot)
  45. {
  46. immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  47. setbits_be16(&immap->im_ioport.iop_pcdat, 0x0002);
  48. setbits_be16(&immap->im_ioport.iop_pcdir, 0x0002 | 0x0004);
  49. }
  50. /*
  51. * Function to retrieve the PIPR register, used for debuging purposes.
  52. */
  53. static inline uint32_t debug_get_pipr(void)
  54. {
  55. uint32_t pipr = 0;
  56. #ifdef DEBUG
  57. immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  58. pipr = in_be32(&immap->im_pcmcia.pcmc_pipr);
  59. #endif
  60. return pipr;
  61. }
  62. static inline int check_card_is_absent(int slot)
  63. {
  64. immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  65. uint32_t pipr = in_be32(&immap->im_pcmcia.pcmc_pipr);
  66. return pipr & (0x18000000 >> (slot << 4));
  67. }
  68. #define NSCU_GCRX_CXOE __MY_PCMCIA_GCRX_CXOE
  69. int pcmcia_hardware_enable(int slot)
  70. {
  71. immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  72. uint reg, mask;
  73. debug("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  74. udelay(10000);
  75. /*
  76. * Configure SIUMCR to enable PCMCIA port B
  77. * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
  78. */
  79. /* Set DBGC to 00 */
  80. clrbits_be32(&immap->im_siu_conf.sc_siumcr, SIUMCR_DBGC11);
  81. /* Clear interrupt state, and disable interrupts */
  82. out_be32(&immap->im_pcmcia.pcmc_pscr, PCMCIA_MASK(slot));
  83. clrbits_be32(&immap->im_pcmcia.pcmc_per, PCMCIA_MASK(slot));
  84. /*
  85. * Disable interrupts, DMA, and PCMCIA buffers
  86. * (isolate the interface) and assert RESET signal
  87. */
  88. debug("Disable PCMCIA buffers and assert RESET\n");
  89. reg = 0;
  90. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  91. reg |= NSCU_GCRX_CXOE;
  92. PCMCIA_PGCRX(slot) = reg;
  93. udelay(500);
  94. power_config(slot);
  95. power_off(slot);
  96. /*
  97. * Make sure there is a card in the slot, then configure the interface.
  98. */
  99. udelay(10000);
  100. reg = debug_get_pipr();
  101. debug("[%d] %s: PIPR(%p)=0x%x\n", __LINE__, __FUNCTION__,
  102. &immap->im_pcmcia.pcmc_pipr, reg);
  103. if (check_card_is_absent(slot)) {
  104. printf (" No Card found\n");
  105. return (1);
  106. }
  107. /*
  108. * Power On.
  109. */
  110. mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
  111. reg = in_be32(&immap->im_pcmcia.pcmc_pipr);
  112. debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
  113. reg,
  114. (reg & PCMCIA_VS1(slot)) ? "n" : "ff",
  115. (reg & PCMCIA_VS2(slot)) ? "n" : "ff");
  116. if ((reg & mask) == mask) {
  117. power_on_5_0(slot);
  118. puts (" 5.0V card found: ");
  119. } else {
  120. power_on_3_3(slot);
  121. puts (" 3.3V card found: ");
  122. }
  123. #if 0
  124. /* VCC switch error flag, PCMCIA slot INPACK_ pin */
  125. cp->cp_pbdir &= ~(0x0020 | 0x0010);
  126. cp->cp_pbpar &= ~(0x0020 | 0x0010);
  127. udelay(500000);
  128. #endif
  129. udelay(1000);
  130. debug("Enable PCMCIA buffers and stop RESET\n");
  131. reg = PCMCIA_PGCRX(slot);
  132. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  133. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  134. reg &= ~NSCU_GCRX_CXOE;
  135. PCMCIA_PGCRX(slot) = reg;
  136. udelay(250000); /* some cards need >150 ms to come up :-( */
  137. debug("# hardware_enable done\n");
  138. return (0);
  139. }
  140. #if defined(CONFIG_CMD_PCMCIA)
  141. int pcmcia_hardware_disable(int slot)
  142. {
  143. u_long reg;
  144. debug("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  145. /* remove all power */
  146. power_off(slot);
  147. debug("Disable PCMCIA buffers and assert RESET\n");
  148. reg = 0;
  149. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  150. reg |= NSCU_GCRX_CXOE; /* active low */
  151. PCMCIA_PGCRX(slot) = reg;
  152. udelay(10000);
  153. return (0);
  154. }
  155. #endif
  156. int pcmcia_voltage_set(int slot, int vcc, int vpp)
  157. {
  158. u_long reg;
  159. uint32_t pipr = 0;
  160. debug("voltage_set: " PCMCIA_BOARD_MSG
  161. " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
  162. 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
  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. reg |= NSCU_GCRX_CXOE; /* active low */
  172. PCMCIA_PGCRX(slot) = reg;
  173. udelay(500);
  174. debug("PCMCIA power OFF\n");
  175. power_config(slot);
  176. power_off(slot);
  177. switch(vcc) {
  178. case 0: break;
  179. case 33: power_on_3_3(slot); break;
  180. case 50: power_on_5_0(slot); break;
  181. default: goto done;
  182. }
  183. /* Checking supported voltages */
  184. pipr = debug_get_pipr();
  185. debug("PIPR: 0x%x --> %s\n", pipr,
  186. (pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
  187. if (vcc)
  188. debug("PCMCIA powered at %sV\n", (vcc == 50) ? "5.0" : "3.3");
  189. else
  190. debug("PCMCIA powered down\n");
  191. done:
  192. debug("Enable PCMCIA buffers and stop RESET\n");
  193. reg = PCMCIA_PGCRX(slot);
  194. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  195. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  196. reg &= ~NSCU_GCRX_CXOE; /* active low */
  197. PCMCIA_PGCRX(slot) = reg;
  198. udelay(500);
  199. debug("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n", slot+'A');
  200. return 0;
  201. }
  202. #endif /* CONFIG_PCMCIA && CONFIG_TQM8xxL */