blob: 1441ab43996af4e9e9890526865bc55fae854963 [file] [log] [blame]
wdenk281e00a2004-08-01 22:48:16 +00001/*
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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
wdenk281e00a2004-08-01 22:48:16 +000011 */
12
13#include <common.h>
14
15#ifdef CONFIG_IMX
16
17#include <asm/arch/imx-regs.h>
18
19void imx_gpio_mode(int gpio_mode)
20{
21 unsigned int pin = gpio_mode & GPIO_PIN_MASK;
22 unsigned int port = (gpio_mode & GPIO_PORT_MASK) >> 5;
23 unsigned int ocr = (gpio_mode & GPIO_OCR_MASK) >> 10;
24 unsigned int tmp;
25
26 /* Pullup enable */
27 if(gpio_mode & GPIO_PUEN)
28 PUEN(port) |= (1<<pin);
29 else
30 PUEN(port) &= ~(1<<pin);
31
32 /* Data direction */
33 if(gpio_mode & GPIO_OUT)
34 DDIR(port) |= 1<<pin;
35 else
36 DDIR(port) &= ~(1<<pin);
37
38 /* Primary / alternate function */
39 if(gpio_mode & GPIO_AF)
40 GPR(port) |= (1<<pin);
41 else
42 GPR(port) &= ~(1<<pin);
43
44 /* use as gpio? */
45 if( ocr == 3 )
46 GIUS(port) |= (1<<pin);
47 else
48 GIUS(port) &= ~(1<<pin);
49
50 /* Output / input configuration */
51 /* FIXME: I'm not very sure about OCR and ICONF, someone
52 * should have a look over it
53 */
54 if(pin<16) {
55 tmp = OCR1(port);
56 tmp &= ~( 3<<(pin*2));
57 tmp |= (ocr << (pin*2));
58 OCR1(port) = tmp;
59
60 if( gpio_mode & GPIO_AOUT )
61 ICONFA1(port) &= ~( 3<<(pin*2));
62 if( gpio_mode & GPIO_BOUT )
63 ICONFB1(port) &= ~( 3<<(pin*2));
64 } else {
65 tmp = OCR2(port);
66 tmp &= ~( 3<<((pin-16)*2));
67 tmp |= (ocr << ((pin-16)*2));
68 OCR2(port) = tmp;
69
70 if( gpio_mode & GPIO_AOUT )
71 ICONFA2(port) &= ~( 3<<((pin-16)*2));
72 if( gpio_mode & GPIO_BOUT )
73 ICONFB2(port) &= ~( 3<<((pin-16)*2));
74 }
75}
76
77#endif /* CONFIG_IMX */