sa1100_h3600.c 4.1 KB

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