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 | void s3c2410_gpio_pullup(unsigned int pin, unsigned int to) |
| 37 | { |
| 38 | void __iomem *base = S3C24XX_GPIO_BASE(pin); |
| 39 | unsigned long offs = S3C2410_GPIO_OFFSET(pin); |
| 40 | unsigned long flags; |
| 41 | unsigned long up; |
| 42 | |
| 43 | if (pin < S3C2410_GPIO_BANKB) |
| 44 | return; |
| 45 | |
| 46 | local_irq_save(flags); |
| 47 | |
| 48 | up = __raw_readl(base + 0x08); |
| 49 | up &= ~(1L << offs); |
| 50 | up |= to << offs; |
| 51 | __raw_writel(up, base + 0x08); |
| 52 | |
| 53 | local_irq_restore(flags); |
| 54 | } |
| 55 | |
| 56 | EXPORT_SYMBOL(s3c2410_gpio_pullup); |
| 57 | |
Ben Dooks | bb6d9b5 | 2008-01-28 13:01:23 +0100 | [diff] [blame] | 58 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 59 | void s3c2410_gpio_setpin(unsigned int pin, unsigned int to) |
| 60 | { |
| 61 | void __iomem *base = S3C24XX_GPIO_BASE(pin); |
| 62 | unsigned long offs = S3C2410_GPIO_OFFSET(pin); |
| 63 | unsigned long flags; |
| 64 | unsigned long dat; |
| 65 | |
| 66 | local_irq_save(flags); |
| 67 | |
| 68 | dat = __raw_readl(base + 0x04); |
| 69 | dat &= ~(1 << offs); |
| 70 | dat |= to << offs; |
| 71 | __raw_writel(dat, base + 0x04); |
| 72 | |
| 73 | local_irq_restore(flags); |
| 74 | } |
| 75 | |
| 76 | EXPORT_SYMBOL(s3c2410_gpio_setpin); |
| 77 | |
| 78 | unsigned int s3c2410_gpio_getpin(unsigned int pin) |
| 79 | { |
| 80 | void __iomem *base = S3C24XX_GPIO_BASE(pin); |
| 81 | unsigned long offs = S3C2410_GPIO_OFFSET(pin); |
| 82 | |
| 83 | return __raw_readl(base + 0x04) & (1<< offs); |
| 84 | } |
| 85 | |
| 86 | EXPORT_SYMBOL(s3c2410_gpio_getpin); |
| 87 | |
| 88 | unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change) |
| 89 | { |
| 90 | unsigned long flags; |
| 91 | unsigned long misccr; |
| 92 | |
| 93 | local_irq_save(flags); |
| 94 | misccr = __raw_readl(S3C24XX_MISCCR); |
| 95 | misccr &= ~clear; |
| 96 | misccr ^= change; |
| 97 | __raw_writel(misccr, S3C24XX_MISCCR); |
| 98 | local_irq_restore(flags); |
| 99 | |
| 100 | return misccr; |
| 101 | } |
| 102 | |
| 103 | EXPORT_SYMBOL(s3c2410_modify_misccr); |