pxa2xx_cm_x270.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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/mach-types.h>
  20. #include <asm/arch/pxa-regs.h>
  21. #include <asm/arch/pxa2xx-gpio.h>
  22. #include <asm/arch/cm-x270.h>
  23. #include "soc_common.h"
  24. static struct pcmcia_irqs irqs[] = {
  25. { 0, PCMCIA_S0_CD_VALID, "PCMCIA0 CD" },
  26. { 1, PCMCIA_S1_CD_VALID, "PCMCIA1 CD" },
  27. };
  28. static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  29. {
  30. GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) |
  31. GPIO_bit(GPIO49_nPWE) |
  32. GPIO_bit(GPIO50_nPIOR) |
  33. GPIO_bit(GPIO51_nPIOW) |
  34. GPIO_bit(GPIO85_nPCE_1) |
  35. GPIO_bit(GPIO54_nPCE_2);
  36. pxa_gpio_mode(GPIO48_nPOE_MD);
  37. pxa_gpio_mode(GPIO49_nPWE_MD);
  38. pxa_gpio_mode(GPIO50_nPIOR_MD);
  39. pxa_gpio_mode(GPIO51_nPIOW_MD);
  40. pxa_gpio_mode(GPIO85_nPCE_1_MD);
  41. pxa_gpio_mode(GPIO54_nPCE_2_MD);
  42. pxa_gpio_mode(GPIO55_nPREG_MD);
  43. pxa_gpio_mode(GPIO56_nPWAIT_MD);
  44. pxa_gpio_mode(GPIO57_nIOIS16_MD);
  45. /* Reset signal */
  46. pxa_gpio_mode(GPIO53_nPCE_2 | GPIO_OUT);
  47. GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
  48. set_irq_type(PCMCIA_S0_CD_VALID, IRQ_TYPE_EDGE_BOTH);
  49. set_irq_type(PCMCIA_S1_CD_VALID, IRQ_TYPE_EDGE_BOTH);
  50. /* irq's for slots: */
  51. set_irq_type(PCMCIA_S0_RDYINT, IRQ_TYPE_EDGE_FALLING);
  52. set_irq_type(PCMCIA_S1_RDYINT, IRQ_TYPE_EDGE_FALLING);
  53. skt->irq = (skt->nr == 0) ? PCMCIA_S0_RDYINT : PCMCIA_S1_RDYINT;
  54. return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
  55. }
  56. static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
  57. {
  58. soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
  59. set_irq_type(IRQ_TO_GPIO(PCMCIA_S0_CD_VALID), IRQ_TYPE_NONE);
  60. set_irq_type(IRQ_TO_GPIO(PCMCIA_S1_CD_VALID), IRQ_TYPE_NONE);
  61. set_irq_type(IRQ_TO_GPIO(PCMCIA_S0_RDYINT), IRQ_TYPE_NONE);
  62. set_irq_type(IRQ_TO_GPIO(PCMCIA_S1_RDYINT), IRQ_TYPE_NONE);
  63. }
  64. static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  65. struct pcmcia_state *state)
  66. {
  67. state->detect = (PCC_DETECT(skt->nr) == 0) ? 1 : 0;
  68. state->ready = (PCC_READY(skt->nr) == 0) ? 0 : 1;
  69. state->bvd1 = 1;
  70. state->bvd2 = 1;
  71. state->vs_3v = 0;
  72. state->vs_Xv = 0;
  73. state->wrprot = 0; /* not available */
  74. }
  75. static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  76. const socket_state_t *state)
  77. {
  78. GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
  79. pxa_gpio_mode(GPIO49_nPWE | GPIO_OUT);
  80. switch (skt->nr) {
  81. case 0:
  82. if (state->flags & SS_RESET) {
  83. GPCR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
  84. GPSR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
  85. udelay(10);
  86. GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
  87. GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
  88. }
  89. break;
  90. case 1:
  91. if (state->flags & SS_RESET) {
  92. GPCR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
  93. GPSR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
  94. udelay(10);
  95. GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2);
  96. GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE);
  97. }
  98. break;
  99. }
  100. pxa_gpio_mode(GPIO49_nPWE_MD);
  101. return 0;
  102. }
  103. static void cmx270_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  104. {
  105. }
  106. static void cmx270_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  107. {
  108. }
  109. static struct pcmcia_low_level cmx270_pcmcia_ops __initdata = {
  110. .owner = THIS_MODULE,
  111. .hw_init = cmx270_pcmcia_hw_init,
  112. .hw_shutdown = cmx270_pcmcia_shutdown,
  113. .socket_state = cmx270_pcmcia_socket_state,
  114. .configure_socket = cmx270_pcmcia_configure_socket,
  115. .socket_init = cmx270_pcmcia_socket_init,
  116. .socket_suspend = cmx270_pcmcia_socket_suspend,
  117. .nr = 2,
  118. };
  119. static struct platform_device *cmx270_pcmcia_device;
  120. static int __init cmx270_pcmcia_init(void)
  121. {
  122. int ret;
  123. if (!machine_is_armcore())
  124. return -ENODEV;
  125. cmx270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  126. if (!cmx270_pcmcia_device)
  127. return -ENOMEM;
  128. ret = platform_device_add_data(cmx270_pcmcia_device, &cmx270_pcmcia_ops,
  129. sizeof(cmx270_pcmcia_ops));
  130. if (ret == 0) {
  131. printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n");
  132. ret = platform_device_add(cmx270_pcmcia_device);
  133. }
  134. if (ret)
  135. platform_device_put(cmx270_pcmcia_device);
  136. return ret;
  137. }
  138. static void __exit cmx270_pcmcia_exit(void)
  139. {
  140. platform_device_unregister(cmx270_pcmcia_device);
  141. }
  142. module_init(cmx270_pcmcia_init);
  143. module_exit(cmx270_pcmcia_exit);
  144. MODULE_LICENSE("GPL");
  145. MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
  146. MODULE_DESCRIPTION("CM-x270 PCMCIA driver");