pcmcia.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. #define PCMCIA_BOARD_MSG "R360MPI"
  13. int pcmcia_hardware_enable(int slot)
  14. {
  15. volatile immap_t *immap;
  16. volatile cpm8xx_t *cp;
  17. volatile pcmconf8xx_t *pcmp;
  18. volatile sysconf8xx_t *sysp;
  19. uint reg, mask;
  20. debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  21. udelay(10000);
  22. immap = (immap_t *)CONFIG_SYS_IMMR;
  23. sysp = (sysconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_siu_conf));
  24. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  25. cp = (cpm8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_cpm));
  26. /*
  27. * Configure SIUMCR to enable PCMCIA port B
  28. * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
  29. */
  30. sysp->sc_siumcr &= ~SIUMCR_DBGC11; /* set DBGC to 00 */
  31. /* clear interrupt state, and disable interrupts */
  32. pcmp->pcmc_pscr = PCMCIA_MASK(_slot_);
  33. pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_);
  34. /*
  35. * Disable interrupts, DMA, and PCMCIA buffers
  36. * (isolate the interface) and assert RESET signal
  37. */
  38. debug ("Disable PCMCIA buffers and assert RESET\n");
  39. reg = 0;
  40. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  41. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  42. PCMCIA_PGCRX(_slot_) = reg;
  43. udelay(500);
  44. /*
  45. * Configure Ports A, B & C pins for
  46. * 5 Volts Enable and 3 Volts enable
  47. */
  48. immap->im_ioport.iop_pcpar &= ~(0x0400);
  49. immap->im_ioport.iop_pcso &= ~(0x0400);/*
  50. immap->im_ioport.iop_pcdir |= 0x0400;*/
  51. immap->im_ioport.iop_papar &= ~(0x0200);/*
  52. immap->im_ioport.iop_padir |= 0x0200;*/
  53. #if 0
  54. immap->im_ioport.iop_pbpar &= ~(0xC000);
  55. immap->im_ioport.iop_pbdir &= ~(0xC000);
  56. #endif
  57. /* remove all power */
  58. immap->im_ioport.iop_pcdat |= 0x0400;
  59. immap->im_ioport.iop_padat |= 0x0200;
  60. /*
  61. * Make sure there is a card in the slot, then configure the interface.
  62. */
  63. udelay(10000);
  64. debug ("[%d] %s: PIPR(%p)=0x%x\n",
  65. __LINE__,__FUNCTION__,
  66. &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
  67. if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
  68. printf (" No Card found\n");
  69. return (1);
  70. }
  71. /*
  72. * Power On.
  73. */
  74. mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
  75. reg = pcmp->pcmc_pipr;
  76. debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
  77. reg,
  78. (reg&PCMCIA_VS1(slot))?"n":"ff",
  79. (reg&PCMCIA_VS2(slot))?"n":"ff");
  80. if ((reg & mask) == mask) {
  81. immap->im_ioport.iop_pcdat &= ~(0x4000);
  82. puts (" 5.0V card found: ");
  83. } else {
  84. immap->im_ioport.iop_padat &= ~(0x0002);
  85. puts (" 3.3V card found: ");
  86. }
  87. immap->im_ioport.iop_pcdir |= 0x0400;
  88. immap->im_ioport.iop_padir |= 0x0200;
  89. #if 0
  90. /* VCC switch error flag, PCMCIA slot INPACK_ pin */
  91. cp->cp_pbdir &= ~(0x0020 | 0x0010);
  92. cp->cp_pbpar &= ~(0x0020 | 0x0010);
  93. udelay(500000);
  94. #endif
  95. debug ("Enable PCMCIA buffers and stop RESET\n");
  96. reg = PCMCIA_PGCRX(_slot_);
  97. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  98. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  99. PCMCIA_PGCRX(_slot_) = reg;
  100. udelay(250000); /* some cards need >150 ms to come up :-( */
  101. debug ("# hardware_enable done\n");
  102. return (0);
  103. }
  104. #if defined(CONFIG_CMD_PCMCIA)
  105. int pcmcia_hardware_disable(int slot)
  106. {
  107. volatile immap_t *immap;
  108. volatile pcmconf8xx_t *pcmp;
  109. u_long reg;
  110. debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  111. immap = (immap_t *)CONFIG_SYS_IMMR;
  112. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  113. /* remove all power */
  114. immap->im_ioport.iop_pcdat |= 0x0400;
  115. immap->im_ioport.iop_padat |= 0x0200;
  116. /* Configure PCMCIA General Control Register */
  117. debug ("Disable PCMCIA buffers and assert RESET\n");
  118. reg = 0;
  119. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  120. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  121. PCMCIA_PGCRX(_slot_) = reg;
  122. udelay(10000);
  123. return (0);
  124. }
  125. #endif
  126. int pcmcia_voltage_set(int slot, int vcc, int vpp)
  127. {
  128. volatile immap_t *immap;
  129. volatile pcmconf8xx_t *pcmp;
  130. u_long reg;
  131. debug ("voltage_set: "
  132. PCMCIA_BOARD_MSG
  133. " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
  134. 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
  135. immap = (immap_t *)CONFIG_SYS_IMMR;
  136. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  137. /*
  138. * Disable PCMCIA buffers (isolate the interface)
  139. * and assert RESET signal
  140. */
  141. debug ("Disable PCMCIA buffers and assert RESET\n");
  142. reg = PCMCIA_PGCRX(_slot_);
  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. * Configure Ports A & C pins for
  149. * 5 Volts Enable and 3 Volts enable,
  150. * Turn off all power
  151. */
  152. debug ("PCMCIA power OFF\n");
  153. immap->im_ioport.iop_pcpar &= ~(0x0400);
  154. immap->im_ioport.iop_pcso &= ~(0x0400);/*
  155. immap->im_ioport.iop_pcdir |= 0x0400;*/
  156. immap->im_ioport.iop_papar &= ~(0x0200);/*
  157. immap->im_ioport.iop_padir |= 0x0200;*/
  158. immap->im_ioport.iop_pcdat |= 0x0400;
  159. immap->im_ioport.iop_padat |= 0x0200;
  160. reg = 0;
  161. switch(vcc) {
  162. case 0: break;
  163. case 33: reg |= 0x0200; break;
  164. case 50: reg |= 0x0400; break;
  165. default: goto done;
  166. }
  167. /* Checking supported voltages */
  168. debug ("PIPR: 0x%x --> %s\n",
  169. pcmp->pcmc_pipr,
  170. (pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
  171. if (reg & 0x0200)
  172. immap->im_ioport.iop_pcdat &= !reg;
  173. if (reg & 0x0400)
  174. immap->im_ioport.iop_padat &= !reg;
  175. immap->im_ioport.iop_pcdir |= 0x0200;
  176. immap->im_ioport.iop_padir |= 0x0400;
  177. if (reg) {
  178. debug ("PCMCIA powered at %sV\n",
  179. (reg&0x0400) ? "5.0" : "3.3");
  180. } else {
  181. debug ("PCMCIA powered down\n");
  182. }
  183. done:
  184. debug ("Enable PCMCIA buffers and stop RESET\n");
  185. reg = PCMCIA_PGCRX(_slot_);
  186. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  187. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  188. PCMCIA_PGCRX(_slot_) = reg;
  189. udelay(500);
  190. debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
  191. slot+'A');
  192. return (0);
  193. }
  194. #endif /* CCONFIG_PCMCIA */