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