pxa2xx_viper.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/pxa-regs.h>
  26. #include <mach/viper.h>
  27. #include <asm/mach-types.h>
  28. #include "soc_common.h"
  29. #include "pxa2xx_base.h"
  30. static struct pcmcia_irqs irqs[] = {
  31. { 0, gpio_to_irq(VIPER_CF_CD_GPIO), "PCMCIA_CD" }
  32. };
  33. static int viper_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  34. {
  35. unsigned long flags;
  36. skt->irq = gpio_to_irq(VIPER_CF_RDY_GPIO);
  37. if (gpio_request(VIPER_CF_CD_GPIO, "CF detect"))
  38. goto err_request_cd;
  39. if (gpio_request(VIPER_CF_RDY_GPIO, "CF ready"))
  40. goto err_request_rdy;
  41. if (gpio_request(VIPER_CF_POWER_GPIO, "CF power"))
  42. goto err_request_pwr;
  43. local_irq_save(flags);
  44. /* GPIO 82 is the CF power enable line. initially off */
  45. if (gpio_direction_output(VIPER_CF_POWER_GPIO, 0) ||
  46. gpio_direction_input(VIPER_CF_CD_GPIO) ||
  47. gpio_direction_input(VIPER_CF_RDY_GPIO)) {
  48. local_irq_restore(flags);
  49. goto err_dir;
  50. }
  51. local_irq_restore(flags);
  52. return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
  53. err_dir:
  54. gpio_free(VIPER_CF_POWER_GPIO);
  55. err_request_pwr:
  56. gpio_free(VIPER_CF_RDY_GPIO);
  57. err_request_rdy:
  58. gpio_free(VIPER_CF_CD_GPIO);
  59. err_request_cd:
  60. printk(KERN_ERR "viper: Failed to setup PCMCIA GPIOs\n");
  61. return -1;
  62. }
  63. /*
  64. * Release all resources.
  65. */
  66. static void viper_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  67. {
  68. soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
  69. gpio_free(VIPER_CF_POWER_GPIO);
  70. gpio_free(VIPER_CF_RDY_GPIO);
  71. gpio_free(VIPER_CF_CD_GPIO);
  72. }
  73. static void viper_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  74. struct pcmcia_state *state)
  75. {
  76. state->detect = gpio_get_value(VIPER_CF_CD_GPIO) ? 0 : 1;
  77. state->ready = gpio_get_value(VIPER_CF_RDY_GPIO) ? 1 : 0;
  78. state->bvd1 = 1;
  79. state->bvd2 = 1;
  80. state->wrprot = 0;
  81. state->vs_3v = 1; /* Can only apply 3.3V */
  82. state->vs_Xv = 0;
  83. }
  84. static int viper_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  85. const socket_state_t *state)
  86. {
  87. /* Silently ignore Vpp, output enable, speaker enable. */
  88. viper_cf_rst(state->flags & SS_RESET);
  89. /* Apply socket voltage */
  90. switch (state->Vcc) {
  91. case 0:
  92. gpio_set_value(VIPER_CF_POWER_GPIO, 0);
  93. break;
  94. case 33:
  95. gpio_set_value(VIPER_CF_POWER_GPIO, 1);
  96. break;
  97. default:
  98. printk(KERN_ERR "%s: Unsupported Vcc:%d\n",
  99. __func__, state->Vcc);
  100. return -1;
  101. }
  102. return 0;
  103. }
  104. static void viper_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  105. {
  106. }
  107. static void viper_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  108. {
  109. }
  110. static struct pcmcia_low_level viper_pcmcia_ops __initdata = {
  111. .owner = THIS_MODULE,
  112. .hw_init = viper_pcmcia_hw_init,
  113. .hw_shutdown = viper_pcmcia_hw_shutdown,
  114. .socket_state = viper_pcmcia_socket_state,
  115. .configure_socket = viper_pcmcia_configure_socket,
  116. .socket_init = viper_pcmcia_socket_init,
  117. .socket_suspend = viper_pcmcia_socket_suspend,
  118. .nr = 1,
  119. };
  120. static struct platform_device *viper_pcmcia_device;
  121. static int __init viper_pcmcia_init(void)
  122. {
  123. int ret;
  124. if (!machine_is_viper())
  125. return -ENODEV;
  126. viper_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  127. if (!viper_pcmcia_device)
  128. return -ENOMEM;
  129. ret = platform_device_add_data(viper_pcmcia_device,
  130. &viper_pcmcia_ops,
  131. sizeof(viper_pcmcia_ops));
  132. if (!ret)
  133. ret = platform_device_add(viper_pcmcia_device);
  134. if (ret)
  135. platform_device_put(viper_pcmcia_device);
  136. return ret;
  137. }
  138. static void __exit viper_pcmcia_exit(void)
  139. {
  140. platform_device_unregister(viper_pcmcia_device);
  141. }
  142. module_init(viper_pcmcia_init);
  143. module_exit(viper_pcmcia_exit);
  144. MODULE_LICENSE("GPL");