machine.h 5.0 KB

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