pxa2xx_e740.c 4.1 KB

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