pxa2xx_balloon3.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * linux/drivers/pcmcia/pxa2xx_balloon3.c
  3. *
  4. * Balloon3 PCMCIA specific routines.
  5. *
  6. * Author: Nick Bane
  7. * Created: June, 2006
  8. * Copyright: Toby Churchill Ltd
  9. * Derived from pxa2xx_mainstone.c, by Nico Pitre
  10. *
  11. * Various modification by Marek Vasut <marek.vasut@gmail.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/gpio.h>
  19. #include <linux/errno.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/irq.h>
  23. #include <linux/io.h>
  24. #include <mach/balloon3.h>
  25. #include <asm/mach-types.h>
  26. #include "soc_common.h"
  27. /*
  28. * These are a list of interrupt sources that provokes a polled
  29. * check of status
  30. */
  31. static struct pcmcia_irqs irqs[] = {
  32. { 0, BALLOON3_S0_CD_IRQ, "PCMCIA0 CD" },
  33. { 0, BALLOON3_BP_NSTSCHG_IRQ, "PCMCIA0 STSCHG" },
  34. };
  35. static int balloon3_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  36. {
  37. uint16_t ver;
  38. ver = __raw_readw(BALLOON3_FPGA_VER);
  39. if (ver < 0x4f08)
  40. pr_warn("The FPGA code, version 0x%04x, is too old. "
  41. "PCMCIA/CF support might be broken in this version!",
  42. ver);
  43. skt->socket.pci_irq = BALLOON3_BP_CF_NRDY_IRQ;
  44. return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
  45. }
  46. static void balloon3_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  47. {
  48. soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
  49. }
  50. static unsigned long balloon3_pcmcia_status[2] = {
  51. BALLOON3_CF_nSTSCHG_BVD1,
  52. BALLOON3_CF_nSTSCHG_BVD1
  53. };
  54. static void balloon3_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  55. struct pcmcia_state *state)
  56. {
  57. uint16_t status;
  58. int flip;
  59. /* This actually reads the STATUS register */
  60. status = __raw_readw(BALLOON3_CF_STATUS_REG);
  61. flip = (status ^ balloon3_pcmcia_status[skt->nr])
  62. & BALLOON3_CF_nSTSCHG_BVD1;
  63. /*
  64. * Workaround for STSCHG which can't be deasserted:
  65. * We therefore disable/enable corresponding IRQs
  66. * as needed to avoid IRQ locks.
  67. */
  68. if (flip) {
  69. balloon3_pcmcia_status[skt->nr] = status;
  70. if (status & BALLOON3_CF_nSTSCHG_BVD1)
  71. enable_irq(BALLOON3_BP_NSTSCHG_IRQ);
  72. else
  73. disable_irq(BALLOON3_BP_NSTSCHG_IRQ);
  74. }
  75. state->detect = !gpio_get_value(BALLOON3_GPIO_S0_CD);
  76. state->ready = !!(status & BALLOON3_CF_nIRQ);
  77. state->bvd1 = !!(status & BALLOON3_CF_nSTSCHG_BVD1);
  78. state->bvd2 = 0; /* not available */
  79. state->vs_3v = 1; /* Always true its a CF card */
  80. state->vs_Xv = 0; /* not available */
  81. state->wrprot = 0; /* not available */
  82. }
  83. static int balloon3_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  84. const socket_state_t *state)
  85. {
  86. __raw_writew(BALLOON3_CF_RESET, BALLOON3_CF_CONTROL_REG |
  87. ((state->flags & SS_RESET) ?
  88. BALLOON3_FPGA_SETnCLR : 0));
  89. return 0;
  90. }
  91. static void balloon3_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  92. {
  93. }
  94. static void balloon3_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  95. {
  96. }
  97. static struct pcmcia_low_level balloon3_pcmcia_ops = {
  98. .owner = THIS_MODULE,
  99. .hw_init = balloon3_pcmcia_hw_init,
  100. .hw_shutdown = balloon3_pcmcia_hw_shutdown,
  101. .socket_state = balloon3_pcmcia_socket_state,
  102. .configure_socket = balloon3_pcmcia_configure_socket,
  103. .socket_init = balloon3_pcmcia_socket_init,
  104. .socket_suspend = balloon3_pcmcia_socket_suspend,
  105. .first = 0,
  106. .nr = 1,
  107. };
  108. static struct platform_device *balloon3_pcmcia_device;
  109. static int __init balloon3_pcmcia_init(void)
  110. {
  111. int ret;
  112. if (!machine_is_balloon3())
  113. return -ENODEV;
  114. balloon3_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  115. if (!balloon3_pcmcia_device)
  116. return -ENOMEM;
  117. ret = platform_device_add_data(balloon3_pcmcia_device,
  118. &balloon3_pcmcia_ops, sizeof(balloon3_pcmcia_ops));
  119. if (!ret)
  120. ret = platform_device_add(balloon3_pcmcia_device);
  121. if (ret)
  122. platform_device_put(balloon3_pcmcia_device);
  123. return ret;
  124. }
  125. static void __exit balloon3_pcmcia_exit(void)
  126. {
  127. platform_device_unregister(balloon3_pcmcia_device);
  128. }
  129. module_init(balloon3_pcmcia_init);
  130. module_exit(balloon3_pcmcia_exit);
  131. MODULE_LICENSE("GPL");
  132. MODULE_AUTHOR("Nick Bane <nick@cecomputing.co.uk>");
  133. MODULE_ALIAS("platform:pxa2xx-pcmcia");
  134. MODULE_DESCRIPTION("Balloon3 board CF/PCMCIA driver");