pxa2xx_stargate2.c 4.3 KB

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