sa1100_h3600.c 4.1 KB

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