pinctrl-mtk-common-v2.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2018 MediaTek Inc.
  4. *
  5. * Author: Sean Wang <sean.wang@mediatek.com>
  6. *
  7. */
  8. #ifndef __PINCTRL_MTK_COMMON_V2_H
  9. #define __PINCTRL_MTK_COMMON_V2_H
  10. #include <linux/gpio/driver.h>
  11. #define MTK_INPUT 0
  12. #define MTK_OUTPUT 1
  13. #define MTK_DISABLE 0
  14. #define MTK_ENABLE 1
  15. #define MTK_PULLDOWN 0
  16. #define MTK_PULLUP 1
  17. #define EINT_NA U16_MAX
  18. #define NO_EINT_SUPPORT EINT_NA
  19. #define PIN_FIELD_CALC(_s_pin, _e_pin, _i_base, _s_addr, _x_addrs, \
  20. _s_bit, _x_bits, _sz_reg, _fixed) { \
  21. .s_pin = _s_pin, \
  22. .e_pin = _e_pin, \
  23. .i_base = _i_base, \
  24. .s_addr = _s_addr, \
  25. .x_addrs = _x_addrs, \
  26. .s_bit = _s_bit, \
  27. .x_bits = _x_bits, \
  28. .sz_reg = _sz_reg, \
  29. .fixed = _fixed, \
  30. }
  31. #define PIN_FIELD(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits) \
  32. PIN_FIELD_CALC(_s_pin, _e_pin, 0, _s_addr, _x_addrs, _s_bit, \
  33. _x_bits, 32, 0)
  34. #define PINS_FIELD(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits) \
  35. PIN_FIELD_CALC(_s_pin, _e_pin, 0, _s_addr, _x_addrs, _s_bit, \
  36. _x_bits, 32, 1)
  37. /* List these attributes which could be modified for the pin */
  38. enum {
  39. PINCTRL_PIN_REG_MODE,
  40. PINCTRL_PIN_REG_DIR,
  41. PINCTRL_PIN_REG_DI,
  42. PINCTRL_PIN_REG_DO,
  43. PINCTRL_PIN_REG_SR,
  44. PINCTRL_PIN_REG_SMT,
  45. PINCTRL_PIN_REG_PD,
  46. PINCTRL_PIN_REG_PU,
  47. PINCTRL_PIN_REG_E4,
  48. PINCTRL_PIN_REG_E8,
  49. PINCTRL_PIN_REG_TDSEL,
  50. PINCTRL_PIN_REG_RDSEL,
  51. PINCTRL_PIN_REG_DRV,
  52. PINCTRL_PIN_REG_PUPD,
  53. PINCTRL_PIN_REG_R0,
  54. PINCTRL_PIN_REG_R1,
  55. PINCTRL_PIN_REG_IES,
  56. PINCTRL_PIN_REG_PULLEN,
  57. PINCTRL_PIN_REG_PULLSEL,
  58. PINCTRL_PIN_REG_MAX,
  59. };
  60. /* Group the pins by the driving current */
  61. enum {
  62. DRV_FIXED,
  63. DRV_GRP0,
  64. DRV_GRP1,
  65. DRV_GRP2,
  66. DRV_GRP3,
  67. DRV_GRP4,
  68. DRV_GRP_MAX,
  69. };
  70. static const char * const mtk_default_register_base_names[] = {
  71. "base",
  72. };
  73. /* struct mtk_pin_field - the structure that holds the information of the field
  74. * used to describe the attribute for the pin
  75. * @base: the index pointing to the entry in base address list
  76. * @offset: the register offset relative to the base address
  77. * @mask: the mask used to filter out the field from the register
  78. * @bitpos: the start bit relative to the register
  79. * @next: the indication that the field would be extended to the
  80. next register
  81. */
  82. struct mtk_pin_field {
  83. u8 index;
  84. u32 offset;
  85. u32 mask;
  86. u8 bitpos;
  87. u8 next;
  88. };
  89. /* struct mtk_pin_field_calc - the structure that holds the range providing
  90. * the guide used to look up the relevant field
  91. * @s_pin: the start pin within the range
  92. * @e_pin: the end pin within the range
  93. * @i_base: the index pointing to the entry in base address list
  94. * @s_addr: the start address for the range
  95. * @x_addrs: the address distance between two consecutive registers
  96. * within the range
  97. * @s_bit: the start bit for the first register within the range
  98. * @x_bits: the bit distance between two consecutive pins within
  99. * the range
  100. * @sz_reg: the size of bits in a register
  101. * @fixed: the consecutive pins share the same bits with the 1st
  102. * pin
  103. */
  104. struct mtk_pin_field_calc {
  105. u16 s_pin;
  106. u16 e_pin;
  107. u8 i_base;
  108. u32 s_addr;
  109. u8 x_addrs;
  110. u8 s_bit;
  111. u8 x_bits;
  112. u8 sz_reg;
  113. u8 fixed;
  114. };
  115. /* struct mtk_pin_reg_calc - the structure that holds all ranges used to
  116. * determine which register the pin would make use of
  117. * for certain pin attribute.
  118. * @range: the start address for the range
  119. * @nranges: the number of items in the range
  120. */
  121. struct mtk_pin_reg_calc {
  122. const struct mtk_pin_field_calc *range;
  123. unsigned int nranges;
  124. };
  125. /**
  126. * struct mtk_func_desc - the structure that providing information
  127. * all the funcs for this pin
  128. * @name: the name of function
  129. * @muxval: the mux to the function
  130. */
  131. struct mtk_func_desc {
  132. const char *name;
  133. u8 muxval;
  134. };
  135. /**
  136. * struct mtk_eint_desc - the structure that providing information
  137. * for eint data per pin
  138. * @eint_m: the eint mux for this pin
  139. * @eitn_n: the eint number for this pin
  140. */
  141. struct mtk_eint_desc {
  142. u16 eint_m;
  143. u16 eint_n;
  144. };
  145. /**
  146. * struct mtk_pin_desc - the structure that providing information
  147. * for each pin of chips
  148. * @number: unique pin number from the global pin number space
  149. * @name: name for this pin
  150. * @eint: the eint data for this pin
  151. * @drv_n: the index with the driving group
  152. * @funcs: all available functions for this pins (only used in
  153. * those drivers compatible to pinctrl-mtk-common.c-like
  154. * ones)
  155. */
  156. struct mtk_pin_desc {
  157. unsigned int number;
  158. const char *name;
  159. struct mtk_eint_desc eint;
  160. u8 drv_n;
  161. struct mtk_func_desc *funcs;
  162. };
  163. struct mtk_pinctrl_group {
  164. const char *name;
  165. unsigned long config;
  166. unsigned pin;
  167. };
  168. struct mtk_pinctrl;
  169. /* struct mtk_pin_soc - the structure that holds SoC-specific data */
  170. struct mtk_pin_soc {
  171. const struct mtk_pin_reg_calc *reg_cal;
  172. const struct mtk_pin_desc *pins;
  173. unsigned int npins;
  174. const struct group_desc *grps;
  175. unsigned int ngrps;
  176. const struct function_desc *funcs;
  177. unsigned int nfuncs;
  178. const struct mtk_eint_regs *eint_regs;
  179. const struct mtk_eint_hw *eint_hw;
  180. /* Specific parameters per SoC */
  181. u8 gpio_m;
  182. bool ies_present;
  183. const char * const *base_names;
  184. unsigned int nbase_names;
  185. /* Specific pinconfig operations */
  186. int (*bias_disable_set)(struct mtk_pinctrl *hw,
  187. const struct mtk_pin_desc *desc);
  188. int (*bias_disable_get)(struct mtk_pinctrl *hw,
  189. const struct mtk_pin_desc *desc, int *res);
  190. int (*bias_set)(struct mtk_pinctrl *hw,
  191. const struct mtk_pin_desc *desc, bool pullup);
  192. int (*bias_get)(struct mtk_pinctrl *hw,
  193. const struct mtk_pin_desc *desc, bool pullup, int *res);
  194. int (*drive_set)(struct mtk_pinctrl *hw,
  195. const struct mtk_pin_desc *desc, u32 arg);
  196. int (*drive_get)(struct mtk_pinctrl *hw,
  197. const struct mtk_pin_desc *desc, int *val);
  198. int (*adv_pull_set)(struct mtk_pinctrl *hw,
  199. const struct mtk_pin_desc *desc, bool pullup,
  200. u32 arg);
  201. int (*adv_pull_get)(struct mtk_pinctrl *hw,
  202. const struct mtk_pin_desc *desc, bool pullup,
  203. u32 *val);
  204. /* Specific driver data */
  205. void *driver_data;
  206. };
  207. struct mtk_pinctrl {
  208. struct pinctrl_dev *pctrl;
  209. void __iomem **base;
  210. u8 nbase;
  211. struct device *dev;
  212. struct gpio_chip chip;
  213. const struct mtk_pin_soc *soc;
  214. struct mtk_eint *eint;
  215. struct mtk_pinctrl_group *groups;
  216. const char **grp_names;
  217. };
  218. void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set);
  219. int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
  220. int field, int value);
  221. int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
  222. int field, int *value);
  223. int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev);
  224. int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
  225. const struct mtk_pin_desc *desc);
  226. int mtk_pinconf_bias_disable_get(struct mtk_pinctrl *hw,
  227. const struct mtk_pin_desc *desc, int *res);
  228. int mtk_pinconf_bias_set(struct mtk_pinctrl *hw,
  229. const struct mtk_pin_desc *desc, bool pullup);
  230. int mtk_pinconf_bias_get(struct mtk_pinctrl *hw,
  231. const struct mtk_pin_desc *desc, bool pullup,
  232. int *res);
  233. int mtk_pinconf_bias_disable_set_rev1(struct mtk_pinctrl *hw,
  234. const struct mtk_pin_desc *desc);
  235. int mtk_pinconf_bias_disable_get_rev1(struct mtk_pinctrl *hw,
  236. const struct mtk_pin_desc *desc,
  237. int *res);
  238. int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl *hw,
  239. const struct mtk_pin_desc *desc, bool pullup);
  240. int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw,
  241. const struct mtk_pin_desc *desc, bool pullup,
  242. int *res);
  243. int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
  244. const struct mtk_pin_desc *desc, u32 arg);
  245. int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,
  246. const struct mtk_pin_desc *desc, int *val);
  247. int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw,
  248. const struct mtk_pin_desc *desc, u32 arg);
  249. int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw,
  250. const struct mtk_pin_desc *desc, int *val);
  251. int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
  252. const struct mtk_pin_desc *desc, bool pullup,
  253. u32 arg);
  254. int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
  255. const struct mtk_pin_desc *desc, bool pullup,
  256. u32 *val);
  257. #endif /* __PINCTRL_MTK_COMMON_V2_H */