pxa2xx_trizeps4.c 6.0 KB

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