pxa2xx_cm_x270.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * linux/drivers/pcmcia/pxa/pxa_cm_x270.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_S0_CD_VALID (84)
  19. #define GPIO_PCMCIA_S0_RDYINT (82)
  20. #define GPIO_PCMCIA_RESET (53)
  21. #define PCMCIA_S0_CD_VALID IRQ_GPIO(GPIO_PCMCIA_S0_CD_VALID)
  22. #define PCMCIA_S0_RDYINT IRQ_GPIO(GPIO_PCMCIA_S0_RDYINT)
  23. static struct pcmcia_irqs irqs[] = {
  24. { 0, PCMCIA_S0_CD_VALID, "PCMCIA0 CD" },
  25. };
  26. static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  27. {
  28. int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset");
  29. if (ret)
  30. return ret;
  31. gpio_direction_output(GPIO_PCMCIA_RESET, 0);
  32. skt->socket.pci_irq = PCMCIA_S0_RDYINT;
  33. ret = soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
  34. if (!ret)
  35. gpio_free(GPIO_PCMCIA_RESET);
  36. return ret;
  37. }
  38. static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
  39. {
  40. soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
  41. gpio_free(GPIO_PCMCIA_RESET);
  42. }
  43. static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  44. struct pcmcia_state *state)
  45. {
  46. state->detect = (gpio_get_value(GPIO_PCMCIA_S0_CD_VALID) == 0) ? 1 : 0;
  47. state->ready = (gpio_get_value(GPIO_PCMCIA_S0_RDYINT) == 0) ? 0 : 1;
  48. state->bvd1 = 1;
  49. state->bvd2 = 1;
  50. state->vs_3v = 0;
  51. state->vs_Xv = 0;
  52. state->wrprot = 0; /* not available */
  53. }
  54. static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  55. const socket_state_t *state)
  56. {
  57. switch (skt->nr) {
  58. case 0:
  59. if (state->flags & SS_RESET) {
  60. gpio_set_value(GPIO_PCMCIA_RESET, 1);
  61. udelay(10);
  62. gpio_set_value(GPIO_PCMCIA_RESET, 0);
  63. }
  64. break;
  65. }
  66. return 0;
  67. }
  68. static void cmx270_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  69. {
  70. }
  71. static void cmx270_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  72. {
  73. }
  74. static struct pcmcia_low_level cmx270_pcmcia_ops __initdata = {
  75. .owner = THIS_MODULE,
  76. .hw_init = cmx270_pcmcia_hw_init,
  77. .hw_shutdown = cmx270_pcmcia_shutdown,
  78. .socket_state = cmx270_pcmcia_socket_state,
  79. .configure_socket = cmx270_pcmcia_configure_socket,
  80. .socket_init = cmx270_pcmcia_socket_init,
  81. .socket_suspend = cmx270_pcmcia_socket_suspend,
  82. .nr = 1,
  83. };
  84. static struct platform_device *cmx270_pcmcia_device;
  85. int __init cmx270_pcmcia_init(void)
  86. {
  87. int ret;
  88. cmx270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  89. if (!cmx270_pcmcia_device)
  90. return -ENOMEM;
  91. ret = platform_device_add_data(cmx270_pcmcia_device, &cmx270_pcmcia_ops,
  92. sizeof(cmx270_pcmcia_ops));
  93. if (ret == 0) {
  94. printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n");
  95. ret = platform_device_add(cmx270_pcmcia_device);
  96. }
  97. if (ret)
  98. platform_device_put(cmx270_pcmcia_device);
  99. return ret;
  100. }
  101. void __exit cmx270_pcmcia_exit(void)
  102. {
  103. platform_device_unregister(cmx270_pcmcia_device);
  104. }