pinctrl-uniphier.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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/bug.h>
  17. #include <linux/kernel.h>
  18. #include <linux/types.h>
  19. #define UNIPHIER_PINCTRL_PINMUX_BASE 0x0
  20. #define UNIPHIER_PINCTRL_LOAD_PINMUX 0x700
  21. #define UNIPHIER_PINCTRL_DRVCTRL_BASE 0x800
  22. #define UNIPHIER_PINCTRL_DRV2CTRL_BASE 0x900
  23. #define UNIPHIER_PINCTRL_PUPDCTRL_BASE 0xa00
  24. #define UNIPHIER_PINCTRL_IECTRL 0xd00
  25. /* input enable control register bit */
  26. #define UNIPHIER_PIN_IECTRL_SHIFT 0
  27. #define UNIPHIER_PIN_IECTRL_BITS 8
  28. #define UNIPHIER_PIN_IECTRL_MASK ((1UL << (UNIPHIER_PIN_IECTRL_BITS)) \
  29. - 1)
  30. /* drive strength control register number */
  31. #define UNIPHIER_PIN_DRVCTRL_SHIFT ((UNIPHIER_PIN_IECTRL_SHIFT) + \
  32. (UNIPHIER_PIN_IECTRL_BITS))
  33. #define UNIPHIER_PIN_DRVCTRL_BITS 9
  34. #define UNIPHIER_PIN_DRVCTRL_MASK ((1UL << (UNIPHIER_PIN_DRVCTRL_BITS)) \
  35. - 1)
  36. /* supported drive strength (mA) */
  37. #define UNIPHIER_PIN_DRV_STR_SHIFT ((UNIPHIER_PIN_DRVCTRL_SHIFT) + \
  38. (UNIPHIER_PIN_DRVCTRL_BITS))
  39. #define UNIPHIER_PIN_DRV_STR_BITS 3
  40. #define UNIPHIER_PIN_DRV_STR_MASK ((1UL << (UNIPHIER_PIN_DRV_STR_BITS)) \
  41. - 1)
  42. /* pull-up / pull-down register number */
  43. #define UNIPHIER_PIN_PUPDCTRL_SHIFT ((UNIPHIER_PIN_DRV_STR_SHIFT) + \
  44. (UNIPHIER_PIN_DRV_STR_BITS))
  45. #define UNIPHIER_PIN_PUPDCTRL_BITS 9
  46. #define UNIPHIER_PIN_PUPDCTRL_MASK ((1UL << (UNIPHIER_PIN_PUPDCTRL_BITS))\
  47. - 1)
  48. /* direction of pull register */
  49. #define UNIPHIER_PIN_PULL_DIR_SHIFT ((UNIPHIER_PIN_PUPDCTRL_SHIFT) + \
  50. (UNIPHIER_PIN_PUPDCTRL_BITS))
  51. #define UNIPHIER_PIN_PULL_DIR_BITS 3
  52. #define UNIPHIER_PIN_PULL_DIR_MASK ((1UL << (UNIPHIER_PIN_PULL_DIR_BITS))\
  53. - 1)
  54. #if UNIPHIER_PIN_PULL_DIR_SHIFT + UNIPHIER_PIN_PULL_DIR_BITS > BITS_PER_LONG
  55. #error "unable to pack pin attributes."
  56. #endif
  57. #define UNIPHIER_PIN_IECTRL_NONE (UNIPHIER_PIN_IECTRL_MASK)
  58. /* selectable drive strength */
  59. enum uniphier_pin_drv_str {
  60. UNIPHIER_PIN_DRV_4_8, /* 2 level control: 4/8 mA */
  61. UNIPHIER_PIN_DRV_8_12_16_20, /* 4 level control: 8/12/16/20 mA */
  62. UNIPHIER_PIN_DRV_FIXED_4, /* fixed to 4mA */
  63. UNIPHIER_PIN_DRV_FIXED_5, /* fixed to 5mA */
  64. UNIPHIER_PIN_DRV_FIXED_8, /* fixed to 8mA */
  65. UNIPHIER_PIN_DRV_NONE, /* no support (input only pin) */
  66. };
  67. /* direction of pull register (no pin supports bi-directional pull biasing) */
  68. enum uniphier_pin_pull_dir {
  69. UNIPHIER_PIN_PULL_UP, /* pull-up or disabled */
  70. UNIPHIER_PIN_PULL_DOWN, /* pull-down or disabled */
  71. UNIPHIER_PIN_PULL_UP_FIXED, /* always pull-up */
  72. UNIPHIER_PIN_PULL_DOWN_FIXED, /* always pull-down */
  73. UNIPHIER_PIN_PULL_NONE, /* no pull register */
  74. };
  75. #define UNIPHIER_PIN_IECTRL(x) \
  76. (((x) & (UNIPHIER_PIN_IECTRL_MASK)) << (UNIPHIER_PIN_IECTRL_SHIFT))
  77. #define UNIPHIER_PIN_DRVCTRL(x) \
  78. (((x) & (UNIPHIER_PIN_DRVCTRL_MASK)) << (UNIPHIER_PIN_DRVCTRL_SHIFT))
  79. #define UNIPHIER_PIN_DRV_STR(x) \
  80. (((x) & (UNIPHIER_PIN_DRV_STR_MASK)) << (UNIPHIER_PIN_DRV_STR_SHIFT))
  81. #define UNIPHIER_PIN_PUPDCTRL(x) \
  82. (((x) & (UNIPHIER_PIN_PUPDCTRL_MASK)) << (UNIPHIER_PIN_PUPDCTRL_SHIFT))
  83. #define UNIPHIER_PIN_PULL_DIR(x) \
  84. (((x) & (UNIPHIER_PIN_PULL_DIR_MASK)) << (UNIPHIER_PIN_PULL_DIR_SHIFT))
  85. #define UNIPHIER_PIN_ATTR_PACKED(iectrl, drvctrl, drv_str, pupdctrl, pull_dir)\
  86. (UNIPHIER_PIN_IECTRL(iectrl) | \
  87. UNIPHIER_PIN_DRVCTRL(drvctrl) | \
  88. UNIPHIER_PIN_DRV_STR(drv_str) | \
  89. UNIPHIER_PIN_PUPDCTRL(pupdctrl) | \
  90. UNIPHIER_PIN_PULL_DIR(pull_dir))
  91. static inline unsigned int uniphier_pin_get_iectrl(void *drv_data)
  92. {
  93. return ((unsigned long)drv_data >> UNIPHIER_PIN_IECTRL_SHIFT) &
  94. UNIPHIER_PIN_IECTRL_MASK;
  95. }
  96. static inline unsigned int uniphier_pin_get_drvctrl(void *drv_data)
  97. {
  98. return ((unsigned long)drv_data >> UNIPHIER_PIN_DRVCTRL_SHIFT) &
  99. UNIPHIER_PIN_DRVCTRL_MASK;
  100. }
  101. static inline unsigned int uniphier_pin_get_drv_str(void *drv_data)
  102. {
  103. return ((unsigned long)drv_data >> UNIPHIER_PIN_DRV_STR_SHIFT) &
  104. UNIPHIER_PIN_DRV_STR_MASK;
  105. }
  106. static inline unsigned int uniphier_pin_get_pupdctrl(void *drv_data)
  107. {
  108. return ((unsigned long)drv_data >> UNIPHIER_PIN_PUPDCTRL_SHIFT) &
  109. UNIPHIER_PIN_PUPDCTRL_MASK;
  110. }
  111. static inline unsigned int uniphier_pin_get_pull_dir(void *drv_data)
  112. {
  113. return ((unsigned long)drv_data >> UNIPHIER_PIN_PULL_DIR_SHIFT) &
  114. UNIPHIER_PIN_PULL_DIR_MASK;
  115. }
  116. enum uniphier_pinmux_gpio_range_type {
  117. UNIPHIER_PINMUX_GPIO_RANGE_PORT,
  118. UNIPHIER_PINMUX_GPIO_RANGE_IRQ,
  119. UNIPHIER_PINMUX_GPIO_RANGE_NONE,
  120. };
  121. struct uniphier_pinctrl_group {
  122. const char *name;
  123. const unsigned *pins;
  124. unsigned num_pins;
  125. const unsigned *muxvals;
  126. enum uniphier_pinmux_gpio_range_type range_type;
  127. };
  128. struct uniphier_pinmux_function {
  129. const char *name;
  130. const char * const *groups;
  131. unsigned num_groups;
  132. };
  133. struct uniphier_pinctrl_socdata {
  134. const struct uniphier_pinctrl_group *groups;
  135. int groups_count;
  136. const struct uniphier_pinmux_function *functions;
  137. int functions_count;
  138. unsigned mux_bits;
  139. unsigned reg_stride;
  140. bool load_pinctrl;
  141. };
  142. #define UNIPHIER_PINCTRL_PIN(a, b, c, d, e, f, g) \
  143. { \
  144. .number = a, \
  145. .name = b, \
  146. .drv_data = (void *)UNIPHIER_PIN_ATTR_PACKED(c, d, e, f, g), \
  147. }
  148. #define __UNIPHIER_PINCTRL_GROUP(grp, type) \
  149. { \
  150. .name = #grp, \
  151. .pins = grp##_pins, \
  152. .num_pins = ARRAY_SIZE(grp##_pins), \
  153. .muxvals = grp##_muxvals + \
  154. BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \
  155. ARRAY_SIZE(grp##_muxvals)), \
  156. .range_type = type, \
  157. }
  158. #define UNIPHIER_PINCTRL_GROUP(grp) \
  159. __UNIPHIER_PINCTRL_GROUP(grp, UNIPHIER_PINMUX_GPIO_RANGE_NONE)
  160. #define UNIPHIER_PINCTRL_GROUP_GPIO_RANGE_PORT(grp) \
  161. __UNIPHIER_PINCTRL_GROUP(grp, UNIPHIER_PINMUX_GPIO_RANGE_PORT)
  162. #define UNIPHIER_PINCTRL_GROUP_GPIO_RANGE_IRQ(grp) \
  163. __UNIPHIER_PINCTRL_GROUP(grp, UNIPHIER_PINMUX_GPIO_RANGE_IRQ)
  164. #define UNIPHIER_PINCTRL_GROUP_SINGLE(grp, array, ofst) \
  165. { \
  166. .name = #grp, \
  167. .pins = array##_pins + ofst, \
  168. .num_pins = 1, \
  169. .muxvals = array##_muxvals + ofst, \
  170. }
  171. #define UNIPHIER_PINMUX_FUNCTION(func) \
  172. { \
  173. .name = #func, \
  174. .groups = func##_groups, \
  175. .num_groups = ARRAY_SIZE(func##_groups), \
  176. }
  177. struct platform_device;
  178. struct pinctrl_desc;
  179. int uniphier_pinctrl_probe(struct platform_device *pdev,
  180. struct pinctrl_desc *desc,
  181. struct uniphier_pinctrl_socdata *socdata);
  182. int uniphier_pinctrl_remove(struct platform_device *pdev);
  183. #endif /* __PINCTRL_UNIPHIER_H__ */