Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 1 | /* |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 2 | * Copyright (C) 2007, OpenWrt.org, Florian Fainelli <florian@openwrt.org> |
| 3 | * Architecture specific GPIO support |
| 4 | * |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License as published by the |
| 7 | * Free Software Foundation; either version 2 of the License, or (at your |
| 8 | * option) any later version. |
| 9 | * |
| 10 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 11 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 12 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
| 13 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 14 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 15 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 16 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 17 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 18 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 19 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along |
| 22 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 24 | * |
| 25 | * Notes : |
| 26 | * au1000 SoC have only one GPIO line : GPIO1 |
| 27 | * others have a second one : GPIO2 |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 28 | */ |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 29 | |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 30 | #include <linux/module.h> |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 31 | |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 32 | #include <asm/mach-au1x00/au1000.h> |
| 33 | #include <asm/gpio.h> |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 34 | |
| 35 | #define gpio1 sys |
| 36 | #if !defined(CONFIG_SOC_AU1000) |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 37 | |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 38 | static struct au1x00_gpio2 *const gpio2 = (struct au1x00_gpio2 *) GPIO2_BASE; |
| 39 | #define GPIO2_OUTPUT_ENABLE_MASK 0x00010000 |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 40 | |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 41 | static int au1xxx_gpio2_read(unsigned gpio) |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 42 | { |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 43 | gpio -= AU1XXX_GPIO_BASE; |
| 44 | return ((gpio2->pinstate >> gpio) & 0x01); |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 47 | static void au1xxx_gpio2_write(unsigned gpio, int value) |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 48 | { |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 49 | gpio -= AU1XXX_GPIO_BASE; |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 50 | |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 51 | gpio2->output = (GPIO2_OUTPUT_ENABLE_MASK << gpio) | (value << gpio); |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 54 | static int au1xxx_gpio2_direction_input(unsigned gpio) |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 55 | { |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 56 | gpio -= AU1XXX_GPIO_BASE; |
| 57 | gpio2->dir &= ~(0x01 << gpio); |
| 58 | return 0; |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 61 | static int au1xxx_gpio2_direction_output(unsigned gpio, int value) |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 62 | { |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 63 | gpio -= AU1XXX_GPIO_BASE; |
| 64 | gpio2->dir = (0x01 << gpio) | (value << gpio); |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | #endif /* !defined(CONFIG_SOC_AU1000) */ |
| 69 | |
| 70 | static int au1xxx_gpio1_read(unsigned gpio) |
| 71 | { |
Sergei Shtylyov | c1dcb14 | 2008-04-30 23:18:41 +0400 | [diff] [blame^] | 72 | return (gpio1->pinstaterd >> gpio) & 0x01; |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static void au1xxx_gpio1_write(unsigned gpio, int value) |
| 76 | { |
| 77 | if (value) |
| 78 | gpio1->outputset = (0x01 << gpio); |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 79 | else |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 80 | /* Output a zero */ |
| 81 | gpio1->outputclr = (0x01 << gpio); |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 84 | static int au1xxx_gpio1_direction_input(unsigned gpio) |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 85 | { |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 86 | gpio1->pininputen = (0x01 << gpio); |
| 87 | return 0; |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 90 | static int au1xxx_gpio1_direction_output(unsigned gpio, int value) |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 91 | { |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 92 | gpio1->trioutclr = (0x01 & gpio); |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | int au1xxx_gpio_get_value(unsigned gpio) |
| 97 | { |
| 98 | if (gpio >= AU1XXX_GPIO_BASE) |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 99 | #if defined(CONFIG_SOC_AU1000) |
| 100 | return 0; |
| 101 | #else |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 102 | return au1xxx_gpio2_read(gpio); |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 103 | #endif |
| 104 | else |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 105 | return au1xxx_gpio1_read(gpio); |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 106 | } |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 107 | EXPORT_SYMBOL(au1xxx_gpio_get_value); |
| 108 | |
| 109 | void au1xxx_gpio_set_value(unsigned gpio, int value) |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 110 | { |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 111 | if (gpio >= AU1XXX_GPIO_BASE) |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 112 | #if defined(CONFIG_SOC_AU1000) |
| 113 | ; |
| 114 | #else |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 115 | au1xxx_gpio2_write(gpio, value); |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 116 | #endif |
| 117 | else |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 118 | au1xxx_gpio1_write(gpio, value); |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 119 | } |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 120 | EXPORT_SYMBOL(au1xxx_gpio_set_value); |
| 121 | |
| 122 | int au1xxx_gpio_direction_input(unsigned gpio) |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 123 | { |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 124 | if (gpio >= AU1XXX_GPIO_BASE) |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 125 | #if defined(CONFIG_SOC_AU1000) |
Yoichi Yuasa | 7acae22 | 2007-08-02 12:48:00 +0900 | [diff] [blame] | 126 | return -ENODEV; |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 127 | #else |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 128 | return au1xxx_gpio2_direction_input(gpio); |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 129 | #endif |
Yoichi Yuasa | 7acae22 | 2007-08-02 12:48:00 +0900 | [diff] [blame] | 130 | |
| 131 | return au1xxx_gpio1_direction_input(gpio); |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 132 | } |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 133 | EXPORT_SYMBOL(au1xxx_gpio_direction_input); |
| 134 | |
| 135 | int au1xxx_gpio_direction_output(unsigned gpio, int value) |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 136 | { |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 137 | if (gpio >= AU1XXX_GPIO_BASE) |
| 138 | #if defined(CONFIG_SOC_AU1000) |
Yoichi Yuasa | 7acae22 | 2007-08-02 12:48:00 +0900 | [diff] [blame] | 139 | return -ENODEV; |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 140 | #else |
| 141 | return au1xxx_gpio2_direction_output(gpio, value); |
| 142 | #endif |
Yoichi Yuasa | 7acae22 | 2007-08-02 12:48:00 +0900 | [diff] [blame] | 143 | |
| 144 | return au1xxx_gpio1_direction_output(gpio, value); |
Pete Popov | 2cce826 | 2005-09-18 11:18:10 +0000 | [diff] [blame] | 145 | } |
Florian Fainelli | 4ead168 | 2007-05-22 21:44:42 +0200 | [diff] [blame] | 146 | EXPORT_SYMBOL(au1xxx_gpio_direction_output); |