pxa2xx_trizeps4.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * linux/drivers/pcmcia/pxa2xx_trizeps4.c
  3. *
  4. * TRIZEPS PCMCIA specific routines.
  5. *
  6. * Author: Jürgen Schindele
  7. * Created: 20 02, 2006
  8. * Copyright: Jürgen Schindele
  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/gpio.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/platform_device.h>
  20. #include <asm/mach-types.h>
  21. #include <asm/irq.h>
  22. #include <mach/pxa2xx-regs.h>
  23. #include <mach/trizeps4.h>
  24. #include "soc_common.h"
  25. extern void board_pcmcia_power(int power);
  26. static struct pcmcia_irqs irqs[] = {
  27. { 0, IRQ_GPIO(GPIO_PCD), "cs0_cd" }
  28. /* on other baseboards we can have more inputs */
  29. };
  30. static int trizeps_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  31. {
  32. int ret, i;
  33. /* we dont have voltage/card/ready detection
  34. * so we dont need interrupts for it
  35. */
  36. switch (skt->nr) {
  37. case 0:
  38. if (gpio_request(GPIO_PRDY, "cf_irq") < 0) {
  39. pr_err("%s: sock %d unable to request gpio %d\n", __func__,
  40. skt->nr, GPIO_PRDY);
  41. return -EBUSY;
  42. }
  43. if (gpio_direction_input(GPIO_PRDY) < 0) {
  44. pr_err("%s: sock %d unable to set input gpio %d\n", __func__,
  45. skt->nr, GPIO_PRDY);
  46. gpio_free(GPIO_PRDY);
  47. return -EINVAL;
  48. }
  49. skt->socket.pci_irq = IRQ_GPIO(GPIO_PRDY);
  50. break;
  51. default:
  52. break;
  53. }
  54. /* release the reset of this card */
  55. pr_debug("%s: sock %d irq %d\n", __func__, skt->nr, skt->socket.pci_irq);
  56. /* supplementory irqs for the socket */
  57. for (i = 0; i < ARRAY_SIZE(irqs); i++) {
  58. if (irqs[i].sock != skt->nr)
  59. continue;
  60. if (gpio_request(irq_to_gpio(irqs[i].irq), irqs[i].str) < 0) {
  61. pr_err("%s: sock %d unable to request gpio %d\n",
  62. __func__, skt->nr, irq_to_gpio(irqs[i].irq));
  63. ret = -EBUSY;
  64. goto error;
  65. }
  66. if (gpio_direction_input(irq_to_gpio(irqs[i].irq)) < 0) {
  67. pr_err("%s: sock %d unable to set input gpio %d\n",
  68. __func__, skt->nr, irq_to_gpio(irqs[i].irq));
  69. ret = -EINVAL;
  70. goto error;
  71. }
  72. }
  73. return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
  74. error:
  75. for (; i >= 0; i--) {
  76. gpio_free(irq_to_gpio(irqs[i].irq));
  77. }
  78. return (ret);
  79. }
  80. static void trizeps_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  81. {
  82. int i;
  83. /* free allocated gpio's */
  84. gpio_free(GPIO_PRDY);
  85. for (i = 0; i < ARRAY_SIZE(irqs); i++)
  86. gpio_free(irq_to_gpio(irqs[i].irq));
  87. }
  88. static unsigned long trizeps_pcmcia_status[2];
  89. static void trizeps_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  90. struct pcmcia_state *state)
  91. {
  92. unsigned short status = 0, change;
  93. status = CFSR_readw();
  94. change = (status ^ trizeps_pcmcia_status[skt->nr]) &
  95. ConXS_CFSR_BVD_MASK;
  96. if (change) {
  97. trizeps_pcmcia_status[skt->nr] = status;
  98. if (status & ConXS_CFSR_BVD1) {
  99. /* enable_irq empty */
  100. } else {
  101. /* disable_irq empty */
  102. }
  103. }
  104. switch (skt->nr) {
  105. case 0:
  106. /* just fill in fix states */
  107. state->detect = gpio_get_value(GPIO_PCD) ? 0 : 1;
  108. state->ready = gpio_get_value(GPIO_PRDY) ? 1 : 0;
  109. state->bvd1 = (status & ConXS_CFSR_BVD1) ? 1 : 0;
  110. state->bvd2 = (status & ConXS_CFSR_BVD2) ? 1 : 0;
  111. state->vs_3v = (status & ConXS_CFSR_VS1) ? 0 : 1;
  112. state->vs_Xv = (status & ConXS_CFSR_VS2) ? 0 : 1;
  113. state->wrprot = 0; /* not available */
  114. break;
  115. #ifndef CONFIG_MACH_TRIZEPS_CONXS
  116. /* on ConXS we only have one slot. Second is inactive */
  117. case 1:
  118. state->detect = 0;
  119. state->ready = 0;
  120. state->bvd1 = 0;
  121. state->bvd2 = 0;
  122. state->vs_3v = 0;
  123. state->vs_Xv = 0;
  124. state->wrprot = 0;
  125. break;
  126. #endif
  127. }
  128. }
  129. static int trizeps_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  130. const socket_state_t *state)
  131. {
  132. int ret = 0;
  133. unsigned short power = 0;
  134. /* we do nothing here just check a bit */
  135. switch (state->Vcc) {
  136. case 0: power &= 0xfc; break;
  137. case 33: power |= ConXS_BCR_S0_VCC_3V3; break;
  138. case 50:
  139. pr_err("%s(): Vcc 5V not supported in socket\n", __func__);
  140. break;
  141. default:
  142. pr_err("%s(): bad Vcc %u\n", __func__, state->Vcc);
  143. ret = -1;
  144. }
  145. switch (state->Vpp) {
  146. case 0: power &= 0xf3; break;
  147. case 33: power |= ConXS_BCR_S0_VPP_3V3; break;
  148. case 120:
  149. pr_err("%s(): Vpp 12V not supported in socket\n", __func__);
  150. break;
  151. default:
  152. if (state->Vpp != state->Vcc) {
  153. pr_err("%s(): bad Vpp %u\n", __func__, state->Vpp);
  154. ret = -1;
  155. }
  156. }
  157. switch (skt->nr) {
  158. case 0: /* we only have 3.3V */
  159. board_pcmcia_power(power);
  160. break;
  161. #ifndef CONFIG_MACH_TRIZEPS_CONXS
  162. /* on ConXS we only have one slot. Second is inactive */
  163. case 1:
  164. #endif
  165. default:
  166. break;
  167. }
  168. return ret;
  169. }
  170. static void trizeps_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  171. {
  172. /* default is on */
  173. board_pcmcia_power(0x9);
  174. }
  175. static void trizeps_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  176. {
  177. board_pcmcia_power(0x0);
  178. }
  179. static struct pcmcia_low_level trizeps_pcmcia_ops = {
  180. .owner = THIS_MODULE,
  181. .hw_init = trizeps_pcmcia_hw_init,
  182. .hw_shutdown = trizeps_pcmcia_hw_shutdown,
  183. .socket_state = trizeps_pcmcia_socket_state,
  184. .configure_socket = trizeps_pcmcia_configure_socket,
  185. .socket_init = trizeps_pcmcia_socket_init,
  186. .socket_suspend = trizeps_pcmcia_socket_suspend,
  187. #ifdef CONFIG_MACH_TRIZEPS_CONXS
  188. .nr = 1,
  189. #else
  190. .nr = 2,
  191. #endif
  192. .first = 0,
  193. };
  194. static struct platform_device *trizeps_pcmcia_device;
  195. static int __init trizeps_pcmcia_init(void)
  196. {
  197. int ret;
  198. if (!machine_is_trizeps4() && !machine_is_trizeps4wl())
  199. return -ENODEV;
  200. trizeps_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  201. if (!trizeps_pcmcia_device)
  202. return -ENOMEM;
  203. ret = platform_device_add_data(trizeps_pcmcia_device,
  204. &trizeps_pcmcia_ops, sizeof(trizeps_pcmcia_ops));
  205. if (ret == 0)
  206. ret = platform_device_add(trizeps_pcmcia_device);
  207. if (ret)
  208. platform_device_put(trizeps_pcmcia_device);
  209. return ret;
  210. }
  211. static void __exit trizeps_pcmcia_exit(void)
  212. {
  213. platform_device_unregister(trizeps_pcmcia_device);
  214. }
  215. fs_initcall(trizeps_pcmcia_init);
  216. module_exit(trizeps_pcmcia_exit);
  217. MODULE_LICENSE("GPL");
  218. MODULE_AUTHOR("Juergen Schindele");
  219. MODULE_ALIAS("platform:pxa2xx-pcmcia");