2 * linux/arch/arm/mach-pxa/mfp-pxa2xx.c
4 * PXA2xx pin mux configuration support
6 * The GPIOs on PXA2xx can be configured as one of many alternate
7 * functions, this is by concept samilar to the MFP configuration
8 * on PXA3xx, what's more important, the low power pin state and
9 * wakeup detection are also supported by the same framework.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/sysdev.h>
21 #include <asm/arch/hardware.h>
22 #include <asm/arch/pxa-regs.h>
23 #include <asm/arch/pxa2xx-regs.h>
24 #include <asm/arch/mfp-pxa2xx.h>
28 #define PGSR(x) __REG2(0x40F00020, ((x) & 0x60) >> 3)
30 #define PWER_WE35 (1 << 24)
34 unsigned can_wakeup : 1;
35 unsigned keypad_gpio : 1;
36 unsigned int mask; /* bit mask in PWER or PKWR */
40 static struct gpio_desc gpio_desc[MFP_PIN_GPIO127 + 1];
42 static int __mfp_config_gpio(unsigned gpio, unsigned long c)
44 unsigned long gafr, mask = GPIO_bit(gpio);
51 /* alternate function and direction */
52 gafr = GAFR(gpio) & ~(0x3 << ((gpio & 0xf) * 2));
53 GAFR(gpio) = gafr | (fn << ((gpio & 0xf) * 2));
61 switch (c & MFP_LPM_STATE_MASK) {
62 case MFP_LPM_DRIVE_HIGH:
65 case MFP_LPM_DRIVE_LOW:
71 pr_warning("%s: invalid low power state for GPIO%d\n",
76 /* give early warning if MFP_LPM_CAN_WAKEUP is set on the
77 * configurations of those pins not able to wakeup
79 if ((c & MFP_LPM_CAN_WAKEUP) && !gpio_desc[gpio].can_wakeup) {
80 pr_warning("%s: GPIO%d unable to wakeup\n",
85 if ((c & MFP_LPM_CAN_WAKEUP) && (c & MFP_DIR_OUT)) {
86 pr_warning("%s: output GPIO%d unable to wakeup\n",
94 void pxa2xx_mfp_config(unsigned long *mfp_cfgs, int num)
100 for (i = 0, c = mfp_cfgs; i < num; i++, c++) {
102 gpio = mfp_to_gpio(MFP_PIN(*c));
104 if (!gpio_desc[gpio].valid) {
105 pr_warning("%s: GPIO%d is invalid pin\n",
110 local_irq_save(flags);
112 gpio_desc[gpio].config = *c;
113 __mfp_config_gpio(gpio, *c);
115 local_irq_restore(flags);
119 int gpio_set_wake(unsigned int gpio, unsigned int on)
124 if (gpio > mfp_to_gpio(MFP_PIN_GPIO127))
127 d = &gpio_desc[gpio];
136 if (d->can_wakeup && (c & MFP_LPM_CAN_WAKEUP)) {
140 if (c & MFP_LPM_EDGE_RISE)
145 if (c & MFP_LPM_EDGE_FALL)
159 static int __init pxa25x_mfp_init(void)
163 if (cpu_is_pxa25x()) {
164 for (i = 0; i <= 84; i++)
165 gpio_desc[i].valid = 1;
167 for (i = 0; i <= 15; i++) {
168 gpio_desc[i].can_wakeup = 1;
169 gpio_desc[i].mask = GPIO_bit(i);
175 postcore_initcall(pxa25x_mfp_init);
176 #endif /* CONFIG_PXA25x */
179 static int pxa27x_pkwr_gpio[] = {
180 13, 16, 17, 34, 36, 37, 38, 39, 90, 91, 93, 94,
181 95, 96, 97, 98, 99, 100, 101, 102
184 int keypad_set_wake(unsigned int on)
186 unsigned int i, gpio, mask = 0;
193 for (i = 0; i < ARRAY_SIZE(pxa27x_pkwr_gpio); i++) {
195 gpio = pxa27x_pkwr_gpio[i];
197 if (gpio_desc[gpio].config & MFP_LPM_CAN_WAKEUP)
198 mask |= gpio_desc[gpio].mask;
205 static int __init pxa27x_mfp_init(void)
209 if (cpu_is_pxa27x()) {
210 for (i = 0; i <= 120; i++) {
211 /* skip GPIO2, 5, 6, 7, 8, they are not
212 * valid pins allow configuration
214 if (i == 2 || i == 5 || i == 6 ||
218 gpio_desc[i].valid = 1;
222 for (i = 0; i < ARRAY_SIZE(pxa27x_pkwr_gpio); i++) {
223 gpio = pxa27x_pkwr_gpio[i];
224 gpio_desc[gpio].can_wakeup = 1;
225 gpio_desc[gpio].keypad_gpio = 1;
226 gpio_desc[gpio].mask = 1 << i;
229 /* Overwrite GPIO13 as a PWER wakeup source */
230 for (i = 0; i <= 15; i++) {
231 /* skip GPIO2, 5, 6, 7, 8 */
232 if (GPIO_bit(i) & 0x1e4)
235 gpio_desc[i].can_wakeup = 1;
236 gpio_desc[i].mask = GPIO_bit(i);
239 gpio_desc[35].can_wakeup = 1;
240 gpio_desc[35].mask = PWER_WE35;
245 postcore_initcall(pxa27x_mfp_init);
246 #endif /* CONFIG_PXA27x */