tqm8xx_pcmcia.c 6.8 KB

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