pxa2xx_trizeps4.c 6.0 KB

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