wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | |
| 15 | #ifdef CONFIG_IMX |
| 16 | |
| 17 | #include <asm/arch/imx-regs.h> |
| 18 | |
| 19 | void 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 */ |