pcmcia.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 pcmconf8xx_t *pcmp;
  26. volatile sysconf8xx_t *sysp;
  27. uint reg, mask;
  28. uchar val;
  29. debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  30. /* Switch on PCMCIA port in PIC register 0x60 */
  31. reg = pic_read (0x60);
  32. debug ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg);
  33. reg &= ~0x10;
  34. /* reg |= 0x08; Vpp not needed */
  35. pic_write (0x60, reg);
  36. #ifdef DEBUG
  37. reg = pic_read (0x60);
  38. printf ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg);
  39. #endif
  40. udelay(10000);
  41. sysp = (sysconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_siu_conf));
  42. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  43. /*
  44. * Configure SIUMCR to enable PCMCIA port B
  45. * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
  46. */
  47. sysp->sc_siumcr &= ~SIUMCR_DBGC11; /* set DBGC to 00 */
  48. /* clear interrupt state, and disable interrupts */
  49. pcmp->pcmc_pscr = PCMCIA_MASK(_slot_);
  50. pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_);
  51. /*
  52. * Disable interrupts, DMA, and PCMCIA buffers
  53. * (isolate the interface) and assert RESET signal
  54. */
  55. debug ("Disable PCMCIA buffers and assert RESET\n");
  56. reg = 0;
  57. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  58. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  59. PCMCIA_PGCRX(_slot_) = reg;
  60. udelay(500);
  61. /*
  62. * Make sure there is a card in the slot, then configure the interface.
  63. */
  64. udelay(10000);
  65. debug ("[%d] %s: PIPR(%p)=0x%x\n",
  66. __LINE__,__FUNCTION__,
  67. &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
  68. if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
  69. printf (" No Card found\n");
  70. return (1);
  71. }
  72. /*
  73. * Power On.
  74. */
  75. mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
  76. reg = pcmp->pcmc_pipr;
  77. debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
  78. reg,
  79. (reg&PCMCIA_VS1(slot))?"n":"ff",
  80. (reg&PCMCIA_VS2(slot))?"n":"ff");
  81. if ((reg & mask) == mask) {
  82. val = 0; /* VCCB3/5 = 0 ==> use Vx = 5.0 V */
  83. puts (" 5.0V card found: ");
  84. } else {
  85. val = MAX1604_VCC_35; /* VCCB3/5 = 1 ==> use Vy = 3.3 V */
  86. puts (" 3.3V card found: ");
  87. }
  88. /* switch VCC on */
  89. val |= MAX1604_OP_SUS | MAX1604_VCCBON;
  90. i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  91. i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
  92. udelay(500000);
  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. volatile pcmconf8xx_t *pcmp;
  107. u_long reg;
  108. uchar val;
  109. debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
  110. immap = (immap_t *)CONFIG_SYS_IMMR;
  111. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  112. /* remove all power, put output in high impedance state */
  113. val = MAX1604_VCCBHIZ | MAX1604_VPPBHIZ;
  114. i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  115. i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
  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. /* Switch off PCMCIA port in PIC register 0x60 */
  123. reg = pic_read (0x60);
  124. debug ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg);
  125. reg |= 0x10;
  126. reg &= ~0x08;
  127. pic_write (0x60, reg);
  128. #ifdef DEBUG
  129. reg = pic_read (0x60);
  130. printf ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg);
  131. #endif
  132. udelay(10000);
  133. return (0);
  134. }
  135. #endif
  136. int pcmcia_voltage_set(int slot, int vcc, int vpp)
  137. {
  138. volatile pcmconf8xx_t *pcmp;
  139. u_long reg;
  140. uchar val;
  141. debug ("voltage_set: "
  142. PCMCIA_BOARD_MSG
  143. " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
  144. 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
  145. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  146. /*
  147. * Disable PCMCIA buffers (isolate the interface)
  148. * and assert RESET signal
  149. */
  150. debug ("Disable PCMCIA buffers and assert RESET\n");
  151. reg = PCMCIA_PGCRX(_slot_);
  152. reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
  153. reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
  154. PCMCIA_PGCRX(_slot_) = reg;
  155. udelay(500);
  156. /*
  157. * Turn off all power (switch to high impedance)
  158. */
  159. debug ("PCMCIA power OFF\n");
  160. val = MAX1604_VCCBHIZ | MAX1604_VPPBHIZ;
  161. i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  162. i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
  163. val = 0;
  164. switch(vcc) {
  165. case 0: break;
  166. case 33: val = MAX1604_VCC_35; break;
  167. case 50: break;
  168. default: goto done;
  169. }
  170. /* Checking supported voltages */
  171. debug ("PIPR: 0x%x --> %s\n",
  172. pcmp->pcmc_pipr,
  173. (pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
  174. i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
  175. if (val) {
  176. debug ("PCMCIA powered at %sV\n",
  177. (val & MAX1604_VCC_35) ? "3.3" : "5.0");
  178. } else {
  179. debug ("PCMCIA powered down\n");
  180. }
  181. done:
  182. debug ("Enable PCMCIA buffers and stop RESET\n");
  183. reg = PCMCIA_PGCRX(_slot_);
  184. reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
  185. reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
  186. PCMCIA_PGCRX(_slot_) = reg;
  187. udelay(500);
  188. debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
  189. slot+'A');
  190. return (0);
  191. }
  192. #endif /* CONFIG_PCMCIA */