Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* linux/arch/arm/mach-s3c2410/gpio.c |
| 2 | * |
| 3 | * Copyright (c) 2004-2005 Simtec Electronics |
| 4 | * Ben Dooks <ben@simtec.co.uk> |
| 5 | * |
| 6 | * S3C2410 GPIO support |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (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, MA 02111-1307 USA |
Ben Dooks | 7f61a84 | 2006-09-20 20:54:54 +0100 | [diff] [blame^] | 21 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/ioport.h> |
| 29 | |
| 30 | #include <asm/hardware.h> |
| 31 | #include <asm/irq.h> |
| 32 | #include <asm/io.h> |
| 33 | |
| 34 | #include <asm/arch/regs-gpio.h> |
| 35 | |
| 36 | void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function) |
| 37 | { |
Lucas Correia Villa Real | 0ca5bc3 | 2006-02-01 21:24:23 +0000 | [diff] [blame] | 38 | void __iomem *base = S3C24XX_GPIO_BASE(pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | unsigned long mask; |
| 40 | unsigned long con; |
| 41 | unsigned long flags; |
| 42 | |
| 43 | if (pin < S3C2410_GPIO_BANKB) { |
| 44 | mask = 1 << S3C2410_GPIO_OFFSET(pin); |
| 45 | } else { |
| 46 | mask = 3 << S3C2410_GPIO_OFFSET(pin)*2; |
| 47 | } |
| 48 | |
Ben Dooks | 42d3a12 | 2005-10-28 15:26:41 +0100 | [diff] [blame] | 49 | switch (function) { |
| 50 | case S3C2410_GPIO_LEAVE: |
| 51 | mask = 0; |
| 52 | function = 0; |
| 53 | break; |
| 54 | |
| 55 | case S3C2410_GPIO_INPUT: |
| 56 | case S3C2410_GPIO_OUTPUT: |
| 57 | case S3C2410_GPIO_SFN2: |
| 58 | case S3C2410_GPIO_SFN3: |
| 59 | if (pin < S3C2410_GPIO_BANKB) { |
| 60 | function &= 1; |
| 61 | function <<= S3C2410_GPIO_OFFSET(pin); |
| 62 | } else { |
| 63 | function &= 3; |
| 64 | function <<= S3C2410_GPIO_OFFSET(pin)*2; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /* modify the specified register wwith IRQs off */ |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | local_irq_save(flags); |
| 71 | |
| 72 | con = __raw_readl(base + 0x00); |
| 73 | con &= ~mask; |
| 74 | con |= function; |
| 75 | |
| 76 | __raw_writel(con, base + 0x00); |
| 77 | |
| 78 | local_irq_restore(flags); |
| 79 | } |
| 80 | |
| 81 | EXPORT_SYMBOL(s3c2410_gpio_cfgpin); |
| 82 | |
| 83 | unsigned int s3c2410_gpio_getcfg(unsigned int pin) |
| 84 | { |
Lucas Correia Villa Real | 0ca5bc3 | 2006-02-01 21:24:23 +0000 | [diff] [blame] | 85 | void __iomem *base = S3C24XX_GPIO_BASE(pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | unsigned long mask; |
| 87 | |
| 88 | if (pin < S3C2410_GPIO_BANKB) { |
| 89 | mask = 1 << S3C2410_GPIO_OFFSET(pin); |
| 90 | } else { |
| 91 | mask = 3 << S3C2410_GPIO_OFFSET(pin)*2; |
| 92 | } |
| 93 | |
| 94 | return __raw_readl(base) & mask; |
| 95 | } |
| 96 | |
| 97 | EXPORT_SYMBOL(s3c2410_gpio_getcfg); |
| 98 | |
| 99 | void s3c2410_gpio_pullup(unsigned int pin, unsigned int to) |
| 100 | { |
Lucas Correia Villa Real | 0ca5bc3 | 2006-02-01 21:24:23 +0000 | [diff] [blame] | 101 | void __iomem *base = S3C24XX_GPIO_BASE(pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | unsigned long offs = S3C2410_GPIO_OFFSET(pin); |
| 103 | unsigned long flags; |
| 104 | unsigned long up; |
| 105 | |
| 106 | if (pin < S3C2410_GPIO_BANKB) |
| 107 | return; |
| 108 | |
| 109 | local_irq_save(flags); |
| 110 | |
| 111 | up = __raw_readl(base + 0x08); |
| 112 | up &= ~(1L << offs); |
| 113 | up |= to << offs; |
| 114 | __raw_writel(up, base + 0x08); |
| 115 | |
| 116 | local_irq_restore(flags); |
| 117 | } |
| 118 | |
| 119 | EXPORT_SYMBOL(s3c2410_gpio_pullup); |
| 120 | |
| 121 | void s3c2410_gpio_setpin(unsigned int pin, unsigned int to) |
| 122 | { |
Lucas Correia Villa Real | 0ca5bc3 | 2006-02-01 21:24:23 +0000 | [diff] [blame] | 123 | void __iomem *base = S3C24XX_GPIO_BASE(pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | unsigned long offs = S3C2410_GPIO_OFFSET(pin); |
| 125 | unsigned long flags; |
| 126 | unsigned long dat; |
| 127 | |
| 128 | local_irq_save(flags); |
| 129 | |
| 130 | dat = __raw_readl(base + 0x04); |
| 131 | dat &= ~(1 << offs); |
| 132 | dat |= to << offs; |
| 133 | __raw_writel(dat, base + 0x04); |
| 134 | |
| 135 | local_irq_restore(flags); |
| 136 | } |
| 137 | |
| 138 | EXPORT_SYMBOL(s3c2410_gpio_setpin); |
| 139 | |
| 140 | unsigned int s3c2410_gpio_getpin(unsigned int pin) |
| 141 | { |
Lucas Correia Villa Real | 0ca5bc3 | 2006-02-01 21:24:23 +0000 | [diff] [blame] | 142 | void __iomem *base = S3C24XX_GPIO_BASE(pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | unsigned long offs = S3C2410_GPIO_OFFSET(pin); |
| 144 | |
| 145 | return __raw_readl(base + 0x04) & (1<< offs); |
| 146 | } |
| 147 | |
| 148 | EXPORT_SYMBOL(s3c2410_gpio_getpin); |
| 149 | |
| 150 | unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change) |
| 151 | { |
| 152 | unsigned long flags; |
| 153 | unsigned long misccr; |
| 154 | |
| 155 | local_irq_save(flags); |
Lucas Correia Villa Real | 0ca5bc3 | 2006-02-01 21:24:23 +0000 | [diff] [blame] | 156 | misccr = __raw_readl(S3C24XX_MISCCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | misccr &= ~clear; |
| 158 | misccr ^= change; |
Lucas Correia Villa Real | 0ca5bc3 | 2006-02-01 21:24:23 +0000 | [diff] [blame] | 159 | __raw_writel(misccr, S3C24XX_MISCCR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | local_irq_restore(flags); |
| 161 | |
| 162 | return misccr; |
| 163 | } |
| 164 | |
| 165 | EXPORT_SYMBOL(s3c2410_modify_misccr); |