gpio.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * TI DaVinci GPIO Support
  3. *
  4. * Copyright (c) 2006 David Brownell
  5. * Copyright (c) 2007, MontaVista Software, Inc. <source@mvista.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #ifndef __DAVINCI_GPIO_H
  13. #define __DAVINCI_GPIO_H
  14. #include <asm-generic/gpio.h>
  15. #define __ARM_GPIOLIB_COMPLEX
  16. /* The inline versions use the static inlines in the driver header */
  17. #include "gpio-davinci.h"
  18. /*
  19. * The get/set/clear functions will inline when called with constant
  20. * parameters referencing built-in GPIOs, for low-overhead bitbanging.
  21. *
  22. * gpio_set_value() will inline only on traditional Davinci style controllers
  23. * with distinct set/clear registers.
  24. *
  25. * Otherwise, calls with variable parameters or referencing external
  26. * GPIOs (e.g. on GPIO expander chips) use outlined functions.
  27. */
  28. static inline void gpio_set_value(unsigned gpio, int value)
  29. {
  30. if (__builtin_constant_p(value) && gpio < davinci_soc_info.gpio_num) {
  31. struct davinci_gpio_controller *ctlr;
  32. u32 mask;
  33. ctlr = __gpio_to_controller(gpio);
  34. if (ctlr->set_data != ctlr->clr_data) {
  35. mask = __gpio_mask(gpio);
  36. if (value)
  37. __raw_writel(mask, ctlr->set_data);
  38. else
  39. __raw_writel(mask, ctlr->clr_data);
  40. return;
  41. }
  42. }
  43. __gpio_set_value(gpio, value);
  44. }
  45. /* Returns zero or nonzero; works for gpios configured as inputs OR
  46. * as outputs, at least for built-in GPIOs.
  47. *
  48. * NOTE: for built-in GPIOs, changes in reported values are synchronized
  49. * to the GPIO clock. This is easily seen after calling gpio_set_value()
  50. * and then immediately gpio_get_value(), where the gpio_get_value() will
  51. * return the old value until the GPIO clock ticks and the new value gets
  52. * latched.
  53. */
  54. static inline int gpio_get_value(unsigned gpio)
  55. {
  56. struct davinci_gpio_controller *ctlr;
  57. if (!__builtin_constant_p(gpio) || gpio >= davinci_soc_info.gpio_num)
  58. return __gpio_get_value(gpio);
  59. ctlr = __gpio_to_controller(gpio);
  60. return __gpio_mask(gpio) & __raw_readl(ctlr->in_data);
  61. }
  62. static inline int gpio_cansleep(unsigned gpio)
  63. {
  64. if (__builtin_constant_p(gpio) && gpio < davinci_soc_info.gpio_num)
  65. return 0;
  66. else
  67. return __gpio_cansleep(gpio);
  68. }
  69. static inline int irq_to_gpio(unsigned irq)
  70. {
  71. /* don't support the reverse mapping */
  72. return -ENOSYS;
  73. }
  74. #endif /* __DAVINCI_GPIO_H */