sa1111_lubbock.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * linux/drivers/pcmcia/pxa2xx_lubbock.c
  3. *
  4. * Author: George Davis
  5. * Created: Jan 10, 2002
  6. * Copyright: MontaVista Software Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * Originally based upon linux/drivers/pcmcia/sa1100_neponset.c
  13. *
  14. * Lubbock PCMCIA specific routines.
  15. *
  16. */
  17. #include <linux/module.h>
  18. #include <linux/kernel.h>
  19. #include <linux/device.h>
  20. #include <linux/errno.h>
  21. #include <linux/init.h>
  22. #include <linux/delay.h>
  23. #include <mach/hardware.h>
  24. #include <asm/hardware/sa1111.h>
  25. #include <asm/mach-types.h>
  26. #include <mach/lubbock.h>
  27. #include "sa1111_generic.h"
  28. static int
  29. lubbock_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  30. const socket_state_t *state)
  31. {
  32. struct sa1111_pcmcia_socket *s = to_skt(skt);
  33. unsigned int pa_dwr_mask, pa_dwr_set, misc_mask, misc_set;
  34. int ret = 0;
  35. pa_dwr_mask = pa_dwr_set = misc_mask = misc_set = 0;
  36. /* Lubbock uses the Maxim MAX1602, with the following connections:
  37. *
  38. * Socket 0 (PCMCIA):
  39. * MAX1602 Lubbock Register
  40. * Pin Signal
  41. * ----- ------- ----------------------
  42. * A0VPP S0_PWR0 SA-1111 GPIO A<0>
  43. * A1VPP S0_PWR1 SA-1111 GPIO A<1>
  44. * A0VCC S0_PWR2 SA-1111 GPIO A<2>
  45. * A1VCC S0_PWR3 SA-1111 GPIO A<3>
  46. * VX VCC
  47. * VY +3.3V
  48. * 12IN +12V
  49. * CODE +3.3V Cirrus Code, CODE = High (VY)
  50. *
  51. * Socket 1 (CF):
  52. * MAX1602 Lubbock Register
  53. * Pin Signal
  54. * ----- ------- ----------------------
  55. * A0VPP GND VPP is not connected
  56. * A1VPP GND VPP is not connected
  57. * A0VCC S1_PWR0 MISC_WR<14>
  58. * A1VCC S1_PWR1 MISC_WR<15>
  59. * VX VCC
  60. * VY +3.3V
  61. * 12IN GND VPP is not connected
  62. * CODE +3.3V Cirrus Code, CODE = High (VY)
  63. *
  64. */
  65. again:
  66. switch (skt->nr) {
  67. case 0:
  68. pa_dwr_mask = GPIO_A0 | GPIO_A1 | GPIO_A2 | GPIO_A3;
  69. switch (state->Vcc) {
  70. case 0: /* Hi-Z */
  71. break;
  72. case 33: /* VY */
  73. pa_dwr_set |= GPIO_A3;
  74. break;
  75. case 50: /* VX */
  76. pa_dwr_set |= GPIO_A2;
  77. break;
  78. default:
  79. printk(KERN_ERR "%s(): unrecognized Vcc %u\n",
  80. __func__, state->Vcc);
  81. ret = -1;
  82. }
  83. switch (state->Vpp) {
  84. case 0: /* Hi-Z */
  85. break;
  86. case 120: /* 12IN */
  87. pa_dwr_set |= GPIO_A1;
  88. break;
  89. default: /* VCC */
  90. if (state->Vpp == state->Vcc)
  91. pa_dwr_set |= GPIO_A0;
  92. else {
  93. printk(KERN_ERR "%s(): unrecognized Vpp %u\n",
  94. __func__, state->Vpp);
  95. ret = -1;
  96. break;
  97. }
  98. }
  99. break;
  100. case 1:
  101. misc_mask = (1 << 15) | (1 << 14);
  102. switch (state->Vcc) {
  103. case 0: /* Hi-Z */
  104. break;
  105. case 33: /* VY */
  106. misc_set |= 1 << 15;
  107. break;
  108. case 50: /* VX */
  109. misc_set |= 1 << 14;
  110. break;
  111. default:
  112. printk(KERN_ERR "%s(): unrecognized Vcc %u\n",
  113. __func__, state->Vcc);
  114. ret = -1;
  115. break;
  116. }
  117. if (state->Vpp != state->Vcc && state->Vpp != 0) {
  118. printk(KERN_ERR "%s(): CF slot cannot support Vpp %u\n",
  119. __func__, state->Vpp);
  120. ret = -1;
  121. break;
  122. }
  123. break;
  124. default:
  125. ret = -1;
  126. }
  127. if (ret == 0)
  128. ret = sa1111_pcmcia_configure_socket(skt, state);
  129. if (ret == 0) {
  130. lubbock_set_misc_wr(misc_mask, misc_set);
  131. sa1111_set_io(s->dev, pa_dwr_mask, pa_dwr_set);
  132. }
  133. #if 1
  134. if (ret == 0 && state->Vcc == 33) {
  135. struct pcmcia_state new_state;
  136. /*
  137. * HACK ALERT:
  138. * We can't sense the voltage properly on Lubbock before
  139. * actually applying some power to the socket (catch 22).
  140. * Resense the socket Voltage Sense pins after applying
  141. * socket power.
  142. *
  143. * Note: It takes about 2.5ms for the MAX1602 VCC output
  144. * to rise.
  145. */
  146. mdelay(3);
  147. sa1111_pcmcia_socket_state(skt, &new_state);
  148. if (!new_state.vs_3v && !new_state.vs_Xv) {
  149. /*
  150. * Switch to 5V, Configure socket with 5V voltage
  151. */
  152. lubbock_set_misc_wr(misc_mask, 0);
  153. sa1111_set_io(s->dev, pa_dwr_mask, 0);
  154. /*
  155. * It takes about 100ms to turn off Vcc.
  156. */
  157. mdelay(100);
  158. /*
  159. * We need to hack around the const qualifier as
  160. * well to keep this ugly workaround localized and
  161. * not force it to the rest of the code. Barf bags
  162. * available in the seat pocket in front of you!
  163. */
  164. ((socket_state_t *)state)->Vcc = 50;
  165. ((socket_state_t *)state)->Vpp = 50;
  166. goto again;
  167. }
  168. }
  169. #endif
  170. return ret;
  171. }
  172. static struct pcmcia_low_level lubbock_pcmcia_ops = {
  173. .owner = THIS_MODULE,
  174. .configure_socket = lubbock_pcmcia_configure_socket,
  175. .first = 0,
  176. .nr = 2,
  177. };
  178. #include "pxa2xx_base.h"
  179. int pcmcia_lubbock_init(struct sa1111_dev *sadev)
  180. {
  181. int ret = -ENODEV;
  182. if (machine_is_lubbock()) {
  183. /*
  184. * Set GPIO_A<3:0> to be outputs for the MAX1600,
  185. * and switch to standby mode.
  186. */
  187. sa1111_set_io_dir(sadev, GPIO_A0|GPIO_A1|GPIO_A2|GPIO_A3, 0, 0);
  188. sa1111_set_io(sadev, GPIO_A0|GPIO_A1|GPIO_A2|GPIO_A3, 0);
  189. sa1111_set_sleep_io(sadev, GPIO_A0|GPIO_A1|GPIO_A2|GPIO_A3, 0);
  190. /* Set CF Socket 1 power to standby mode. */
  191. lubbock_set_misc_wr((1 << 15) | (1 << 14), 0);
  192. pxa2xx_drv_pcmcia_ops(&lubbock_pcmcia_ops);
  193. pxa2xx_configure_sockets(&sadev->dev);
  194. ret = sa1111_pcmcia_add(sadev, &lubbock_pcmcia_ops,
  195. pxa2xx_drv_pcmcia_add_one);
  196. }
  197. return ret;
  198. }
  199. MODULE_LICENSE("GPL");