pcmcia.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. volatile immap_t *immap;
  111. volatile cpm8xx_t *cp;
  112. immap = (immap_t *)CONFIG_SYS_IMMR;
  113. cp = (cpm8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_cpm));
  114. cfg_vppd(0); cfg_vppd(1); /* VPPD0,VPPD1 VAVPP => Hi-Z */
  115. cfg_vccd(0); cfg_vccd(1); /* 3V and 5V off */
  116. cfg_shdn();
  117. cfg_oc();
  118. /*
  119. * Configure Port A for TPS2211 PC-Card Power-Interface Switch
  120. *
  121. * Switch off all voltages, assert shutdown
  122. */
  123. set_vppd(0, 1); set_vppd(1, 1);
  124. set_vccd(0, 0); set_vccd(1, 0);
  125. set_shdn(1);
  126. udelay(100000);
  127. }
  128. int pcmcia_hardware_enable(int slot)
  129. {
  130. volatile immap_t *immap;
  131. volatile cpm8xx_t *cp;
  132. volatile pcmconf8xx_t *pcmp;
  133. volatile sysconf8xx_t *sysp;
  134. uint reg, pipr, mask;
  135. int i;
  136. debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  137. udelay(10000);
  138. immap = (immap_t *)CONFIG_SYS_IMMR;
  139. sysp = (sysconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_siu_conf));
  140. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  141. cp = (cpm8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_cpm));
  142. /* Configure Ports for TPS2211A PC-Card Power-Interface Switch */
  143. cfg_ports ();
  144. /* clear interrupt state, and disable interrupts */
  145. pcmp->pcmc_pscr = PCMCIA_MASK(_slot_);
  146. pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_);
  147. /*
  148. * Disable interrupts, DMA, and PCMCIA buffers
  149. * (isolate the interface) and assert RESET signal
  150. */
  151. debug ("Disable PCMCIA buffers and assert RESET\n");
  152. reg = 0;
  153. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  154. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  155. PCMCIA_PGCRX(_slot_) = reg;
  156. udelay(500);
  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",
  162. __LINE__,__FUNCTION__,
  163. &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
  164. if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
  165. printf (" No Card found\n");
  166. return (1);
  167. }
  168. /*
  169. * Power On: Set VAVCC to 3.3V or 5V, set VAVPP to Hi-Z
  170. */
  171. mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
  172. pipr = pcmp->pcmc_pipr;
  173. debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
  174. pipr,
  175. (reg&PCMCIA_VS1(slot))?"n":"ff",
  176. (reg&PCMCIA_VS2(slot))?"n":"ff");
  177. if ((pipr & mask) == mask) {
  178. set_vppd(0, 1); set_vppd(1, 1); /* VAVPP => Hi-Z */
  179. set_vccd(0, 0); set_vccd(1, 1); /* 5V on, 3V off */
  180. puts (" 5.0V card found: ");
  181. } else {
  182. set_vppd(0, 1); set_vppd(1, 1); /* VAVPP => Hi-Z */
  183. set_vccd(0, 1); set_vccd(1, 0); /* 5V off, 3V on */
  184. puts (" 3.3V card found: ");
  185. }
  186. /* Wait 500 ms; use this to check for over-current */
  187. for (i=0; i<5000; ++i) {
  188. if (!get_oc()) {
  189. printf (" *** Overcurrent - Safety shutdown ***\n");
  190. set_vccd(0, 0); set_vccd(1, 0); /* VAVPP => Hi-Z */
  191. return (1);
  192. }
  193. udelay (100);
  194. }
  195. debug ("Enable PCMCIA buffers and stop RESET\n");
  196. reg = PCMCIA_PGCRX(_slot_);
  197. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  198. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  199. PCMCIA_PGCRX(_slot_) = reg;
  200. udelay(250000); /* some cards need >150 ms to come up :-( */
  201. debug ("# hardware_enable done\n");
  202. return (0);
  203. }
  204. #if defined(CONFIG_CMD_PCMCIA)
  205. int pcmcia_hardware_disable(int slot)
  206. {
  207. volatile immap_t *immap;
  208. volatile pcmconf8xx_t *pcmp;
  209. u_long reg;
  210. debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  211. immap = (immap_t *)CONFIG_SYS_IMMR;
  212. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  213. /* Configure PCMCIA General Control Register */
  214. debug ("Disable PCMCIA buffers and assert RESET\n");
  215. reg = 0;
  216. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  217. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  218. PCMCIA_PGCRX(_slot_) = reg;
  219. /* All voltages off / Hi-Z */
  220. set_vppd(0, 1); set_vppd(1, 1);
  221. set_vccd(0, 1); set_vccd(1, 1);
  222. udelay(10000);
  223. return (0);
  224. }
  225. #endif
  226. int pcmcia_voltage_set(int slot, int vcc, int vpp)
  227. {
  228. volatile immap_t *immap;
  229. volatile cpm8xx_t *cp;
  230. volatile pcmconf8xx_t *pcmp;
  231. u_long reg;
  232. ushort sreg;
  233. debug ("voltage_set: "
  234. PCMCIA_BOARD_MSG
  235. " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
  236. 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
  237. immap = (immap_t *)CONFIG_SYS_IMMR;
  238. cp = (cpm8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_cpm));
  239. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  240. /*
  241. * Disable PCMCIA buffers (isolate the interface)
  242. * and assert RESET signal
  243. */
  244. debug ("Disable PCMCIA buffers and assert RESET\n");
  245. reg = PCMCIA_PGCRX(_slot_);
  246. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  247. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  248. PCMCIA_PGCRX(_slot_) = reg;
  249. udelay(500);
  250. /*
  251. * Configure Port C pins for
  252. * 5 Volts Enable and 3 Volts enable,
  253. * Turn all power pins to Hi-Z
  254. */
  255. debug ("PCMCIA power OFF\n");
  256. cfg_ports (); /* Enables switch, but all in Hi-Z */
  257. sreg = immap->im_ioport.iop_pcdat;
  258. set_vppd(0, 1); set_vppd(1, 1);
  259. switch(vcc) {
  260. case 0:
  261. break; /* Switch off */
  262. case 33:
  263. set_vccd(0, 1); set_vccd(1, 0);
  264. break;
  265. case 50:
  266. set_vccd(0, 0); set_vccd(1, 1);
  267. break;
  268. default:
  269. goto done;
  270. }
  271. /* Checking supported voltages */
  272. debug ("PIPR: 0x%x --> %s\n",
  273. pcmp->pcmc_pipr,
  274. (pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
  275. done:
  276. debug ("Enable PCMCIA buffers and stop RESET\n");
  277. reg = PCMCIA_PGCRX(_slot_);
  278. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  279. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  280. PCMCIA_PGCRX(_slot_) = reg;
  281. udelay(500);
  282. debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
  283. slot+'A');
  284. return (0);
  285. }
  286. #endif /* CONFIG_PCMCIA */