pxa2xx_mainstone.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * linux/drivers/pcmcia/pxa2xx_mainstone.c
  3. *
  4. * Mainstone PCMCIA specific routines.
  5. *
  6. * Created: May 12, 2004
  7. * Author: Nicolas Pitre
  8. * Copyright: MontaVista Software Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <linux/errno.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/platform_device.h>
  20. #include <pcmcia/ss.h>
  21. #include <asm/mach-types.h>
  22. #include <asm/irq.h>
  23. #include <mach/pxa2xx-regs.h>
  24. #include <mach/mainstone.h>
  25. #include "soc_common.h"
  26. static struct pcmcia_irqs irqs[] = {
  27. { 0, MAINSTONE_S0_CD_IRQ, "PCMCIA0 CD" },
  28. { 1, MAINSTONE_S1_CD_IRQ, "PCMCIA1 CD" },
  29. { 0, MAINSTONE_S0_STSCHG_IRQ, "PCMCIA0 STSCHG" },
  30. { 1, MAINSTONE_S1_STSCHG_IRQ, "PCMCIA1 STSCHG" },
  31. };
  32. static int mst_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  33. {
  34. /*
  35. * Setup default state of GPIO outputs
  36. * before we enable them as outputs.
  37. */
  38. skt->socket.pci_irq = (skt->nr == 0) ? MAINSTONE_S0_IRQ : MAINSTONE_S1_IRQ;
  39. return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
  40. }
  41. static void mst_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  42. {
  43. soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
  44. }
  45. static unsigned long mst_pcmcia_status[2];
  46. static void mst_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  47. struct pcmcia_state *state)
  48. {
  49. unsigned long status, flip;
  50. status = (skt->nr == 0) ? MST_PCMCIA0 : MST_PCMCIA1;
  51. flip = (status ^ mst_pcmcia_status[skt->nr]) & MST_PCMCIA_nSTSCHG_BVD1;
  52. /*
  53. * Workaround for STSCHG which can't be deasserted:
  54. * We therefore disable/enable corresponding IRQs
  55. * as needed to avoid IRQ locks.
  56. */
  57. if (flip) {
  58. mst_pcmcia_status[skt->nr] = status;
  59. if (status & MST_PCMCIA_nSTSCHG_BVD1)
  60. enable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ
  61. : MAINSTONE_S1_STSCHG_IRQ );
  62. else
  63. disable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ
  64. : MAINSTONE_S1_STSCHG_IRQ );
  65. }
  66. state->detect = (status & MST_PCMCIA_nCD) ? 0 : 1;
  67. state->ready = (status & MST_PCMCIA_nIRQ) ? 1 : 0;
  68. state->bvd1 = (status & MST_PCMCIA_nSTSCHG_BVD1) ? 1 : 0;
  69. state->bvd2 = (status & MST_PCMCIA_nSPKR_BVD2) ? 1 : 0;
  70. state->vs_3v = (status & MST_PCMCIA_nVS1) ? 0 : 1;
  71. state->vs_Xv = (status & MST_PCMCIA_nVS2) ? 0 : 1;
  72. state->wrprot = 0; /* not available */
  73. }
  74. static int mst_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  75. const socket_state_t *state)
  76. {
  77. unsigned long power = 0;
  78. int ret = 0;
  79. switch (state->Vcc) {
  80. case 0: power |= MST_PCMCIA_PWR_VCC_0; break;
  81. case 33: power |= MST_PCMCIA_PWR_VCC_33; break;
  82. case 50: power |= MST_PCMCIA_PWR_VCC_50; break;
  83. default:
  84. printk(KERN_ERR "%s(): bad Vcc %u\n",
  85. __func__, state->Vcc);
  86. ret = -1;
  87. }
  88. switch (state->Vpp) {
  89. case 0: power |= MST_PCMCIA_PWR_VPP_0; break;
  90. case 120: power |= MST_PCMCIA_PWR_VPP_120; break;
  91. default:
  92. if(state->Vpp == state->Vcc) {
  93. power |= MST_PCMCIA_PWR_VPP_VCC;
  94. } else {
  95. printk(KERN_ERR "%s(): bad Vpp %u\n",
  96. __func__, state->Vpp);
  97. ret = -1;
  98. }
  99. }
  100. if (state->flags & SS_RESET)
  101. power |= MST_PCMCIA_RESET;
  102. switch (skt->nr) {
  103. case 0: MST_PCMCIA0 = power; break;
  104. case 1: MST_PCMCIA1 = power; break;
  105. default: ret = -1;
  106. }
  107. return ret;
  108. }
  109. static void mst_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  110. {
  111. }
  112. static void mst_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  113. {
  114. }
  115. static struct pcmcia_low_level mst_pcmcia_ops __initdata = {
  116. .owner = THIS_MODULE,
  117. .hw_init = mst_pcmcia_hw_init,
  118. .hw_shutdown = mst_pcmcia_hw_shutdown,
  119. .socket_state = mst_pcmcia_socket_state,
  120. .configure_socket = mst_pcmcia_configure_socket,
  121. .socket_init = mst_pcmcia_socket_init,
  122. .socket_suspend = mst_pcmcia_socket_suspend,
  123. .nr = 2,
  124. };
  125. static struct platform_device *mst_pcmcia_device;
  126. static int __init mst_pcmcia_init(void)
  127. {
  128. int ret;
  129. if (!machine_is_mainstone())
  130. return -ENODEV;
  131. mst_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  132. if (!mst_pcmcia_device)
  133. return -ENOMEM;
  134. ret = platform_device_add_data(mst_pcmcia_device, &mst_pcmcia_ops,
  135. sizeof(mst_pcmcia_ops));
  136. if (ret == 0)
  137. ret = platform_device_add(mst_pcmcia_device);
  138. if (ret)
  139. platform_device_put(mst_pcmcia_device);
  140. return ret;
  141. }
  142. static void __exit mst_pcmcia_exit(void)
  143. {
  144. platform_device_unregister(mst_pcmcia_device);
  145. }
  146. fs_initcall(mst_pcmcia_init);
  147. module_exit(mst_pcmcia_exit);
  148. MODULE_LICENSE("GPL");
  149. MODULE_ALIAS("platform:pxa2xx-pcmcia");