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