pxa2xx_e740.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Toshiba e740 PCMCIA specific routines.
  3. *
  4. * (c) 2004 Ian Molton <spyro@f2s.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/errno.h>
  14. #include <linux/gpio.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/platform_device.h>
  17. #include <mach/eseries-gpio.h>
  18. #include <asm/irq.h>
  19. #include <asm/mach-types.h>
  20. #include "soc_common.h"
  21. static struct pcmcia_irqs cd_irqs[] = {
  22. {
  23. .sock = 0,
  24. .irq = IRQ_GPIO(GPIO_E740_PCMCIA_CD0),
  25. .str = "CF card detect"
  26. },
  27. {
  28. .sock = 1,
  29. .irq = IRQ_GPIO(GPIO_E740_PCMCIA_CD1),
  30. .str = "Wifi switch"
  31. },
  32. };
  33. static int e740_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  34. {
  35. skt->socket.pci_irq = skt->nr == 0 ? IRQ_GPIO(GPIO_E740_PCMCIA_RDY0) :
  36. IRQ_GPIO(GPIO_E740_PCMCIA_RDY1);
  37. return soc_pcmcia_request_irqs(skt, &cd_irqs[skt->nr], 1);
  38. }
  39. /*
  40. * Release all resources.
  41. */
  42. static void e740_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  43. {
  44. soc_pcmcia_free_irqs(skt, &cd_irqs[skt->nr], 1);
  45. }
  46. static void e740_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  47. struct pcmcia_state *state)
  48. {
  49. if (skt->nr == 0) {
  50. state->detect = gpio_get_value(GPIO_E740_PCMCIA_CD0) ? 0 : 1;
  51. state->ready = gpio_get_value(GPIO_E740_PCMCIA_RDY0) ? 1 : 0;
  52. } else {
  53. state->detect = gpio_get_value(GPIO_E740_PCMCIA_CD1) ? 0 : 1;
  54. state->ready = gpio_get_value(GPIO_E740_PCMCIA_RDY1) ? 1 : 0;
  55. }
  56. state->vs_3v = 1;
  57. state->bvd1 = 1;
  58. state->bvd2 = 1;
  59. state->wrprot = 0;
  60. state->vs_Xv = 0;
  61. }
  62. static int e740_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  63. const socket_state_t *state)
  64. {
  65. if (state->flags & SS_RESET) {
  66. if (skt->nr == 0)
  67. gpio_set_value(GPIO_E740_PCMCIA_RST0, 1);
  68. else
  69. gpio_set_value(GPIO_E740_PCMCIA_RST1, 1);
  70. } else {
  71. if (skt->nr == 0)
  72. gpio_set_value(GPIO_E740_PCMCIA_RST0, 0);
  73. else
  74. gpio_set_value(GPIO_E740_PCMCIA_RST1, 0);
  75. }
  76. switch (state->Vcc) {
  77. case 0: /* Socket off */
  78. if (skt->nr == 0)
  79. gpio_set_value(GPIO_E740_PCMCIA_PWR0, 0);
  80. else
  81. gpio_set_value(GPIO_E740_PCMCIA_PWR1, 1);
  82. break;
  83. case 50:
  84. case 33: /* socket on */
  85. if (skt->nr == 0)
  86. gpio_set_value(GPIO_E740_PCMCIA_PWR0, 1);
  87. else
  88. gpio_set_value(GPIO_E740_PCMCIA_PWR1, 0);
  89. break;
  90. default:
  91. printk(KERN_ERR "e740_cs: Unsupported Vcc: %d\n", state->Vcc);
  92. }
  93. return 0;
  94. }
  95. /*
  96. * Enable card status IRQs on (re-)initialisation. This can
  97. * be called at initialisation, power management event, or
  98. * pcmcia event.
  99. */
  100. static void e740_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  101. {
  102. soc_pcmcia_enable_irqs(skt, cd_irqs, ARRAY_SIZE(cd_irqs));
  103. }
  104. /*
  105. * Disable card status IRQs on suspend.
  106. */
  107. static void e740_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  108. {
  109. soc_pcmcia_disable_irqs(skt, cd_irqs, ARRAY_SIZE(cd_irqs));
  110. }
  111. static struct pcmcia_low_level e740_pcmcia_ops = {
  112. .owner = THIS_MODULE,
  113. .hw_init = e740_pcmcia_hw_init,
  114. .hw_shutdown = e740_pcmcia_hw_shutdown,
  115. .socket_state = e740_pcmcia_socket_state,
  116. .configure_socket = e740_pcmcia_configure_socket,
  117. .socket_init = e740_pcmcia_socket_init,
  118. .socket_suspend = e740_pcmcia_socket_suspend,
  119. .nr = 2,
  120. };
  121. static struct platform_device *e740_pcmcia_device;
  122. static int __init e740_pcmcia_init(void)
  123. {
  124. int ret;
  125. if (!machine_is_e740())
  126. return -ENODEV;
  127. e740_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  128. if (!e740_pcmcia_device)
  129. return -ENOMEM;
  130. ret = platform_device_add_data(e740_pcmcia_device, &e740_pcmcia_ops,
  131. sizeof(e740_pcmcia_ops));
  132. if (!ret)
  133. ret = platform_device_add(e740_pcmcia_device);
  134. if (ret)
  135. platform_device_put(e740_pcmcia_device);
  136. return ret;
  137. }
  138. static void __exit e740_pcmcia_exit(void)
  139. {
  140. platform_device_unregister(e740_pcmcia_device);
  141. }
  142. module_init(e740_pcmcia_init);
  143. module_exit(e740_pcmcia_exit);
  144. MODULE_LICENSE("GPL v2");
  145. MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
  146. MODULE_ALIAS("platform:pxa2xx-pcmcia");
  147. MODULE_DESCRIPTION("e740 PCMCIA platform support");