pxa2xx_balloon3.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. static int balloon3_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  28. {
  29. uint16_t ver;
  30. ver = __raw_readw(BALLOON3_FPGA_VER);
  31. if (ver < 0x4f08)
  32. pr_warn("The FPGA code, version 0x%04x, is too old. "
  33. "PCMCIA/CF support might be broken in this version!",
  34. ver);
  35. skt->socket.pci_irq = BALLOON3_BP_CF_NRDY_IRQ;
  36. skt->stat[SOC_STAT_CD].gpio = BALLOON3_GPIO_S0_CD;
  37. skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD";
  38. skt->stat[SOC_STAT_BVD1].irq = BALLOON3_BP_NSTSCHG_IRQ;
  39. skt->stat[SOC_STAT_BVD1].name = "PCMCIA0 STSCHG";
  40. return 0;
  41. }
  42. static unsigned long balloon3_pcmcia_status[2] = {
  43. BALLOON3_CF_nSTSCHG_BVD1,
  44. BALLOON3_CF_nSTSCHG_BVD1
  45. };
  46. static void balloon3_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  47. struct pcmcia_state *state)
  48. {
  49. uint16_t status;
  50. int flip;
  51. /* This actually reads the STATUS register */
  52. status = __raw_readw(BALLOON3_CF_STATUS_REG);
  53. flip = (status ^ balloon3_pcmcia_status[skt->nr])
  54. & BALLOON3_CF_nSTSCHG_BVD1;
  55. /*
  56. * Workaround for STSCHG which can't be deasserted:
  57. * We therefore disable/enable corresponding IRQs
  58. * as needed to avoid IRQ locks.
  59. */
  60. if (flip) {
  61. balloon3_pcmcia_status[skt->nr] = status;
  62. if (status & BALLOON3_CF_nSTSCHG_BVD1)
  63. enable_irq(BALLOON3_BP_NSTSCHG_IRQ);
  64. else
  65. disable_irq(BALLOON3_BP_NSTSCHG_IRQ);
  66. }
  67. state->ready = !!(status & BALLOON3_CF_nIRQ);
  68. state->bvd1 = !!(status & BALLOON3_CF_nSTSCHG_BVD1);
  69. state->bvd2 = 0; /* not available */
  70. state->vs_3v = 1; /* Always true its a CF card */
  71. state->vs_Xv = 0; /* not available */
  72. }
  73. static int balloon3_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  74. const socket_state_t *state)
  75. {
  76. __raw_writew(BALLOON3_CF_RESET, BALLOON3_CF_CONTROL_REG +
  77. ((state->flags & SS_RESET) ?
  78. BALLOON3_FPGA_SETnCLR : 0));
  79. return 0;
  80. }
  81. static struct pcmcia_low_level balloon3_pcmcia_ops = {
  82. .owner = THIS_MODULE,
  83. .hw_init = balloon3_pcmcia_hw_init,
  84. .socket_state = balloon3_pcmcia_socket_state,
  85. .configure_socket = balloon3_pcmcia_configure_socket,
  86. .first = 0,
  87. .nr = 1,
  88. };
  89. static struct platform_device *balloon3_pcmcia_device;
  90. static int __init balloon3_pcmcia_init(void)
  91. {
  92. int ret;
  93. if (!machine_is_balloon3())
  94. return -ENODEV;
  95. balloon3_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  96. if (!balloon3_pcmcia_device)
  97. return -ENOMEM;
  98. ret = platform_device_add_data(balloon3_pcmcia_device,
  99. &balloon3_pcmcia_ops, sizeof(balloon3_pcmcia_ops));
  100. if (!ret)
  101. ret = platform_device_add(balloon3_pcmcia_device);
  102. if (ret)
  103. platform_device_put(balloon3_pcmcia_device);
  104. return ret;
  105. }
  106. static void __exit balloon3_pcmcia_exit(void)
  107. {
  108. platform_device_unregister(balloon3_pcmcia_device);
  109. }
  110. module_init(balloon3_pcmcia_init);
  111. module_exit(balloon3_pcmcia_exit);
  112. MODULE_LICENSE("GPL");
  113. MODULE_AUTHOR("Nick Bane <nick@cecomputing.co.uk>");
  114. MODULE_ALIAS("platform:pxa2xx-pcmcia");
  115. MODULE_DESCRIPTION("Balloon3 board CF/PCMCIA driver");