pxa2xx_trizeps4.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 int trizeps_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  27. {
  28. /* we dont have voltage/card/ready detection
  29. * so we dont need interrupts for it
  30. */
  31. switch (skt->nr) {
  32. case 0:
  33. skt->stat[SOC_STAT_CD].gpio = GPIO_PCD;
  34. skt->stat[SOC_STAT_CD].name = "cs0_cd";
  35. skt->stat[SOC_STAT_RDY].gpio = GPIO_PRDY;
  36. skt->stat[SOC_STAT_RDY].name = "cs0_rdy";
  37. break;
  38. default:
  39. break;
  40. }
  41. /* release the reset of this card */
  42. pr_debug("%s: sock %d irq %d\n", __func__, skt->nr, skt->socket.pci_irq);
  43. return 0;
  44. }
  45. static unsigned long trizeps_pcmcia_status[2];
  46. static void trizeps_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  47. struct pcmcia_state *state)
  48. {
  49. unsigned short status = 0, change;
  50. status = CFSR_readw();
  51. change = (status ^ trizeps_pcmcia_status[skt->nr]) &
  52. ConXS_CFSR_BVD_MASK;
  53. if (change) {
  54. trizeps_pcmcia_status[skt->nr] = status;
  55. if (status & ConXS_CFSR_BVD1) {
  56. /* enable_irq empty */
  57. } else {
  58. /* disable_irq empty */
  59. }
  60. }
  61. switch (skt->nr) {
  62. case 0:
  63. /* just fill in fix states */
  64. state->bvd1 = (status & ConXS_CFSR_BVD1) ? 1 : 0;
  65. state->bvd2 = (status & ConXS_CFSR_BVD2) ? 1 : 0;
  66. state->vs_3v = (status & ConXS_CFSR_VS1) ? 0 : 1;
  67. state->vs_Xv = (status & ConXS_CFSR_VS2) ? 0 : 1;
  68. break;
  69. #ifndef CONFIG_MACH_TRIZEPS_CONXS
  70. /* on ConXS we only have one slot. Second is inactive */
  71. case 1:
  72. state->detect = 0;
  73. state->ready = 0;
  74. state->bvd1 = 0;
  75. state->bvd2 = 0;
  76. state->vs_3v = 0;
  77. state->vs_Xv = 0;
  78. break;
  79. #endif
  80. }
  81. }
  82. static int trizeps_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  83. const socket_state_t *state)
  84. {
  85. int ret = 0;
  86. unsigned short power = 0;
  87. /* we do nothing here just check a bit */
  88. switch (state->Vcc) {
  89. case 0: power &= 0xfc; break;
  90. case 33: power |= ConXS_BCR_S0_VCC_3V3; break;
  91. case 50:
  92. pr_err("%s(): Vcc 5V not supported in socket\n", __func__);
  93. break;
  94. default:
  95. pr_err("%s(): bad Vcc %u\n", __func__, state->Vcc);
  96. ret = -1;
  97. }
  98. switch (state->Vpp) {
  99. case 0: power &= 0xf3; break;
  100. case 33: power |= ConXS_BCR_S0_VPP_3V3; break;
  101. case 120:
  102. pr_err("%s(): Vpp 12V not supported in socket\n", __func__);
  103. break;
  104. default:
  105. if (state->Vpp != state->Vcc) {
  106. pr_err("%s(): bad Vpp %u\n", __func__, state->Vpp);
  107. ret = -1;
  108. }
  109. }
  110. switch (skt->nr) {
  111. case 0: /* we only have 3.3V */
  112. board_pcmcia_power(power);
  113. break;
  114. #ifndef CONFIG_MACH_TRIZEPS_CONXS
  115. /* on ConXS we only have one slot. Second is inactive */
  116. case 1:
  117. #endif
  118. default:
  119. break;
  120. }
  121. return ret;
  122. }
  123. static void trizeps_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  124. {
  125. /* default is on */
  126. board_pcmcia_power(0x9);
  127. }
  128. static void trizeps_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  129. {
  130. board_pcmcia_power(0x0);
  131. }
  132. static struct pcmcia_low_level trizeps_pcmcia_ops = {
  133. .owner = THIS_MODULE,
  134. .hw_init = trizeps_pcmcia_hw_init,
  135. .socket_state = trizeps_pcmcia_socket_state,
  136. .configure_socket = trizeps_pcmcia_configure_socket,
  137. .socket_init = trizeps_pcmcia_socket_init,
  138. .socket_suspend = trizeps_pcmcia_socket_suspend,
  139. #ifdef CONFIG_MACH_TRIZEPS_CONXS
  140. .nr = 1,
  141. #else
  142. .nr = 2,
  143. #endif
  144. .first = 0,
  145. };
  146. static struct platform_device *trizeps_pcmcia_device;
  147. static int __init trizeps_pcmcia_init(void)
  148. {
  149. int ret;
  150. if (!machine_is_trizeps4() && !machine_is_trizeps4wl())
  151. return -ENODEV;
  152. trizeps_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  153. if (!trizeps_pcmcia_device)
  154. return -ENOMEM;
  155. ret = platform_device_add_data(trizeps_pcmcia_device,
  156. &trizeps_pcmcia_ops, sizeof(trizeps_pcmcia_ops));
  157. if (ret == 0)
  158. ret = platform_device_add(trizeps_pcmcia_device);
  159. if (ret)
  160. platform_device_put(trizeps_pcmcia_device);
  161. return ret;
  162. }
  163. static void __exit trizeps_pcmcia_exit(void)
  164. {
  165. platform_device_unregister(trizeps_pcmcia_device);
  166. }
  167. fs_initcall(trizeps_pcmcia_init);
  168. module_exit(trizeps_pcmcia_exit);
  169. MODULE_LICENSE("GPL");
  170. MODULE_AUTHOR("Juergen Schindele");
  171. MODULE_ALIAS("platform:pxa2xx-pcmcia");