pinctrl-mtk-common.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2018 MediaTek Inc.
  4. * Author: Ryder Lee <ryder.lee@mediatek.com>
  5. */
  6. #ifndef __PINCTRL_MEDIATEK_H__
  7. #define __PINCTRL_MEDIATEK_H__
  8. #define MTK_PINCTRL_V0 0x0
  9. #define MTK_PINCTRL_V1 0x1
  10. #define BASE_CALC_NONE 0
  11. #define MAX_BASE_CALC 10
  12. #define MTK_RANGE(_a) { .range = (_a), .nranges = ARRAY_SIZE(_a), }
  13. #define MTK_PIN(_number, _name, _drv_n) \
  14. MTK_TYPED_PIN(_number, _name, _drv_n, IO_TYPE_DEFAULT)
  15. #define MTK_TYPED_PIN(_number, _name, _drv_n, _io_n) { \
  16. .number = _number, \
  17. .name = _name, \
  18. .drv_n = _drv_n, \
  19. .io_n = _io_n, \
  20. }
  21. #define PINCTRL_PIN_GROUP(name, id) \
  22. { \
  23. name, \
  24. id##_pins, \
  25. ARRAY_SIZE(id##_pins), \
  26. id##_funcs, \
  27. }
  28. #define PIN_FIELD_BASE_CALC(_s_pin, _e_pin, _i_base, _s_addr, _x_addrs, \
  29. _s_bit, _x_bits, _sz_reg, _fixed) { \
  30. .s_pin = _s_pin, \
  31. .e_pin = _e_pin, \
  32. .i_base = _i_base, \
  33. .s_addr = _s_addr, \
  34. .x_addrs = _x_addrs, \
  35. .s_bit = _s_bit, \
  36. .x_bits = _x_bits, \
  37. .sz_reg = _sz_reg, \
  38. .fixed = _fixed, \
  39. }
  40. #define PIN_FIELD_CALC(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, \
  41. _x_bits, _sz_reg, _fixed) \
  42. PIN_FIELD_BASE_CALC(_s_pin, _e_pin, BASE_CALC_NONE, _s_addr, \
  43. _x_addrs, _s_bit, _x_bits, _sz_reg, _fixed)
  44. /* List these attributes which could be modified for the pin */
  45. enum {
  46. PINCTRL_PIN_REG_MODE,
  47. PINCTRL_PIN_REG_DIR,
  48. PINCTRL_PIN_REG_DI,
  49. PINCTRL_PIN_REG_DO,
  50. PINCTRL_PIN_REG_SMT,
  51. PINCTRL_PIN_REG_PD,
  52. PINCTRL_PIN_REG_PU,
  53. PINCTRL_PIN_REG_E4,
  54. PINCTRL_PIN_REG_E8,
  55. PINCTRL_PIN_REG_IES,
  56. PINCTRL_PIN_REG_PULLEN,
  57. PINCTRL_PIN_REG_PULLSEL,
  58. PINCTRL_PIN_REG_DRV,
  59. PINCTRL_PIN_REG_PUPD,
  60. PINCTRL_PIN_REG_R0,
  61. PINCTRL_PIN_REG_R1,
  62. PINCTRL_PIN_REG_MAX,
  63. };
  64. /* Group the pins by the driving current */
  65. enum {
  66. DRV_FIXED,
  67. DRV_GRP0,
  68. DRV_GRP1,
  69. DRV_GRP2,
  70. DRV_GRP3,
  71. DRV_GRP4,
  72. };
  73. /* Group the pins by the io type */
  74. enum {
  75. IO_TYPE_DEFAULT,
  76. IO_TYPE_GRP0,
  77. IO_TYPE_GRP1,
  78. IO_TYPE_GRP2,
  79. IO_TYPE_GRP3,
  80. IO_TYPE_GRP4,
  81. IO_TYPE_GRP5,
  82. IO_TYPE_GRP6,
  83. };
  84. /**
  85. * struct mtk_pin_field - the structure that holds the information of the field
  86. * used to describe the attribute for the pin
  87. * @index: the index pointing to the entry in base address list
  88. * @offset: the register offset relative to the base address
  89. * @mask: the mask used to filter out the field from the register
  90. * @bitpos: the start bit relative to the register
  91. * @next: the indication that the field would be extended to the
  92. next register
  93. */
  94. struct mtk_pin_field {
  95. u8 index;
  96. u32 offset;
  97. u32 mask;
  98. u8 bitpos;
  99. u8 next;
  100. };
  101. /**
  102. * struct mtk_pin_field_calc - the structure that holds the range providing
  103. * the guide used to look up the relevant field
  104. * @s_pin: the start pin within the range
  105. * @e_pin: the end pin within the range
  106. * @i_base: the index pointing to the entry in base address list
  107. * @s_addr: the start address for the range
  108. * @x_addrs: the address distance between two consecutive registers
  109. * within the range
  110. * @s_bit: the start bit for the first register within the range
  111. * @x_bits: the bit distance between two consecutive pins within
  112. * the range
  113. * @sz_reg: the size of bits in a register
  114. * @fixed: the consecutive pins share the same bits with the 1st
  115. * pin
  116. */
  117. struct mtk_pin_field_calc {
  118. u16 s_pin;
  119. u16 e_pin;
  120. u8 i_base;
  121. u32 s_addr;
  122. u8 x_addrs;
  123. u8 s_bit;
  124. u8 x_bits;
  125. u8 sz_reg;
  126. u8 fixed;
  127. };
  128. /**
  129. * struct mtk_pin_reg_calc - the structure that holds all ranges used to
  130. * determine which register the pin would make use of
  131. * for certain pin attribute.
  132. * @range: the start address for the range
  133. * @nranges: the number of items in the range
  134. */
  135. struct mtk_pin_reg_calc {
  136. const struct mtk_pin_field_calc *range;
  137. unsigned int nranges;
  138. };
  139. /**
  140. * struct mtk_pin_desc - the structure that providing information
  141. * for each pin of chips
  142. * @number: unique pin number from the global pin number space
  143. * @name: name for this pin
  144. * @drv_n: the index with the driving group
  145. * @io_n: the index with the io type
  146. */
  147. struct mtk_pin_desc {
  148. unsigned int number;
  149. const char *name;
  150. u8 drv_n;
  151. u8 io_n;
  152. };
  153. /**
  154. * struct mtk_group_desc - generic pin group descriptor
  155. * @name: name of the pin group
  156. * @pins: array of pins that belong to the group
  157. * @num_pins: number of pins in the group
  158. * @data: pin controller driver specific data
  159. */
  160. struct mtk_group_desc {
  161. const char *name;
  162. const int *pins;
  163. int num_pins;
  164. const void *data;
  165. };
  166. /**
  167. * struct mtk_function_desc - generic function descriptor
  168. * @name: name of the function
  169. * @group_names: array of pin group names
  170. * @num_group_names: number of pin group names
  171. */
  172. struct mtk_function_desc {
  173. const char *name;
  174. const char * const *group_names;
  175. int num_group_names;
  176. };
  177. /**
  178. * struct mtk_io_type_desc - io class descriptor for specific pins
  179. * @name: name of the io class
  180. */
  181. struct mtk_io_type_desc {
  182. const char *name;
  183. #if CONFIG_IS_ENABLED(PINCONF)
  184. /* Specific pinconfig operations */
  185. int (*bias_set)(struct udevice *dev, u32 pin, bool disable,
  186. bool pullup, u32 val);
  187. int (*drive_set)(struct udevice *dev, u32 pin, u32 arg);
  188. int (*input_enable)(struct udevice *dev, u32 pin, u32 arg);
  189. #endif
  190. };
  191. /* struct mtk_pin_soc - the structure that holds SoC-specific data */
  192. struct mtk_pinctrl_soc {
  193. const char *name;
  194. const struct mtk_pin_reg_calc *reg_cal;
  195. const struct mtk_pin_desc *pins;
  196. int npins;
  197. const struct mtk_group_desc *grps;
  198. int ngrps;
  199. const struct mtk_function_desc *funcs;
  200. int nfuncs;
  201. const struct mtk_io_type_desc *io_type;
  202. u8 ntype;
  203. int gpio_mode;
  204. const char * const *base_names;
  205. unsigned int nbase_names;
  206. int rev;
  207. int base_calc;
  208. };
  209. /**
  210. * struct mtk_pinctrl_priv - private data for MTK pinctrl driver
  211. *
  212. * @base: base address of the pinctrl device
  213. * @soc: SoC specific data
  214. */
  215. struct mtk_pinctrl_priv {
  216. void __iomem *base[MAX_BASE_CALC];
  217. const struct mtk_pinctrl_soc *soc;
  218. };
  219. extern const struct pinctrl_ops mtk_pinctrl_ops;
  220. /* A common read-modify-write helper for MediaTek chips */
  221. void mtk_rmw(struct udevice *dev, u32 reg, u32 mask, u32 set);
  222. void mtk_i_rmw(struct udevice *dev, u8 i, u32 reg, u32 mask, u32 set);
  223. int mtk_pinctrl_common_probe(struct udevice *dev,
  224. const struct mtk_pinctrl_soc *soc);
  225. #if CONFIG_IS_ENABLED(PINCONF)
  226. int mtk_pinconf_bias_set_pu_pd(struct udevice *dev, u32 pin, bool disable,
  227. bool pullup, u32 val);
  228. int mtk_pinconf_bias_set_pullen_pullsel(struct udevice *dev, u32 pin,
  229. bool disable, bool pullup, u32 val);
  230. int mtk_pinconf_bias_set_pupd_r1_r0(struct udevice *dev, u32 pin, bool disable,
  231. bool pullup, u32 val);
  232. int mtk_pinconf_bias_set_v0(struct udevice *dev, u32 pin, bool disable,
  233. bool pullup, u32 val);
  234. int mtk_pinconf_bias_set_v1(struct udevice *dev, u32 pin, bool disable,
  235. bool pullup, u32 val);
  236. int mtk_pinconf_input_enable_v1(struct udevice *dev, u32 pin, u32 arg);
  237. int mtk_pinconf_drive_set_v0(struct udevice *dev, u32 pin, u32 arg);
  238. int mtk_pinconf_drive_set_v1(struct udevice *dev, u32 pin, u32 arg);
  239. #endif
  240. #endif /* __PINCTRL_MEDIATEK_H__ */