gpio.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. /**
  19. * struct msm_gpio - GPIO pin description
  20. * @gpio_cfg - configuration bitmap, as per gpio_tlmm_config()
  21. * @label - textual label
  22. *
  23. * Usually, GPIO's are operated by sets.
  24. * This struct accumulate all GPIO information in single source
  25. * and facilitete group operations provided by msm_gpios_xxx()
  26. */
  27. struct msm_gpio {
  28. u32 gpio_cfg;
  29. const char *label;
  30. };
  31. /**
  32. * msm_gpios_request_enable() - request and enable set of GPIOs
  33. *
  34. * Request and configure set of GPIO's
  35. * In case of error, all operations rolled back.
  36. * Return error code.
  37. *
  38. * @table: GPIO table
  39. * @size: number of entries in @table
  40. */
  41. int msm_gpios_request_enable(const struct msm_gpio *table, int size);
  42. /**
  43. * msm_gpios_disable_free() - disable and free set of GPIOs
  44. *
  45. * @table: GPIO table
  46. * @size: number of entries in @table
  47. */
  48. void msm_gpios_disable_free(const struct msm_gpio *table, int size);
  49. /**
  50. * msm_gpios_request() - request set of GPIOs
  51. * In case of error, all operations rolled back.
  52. * Return error code.
  53. *
  54. * @table: GPIO table
  55. * @size: number of entries in @table
  56. */
  57. int msm_gpios_request(const struct msm_gpio *table, int size);
  58. /**
  59. * msm_gpios_free() - free set of GPIOs
  60. *
  61. * @table: GPIO table
  62. * @size: number of entries in @table
  63. */
  64. void msm_gpios_free(const struct msm_gpio *table, int size);
  65. /**
  66. * msm_gpios_enable() - enable set of GPIOs
  67. * In case of error, all operations rolled back.
  68. * Return error code.
  69. *
  70. * @table: GPIO table
  71. * @size: number of entries in @table
  72. */
  73. int msm_gpios_enable(const struct msm_gpio *table, int size);
  74. /**
  75. * msm_gpios_disable() - disable set of GPIOs
  76. *
  77. * @table: GPIO table
  78. * @size: number of entries in @table
  79. */
  80. void msm_gpios_disable(const struct msm_gpio *table, int size);
  81. /* GPIO TLMM (Top Level Multiplexing) Definitions */
  82. /* GPIO TLMM: Function -- GPIO specific */
  83. /* GPIO TLMM: Direction */
  84. enum {
  85. GPIO_INPUT,
  86. GPIO_OUTPUT,
  87. };
  88. /* GPIO TLMM: Pullup/Pulldown */
  89. enum {
  90. GPIO_NO_PULL,
  91. GPIO_PULL_DOWN,
  92. GPIO_KEEPER,
  93. GPIO_PULL_UP,
  94. };
  95. /* GPIO TLMM: Drive Strength */
  96. enum {
  97. GPIO_2MA,
  98. GPIO_4MA,
  99. GPIO_6MA,
  100. GPIO_8MA,
  101. GPIO_10MA,
  102. GPIO_12MA,
  103. GPIO_14MA,
  104. GPIO_16MA,
  105. };
  106. enum {
  107. GPIO_ENABLE,
  108. GPIO_DISABLE,
  109. };
  110. #define GPIO_CFG(gpio, func, dir, pull, drvstr) \
  111. ((((gpio) & 0x3FF) << 4) | \
  112. ((func) & 0xf) | \
  113. (((dir) & 0x1) << 14) | \
  114. (((pull) & 0x3) << 15) | \
  115. (((drvstr) & 0xF) << 17))
  116. /**
  117. * extract GPIO pin from bit-field used for gpio_tlmm_config
  118. */
  119. #define GPIO_PIN(gpio_cfg) (((gpio_cfg) >> 4) & 0x3ff)
  120. #define GPIO_FUNC(gpio_cfg) (((gpio_cfg) >> 0) & 0xf)
  121. #define GPIO_DIR(gpio_cfg) (((gpio_cfg) >> 14) & 0x1)
  122. #define GPIO_PULL(gpio_cfg) (((gpio_cfg) >> 15) & 0x3)
  123. #define GPIO_DRVSTR(gpio_cfg) (((gpio_cfg) >> 17) & 0xf)
  124. int gpio_tlmm_config(unsigned config, unsigned disable);
  125. #endif /* __ASM_ARCH_MSM_GPIO_H */