Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* linux/arch/arm/mach-s3c2410/gpio.c |
| 2 | * |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 3 | * Copyright (c) 2004-2006 Simtec Electronics |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Ben Dooks <ben@simtec.co.uk> |
| 5 | * |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 6 | * S3C2410 GPIO support |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 21 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 30 | #include <mach/hardware.h> |
Ben Dooks | 620abe2 | 2009-10-26 21:21:32 +0000 | [diff] [blame] | 31 | #include <mach/gpio-fns.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 34 | #include <mach/regs-gpio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 36 | int s3c2410_gpio_irqfilter(unsigned int pin, unsigned int on, |
| 37 | unsigned int config) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | { |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 39 | void __iomem *reg = S3C24XX_EINFLT0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | unsigned long flags; |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 41 | unsigned long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Ben Dooks | 070276d | 2009-05-17 22:32:23 +0100 | [diff] [blame] | 43 | if (pin < S3C2410_GPG(8) || pin > S3C2410_GPG(15)) |
Ben Dooks | 373e964 | 2009-05-18 19:40:18 +0100 | [diff] [blame] | 44 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 46 | config &= 0xff; |
Ben Dooks | 42d3a12 | 2005-10-28 15:26:41 +0100 | [diff] [blame] | 47 | |
Ben Dooks | 070276d | 2009-05-17 22:32:23 +0100 | [diff] [blame] | 48 | pin -= S3C2410_GPG(8); |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 49 | reg += pin & ~3; |
Ben Dooks | 42d3a12 | 2005-10-28 15:26:41 +0100 | [diff] [blame] | 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | local_irq_save(flags); |
| 52 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 53 | /* update filter width and clock source */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 55 | val = __raw_readl(reg); |
| 56 | val &= ~(0xff << ((pin & 3) * 8)); |
| 57 | val |= config << ((pin & 3) * 8); |
| 58 | __raw_writel(val, reg); |
| 59 | |
| 60 | /* update filter enable */ |
| 61 | |
| 62 | val = __raw_readl(S3C24XX_EXTINT2); |
| 63 | val &= ~(1 << ((pin * 4) + 3)); |
| 64 | val |= on << ((pin * 4) + 3); |
| 65 | __raw_writel(val, S3C24XX_EXTINT2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | local_irq_restore(flags); |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 68 | |
| 69 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 72 | EXPORT_SYMBOL(s3c2410_gpio_irqfilter); |