ar71xx_gpio.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * (C) Copyright 2010
  3. * Michael Kurz <michi.kurz@googlemail.com>.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef _AR71XX_GPIO_H
  24. #define _AR71XX_GPIO_H
  25. #include <common.h>
  26. #include <asm/ar71xx.h>
  27. static inline void ar71xx_setpin(uint8_t pin, uint8_t state)
  28. {
  29. uint32_t reg = readl(KSEG1ADDR(AR71XX_GPIO_BASE + GPIO_REG_OUT));
  30. if (state != 0) {
  31. reg |= (1 << pin);
  32. } else {
  33. reg &= ~(1 << pin);
  34. }
  35. writel(reg, KSEG1ADDR(AR71XX_GPIO_BASE + GPIO_REG_OUT));
  36. readl(KSEG1ADDR(AR71XX_GPIO_BASE + GPIO_REG_OUT));
  37. }
  38. static inline uint32_t ar71xx_getpin(uint8_t pin)
  39. {
  40. uint32_t reg = readl(KSEG1ADDR(AR71XX_GPIO_BASE + GPIO_REG_IN));
  41. return (((reg & (1 << pin)) != 0) ? 1 : 0);
  42. }
  43. static inline void ar71xx_setpindir(uint8_t pin, uint8_t direction)
  44. {
  45. uint32_t reg = readl(KSEG1ADDR(AR71XX_GPIO_BASE + GPIO_REG_OE));
  46. if (direction != 0) {
  47. reg |= (1 << pin);
  48. } else {
  49. reg &= ~(1 << pin);
  50. }
  51. writel(reg, KSEG1ADDR(AR71XX_GPIO_BASE + GPIO_REG_OE));
  52. readl(KSEG1ADDR(AR71XX_GPIO_BASE + GPIO_REG_OE));
  53. }
  54. #endif /* AR71XX_GPIO_H */