pxa2xx_cm_x255.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * linux/drivers/pcmcia/pxa/pxa_cm_x255.c
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * Compulab Ltd., 2003, 2007, 2008
  9. * Mike Rapoport <mike@compulab.co.il>
  10. *
  11. */
  12. #include <linux/platform_device.h>
  13. #include <linux/irq.h>
  14. #include <linux/delay.h>
  15. #include <linux/gpio.h>
  16. #include <linux/export.h>
  17. #include "soc_common.h"
  18. #define GPIO_PCMCIA_SKTSEL (54)
  19. #define GPIO_PCMCIA_S0_CD_VALID (16)
  20. #define GPIO_PCMCIA_S1_CD_VALID (17)
  21. #define GPIO_PCMCIA_S0_RDYINT (6)
  22. #define GPIO_PCMCIA_S1_RDYINT (8)
  23. #define GPIO_PCMCIA_RESET (9)
  24. static int cmx255_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  25. {
  26. int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset");
  27. if (ret)
  28. return ret;
  29. gpio_direction_output(GPIO_PCMCIA_RESET, 0);
  30. if (skt->nr == 0) {
  31. skt->stat[SOC_STAT_CD].gpio = GPIO_PCMCIA_S0_CD_VALID;
  32. skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD";
  33. skt->stat[SOC_STAT_RDY].gpio = GPIO_PCMCIA_S0_RDYINT;
  34. skt->stat[SOC_STAT_RDY].name = "PCMCIA0 RDY";
  35. } else {
  36. skt->stat[SOC_STAT_CD].gpio = GPIO_PCMCIA_S1_CD_VALID;
  37. skt->stat[SOC_STAT_CD].name = "PCMCIA1 CD";
  38. skt->stat[SOC_STAT_RDY].gpio = GPIO_PCMCIA_S1_RDYINT;
  39. skt->stat[SOC_STAT_RDY].name = "PCMCIA1 RDY";
  40. }
  41. return 0;
  42. }
  43. static void cmx255_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
  44. {
  45. gpio_free(GPIO_PCMCIA_RESET);
  46. }
  47. static void cmx255_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  48. struct pcmcia_state *state)
  49. {
  50. state->vs_3v = 0;
  51. state->vs_Xv = 0;
  52. }
  53. static int cmx255_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  54. const socket_state_t *state)
  55. {
  56. switch (skt->nr) {
  57. case 0:
  58. if (state->flags & SS_RESET) {
  59. gpio_set_value(GPIO_PCMCIA_SKTSEL, 0);
  60. udelay(1);
  61. gpio_set_value(GPIO_PCMCIA_RESET, 1);
  62. udelay(10);
  63. gpio_set_value(GPIO_PCMCIA_RESET, 0);
  64. }
  65. break;
  66. case 1:
  67. if (state->flags & SS_RESET) {
  68. gpio_set_value(GPIO_PCMCIA_SKTSEL, 1);
  69. udelay(1);
  70. gpio_set_value(GPIO_PCMCIA_RESET, 1);
  71. udelay(10);
  72. gpio_set_value(GPIO_PCMCIA_RESET, 0);
  73. }
  74. break;
  75. }
  76. return 0;
  77. }
  78. static struct pcmcia_low_level cmx255_pcmcia_ops __initdata = {
  79. .owner = THIS_MODULE,
  80. .hw_init = cmx255_pcmcia_hw_init,
  81. .hw_shutdown = cmx255_pcmcia_shutdown,
  82. .socket_state = cmx255_pcmcia_socket_state,
  83. .configure_socket = cmx255_pcmcia_configure_socket,
  84. .nr = 1,
  85. };
  86. static struct platform_device *cmx255_pcmcia_device;
  87. int __init cmx255_pcmcia_init(void)
  88. {
  89. int ret;
  90. cmx255_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  91. if (!cmx255_pcmcia_device)
  92. return -ENOMEM;
  93. ret = platform_device_add_data(cmx255_pcmcia_device, &cmx255_pcmcia_ops,
  94. sizeof(cmx255_pcmcia_ops));
  95. if (ret == 0) {
  96. printk(KERN_INFO "Registering cm-x255 PCMCIA interface.\n");
  97. ret = platform_device_add(cmx255_pcmcia_device);
  98. }
  99. if (ret)
  100. platform_device_put(cmx255_pcmcia_device);
  101. return ret;
  102. }
  103. void __exit cmx255_pcmcia_exit(void)
  104. {
  105. platform_device_unregister(cmx255_pcmcia_device);
  106. }