pinctrl-mtk-common.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. #define NO_EINT_SUPPORT 255
  19. #define MTK_CHIP_TYPE_BASE 0
  20. #define MTK_CHIP_TYPE_PMIC 1
  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. struct mtk_desc_function {
  27. const char *name;
  28. unsigned char muxval;
  29. };
  30. struct mtk_desc_eint {
  31. unsigned char eintmux;
  32. unsigned char eintnum;
  33. };
  34. struct mtk_desc_pin {
  35. struct pinctrl_pin_desc pin;
  36. const char *chip;
  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. .chip = _chip, \
  44. .eint = _eint, \
  45. .functions = (struct mtk_desc_function[]){ \
  46. __VA_ARGS__, { } }, \
  47. }
  48. #define MTK_EINT_FUNCTION(_eintmux, _eintnum) \
  49. { \
  50. .eintmux = _eintmux, \
  51. .eintnum = _eintnum, \
  52. }
  53. #define MTK_FUNCTION(_val, _name) \
  54. { \
  55. .muxval = _val, \
  56. .name = _name, \
  57. }
  58. #define SET_ADDR(x, y) (x + (y->devdata->port_align))
  59. #define CLR_ADDR(x, y) (x + (y->devdata->port_align << 1))
  60. struct mtk_pinctrl_group {
  61. const char *name;
  62. unsigned long config;
  63. unsigned pin;
  64. };
  65. /**
  66. * struct mtk_drv_group_desc - Provide driving group data.
  67. * @max_drv: The maximum current of this group.
  68. * @min_drv: The minimum current of this group.
  69. * @low_bit: The lowest bit of this group.
  70. * @high_bit: The highest bit of this group.
  71. * @step: The step current of this group.
  72. */
  73. struct mtk_drv_group_desc {
  74. unsigned char min_drv;
  75. unsigned char max_drv;
  76. unsigned char low_bit;
  77. unsigned char high_bit;
  78. unsigned char step;
  79. };
  80. #define MTK_DRV_GRP(_min, _max, _low, _high, _step) \
  81. { \
  82. .min_drv = _min, \
  83. .max_drv = _max, \
  84. .low_bit = _low, \
  85. .high_bit = _high, \
  86. .step = _step, \
  87. }
  88. /**
  89. * struct mtk_pin_drv_grp - Provide each pin driving info.
  90. * @pin: The pin number.
  91. * @offset: The offset of driving register for this pin.
  92. * @bit: The bit of driving register for this pin.
  93. * @grp: The group for this pin belongs to.
  94. */
  95. struct mtk_pin_drv_grp {
  96. unsigned int pin;
  97. unsigned int offset;
  98. unsigned char bit;
  99. unsigned char grp;
  100. };
  101. #define MTK_PIN_DRV_GRP(_pin, _offset, _bit, _grp) \
  102. { \
  103. .pin = _pin, \
  104. .offset = _offset, \
  105. .bit = _bit, \
  106. .grp = _grp, \
  107. }
  108. struct mtk_eint_offsets {
  109. const char *name;
  110. unsigned int stat;
  111. unsigned int ack;
  112. unsigned int mask;
  113. unsigned int mask_set;
  114. unsigned int mask_clr;
  115. unsigned int sens;
  116. unsigned int sens_set;
  117. unsigned int sens_clr;
  118. unsigned int soft;
  119. unsigned int soft_set;
  120. unsigned int soft_clr;
  121. unsigned int pol;
  122. unsigned int pol_set;
  123. unsigned int pol_clr;
  124. unsigned int dom_en;
  125. unsigned int dbnc_ctrl;
  126. unsigned int dbnc_set;
  127. unsigned int dbnc_clr;
  128. u8 port_mask;
  129. u8 ports;
  130. };
  131. /**
  132. * struct mtk_pinctrl_devdata - Provide HW GPIO related data.
  133. * @pins: An array describing all pins the pin controller affects.
  134. * @npins: The number of entries in @pins.
  135. *
  136. * @grp_desc: The driving group info.
  137. * @pin_drv_grp: The driving group for all pins.
  138. * @spec_pull_set: Each SoC may have special pins for pull up/down setting,
  139. * these pins' pull setting are very different, they have separate pull
  140. * up/down bit, R0 and R1 resistor bit, so they need special pull setting.
  141. * If special setting is success, this should return 0, otherwise it should
  142. * return non-zero value.
  143. * @spec_ies_smt_set: Some pins are irregular, their input enable and smt
  144. * control register are discontinuous, but they are mapping together. That
  145. * means when user set smt, input enable is set at the same time. So they
  146. * also need special control. If special control is success, this should
  147. * return 0, otherwise return non-zero value.
  148. *
  149. * @dir_offset: The direction register offset.
  150. * @pullen_offset: The pull-up/pull-down enable register offset.
  151. * @pinmux_offset: The pinmux register offset.
  152. *
  153. * @type1_start: Some chips have two base addresses for pull select register,
  154. * that means some pins use the first address and others use the second. This
  155. * member record the start of pin number to use the second address.
  156. * @type1_end: The end of pin number to use the second address.
  157. *
  158. * @port_shf: The shift between two registers.
  159. * @port_mask: The mask of register.
  160. * @port_align: Provide clear register and set register step.
  161. */
  162. struct mtk_pinctrl_devdata {
  163. const struct mtk_desc_pin *pins;
  164. unsigned int npins;
  165. const struct mtk_drv_group_desc *grp_desc;
  166. unsigned int n_grp_cls;
  167. const struct mtk_pin_drv_grp *pin_drv_grp;
  168. unsigned int n_pin_drv_grps;
  169. int (*spec_pull_set)(struct regmap *reg, unsigned int pin,
  170. unsigned char align, bool isup, unsigned int arg);
  171. int (*spec_ies_smt_set)(struct regmap *reg, unsigned int pin,
  172. unsigned char align, int value);
  173. unsigned int dir_offset;
  174. unsigned int ies_offset;
  175. unsigned int smt_offset;
  176. unsigned int pullen_offset;
  177. unsigned int pullsel_offset;
  178. unsigned int drv_offset;
  179. unsigned int invser_offset;
  180. unsigned int dout_offset;
  181. unsigned int din_offset;
  182. unsigned int pinmux_offset;
  183. unsigned short type1_start;
  184. unsigned short type1_end;
  185. unsigned char port_shf;
  186. unsigned char port_mask;
  187. unsigned char port_align;
  188. unsigned char chip_type;
  189. struct mtk_eint_offsets eint_offsets;
  190. unsigned int ap_num;
  191. unsigned int db_cnt;
  192. };
  193. struct mtk_pinctrl {
  194. struct regmap *regmap1;
  195. struct regmap *regmap2;
  196. struct device *dev;
  197. struct gpio_chip *chip;
  198. struct mtk_pinctrl_group *groups;
  199. unsigned ngroups;
  200. const char **grp_names;
  201. struct pinctrl_dev *pctl_dev;
  202. const struct mtk_pinctrl_devdata *devdata;
  203. void __iomem *eint_reg_base;
  204. struct irq_domain *domain;
  205. int *eint_dual_edges;
  206. };
  207. int mtk_pctrl_init(struct platform_device *pdev,
  208. const struct mtk_pinctrl_devdata *data);
  209. #endif /* __PINCTRL_MTK_COMMON_H */