mfp.txt 11 KB

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