machine.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Machine interface for the pinctrl subsystem.
  4. *
  5. * Copyright (C) 2011 ST-Ericsson SA
  6. * Written on behalf of Linaro for ST-Ericsson
  7. * Based on bits of regulator core, gpio core and clk core
  8. *
  9. * Author: Linus Walleij <[email protected]>
  10. */
  11. #ifndef __LINUX_PINCTRL_MACHINE_H
  12. #define __LINUX_PINCTRL_MACHINE_H
  13. #include <linux/bug.h>
  14. #include <linux/pinctrl/pinctrl-state.h>
  15. enum pinctrl_map_type {
  16. PIN_MAP_TYPE_INVALID,
  17. PIN_MAP_TYPE_DUMMY_STATE,
  18. PIN_MAP_TYPE_MUX_GROUP,
  19. PIN_MAP_TYPE_CONFIGS_PIN,
  20. PIN_MAP_TYPE_CONFIGS_GROUP,
  21. };
  22. /**
  23. * struct pinctrl_map_mux - mapping table content for MAP_TYPE_MUX_GROUP
  24. * @group: the name of the group whose mux function is to be configured. This
  25. * field may be left NULL, and the first applicable group for the function
  26. * will be used.
  27. * @function: the mux function to select for the group
  28. */
  29. struct pinctrl_map_mux {
  30. const char *group;
  31. const char *function;
  32. };
  33. /**
  34. * struct pinctrl_map_configs - mapping table content for MAP_TYPE_CONFIGS_*
  35. * @group_or_pin: the name of the pin or group whose configuration parameters
  36. * are to be configured.
  37. * @configs: a pointer to an array of config parameters/values to program into
  38. * hardware. Each individual pin controller defines the format and meaning
  39. * of config parameters.
  40. * @num_configs: the number of entries in array @configs
  41. */
  42. struct pinctrl_map_configs {
  43. const char *group_or_pin;
  44. unsigned long *configs;
  45. unsigned num_configs;
  46. };
  47. /**
  48. * struct pinctrl_map - boards/machines shall provide this map for devices
  49. * @dev_name: the name of the device using this specific mapping, the name
  50. * must be the same as in your struct device*. If this name is set to the
  51. * same name as the pin controllers own dev_name(), the map entry will be
  52. * hogged by the driver itself upon registration
  53. * @name: the name of this specific map entry for the particular machine.
  54. * This is the parameter passed to pinmux_lookup_state()
  55. * @type: the type of mapping table entry
  56. * @ctrl_dev_name: the name of the device controlling this specific mapping,
  57. * the name must be the same as in your struct device*. This field is not
  58. * used for PIN_MAP_TYPE_DUMMY_STATE
  59. * @data: Data specific to the mapping type
  60. */
  61. struct pinctrl_map {
  62. const char *dev_name;
  63. const char *name;
  64. enum pinctrl_map_type type;
  65. const char *ctrl_dev_name;
  66. union {
  67. struct pinctrl_map_mux mux;
  68. struct pinctrl_map_configs configs;
  69. } data;
  70. };
  71. /* Convenience macros to create mapping table entries */
  72. #define PIN_MAP_DUMMY_STATE(dev, state) \
  73. { \
  74. .dev_name = dev, \
  75. .name = state, \
  76. .type = PIN_MAP_TYPE_DUMMY_STATE, \
  77. }
  78. #define PIN_MAP_MUX_GROUP(dev, state, pinctrl, grp, func) \
  79. { \
  80. .dev_name = dev, \
  81. .name = state, \
  82. .type = PIN_MAP_TYPE_MUX_GROUP, \
  83. .ctrl_dev_name = pinctrl, \
  84. .data.mux = { \
  85. .group = grp, \
  86. .function = func, \
  87. }, \
  88. }
  89. #define PIN_MAP_MUX_GROUP_DEFAULT(dev, pinctrl, grp, func) \
  90. PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, func)
  91. #define PIN_MAP_MUX_GROUP_HOG(dev, state, grp, func) \
  92. PIN_MAP_MUX_GROUP(dev, state, dev, grp, func)
  93. #define PIN_MAP_MUX_GROUP_HOG_DEFAULT(dev, grp, func) \
  94. PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, func)
  95. #define PIN_MAP_CONFIGS_PIN(dev, state, pinctrl, pin, cfgs) \
  96. { \
  97. .dev_name = dev, \
  98. .name = state, \
  99. .type = PIN_MAP_TYPE_CONFIGS_PIN, \
  100. .ctrl_dev_name = pinctrl, \
  101. .data.configs = { \
  102. .group_or_pin = pin, \
  103. .configs = cfgs, \
  104. .num_configs = ARRAY_SIZE(cfgs), \
  105. }, \
  106. }
  107. #define PIN_MAP_CONFIGS_PIN_DEFAULT(dev, pinctrl, pin, cfgs) \
  108. PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, pinctrl, pin, cfgs)
  109. #define PIN_MAP_CONFIGS_PIN_HOG(dev, state, pin, cfgs) \
  110. PIN_MAP_CONFIGS_PIN(dev, state, dev, pin, cfgs)
  111. #define PIN_MAP_CONFIGS_PIN_HOG_DEFAULT(dev, pin, cfgs) \
  112. PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, dev, pin, cfgs)
  113. #define PIN_MAP_CONFIGS_GROUP(dev, state, pinctrl, grp, cfgs) \
  114. { \
  115. .dev_name = dev, \
  116. .name = state, \
  117. .type = PIN_MAP_TYPE_CONFIGS_GROUP, \
  118. .ctrl_dev_name = pinctrl, \
  119. .data.configs = { \
  120. .group_or_pin = grp, \
  121. .configs = cfgs, \
  122. .num_configs = ARRAY_SIZE(cfgs), \
  123. }, \
  124. }
  125. #define PIN_MAP_CONFIGS_GROUP_DEFAULT(dev, pinctrl, grp, cfgs) \
  126. PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, cfgs)
  127. #define PIN_MAP_CONFIGS_GROUP_HOG(dev, state, grp, cfgs) \
  128. PIN_MAP_CONFIGS_GROUP(dev, state, dev, grp, cfgs)
  129. #define PIN_MAP_CONFIGS_GROUP_HOG_DEFAULT(dev, grp, cfgs) \
  130. PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, cfgs)
  131. #ifdef CONFIG_PINCTRL
  132. extern int pinctrl_register_mappings(const struct pinctrl_map *map,
  133. unsigned num_maps);
  134. extern void pinctrl_unregister_mappings(const struct pinctrl_map *map);
  135. extern void pinctrl_provide_dummies(void);
  136. #else
  137. static inline int pinctrl_register_mappings(const struct pinctrl_map *map,
  138. unsigned num_maps)
  139. {
  140. return 0;
  141. }
  142. static inline void pinctrl_unregister_mappings(const struct pinctrl_map *map)
  143. {
  144. }
  145. static inline void pinctrl_provide_dummies(void)
  146. {
  147. }
  148. #endif /* !CONFIG_PINCTRL */
  149. #endif