pxa2xx_palmtx.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * linux/drivers/pcmcia/pxa2xx_palmtx.c
  3. *
  4. * Driver for Palm T|X PCMCIA
  5. *
  6. * Copyright (C) 2007-2008 Marek Vasut <marek.vasut@gmail.com>
  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. */
  13. #include <linux/module.h>
  14. #include <linux/platform_device.h>
  15. #include <asm/mach-types.h>
  16. #include <mach/gpio.h>
  17. #include <mach/palmtx.h>
  18. #include "soc_common.h"
  19. static int palmtx_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  20. {
  21. int ret;
  22. ret = gpio_request(GPIO_NR_PALMTX_PCMCIA_POWER1, "PCMCIA PWR1");
  23. if (ret)
  24. goto err1;
  25. ret = gpio_direction_output(GPIO_NR_PALMTX_PCMCIA_POWER1, 0);
  26. if (ret)
  27. goto err2;
  28. ret = gpio_request(GPIO_NR_PALMTX_PCMCIA_POWER2, "PCMCIA PWR2");
  29. if (ret)
  30. goto err2;
  31. ret = gpio_direction_output(GPIO_NR_PALMTX_PCMCIA_POWER2, 0);
  32. if (ret)
  33. goto err3;
  34. ret = gpio_request(GPIO_NR_PALMTX_PCMCIA_RESET, "PCMCIA RST");
  35. if (ret)
  36. goto err3;
  37. ret = gpio_direction_output(GPIO_NR_PALMTX_PCMCIA_RESET, 1);
  38. if (ret)
  39. goto err4;
  40. ret = gpio_request(GPIO_NR_PALMTX_PCMCIA_READY, "PCMCIA RDY");
  41. if (ret)
  42. goto err4;
  43. ret = gpio_direction_input(GPIO_NR_PALMTX_PCMCIA_READY);
  44. if (ret)
  45. goto err5;
  46. skt->irq = gpio_to_irq(GPIO_NR_PALMTX_PCMCIA_READY);
  47. return 0;
  48. err5:
  49. gpio_free(GPIO_NR_PALMTX_PCMCIA_READY);
  50. err4:
  51. gpio_free(GPIO_NR_PALMTX_PCMCIA_RESET);
  52. err3:
  53. gpio_free(GPIO_NR_PALMTX_PCMCIA_POWER2);
  54. err2:
  55. gpio_free(GPIO_NR_PALMTX_PCMCIA_POWER1);
  56. err1:
  57. return ret;
  58. }
  59. static void palmtx_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  60. {
  61. gpio_free(GPIO_NR_PALMTX_PCMCIA_READY);
  62. gpio_free(GPIO_NR_PALMTX_PCMCIA_RESET);
  63. gpio_free(GPIO_NR_PALMTX_PCMCIA_POWER2);
  64. gpio_free(GPIO_NR_PALMTX_PCMCIA_POWER1);
  65. }
  66. static void palmtx_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  67. struct pcmcia_state *state)
  68. {
  69. state->detect = 1; /* always inserted */
  70. state->ready = !!gpio_get_value(GPIO_NR_PALMTX_PCMCIA_READY);
  71. state->bvd1 = 1;
  72. state->bvd2 = 1;
  73. state->wrprot = 0;
  74. state->vs_3v = 1;
  75. state->vs_Xv = 0;
  76. }
  77. static int
  78. palmtx_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  79. const socket_state_t *state)
  80. {
  81. gpio_set_value(GPIO_NR_PALMTX_PCMCIA_POWER1, 1);
  82. gpio_set_value(GPIO_NR_PALMTX_PCMCIA_POWER2, 1);
  83. gpio_set_value(GPIO_NR_PALMTX_PCMCIA_RESET,
  84. !!(state->flags & SS_RESET));
  85. return 0;
  86. }
  87. static void palmtx_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  88. {
  89. }
  90. static void palmtx_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  91. {
  92. }
  93. static struct pcmcia_low_level palmtx_pcmcia_ops = {
  94. .owner = THIS_MODULE,
  95. .first = 0,
  96. .nr = 1,
  97. .hw_init = palmtx_pcmcia_hw_init,
  98. .hw_shutdown = palmtx_pcmcia_hw_shutdown,
  99. .socket_state = palmtx_pcmcia_socket_state,
  100. .configure_socket = palmtx_pcmcia_configure_socket,
  101. .socket_init = palmtx_pcmcia_socket_init,
  102. .socket_suspend = palmtx_pcmcia_socket_suspend,
  103. };
  104. static struct platform_device *palmtx_pcmcia_device;
  105. static int __init palmtx_pcmcia_init(void)
  106. {
  107. int ret;
  108. if (!machine_is_palmtx())
  109. return -ENODEV;
  110. palmtx_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  111. if (!palmtx_pcmcia_device)
  112. return -ENOMEM;
  113. ret = platform_device_add_data(palmtx_pcmcia_device, &palmtx_pcmcia_ops,
  114. sizeof(palmtx_pcmcia_ops));
  115. if (!ret)
  116. ret = platform_device_add(palmtx_pcmcia_device);
  117. if (ret)
  118. platform_device_put(palmtx_pcmcia_device);
  119. return ret;
  120. }
  121. static void __exit palmtx_pcmcia_exit(void)
  122. {
  123. platform_device_unregister(palmtx_pcmcia_device);
  124. }
  125. module_init(palmtx_pcmcia_init);
  126. module_exit(palmtx_pcmcia_exit);
  127. MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
  128. MODULE_DESCRIPTION("PCMCIA support for Palm T|X");
  129. MODULE_ALIAS("platform:pxa2xx-pcmcia");
  130. MODULE_LICENSE("GPL");