pxa2xx_lubbock.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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/sched.h>
  20. #include <linux/device.h>
  21. #include <linux/errno.h>
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <asm/hardware.h>
  25. #include <asm/hardware/sa1111.h>
  26. #include <asm/mach-types.h>
  27. #include <asm/arch/pxa-regs.h>
  28. #include <asm/arch/lubbock.h>
  29. #include "sa1111_generic.h"
  30. static int
  31. lubbock_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  32. {
  33. /*
  34. * Setup default state of GPIO outputs
  35. * before we enable them as outputs.
  36. */
  37. GPSR(GPIO48_nPOE) =
  38. GPIO_bit(GPIO48_nPOE) |
  39. GPIO_bit(GPIO49_nPWE) |
  40. GPIO_bit(GPIO50_nPIOR) |
  41. GPIO_bit(GPIO51_nPIOW) |
  42. GPIO_bit(GPIO52_nPCE_1) |
  43. GPIO_bit(GPIO53_nPCE_2);
  44. pxa_gpio_mode(GPIO48_nPOE_MD);
  45. pxa_gpio_mode(GPIO49_nPWE_MD);
  46. pxa_gpio_mode(GPIO50_nPIOR_MD);
  47. pxa_gpio_mode(GPIO51_nPIOW_MD);
  48. pxa_gpio_mode(GPIO52_nPCE_1_MD);
  49. pxa_gpio_mode(GPIO53_nPCE_2_MD);
  50. pxa_gpio_mode(GPIO54_pSKTSEL_MD);
  51. pxa_gpio_mode(GPIO55_nPREG_MD);
  52. pxa_gpio_mode(GPIO56_nPWAIT_MD);
  53. pxa_gpio_mode(GPIO57_nIOIS16_MD);
  54. return sa1111_pcmcia_hw_init(skt);
  55. }
  56. static int
  57. lubbock_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  58. const socket_state_t *state)
  59. {
  60. unsigned int pa_dwr_mask, pa_dwr_set, misc_mask, misc_set;
  61. int ret = 0;
  62. pa_dwr_mask = pa_dwr_set = misc_mask = misc_set = 0;
  63. /* Lubbock uses the Maxim MAX1602, with the following connections:
  64. *
  65. * Socket 0 (PCMCIA):
  66. * MAX1602 Lubbock Register
  67. * Pin Signal
  68. * ----- ------- ----------------------
  69. * A0VPP S0_PWR0 SA-1111 GPIO A<0>
  70. * A1VPP S0_PWR1 SA-1111 GPIO A<1>
  71. * A0VCC S0_PWR2 SA-1111 GPIO A<2>
  72. * A1VCC S0_PWR3 SA-1111 GPIO A<3>
  73. * VX VCC
  74. * VY +3.3V
  75. * 12IN +12V
  76. * CODE +3.3V Cirrus Code, CODE = High (VY)
  77. *
  78. * Socket 1 (CF):
  79. * MAX1602 Lubbock Register
  80. * Pin Signal
  81. * ----- ------- ----------------------
  82. * A0VPP GND VPP is not connected
  83. * A1VPP GND VPP is not connected
  84. * A0VCC S1_PWR0 MISC_WR<14>
  85. * A1VCC S1_PWR1 MISC_WR<15>
  86. * VX VCC
  87. * VY +3.3V
  88. * 12IN GND VPP is not connected
  89. * CODE +3.3V Cirrus Code, CODE = High (VY)
  90. *
  91. */
  92. again:
  93. switch (skt->nr) {
  94. case 0:
  95. pa_dwr_mask = GPIO_A0 | GPIO_A1 | GPIO_A2 | GPIO_A3;
  96. switch (state->Vcc) {
  97. case 0: /* Hi-Z */
  98. break;
  99. case 33: /* VY */
  100. pa_dwr_set |= GPIO_A3;
  101. break;
  102. case 50: /* VX */
  103. pa_dwr_set |= GPIO_A2;
  104. break;
  105. default:
  106. printk(KERN_ERR "%s(): unrecognized Vcc %u\n",
  107. __FUNCTION__, state->Vcc);
  108. ret = -1;
  109. }
  110. switch (state->Vpp) {
  111. case 0: /* Hi-Z */
  112. break;
  113. case 120: /* 12IN */
  114. pa_dwr_set |= GPIO_A1;
  115. break;
  116. default: /* VCC */
  117. if (state->Vpp == state->Vcc)
  118. pa_dwr_set |= GPIO_A0;
  119. else {
  120. printk(KERN_ERR "%s(): unrecognized Vpp %u\n",
  121. __FUNCTION__, state->Vpp);
  122. ret = -1;
  123. break;
  124. }
  125. }
  126. break;
  127. case 1:
  128. misc_mask = (1 << 15) | (1 << 14);
  129. switch (state->Vcc) {
  130. case 0: /* Hi-Z */
  131. break;
  132. case 33: /* VY */
  133. misc_set |= 1 << 15;
  134. break;
  135. case 50: /* VX */
  136. misc_set |= 1 << 14;
  137. break;
  138. default:
  139. printk(KERN_ERR "%s(): unrecognized Vcc %u\n",
  140. __FUNCTION__, state->Vcc);
  141. ret = -1;
  142. break;
  143. }
  144. if (state->Vpp != state->Vcc && state->Vpp != 0) {
  145. printk(KERN_ERR "%s(): CF slot cannot support Vpp %u\n",
  146. __FUNCTION__, state->Vpp);
  147. ret = -1;
  148. break;
  149. }
  150. break;
  151. default:
  152. ret = -1;
  153. }
  154. if (ret == 0)
  155. ret = sa1111_pcmcia_configure_socket(skt, state);
  156. if (ret == 0) {
  157. lubbock_set_misc_wr(misc_mask, misc_set);
  158. sa1111_set_io(SA1111_DEV(skt->dev), pa_dwr_mask, pa_dwr_set);
  159. }
  160. #if 1
  161. if (ret == 0 && state->Vcc == 33) {
  162. struct pcmcia_state new_state;
  163. /*
  164. * HACK ALERT:
  165. * We can't sense the voltage properly on Lubbock before
  166. * actually applying some power to the socket (catch 22).
  167. * Resense the socket Voltage Sense pins after applying
  168. * socket power.
  169. *
  170. * Note: It takes about 2.5ms for the MAX1602 VCC output
  171. * to rise.
  172. */
  173. mdelay(3);
  174. sa1111_pcmcia_socket_state(skt, &new_state);
  175. if (!new_state.vs_3v && !new_state.vs_Xv) {
  176. /*
  177. * Switch to 5V, Configure socket with 5V voltage
  178. */
  179. lubbock_set_misc_wr(misc_mask, 0);
  180. sa1111_set_io(SA1111_DEV(skt->dev), pa_dwr_mask, 0);
  181. /*
  182. * It takes about 100ms to turn off Vcc.
  183. */
  184. mdelay(100);
  185. /*
  186. * We need to hack around the const qualifier as
  187. * well to keep this ugly workaround localized and
  188. * not force it to the rest of the code. Barf bags
  189. * avaliable in the seat pocket in front of you!
  190. */
  191. ((socket_state_t *)state)->Vcc = 50;
  192. ((socket_state_t *)state)->Vpp = 50;
  193. goto again;
  194. }
  195. }
  196. #endif
  197. return ret;
  198. }
  199. static struct pcmcia_low_level lubbock_pcmcia_ops = {
  200. .owner = THIS_MODULE,
  201. .hw_init = lubbock_pcmcia_hw_init,
  202. .hw_shutdown = sa1111_pcmcia_hw_shutdown,
  203. .socket_state = sa1111_pcmcia_socket_state,
  204. .configure_socket = lubbock_pcmcia_configure_socket,
  205. .socket_init = sa1111_pcmcia_socket_init,
  206. .socket_suspend = sa1111_pcmcia_socket_suspend,
  207. .first = 0,
  208. .nr = 2,
  209. };
  210. #include "pxa2xx_base.h"
  211. int __init pcmcia_lubbock_init(struct sa1111_dev *sadev)
  212. {
  213. int ret = -ENODEV;
  214. if (machine_is_lubbock()) {
  215. /*
  216. * Set GPIO_A<3:0> to be outputs for the MAX1600,
  217. * and switch to standby mode.
  218. */
  219. sa1111_set_io_dir(sadev, GPIO_A0|GPIO_A1|GPIO_A2|GPIO_A3, 0, 0);
  220. sa1111_set_io(sadev, GPIO_A0|GPIO_A1|GPIO_A2|GPIO_A3, 0);
  221. sa1111_set_sleep_io(sadev, GPIO_A0|GPIO_A1|GPIO_A2|GPIO_A3, 0);
  222. /* Set CF Socket 1 power to standby mode. */
  223. lubbock_set_misc_wr((1 << 15) | (1 << 14), 0);
  224. sadev->dev.platform_data = &lubbock_pcmcia_ops;
  225. ret = pxa2xx_drv_pcmcia_probe(&sadev->dev);
  226. }
  227. return ret;
  228. }
  229. MODULE_LICENSE("GPL");