pxa2xx_cm_x255.c 3.5 KB

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