pinctrl-mtk-common.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2014 MediaTek Inc.
  4. * Author: Hongzhou.Yang <[email protected]>
  5. */
  6. #ifndef __PINCTRL_MTK_COMMON_H
  7. #define __PINCTRL_MTK_COMMON_H
  8. #include <linux/pinctrl/pinctrl.h>
  9. #include <linux/regmap.h>
  10. #include <linux/pinctrl/pinconf-generic.h>
  11. #include "mtk-eint.h"
  12. #define NO_EINT_SUPPORT 255
  13. #define MT_EDGE_SENSITIVE 0
  14. #define MT_LEVEL_SENSITIVE 1
  15. #define EINT_DBNC_SET_DBNC_BITS 4
  16. #define EINT_DBNC_RST_BIT (0x1 << 1)
  17. #define EINT_DBNC_SET_EN (0x1 << 0)
  18. #define MTK_PINCTRL_NOT_SUPPORT (0xffff)
  19. struct mtk_desc_function {
  20. const char *name;
  21. unsigned char muxval;
  22. };
  23. struct mtk_desc_eint {
  24. unsigned char eintmux;
  25. unsigned char eintnum;
  26. };
  27. struct mtk_desc_pin {
  28. struct pinctrl_pin_desc pin;
  29. const struct mtk_desc_eint eint;
  30. const struct mtk_desc_function *functions;
  31. };
  32. #define MTK_PIN(_pin, _pad, _chip, _eint, ...) \
  33. { \
  34. .pin = _pin, \
  35. .eint = _eint, \
  36. .functions = (struct mtk_desc_function[]){ \
  37. __VA_ARGS__, { } }, \
  38. }
  39. #define MTK_EINT_FUNCTION(_eintmux, _eintnum) \
  40. { \
  41. .eintmux = _eintmux, \
  42. .eintnum = _eintnum, \
  43. }
  44. #define MTK_FUNCTION(_val, _name) \
  45. { \
  46. .muxval = _val, \
  47. .name = _name, \
  48. }
  49. #define SET_ADDR(x, y) (x + (y->devdata->port_align))
  50. #define CLR_ADDR(x, y) (x + (y->devdata->port_align << 1))
  51. struct mtk_pinctrl_group {
  52. const char *name;
  53. unsigned long config;
  54. unsigned pin;
  55. };
  56. /**
  57. * struct mtk_drv_group_desc - Provide driving group data.
  58. * @max_drv: The maximum current of this group.
  59. * @min_drv: The minimum current of this group.
  60. * @low_bit: The lowest bit of this group.
  61. * @high_bit: The highest bit of this group.
  62. * @step: The step current of this group.
  63. */
  64. struct mtk_drv_group_desc {
  65. unsigned char min_drv;
  66. unsigned char max_drv;
  67. unsigned char low_bit;
  68. unsigned char high_bit;
  69. unsigned char step;
  70. };
  71. #define MTK_DRV_GRP(_min, _max, _low, _high, _step) \
  72. { \
  73. .min_drv = _min, \
  74. .max_drv = _max, \
  75. .low_bit = _low, \
  76. .high_bit = _high, \
  77. .step = _step, \
  78. }
  79. /**
  80. * struct mtk_pin_drv_grp - Provide each pin driving info.
  81. * @pin: The pin number.
  82. * @offset: The offset of driving register for this pin.
  83. * @bit: The bit of driving register for this pin.
  84. * @grp: The group for this pin belongs to.
  85. */
  86. struct mtk_pin_drv_grp {
  87. unsigned short pin;
  88. unsigned short offset;
  89. unsigned char bit;
  90. unsigned char grp;
  91. };
  92. #define MTK_PIN_DRV_GRP(_pin, _offset, _bit, _grp) \
  93. { \
  94. .pin = _pin, \
  95. .offset = _offset, \
  96. .bit = _bit, \
  97. .grp = _grp, \
  98. }
  99. /**
  100. * struct mtk_pin_spec_pupd_set_samereg
  101. * - For special pins' pull up/down setting which resides in same register
  102. * @pin: The pin number.
  103. * @offset: The offset of special pull up/down setting register.
  104. * @pupd_bit: The pull up/down bit in this register.
  105. * @r0_bit: The r0 bit of pull resistor.
  106. * @r1_bit: The r1 bit of pull resistor.
  107. */
  108. struct mtk_pin_spec_pupd_set_samereg {
  109. unsigned short pin;
  110. unsigned short offset;
  111. unsigned char pupd_bit;
  112. unsigned char r1_bit;
  113. unsigned char r0_bit;
  114. };
  115. #define MTK_PIN_PUPD_SPEC_SR(_pin, _offset, _pupd, _r1, _r0) \
  116. { \
  117. .pin = _pin, \
  118. .offset = _offset, \
  119. .pupd_bit = _pupd, \
  120. .r1_bit = _r1, \
  121. .r0_bit = _r0, \
  122. }
  123. /**
  124. * struct mtk_pin_ies_set - For special pins' ies and smt setting.
  125. * @start: The start pin number of those special pins.
  126. * @end: The end pin number of those special pins.
  127. * @offset: The offset of special setting register.
  128. * @bit: The bit of special setting register.
  129. */
  130. struct mtk_pin_ies_smt_set {
  131. unsigned short start;
  132. unsigned short end;
  133. unsigned short offset;
  134. unsigned char bit;
  135. };
  136. #define MTK_PIN_IES_SMT_SPEC(_start, _end, _offset, _bit) \
  137. { \
  138. .start = _start, \
  139. .end = _end, \
  140. .bit = _bit, \
  141. .offset = _offset, \
  142. }
  143. struct mtk_eint_offsets {
  144. const char *name;
  145. unsigned int stat;
  146. unsigned int ack;
  147. unsigned int mask;
  148. unsigned int mask_set;
  149. unsigned int mask_clr;
  150. unsigned int sens;
  151. unsigned int sens_set;
  152. unsigned int sens_clr;
  153. unsigned int soft;
  154. unsigned int soft_set;
  155. unsigned int soft_clr;
  156. unsigned int pol;
  157. unsigned int pol_set;
  158. unsigned int pol_clr;
  159. unsigned int dom_en;
  160. unsigned int dbnc_ctrl;
  161. unsigned int dbnc_set;
  162. unsigned int dbnc_clr;
  163. u8 port_mask;
  164. u8 ports;
  165. };
  166. /**
  167. * struct mtk_pinctrl_devdata - Provide HW GPIO related data.
  168. * @pins: An array describing all pins the pin controller affects.
  169. * @npins: The number of entries in @pins.
  170. *
  171. * @grp_desc: The driving group info.
  172. * @pin_drv_grp: The driving group for all pins.
  173. * @spec_ies: Special pin setting for input enable
  174. * @n_spec_ies: Number of entries in spec_ies
  175. * @spec_pupd: Special pull up/down setting
  176. * @n_spec_pupd: Number of entries in spec_pupd
  177. * @spec_smt: Special pin setting for schmitt
  178. * @n_spec_smt: Number of entries in spec_smt
  179. * @spec_pull_set: Each SoC may have special pins for pull up/down setting,
  180. * these pins' pull setting are very different, they have separate pull
  181. * up/down bit, R0 and R1 resistor bit, so they need special pull setting.
  182. * If special setting is success, this should return 0, otherwise it should
  183. * return non-zero value.
  184. * @spec_ies_smt_set: Some pins are irregular, their input enable and smt
  185. * control register are discontinuous, but they are mapping together. That
  186. * means when user set smt, input enable is set at the same time. So they
  187. * also need special control. If special control is success, this should
  188. * return 0, otherwise return non-zero value.
  189. * @spec_pinmux_set: In some cases, there are two pinmux functions share
  190. * the same value in the same segment of pinmux control register. If user
  191. * want to use one of the two functions, they need an extra bit setting to
  192. * select the right one.
  193. * @spec_dir_set: In very few SoCs, direction control registers are not
  194. * arranged continuously, they may be cut to parts. So they need special
  195. * dir setting.
  196. * @dir_offset: The direction register offset.
  197. * @pullen_offset: The pull-up/pull-down enable register offset.
  198. * @pinmux_offset: The pinmux register offset.
  199. *
  200. * @type1_start: Some chips have two base addresses for pull select register,
  201. * that means some pins use the first address and others use the second. This
  202. * member record the start of pin number to use the second address.
  203. * @type1_end: The end of pin number to use the second address.
  204. *
  205. * @port_shf: The shift between two registers.
  206. * @port_mask: The mask of register.
  207. * @port_align: Provide clear register and set register step.
  208. */
  209. struct mtk_pinctrl_devdata {
  210. const struct mtk_desc_pin *pins;
  211. unsigned int npins;
  212. const struct mtk_drv_group_desc *grp_desc;
  213. unsigned int n_grp_cls;
  214. const struct mtk_pin_drv_grp *pin_drv_grp;
  215. unsigned int n_pin_drv_grps;
  216. const struct mtk_pin_ies_smt_set *spec_ies;
  217. unsigned int n_spec_ies;
  218. const struct mtk_pin_spec_pupd_set_samereg *spec_pupd;
  219. unsigned int n_spec_pupd;
  220. const struct mtk_pin_ies_smt_set *spec_smt;
  221. unsigned int n_spec_smt;
  222. int (*spec_pull_set)(struct regmap *regmap,
  223. const struct mtk_pinctrl_devdata *devdata,
  224. unsigned int pin, bool isup, unsigned int r1r0);
  225. int (*spec_ies_smt_set)(struct regmap *reg,
  226. const struct mtk_pinctrl_devdata *devdata,
  227. unsigned int pin, int value, enum pin_config_param arg);
  228. void (*spec_pinmux_set)(struct regmap *reg, unsigned int pin,
  229. unsigned int mode);
  230. void (*spec_dir_set)(unsigned int *reg_addr, unsigned int pin);
  231. unsigned int dir_offset;
  232. unsigned int ies_offset;
  233. unsigned int smt_offset;
  234. unsigned int pullen_offset;
  235. unsigned int pullsel_offset;
  236. unsigned int drv_offset;
  237. unsigned int dout_offset;
  238. unsigned int din_offset;
  239. unsigned int pinmux_offset;
  240. unsigned short type1_start;
  241. unsigned short type1_end;
  242. unsigned char port_shf;
  243. unsigned char port_mask;
  244. unsigned char port_align;
  245. struct mtk_eint_hw eint_hw;
  246. struct mtk_eint_regs *eint_regs;
  247. unsigned int mode_mask;
  248. unsigned int mode_per_reg;
  249. unsigned int mode_shf;
  250. };
  251. struct mtk_pinctrl {
  252. struct regmap *regmap1;
  253. struct regmap *regmap2;
  254. struct pinctrl_desc pctl_desc;
  255. struct device *dev;
  256. struct gpio_chip *chip;
  257. struct mtk_pinctrl_group *groups;
  258. unsigned ngroups;
  259. const char **grp_names;
  260. struct pinctrl_dev *pctl_dev;
  261. const struct mtk_pinctrl_devdata *devdata;
  262. struct mtk_eint *eint;
  263. };
  264. int mtk_pctrl_init(struct platform_device *pdev,
  265. const struct mtk_pinctrl_devdata *data,
  266. struct regmap *regmap);
  267. int mtk_pctrl_common_probe(struct platform_device *pdev);
  268. int mtk_pctrl_spec_pull_set_samereg(struct regmap *regmap,
  269. const struct mtk_pinctrl_devdata *devdata,
  270. unsigned int pin, bool isup, unsigned int r1r0);
  271. int mtk_pconf_spec_set_ies_smt_range(struct regmap *regmap,
  272. const struct mtk_pinctrl_devdata *devdata,
  273. unsigned int pin, int value, enum pin_config_param arg);
  274. extern const struct dev_pm_ops mtk_eint_pm_ops;
  275. #endif /* __PINCTRL_MTK_COMMON_H */