pinctrl-mvebu.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Marvell MVEBU pinctrl driver
  4. *
  5. * Authors: Sebastian Hesselbarth <[email protected]>
  6. * Thomas Petazzoni <[email protected]>
  7. */
  8. #ifndef __PINCTRL_MVEBU_H__
  9. #define __PINCTRL_MVEBU_H__
  10. /**
  11. * struct mvebu_mpp_ctrl_data - private data for the mpp ctrl operations
  12. * @base: base address of pinctrl hardware
  13. * @regmap.map: regmap structure
  14. * @regmap.offset: regmap offset
  15. */
  16. struct mvebu_mpp_ctrl_data {
  17. union {
  18. void __iomem *base;
  19. struct {
  20. struct regmap *map;
  21. u32 offset;
  22. } regmap;
  23. };
  24. };
  25. /**
  26. * struct mvebu_mpp_ctrl - describe a mpp control
  27. * @name: name of the control group
  28. * @pid: first pin id handled by this control
  29. * @npins: number of pins controlled by this control
  30. * @mpp_get: (optional) special function to get mpp setting
  31. * @mpp_set: (optional) special function to set mpp setting
  32. * @mpp_gpio_req: (optional) special function to request gpio
  33. * @mpp_gpio_dir: (optional) special function to set gpio direction
  34. *
  35. * A mpp_ctrl describes a muxable unit, e.g. pin, group of pins, or
  36. * internal function, inside the SoC. Each muxable unit can be switched
  37. * between two or more different settings, e.g. assign mpp pin 13 to
  38. * uart1 or sata.
  39. *
  40. * The mpp_get/_set functions are mandatory and are used to get/set a
  41. * specific mode. The optional mpp_gpio_req/_dir functions can be used
  42. * to allow pin settings with varying gpio pins.
  43. */
  44. struct mvebu_mpp_ctrl {
  45. const char *name;
  46. u8 pid;
  47. u8 npins;
  48. unsigned *pins;
  49. int (*mpp_get)(struct mvebu_mpp_ctrl_data *data, unsigned pid,
  50. unsigned long *config);
  51. int (*mpp_set)(struct mvebu_mpp_ctrl_data *data, unsigned pid,
  52. unsigned long config);
  53. int (*mpp_gpio_req)(struct mvebu_mpp_ctrl_data *data, unsigned pid);
  54. int (*mpp_gpio_dir)(struct mvebu_mpp_ctrl_data *data, unsigned pid,
  55. bool input);
  56. };
  57. /**
  58. * struct mvebu_mpp_ctrl_setting - describe a mpp ctrl setting
  59. * @val: ctrl setting value
  60. * @name: ctrl setting name, e.g. uart2, spi0 - unique per mpp_mode
  61. * @subname: (optional) additional ctrl setting name, e.g. rts, cts
  62. * @variant: (optional) variant identifier mask
  63. * @flags: (private) flags to store gpi/gpo/gpio capabilities
  64. *
  65. * A ctrl_setting describes a specific internal mux function that a mpp pin
  66. * can be switched to. The value (val) will be written in the corresponding
  67. * register for common mpp pin configuration registers on MVEBU. SoC specific
  68. * mpp_get/_set function may use val to distinguish between different settings.
  69. *
  70. * The name will be used to switch to this setting in DT description, e.g.
  71. * marvell,function = "uart2". subname is only for debugging purposes.
  72. *
  73. * If name is one of "gpi", "gpo", "gpio" gpio capabilities are
  74. * parsed during initialization and stored in flags.
  75. *
  76. * The variant can be used to combine different revisions of one SoC to a
  77. * common pinctrl driver. It is matched (AND) with variant of soc_info to
  78. * determine if a setting is available on the current SoC revision.
  79. */
  80. struct mvebu_mpp_ctrl_setting {
  81. u8 val;
  82. const char *name;
  83. const char *subname;
  84. u8 variant;
  85. u8 flags;
  86. #define MVEBU_SETTING_GPO (1 << 0)
  87. #define MVEBU_SETTING_GPI (1 << 1)
  88. };
  89. /**
  90. * struct mvebu_mpp_mode - link ctrl and settings
  91. * @pid: first pin id handled by this mode
  92. * @settings: list of settings available for this mode
  93. *
  94. * A mode connects all available settings with the corresponding mpp_ctrl
  95. * given by pid.
  96. */
  97. struct mvebu_mpp_mode {
  98. u8 pid;
  99. struct mvebu_mpp_ctrl_setting *settings;
  100. };
  101. /**
  102. * struct mvebu_pinctrl_soc_info - SoC specific info passed to pinctrl-mvebu
  103. * @variant: variant mask of soc_info
  104. * @controls: list of available mvebu_mpp_ctrls
  105. * @control_data: optional array, one entry for each control
  106. * @ncontrols: number of available mvebu_mpp_ctrls
  107. * @modes: list of available mvebu_mpp_modes
  108. * @nmodes: number of available mvebu_mpp_modes
  109. * @gpioranges: list of pinctrl_gpio_ranges
  110. * @ngpioranges: number of available pinctrl_gpio_ranges
  111. *
  112. * This struct describes all pinctrl related information for a specific SoC.
  113. * If variant is unequal 0 it will be matched (AND) with variant of each
  114. * setting and allows to distinguish between different revisions of one SoC.
  115. */
  116. struct mvebu_pinctrl_soc_info {
  117. u8 variant;
  118. const struct mvebu_mpp_ctrl *controls;
  119. struct mvebu_mpp_ctrl_data *control_data;
  120. int ncontrols;
  121. struct mvebu_mpp_mode *modes;
  122. int nmodes;
  123. struct pinctrl_gpio_range *gpioranges;
  124. int ngpioranges;
  125. };
  126. #define MPP_FUNC_CTRL(_idl, _idh, _name, _func) \
  127. { \
  128. .name = _name, \
  129. .pid = _idl, \
  130. .npins = _idh - _idl + 1, \
  131. .pins = (unsigned[_idh - _idl + 1]) { }, \
  132. .mpp_get = _func ## _get, \
  133. .mpp_set = _func ## _set, \
  134. .mpp_gpio_req = NULL, \
  135. .mpp_gpio_dir = NULL, \
  136. }
  137. #define MPP_FUNC_GPIO_CTRL(_idl, _idh, _name, _func) \
  138. { \
  139. .name = _name, \
  140. .pid = _idl, \
  141. .npins = _idh - _idl + 1, \
  142. .pins = (unsigned[_idh - _idl + 1]) { }, \
  143. .mpp_get = _func ## _get, \
  144. .mpp_set = _func ## _set, \
  145. .mpp_gpio_req = _func ## _gpio_req, \
  146. .mpp_gpio_dir = _func ## _gpio_dir, \
  147. }
  148. #define _MPP_VAR_FUNCTION(_val, _name, _subname, _mask) \
  149. { \
  150. .val = _val, \
  151. .name = _name, \
  152. .subname = _subname, \
  153. .variant = _mask, \
  154. .flags = 0, \
  155. }
  156. #if defined(CONFIG_DEBUG_FS)
  157. #define MPP_VAR_FUNCTION(_val, _name, _subname, _mask) \
  158. _MPP_VAR_FUNCTION(_val, _name, _subname, _mask)
  159. #else
  160. #define MPP_VAR_FUNCTION(_val, _name, _subname, _mask) \
  161. _MPP_VAR_FUNCTION(_val, _name, NULL, _mask)
  162. #endif
  163. #define MPP_FUNCTION(_val, _name, _subname) \
  164. MPP_VAR_FUNCTION(_val, _name, _subname, (u8)-1)
  165. #define MPP_MODE(_id, ...) \
  166. { \
  167. .pid = _id, \
  168. .settings = (struct mvebu_mpp_ctrl_setting[]){ \
  169. __VA_ARGS__, { } }, \
  170. }
  171. #define MPP_GPIO_RANGE(_id, _pinbase, _gpiobase, _npins) \
  172. { \
  173. .name = "mvebu-gpio", \
  174. .id = _id, \
  175. .pin_base = _pinbase, \
  176. .base = _gpiobase, \
  177. .npins = _npins, \
  178. }
  179. #define MVEBU_MPPS_PER_REG 8
  180. #define MVEBU_MPP_BITS 4
  181. #define MVEBU_MPP_MASK 0xf
  182. int mvebu_mmio_mpp_ctrl_get(struct mvebu_mpp_ctrl_data *data, unsigned pid,
  183. unsigned long *config);
  184. int mvebu_mmio_mpp_ctrl_set(struct mvebu_mpp_ctrl_data *data, unsigned pid,
  185. unsigned long config);
  186. int mvebu_regmap_mpp_ctrl_get(struct mvebu_mpp_ctrl_data *data, unsigned pid,
  187. unsigned long *config);
  188. int mvebu_regmap_mpp_ctrl_set(struct mvebu_mpp_ctrl_data *data, unsigned pid,
  189. unsigned long config);
  190. int mvebu_pinctrl_probe(struct platform_device *pdev);
  191. int mvebu_pinctrl_simple_mmio_probe(struct platform_device *pdev);
  192. int mvebu_pinctrl_simple_regmap_probe(struct platform_device *pdev,
  193. struct device *syscon_dev, u32 offset);
  194. #endif