tqm8xx_pcmcia.c 7.6 KB

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