mpc85xx_gpio.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright 2010 eXMeritus, A Boeing Company
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  17. * MA 02111-1307 USA
  18. */
  19. #ifndef POWERPC_ASM_MPC85XX_GPIO_H_
  20. #define POWERPC_ASM_MPC85XX_GPIO_H_
  21. # include <asm/immap_85xx.h>
  22. /*
  23. * The following internal functions are an MPC85XX-specific GPIO API which
  24. * allows setting and querying multiple GPIOs in a single operation.
  25. *
  26. * All of these look relatively large, but the arguments are almost always
  27. * constants, so they compile down to just a few instructions and a
  28. * memory-mapped IO operation or two.
  29. */
  30. static inline void mpc85xx_gpio_set(unsigned int mask,
  31. unsigned int dir, unsigned int val)
  32. {
  33. ccsr_gpio_t *gpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR + 0xc00);
  34. /* First mask off the unwanted parts of "dir" and "val" */
  35. dir &= mask;
  36. val &= mask;
  37. /* Now read in the values we're supposed to preserve */
  38. dir |= (in_be32(&gpio->gpdir) & ~mask);
  39. val |= (in_be32(&gpio->gpdat) & ~mask);
  40. /*
  41. * Poke the new output values first, then set the direction. This
  42. * helps to avoid transient data when switching from input to output
  43. * and vice versa.
  44. */
  45. out_be32(&gpio->gpdat, val);
  46. out_be32(&gpio->gpdir, dir);
  47. }
  48. static inline void mpc85xx_gpio_set_in(unsigned int gpios)
  49. {
  50. mpc85xx_gpio_set(gpios, 0x00000000, 0x00000000);
  51. }
  52. static inline void mpc85xx_gpio_set_low(unsigned int gpios)
  53. {
  54. mpc85xx_gpio_set(gpios, 0xFFFFFFFF, 0x00000000);
  55. }
  56. static inline void mpc85xx_gpio_set_high(unsigned int gpios)
  57. {
  58. mpc85xx_gpio_set(gpios, 0xFFFFFFFF, 0xFFFFFFFF);
  59. }
  60. static inline unsigned int mpc85xx_gpio_get(unsigned int mask)
  61. {
  62. ccsr_gpio_t *gpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR + 0xc00);
  63. /* Read the requested values */
  64. return in_be32(&gpio->gpdat) & mask;
  65. }
  66. /*
  67. * These implement the generic Linux GPIO API on top of the other functions
  68. * in this header.
  69. */
  70. static inline int gpio_request(unsigned gpio, const char *label)
  71. {
  72. /* Compatibility shim */
  73. return 0;
  74. }
  75. static inline void gpio_free(unsigned gpio)
  76. {
  77. /* Compatibility shim */
  78. }
  79. static inline int gpio_direction_input(unsigned gpio)
  80. {
  81. mpc85xx_gpio_set_in(1U << gpio);
  82. return 0;
  83. }
  84. static inline int gpio_direction_output(unsigned gpio, int value)
  85. {
  86. mpc85xx_gpio_set_low(1U << gpio);
  87. return 0;
  88. }
  89. static inline int gpio_get_value(unsigned gpio)
  90. {
  91. return !!mpc85xx_gpio_get(1U << gpio);
  92. }
  93. static inline void gpio_set_value(unsigned gpio, int value)
  94. {
  95. if (value)
  96. mpc85xx_gpio_set_high(1U << gpio);
  97. else
  98. mpc85xx_gpio_set_low(1U << gpio);
  99. }
  100. static inline int gpio_is_valid(int gpio)
  101. {
  102. return (gpio >= 0) && (gpio < 32);
  103. }
  104. #endif /* not POWERPC_ASM_MPC85XX_GPIO_H_ */