pxa2xx_trizeps4.c 6.0 KB

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