pxa2xx_cm_x255.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 <asm/mach-types.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. #define PCMCIA_S0_CD_VALID IRQ_GPIO(GPIO_PCMCIA_S0_CD_VALID)
  25. #define PCMCIA_S1_CD_VALID IRQ_GPIO(GPIO_PCMCIA_S1_CD_VALID)
  26. #define PCMCIA_S0_RDYINT IRQ_GPIO(GPIO_PCMCIA_S0_RDYINT)
  27. #define PCMCIA_S1_RDYINT IRQ_GPIO(GPIO_PCMCIA_S1_RDYINT)
  28. static struct pcmcia_irqs irqs[] = {
  29. { 0, PCMCIA_S0_CD_VALID, "PCMCIA0 CD" },
  30. { 1, PCMCIA_S1_CD_VALID, "PCMCIA1 CD" },
  31. };
  32. static int cmx255_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  33. {
  34. int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset");
  35. if (ret)
  36. return ret;
  37. gpio_direction_output(GPIO_PCMCIA_RESET, 0);
  38. skt->irq = skt->nr == 0 ? PCMCIA_S0_RDYINT : PCMCIA_S1_RDYINT;
  39. ret = soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
  40. if (!ret)
  41. gpio_free(GPIO_PCMCIA_RESET);
  42. return ret;
  43. }
  44. static void cmx255_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
  45. {
  46. soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
  47. gpio_free(GPIO_PCMCIA_RESET);
  48. }
  49. static void cmx255_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  50. struct pcmcia_state *state)
  51. {
  52. int cd = skt->nr ? GPIO_PCMCIA_S1_CD_VALID : GPIO_PCMCIA_S0_CD_VALID;
  53. int rdy = skt->nr ? GPIO_PCMCIA_S1_RDYINT : GPIO_PCMCIA_S0_RDYINT;
  54. state->detect = !gpio_get_value(cd);
  55. state->ready = !!gpio_get_value(rdy);
  56. state->bvd1 = 1;
  57. state->bvd2 = 1;
  58. state->vs_3v = 0;
  59. state->vs_Xv = 0;
  60. state->wrprot = 0; /* not available */
  61. }
  62. static int cmx255_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  63. const socket_state_t *state)
  64. {
  65. switch (skt->nr) {
  66. case 0:
  67. if (state->flags & SS_RESET) {
  68. gpio_set_value(GPIO_PCMCIA_SKTSEL, 0);
  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. case 1:
  76. if (state->flags & SS_RESET) {
  77. gpio_set_value(GPIO_PCMCIA_SKTSEL, 1);
  78. udelay(1);
  79. gpio_set_value(GPIO_PCMCIA_RESET, 1);
  80. udelay(10);
  81. gpio_set_value(GPIO_PCMCIA_RESET, 0);
  82. }
  83. break;
  84. }
  85. return 0;
  86. }
  87. static void cmx255_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  88. {
  89. }
  90. static void cmx255_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  91. {
  92. }
  93. static struct pcmcia_low_level cmx255_pcmcia_ops __initdata = {
  94. .owner = THIS_MODULE,
  95. .hw_init = cmx255_pcmcia_hw_init,
  96. .hw_shutdown = cmx255_pcmcia_shutdown,
  97. .socket_state = cmx255_pcmcia_socket_state,
  98. .configure_socket = cmx255_pcmcia_configure_socket,
  99. .socket_init = cmx255_pcmcia_socket_init,
  100. .socket_suspend = cmx255_pcmcia_socket_suspend,
  101. .nr = 1,
  102. };
  103. static struct platform_device *cmx255_pcmcia_device;
  104. int __init cmx255_pcmcia_init(void)
  105. {
  106. int ret;
  107. cmx255_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  108. if (!cmx255_pcmcia_device)
  109. return -ENOMEM;
  110. ret = platform_device_add_data(cmx255_pcmcia_device, &cmx255_pcmcia_ops,
  111. sizeof(cmx255_pcmcia_ops));
  112. if (ret == 0) {
  113. printk(KERN_INFO "Registering cm-x255 PCMCIA interface.\n");
  114. ret = platform_device_add(cmx255_pcmcia_device);
  115. }
  116. if (ret)
  117. platform_device_put(cmx255_pcmcia_device);
  118. return ret;
  119. }
  120. void __exit cmx255_pcmcia_exit(void)
  121. {
  122. platform_device_unregister(cmx255_pcmcia_device);
  123. }