tqm8xx_pcmcia.c 7.7 KB

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