pinctrl-meson.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. };
  36. /**
  37. * struct meson_pmx_func - a pinmux function
  38. *
  39. * @name: function name
  40. * @groups: groups in the function
  41. * @num_groups: number of groups in the function
  42. */
  43. struct meson_pmx_func {
  44. const char *name;
  45. const char * const *groups;
  46. unsigned int num_groups;
  47. };
  48. /**
  49. * struct meson_reg_desc - a register descriptor
  50. *
  51. * @reg: register offset in the regmap
  52. * @bit: bit index in register
  53. *
  54. * The structure describes the information needed to control pull,
  55. * pull-enable, direction, etc. for a single pin
  56. */
  57. struct meson_reg_desc {
  58. unsigned int reg;
  59. unsigned int bit;
  60. };
  61. /**
  62. * enum meson_reg_type - type of registers encoded in @meson_reg_desc
  63. */
  64. enum meson_reg_type {
  65. REG_PULLEN,
  66. REG_PULL,
  67. REG_DIR,
  68. REG_OUT,
  69. REG_IN,
  70. NUM_REG,
  71. };
  72. /**
  73. * struct meson bank
  74. *
  75. * @name: bank name
  76. * @first: first pin of the bank
  77. * @last: last pin of the bank
  78. * @regs: array of register descriptors
  79. *
  80. * A bank represents a set of pins controlled by a contiguous set of
  81. * bits in the domain registers. The structure specifies which bits in
  82. * the regmap control the different functionalities. Each member of
  83. * the @regs array refers to the first pin of the bank.
  84. */
  85. struct meson_bank {
  86. const char *name;
  87. unsigned int first;
  88. unsigned int last;
  89. struct meson_reg_desc regs[NUM_REG];
  90. };
  91. /**
  92. * struct meson_domain_data - domain platform data
  93. *
  94. * @name: name of the domain
  95. * @banks: set of banks belonging to the domain
  96. * @num_banks: number of banks in the domain
  97. */
  98. struct meson_domain_data {
  99. const char *name;
  100. struct meson_bank *banks;
  101. unsigned int num_banks;
  102. unsigned int pin_base;
  103. unsigned int num_pins;
  104. };
  105. /**
  106. * struct meson_domain
  107. *
  108. * @reg_mux: registers for mux settings
  109. * @reg_pullen: registers for pull-enable settings
  110. * @reg_pull: registers for pull settings
  111. * @reg_gpio: registers for gpio settings
  112. * @chip: gpio chip associated with the domain
  113. * @data; platform data for the domain
  114. * @node: device tree node for the domain
  115. *
  116. * A domain represents a set of banks controlled by the same set of
  117. * registers.
  118. */
  119. struct meson_domain {
  120. struct regmap *reg_mux;
  121. struct regmap *reg_pullen;
  122. struct regmap *reg_pull;
  123. struct regmap *reg_gpio;
  124. struct gpio_chip chip;
  125. struct meson_domain_data *data;
  126. struct device_node *of_node;
  127. };
  128. struct meson_pinctrl_data {
  129. const struct pinctrl_pin_desc *pins;
  130. struct meson_pmx_group *groups;
  131. struct meson_pmx_func *funcs;
  132. struct meson_domain_data *domain_data;
  133. unsigned int num_pins;
  134. unsigned int num_groups;
  135. unsigned int num_funcs;
  136. };
  137. struct meson_pinctrl {
  138. struct device *dev;
  139. struct pinctrl_dev *pcdev;
  140. struct pinctrl_desc desc;
  141. struct meson_pinctrl_data *data;
  142. struct meson_domain *domain;
  143. };
  144. #define PIN(x, b) (b + x)
  145. #define GROUP(grp, r, b) \
  146. { \
  147. .name = #grp, \
  148. .pins = grp ## _pins, \
  149. .num_pins = ARRAY_SIZE(grp ## _pins), \
  150. .reg = r, \
  151. .bit = b, \
  152. }
  153. #define GPIO_GROUP(gpio, b) \
  154. { \
  155. .name = #gpio, \
  156. .pins = (const unsigned int[]){ PIN(gpio, b) }, \
  157. .num_pins = 1, \
  158. .is_gpio = true, \
  159. }
  160. #define FUNCTION(fn) \
  161. { \
  162. .name = #fn, \
  163. .groups = fn ## _groups, \
  164. .num_groups = ARRAY_SIZE(fn ## _groups), \
  165. }
  166. #define BANK(n, f, l, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
  167. { \
  168. .name = n, \
  169. .first = f, \
  170. .last = l, \
  171. .regs = { \
  172. [REG_PULLEN] = { per, peb }, \
  173. [REG_PULL] = { pr, pb }, \
  174. [REG_DIR] = { dr, db }, \
  175. [REG_OUT] = { or, ob }, \
  176. [REG_IN] = { ir, ib }, \
  177. }, \
  178. }
  179. #define MESON_PIN(x, b) PINCTRL_PIN(PIN(x, b), #x)
  180. extern struct meson_pinctrl_data meson8_cbus_pinctrl_data;
  181. extern struct meson_pinctrl_data meson8_aobus_pinctrl_data;
  182. extern struct meson_pinctrl_data meson8b_cbus_pinctrl_data;
  183. extern struct meson_pinctrl_data meson8b_aobus_pinctrl_data;