tqm8xx_pcmcia.c 6.7 KB

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