Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 |
| 3 | * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de> |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | #include <common.h> |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 24 | #ifdef CONFIG_MX31 |
Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 25 | #include <asm/arch/mx31-regs.h> |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 26 | #endif |
Liu Hui-R64343 | a71164c | 2011-01-03 22:27:38 +0000 | [diff] [blame] | 27 | #if defined(CONFIG_MX51) || defined(CONFIG_MX53) |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 28 | #include <asm/arch/imx-regs.h> |
| 29 | #endif |
| 30 | #include <asm/io.h> |
| 31 | #include <mxc_gpio.h> |
Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 32 | |
| 33 | /* GPIO port description */ |
| 34 | static unsigned long gpio_ports[] = { |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 35 | [0] = GPIO1_BASE_ADDR, |
| 36 | [1] = GPIO2_BASE_ADDR, |
| 37 | [2] = GPIO3_BASE_ADDR, |
Liu Hui-R64343 | a71164c | 2011-01-03 22:27:38 +0000 | [diff] [blame] | 38 | #if defined(CONFIG_MX51) || defined(CONFIG_MX53) |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 39 | [3] = GPIO4_BASE_ADDR, |
| 40 | #endif |
Liu Hui-R64343 | a71164c | 2011-01-03 22:27:38 +0000 | [diff] [blame] | 41 | #if defined(CONFIG_MX53) |
| 42 | [4] = GPIO5_BASE_ADDR, |
| 43 | [5] = GPIO6_BASE_ADDR, |
| 44 | [6] = GPIO7_BASE_ADDR, |
| 45 | #endif |
Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 46 | }; |
| 47 | |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 48 | int mxc_gpio_direction(unsigned int gpio, enum mxc_gpio_direction direction) |
Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 49 | { |
| 50 | unsigned int port = gpio >> 5; |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 51 | struct gpio_regs *regs; |
Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 52 | u32 l; |
| 53 | |
| 54 | if (port >= ARRAY_SIZE(gpio_ports)) |
| 55 | return 1; |
| 56 | |
| 57 | gpio &= 0x1f; |
| 58 | |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 59 | regs = (struct gpio_regs *)gpio_ports[port]; |
| 60 | |
| 61 | l = readl(®s->gpio_dir); |
| 62 | |
Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 63 | switch (direction) { |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 64 | case MXC_GPIO_DIRECTION_OUT: |
Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 65 | l |= 1 << gpio; |
| 66 | break; |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 67 | case MXC_GPIO_DIRECTION_IN: |
Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 68 | l &= ~(1 << gpio); |
| 69 | } |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 70 | writel(l, ®s->gpio_dir); |
Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 75 | void mxc_gpio_set(unsigned int gpio, unsigned int value) |
Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 76 | { |
| 77 | unsigned int port = gpio >> 5; |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 78 | struct gpio_regs *regs; |
Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 79 | u32 l; |
| 80 | |
| 81 | if (port >= ARRAY_SIZE(gpio_ports)) |
| 82 | return; |
| 83 | |
| 84 | gpio &= 0x1f; |
| 85 | |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 86 | regs = (struct gpio_regs *)gpio_ports[port]; |
| 87 | |
| 88 | l = readl(®s->gpio_dr); |
Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 89 | if (value) |
| 90 | l |= 1 << gpio; |
| 91 | else |
| 92 | l &= ~(1 << gpio); |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 93 | writel(l, ®s->gpio_dr); |
Guennadi Liakhovetski | 7c6a856 | 2009-02-07 01:18:07 +0100 | [diff] [blame] | 94 | } |
Stefano Babic | a44d2a5 | 2010-04-13 12:07:00 +0200 | [diff] [blame] | 95 | |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 96 | int mxc_gpio_get(unsigned int gpio) |
Stefano Babic | a44d2a5 | 2010-04-13 12:07:00 +0200 | [diff] [blame] | 97 | { |
| 98 | unsigned int port = gpio >> 5; |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 99 | struct gpio_regs *regs; |
Stefano Babic | a44d2a5 | 2010-04-13 12:07:00 +0200 | [diff] [blame] | 100 | u32 l; |
| 101 | |
| 102 | if (port >= ARRAY_SIZE(gpio_ports)) |
| 103 | return -1; |
| 104 | |
| 105 | gpio &= 0x1f; |
| 106 | |
Stefano Babic | d77fe99 | 2010-07-06 17:05:06 +0200 | [diff] [blame] | 107 | regs = (struct gpio_regs *)gpio_ports[port]; |
| 108 | |
| 109 | l = (readl(®s->gpio_dr) >> gpio) & 0x01; |
Stefano Babic | a44d2a5 | 2010-04-13 12:07:00 +0200 | [diff] [blame] | 110 | |
| 111 | return l; |
| 112 | } |