pxa2xx_viper.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Viper/Zeus PCMCIA support
  3. * Copyright 2004 Arcom Control Systems
  4. *
  5. * Maintained by Marc Zyngier <maz@misterjones.org>
  6. *
  7. * Based on:
  8. * iPAQ h2200 PCMCIA support
  9. * Copyright 2004 Koen Kooi <koen@vestingbar.nl>
  10. *
  11. * This file is subject to the terms and conditions of the GNU General Public
  12. * License. See the file COPYING in the main directory of this archive for
  13. * more details.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/errno.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/gpio.h>
  22. #include <pcmcia/ss.h>
  23. #include <asm/irq.h>
  24. #include <linux/platform_data/pcmcia-pxa2xx_viper.h>
  25. #include "soc_common.h"
  26. #include "pxa2xx_base.h"
  27. static struct platform_device *arcom_pcmcia_dev;
  28. static inline struct arcom_pcmcia_pdata *viper_get_pdata(void)
  29. {
  30. return arcom_pcmcia_dev->dev.platform_data;
  31. }
  32. static int viper_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  33. {
  34. struct arcom_pcmcia_pdata *pdata = viper_get_pdata();
  35. unsigned long flags;
  36. skt->stat[SOC_STAT_CD].gpio = pdata->cd_gpio;
  37. skt->stat[SOC_STAT_CD].name = "PCMCIA_CD";
  38. skt->stat[SOC_STAT_RDY].gpio = pdata->rdy_gpio;
  39. skt->stat[SOC_STAT_RDY].name = "CF ready";
  40. if (gpio_request(pdata->pwr_gpio, "CF power"))
  41. goto err_request_pwr;
  42. local_irq_save(flags);
  43. if (gpio_direction_output(pdata->pwr_gpio, 0)) {
  44. local_irq_restore(flags);
  45. goto err_dir;
  46. }
  47. local_irq_restore(flags);
  48. return 0;
  49. err_dir:
  50. gpio_free(pdata->pwr_gpio);
  51. err_request_pwr:
  52. dev_err(&arcom_pcmcia_dev->dev, "Failed to setup PCMCIA GPIOs\n");
  53. return -1;
  54. }
  55. /*
  56. * Release all resources.
  57. */
  58. static void viper_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  59. {
  60. struct arcom_pcmcia_pdata *pdata = viper_get_pdata();
  61. gpio_free(pdata->pwr_gpio);
  62. }
  63. static void viper_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  64. struct pcmcia_state *state)
  65. {
  66. state->vs_3v = 1; /* Can only apply 3.3V */
  67. state->vs_Xv = 0;
  68. }
  69. static int viper_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  70. const socket_state_t *state)
  71. {
  72. struct arcom_pcmcia_pdata *pdata = viper_get_pdata();
  73. /* Silently ignore Vpp, output enable, speaker enable. */
  74. pdata->reset(state->flags & SS_RESET);
  75. /* Apply socket voltage */
  76. switch (state->Vcc) {
  77. case 0:
  78. gpio_set_value(pdata->pwr_gpio, 0);
  79. break;
  80. case 33:
  81. gpio_set_value(pdata->pwr_gpio, 1);
  82. break;
  83. default:
  84. dev_err(&arcom_pcmcia_dev->dev, "Unsupported Vcc:%d\n", state->Vcc);
  85. return -1;
  86. }
  87. return 0;
  88. }
  89. static struct pcmcia_low_level viper_pcmcia_ops = {
  90. .owner = THIS_MODULE,
  91. .hw_init = viper_pcmcia_hw_init,
  92. .hw_shutdown = viper_pcmcia_hw_shutdown,
  93. .socket_state = viper_pcmcia_socket_state,
  94. .configure_socket = viper_pcmcia_configure_socket,
  95. .nr = 1,
  96. };
  97. static struct platform_device *viper_pcmcia_device;
  98. static int viper_pcmcia_probe(struct platform_device *pdev)
  99. {
  100. int ret;
  101. /* I can't imagine more than one device, but you never know... */
  102. if (arcom_pcmcia_dev)
  103. return -EEXIST;
  104. if (!pdev->dev.platform_data)
  105. return -EINVAL;
  106. viper_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  107. if (!viper_pcmcia_device)
  108. return -ENOMEM;
  109. arcom_pcmcia_dev = pdev;
  110. viper_pcmcia_device->dev.parent = &pdev->dev;
  111. ret = platform_device_add_data(viper_pcmcia_device,
  112. &viper_pcmcia_ops,
  113. sizeof(viper_pcmcia_ops));
  114. if (!ret)
  115. ret = platform_device_add(viper_pcmcia_device);
  116. if (ret) {
  117. platform_device_put(viper_pcmcia_device);
  118. arcom_pcmcia_dev = NULL;
  119. }
  120. return ret;
  121. }
  122. static int viper_pcmcia_remove(struct platform_device *pdev)
  123. {
  124. platform_device_unregister(viper_pcmcia_device);
  125. arcom_pcmcia_dev = NULL;
  126. return 0;
  127. }
  128. static struct platform_device_id viper_pcmcia_id_table[] = {
  129. { .name = "viper-pcmcia", },
  130. { .name = "zeus-pcmcia", },
  131. { },
  132. };
  133. static struct platform_driver viper_pcmcia_driver = {
  134. .probe = viper_pcmcia_probe,
  135. .remove = viper_pcmcia_remove,
  136. .driver = {
  137. .name = "arcom-pcmcia",
  138. },
  139. .id_table = viper_pcmcia_id_table,
  140. };
  141. module_platform_driver(viper_pcmcia_driver);
  142. MODULE_DEVICE_TABLE(platform, viper_pcmcia_id_table);
  143. MODULE_LICENSE("GPL");