mfp.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. ==============================================
  2. MFP Configuration for PXA2xx/PXA3xx Processors
  3. ==============================================
  4. Eric Miao <[email protected]>
  5. MFP stands for Multi-Function Pin, which is the pin-mux logic on PXA3xx and
  6. later PXA series processors. This document describes the existing MFP API,
  7. and how board/platform driver authors could make use of it.
  8. Basic Concept
  9. =============
  10. Unlike the GPIO alternate function settings on PXA25x and PXA27x, a new MFP
  11. mechanism is introduced from PXA3xx to completely move the pin-mux functions
  12. out of the GPIO controller. In addition to pin-mux configurations, the MFP
  13. also controls the low power state, driving strength, pull-up/down and event
  14. detection of each pin. Below is a diagram of internal connections between
  15. the MFP logic and the remaining SoC peripherals::
  16. +--------+
  17. | |--(GPIO19)--+
  18. | GPIO | |
  19. | |--(GPIO...) |
  20. +--------+ |
  21. | +---------+
  22. +--------+ +------>| |
  23. | PWM2 |--(PWM_OUT)-------->| MFP |
  24. +--------+ +------>| |-------> to external PAD
  25. | +---->| |
  26. +--------+ | | +-->| |
  27. | SSP2 |---(TXD)----+ | | +---------+
  28. +--------+ | |
  29. | |
  30. +--------+ | |
  31. | Keypad |--(MKOUT4)----+ |
  32. +--------+ |
  33. |
  34. +--------+ |
  35. | UART2 |---(TXD)--------+
  36. +--------+
  37. NOTE: the external pad is named as MFP_PIN_GPIO19, it doesn't necessarily
  38. mean it's dedicated for GPIO19, only as a hint that internally this pin
  39. can be routed from GPIO19 of the GPIO controller.
  40. To better understand the change from PXA25x/PXA27x GPIO alternate function
  41. to this new MFP mechanism, here are several key points:
  42. 1. GPIO controller on PXA3xx is now a dedicated controller, same as other
  43. internal controllers like PWM, SSP and UART, with 128 internal signals
  44. which can be routed to external through one or more MFPs (e.g. GPIO<0>
  45. can be routed through either MFP_PIN_GPIO0 as well as MFP_PIN_GPIO0_2,
  46. see arch/arm/mach-pxa/mfp-pxa300.h)
  47. 2. Alternate function configuration is removed from this GPIO controller,
  48. the remaining functions are pure GPIO-specific, i.e.
  49. - GPIO signal level control
  50. - GPIO direction control
  51. - GPIO level change detection
  52. 3. Low power state for each pin is now controlled by MFP, this means the
  53. PGSRx registers on PXA2xx are now useless on PXA3xx
  54. 4. Wakeup detection is now controlled by MFP, PWER does not control the
  55. wakeup from GPIO(s) any more, depending on the sleeping state, ADxER
  56. (as defined in pxa3xx-regs.h) controls the wakeup from MFP
  57. NOTE: with such a clear separation of MFP and GPIO, by GPIO<xx> we normally
  58. mean it is a GPIO signal, and by MFP<xxx> or pin xxx, we mean a physical
  59. pad (or ball).
  60. MFP API Usage
  61. =============
  62. For board code writers, here are some guidelines:
  63. 1. include ONE of the following header files in your <board>.c:
  64. - #include "mfp-pxa25x.h"
  65. - #include "mfp-pxa27x.h"
  66. - #include "mfp-pxa300.h"
  67. - #include "mfp-pxa320.h"
  68. - #include "mfp-pxa930.h"
  69. NOTE: only one file in your <board>.c, depending on the processors used,
  70. because pin configuration definitions may conflict in these file (i.e.
  71. same name, different meaning and settings on different processors). E.g.
  72. for zylonite platform, which support both PXA300/PXA310 and PXA320, two
  73. separate files are introduced: zylonite_pxa300.c and zylonite_pxa320.c
  74. (in addition to handle MFP configuration differences, they also handle
  75. the other differences between the two combinations).
  76. NOTE: PXA300 and PXA310 are almost identical in pin configurations (with
  77. PXA310 supporting some additional ones), thus the difference is actually
  78. covered in a single mfp-pxa300.h.
  79. 2. prepare an array for the initial pin configurations, e.g.::
  80. static unsigned long mainstone_pin_config[] __initdata = {
  81. /* Chip Select */
  82. GPIO15_nCS_1,
  83. /* LCD - 16bpp Active TFT */
  84. GPIOxx_TFT_LCD_16BPP,
  85. GPIO16_PWM0_OUT, /* Backlight */
  86. /* MMC */
  87. GPIO32_MMC_CLK,
  88. GPIO112_MMC_CMD,
  89. GPIO92_MMC_DAT_0,
  90. GPIO109_MMC_DAT_1,
  91. GPIO110_MMC_DAT_2,
  92. GPIO111_MMC_DAT_3,
  93. ...
  94. /* GPIO */
  95. GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
  96. };
  97. a) once the pin configurations are passed to pxa{2xx,3xx}_mfp_config(),
  98. and written to the actual registers, they are useless and may discard,
  99. adding '__initdata' will help save some additional bytes here.
  100. b) when there is only one possible pin configurations for a component,
  101. some simplified definitions can be used, e.g. GPIOxx_TFT_LCD_16BPP on
  102. PXA25x and PXA27x processors
  103. c) if by board design, a pin can be configured to wake up the system
  104. from low power state, it can be 'OR'ed with any of:
  105. WAKEUP_ON_EDGE_BOTH
  106. WAKEUP_ON_EDGE_RISE
  107. WAKEUP_ON_EDGE_FALL
  108. WAKEUP_ON_LEVEL_HIGH - specifically for enabling of keypad GPIOs,
  109. to indicate that this pin has the capability of wake-up the system,
  110. and on which edge(s). This, however, doesn't necessarily mean the
  111. pin _will_ wakeup the system, it will only when set_irq_wake() is
  112. invoked with the corresponding GPIO IRQ (GPIO_IRQ(xx) or gpio_to_irq())
  113. and eventually calls gpio_set_wake() for the actual register setting.
  114. d) although PXA3xx MFP supports edge detection on each pin, the
  115. internal logic will only wakeup the system when those specific bits
  116. in ADxER registers are set, which can be well mapped to the
  117. corresponding peripheral, thus set_irq_wake() can be called with
  118. the peripheral IRQ to enable the wakeup.
  119. MFP on PXA3xx
  120. =============
  121. Every external I/O pad on PXA3xx (excluding those for special purpose) has
  122. one MFP logic associated, and is controlled by one MFP register (MFPR).
  123. The MFPR has the following bit definitions (for PXA300/PXA310/PXA320)::
  124. 31 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
  125. +-------------------------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  126. | RESERVED |PS|PU|PD| DRIVE |SS|SD|SO|EC|EF|ER|--| AF_SEL |
  127. +-------------------------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  128. Bit 3: RESERVED
  129. Bit 4: EDGE_RISE_EN - enable detection of rising edge on this pin
  130. Bit 5: EDGE_FALL_EN - enable detection of falling edge on this pin
  131. Bit 6: EDGE_CLEAR - disable edge detection on this pin
  132. Bit 7: SLEEP_OE_N - enable outputs during low power modes
  133. Bit 8: SLEEP_DATA - output data on the pin during low power modes
  134. Bit 9: SLEEP_SEL - selection control for low power modes signals
  135. Bit 13: PULLDOWN_EN - enable the internal pull-down resistor on this pin
  136. Bit 14: PULLUP_EN - enable the internal pull-up resistor on this pin
  137. Bit 15: PULL_SEL - pull state controlled by selected alternate function
  138. (0) or by PULL{UP,DOWN}_EN bits (1)
  139. Bit 0 - 2: AF_SEL - alternate function selection, 8 possibilities, from 0-7
  140. Bit 10-12: DRIVE - drive strength and slew rate
  141. 0b000 - fast 1mA
  142. 0b001 - fast 2mA
  143. 0b002 - fast 3mA
  144. 0b003 - fast 4mA
  145. 0b004 - slow 6mA
  146. 0b005 - fast 6mA
  147. 0b006 - slow 10mA
  148. 0b007 - fast 10mA
  149. MFP Design for PXA2xx/PXA3xx
  150. ============================
  151. Due to the difference of pin-mux handling between PXA2xx and PXA3xx, a unified
  152. MFP API is introduced to cover both series of processors.
  153. The basic idea of this design is to introduce definitions for all possible pin
  154. configurations, these definitions are processor and platform independent, and
  155. the actual API invoked to convert these definitions into register settings and
  156. make them effective there-after.
  157. Files Involved
  158. --------------
  159. - arch/arm/mach-pxa/include/mach/mfp.h
  160. for
  161. 1. Unified pin definitions - enum constants for all configurable pins
  162. 2. processor-neutral bit definitions for a possible MFP configuration
  163. - arch/arm/mach-pxa/mfp-pxa3xx.h
  164. for PXA3xx specific MFPR register bit definitions and PXA3xx common pin
  165. configurations
  166. - arch/arm/mach-pxa/mfp-pxa2xx.h
  167. for PXA2xx specific definitions and PXA25x/PXA27x common pin configurations
  168. - arch/arm/mach-pxa/mfp-pxa25x.h
  169. arch/arm/mach-pxa/mfp-pxa27x.h
  170. arch/arm/mach-pxa/mfp-pxa300.h
  171. arch/arm/mach-pxa/mfp-pxa320.h
  172. arch/arm/mach-pxa/mfp-pxa930.h
  173. for processor specific definitions
  174. - arch/arm/mach-pxa/mfp-pxa3xx.c
  175. - arch/arm/mach-pxa/mfp-pxa2xx.c
  176. for implementation of the pin configuration to take effect for the actual
  177. processor.
  178. Pin Configuration
  179. -----------------
  180. The following comments are copied from mfp.h (see the actual source code
  181. for most updated info)::
  182. /*
  183. * a possible MFP configuration is represented by a 32-bit integer
  184. *
  185. * bit 0.. 9 - MFP Pin Number (1024 Pins Maximum)
  186. * bit 10..12 - Alternate Function Selection
  187. * bit 13..15 - Drive Strength
  188. * bit 16..18 - Low Power Mode State
  189. * bit 19..20 - Low Power Mode Edge Detection
  190. * bit 21..22 - Run Mode Pull State
  191. *
  192. * to facilitate the definition, the following macros are provided
  193. *
  194. * MFP_CFG_DEFAULT - default MFP configuration value, with
  195. * alternate function = 0,
  196. * drive strength = fast 3mA (MFP_DS03X)
  197. * low power mode = default
  198. * edge detection = none
  199. *
  200. * MFP_CFG - default MFPR value with alternate function
  201. * MFP_CFG_DRV - default MFPR value with alternate function and
  202. * pin drive strength
  203. * MFP_CFG_LPM - default MFPR value with alternate function and
  204. * low power mode
  205. * MFP_CFG_X - default MFPR value with alternate function,
  206. * pin drive strength and low power mode
  207. */
  208. Examples of pin configurations are::
  209. #define GPIO94_SSP3_RXD MFP_CFG_X(GPIO94, AF1, DS08X, FLOAT)
  210. which reads GPIO94 can be configured as SSP3_RXD, with alternate function
  211. selection of 1, driving strength of 0b101, and a float state in low power
  212. modes.
  213. NOTE: this is the default setting of this pin being configured as SSP3_RXD
  214. which can be modified a bit in board code, though it is not recommended to
  215. do so, simply because this default setting is usually carefully encoded,
  216. and is supposed to work in most cases.
  217. Register Settings
  218. -----------------
  219. Register settings on PXA3xx for a pin configuration is actually very
  220. straight-forward, most bits can be converted directly into MFPR value
  221. in a easier way. Two sets of MFPR values are calculated: the run-time
  222. ones and the low power mode ones, to allow different settings.
  223. The conversion from a generic pin configuration to the actual register
  224. settings on PXA2xx is a bit complicated: many registers are involved,
  225. including GAFRx, GPDRx, PGSRx, PWER, PKWR, PFER and PRER. Please see
  226. mfp-pxa2xx.c for how the conversion is made.