gpio.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * This program is free software; you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation; either version 2 of the License, or (at your
  5. * option) any later version.
  6. *
  7. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  8. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  10. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  11. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  12. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  13. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  14. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  16. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/module.h>
  23. #include <au1000.h>
  24. #include <au1xxx_gpio.h>
  25. #define gpio1 sys
  26. #if !defined(CONFIG_SOC_AU1000)
  27. static AU1X00_GPIO2 * const gpio2 = (AU1X00_GPIO2 *)GPIO2_BASE;
  28. #define GPIO2_OUTPUT_ENABLE_MASK 0x00010000
  29. int au1xxx_gpio2_read(int signal)
  30. {
  31. signal -= 200;
  32. /* gpio2->dir &= ~(0x01 << signal); //Set GPIO to input */
  33. return ((gpio2->pinstate >> signal) & 0x01);
  34. }
  35. void au1xxx_gpio2_write(int signal, int value)
  36. {
  37. signal -= 200;
  38. gpio2->output = (GPIO2_OUTPUT_ENABLE_MASK << signal) |
  39. (value << signal);
  40. }
  41. void au1xxx_gpio2_tristate(int signal)
  42. {
  43. signal -= 200;
  44. gpio2->dir &= ~(0x01 << signal); /* Set GPIO to input */
  45. }
  46. #endif
  47. int au1xxx_gpio1_read(int signal)
  48. {
  49. /* gpio1->trioutclr |= (0x01 << signal); */
  50. return ((gpio1->pinstaterd >> signal) & 0x01);
  51. }
  52. void au1xxx_gpio1_write(int signal, int value)
  53. {
  54. if(value)
  55. gpio1->outputset = (0x01 << signal);
  56. else
  57. gpio1->outputclr = (0x01 << signal); /* Output a Zero */
  58. }
  59. void au1xxx_gpio1_tristate(int signal)
  60. {
  61. gpio1->trioutclr = (0x01 << signal); /* Tristate signal */
  62. }
  63. int au1xxx_gpio_read(int signal)
  64. {
  65. if(signal >= 200)
  66. #if defined(CONFIG_SOC_AU1000)
  67. return 0;
  68. #else
  69. return au1xxx_gpio2_read(signal);
  70. #endif
  71. else
  72. return au1xxx_gpio1_read(signal);
  73. }
  74. void au1xxx_gpio_write(int signal, int value)
  75. {
  76. if(signal >= 200)
  77. #if defined(CONFIG_SOC_AU1000)
  78. ;
  79. #else
  80. au1xxx_gpio2_write(signal, value);
  81. #endif
  82. else
  83. au1xxx_gpio1_write(signal, value);
  84. }
  85. void au1xxx_gpio_tristate(int signal)
  86. {
  87. if(signal >= 200)
  88. #if defined(CONFIG_SOC_AU1000)
  89. ;
  90. #else
  91. au1xxx_gpio2_tristate(signal);
  92. #endif
  93. else
  94. au1xxx_gpio1_tristate(signal);
  95. }
  96. void au1xxx_gpio1_set_inputs(void)
  97. {
  98. gpio1->pininputen = 0;
  99. }
  100. EXPORT_SYMBOL(au1xxx_gpio1_set_inputs);
  101. EXPORT_SYMBOL(au1xxx_gpio_tristate);
  102. EXPORT_SYMBOL(au1xxx_gpio_write);
  103. EXPORT_SYMBOL(au1xxx_gpio_read);