pxa2xx_cm_x270.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * linux/drivers/pcmcia/pxa/pxa_cm_x270.c
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * Compulab Ltd., 2003, 2007
  9. * Mike Rapoport <mike@compulab.co.il>
  10. *
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/irq.h>
  16. #include <linux/delay.h>
  17. #include <pcmcia/ss.h>
  18. #include <asm/hardware.h>
  19. #include <asm/arch/pxa-regs.h>
  20. #include <asm/arch/pxa2xx-gpio.h>
  21. #include <asm/arch/cm-x270.h>
  22. #include "soc_common.h"
  23. static struct pcmcia_irqs irqs[] = {
  24. { 0, PCMCIA_S0_CD_VALID, "PCMCIA0 CD" },
  25. { 1, PCMCIA_S1_CD_VALID, "PCMCIA1 CD" },
  26. };
  27. static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  28. {
  29. GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) |
  30. GPIO_bit(GPIO49_nPWE) |
  31. GPIO_bit(GPIO50_nPIOR) |
  32. GPIO_bit(GPIO51_nPIOW) |
  33. GPIO_bit(GPIO85_nPCE_1) |
  34. GPIO_bit(GPIO54_nPCE_2);
  35. pxa_gpio_mode(GPIO48_nPOE_MD);
  36. pxa_gpio_mode(GPIO49_nPWE_MD);
  37. pxa_gpio_mode(GPIO50_nPIOR_MD);
  38. pxa_gpio_mode(GPIO51_nPIOW_MD);
  39. pxa_gpio_mode(GPIO85_nPCE_1_MD);
  40. pxa_gpio_mode(GPIO54_nPCE_2_MD);
  41. pxa_gpio_mode(GPIO55_nPREG_MD);
  42. pxa_gpio_mode(GPIO56_nPWAIT_MD);
  43. pxa_gpio_mode(GPIO57_nIOIS16_MD);
  44. /* Reset signal */
  45. pxa_gpio_mode(GPIO53_nPCE_2 | GPIO_OUT);
  46. GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
  47. set_irq_type(PCMCIA_S0_CD_VALID, IRQ_TYPE_EDGE_BOTH);
  48. set_irq_type(PCMCIA_S1_CD_VALID, IRQ_TYPE_EDGE_BOTH);
  49. /* irq's for slots: */
  50. set_irq_type(PCMCIA_S0_RDYINT, IRQ_TYPE_EDGE_FALLING);
  51. set_irq_type(PCMCIA_S1_RDYINT, IRQ_TYPE_EDGE_FALLING);
  52. skt->irq = (skt->nr == 0) ? PCMCIA_S0_RDYINT : PCMCIA_S1_RDYINT;
  53. return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
  54. }
  55. static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
  56. {
  57. soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
  58. set_irq_type(IRQ_TO_GPIO(PCMCIA_S0_CD_VALID), IRQ_TYPE_NONE);
  59. set_irq_type(IRQ_TO_GPIO(PCMCIA_S1_CD_VALID), IRQ_TYPE_NONE);
  60. set_irq_type(IRQ_TO_GPIO(PCMCIA_S0_RDYINT), IRQ_TYPE_NONE);
  61. set_irq_type(IRQ_TO_GPIO(PCMCIA_S1_RDYINT), IRQ_TYPE_NONE);
  62. }
  63. static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  64. struct pcmcia_state *state)
  65. {
  66. state->detect = (PCC_DETECT(skt->nr) == 0) ? 1 : 0;
  67. state->ready = (PCC_READY(skt->nr) == 0) ? 0 : 1;
  68. state->bvd1 = 1;
  69. state->bvd2 = 1;
  70. state->vs_3v = 0;
  71. state->vs_Xv = 0;
  72. state->wrprot = 0; /* not available */
  73. }
  74. static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  75. const socket_state_t *state)
  76. {
  77. GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
  78. pxa_gpio_mode(GPIO49_nPWE | GPIO_OUT);
  79. switch (skt->nr) {
  80. case 0:
  81. if (state->flags & SS_RESET) {
  82. GPCR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
  83. GPSR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
  84. udelay(10);
  85. GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
  86. GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
  87. }
  88. break;
  89. case 1:
  90. if (state->flags & SS_RESET) {
  91. GPCR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
  92. GPSR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
  93. udelay(10);
  94. GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
  95. GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
  96. }
  97. break;
  98. }
  99. pxa_gpio_mode(GPIO49_nPWE_MD);
  100. return 0;
  101. }
  102. static void cmx270_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  103. {
  104. }
  105. static void cmx270_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  106. {
  107. }
  108. static struct pcmcia_low_level cmx270_pcmcia_ops = {
  109. .owner = THIS_MODULE,
  110. .hw_init = cmx270_pcmcia_hw_init,
  111. .hw_shutdown = cmx270_pcmcia_shutdown,
  112. .socket_state = cmx270_pcmcia_socket_state,
  113. .configure_socket = cmx270_pcmcia_configure_socket,
  114. .socket_init = cmx270_pcmcia_socket_init,
  115. .socket_suspend = cmx270_pcmcia_socket_suspend,
  116. .nr = 2,
  117. };
  118. static struct platform_device *cmx270_pcmcia_device;
  119. static int __init cmx270_pcmcia_init(void)
  120. {
  121. int ret;
  122. cmx270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  123. if (!cmx270_pcmcia_device)
  124. return -ENOMEM;
  125. cmx270_pcmcia_device->dev.platform_data = &cmx270_pcmcia_ops;
  126. printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n");
  127. ret = platform_device_add(cmx270_pcmcia_device);
  128. if (ret)
  129. platform_device_put(cmx270_pcmcia_device);
  130. return ret;
  131. }
  132. static void __exit cmx270_pcmcia_exit(void)
  133. {
  134. platform_device_unregister(cmx270_pcmcia_device);
  135. }
  136. module_init(cmx270_pcmcia_init);
  137. module_exit(cmx270_pcmcia_exit);
  138. MODULE_LICENSE("GPL");
  139. MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
  140. MODULE_DESCRIPTION("CM-x270 PCMCIA driver");