pinctrl-mtk-common.h 8.5 KB

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