gpio.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2007 Google, Inc.
  3. * Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved.
  4. * Author: Mike Lockwood <lockwood@android.com>
  5. *
  6. * This software is licensed under the terms of the GNU General Public
  7. * License version 2, as published by the Free Software Foundation, and
  8. * may be copied, distributed, and modified under those terms.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #ifndef __ASM_ARCH_MSM_GPIO_H
  17. #define __ASM_ARCH_MSM_GPIO_H
  18. #include <asm-generic/gpio.h>
  19. #define gpio_get_value __gpio_get_value
  20. #define gpio_set_value __gpio_set_value
  21. #define gpio_cansleep __gpio_cansleep
  22. #define gpio_to_irq __gpio_to_irq
  23. /**
  24. * struct msm_gpio - GPIO pin description
  25. * @gpio_cfg - configuration bitmap, as per gpio_tlmm_config()
  26. * @label - textual label
  27. *
  28. * Usually, GPIO's are operated by sets.
  29. * This struct accumulate all GPIO information in single source
  30. * and facilitete group operations provided by msm_gpios_xxx()
  31. */
  32. struct msm_gpio {
  33. u32 gpio_cfg;
  34. const char *label;
  35. };
  36. /**
  37. * msm_gpios_request_enable() - request and enable set of GPIOs
  38. *
  39. * Request and configure set of GPIO's
  40. * In case of error, all operations rolled back.
  41. * Return error code.
  42. *
  43. * @table: GPIO table
  44. * @size: number of entries in @table
  45. */
  46. int msm_gpios_request_enable(const struct msm_gpio *table, int size);
  47. /**
  48. * msm_gpios_disable_free() - disable and free set of GPIOs
  49. *
  50. * @table: GPIO table
  51. * @size: number of entries in @table
  52. */
  53. void msm_gpios_disable_free(const struct msm_gpio *table, int size);
  54. /**
  55. * msm_gpios_request() - request set of GPIOs
  56. * In case of error, all operations rolled back.
  57. * Return error code.
  58. *
  59. * @table: GPIO table
  60. * @size: number of entries in @table
  61. */
  62. int msm_gpios_request(const struct msm_gpio *table, int size);
  63. /**
  64. * msm_gpios_free() - free set of GPIOs
  65. *
  66. * @table: GPIO table
  67. * @size: number of entries in @table
  68. */
  69. void msm_gpios_free(const struct msm_gpio *table, int size);
  70. /**
  71. * msm_gpios_enable() - enable set of GPIOs
  72. * In case of error, all operations rolled back.
  73. * Return error code.
  74. *
  75. * @table: GPIO table
  76. * @size: number of entries in @table
  77. */
  78. int msm_gpios_enable(const struct msm_gpio *table, int size);
  79. /**
  80. * msm_gpios_disable() - disable set of GPIOs
  81. *
  82. * @table: GPIO table
  83. * @size: number of entries in @table
  84. */
  85. void msm_gpios_disable(const struct msm_gpio *table, int size);
  86. /* GPIO TLMM (Top Level Multiplexing) Definitions */
  87. /* GPIO TLMM: Function -- GPIO specific */
  88. /* GPIO TLMM: Direction */
  89. enum {
  90. GPIO_INPUT,
  91. GPIO_OUTPUT,
  92. };
  93. /* GPIO TLMM: Pullup/Pulldown */
  94. enum {
  95. GPIO_NO_PULL,
  96. GPIO_PULL_DOWN,
  97. GPIO_KEEPER,
  98. GPIO_PULL_UP,
  99. };
  100. /* GPIO TLMM: Drive Strength */
  101. enum {
  102. GPIO_2MA,
  103. GPIO_4MA,
  104. GPIO_6MA,
  105. GPIO_8MA,
  106. GPIO_10MA,
  107. GPIO_12MA,
  108. GPIO_14MA,
  109. GPIO_16MA,
  110. };
  111. enum {
  112. GPIO_ENABLE,
  113. GPIO_DISABLE,
  114. };
  115. #define GPIO_CFG(gpio, func, dir, pull, drvstr) \
  116. ((((gpio) & 0x3FF) << 4) | \
  117. ((func) & 0xf) | \
  118. (((dir) & 0x1) << 14) | \
  119. (((pull) & 0x3) << 15) | \
  120. (((drvstr) & 0xF) << 17))
  121. /**
  122. * extract GPIO pin from bit-field used for gpio_tlmm_config
  123. */
  124. #define GPIO_PIN(gpio_cfg) (((gpio_cfg) >> 4) & 0x3ff)
  125. #define GPIO_FUNC(gpio_cfg) (((gpio_cfg) >> 0) & 0xf)
  126. #define GPIO_DIR(gpio_cfg) (((gpio_cfg) >> 14) & 0x1)
  127. #define GPIO_PULL(gpio_cfg) (((gpio_cfg) >> 15) & 0x3)
  128. #define GPIO_DRVSTR(gpio_cfg) (((gpio_cfg) >> 17) & 0xf)
  129. int gpio_tlmm_config(unsigned config, unsigned disable);
  130. #endif /* __ASM_ARCH_MSM_GPIO_H */