pinctrl-uniphier.h 6.3 KB

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