pcmcia.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. #include <common.h>
  2. #include <mpc8xx.h>
  3. #include <pcmcia.h>
  4. #undef CONFIG_PCMCIA
  5. #if defined(CONFIG_CMD_PCMCIA)
  6. #define CONFIG_PCMCIA
  7. #endif
  8. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
  9. #define CONFIG_PCMCIA
  10. #endif
  11. #ifdef CONFIG_PCMCIA
  12. /* some sane bit macros */
  13. #define _BD(_b) (1U << (31-(_b)))
  14. #define _BDR(_l, _h) (((((1U << (31-(_l))) - 1) << 1) | 1) & ~((1U << (31-(_h))) - 1))
  15. #define _BW(_b) (1U << (15-(_b)))
  16. #define _BWR(_l, _h) (((((1U << (15-(_l))) - 1) << 1) | 1) & ~((1U << (15-(_h))) - 1))
  17. #define _BB(_b) (1U << (7-(_b)))
  18. #define _BBR(_l, _h) (((((1U << (7-(_l))) - 1) << 1) | 1) & ~((1U << (7-(_h))) - 1))
  19. #define _B(_b) _BD(_b)
  20. #define _BR(_l, _h) _BDR(_l, _h)
  21. #define PCMCIA_BOARD_MSG "NETTA"
  22. static const unsigned short vppd_masks[2] = { _BW(14), _BW(15) };
  23. static void cfg_vppd(int no)
  24. {
  25. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  26. unsigned short mask;
  27. if ((unsigned int)no >= sizeof(vppd_masks)/sizeof(vppd_masks[0]))
  28. return;
  29. mask = vppd_masks[no];
  30. immap->im_ioport.iop_papar &= ~mask;
  31. immap->im_ioport.iop_paodr &= ~mask;
  32. immap->im_ioport.iop_padir |= mask;
  33. }
  34. static void set_vppd(int no, int what)
  35. {
  36. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  37. unsigned short mask;
  38. if ((unsigned int)no >= sizeof(vppd_masks)/sizeof(vppd_masks[0]))
  39. return;
  40. mask = vppd_masks[no];
  41. if (what)
  42. immap->im_ioport.iop_padat |= mask;
  43. else
  44. immap->im_ioport.iop_padat &= ~mask;
  45. }
  46. static const unsigned short vccd_masks[2] = { _BW(10), _BW(6) };
  47. static void cfg_vccd(int no)
  48. {
  49. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  50. unsigned short mask;
  51. if ((unsigned int)no >= sizeof(vccd_masks)/sizeof(vccd_masks[0]))
  52. return;
  53. mask = vccd_masks[no];
  54. immap->im_ioport.iop_papar &= ~mask;
  55. immap->im_ioport.iop_paodr &= ~mask;
  56. immap->im_ioport.iop_padir |= mask;
  57. }
  58. static void set_vccd(int no, int what)
  59. {
  60. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  61. unsigned short mask;
  62. if ((unsigned int)no >= sizeof(vccd_masks)/sizeof(vccd_masks[0]))
  63. return;
  64. mask = vccd_masks[no];
  65. if (what)
  66. immap->im_ioport.iop_padat |= mask;
  67. else
  68. immap->im_ioport.iop_padat &= ~mask;
  69. }
  70. static const unsigned short oc_mask = _BW(8);
  71. static void cfg_oc(void)
  72. {
  73. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  74. unsigned short mask = oc_mask;
  75. immap->im_ioport.iop_pcdir &= ~mask;
  76. immap->im_ioport.iop_pcso &= ~mask;
  77. immap->im_ioport.iop_pcint &= ~mask;
  78. immap->im_ioport.iop_pcpar &= ~mask;
  79. }
  80. static int get_oc(void)
  81. {
  82. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  83. unsigned short mask = oc_mask;
  84. int what;
  85. what = !!(immap->im_ioport.iop_pcdat & mask);;
  86. return what;
  87. }
  88. static const unsigned short shdn_mask = _BW(12);
  89. static void cfg_shdn(void)
  90. {
  91. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  92. unsigned short mask;
  93. mask = shdn_mask;
  94. immap->im_ioport.iop_papar &= ~mask;
  95. immap->im_ioport.iop_paodr &= ~mask;
  96. immap->im_ioport.iop_padir |= mask;
  97. }
  98. static void set_shdn(int what)
  99. {
  100. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  101. unsigned short mask;
  102. mask = shdn_mask;
  103. if (what)
  104. immap->im_ioport.iop_padat |= mask;
  105. else
  106. immap->im_ioport.iop_padat &= ~mask;
  107. }
  108. static void cfg_ports (void)
  109. {
  110. cfg_vppd(0); cfg_vppd(1); /* VPPD0,VPPD1 VAVPP => Hi-Z */
  111. cfg_vccd(0); cfg_vccd(1); /* 3V and 5V off */
  112. cfg_shdn();
  113. cfg_oc();
  114. /*
  115. * Configure Port A for TPS2211 PC-Card Power-Interface Switch
  116. *
  117. * Switch off all voltages, assert shutdown
  118. */
  119. set_vppd(0, 1); set_vppd(1, 1);
  120. set_vccd(0, 0); set_vccd(1, 0);
  121. set_shdn(1);
  122. udelay(100000);
  123. }
  124. int pcmcia_hardware_enable(int slot)
  125. {
  126. volatile pcmconf8xx_t *pcmp;
  127. uint reg, pipr, mask;
  128. int i;
  129. debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  130. udelay(10000);
  131. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  132. /* Configure Ports for TPS2211A PC-Card Power-Interface Switch */
  133. cfg_ports ();
  134. /* clear interrupt state, and disable interrupts */
  135. pcmp->pcmc_pscr = PCMCIA_MASK(_slot_);
  136. pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_);
  137. /*
  138. * Disable interrupts, DMA, and PCMCIA buffers
  139. * (isolate the interface) and assert RESET signal
  140. */
  141. debug ("Disable PCMCIA buffers and assert RESET\n");
  142. reg = 0;
  143. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  144. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  145. PCMCIA_PGCRX(_slot_) = reg;
  146. udelay(500);
  147. /*
  148. * Make sure there is a card in the slot, then configure the interface.
  149. */
  150. udelay(10000);
  151. debug ("[%d] %s: PIPR(%p)=0x%x\n",
  152. __LINE__,__FUNCTION__,
  153. &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
  154. if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
  155. printf (" No Card found\n");
  156. return (1);
  157. }
  158. /*
  159. * Power On: Set VAVCC to 3.3V or 5V, set VAVPP to Hi-Z
  160. */
  161. mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
  162. pipr = pcmp->pcmc_pipr;
  163. debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
  164. pipr,
  165. (reg&PCMCIA_VS1(slot))?"n":"ff",
  166. (reg&PCMCIA_VS2(slot))?"n":"ff");
  167. if ((pipr & mask) == mask) {
  168. set_vppd(0, 1); set_vppd(1, 1); /* VAVPP => Hi-Z */
  169. set_vccd(0, 0); set_vccd(1, 1); /* 5V on, 3V off */
  170. puts (" 5.0V card found: ");
  171. } else {
  172. set_vppd(0, 1); set_vppd(1, 1); /* VAVPP => Hi-Z */
  173. set_vccd(0, 1); set_vccd(1, 0); /* 5V off, 3V on */
  174. puts (" 3.3V card found: ");
  175. }
  176. /* Wait 500 ms; use this to check for over-current */
  177. for (i=0; i<5000; ++i) {
  178. if (!get_oc()) {
  179. printf (" *** Overcurrent - Safety shutdown ***\n");
  180. set_vccd(0, 0); set_vccd(1, 0); /* VAVPP => Hi-Z */
  181. return (1);
  182. }
  183. udelay (100);
  184. }
  185. debug ("Enable PCMCIA buffers and stop RESET\n");
  186. reg = PCMCIA_PGCRX(_slot_);
  187. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  188. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  189. PCMCIA_PGCRX(_slot_) = reg;
  190. udelay(250000); /* some cards need >150 ms to come up :-( */
  191. debug ("# hardware_enable done\n");
  192. return (0);
  193. }
  194. #if defined(CONFIG_CMD_PCMCIA)
  195. int pcmcia_hardware_disable(int slot)
  196. {
  197. u_long reg;
  198. debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  199. /* Configure PCMCIA General Control Register */
  200. debug ("Disable PCMCIA buffers and assert RESET\n");
  201. reg = 0;
  202. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  203. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  204. PCMCIA_PGCRX(_slot_) = reg;
  205. /* All voltages off / Hi-Z */
  206. set_vppd(0, 1); set_vppd(1, 1);
  207. set_vccd(0, 1); set_vccd(1, 1);
  208. udelay(10000);
  209. return (0);
  210. }
  211. #endif
  212. int pcmcia_voltage_set(int slot, int vcc, int vpp)
  213. {
  214. volatile pcmconf8xx_t *pcmp;
  215. u_long reg;
  216. debug ("voltage_set: "
  217. PCMCIA_BOARD_MSG
  218. " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
  219. 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
  220. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  221. /*
  222. * Disable PCMCIA buffers (isolate the interface)
  223. * and assert RESET signal
  224. */
  225. debug ("Disable PCMCIA buffers and assert RESET\n");
  226. reg = PCMCIA_PGCRX(_slot_);
  227. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  228. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  229. PCMCIA_PGCRX(_slot_) = reg;
  230. udelay(500);
  231. /*
  232. * Configure Port C pins for
  233. * 5 Volts Enable and 3 Volts enable,
  234. * Turn all power pins to Hi-Z
  235. */
  236. debug ("PCMCIA power OFF\n");
  237. cfg_ports (); /* Enables switch, but all in Hi-Z */
  238. set_vppd(0, 1); set_vppd(1, 1);
  239. switch(vcc) {
  240. case 0:
  241. break; /* Switch off */
  242. case 33:
  243. set_vccd(0, 1); set_vccd(1, 0);
  244. break;
  245. case 50:
  246. set_vccd(0, 0); set_vccd(1, 1);
  247. break;
  248. default:
  249. goto done;
  250. }
  251. /* Checking supported voltages */
  252. debug ("PIPR: 0x%x --> %s\n",
  253. pcmp->pcmc_pipr,
  254. (pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
  255. done:
  256. debug ("Enable PCMCIA buffers and stop RESET\n");
  257. reg = PCMCIA_PGCRX(_slot_);
  258. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  259. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  260. PCMCIA_PGCRX(_slot_) = reg;
  261. udelay(500);
  262. debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
  263. slot+'A');
  264. return (0);
  265. }
  266. #endif /* CONFIG_PCMCIA */