pinctrl-meson.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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/driver.h>
  14. #include <linux/pinctrl/pinctrl.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/regmap.h>
  17. #include <linux/types.h>
  18. /**
  19. * struct meson_pmx_group - a pinmux group
  20. *
  21. * @name: group name
  22. * @pins: pins in the group
  23. * @num_pins: number of pins in the group
  24. * @is_gpio: whether the group is a single GPIO group
  25. * @reg: register offset for the group in the domain mux registers
  26. * @bit bit index enabling the group
  27. * @domain: index of the domain this group belongs to
  28. */
  29. struct meson_pmx_group {
  30. const char *name;
  31. const unsigned int *pins;
  32. unsigned int num_pins;
  33. const void *data;
  34. };
  35. /**
  36. * struct meson_pmx_func - a pinmux function
  37. *
  38. * @name: function name
  39. * @groups: groups in the function
  40. * @num_groups: number of groups in the function
  41. */
  42. struct meson_pmx_func {
  43. const char *name;
  44. const char * const *groups;
  45. unsigned int num_groups;
  46. };
  47. /**
  48. * struct meson_reg_desc - a register descriptor
  49. *
  50. * @reg: register offset in the regmap
  51. * @bit: bit index in register
  52. *
  53. * The structure describes the information needed to control pull,
  54. * pull-enable, direction, etc. for a single pin
  55. */
  56. struct meson_reg_desc {
  57. unsigned int reg;
  58. unsigned int bit;
  59. };
  60. /**
  61. * enum meson_reg_type - type of registers encoded in @meson_reg_desc
  62. */
  63. enum meson_reg_type {
  64. REG_PULLEN,
  65. REG_PULL,
  66. REG_DIR,
  67. REG_OUT,
  68. REG_IN,
  69. NUM_REG,
  70. };
  71. /**
  72. * struct meson bank
  73. *
  74. * @name: bank name
  75. * @first: first pin of the bank
  76. * @last: last pin of the bank
  77. * @irq: hwirq base number 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. int irq_first;
  90. int irq_last;
  91. struct meson_reg_desc regs[NUM_REG];
  92. };
  93. struct meson_pinctrl_data {
  94. const char *name;
  95. const struct pinctrl_pin_desc *pins;
  96. struct meson_pmx_group *groups;
  97. struct meson_pmx_func *funcs;
  98. unsigned int num_pins;
  99. unsigned int num_groups;
  100. unsigned int num_funcs;
  101. struct meson_bank *banks;
  102. unsigned int num_banks;
  103. const struct pinmux_ops *pmx_ops;
  104. void *pmx_data;
  105. };
  106. struct meson_pinctrl {
  107. struct device *dev;
  108. struct pinctrl_dev *pcdev;
  109. struct pinctrl_desc desc;
  110. struct meson_pinctrl_data *data;
  111. struct regmap *reg_mux;
  112. struct regmap *reg_pullen;
  113. struct regmap *reg_pull;
  114. struct regmap *reg_gpio;
  115. struct gpio_chip chip;
  116. struct device_node *of_node;
  117. };
  118. #define FUNCTION(fn) \
  119. { \
  120. .name = #fn, \
  121. .groups = fn ## _groups, \
  122. .num_groups = ARRAY_SIZE(fn ## _groups), \
  123. }
  124. #define BANK(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
  125. { \
  126. .name = n, \
  127. .first = f, \
  128. .last = l, \
  129. .irq_first = fi, \
  130. .irq_last = li, \
  131. .regs = { \
  132. [REG_PULLEN] = { per, peb }, \
  133. [REG_PULL] = { pr, pb }, \
  134. [REG_DIR] = { dr, db }, \
  135. [REG_OUT] = { or, ob }, \
  136. [REG_IN] = { ir, ib }, \
  137. }, \
  138. }
  139. #define MESON_PIN(x) PINCTRL_PIN(x, #x)
  140. /* Common pmx functions */
  141. int meson_pmx_get_funcs_count(struct pinctrl_dev *pcdev);
  142. const char *meson_pmx_get_func_name(struct pinctrl_dev *pcdev,
  143. unsigned selector);
  144. int meson_pmx_get_groups(struct pinctrl_dev *pcdev,
  145. unsigned selector,
  146. const char * const **groups,
  147. unsigned * const num_groups);
  148. /* Common probe function */
  149. int meson_pinctrl_probe(struct platform_device *pdev);