pxa2xx_balloon3.c 3.4 KB

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