pcmcia.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #include <common.h>
  2. #include <mpc8xx.h>
  3. #include <pcmcia.h>
  4. #include <i2c.h>
  5. #undef CONFIG_PCMCIA
  6. #if defined(CONFIG_CMD_PCMCIA)
  7. #define CONFIG_PCMCIA
  8. #endif
  9. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
  10. #define CONFIG_PCMCIA
  11. #endif
  12. #ifdef CONFIG_PCMCIA
  13. #define PCMCIA_BOARD_MSG "LWMON"
  14. /* #define's for MAX1604 Power Switch */
  15. #define MAX1604_OP_SUS 0x80
  16. #define MAX1604_VCCBON 0x40
  17. #define MAX1604_VCC_35 0x20
  18. #define MAX1604_VCCBHIZ 0x10
  19. #define MAX1604_VPPBON 0x08
  20. #define MAX1604_VPPBPBPGM 0x04
  21. #define MAX1604_VPPBHIZ 0x02
  22. /* reserved 0x01 */
  23. int pcmcia_hardware_enable(int slot)
  24. {
  25. volatile immap_t *immap;
  26. volatile cpm8xx_t *cp;
  27. volatile pcmconf8xx_t *pcmp;
  28. volatile sysconf8xx_t *sysp;
  29. uint reg, mask;
  30. uchar val;
  31. debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  32. /* Switch on PCMCIA port in PIC register 0x60 */
  33. reg = pic_read (0x60);
  34. debug ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg);
  35. reg &= ~0x10;
  36. /* reg |= 0x08; Vpp not needed */
  37. pic_write (0x60, reg);
  38. #ifdef DEBUG
  39. reg = pic_read (0x60);
  40. printf ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg);
  41. #endif
  42. udelay(10000);
  43. immap = (immap_t *)CONFIG_SYS_IMMR;
  44. sysp = (sysconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_siu_conf));
  45. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  46. cp = (cpm8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_cpm));
  47. /*
  48. * Configure SIUMCR to enable PCMCIA port B
  49. * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
  50. */
  51. sysp->sc_siumcr &= ~SIUMCR_DBGC11; /* set DBGC to 00 */
  52. /* clear interrupt state, and disable interrupts */
  53. pcmp->pcmc_pscr = PCMCIA_MASK(_slot_);
  54. pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_);
  55. /*
  56. * Disable interrupts, DMA, and PCMCIA buffers
  57. * (isolate the interface) and assert RESET signal
  58. */
  59. debug ("Disable PCMCIA buffers and assert RESET\n");
  60. reg = 0;
  61. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  62. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  63. PCMCIA_PGCRX(_slot_) = reg;
  64. udelay(500);
  65. /*
  66. * Make sure there is a card in the slot, then configure the interface.
  67. */
  68. udelay(10000);
  69. debug ("[%d] %s: PIPR(%p)=0x%x\n",
  70. __LINE__,__FUNCTION__,
  71. &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
  72. if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
  73. printf (" No Card found\n");
  74. return (1);
  75. }
  76. /*
  77. * Power On.
  78. */
  79. mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
  80. reg = pcmp->pcmc_pipr;
  81. debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
  82. reg,
  83. (reg&PCMCIA_VS1(slot))?"n":"ff",
  84. (reg&PCMCIA_VS2(slot))?"n":"ff");
  85. if ((reg & mask) == mask) {
  86. val = 0; /* VCCB3/5 = 0 ==> use Vx = 5.0 V */
  87. puts (" 5.0V card found: ");
  88. } else {
  89. val = MAX1604_VCC_35; /* VCCB3/5 = 1 ==> use Vy = 3.3 V */
  90. puts (" 3.3V card found: ");
  91. }
  92. /* switch VCC on */
  93. val |= MAX1604_OP_SUS | MAX1604_VCCBON;
  94. i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  95. i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
  96. udelay(500000);
  97. debug ("Enable PCMCIA buffers and stop RESET\n");
  98. reg = PCMCIA_PGCRX(_slot_);
  99. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  100. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  101. PCMCIA_PGCRX(_slot_) = reg;
  102. udelay(250000); /* some cards need >150 ms to come up :-( */
  103. debug ("# hardware_enable done\n");
  104. return (0);
  105. }
  106. #if defined(CONFIG_CMD_PCMCIA)
  107. int pcmcia_hardware_disable(int slot)
  108. {
  109. volatile immap_t *immap;
  110. volatile pcmconf8xx_t *pcmp;
  111. u_long reg;
  112. uchar val;
  113. debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  114. immap = (immap_t *)CONFIG_SYS_IMMR;
  115. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  116. /* remove all power, put output in high impedance state */
  117. val = MAX1604_VCCBHIZ | MAX1604_VPPBHIZ;
  118. i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  119. i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
  120. /* Configure PCMCIA General Control Register */
  121. debug ("Disable PCMCIA buffers and assert RESET\n");
  122. reg = 0;
  123. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  124. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  125. PCMCIA_PGCRX(_slot_) = reg;
  126. /* Switch off PCMCIA port in PIC register 0x60 */
  127. reg = pic_read (0x60);
  128. debug ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg);
  129. reg |= 0x10;
  130. reg &= ~0x08;
  131. pic_write (0x60, reg);
  132. #ifdef DEBUG
  133. reg = pic_read (0x60);
  134. printf ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg);
  135. #endif
  136. udelay(10000);
  137. return (0);
  138. }
  139. #endif
  140. int pcmcia_voltage_set(int slot, int vcc, int vpp)
  141. {
  142. volatile immap_t *immap;
  143. volatile pcmconf8xx_t *pcmp;
  144. u_long reg;
  145. uchar val;
  146. debug ("voltage_set: "
  147. PCMCIA_BOARD_MSG
  148. " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
  149. 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
  150. immap = (immap_t *)CONFIG_SYS_IMMR;
  151. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  152. /*
  153. * Disable PCMCIA buffers (isolate the interface)
  154. * and assert RESET signal
  155. */
  156. debug ("Disable PCMCIA buffers and assert RESET\n");
  157. reg = PCMCIA_PGCRX(_slot_);
  158. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  159. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  160. PCMCIA_PGCRX(_slot_) = reg;
  161. udelay(500);
  162. /*
  163. * Turn off all power (switch to high impedance)
  164. */
  165. debug ("PCMCIA power OFF\n");
  166. val = MAX1604_VCCBHIZ | MAX1604_VPPBHIZ;
  167. i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  168. i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
  169. val = 0;
  170. switch(vcc) {
  171. case 0: break;
  172. case 33: val = MAX1604_VCC_35; break;
  173. case 50: break;
  174. default: goto done;
  175. }
  176. /* Checking supported voltages */
  177. debug ("PIPR: 0x%x --> %s\n",
  178. pcmp->pcmc_pipr,
  179. (pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
  180. i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
  181. if (val) {
  182. debug ("PCMCIA powered at %sV\n",
  183. (val & MAX1604_VCC_35) ? "3.3" : "5.0");
  184. } else {
  185. debug ("PCMCIA powered down\n");
  186. }
  187. done:
  188. debug ("Enable PCMCIA buffers and stop RESET\n");
  189. reg = PCMCIA_PGCRX(_slot_);
  190. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  191. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  192. PCMCIA_PGCRX(_slot_) = reg;
  193. udelay(500);
  194. debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
  195. slot+'A');
  196. return (0);
  197. }
  198. #endif /* CONFIG_PCMCIA */