mpp.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef __PM8XXX_MPP_H
  13. #define __PM8XXX_MPP_H
  14. #include <linux/errno.h>
  15. #define PM8XXX_MPP_DEV_NAME "pm8xxx-mpp"
  16. struct pm8xxx_mpp_core_data {
  17. int base_addr;
  18. int nmpps;
  19. };
  20. struct pm8xxx_mpp_platform_data {
  21. struct pm8xxx_mpp_core_data core_data;
  22. int mpp_base;
  23. };
  24. /**
  25. * struct pm8xxx_mpp_config_data - structure to specify mpp configuration values
  26. * @type: MPP type which determines the overall MPP function (i.e. digital
  27. * in/out/bi, analog in/out, current sink, or test). It should be
  28. * set to the value of one of PM8XXX_MPP_TYPE_D_*.
  29. * @level: meaning depends upon MPP type specified
  30. * @control: meaning depends upon MPP type specified
  31. *
  32. * Usage of level argument:
  33. * 1. type = PM8XXX_MPP_TYPE_D_INPUT, PM8XXX_MPP_TYPE_D_OUTPUT,
  34. * PM8XXX_MPP_TYPE_D_BI_DIR, or PM8XXX_MPP_TYPE_DTEST_OUTPUT -
  35. *
  36. * level specifies that digital logic level to use for the MPP. It should
  37. * be set to the value of one of PM8XXX_MPP_DIG_LEVEL_*. Actual regulator
  38. * connections for these level choices are PMIC chip specific.
  39. *
  40. * 2. type = PM8XXX_MPP_TYPE_A_INPUT -
  41. *
  42. * level specifies where in the PMIC chip the analog input value should
  43. * be routed to. It should be set to the value of one of
  44. * PM8XXX_MPP_AIN_AMUX_*.
  45. *
  46. * 3. type = PM8XXX_MPP_TYPE_A_OUTPUT -
  47. *
  48. * level specifies the output analog voltage reference level. It should
  49. * be set to the value of one of PM8XXX_MPP_AOUT_LVL_*.
  50. *
  51. * 4. type = PM8XXX_MPP_TYPE_SINK or PM8XXX_MPP_TYPE_DTEST_SINK -
  52. *
  53. * level specifies the output current level. It should be set to the value
  54. * of one of PM8XXX_MPP_CS_OUT_*.
  55. *
  56. * Usage of control argument:
  57. * 1. type = PM8XXX_MPP_TYPE_D_INPUT -
  58. *
  59. * control specifies how the digital input should be routed in the chip.
  60. * It should be set to the value of one of PM8XXX_MPP_DIN_TO_*.
  61. *
  62. * 2. type = PM8XXX_MPP_TYPE_D_OUTPUT -
  63. *
  64. * control specifies the digital output value. It should be set to the
  65. * value of one of PM8XXX_MPP_DOUT_CTRL_*.
  66. *
  67. * 3. type = PM8XXX_MPP_TYPE_D_BI_DIR -
  68. *
  69. * control specifies the pullup resistor value. It should be set to the
  70. * value of one of PM8XXX_MPP_BI_PULLUP_*.
  71. *
  72. * 4. type = PM8XXX_MPP_TYPE_A_INPUT -
  73. *
  74. * control is unused; a value of 0 is sufficient.
  75. *
  76. * 5. type = PM8XXX_MPP_TYPE_A_OUTPUT -
  77. *
  78. * control specifies if analog output is enabled. It should be set to the
  79. * value of one of PM8XXX_MPP_AOUT_CTRL_*.
  80. *
  81. * 6. type = PM8XXX_MPP_TYPE_SINK -
  82. *
  83. * control specifies if current sinking is enabled. It should be set to
  84. * the value of one of PM8XXX_MPP_CS_CTRL_*.
  85. *
  86. * 7. type = PM8XXX_MPP_TYPE_DTEST_SINK -
  87. *
  88. * control specifies if current sinking is enabled. It should be set to
  89. * the value of one of PM8XXX_MPP_DTEST_CS_CTRL_*.
  90. *
  91. * 8. type = PM8XXX_MPP_TYPE_DTEST_OUTPUT -
  92. *
  93. * control specifies which DTEST bus value to output. It should be set to
  94. * the value of one of PM8XXX_MPP_DTEST_*.
  95. */
  96. struct pm8xxx_mpp_config_data {
  97. unsigned type;
  98. unsigned level;
  99. unsigned control;
  100. };
  101. /* API */
  102. #if defined(CONFIG_GPIO_PM8XXX_MPP) || defined(CONFIG_GPIO_PM8XXX_MPP_MODULE)
  103. /**
  104. * pm8xxx_mpp_config() - configure control options of a multi-purpose pin (MPP)
  105. * @mpp: global GPIO number corresponding to the MPP
  106. * @config: configuration to set for this MPP
  107. * Context: can sleep
  108. *
  109. * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
  110. */
  111. int pm8xxx_mpp_config(unsigned mpp, struct pm8xxx_mpp_config_data *config);
  112. #else
  113. static inline int pm8xxx_mpp_config(unsigned mpp,
  114. struct pm8xxx_mpp_config_data *config)
  115. {
  116. return -ENXIO;
  117. }
  118. #endif
  119. /* MPP Type: type */
  120. #define PM8XXX_MPP_TYPE_D_INPUT 0
  121. #define PM8XXX_MPP_TYPE_D_OUTPUT 1
  122. #define PM8XXX_MPP_TYPE_D_BI_DIR 2
  123. #define PM8XXX_MPP_TYPE_A_INPUT 3
  124. #define PM8XXX_MPP_TYPE_A_OUTPUT 4
  125. #define PM8XXX_MPP_TYPE_SINK 5
  126. #define PM8XXX_MPP_TYPE_DTEST_SINK 6
  127. #define PM8XXX_MPP_TYPE_DTEST_OUTPUT 7
  128. /* Digital Input/Output: level */
  129. #define PM8XXX_MPP_DIG_LEVEL_VIO_0 0
  130. #define PM8XXX_MPP_DIG_LEVEL_VIO_1 1
  131. #define PM8XXX_MPP_DIG_LEVEL_VIO_2 2
  132. #define PM8XXX_MPP_DIG_LEVEL_VIO_3 3
  133. #define PM8XXX_MPP_DIG_LEVEL_VIO_4 4
  134. #define PM8XXX_MPP_DIG_LEVEL_VIO_5 5
  135. #define PM8XXX_MPP_DIG_LEVEL_VIO_6 6
  136. #define PM8XXX_MPP_DIG_LEVEL_VIO_7 7
  137. /* Digital Input/Output: level [PM8058] */
  138. #define PM8058_MPP_DIG_LEVEL_VPH 0
  139. #define PM8058_MPP_DIG_LEVEL_S3 1
  140. #define PM8058_MPP_DIG_LEVEL_L2 2
  141. #define PM8058_MPP_DIG_LEVEL_L3 3
  142. /* Digital Input/Output: level [PM8901] */
  143. #define PM8901_MPP_DIG_LEVEL_MSMIO 0
  144. #define PM8901_MPP_DIG_LEVEL_DIG 1
  145. #define PM8901_MPP_DIG_LEVEL_L5 2
  146. #define PM8901_MPP_DIG_LEVEL_S4 3
  147. #define PM8901_MPP_DIG_LEVEL_VPH 4
  148. /* Digital Input/Output: level [PM8921] */
  149. #define PM8921_MPP_DIG_LEVEL_S4 1
  150. #define PM8921_MPP_DIG_LEVEL_L15 3
  151. #define PM8921_MPP_DIG_LEVEL_L17 4
  152. #define PM8921_MPP_DIG_LEVEL_VPH 7
  153. /* Digital Input/Output: level [PM8821] */
  154. #define PM8821_MPP_DIG_LEVEL_1P8 0
  155. #define PM8821_MPP_DIG_LEVEL_VPH 7
  156. /* Digital Input/Output: level [PM8018] */
  157. #define PM8018_MPP_DIG_LEVEL_L4 0
  158. #define PM8018_MPP_DIG_LEVEL_L14 1
  159. #define PM8018_MPP_DIG_LEVEL_S3 2
  160. #define PM8018_MPP_DIG_LEVEL_L6 3
  161. #define PM8018_MPP_DIG_LEVEL_L2 4
  162. #define PM8018_MPP_DIG_LEVEL_L5 5
  163. #define PM8018_MPP_DIG_LEVEL_VPH 7
  164. /* Digital Input/Output: level [PM8038] */
  165. #define PM8038_MPP_DIG_LEVEL_L20 0
  166. #define PM8038_MPP_DIG_LEVEL_L11 1
  167. #define PM8038_MPP_DIG_LEVEL_L5 2
  168. #define PM8038_MPP_DIG_LEVEL_L15 3
  169. #define PM8038_MPP_DIG_LEVEL_L17 4
  170. #define PM8038_MPP_DIG_LEVEL_VPH 7
  171. /* Digital Input: control */
  172. #define PM8XXX_MPP_DIN_TO_INT 0
  173. #define PM8XXX_MPP_DIN_TO_DBUS1 1
  174. #define PM8XXX_MPP_DIN_TO_DBUS2 2
  175. #define PM8XXX_MPP_DIN_TO_DBUS3 3
  176. /* Digital Output: control */
  177. #define PM8XXX_MPP_DOUT_CTRL_LOW 0
  178. #define PM8XXX_MPP_DOUT_CTRL_HIGH 1
  179. #define PM8XXX_MPP_DOUT_CTRL_MPP 2
  180. #define PM8XXX_MPP_DOUT_CTRL_INV_MPP 3
  181. /* Bidirectional: control */
  182. #define PM8XXX_MPP_BI_PULLUP_1KOHM 0
  183. #define PM8XXX_MPP_BI_PULLUP_OPEN 1
  184. #define PM8XXX_MPP_BI_PULLUP_10KOHM 2
  185. #define PM8XXX_MPP_BI_PULLUP_30KOHM 3
  186. /* Analog Input: level */
  187. #define PM8XXX_MPP_AIN_AMUX_CH5 0
  188. #define PM8XXX_MPP_AIN_AMUX_CH6 1
  189. #define PM8XXX_MPP_AIN_AMUX_CH7 2
  190. #define PM8XXX_MPP_AIN_AMUX_CH8 3
  191. #define PM8XXX_MPP_AIN_AMUX_CH9 4
  192. #define PM8XXX_MPP_AIN_AMUX_ABUS1 5
  193. #define PM8XXX_MPP_AIN_AMUX_ABUS2 6
  194. #define PM8XXX_MPP_AIN_AMUX_ABUS3 7
  195. /* Analog Output: level */
  196. #define PM8XXX_MPP_AOUT_LVL_1V25 0
  197. #define PM8XXX_MPP_AOUT_LVL_1V25_2 1
  198. #define PM8XXX_MPP_AOUT_LVL_0V625 2
  199. #define PM8XXX_MPP_AOUT_LVL_0V3125 3
  200. #define PM8XXX_MPP_AOUT_LVL_MPP 4
  201. #define PM8XXX_MPP_AOUT_LVL_ABUS1 5
  202. #define PM8XXX_MPP_AOUT_LVL_ABUS2 6
  203. #define PM8XXX_MPP_AOUT_LVL_ABUS3 7
  204. /* Analog Output: control */
  205. #define PM8XXX_MPP_AOUT_CTRL_DISABLE 0
  206. #define PM8XXX_MPP_AOUT_CTRL_ENABLE 1
  207. #define PM8XXX_MPP_AOUT_CTRL_MPP_HIGH_EN 2
  208. #define PM8XXX_MPP_AOUT_CTRL_MPP_LOW_EN 3
  209. /* Current Sink: level */
  210. #define PM8XXX_MPP_CS_OUT_5MA 0
  211. #define PM8XXX_MPP_CS_OUT_10MA 1
  212. #define PM8XXX_MPP_CS_OUT_15MA 2
  213. #define PM8XXX_MPP_CS_OUT_20MA 3
  214. #define PM8XXX_MPP_CS_OUT_25MA 4
  215. #define PM8XXX_MPP_CS_OUT_30MA 5
  216. #define PM8XXX_MPP_CS_OUT_35MA 6
  217. #define PM8XXX_MPP_CS_OUT_40MA 7
  218. /* Current Sink: control */
  219. #define PM8XXX_MPP_CS_CTRL_DISABLE 0
  220. #define PM8XXX_MPP_CS_CTRL_ENABLE 1
  221. #define PM8XXX_MPP_CS_CTRL_MPP_HIGH_EN 2
  222. #define PM8XXX_MPP_CS_CTRL_MPP_LOW_EN 3
  223. /* DTEST Current Sink: control */
  224. #define PM8XXX_MPP_DTEST_CS_CTRL_EN1 0
  225. #define PM8XXX_MPP_DTEST_CS_CTRL_EN2 1
  226. #define PM8XXX_MPP_DTEST_CS_CTRL_EN3 2
  227. #define PM8XXX_MPP_DTEST_CS_CTRL_EN4 3
  228. /* DTEST Digital Output: control */
  229. #define PM8XXX_MPP_DTEST_DBUS1 0
  230. #define PM8XXX_MPP_DTEST_DBUS2 1
  231. #define PM8XXX_MPP_DTEST_DBUS3 2
  232. #define PM8XXX_MPP_DTEST_DBUS4 3
  233. #endif