pinctrl-mvebu.h 6.4 KB

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