pxa2xx_vpac270.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * linux/drivers/pcmcia/pxa2xx_vpac270.c
  3. *
  4. * Driver for Voipac PXA270 PCMCIA and CF sockets
  5. *
  6. * Copyright (C) 2010-2011 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/gpio.h>
  14. #include <linux/module.h>
  15. #include <linux/platform_device.h>
  16. #include <asm/mach-types.h>
  17. #include <mach/vpac270.h>
  18. #include "soc_common.h"
  19. static struct gpio vpac270_pcmcia_gpios[] = {
  20. { GPIO107_VPAC270_PCMCIA_PPEN, GPIOF_INIT_LOW, "PCMCIA PPEN" },
  21. { GPIO11_VPAC270_PCMCIA_RESET, GPIOF_INIT_LOW, "PCMCIA Reset" },
  22. };
  23. static struct gpio vpac270_cf_gpios[] = {
  24. { GPIO16_VPAC270_CF_RESET, GPIOF_INIT_LOW, "CF Reset" },
  25. };
  26. static int vpac270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  27. {
  28. int ret;
  29. if (skt->nr == 0) {
  30. ret = gpio_request_array(vpac270_pcmcia_gpios,
  31. ARRAY_SIZE(vpac270_pcmcia_gpios));
  32. skt->stat[SOC_STAT_CD].gpio = GPIO84_VPAC270_PCMCIA_CD;
  33. skt->stat[SOC_STAT_CD].name = "PCMCIA CD";
  34. skt->stat[SOC_STAT_RDY].gpio = GPIO35_VPAC270_PCMCIA_RDY;
  35. skt->stat[SOC_STAT_RDY].name = "PCMCIA Ready";
  36. } else {
  37. ret = gpio_request_array(vpac270_cf_gpios,
  38. ARRAY_SIZE(vpac270_cf_gpios));
  39. skt->stat[SOC_STAT_CD].gpio = GPIO17_VPAC270_CF_CD;
  40. skt->stat[SOC_STAT_CD].name = "CF CD";
  41. skt->stat[SOC_STAT_RDY].gpio = GPIO12_VPAC270_CF_RDY;
  42. skt->stat[SOC_STAT_RDY].name = "CF Ready";
  43. }
  44. return ret;
  45. }
  46. static void vpac270_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  47. {
  48. if (skt->nr == 0)
  49. gpio_free_array(vpac270_pcmcia_gpios,
  50. ARRAY_SIZE(vpac270_pcmcia_gpios));
  51. else
  52. gpio_free_array(vpac270_cf_gpios,
  53. ARRAY_SIZE(vpac270_cf_gpios));
  54. }
  55. static void vpac270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  56. struct pcmcia_state *state)
  57. {
  58. state->vs_3v = 1;
  59. state->vs_Xv = 0;
  60. }
  61. static int
  62. vpac270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  63. const socket_state_t *state)
  64. {
  65. if (skt->nr == 0) {
  66. gpio_set_value(GPIO11_VPAC270_PCMCIA_RESET,
  67. (state->flags & SS_RESET));
  68. gpio_set_value(GPIO107_VPAC270_PCMCIA_PPEN,
  69. !(state->Vcc == 33 || state->Vcc == 50));
  70. } else {
  71. gpio_set_value(GPIO16_VPAC270_CF_RESET,
  72. (state->flags & SS_RESET));
  73. }
  74. return 0;
  75. }
  76. static struct pcmcia_low_level vpac270_pcmcia_ops = {
  77. .owner = THIS_MODULE,
  78. .first = 0,
  79. .nr = 2,
  80. .hw_init = vpac270_pcmcia_hw_init,
  81. .hw_shutdown = vpac270_pcmcia_hw_shutdown,
  82. .socket_state = vpac270_pcmcia_socket_state,
  83. .configure_socket = vpac270_pcmcia_configure_socket,
  84. };
  85. static struct platform_device *vpac270_pcmcia_device;
  86. static int __init vpac270_pcmcia_init(void)
  87. {
  88. int ret;
  89. if (!machine_is_vpac270())
  90. return -ENODEV;
  91. vpac270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  92. if (!vpac270_pcmcia_device)
  93. return -ENOMEM;
  94. ret = platform_device_add_data(vpac270_pcmcia_device,
  95. &vpac270_pcmcia_ops, sizeof(vpac270_pcmcia_ops));
  96. if (!ret)
  97. ret = platform_device_add(vpac270_pcmcia_device);
  98. if (ret)
  99. platform_device_put(vpac270_pcmcia_device);
  100. return ret;
  101. }
  102. static void __exit vpac270_pcmcia_exit(void)
  103. {
  104. platform_device_unregister(vpac270_pcmcia_device);
  105. }
  106. module_init(vpac270_pcmcia_init);
  107. module_exit(vpac270_pcmcia_exit);
  108. MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
  109. MODULE_DESCRIPTION("PCMCIA support for Voipac PXA270");
  110. MODULE_ALIAS("platform:pxa2xx-pcmcia");
  111. MODULE_LICENSE("GPL");