Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 2 | /* |
| 3 | * arch/arm/mach-imx/generic.c |
| 4 | * |
| 5 | * author: Sascha Hauer |
| 6 | * Created: april 20th, 2004 |
| 7 | * Copyright: Synertronixx GmbH |
| 8 | * |
| 9 | * Common code for i.MX machines |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
| 13 | |
| 14 | #ifdef CONFIG_IMX |
| 15 | |
| 16 | #include <asm/arch/imx-regs.h> |
| 17 | |
| 18 | void imx_gpio_mode(int gpio_mode) |
| 19 | { |
| 20 | unsigned int pin = gpio_mode & GPIO_PIN_MASK; |
| 21 | unsigned int port = (gpio_mode & GPIO_PORT_MASK) >> 5; |
| 22 | unsigned int ocr = (gpio_mode & GPIO_OCR_MASK) >> 10; |
| 23 | unsigned int tmp; |
| 24 | |
| 25 | /* Pullup enable */ |
| 26 | if(gpio_mode & GPIO_PUEN) |
| 27 | PUEN(port) |= (1<<pin); |
| 28 | else |
| 29 | PUEN(port) &= ~(1<<pin); |
| 30 | |
| 31 | /* Data direction */ |
| 32 | if(gpio_mode & GPIO_OUT) |
| 33 | DDIR(port) |= 1<<pin; |
| 34 | else |
| 35 | DDIR(port) &= ~(1<<pin); |
| 36 | |
| 37 | /* Primary / alternate function */ |
| 38 | if(gpio_mode & GPIO_AF) |
| 39 | GPR(port) |= (1<<pin); |
| 40 | else |
| 41 | GPR(port) &= ~(1<<pin); |
| 42 | |
| 43 | /* use as gpio? */ |
| 44 | if( ocr == 3 ) |
| 45 | GIUS(port) |= (1<<pin); |
| 46 | else |
| 47 | GIUS(port) &= ~(1<<pin); |
| 48 | |
| 49 | /* Output / input configuration */ |
| 50 | /* FIXME: I'm not very sure about OCR and ICONF, someone |
| 51 | * should have a look over it |
| 52 | */ |
| 53 | if(pin<16) { |
| 54 | tmp = OCR1(port); |
| 55 | tmp &= ~( 3<<(pin*2)); |
| 56 | tmp |= (ocr << (pin*2)); |
| 57 | OCR1(port) = tmp; |
| 58 | |
| 59 | if( gpio_mode & GPIO_AOUT ) |
| 60 | ICONFA1(port) &= ~( 3<<(pin*2)); |
| 61 | if( gpio_mode & GPIO_BOUT ) |
| 62 | ICONFB1(port) &= ~( 3<<(pin*2)); |
| 63 | } else { |
| 64 | tmp = OCR2(port); |
| 65 | tmp &= ~( 3<<((pin-16)*2)); |
| 66 | tmp |= (ocr << ((pin-16)*2)); |
| 67 | OCR2(port) = tmp; |
| 68 | |
| 69 | if( gpio_mode & GPIO_AOUT ) |
| 70 | ICONFA2(port) &= ~( 3<<((pin-16)*2)); |
| 71 | if( gpio_mode & GPIO_BOUT ) |
| 72 | ICONFB2(port) &= ~( 3<<((pin-16)*2)); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | #endif /* CONFIG_IMX */ |