Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 1 | /* linux/arch/arm/plat-s3c24xx/gpio.c |
| 2 | * |
| 3 | * Copyright (c) 2004-2005 Simtec Electronics |
| 4 | * Ben Dooks <ben@simtec.co.uk> |
| 5 | * |
| 6 | * S3C24XX 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 |
| 21 | */ |
| 22 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 23 | #include <linux/kernel.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/ioport.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 28 | #include <linux/io.h> |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 29 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 30 | #include <mach/hardware.h> |
Ben Dooks | 365854a | 2009-10-26 21:17:15 +0000 | [diff] [blame] | 31 | #include <mach/gpio-fns.h> |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 32 | #include <asm/irq.h> |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 33 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 34 | #include <mach/regs-gpio.h> |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 35 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 36 | unsigned int s3c2410_gpio_getcfg(unsigned int pin) |
| 37 | { |
| 38 | void __iomem *base = S3C24XX_GPIO_BASE(pin); |
| 39 | unsigned long val = __raw_readl(base); |
| 40 | |
| 41 | if (pin < S3C2410_GPIO_BANKB) { |
| 42 | val >>= S3C2410_GPIO_OFFSET(pin); |
| 43 | val &= 1; |
| 44 | val += 1; |
| 45 | } else { |
| 46 | val >>= S3C2410_GPIO_OFFSET(pin)*2; |
| 47 | val &= 3; |
| 48 | } |
| 49 | |
| 50 | return val | S3C2410_GPIO_INPUT; |
| 51 | } |
| 52 | |
| 53 | EXPORT_SYMBOL(s3c2410_gpio_getcfg); |
| 54 | |
| 55 | void s3c2410_gpio_pullup(unsigned int pin, unsigned int to) |
| 56 | { |
| 57 | void __iomem *base = S3C24XX_GPIO_BASE(pin); |
| 58 | unsigned long offs = S3C2410_GPIO_OFFSET(pin); |
| 59 | unsigned long flags; |
| 60 | unsigned long up; |
| 61 | |
| 62 | if (pin < S3C2410_GPIO_BANKB) |
| 63 | return; |
| 64 | |
| 65 | local_irq_save(flags); |
| 66 | |
| 67 | up = __raw_readl(base + 0x08); |
| 68 | up &= ~(1L << offs); |
| 69 | up |= to << offs; |
| 70 | __raw_writel(up, base + 0x08); |
| 71 | |
| 72 | local_irq_restore(flags); |
| 73 | } |
| 74 | |
| 75 | EXPORT_SYMBOL(s3c2410_gpio_pullup); |
| 76 | |
Ben Dooks | bb6d9b5 | 2008-01-28 13:01:23 +0100 | [diff] [blame] | 77 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 78 | void s3c2410_gpio_setpin(unsigned int pin, unsigned int to) |
| 79 | { |
| 80 | void __iomem *base = S3C24XX_GPIO_BASE(pin); |
| 81 | unsigned long offs = S3C2410_GPIO_OFFSET(pin); |
| 82 | unsigned long flags; |
| 83 | unsigned long dat; |
| 84 | |
| 85 | local_irq_save(flags); |
| 86 | |
| 87 | dat = __raw_readl(base + 0x04); |
| 88 | dat &= ~(1 << offs); |
| 89 | dat |= to << offs; |
| 90 | __raw_writel(dat, base + 0x04); |
| 91 | |
| 92 | local_irq_restore(flags); |
| 93 | } |
| 94 | |
| 95 | EXPORT_SYMBOL(s3c2410_gpio_setpin); |
| 96 | |
| 97 | unsigned int s3c2410_gpio_getpin(unsigned int pin) |
| 98 | { |
| 99 | void __iomem *base = S3C24XX_GPIO_BASE(pin); |
| 100 | unsigned long offs = S3C2410_GPIO_OFFSET(pin); |
| 101 | |
| 102 | return __raw_readl(base + 0x04) & (1<< offs); |
| 103 | } |
| 104 | |
| 105 | EXPORT_SYMBOL(s3c2410_gpio_getpin); |
| 106 | |
| 107 | unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change) |
| 108 | { |
| 109 | unsigned long flags; |
| 110 | unsigned long misccr; |
| 111 | |
| 112 | local_irq_save(flags); |
| 113 | misccr = __raw_readl(S3C24XX_MISCCR); |
| 114 | misccr &= ~clear; |
| 115 | misccr ^= change; |
| 116 | __raw_writel(misccr, S3C24XX_MISCCR); |
| 117 | local_irq_restore(flags); |
| 118 | |
| 119 | return misccr; |
| 120 | } |
| 121 | |
| 122 | EXPORT_SYMBOL(s3c2410_modify_misccr); |