pxa2xx_palmtc.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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-2011 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 struct gpio palmtc_pcmcia_gpios[] = {
  22. { GPIO_NR_PALMTC_PCMCIA_POWER1, GPIOF_INIT_LOW, "PCMCIA Power 1" },
  23. { GPIO_NR_PALMTC_PCMCIA_POWER2, GPIOF_INIT_LOW, "PCMCIA Power 2" },
  24. { GPIO_NR_PALMTC_PCMCIA_POWER3, GPIOF_INIT_LOW, "PCMCIA Power 3" },
  25. { GPIO_NR_PALMTC_PCMCIA_RESET, GPIOF_INIT_HIGH,"PCMCIA Reset" },
  26. { GPIO_NR_PALMTC_PCMCIA_READY, GPIOF_IN, "PCMCIA Ready" },
  27. { GPIO_NR_PALMTC_PCMCIA_PWRREADY, GPIOF_IN, "PCMCIA Power Ready" },
  28. };
  29. static int palmtc_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  30. {
  31. int ret;
  32. ret = gpio_request_array(palmtc_pcmcia_gpios,
  33. ARRAY_SIZE(palmtc_pcmcia_gpios));
  34. skt->socket.pci_irq = IRQ_GPIO(GPIO_NR_PALMTC_PCMCIA_READY);
  35. return ret;
  36. }
  37. static void palmtc_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  38. {
  39. gpio_free_array(palmtc_pcmcia_gpios, ARRAY_SIZE(palmtc_pcmcia_gpios));
  40. }
  41. static void palmtc_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  42. struct pcmcia_state *state)
  43. {
  44. state->detect = 1; /* always inserted */
  45. state->ready = !!gpio_get_value(GPIO_NR_PALMTC_PCMCIA_READY);
  46. state->bvd1 = 1;
  47. state->bvd2 = 1;
  48. state->wrprot = 0;
  49. state->vs_3v = 1;
  50. state->vs_Xv = 0;
  51. }
  52. static int palmtc_wifi_powerdown(void)
  53. {
  54. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_RESET, 1);
  55. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_POWER2, 0);
  56. mdelay(40);
  57. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_POWER1, 0);
  58. return 0;
  59. }
  60. static int palmtc_wifi_powerup(void)
  61. {
  62. int timeout = 50;
  63. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_POWER3, 1);
  64. mdelay(50);
  65. /* Power up the card, 1.8V first, after a while 3.3V */
  66. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_POWER1, 1);
  67. mdelay(100);
  68. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_POWER2, 1);
  69. /* Wait till the card is ready */
  70. while (!gpio_get_value(GPIO_NR_PALMTC_PCMCIA_PWRREADY) &&
  71. timeout) {
  72. mdelay(1);
  73. timeout--;
  74. }
  75. /* Power down the WiFi in case of error */
  76. if (!timeout) {
  77. palmtc_wifi_powerdown();
  78. return 1;
  79. }
  80. /* Reset the card */
  81. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_RESET, 1);
  82. mdelay(20);
  83. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_RESET, 0);
  84. mdelay(25);
  85. gpio_set_value(GPIO_NR_PALMTC_PCMCIA_POWER3, 0);
  86. return 0;
  87. }
  88. static int palmtc_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  89. const socket_state_t *state)
  90. {
  91. int ret = 1;
  92. if (state->Vcc == 0)
  93. ret = palmtc_wifi_powerdown();
  94. else if (state->Vcc == 33)
  95. ret = palmtc_wifi_powerup();
  96. return ret;
  97. }
  98. static void palmtc_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  99. {
  100. }
  101. static void palmtc_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  102. {
  103. }
  104. static struct pcmcia_low_level palmtc_pcmcia_ops = {
  105. .owner = THIS_MODULE,
  106. .first = 0,
  107. .nr = 1,
  108. .hw_init = palmtc_pcmcia_hw_init,
  109. .hw_shutdown = palmtc_pcmcia_hw_shutdown,
  110. .socket_state = palmtc_pcmcia_socket_state,
  111. .configure_socket = palmtc_pcmcia_configure_socket,
  112. .socket_init = palmtc_pcmcia_socket_init,
  113. .socket_suspend = palmtc_pcmcia_socket_suspend,
  114. };
  115. static struct platform_device *palmtc_pcmcia_device;
  116. static int __init palmtc_pcmcia_init(void)
  117. {
  118. int ret;
  119. if (!machine_is_palmtc())
  120. return -ENODEV;
  121. palmtc_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  122. if (!palmtc_pcmcia_device)
  123. return -ENOMEM;
  124. ret = platform_device_add_data(palmtc_pcmcia_device, &palmtc_pcmcia_ops,
  125. sizeof(palmtc_pcmcia_ops));
  126. if (!ret)
  127. ret = platform_device_add(palmtc_pcmcia_device);
  128. if (ret)
  129. platform_device_put(palmtc_pcmcia_device);
  130. return ret;
  131. }
  132. static void __exit palmtc_pcmcia_exit(void)
  133. {
  134. platform_device_unregister(palmtc_pcmcia_device);
  135. }
  136. module_init(palmtc_pcmcia_init);
  137. module_exit(palmtc_pcmcia_exit);
  138. MODULE_AUTHOR("Alex Osborne <ato@meshy.org>,"
  139. " Marek Vasut <marek.vasut@gmail.com>");
  140. MODULE_DESCRIPTION("PCMCIA support for Palm Tungsten|C");
  141. MODULE_ALIAS("platform:pxa2xx-pcmcia");
  142. MODULE_LICENSE("GPL");