stm32-pinctrl.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (c) 2017 Linaro Limited
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_STM32_PINCTRL_H_
  7. #define ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_STM32_PINCTRL_H_
  8. #include <dt-bindings/pinctrl/stm32-pinctrl-common.h>
  9. /* Adapted from Linux: include/dt-bindings/pinctrl/stm32-pinfunc.h */
  10. /**
  11. * @brief Pin modes
  12. */
  13. #define STM32_AF0 0x0
  14. #define STM32_AF1 0x1
  15. #define STM32_AF2 0x2
  16. #define STM32_AF3 0x3
  17. #define STM32_AF4 0x4
  18. #define STM32_AF5 0x5
  19. #define STM32_AF6 0x6
  20. #define STM32_AF7 0x7
  21. #define STM32_AF8 0x8
  22. #define STM32_AF9 0x9
  23. #define STM32_AF10 0xa
  24. #define STM32_AF11 0xb
  25. #define STM32_AF12 0xc
  26. #define STM32_AF13 0xd
  27. #define STM32_AF14 0xe
  28. #define STM32_AF15 0xf
  29. #define STM32_ANALOG 0x10
  30. /**
  31. * @brief Macro to generate pinmux int using port, pin number and mode arguments
  32. * This is taken from Linux equivalent st,stm32f429-pinctrl binding
  33. */
  34. #define PIN_NO(port, line) (((port) - 'A') * 0x10 + (line))
  35. #define STM32_PINMUX(port, line, mode) (((PIN_NO(port, line)) << 8) | (STM32_ ## mode))
  36. /**
  37. * @brief PIN configuration bitfield
  38. *
  39. * Pin configuration is coded with the following
  40. * fields
  41. * Alternate Functions [ 0 : 3 ]
  42. * GPIO Mode [ 4 : 5 ]
  43. * GPIO Output type [ 6 ]
  44. * GPIO Speed [ 7 : 8 ]
  45. * GPIO PUPD config [ 9 : 10 ]
  46. *
  47. * Applicable to STM32F3, STM32F4, STM32L4 series
  48. */
  49. /* Alternate functions */
  50. #define STM32_FUNC_ALT_0 0
  51. #define STM32_FUNC_ALT_1 1
  52. #define STM32_FUNC_ALT_2 2
  53. #define STM32_FUNC_ALT_3 3
  54. #define STM32_FUNC_ALT_4 4
  55. #define STM32_FUNC_ALT_5 5
  56. #define STM32_FUNC_ALT_6 6
  57. #define STM32_FUNC_ALT_7 7
  58. #define STM32_FUNC_ALT_8 8
  59. #define STM32_FUNC_ALT_9 9
  60. #define STM32_FUNC_ALT_10 10
  61. #define STM32_FUNC_ALT_11 11
  62. #define STM32_FUNC_ALT_12 12
  63. #define STM32_FUNC_ALT_13 13
  64. #define STM32_FUNC_ALT_14 14
  65. #define STM32_FUNC_ALT_15 15
  66. #define STM32_AFR_MASK 0xF
  67. #define STM32_AFR_SHIFT 0
  68. /* GPIO Mode */
  69. #define STM32_MODER_INPUT_MODE (0x0<<STM32_MODER_SHIFT)
  70. #define STM32_MODER_OUTPUT_MODE (0x1<<STM32_MODER_SHIFT)
  71. #define STM32_MODER_ALT_MODE (0x2<<STM32_MODER_SHIFT)
  72. #define STM32_MODER_ANALOG_MODE (0x3<<STM32_MODER_SHIFT)
  73. #define STM32_MODER_MASK 0x3
  74. #define STM32_MODER_SHIFT 4
  75. /* GPIO Output type */
  76. #define STM32_OTYPER_PUSH_PULL (0x0<<STM32_OTYPER_SHIFT)
  77. #define STM32_OTYPER_OPEN_DRAIN (0x1<<STM32_OTYPER_SHIFT)
  78. #define STM32_OTYPER_MASK 0x1
  79. #define STM32_OTYPER_SHIFT 6
  80. /* GPIO speed */
  81. #define STM32_OSPEEDR_LOW_SPEED (0x0<<STM32_OSPEEDR_SHIFT)
  82. #define STM32_OSPEEDR_MEDIUM_SPEED (0x1<<STM32_OSPEEDR_SHIFT)
  83. #define STM32_OSPEEDR_HIGH_SPEED (0x2<<STM32_OSPEEDR_SHIFT)
  84. #define STM32_OSPEEDR_VERY_HIGH_SPEED (0x3<<STM32_OSPEEDR_SHIFT)
  85. #define STM32_OSPEEDR_MASK 0x3
  86. #define STM32_OSPEEDR_SHIFT 7
  87. /* GPIO High impedance/Pull-up/pull-down */
  88. #define STM32_PUPDR_NO_PULL (0x0<<STM32_PUPDR_SHIFT)
  89. #define STM32_PUPDR_PULL_UP (0x1<<STM32_PUPDR_SHIFT)
  90. #define STM32_PUPDR_PULL_DOWN (0x2<<STM32_PUPDR_SHIFT)
  91. #define STM32_PUPDR_MASK 0x3
  92. #define STM32_PUPDR_SHIFT 9
  93. /* Alternate functions definitions */
  94. #define STM32_PINMUX_ALT_FUNC_0 (STM32_FUNC_ALT_0 | STM32_MODER_ALT_MODE)
  95. #define STM32_PINMUX_ALT_FUNC_1 (STM32_FUNC_ALT_1 | STM32_MODER_ALT_MODE)
  96. #define STM32_PINMUX_ALT_FUNC_2 (STM32_FUNC_ALT_2 | STM32_MODER_ALT_MODE)
  97. #define STM32_PINMUX_ALT_FUNC_3 (STM32_FUNC_ALT_3 | STM32_MODER_ALT_MODE)
  98. #define STM32_PINMUX_ALT_FUNC_4 (STM32_FUNC_ALT_4 | STM32_MODER_ALT_MODE)
  99. #define STM32_PINMUX_ALT_FUNC_5 (STM32_FUNC_ALT_5 | STM32_MODER_ALT_MODE)
  100. #define STM32_PINMUX_ALT_FUNC_6 (STM32_FUNC_ALT_6 | STM32_MODER_ALT_MODE)
  101. #define STM32_PINMUX_ALT_FUNC_7 (STM32_FUNC_ALT_7 | STM32_MODER_ALT_MODE)
  102. #define STM32_PINMUX_ALT_FUNC_8 (STM32_FUNC_ALT_8 | STM32_MODER_ALT_MODE)
  103. #define STM32_PINMUX_ALT_FUNC_9 (STM32_FUNC_ALT_9 | STM32_MODER_ALT_MODE)
  104. #define STM32_PINMUX_ALT_FUNC_10 (STM32_FUNC_ALT_10 | STM32_MODER_ALT_MODE)
  105. #define STM32_PINMUX_ALT_FUNC_11 (STM32_FUNC_ALT_11 | STM32_MODER_ALT_MODE)
  106. #define STM32_PINMUX_ALT_FUNC_12 (STM32_FUNC_ALT_12 | STM32_MODER_ALT_MODE)
  107. #define STM32_PINMUX_ALT_FUNC_13 (STM32_FUNC_ALT_13 | STM32_MODER_ALT_MODE)
  108. #define STM32_PINMUX_ALT_FUNC_14 (STM32_FUNC_ALT_14 | STM32_MODER_ALT_MODE)
  109. #define STM32_PINMUX_ALT_FUNC_15 (STM32_FUNC_ALT_15 | STM32_MODER_ALT_MODE)
  110. /* Useful definitions */
  111. #define STM32_PUSHPULL_NOPULL (STM32_OTYPER_PUSH_PULL | STM32_PUPDR_NO_PULL)
  112. #define STM32_OPENDRAIN_PULLUP (STM32_OTYPER_OPEN_DRAIN | STM32_PUPDR_PULL_UP)
  113. #define STM32_PUSHPULL_PULLUP (STM32_OTYPER_PUSH_PULL | STM32_PUPDR_PULL_UP)
  114. #endif /* ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_STM32_PINCTRL_H_ */