xref: /openbmc/u-boot/arch/arm/cpu/arm920t/imx/generic.c (revision 4e3349b6)
1 /*
2  *  arch/arm/mach-imx/generic.c
3  *
4  *  author: Sascha Hauer
5  *  Created: april 20th, 2004
6  *  Copyright: Synertronixx GmbH
7  *
8  *  Common code for i.MX machines
9  *
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.
14  *
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.
19  *
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
23  *
24  */
25 
26 #include <common.h>
27 
28 #ifdef CONFIG_IMX
29 
30 #include <asm/arch/imx-regs.h>
31 
32 void imx_gpio_mode(int gpio_mode)
33 {
34 	unsigned int pin = gpio_mode & GPIO_PIN_MASK;
35 	unsigned int port = (gpio_mode & GPIO_PORT_MASK) >> 5;
36 	unsigned int ocr = (gpio_mode & GPIO_OCR_MASK) >> 10;
37 	unsigned int tmp;
38 
39 	/* Pullup enable */
40 	if(gpio_mode & GPIO_PUEN)
41 		PUEN(port) |= (1<<pin);
42 	else
43 		PUEN(port) &= ~(1<<pin);
44 
45 	/* Data direction */
46 	if(gpio_mode & GPIO_OUT)
47 		DDIR(port) |= 1<<pin;
48 	else
49 		DDIR(port) &= ~(1<<pin);
50 
51 	/* Primary / alternate function */
52 	if(gpio_mode & GPIO_AF)
53 		GPR(port) |= (1<<pin);
54 	else
55 		GPR(port) &= ~(1<<pin);
56 
57 	/* use as gpio? */
58 	if( ocr == 3 )
59 		GIUS(port) |= (1<<pin);
60 	else
61 		GIUS(port) &= ~(1<<pin);
62 
63 	/* Output / input configuration */
64 	/* FIXME: I'm not very sure about OCR and ICONF, someone
65 	 * should have a look over it
66 	 */
67 	if(pin<16) {
68 		tmp = OCR1(port);
69 		tmp &= ~( 3<<(pin*2));
70 		tmp |= (ocr << (pin*2));
71 		OCR1(port) = tmp;
72 
73 		if( gpio_mode &	GPIO_AOUT )
74 			ICONFA1(port) &= ~( 3<<(pin*2));
75 		if( gpio_mode &	GPIO_BOUT )
76 			ICONFB1(port) &= ~( 3<<(pin*2));
77 	} else {
78 		tmp = OCR2(port);
79 		tmp &= ~( 3<<((pin-16)*2));
80 		tmp |= (ocr << ((pin-16)*2));
81 		OCR2(port) = tmp;
82 
83 		if( gpio_mode &	GPIO_AOUT )
84 			ICONFA2(port) &= ~( 3<<((pin-16)*2));
85 		if( gpio_mode &	GPIO_BOUT )
86 			ICONFB2(port) &= ~( 3<<((pin-16)*2));
87 	}
88 }
89 
90 #endif /* CONFIG_IMX */
91