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