sa1100_nanoengine.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * drivers/pcmcia/sa1100_nanoengine.c
  3. *
  4. * PCMCIA implementation routines for BSI nanoEngine.
  5. *
  6. * In order to have a fully functional pcmcia subsystem in a BSE nanoEngine
  7. * board you should carefully read this:
  8. * http://cambuca.ldhs.cetuc.puc-rio.br/nanoengine/
  9. *
  10. * Copyright (C) 2010 Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br>
  11. *
  12. * Based on original work for kernel 2.4 by
  13. * Miguel Freitas <miguel@cpti.cetuc.puc-rio.br>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License version 2 as
  17. * published by the Free Software Foundation.
  18. *
  19. */
  20. #include <linux/device.h>
  21. #include <linux/errno.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/irq.h>
  24. #include <linux/init.h>
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/signal.h>
  28. #include <asm/mach-types.h>
  29. #include <asm/irq.h>
  30. #include <mach/hardware.h>
  31. #include <mach/nanoengine.h>
  32. #include "sa1100_generic.h"
  33. static struct pcmcia_irqs irqs_skt0[] = {
  34. /* socket, IRQ, name */
  35. { 0, NANOENGINE_IRQ_GPIO_PC_CD0, "PC CD0" },
  36. };
  37. static struct pcmcia_irqs irqs_skt1[] = {
  38. /* socket, IRQ, name */
  39. { 1, NANOENGINE_IRQ_GPIO_PC_CD1, "PC CD1" },
  40. };
  41. struct nanoengine_pins {
  42. unsigned input_pins;
  43. unsigned output_pins;
  44. unsigned clear_outputs;
  45. unsigned transition_pins;
  46. unsigned pci_irq;
  47. struct pcmcia_irqs *pcmcia_irqs;
  48. unsigned pcmcia_irqs_size;
  49. };
  50. static struct nanoengine_pins nano_skts[] = {
  51. {
  52. .input_pins = GPIO_PC_READY0 | GPIO_PC_CD0,
  53. .output_pins = GPIO_PC_RESET0,
  54. .clear_outputs = GPIO_PC_RESET0,
  55. .transition_pins = NANOENGINE_IRQ_GPIO_PC_CD0,
  56. .pci_irq = NANOENGINE_IRQ_GPIO_PC_READY0,
  57. .pcmcia_irqs = irqs_skt0,
  58. .pcmcia_irqs_size = ARRAY_SIZE(irqs_skt0)
  59. }, {
  60. .input_pins = GPIO_PC_READY1 | GPIO_PC_CD1,
  61. .output_pins = GPIO_PC_RESET1,
  62. .clear_outputs = GPIO_PC_RESET1,
  63. .transition_pins = NANOENGINE_IRQ_GPIO_PC_CD1,
  64. .pci_irq = NANOENGINE_IRQ_GPIO_PC_READY1,
  65. .pcmcia_irqs = irqs_skt1,
  66. .pcmcia_irqs_size = ARRAY_SIZE(irqs_skt1)
  67. }
  68. };
  69. unsigned num_nano_pcmcia_sockets = ARRAY_SIZE(nano_skts);
  70. static int nanoengine_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  71. {
  72. unsigned i = skt->nr;
  73. if (i >= num_nano_pcmcia_sockets)
  74. return -ENXIO;
  75. GPDR &= ~nano_skts[i].input_pins;
  76. GPDR |= nano_skts[i].output_pins;
  77. GPCR = nano_skts[i].clear_outputs;
  78. irq_set_irq_type(nano_skts[i].transition_pins, IRQ_TYPE_EDGE_BOTH);
  79. skt->socket.pci_irq = nano_skts[i].pci_irq;
  80. return soc_pcmcia_request_irqs(skt,
  81. nano_skts[i].pcmcia_irqs, nano_skts[i].pcmcia_irqs_size);
  82. }
  83. /*
  84. * Release all resources.
  85. */
  86. static void nanoengine_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  87. {
  88. unsigned i = skt->nr;
  89. if (i >= num_nano_pcmcia_sockets)
  90. return;
  91. soc_pcmcia_free_irqs(skt,
  92. nano_skts[i].pcmcia_irqs, nano_skts[i].pcmcia_irqs_size);
  93. }
  94. static int nanoengine_pcmcia_configure_socket(
  95. struct soc_pcmcia_socket *skt, const socket_state_t *state)
  96. {
  97. unsigned reset;
  98. unsigned i = skt->nr;
  99. if (i >= num_nano_pcmcia_sockets)
  100. return -ENXIO;
  101. switch (i) {
  102. case 0:
  103. reset = GPIO_PC_RESET0;
  104. break;
  105. case 1:
  106. reset = GPIO_PC_RESET1;
  107. break;
  108. default:
  109. return -ENXIO;
  110. }
  111. if (state->flags & SS_RESET)
  112. GPSR = reset;
  113. else
  114. GPCR = reset;
  115. return 0;
  116. }
  117. static void nanoengine_pcmcia_socket_state(
  118. struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
  119. {
  120. unsigned long levels = GPLR;
  121. unsigned i = skt->nr;
  122. if (i >= num_nano_pcmcia_sockets)
  123. return;
  124. memset(state, 0, sizeof(struct pcmcia_state));
  125. switch (i) {
  126. case 0:
  127. state->ready = (levels & GPIO_PC_READY0) ? 1 : 0;
  128. state->detect = !(levels & GPIO_PC_CD0) ? 1 : 0;
  129. break;
  130. case 1:
  131. state->ready = (levels & GPIO_PC_READY1) ? 1 : 0;
  132. state->detect = !(levels & GPIO_PC_CD1) ? 1 : 0;
  133. break;
  134. default:
  135. return;
  136. }
  137. state->bvd1 = 1;
  138. state->bvd2 = 1;
  139. state->wrprot = 0; /* Not available */
  140. state->vs_3v = 1; /* Can only apply 3.3V */
  141. state->vs_Xv = 0;
  142. }
  143. /*
  144. * Enable card status IRQs on (re-)initialisation. This can
  145. * be called at initialisation, power management event, or
  146. * pcmcia event.
  147. */
  148. static void nanoengine_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  149. {
  150. unsigned i = skt->nr;
  151. if (i >= num_nano_pcmcia_sockets)
  152. return;
  153. soc_pcmcia_enable_irqs(skt,
  154. nano_skts[i].pcmcia_irqs, nano_skts[i].pcmcia_irqs_size);
  155. }
  156. /*
  157. * Disable card status IRQs on suspend.
  158. */
  159. static void nanoengine_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  160. {
  161. unsigned i = skt->nr;
  162. if (i >= num_nano_pcmcia_sockets)
  163. return;
  164. soc_pcmcia_disable_irqs(skt,
  165. nano_skts[i].pcmcia_irqs, nano_skts[i].pcmcia_irqs_size);
  166. }
  167. static struct pcmcia_low_level nanoengine_pcmcia_ops = {
  168. .owner = THIS_MODULE,
  169. .hw_init = nanoengine_pcmcia_hw_init,
  170. .hw_shutdown = nanoengine_pcmcia_hw_shutdown,
  171. .configure_socket = nanoengine_pcmcia_configure_socket,
  172. .socket_state = nanoengine_pcmcia_socket_state,
  173. .socket_init = nanoengine_pcmcia_socket_init,
  174. .socket_suspend = nanoengine_pcmcia_socket_suspend,
  175. };
  176. int pcmcia_nanoengine_init(struct device *dev)
  177. {
  178. int ret = -ENODEV;
  179. if (machine_is_nanoengine())
  180. ret = sa11xx_drv_pcmcia_probe(
  181. dev, &nanoengine_pcmcia_ops, 0, 2);
  182. return ret;
  183. }