pinctrl-owl.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * OWL SoC's Pinctrl definitions
  4. *
  5. * Copyright (c) 2014 Actions Semi Inc.
  6. * Author: David Liu <[email protected]>
  7. *
  8. * Copyright (c) 2018 Linaro Ltd.
  9. * Author: Manivannan Sadhasivam <[email protected]>
  10. */
  11. #ifndef __PINCTRL_OWL_H__
  12. #define __PINCTRL_OWL_H__
  13. #define OWL_PINCONF_SLEW_SLOW 0
  14. #define OWL_PINCONF_SLEW_FAST 1
  15. #define MUX_PG(group_name, reg, shift, width) \
  16. { \
  17. .name = #group_name, \
  18. .pads = group_name##_pads, \
  19. .npads = ARRAY_SIZE(group_name##_pads), \
  20. .funcs = group_name##_funcs, \
  21. .nfuncs = ARRAY_SIZE(group_name##_funcs), \
  22. .mfpctl_reg = MFCTL##reg, \
  23. .mfpctl_shift = shift, \
  24. .mfpctl_width = width, \
  25. .drv_reg = -1, \
  26. .drv_shift = -1, \
  27. .drv_width = -1, \
  28. .sr_reg = -1, \
  29. .sr_shift = -1, \
  30. .sr_width = -1, \
  31. }
  32. #define DRV_PG(group_name, reg, shift, width) \
  33. { \
  34. .name = #group_name, \
  35. .pads = group_name##_pads, \
  36. .npads = ARRAY_SIZE(group_name##_pads), \
  37. .mfpctl_reg = -1, \
  38. .mfpctl_shift = -1, \
  39. .mfpctl_width = -1, \
  40. .drv_reg = PAD_DRV##reg, \
  41. .drv_shift = shift, \
  42. .drv_width = width, \
  43. .sr_reg = -1, \
  44. .sr_shift = -1, \
  45. .sr_width = -1, \
  46. }
  47. #define SR_PG(group_name, reg, shift, width) \
  48. { \
  49. .name = #group_name, \
  50. .pads = group_name##_pads, \
  51. .npads = ARRAY_SIZE(group_name##_pads), \
  52. .mfpctl_reg = -1, \
  53. .mfpctl_shift = -1, \
  54. .mfpctl_width = -1, \
  55. .drv_reg = -1, \
  56. .drv_shift = -1, \
  57. .drv_width = -1, \
  58. .sr_reg = PAD_SR##reg, \
  59. .sr_shift = shift, \
  60. .sr_width = width, \
  61. }
  62. #define FUNCTION(fname) \
  63. { \
  64. .name = #fname, \
  65. .groups = fname##_groups, \
  66. .ngroups = ARRAY_SIZE(fname##_groups), \
  67. }
  68. /* PAD PULL UP/DOWN CONFIGURES */
  69. #define PULLCTL_CONF(pull_reg, pull_sft, pull_wdt) \
  70. { \
  71. .reg = PAD_PULLCTL##pull_reg, \
  72. .shift = pull_sft, \
  73. .width = pull_wdt, \
  74. }
  75. #define PAD_PULLCTL_CONF(pad_name, pull_reg, pull_sft, pull_wdt) \
  76. struct owl_pullctl pad_name##_pullctl_conf \
  77. = PULLCTL_CONF(pull_reg, pull_sft, pull_wdt)
  78. #define ST_CONF(st_reg, st_sft, st_wdt) \
  79. { \
  80. .reg = PAD_ST##st_reg, \
  81. .shift = st_sft, \
  82. .width = st_wdt, \
  83. }
  84. #define PAD_ST_CONF(pad_name, st_reg, st_sft, st_wdt) \
  85. struct owl_st pad_name##_st_conf \
  86. = ST_CONF(st_reg, st_sft, st_wdt)
  87. #define PAD_INFO(name) \
  88. { \
  89. .pad = name, \
  90. .pullctl = NULL, \
  91. .st = NULL, \
  92. }
  93. #define PAD_INFO_ST(name) \
  94. { \
  95. .pad = name, \
  96. .pullctl = NULL, \
  97. .st = &name##_st_conf, \
  98. }
  99. #define PAD_INFO_PULLCTL(name) \
  100. { \
  101. .pad = name, \
  102. .pullctl = &name##_pullctl_conf, \
  103. .st = NULL, \
  104. }
  105. #define PAD_INFO_PULLCTL_ST(name) \
  106. { \
  107. .pad = name, \
  108. .pullctl = &name##_pullctl_conf, \
  109. .st = &name##_st_conf, \
  110. }
  111. #define OWL_GPIO_PORT_A 0
  112. #define OWL_GPIO_PORT_B 1
  113. #define OWL_GPIO_PORT_C 2
  114. #define OWL_GPIO_PORT_D 3
  115. #define OWL_GPIO_PORT_E 4
  116. #define OWL_GPIO_PORT_F 5
  117. #define OWL_GPIO_PORT(port, base, count, _outen, _inen, _dat, _intc_ctl,\
  118. _intc_pd, _intc_msk, _intc_type, _share) \
  119. [OWL_GPIO_PORT_##port] = { \
  120. .offset = base, \
  121. .pins = count, \
  122. .outen = _outen, \
  123. .inen = _inen, \
  124. .dat = _dat, \
  125. .intc_ctl = _intc_ctl, \
  126. .intc_pd = _intc_pd, \
  127. .intc_msk = _intc_msk, \
  128. .intc_type = _intc_type, \
  129. .shared_ctl_offset = _share, \
  130. }
  131. enum owl_pinconf_drv {
  132. OWL_PINCONF_DRV_2MA,
  133. OWL_PINCONF_DRV_4MA,
  134. OWL_PINCONF_DRV_8MA,
  135. OWL_PINCONF_DRV_12MA,
  136. };
  137. /* GPIO CTRL Bit Definition */
  138. #define OWL_GPIO_CTLR_PENDING 0
  139. #define OWL_GPIO_CTLR_ENABLE 1
  140. #define OWL_GPIO_CTLR_SAMPLE_CLK_24M 2
  141. /* GPIO TYPE Bit Definition */
  142. #define OWL_GPIO_INT_LEVEL_HIGH 0
  143. #define OWL_GPIO_INT_LEVEL_LOW 1
  144. #define OWL_GPIO_INT_EDGE_RISING 2
  145. #define OWL_GPIO_INT_EDGE_FALLING 3
  146. #define OWL_GPIO_INT_MASK 3
  147. /**
  148. * struct owl_pullctl - Actions pad pull control register
  149. * @reg: offset to the pull control register
  150. * @shift: shift value of the register
  151. * @width: width of the register
  152. */
  153. struct owl_pullctl {
  154. int reg;
  155. unsigned int shift;
  156. unsigned int width;
  157. };
  158. /**
  159. * struct owl_st - Actions pad schmitt trigger enable register
  160. * @reg: offset to the schmitt trigger enable register
  161. * @shift: shift value of the register
  162. * @width: width of the register
  163. */
  164. struct owl_st {
  165. int reg;
  166. unsigned int shift;
  167. unsigned int width;
  168. };
  169. /**
  170. * struct owl_pingroup - Actions pingroup definition
  171. * @name: name of the pin group
  172. * @pads: list of pins assigned to this pingroup
  173. * @npads: size of @pads array
  174. * @funcs: list of pinmux functions for this pingroup
  175. * @nfuncs: size of @funcs array
  176. * @mfpctl_reg: multiplexing control register offset
  177. * @mfpctl_shift: multiplexing control register bit mask
  178. * @mfpctl_width: multiplexing control register width
  179. * @drv_reg: drive control register offset
  180. * @drv_shift: drive control register bit mask
  181. * @drv_width: driver control register width
  182. * @sr_reg: slew rate control register offset
  183. * @sr_shift: slew rate control register bit mask
  184. * @sr_width: slew rate control register width
  185. */
  186. struct owl_pingroup {
  187. const char *name;
  188. unsigned int *pads;
  189. unsigned int npads;
  190. unsigned int *funcs;
  191. unsigned int nfuncs;
  192. int mfpctl_reg;
  193. unsigned int mfpctl_shift;
  194. unsigned int mfpctl_width;
  195. int drv_reg;
  196. unsigned int drv_shift;
  197. unsigned int drv_width;
  198. int sr_reg;
  199. unsigned int sr_shift;
  200. unsigned int sr_width;
  201. };
  202. /**
  203. * struct owl_padinfo - Actions pinctrl pad info
  204. * @pad: pad name of the SoC
  205. * @pullctl: pull control register info
  206. * @st: schmitt trigger register info
  207. */
  208. struct owl_padinfo {
  209. int pad;
  210. struct owl_pullctl *pullctl;
  211. struct owl_st *st;
  212. };
  213. /**
  214. * struct owl_pinmux_func - Actions pinctrl mux functions
  215. * @name: name of the pinmux function.
  216. * @groups: array of pin groups that may select this function.
  217. * @ngroups: number of entries in @groups.
  218. */
  219. struct owl_pinmux_func {
  220. const char *name;
  221. const char * const *groups;
  222. unsigned int ngroups;
  223. };
  224. /**
  225. * struct owl_gpio_port - Actions GPIO port info
  226. * @offset: offset of the GPIO port.
  227. * @pins: number of pins belongs to the GPIO port.
  228. * @outen: offset of the output enable register.
  229. * @inen: offset of the input enable register.
  230. * @dat: offset of the data register.
  231. * @intc_ctl: offset of the interrupt control register.
  232. * @intc_pd: offset of the interrupt pending register.
  233. * @intc_msk: offset of the interrupt mask register.
  234. * @intc_type: offset of the interrupt type register.
  235. */
  236. struct owl_gpio_port {
  237. unsigned int offset;
  238. unsigned int pins;
  239. unsigned int outen;
  240. unsigned int inen;
  241. unsigned int dat;
  242. unsigned int intc_ctl;
  243. unsigned int intc_pd;
  244. unsigned int intc_msk;
  245. unsigned int intc_type;
  246. u8 shared_ctl_offset;
  247. };
  248. /**
  249. * struct owl_pinctrl_soc_data - Actions pin controller driver configuration
  250. * @pins: array describing all pins of the pin controller.
  251. * @npins: number of entries in @pins.
  252. * @functions: array describing all mux functions of this SoC.
  253. * @nfunction: number of entries in @functions.
  254. * @groups: array describing all pin groups of this SoC.
  255. * @ngroups: number of entries in @groups.
  256. * @padinfo: array describing the pad info of this SoC.
  257. * @ngpios: number of pingroups the driver should expose as GPIOs.
  258. * @ports: array describing all GPIO ports of this SoC.
  259. * @nports: number of GPIO ports in this SoC.
  260. */
  261. struct owl_pinctrl_soc_data {
  262. const struct pinctrl_pin_desc *pins;
  263. unsigned int npins;
  264. const struct owl_pinmux_func *functions;
  265. unsigned int nfunctions;
  266. const struct owl_pingroup *groups;
  267. unsigned int ngroups;
  268. const struct owl_padinfo *padinfo;
  269. unsigned int ngpios;
  270. const struct owl_gpio_port *ports;
  271. unsigned int nports;
  272. int (*padctl_val2arg)(const struct owl_padinfo *padinfo,
  273. unsigned int param,
  274. u32 *arg);
  275. int (*padctl_arg2val)(const struct owl_padinfo *info,
  276. unsigned int param,
  277. u32 *arg);
  278. };
  279. int owl_pinctrl_probe(struct platform_device *pdev,
  280. struct owl_pinctrl_soc_data *soc_data);
  281. #endif /* __PINCTRL_OWL_H__ */