pxa2xx_lubbock.c 5.9 KB

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