sa1100_h3600.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * drivers/pcmcia/sa1100_h3600.c
  4. *
  5. * PCMCIA implementation routines for H3600
  6. *
  7. */
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/device.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/init.h>
  13. #include <linux/delay.h>
  14. #include <linux/gpio.h>
  15. #include <mach/hardware.h>
  16. #include <asm/irq.h>
  17. #include <asm/mach-types.h>
  18. #include <mach/h3xxx.h>
  19. #include "sa1100_generic.h"
  20. static int h3600_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  21. {
  22. int err;
  23. skt->stat[SOC_STAT_CD].name = skt->nr ? "pcmcia1-detect" : "pcmcia0-detect";
  24. skt->stat[SOC_STAT_RDY].name = skt->nr ? "pcmcia1-ready" : "pcmcia0-ready";
  25. err = soc_pcmcia_request_gpiods(skt);
  26. if (err)
  27. return err;
  28. switch (skt->nr) {
  29. case 0:
  30. err = gpio_request(H3XXX_EGPIO_OPT_NVRAM_ON, "OPT NVRAM ON");
  31. if (err)
  32. goto err01;
  33. err = gpio_direction_output(H3XXX_EGPIO_OPT_NVRAM_ON, 0);
  34. if (err)
  35. goto err03;
  36. err = gpio_request(H3XXX_EGPIO_OPT_ON, "OPT ON");
  37. if (err)
  38. goto err03;
  39. err = gpio_direction_output(H3XXX_EGPIO_OPT_ON, 0);
  40. if (err)
  41. goto err04;
  42. err = gpio_request(H3XXX_EGPIO_OPT_RESET, "OPT RESET");
  43. if (err)
  44. goto err04;
  45. err = gpio_direction_output(H3XXX_EGPIO_OPT_RESET, 0);
  46. if (err)
  47. goto err05;
  48. err = gpio_request(H3XXX_EGPIO_CARD_RESET, "PCMCIA CARD RESET");
  49. if (err)
  50. goto err05;
  51. err = gpio_direction_output(H3XXX_EGPIO_CARD_RESET, 0);
  52. if (err)
  53. goto err06;
  54. break;
  55. case 1:
  56. break;
  57. }
  58. return 0;
  59. err06: gpio_free(H3XXX_EGPIO_CARD_RESET);
  60. err05: gpio_free(H3XXX_EGPIO_OPT_RESET);
  61. err04: gpio_free(H3XXX_EGPIO_OPT_ON);
  62. err03: gpio_free(H3XXX_EGPIO_OPT_NVRAM_ON);
  63. err01: gpio_free(H3XXX_GPIO_PCMCIA_IRQ0);
  64. return err;
  65. }
  66. static void h3600_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  67. {
  68. switch (skt->nr) {
  69. case 0:
  70. /* Disable CF bus: */
  71. gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 0);
  72. gpio_set_value(H3XXX_EGPIO_OPT_ON, 0);
  73. gpio_set_value(H3XXX_EGPIO_OPT_RESET, 1);
  74. gpio_free(H3XXX_EGPIO_CARD_RESET);
  75. gpio_free(H3XXX_EGPIO_OPT_RESET);
  76. gpio_free(H3XXX_EGPIO_OPT_ON);
  77. gpio_free(H3XXX_EGPIO_OPT_NVRAM_ON);
  78. break;
  79. case 1:
  80. break;
  81. }
  82. }
  83. static void
  84. h3600_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
  85. {
  86. state->bvd1 = 0;
  87. state->bvd2 = 0;
  88. state->vs_3v = 0;
  89. state->vs_Xv = 0;
  90. }
  91. static int
  92. h3600_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
  93. {
  94. if (state->Vcc != 0 && state->Vcc != 33 && state->Vcc != 50) {
  95. printk(KERN_ERR "h3600_pcmcia: unrecognized Vcc %u.%uV\n",
  96. state->Vcc / 10, state->Vcc % 10);
  97. return -1;
  98. }
  99. gpio_set_value(H3XXX_EGPIO_CARD_RESET, !!(state->flags & SS_RESET));
  100. /* Silently ignore Vpp, output enable, speaker enable. */
  101. return 0;
  102. }
  103. static void h3600_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  104. {
  105. /* Enable CF bus: */
  106. gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 1);
  107. gpio_set_value(H3XXX_EGPIO_OPT_ON, 1);
  108. gpio_set_value(H3XXX_EGPIO_OPT_RESET, 0);
  109. msleep(10);
  110. }
  111. static void h3600_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  112. {
  113. /*
  114. * FIXME: This doesn't fit well. We don't have the mechanism in
  115. * the generic PCMCIA layer to deal with the idea of two sockets
  116. * on one bus. We rely on the cs.c behaviour shutting down
  117. * socket 0 then socket 1.
  118. */
  119. if (skt->nr == 1) {
  120. gpio_set_value(H3XXX_EGPIO_OPT_ON, 0);
  121. gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 0);
  122. /* hmm, does this suck power? */
  123. gpio_set_value(H3XXX_EGPIO_OPT_RESET, 1);
  124. }
  125. }
  126. struct pcmcia_low_level h3600_pcmcia_ops = {
  127. .owner = THIS_MODULE,
  128. .hw_init = h3600_pcmcia_hw_init,
  129. .hw_shutdown = h3600_pcmcia_hw_shutdown,
  130. .socket_state = h3600_pcmcia_socket_state,
  131. .configure_socket = h3600_pcmcia_configure_socket,
  132. .socket_init = h3600_pcmcia_socket_init,
  133. .socket_suspend = h3600_pcmcia_socket_suspend,
  134. };
  135. int pcmcia_h3600_init(struct device *dev)
  136. {
  137. int ret = -ENODEV;
  138. if (machine_is_h3600() || machine_is_h3100())
  139. ret = sa11xx_drv_pcmcia_probe(dev, &h3600_pcmcia_ops, 0, 2);
  140. return ret;
  141. }