pinctrl-uniphier.h 6.9 KB

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