sa1100_nanoengine.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * drivers/pcmcia/sa1100_nanoengine.c
  3. *
  4. * PCMCIA implementation routines for BSI nanoEngine.
  5. *
  6. * In order to have a fully functional pcmcia subsystem in a BSE nanoEngine
  7. * board you should carefully read this:
  8. * http://cambuca.ldhs.cetuc.puc-rio.br/nanoengine/
  9. *
  10. * Copyright (C) 2010 Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br>
  11. *
  12. * Based on original work for kernel 2.4 by
  13. * Miguel Freitas <miguel@cpti.cetuc.puc-rio.br>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License version 2 as
  17. * published by the Free Software Foundation.
  18. *
  19. */
  20. #include <linux/device.h>
  21. #include <linux/errno.h>
  22. #include <linux/gpio.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <linux/init.h>
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/signal.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/irq.h>
  31. #include <mach/hardware.h>
  32. #include <mach/nanoengine.h>
  33. #include "sa1100_generic.h"
  34. struct nanoengine_pins {
  35. unsigned output_pins;
  36. unsigned clear_outputs;
  37. int gpio_rst;
  38. int gpio_cd;
  39. int gpio_rdy;
  40. };
  41. static struct nanoengine_pins nano_skts[] = {
  42. {
  43. .gpio_rst = GPIO_PC_RESET0,
  44. .gpio_cd = GPIO_PC_CD0,
  45. .gpio_rdy = GPIO_PC_READY0,
  46. }, {
  47. .gpio_rst = GPIO_PC_RESET1,
  48. .gpio_cd = GPIO_PC_CD1,
  49. .gpio_rdy = GPIO_PC_READY1,
  50. }
  51. };
  52. unsigned num_nano_pcmcia_sockets = ARRAY_SIZE(nano_skts);
  53. static int nanoengine_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  54. {
  55. unsigned i = skt->nr;
  56. int ret;
  57. if (i >= num_nano_pcmcia_sockets)
  58. return -ENXIO;
  59. ret = gpio_request_one(nano_skts[i].gpio_rst, GPIOF_OUT_INIT_LOW,
  60. i ? "PC RST1" : "PC RST0");
  61. if (ret)
  62. return ret;
  63. skt->stat[SOC_STAT_CD].gpio = nano_skts[i].gpio_cd;
  64. skt->stat[SOC_STAT_CD].name = i ? "PC CD1" : "PC CD0";
  65. skt->stat[SOC_STAT_RDY].gpio = nano_skts[i].gpio_rdy;
  66. skt->stat[SOC_STAT_RDY].name = i ? "PC RDY1" : "PC RDY0";
  67. return 0;
  68. }
  69. static void nanoengine_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  70. {
  71. gpio_free(nano_skts[skt->nr].gpio_rst);
  72. }
  73. static int nanoengine_pcmcia_configure_socket(
  74. struct soc_pcmcia_socket *skt, const socket_state_t *state)
  75. {
  76. unsigned i = skt->nr;
  77. if (i >= num_nano_pcmcia_sockets)
  78. return -ENXIO;
  79. gpio_set_value(nano_skts[skt->nr].gpio_rst, !!(state->flags & SS_RESET));
  80. return 0;
  81. }
  82. static void nanoengine_pcmcia_socket_state(
  83. struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
  84. {
  85. unsigned i = skt->nr;
  86. if (i >= num_nano_pcmcia_sockets)
  87. return;
  88. state->bvd1 = 1;
  89. state->bvd2 = 1;
  90. state->vs_3v = 1; /* Can only apply 3.3V */
  91. state->vs_Xv = 0;
  92. }
  93. static struct pcmcia_low_level nanoengine_pcmcia_ops = {
  94. .owner = THIS_MODULE,
  95. .hw_init = nanoengine_pcmcia_hw_init,
  96. .hw_shutdown = nanoengine_pcmcia_hw_shutdown,
  97. .configure_socket = nanoengine_pcmcia_configure_socket,
  98. .socket_state = nanoengine_pcmcia_socket_state,
  99. };
  100. int pcmcia_nanoengine_init(struct device *dev)
  101. {
  102. int ret = -ENODEV;
  103. if (machine_is_nanoengine())
  104. ret = sa11xx_drv_pcmcia_probe(
  105. dev, &nanoengine_pcmcia_ops, 0, 2);
  106. return ret;
  107. }