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