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