pxa2xx_palmtc.c 3.9 KB

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