pxa2xx_palmtc.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * linux/drivers/pcmcia/pxa2xx_palmtc.c
  3. *
  4. * Driver for Palm Tungsten|C PCMCIA
  5. *
  6. * Copyright (C) 2008 Alex Osborne <ato@meshy.org>
  7. * Copyright (C) 2009 Marek Vasut <marek.vasut@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/gpio.h>
  17. #include <linux/delay.h>
  18. #include <asm/mach-types.h>
  19. #include <mach/palmtc.h>
  20. #include "soc_common.h"
  21. static int palmtc_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  22. {
  23. int ret;
  24. ret = gpio_request(GPIO_NR_PALMTC_PCMCIA_POWER1, "PCMCIA PWR1");
  25. if (ret)
  26. goto err1;
  27. ret = gpio_direction_output(GPIO_NR_PALMTC_PCMCIA_POWER1, 0);
  28. if (ret)
  29. goto err2;
  30. ret = gpio_request(GPIO_NR_PALMTC_PCMCIA_POWER2, "PCMCIA PWR2");
  31. if (ret)
  32. goto err2;
  33. ret = gpio_direction_output(GPIO_NR_PALMTC_PCMCIA_POWER2, 0);
  34. if (ret)
  35. goto err3;
  36. ret = gpio_request(GPIO_NR_PALMTC_PCMCIA_POWER3, "PCMCIA PWR3");
  37. if (ret)
  38. goto err3;
  39. ret = gpio_direction_output(GPIO_NR_PALMTC_PCMCIA_POWER3, 0);
  40. if (ret)
  41. goto err4;
  42. ret = gpio_request(GPIO_NR_PALMTC_PCMCIA_RESET, "PCMCIA RST");
  43. if (ret)
  44. goto err4;
  45. ret = gpio_direction_output(GPIO_NR_PALMTC_PCMCIA_RESET, 1);
  46. if (ret)
  47. goto err5;
  48. ret = gpio_request(GPIO_NR_PALMTC_PCMCIA_READY, "PCMCIA RDY");
  49. if (ret)
  50. goto err5;
  51. ret = gpio_direction_input(GPIO_NR_PALMTC_PCMCIA_READY);
  52. if (ret)
  53. goto err6;
  54. ret = gpio_request(GPIO_NR_PALMTC_PCMCIA_PWRREADY, "PCMCIA PWRRDY");
  55. if (ret)
  56. goto err6;
  57. ret = gpio_direction_input(GPIO_NR_PALMTC_PCMCIA_PWRREADY);
  58. if (ret)
  59. goto err7;
  60. skt->irq = IRQ_GPIO(GPIO_NR_PALMTC_PCMCIA_READY);
  61. return 0;
  62. err7:
  63. gpio_free(GPIO_NR_PALMTC_PCMCIA_PWRREADY);
  64. err6:
  65. gpio_free(GPIO_NR_PALMTC_PCMCIA_READY);
  66. err5:
  67. gpio_free(GPIO_NR_PALMTC_PCMCIA_RESET);
  68. err4:
  69. gpio_free(GPIO_NR_PALMTC_PCMCIA_POWER3);
  70. err3:
  71. gpio_free(GPIO_NR_PALMTC_PCMCIA_POWER2);
  72. err2:
  73. gpio_free(GPIO_NR_PALMTC_PCMCIA_POWER1);
  74. err1:
  75. return ret;
  76. }
  77. static void palmtc_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  78. {
  79. gpio_free(GPIO_NR_PALMTC_PCMCIA_PWRREADY);
  80. gpio_free(GPIO_NR_PALMTC_PCMCIA_READY);
  81. gpio_free(GPIO_NR_PALMTC_PCMCIA_RESET);
  82. gpio_free(GPIO_NR_PALMTC_PCMCIA_POWER3);
  83. gpio_free(GPIO_NR_PALMTC_PCMCIA_POWER2);
  84. gpio_free(GPIO_NR_PALMTC_PCMCIA_POWER1);
  85. }
  86. static void palmtc_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  87. struct pcmcia_state *state)
  88. {
  89. state->detect = 1; /* always inserted */
  90. state->ready = !!gpio_get_value(GPIO_NR_PALMTC_PCMCIA_READY);
  91. state->bvd1 = 1;
  92. state->bvd2 = 1;
  93. state->wrprot = 0;
  94. state->vs_3v = 1;
  95. state->vs_Xv = 0;
  96. }
  97. static int palmtc_wifi_powerdown(void)
  98. {
  99. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_RESET, 1);
  100. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_POWER2, 0);
  101. mdelay(40);
  102. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_POWER1, 0);
  103. return 0;
  104. }
  105. static int palmtc_wifi_powerup(void)
  106. {
  107. int timeout = 50;
  108. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_POWER3, 1);
  109. mdelay(50);
  110. /* Power up the card, 1.8V first, after a while 3.3V */
  111. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_POWER1, 1);
  112. mdelay(100);
  113. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_POWER2, 1);
  114. /* Wait till the card is ready */
  115. while (!gpio_get_value(GPIO_NR_PALMTC_PCMCIA_PWRREADY) &&
  116. timeout) {
  117. mdelay(1);
  118. timeout--;
  119. }
  120. /* Power down the WiFi in case of error */
  121. if (!timeout) {
  122. palmtc_wifi_powerdown();
  123. return 1;
  124. }
  125. /* Reset the card */
  126. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_RESET, 1);
  127. mdelay(20);
  128. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_RESET, 0);
  129. mdelay(25);
  130. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_POWER3, 0);
  131. return 0;
  132. }
  133. static int palmtc_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  134. const socket_state_t *state)
  135. {
  136. int ret = 1;
  137. if (state->Vcc == 0)
  138. ret = palmtc_wifi_powerdown();
  139. else if (state->Vcc == 33)
  140. ret = palmtc_wifi_powerup();
  141. return ret;
  142. }
  143. static void palmtc_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  144. {
  145. }
  146. static void palmtc_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  147. {
  148. }
  149. static struct pcmcia_low_level palmtc_pcmcia_ops = {
  150. .owner = THIS_MODULE,
  151. .first = 0,
  152. .nr = 1,
  153. .hw_init = palmtc_pcmcia_hw_init,
  154. .hw_shutdown = palmtc_pcmcia_hw_shutdown,
  155. .socket_state = palmtc_pcmcia_socket_state,
  156. .configure_socket = palmtc_pcmcia_configure_socket,
  157. .socket_init = palmtc_pcmcia_socket_init,
  158. .socket_suspend = palmtc_pcmcia_socket_suspend,
  159. };
  160. static struct platform_device *palmtc_pcmcia_device;
  161. static int __init palmtc_pcmcia_init(void)
  162. {
  163. int ret;
  164. if (!machine_is_palmtc())
  165. return -ENODEV;
  166. palmtc_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  167. if (!palmtc_pcmcia_device)
  168. return -ENOMEM;
  169. ret = platform_device_add_data(palmtc_pcmcia_device, &palmtc_pcmcia_ops,
  170. sizeof(palmtc_pcmcia_ops));
  171. if (!ret)
  172. ret = platform_device_add(palmtc_pcmcia_device);
  173. if (ret)
  174. platform_device_put(palmtc_pcmcia_device);
  175. return ret;
  176. }
  177. static void __exit palmtc_pcmcia_exit(void)
  178. {
  179. platform_device_unregister(palmtc_pcmcia_device);
  180. }
  181. module_init(palmtc_pcmcia_init);
  182. module_exit(palmtc_pcmcia_exit);
  183. MODULE_AUTHOR("Alex Osborne <ato@meshy.org>,"
  184. " Marek Vasut <marek.vasut@gmail.com>");
  185. MODULE_DESCRIPTION("PCMCIA support for Palm Tungsten|C");
  186. MODULE_ALIAS("platform:pxa2xx-pcmcia");
  187. MODULE_LICENSE("GPL");