pinctrl-meson.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Pin controller and GPIO driver for Amlogic Meson SoCs
  3. *
  4. * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * You should have received a copy of the GNU General Public License
  11. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #include <linux/gpio.h>
  14. #include <linux/pinctrl/pinctrl.h>
  15. #include <linux/regmap.h>
  16. #include <linux/types.h>
  17. /**
  18. * struct meson_pmx_group - a pinmux group
  19. *
  20. * @name: group name
  21. * @pins: pins in the group
  22. * @num_pins: number of pins in the group
  23. * @is_gpio: whether the group is a single GPIO group
  24. * @reg: register offset for the group in the domain mux registers
  25. * @bit bit index enabling the group
  26. * @domain: index of the domain this group belongs to
  27. */
  28. struct meson_pmx_group {
  29. const char *name;
  30. const unsigned int *pins;
  31. unsigned int num_pins;
  32. bool is_gpio;
  33. unsigned int reg;
  34. unsigned int bit;
  35. unsigned int domain;
  36. };
  37. /**
  38. * struct meson_pmx_func - a pinmux function
  39. *
  40. * @name: function name
  41. * @groups: groups in the function
  42. * @num_groups: number of groups in the function
  43. */
  44. struct meson_pmx_func {
  45. const char *name;
  46. const char * const *groups;
  47. unsigned int num_groups;
  48. };
  49. /**
  50. * struct meson_reg_desc - a register descriptor
  51. *
  52. * @reg: register offset in the regmap
  53. * @bit: bit index in register
  54. *
  55. * The structure describes the information needed to control pull,
  56. * pull-enable, direction, etc. for a single pin
  57. */
  58. struct meson_reg_desc {
  59. unsigned int reg;
  60. unsigned int bit;
  61. };
  62. /**
  63. * enum meson_reg_type - type of registers encoded in @meson_reg_desc
  64. */
  65. enum meson_reg_type {
  66. REG_PULLEN,
  67. REG_PULL,
  68. REG_DIR,
  69. REG_OUT,
  70. REG_IN,
  71. NUM_REG,
  72. };
  73. /**
  74. * struct meson bank
  75. *
  76. * @name: bank name
  77. * @first: first pin of the bank
  78. * @last: last pin of the bank
  79. * @regs: array of register descriptors
  80. *
  81. * A bank represents a set of pins controlled by a contiguous set of
  82. * bits in the domain registers. The structure specifies which bits in
  83. * the regmap control the different functionalities. Each member of
  84. * the @regs array refers to the first pin of the bank.
  85. */
  86. struct meson_bank {
  87. const char *name;
  88. unsigned int first;
  89. unsigned int last;
  90. struct meson_reg_desc regs[NUM_REG];
  91. };
  92. /**
  93. * struct meson_domain_data - domain platform data
  94. *
  95. * @name: name of the domain
  96. * @banks: set of banks belonging to the domain
  97. * @num_banks: number of banks in the domain
  98. */
  99. struct meson_domain_data {
  100. const char *name;
  101. struct meson_bank *banks;
  102. unsigned int num_banks;
  103. unsigned int pin_base;
  104. unsigned int num_pins;
  105. };
  106. /**
  107. * struct meson_domain
  108. *
  109. * @reg_mux: registers for mux settings
  110. * @reg_pullen: registers for pull-enable settings
  111. * @reg_pull: registers for pull settings
  112. * @reg_gpio: registers for gpio settings
  113. * @chip: gpio chip associated with the domain
  114. * @data; platform data for the domain
  115. * @node: device tree node for the domain
  116. *
  117. * A domain represents a set of banks controlled by the same set of
  118. * registers.
  119. */
  120. struct meson_domain {
  121. struct regmap *reg_mux;
  122. struct regmap *reg_pullen;
  123. struct regmap *reg_pull;
  124. struct regmap *reg_gpio;
  125. struct gpio_chip chip;
  126. struct meson_domain_data *data;
  127. struct device_node *of_node;
  128. };
  129. struct meson_pinctrl_data {
  130. const struct pinctrl_pin_desc *pins;
  131. struct meson_pmx_group *groups;
  132. struct meson_pmx_func *funcs;
  133. struct meson_domain_data *domain_data;
  134. unsigned int num_pins;
  135. unsigned int num_groups;
  136. unsigned int num_funcs;
  137. unsigned int num_domains;
  138. };
  139. struct meson_pinctrl {
  140. struct device *dev;
  141. struct pinctrl_dev *pcdev;
  142. struct pinctrl_desc desc;
  143. struct meson_pinctrl_data *data;
  144. struct meson_domain *domains;
  145. };
  146. #define PIN(x, b) (b + x)
  147. #define GROUP(grp, r, b) \
  148. { \
  149. .name = #grp, \
  150. .pins = grp ## _pins, \
  151. .num_pins = ARRAY_SIZE(grp ## _pins), \
  152. .reg = r, \
  153. .bit = b, \
  154. .domain = 0, \
  155. }
  156. #define GPIO_GROUP(gpio, b) \
  157. { \
  158. .name = #gpio, \
  159. .pins = (const unsigned int[]){ PIN(gpio, b) }, \
  160. .num_pins = 1, \
  161. .is_gpio = true, \
  162. }
  163. #define GROUP_AO(grp, r, b) \
  164. { \
  165. .name = #grp, \
  166. .pins = grp ## _pins, \
  167. .num_pins = ARRAY_SIZE(grp ## _pins), \
  168. .reg = r, \
  169. .bit = b, \
  170. .domain = 1, \
  171. }
  172. #define FUNCTION(fn) \
  173. { \
  174. .name = #fn, \
  175. .groups = fn ## _groups, \
  176. .num_groups = ARRAY_SIZE(fn ## _groups), \
  177. }
  178. #define BANK(n, f, l, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
  179. { \
  180. .name = n, \
  181. .first = f, \
  182. .last = l, \
  183. .regs = { \
  184. [REG_PULLEN] = { per, peb }, \
  185. [REG_PULL] = { pr, pb }, \
  186. [REG_DIR] = { dr, db }, \
  187. [REG_OUT] = { or, ob }, \
  188. [REG_IN] = { ir, ib }, \
  189. }, \
  190. }
  191. #define MESON_PIN(x, b) PINCTRL_PIN(PIN(x, b), #x)
  192. extern struct meson_pinctrl_data meson8_pinctrl_data;
  193. extern struct meson_pinctrl_data meson8b_pinctrl_data;