pinctrl-mvebu.h 6.9 KB

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