pinctrl-meson.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2016 - Beniamino Galvani <b.galvani@gmail.com>
  4. */
  5. #ifndef __PINCTRL_MESON_H__
  6. #define __PINCTRL_MESON_H__
  7. #include <linux/types.h>
  8. struct meson_pmx_group {
  9. const char *name;
  10. const unsigned int *pins;
  11. unsigned int num_pins;
  12. bool is_gpio;
  13. unsigned int reg;
  14. unsigned int bit;
  15. };
  16. struct meson_pmx_func {
  17. const char *name;
  18. const char * const *groups;
  19. unsigned int num_groups;
  20. };
  21. struct meson_pinctrl_data {
  22. const char *name;
  23. struct meson_pmx_group *groups;
  24. struct meson_pmx_func *funcs;
  25. struct meson_bank *banks;
  26. unsigned int pin_base;
  27. unsigned int num_pins;
  28. unsigned int num_groups;
  29. unsigned int num_funcs;
  30. unsigned int num_banks;
  31. };
  32. struct meson_pinctrl {
  33. struct meson_pinctrl_data *data;
  34. void __iomem *reg_mux;
  35. void __iomem *reg_gpio;
  36. };
  37. /**
  38. * struct meson_reg_desc - a register descriptor
  39. *
  40. * @reg: register offset in the regmap
  41. * @bit: bit index in register
  42. *
  43. * The structure describes the information needed to control pull,
  44. * pull-enable, direction, etc. for a single pin
  45. */
  46. struct meson_reg_desc {
  47. unsigned int reg;
  48. unsigned int bit;
  49. };
  50. /**
  51. * enum meson_reg_type - type of registers encoded in @meson_reg_desc
  52. */
  53. enum meson_reg_type {
  54. REG_PULLEN,
  55. REG_PULL,
  56. REG_DIR,
  57. REG_OUT,
  58. REG_IN,
  59. NUM_REG,
  60. };
  61. /**
  62. * struct meson bank
  63. *
  64. * @name: bank name
  65. * @first: first pin of the bank
  66. * @last: last pin of the bank
  67. * @regs: array of register descriptors
  68. *
  69. * A bank represents a set of pins controlled by a contiguous set of
  70. * bits in the domain registers. The structure specifies which bits in
  71. * the regmap control the different functionalities. Each member of
  72. * the @regs array refers to the first pin of the bank.
  73. */
  74. struct meson_bank {
  75. const char *name;
  76. unsigned int first;
  77. unsigned int last;
  78. struct meson_reg_desc regs[NUM_REG];
  79. };
  80. #define PIN(x, b) (b + x)
  81. #define GROUP(grp, r, b) \
  82. { \
  83. .name = #grp, \
  84. .pins = grp ## _pins, \
  85. .num_pins = ARRAY_SIZE(grp ## _pins), \
  86. .reg = r, \
  87. .bit = b, \
  88. }
  89. #define GPIO_GROUP(gpio, b) \
  90. { \
  91. .name = #gpio, \
  92. .pins = (const unsigned int[]){ PIN(gpio, b) }, \
  93. .num_pins = 1, \
  94. .is_gpio = true, \
  95. }
  96. #define FUNCTION(fn) \
  97. { \
  98. .name = #fn, \
  99. .groups = fn ## _groups, \
  100. .num_groups = ARRAY_SIZE(fn ## _groups), \
  101. }
  102. #define BANK(n, f, l, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
  103. { \
  104. .name = n, \
  105. .first = f, \
  106. .last = l, \
  107. .regs = { \
  108. [REG_PULLEN] = { per, peb }, \
  109. [REG_PULL] = { pr, pb }, \
  110. [REG_DIR] = { dr, db }, \
  111. [REG_OUT] = { or, ob }, \
  112. [REG_IN] = { ir, ib }, \
  113. }, \
  114. }
  115. #define MESON_PIN(x, b) PINCTRL_PIN(PIN(x, b), #x)
  116. extern const struct pinctrl_ops meson_pinctrl_ops;
  117. int meson_pinctrl_probe(struct udevice *dev);
  118. #endif /* __PINCTRL_MESON_H__ */