pcmcia.c 5.7 KB

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