pinctrl-uniphier.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2015-2017 Socionext Inc.
  4. * Author: Masahiro Yamada <[email protected]>
  5. */
  6. #ifndef __PINCTRL_UNIPHIER_H__
  7. #define __PINCTRL_UNIPHIER_H__
  8. #include <linux/bits.h>
  9. #include <linux/build_bug.h>
  10. #include <linux/kernel.h>
  11. #include <linux/types.h>
  12. struct platform_device;
  13. /* input enable control register bit */
  14. #define UNIPHIER_PIN_IECTRL_SHIFT 0
  15. #define UNIPHIER_PIN_IECTRL_BITS 3
  16. #define UNIPHIER_PIN_IECTRL_MASK ((1UL << (UNIPHIER_PIN_IECTRL_BITS)) \
  17. - 1)
  18. /* drive strength control register number */
  19. #define UNIPHIER_PIN_DRVCTRL_SHIFT ((UNIPHIER_PIN_IECTRL_SHIFT) + \
  20. (UNIPHIER_PIN_IECTRL_BITS))
  21. #define UNIPHIER_PIN_DRVCTRL_BITS 9
  22. #define UNIPHIER_PIN_DRVCTRL_MASK ((1UL << (UNIPHIER_PIN_DRVCTRL_BITS)) \
  23. - 1)
  24. /* drive control type */
  25. #define UNIPHIER_PIN_DRV_TYPE_SHIFT ((UNIPHIER_PIN_DRVCTRL_SHIFT) + \
  26. (UNIPHIER_PIN_DRVCTRL_BITS))
  27. #define UNIPHIER_PIN_DRV_TYPE_BITS 3
  28. #define UNIPHIER_PIN_DRV_TYPE_MASK ((1UL << (UNIPHIER_PIN_DRV_TYPE_BITS)) \
  29. - 1)
  30. /* pull-up / pull-down register number */
  31. #define UNIPHIER_PIN_PUPDCTRL_SHIFT ((UNIPHIER_PIN_DRV_TYPE_SHIFT) + \
  32. (UNIPHIER_PIN_DRV_TYPE_BITS))
  33. #define UNIPHIER_PIN_PUPDCTRL_BITS 9
  34. #define UNIPHIER_PIN_PUPDCTRL_MASK ((1UL << (UNIPHIER_PIN_PUPDCTRL_BITS))\
  35. - 1)
  36. /* direction of pull register */
  37. #define UNIPHIER_PIN_PULL_DIR_SHIFT ((UNIPHIER_PIN_PUPDCTRL_SHIFT) + \
  38. (UNIPHIER_PIN_PUPDCTRL_BITS))
  39. #define UNIPHIER_PIN_PULL_DIR_BITS 3
  40. #define UNIPHIER_PIN_PULL_DIR_MASK ((1UL << (UNIPHIER_PIN_PULL_DIR_BITS))\
  41. - 1)
  42. #if UNIPHIER_PIN_PULL_DIR_SHIFT + UNIPHIER_PIN_PULL_DIR_BITS > BITS_PER_LONG
  43. #error "unable to pack pin attributes."
  44. #endif
  45. #define UNIPHIER_PIN_IECTRL_NONE (UNIPHIER_PIN_IECTRL_MASK)
  46. #define UNIPHIER_PIN_IECTRL_EXIST 0
  47. /* drive control type */
  48. enum uniphier_pin_drv_type {
  49. UNIPHIER_PIN_DRV_1BIT, /* 2 level control: 4/8 mA */
  50. UNIPHIER_PIN_DRV_2BIT, /* 4 level control: 8/12/16/20 mA */
  51. UNIPHIER_PIN_DRV_3BIT, /* 8 level control: 4/5/7/9/11/12/14/16 mA */
  52. UNIPHIER_PIN_DRV_FIXED4, /* fixed to 4mA */
  53. UNIPHIER_PIN_DRV_FIXED5, /* fixed to 5mA */
  54. UNIPHIER_PIN_DRV_FIXED8, /* fixed to 8mA */
  55. UNIPHIER_PIN_DRV_NONE, /* no support (input only pin) */
  56. };
  57. /* direction of pull register (no pin supports bi-directional pull biasing) */
  58. enum uniphier_pin_pull_dir {
  59. UNIPHIER_PIN_PULL_UP, /* pull-up or disabled */
  60. UNIPHIER_PIN_PULL_DOWN, /* pull-down or disabled */
  61. UNIPHIER_PIN_PULL_UP_FIXED, /* always pull-up */
  62. UNIPHIER_PIN_PULL_DOWN_FIXED, /* always pull-down */
  63. UNIPHIER_PIN_PULL_NONE, /* no pull register */
  64. };
  65. #define UNIPHIER_PIN_IECTRL(x) \
  66. (((x) & (UNIPHIER_PIN_IECTRL_MASK)) << (UNIPHIER_PIN_IECTRL_SHIFT))
  67. #define UNIPHIER_PIN_DRVCTRL(x) \
  68. (((x) & (UNIPHIER_PIN_DRVCTRL_MASK)) << (UNIPHIER_PIN_DRVCTRL_SHIFT))
  69. #define UNIPHIER_PIN_DRV_TYPE(x) \
  70. (((x) & (UNIPHIER_PIN_DRV_TYPE_MASK)) << (UNIPHIER_PIN_DRV_TYPE_SHIFT))
  71. #define UNIPHIER_PIN_PUPDCTRL(x) \
  72. (((x) & (UNIPHIER_PIN_PUPDCTRL_MASK)) << (UNIPHIER_PIN_PUPDCTRL_SHIFT))
  73. #define UNIPHIER_PIN_PULL_DIR(x) \
  74. (((x) & (UNIPHIER_PIN_PULL_DIR_MASK)) << (UNIPHIER_PIN_PULL_DIR_SHIFT))
  75. #define UNIPHIER_PIN_ATTR_PACKED(iectrl, drvctrl, drv_type, pupdctrl, pull_dir)\
  76. (UNIPHIER_PIN_IECTRL(iectrl) | \
  77. UNIPHIER_PIN_DRVCTRL(drvctrl) | \
  78. UNIPHIER_PIN_DRV_TYPE(drv_type) | \
  79. UNIPHIER_PIN_PUPDCTRL(pupdctrl) | \
  80. UNIPHIER_PIN_PULL_DIR(pull_dir))
  81. static inline unsigned int uniphier_pin_get_iectrl(void *drv_data)
  82. {
  83. return ((unsigned long)drv_data >> UNIPHIER_PIN_IECTRL_SHIFT) &
  84. UNIPHIER_PIN_IECTRL_MASK;
  85. }
  86. static inline unsigned int uniphier_pin_get_drvctrl(void *drv_data)
  87. {
  88. return ((unsigned long)drv_data >> UNIPHIER_PIN_DRVCTRL_SHIFT) &
  89. UNIPHIER_PIN_DRVCTRL_MASK;
  90. }
  91. static inline unsigned int uniphier_pin_get_drv_type(void *drv_data)
  92. {
  93. return ((unsigned long)drv_data >> UNIPHIER_PIN_DRV_TYPE_SHIFT) &
  94. UNIPHIER_PIN_DRV_TYPE_MASK;
  95. }
  96. static inline unsigned int uniphier_pin_get_pupdctrl(void *drv_data)
  97. {
  98. return ((unsigned long)drv_data >> UNIPHIER_PIN_PUPDCTRL_SHIFT) &
  99. UNIPHIER_PIN_PUPDCTRL_MASK;
  100. }
  101. static inline unsigned int uniphier_pin_get_pull_dir(void *drv_data)
  102. {
  103. return ((unsigned long)drv_data >> UNIPHIER_PIN_PULL_DIR_SHIFT) &
  104. UNIPHIER_PIN_PULL_DIR_MASK;
  105. }
  106. struct uniphier_pinctrl_group {
  107. const char *name;
  108. const unsigned *pins;
  109. unsigned num_pins;
  110. const int *muxvals;
  111. };
  112. struct uniphier_pinmux_function {
  113. const char *name;
  114. const char * const *groups;
  115. unsigned num_groups;
  116. };
  117. struct uniphier_pinctrl_socdata {
  118. const struct pinctrl_pin_desc *pins;
  119. unsigned int npins;
  120. const struct uniphier_pinctrl_group *groups;
  121. int groups_count;
  122. const struct uniphier_pinmux_function *functions;
  123. int functions_count;
  124. int (*get_gpio_muxval)(unsigned int pin, unsigned int gpio_offset);
  125. unsigned int caps;
  126. #define UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL BIT(1)
  127. #define UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE BIT(0)
  128. };
  129. #define UNIPHIER_PINCTRL_PIN(a, b, c, d, e, f, g) \
  130. { \
  131. .number = a, \
  132. .name = b, \
  133. .drv_data = (void *)UNIPHIER_PIN_ATTR_PACKED(c, d, e, f, g), \
  134. }
  135. #define __UNIPHIER_PINCTRL_GROUP(grp, mux) \
  136. { \
  137. .name = #grp, \
  138. .pins = grp##_pins, \
  139. .num_pins = ARRAY_SIZE(grp##_pins), \
  140. .muxvals = mux, \
  141. }
  142. #define UNIPHIER_PINCTRL_GROUP(grp) \
  143. __UNIPHIER_PINCTRL_GROUP(grp, \
  144. grp##_muxvals + \
  145. BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \
  146. ARRAY_SIZE(grp##_muxvals)))
  147. #define UNIPHIER_PINCTRL_GROUP_GPIO(grp) \
  148. __UNIPHIER_PINCTRL_GROUP(grp, NULL)
  149. #define UNIPHIER_PINMUX_FUNCTION(func) \
  150. { \
  151. .name = #func, \
  152. .groups = func##_groups, \
  153. .num_groups = ARRAY_SIZE(func##_groups), \
  154. }
  155. int uniphier_pinctrl_probe(struct platform_device *pdev,
  156. const struct uniphier_pinctrl_socdata *socdata);
  157. extern const struct dev_pm_ops uniphier_pinctrl_pm_ops;
  158. #endif /* __PINCTRL_UNIPHIER_H__ */