pxa2xx_cm_x255.c 3.7 KB

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