gpio.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2007, OpenWrt.org, Florian Fainelli <florian@openwrt.org>
  3. * RDC321x architecture specific GPIO support
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #include <linux/autoconf.h>
  11. #include <linux/init.h>
  12. #include <linux/io.h>
  13. #include <linux/types.h>
  14. #include <linux/module.h>
  15. #include <linux/delay.h>
  16. #include <asm/mach-rdc321x/rdc321x_defs.h>
  17. static inline int rdc_gpio_is_valid(unsigned gpio)
  18. {
  19. return (gpio <= RDC_MAX_GPIO);
  20. }
  21. static unsigned int rdc_gpio_read(unsigned gpio)
  22. {
  23. unsigned int val;
  24. val = 0x80000000 | (7 << 11) | ((gpio&0x20?0x84:0x48));
  25. outl(val, RDC3210_CFGREG_ADDR);
  26. udelay(10);
  27. val = inl(RDC3210_CFGREG_DATA);
  28. val |= (0x1 << (gpio & 0x1F));
  29. outl(val, RDC3210_CFGREG_DATA);
  30. udelay(10);
  31. val = 0x80000000 | (7 << 11) | ((gpio&0x20?0x88:0x4C));
  32. outl(val, RDC3210_CFGREG_ADDR);
  33. udelay(10);
  34. val = inl(RDC3210_CFGREG_DATA);
  35. return val;
  36. }
  37. static void rdc_gpio_write(unsigned int val)
  38. {
  39. if (val) {
  40. outl(val, RDC3210_CFGREG_DATA);
  41. udelay(10);
  42. }
  43. }
  44. int rdc_gpio_get_value(unsigned gpio)
  45. {
  46. if (rdc_gpio_is_valid(gpio))
  47. return (int)rdc_gpio_read(gpio);
  48. else
  49. return -EINVAL;
  50. }
  51. EXPORT_SYMBOL(rdc_gpio_get_value);
  52. void rdc_gpio_set_value(unsigned gpio, int value)
  53. {
  54. unsigned int val;
  55. if (!rdc_gpio_is_valid(gpio))
  56. return;
  57. val = rdc_gpio_read(gpio);
  58. if (value)
  59. val &= ~(0x1 << (gpio & 0x1F));
  60. else
  61. val |= (0x1 << (gpio & 0x1F));
  62. rdc_gpio_write(val);
  63. }
  64. EXPORT_SYMBOL(rdc_gpio_set_value);
  65. int rdc_gpio_direction_input(unsigned gpio)
  66. {
  67. return 0;
  68. }
  69. EXPORT_SYMBOL(rdc_gpio_direction_input);
  70. int rdc_gpio_direction_output(unsigned gpio, int value)
  71. {
  72. return 0;
  73. }
  74. EXPORT_SYMBOL(rdc_gpio_direction_output);