pxa2xx_viper.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * VIPER PCMCIA support
  3. * Copyright 2004 Arcom Control Systems
  4. *
  5. * Maintained by Marc Zyngier <maz@misterjones.org>
  6. * <marc.zyngier@altran.com>
  7. *
  8. * Based on:
  9. * iPAQ h2200 PCMCIA support
  10. * Copyright 2004 Koen Kooi <koen@vestingbar.nl>
  11. *
  12. * This file is subject to the terms and conditions of the GNU General Public
  13. * License. See the file COPYING in the main directory of this archive for
  14. * more details.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/kernel.h>
  19. #include <linux/errno.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/gpio.h>
  23. #include <pcmcia/ss.h>
  24. #include <asm/irq.h>
  25. #include <mach/viper.h>
  26. #include <asm/mach-types.h>
  27. #include "soc_common.h"
  28. #include "pxa2xx_base.h"
  29. static struct pcmcia_irqs irqs[] = {
  30. { 0, gpio_to_irq(VIPER_CF_CD_GPIO), "PCMCIA_CD" }
  31. };
  32. static int viper_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  33. {
  34. unsigned long flags;
  35. skt->irq = gpio_to_irq(VIPER_CF_RDY_GPIO);
  36. if (gpio_request(VIPER_CF_CD_GPIO, "CF detect"))
  37. goto err_request_cd;
  38. if (gpio_request(VIPER_CF_RDY_GPIO, "CF ready"))
  39. goto err_request_rdy;
  40. if (gpio_request(VIPER_CF_POWER_GPIO, "CF power"))
  41. goto err_request_pwr;
  42. local_irq_save(flags);
  43. /* GPIO 82 is the CF power enable line. initially off */
  44. if (gpio_direction_output(VIPER_CF_POWER_GPIO, 0) ||
  45. gpio_direction_input(VIPER_CF_CD_GPIO) ||
  46. gpio_direction_input(VIPER_CF_RDY_GPIO)) {
  47. local_irq_restore(flags);
  48. goto err_dir;
  49. }
  50. local_irq_restore(flags);
  51. return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
  52. err_dir:
  53. gpio_free(VIPER_CF_POWER_GPIO);
  54. err_request_pwr:
  55. gpio_free(VIPER_CF_RDY_GPIO);
  56. err_request_rdy:
  57. gpio_free(VIPER_CF_CD_GPIO);
  58. err_request_cd:
  59. printk(KERN_ERR "viper: Failed to setup PCMCIA GPIOs\n");
  60. return -1;
  61. }
  62. /*
  63. * Release all resources.
  64. */
  65. static void viper_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  66. {
  67. soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
  68. gpio_free(VIPER_CF_POWER_GPIO);
  69. gpio_free(VIPER_CF_RDY_GPIO);
  70. gpio_free(VIPER_CF_CD_GPIO);
  71. }
  72. static void viper_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  73. struct pcmcia_state *state)
  74. {
  75. state->detect = gpio_get_value(VIPER_CF_CD_GPIO) ? 0 : 1;
  76. state->ready = gpio_get_value(VIPER_CF_RDY_GPIO) ? 1 : 0;
  77. state->bvd1 = 1;
  78. state->bvd2 = 1;
  79. state->wrprot = 0;
  80. state->vs_3v = 1; /* Can only apply 3.3V */
  81. state->vs_Xv = 0;
  82. }
  83. static int viper_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  84. const socket_state_t *state)
  85. {
  86. /* Silently ignore Vpp, output enable, speaker enable. */
  87. viper_cf_rst(state->flags & SS_RESET);
  88. /* Apply socket voltage */
  89. switch (state->Vcc) {
  90. case 0:
  91. gpio_set_value(VIPER_CF_POWER_GPIO, 0);
  92. break;
  93. case 33:
  94. gpio_set_value(VIPER_CF_POWER_GPIO, 1);
  95. break;
  96. default:
  97. printk(KERN_ERR "%s: Unsupported Vcc:%d\n",
  98. __func__, state->Vcc);
  99. return -1;
  100. }
  101. return 0;
  102. }
  103. static void viper_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  104. {
  105. }
  106. static void viper_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  107. {
  108. }
  109. static struct pcmcia_low_level viper_pcmcia_ops __initdata = {
  110. .owner = THIS_MODULE,
  111. .hw_init = viper_pcmcia_hw_init,
  112. .hw_shutdown = viper_pcmcia_hw_shutdown,
  113. .socket_state = viper_pcmcia_socket_state,
  114. .configure_socket = viper_pcmcia_configure_socket,
  115. .socket_init = viper_pcmcia_socket_init,
  116. .socket_suspend = viper_pcmcia_socket_suspend,
  117. .nr = 1,
  118. };
  119. static struct platform_device *viper_pcmcia_device;
  120. static int __init viper_pcmcia_init(void)
  121. {
  122. int ret;
  123. if (!machine_is_viper())
  124. return -ENODEV;
  125. viper_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  126. if (!viper_pcmcia_device)
  127. return -ENOMEM;
  128. ret = platform_device_add_data(viper_pcmcia_device,
  129. &viper_pcmcia_ops,
  130. sizeof(viper_pcmcia_ops));
  131. if (!ret)
  132. ret = platform_device_add(viper_pcmcia_device);
  133. if (ret)
  134. platform_device_put(viper_pcmcia_device);
  135. return ret;
  136. }
  137. static void __exit viper_pcmcia_exit(void)
  138. {
  139. platform_device_unregister(viper_pcmcia_device);
  140. }
  141. module_init(viper_pcmcia_init);
  142. module_exit(viper_pcmcia_exit);
  143. MODULE_LICENSE("GPL");