pxa2xx_palmld.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * linux/drivers/pcmcia/pxa2xx_palmld.c
  3. *
  4. * Driver for Palm LifeDrive PCMCIA
  5. *
  6. * Copyright (C) 2006 Alex Osborne <ato@meshy.org>
  7. * Copyright (C) 2007-2008 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 <asm/mach-types.h>
  18. #include <mach/palmld.h>
  19. #include "soc_common.h"
  20. static int palmld_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  21. {
  22. int ret;
  23. ret = gpio_request(GPIO_NR_PALMLD_PCMCIA_POWER, "PCMCIA PWR");
  24. if (ret)
  25. goto err1;
  26. ret = gpio_direction_output(GPIO_NR_PALMLD_PCMCIA_POWER, 0);
  27. if (ret)
  28. goto err2;
  29. ret = gpio_request(GPIO_NR_PALMLD_PCMCIA_RESET, "PCMCIA RST");
  30. if (ret)
  31. goto err2;
  32. ret = gpio_direction_output(GPIO_NR_PALMLD_PCMCIA_RESET, 1);
  33. if (ret)
  34. goto err3;
  35. ret = gpio_request(GPIO_NR_PALMLD_PCMCIA_READY, "PCMCIA RDY");
  36. if (ret)
  37. goto err3;
  38. ret = gpio_direction_input(GPIO_NR_PALMLD_PCMCIA_READY);
  39. if (ret)
  40. goto err4;
  41. skt->irq = IRQ_GPIO(GPIO_NR_PALMLD_PCMCIA_READY);
  42. return 0;
  43. err4:
  44. gpio_free(GPIO_NR_PALMLD_PCMCIA_READY);
  45. err3:
  46. gpio_free(GPIO_NR_PALMLD_PCMCIA_RESET);
  47. err2:
  48. gpio_free(GPIO_NR_PALMLD_PCMCIA_POWER);
  49. err1:
  50. return ret;
  51. }
  52. static void palmld_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  53. {
  54. gpio_free(GPIO_NR_PALMLD_PCMCIA_READY);
  55. gpio_free(GPIO_NR_PALMLD_PCMCIA_RESET);
  56. gpio_free(GPIO_NR_PALMLD_PCMCIA_POWER);
  57. }
  58. static void palmld_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  59. struct pcmcia_state *state)
  60. {
  61. state->detect = 1; /* always inserted */
  62. state->ready = !!gpio_get_value(GPIO_NR_PALMLD_PCMCIA_READY);
  63. state->bvd1 = 1;
  64. state->bvd2 = 1;
  65. state->wrprot = 0;
  66. state->vs_3v = 1;
  67. state->vs_Xv = 0;
  68. }
  69. static int palmld_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  70. const socket_state_t *state)
  71. {
  72. gpio_set_value(GPIO_NR_PALMLD_PCMCIA_POWER, 1);
  73. gpio_set_value(GPIO_NR_PALMLD_PCMCIA_RESET,
  74. !!(state->flags & SS_RESET));
  75. return 0;
  76. }
  77. static void palmld_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  78. {
  79. }
  80. static void palmld_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  81. {
  82. }
  83. static struct pcmcia_low_level palmld_pcmcia_ops = {
  84. .owner = THIS_MODULE,
  85. .first = 0,
  86. .nr = 2,
  87. .hw_init = palmld_pcmcia_hw_init,
  88. .hw_shutdown = palmld_pcmcia_hw_shutdown,
  89. .socket_state = palmld_pcmcia_socket_state,
  90. .configure_socket = palmld_pcmcia_configure_socket,
  91. .socket_init = palmld_pcmcia_socket_init,
  92. .socket_suspend = palmld_pcmcia_socket_suspend,
  93. };
  94. static struct platform_device *palmld_pcmcia_device;
  95. static int __init palmld_pcmcia_init(void)
  96. {
  97. int ret;
  98. if (!machine_is_palmld())
  99. return -ENODEV;
  100. palmld_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  101. if (!palmld_pcmcia_device)
  102. return -ENOMEM;
  103. ret = platform_device_add_data(palmld_pcmcia_device, &palmld_pcmcia_ops,
  104. sizeof(palmld_pcmcia_ops));
  105. if (!ret)
  106. ret = platform_device_add(palmld_pcmcia_device);
  107. if (ret)
  108. platform_device_put(palmld_pcmcia_device);
  109. return ret;
  110. }
  111. static void __exit palmld_pcmcia_exit(void)
  112. {
  113. platform_device_unregister(palmld_pcmcia_device);
  114. }
  115. module_init(palmld_pcmcia_init);
  116. module_exit(palmld_pcmcia_exit);
  117. MODULE_AUTHOR("Alex Osborne <ato@meshy.org>,"
  118. " Marek Vasut <marek.vasut@gmail.com>");
  119. MODULE_DESCRIPTION("PCMCIA support for Palm LifeDrive");
  120. MODULE_ALIAS("platform:pxa2xx-pcmcia");
  121. MODULE_LICENSE("GPL");