2 * arch/arm/mach-mxc/generic.c
5 * Created: april 20th, 2004
6 * Copyright: Synertronixx GmbH
8 * Common code for i.MX machines
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/errno.h>
27 #include <linux/init.h>
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/string.h>
31 #include <linux/gpio.h>
33 #include <mach/hardware.h>
34 #include <asm/mach/map.h>
35 #include <mach/iomux.h>
37 void mxc_gpio_mode(int gpio_mode
)
39 unsigned int pin
= gpio_mode
& GPIO_PIN_MASK
;
40 unsigned int port
= (gpio_mode
& GPIO_PORT_MASK
) >> GPIO_PORT_SHIFT
;
41 unsigned int ocr
= (gpio_mode
& GPIO_OCR_MASK
) >> GPIO_OCR_SHIFT
;
45 tmp
= __raw_readl(VA_GPIO_BASE
+ MXC_PUEN(port
));
46 if (gpio_mode
& GPIO_PUEN
)
50 __raw_writel(tmp
, VA_GPIO_BASE
+ MXC_PUEN(port
));
53 tmp
= __raw_readl(VA_GPIO_BASE
+ MXC_DDIR(port
));
54 if (gpio_mode
& GPIO_OUT
)
58 __raw_writel(tmp
, VA_GPIO_BASE
+ MXC_DDIR(port
));
60 /* Primary / alternate function */
61 tmp
= __raw_readl(VA_GPIO_BASE
+ MXC_GPR(port
));
62 if (gpio_mode
& GPIO_AF
)
66 __raw_writel(tmp
, VA_GPIO_BASE
+ MXC_GPR(port
));
69 tmp
= __raw_readl(VA_GPIO_BASE
+ MXC_GIUS(port
));
70 if (gpio_mode
& (GPIO_PF
| GPIO_AF
))
74 __raw_writel(tmp
, VA_GPIO_BASE
+ MXC_GIUS(port
));
77 tmp
= __raw_readl(VA_GPIO_BASE
+ MXC_OCR1(port
));
78 tmp
&= ~(3 << (pin
* 2));
79 tmp
|= (ocr
<< (pin
* 2));
80 __raw_writel(tmp
, VA_GPIO_BASE
+ MXC_OCR1(port
));
82 tmp
= __raw_readl(VA_GPIO_BASE
+ MXC_ICONFA1(port
));
83 tmp
&= ~(3 << (pin
* 2));
84 tmp
|= ((gpio_mode
>> GPIO_AOUT_SHIFT
) & 3) << (pin
* 2);
85 __raw_writel(tmp
, VA_GPIO_BASE
+ MXC_ICONFA1(port
));
87 tmp
= __raw_readl(VA_GPIO_BASE
+ MXC_ICONFB1(port
));
88 tmp
&= ~(3 << (pin
* 2));
89 tmp
|= ((gpio_mode
>> GPIO_BOUT_SHIFT
) & 3) << (pin
* 2);
90 __raw_writel(tmp
, VA_GPIO_BASE
+ MXC_ICONFB1(port
));
94 tmp
= __raw_readl(VA_GPIO_BASE
+ MXC_OCR2(port
));
95 tmp
&= ~(3 << (pin
* 2));
96 tmp
|= (ocr
<< (pin
* 2));
97 __raw_writel(tmp
, VA_GPIO_BASE
+ MXC_OCR2(port
));
99 tmp
= __raw_readl(VA_GPIO_BASE
+ MXC_ICONFA2(port
));
100 tmp
&= ~(3 << (pin
* 2));
101 tmp
|= ((gpio_mode
>> GPIO_AOUT_SHIFT
) & 3) << (pin
* 2);
102 __raw_writel(tmp
, VA_GPIO_BASE
+ MXC_ICONFA2(port
));
104 tmp
= __raw_readl(VA_GPIO_BASE
+ MXC_ICONFB2(port
));
105 tmp
&= ~(3 << (pin
* 2));
106 tmp
|= ((gpio_mode
>> GPIO_BOUT_SHIFT
) & 3) << (pin
* 2);
107 __raw_writel(tmp
, VA_GPIO_BASE
+ MXC_ICONFB2(port
));
110 EXPORT_SYMBOL(mxc_gpio_mode
);
112 int mxc_gpio_setup_multiple_pins(const int *pin_list
, unsigned count
,
115 const int *p
= pin_list
;
121 for (i
= 0; i
< count
; i
++) {
122 gpio
= *p
& (GPIO_PIN_MASK
| GPIO_PORT_MASK
);
123 mode
= *p
& ~(GPIO_PIN_MASK
| GPIO_PORT_MASK
);
125 if (gpio
>= (GPIO_PORT_MAX
+ 1) * 32)
128 ret
= gpio_request(gpio
, label
);
132 mxc_gpio_mode(gpio
| mode
);
139 mxc_gpio_release_multiple_pins(pin_list
, i
);
142 EXPORT_SYMBOL(mxc_gpio_setup_multiple_pins
);
144 void mxc_gpio_release_multiple_pins(const int *pin_list
, int count
)
146 const int *p
= pin_list
;
149 for (i
= 0; i
< count
; i
++) {
150 unsigned gpio
= *p
& (GPIO_PIN_MASK
| GPIO_PORT_MASK
);
156 EXPORT_SYMBOL(mxc_gpio_release_multiple_pins
);