pxa2xx_stargate2.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * linux/drivers/pcmcia/pxa2xx_stargate2.c
  3. *
  4. * Stargate 2 PCMCIA specific routines.
  5. *
  6. * Created: December 6, 2005
  7. * Author: Ed C. Epp
  8. * Copyright: Intel Corp 2005
  9. * Jonathan Cameron <jic23@cam.ac.uk> 2009
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/delay.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/gpio.h>
  22. #include <pcmcia/ss.h>
  23. #include <asm/irq.h>
  24. #include <asm/mach-types.h>
  25. #include "soc_common.h"
  26. #define SG2_S0_POWER_CTL 108
  27. #define SG2_S0_GPIO_RESET 82
  28. #define SG2_S0_GPIO_DETECT 53
  29. #define SG2_S0_GPIO_READY 81
  30. static struct pcmcia_irqs irqs[] = {
  31. { 0, IRQ_GPIO(SG2_S0_GPIO_DETECT), "PCMCIA0 CD" },
  32. };
  33. static struct gpio sg2_pcmcia_gpios[] = {
  34. { SG2_S0_GPIO_RESET, GPIOF_OUT_INIT_HIGH, "PCMCIA Reset" },
  35. { SG2_S0_POWER_CTL, GPIOF_OUT_INIT_HIGH, "PCMCIA Power Ctrl" },
  36. };
  37. static int sg2_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  38. {
  39. skt->socket.pci_irq = IRQ_GPIO(SG2_S0_GPIO_READY);
  40. return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
  41. }
  42. static void sg2_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  43. {
  44. soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
  45. }
  46. static void sg2_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  47. struct pcmcia_state *state)
  48. {
  49. state->detect = !gpio_get_value(SG2_S0_GPIO_DETECT);
  50. state->ready = !!gpio_get_value(SG2_S0_GPIO_READY);
  51. state->bvd1 = 0; /* not available - battery detect on card */
  52. state->bvd2 = 0; /* not available */
  53. state->vs_3v = 1; /* not available - voltage detect for card */
  54. state->vs_Xv = 0; /* not available */
  55. state->wrprot = 0; /* not available - write protect */
  56. }
  57. static int sg2_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  58. const socket_state_t *state)
  59. {
  60. /* Enable card power */
  61. switch (state->Vcc) {
  62. case 0:
  63. /* sets power ctl register high */
  64. gpio_set_value(SG2_S0_POWER_CTL, 1);
  65. break;
  66. case 33:
  67. case 50:
  68. /* sets power control register low (clear) */
  69. gpio_set_value(SG2_S0_POWER_CTL, 0);
  70. msleep(100);
  71. break;
  72. default:
  73. pr_err("%s(): bad Vcc %u\n",
  74. __func__, state->Vcc);
  75. return -1;
  76. }
  77. /* reset */
  78. gpio_set_value(SG2_S0_GPIO_RESET, !!(state->flags & SS_RESET));
  79. return 0;
  80. }
  81. static void sg2_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  82. {
  83. soc_pcmcia_enable_irqs(skt, irqs, ARRAY_SIZE(irqs));
  84. }
  85. static void sg2_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  86. {
  87. soc_pcmcia_disable_irqs(skt, irqs, ARRAY_SIZE(irqs));
  88. }
  89. static struct pcmcia_low_level sg2_pcmcia_ops __initdata = {
  90. .owner = THIS_MODULE,
  91. .hw_init = sg2_pcmcia_hw_init,
  92. .hw_shutdown = sg2_pcmcia_hw_shutdown,
  93. .socket_state = sg2_pcmcia_socket_state,
  94. .configure_socket = sg2_pcmcia_configure_socket,
  95. .socket_init = sg2_pcmcia_socket_init,
  96. .socket_suspend = sg2_pcmcia_socket_suspend,
  97. .nr = 1,
  98. };
  99. static struct platform_device *sg2_pcmcia_device;
  100. static int __init sg2_pcmcia_init(void)
  101. {
  102. int ret;
  103. if (!machine_is_stargate2())
  104. return -ENODEV;
  105. sg2_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  106. if (!sg2_pcmcia_device)
  107. return -ENOMEM;
  108. ret = gpio_request_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
  109. if (ret)
  110. goto error_put_platform_device;
  111. ret = platform_device_add_data(sg2_pcmcia_device,
  112. &sg2_pcmcia_ops,
  113. sizeof(sg2_pcmcia_ops));
  114. if (ret)
  115. goto error_free_gpios;
  116. ret = platform_device_add(sg2_pcmcia_device);
  117. if (ret)
  118. goto error_free_gpios;
  119. return 0;
  120. error_free_gpios:
  121. gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
  122. error_put_platform_device:
  123. platform_device_put(sg2_pcmcia_device);
  124. return ret;
  125. }
  126. static void __exit sg2_pcmcia_exit(void)
  127. {
  128. platform_device_unregister(sg2_pcmcia_device);
  129. gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
  130. }
  131. fs_initcall(sg2_pcmcia_init);
  132. module_exit(sg2_pcmcia_exit);
  133. MODULE_LICENSE("GPL");
  134. MODULE_ALIAS("platform:pxa2xx-pcmcia");