pxa2xx_stargate2.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. {.sock = 0, .str = "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 = gpio_to_irq(SG2_S0_GPIO_READY);
  40. irqs[0].irq = gpio_to_irq(SG2_S0_GPIO_DETECT);
  41. return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
  42. }
  43. static void sg2_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  44. {
  45. soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
  46. }
  47. static void sg2_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  48. struct pcmcia_state *state)
  49. {
  50. state->detect = !gpio_get_value(SG2_S0_GPIO_DETECT);
  51. state->ready = !!gpio_get_value(SG2_S0_GPIO_READY);
  52. state->bvd1 = 0; /* not available - battery detect on card */
  53. state->bvd2 = 0; /* not available */
  54. state->vs_3v = 1; /* not available - voltage detect for card */
  55. state->vs_Xv = 0; /* not available */
  56. state->wrprot = 0; /* not available - write protect */
  57. }
  58. static int sg2_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  59. const socket_state_t *state)
  60. {
  61. /* Enable card power */
  62. switch (state->Vcc) {
  63. case 0:
  64. /* sets power ctl register high */
  65. gpio_set_value(SG2_S0_POWER_CTL, 1);
  66. break;
  67. case 33:
  68. case 50:
  69. /* sets power control register low (clear) */
  70. gpio_set_value(SG2_S0_POWER_CTL, 0);
  71. msleep(100);
  72. break;
  73. default:
  74. pr_err("%s(): bad Vcc %u\n",
  75. __func__, state->Vcc);
  76. return -1;
  77. }
  78. /* reset */
  79. gpio_set_value(SG2_S0_GPIO_RESET, !!(state->flags & SS_RESET));
  80. return 0;
  81. }
  82. static void sg2_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  83. {
  84. soc_pcmcia_enable_irqs(skt, irqs, ARRAY_SIZE(irqs));
  85. }
  86. static void sg2_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  87. {
  88. soc_pcmcia_disable_irqs(skt, irqs, ARRAY_SIZE(irqs));
  89. }
  90. static struct pcmcia_low_level sg2_pcmcia_ops __initdata = {
  91. .owner = THIS_MODULE,
  92. .hw_init = sg2_pcmcia_hw_init,
  93. .hw_shutdown = sg2_pcmcia_hw_shutdown,
  94. .socket_state = sg2_pcmcia_socket_state,
  95. .configure_socket = sg2_pcmcia_configure_socket,
  96. .socket_init = sg2_pcmcia_socket_init,
  97. .socket_suspend = sg2_pcmcia_socket_suspend,
  98. .nr = 1,
  99. };
  100. static struct platform_device *sg2_pcmcia_device;
  101. static int __init sg2_pcmcia_init(void)
  102. {
  103. int ret;
  104. if (!machine_is_stargate2())
  105. return -ENODEV;
  106. sg2_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  107. if (!sg2_pcmcia_device)
  108. return -ENOMEM;
  109. ret = gpio_request_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
  110. if (ret)
  111. goto error_put_platform_device;
  112. ret = platform_device_add_data(sg2_pcmcia_device,
  113. &sg2_pcmcia_ops,
  114. sizeof(sg2_pcmcia_ops));
  115. if (ret)
  116. goto error_free_gpios;
  117. ret = platform_device_add(sg2_pcmcia_device);
  118. if (ret)
  119. goto error_free_gpios;
  120. return 0;
  121. error_free_gpios:
  122. gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
  123. error_put_platform_device:
  124. platform_device_put(sg2_pcmcia_device);
  125. return ret;
  126. }
  127. static void __exit sg2_pcmcia_exit(void)
  128. {
  129. platform_device_unregister(sg2_pcmcia_device);
  130. gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
  131. }
  132. fs_initcall(sg2_pcmcia_init);
  133. module_exit(sg2_pcmcia_exit);
  134. MODULE_LICENSE("GPL");
  135. MODULE_ALIAS("platform:pxa2xx-pcmcia");