blob: 36a3132f39e72367d7a372c0c11d642bc57b4e3f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* linux/arch/arm/mach-s3c2410/gpio.c
2 *
Ben Dooksa21765a2007-02-11 18:31:01 +01003 * Copyright (c) 2004-2006 Simtec Electronics
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Ben Dooks <ben@simtec.co.uk>
5 *
Ben Dooksa21765a2007-02-11 18:31:01 +01006 * S3C2410 GPIO support
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
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 Dooksa21765a2007-02-11 18:31:01 +010021 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
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 Kingfced80c2008-09-06 12:10:45 +010028#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Russell Kinga09e64f2008-08-05 16:14:15 +010030#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Russell Kinga09e64f2008-08-05 16:14:15 +010033#include <mach/regs-gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Ben Dooksa21765a2007-02-11 18:31:01 +010035int s3c2410_gpio_irqfilter(unsigned int pin, unsigned int on,
36 unsigned int config)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
Ben Dooksa21765a2007-02-11 18:31:01 +010038 void __iomem *reg = S3C24XX_EINFLT0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 unsigned long flags;
Ben Dooksa21765a2007-02-11 18:31:01 +010040 unsigned long val;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Ben Dooksa21765a2007-02-11 18:31:01 +010042 if (pin < S3C2410_GPG8 || pin > S3C2410_GPG15)
43 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Ben Dooksa21765a2007-02-11 18:31:01 +010045 config &= 0xff;
Ben Dooks42d3a122005-10-28 15:26:41 +010046
Ben Dooksa21765a2007-02-11 18:31:01 +010047 pin -= S3C2410_GPG8;
48 reg += pin & ~3;
Ben Dooks42d3a122005-10-28 15:26:41 +010049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 local_irq_save(flags);
51
Ben Dooksa21765a2007-02-11 18:31:01 +010052 /* update filter width and clock source */
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Ben Dooksa21765a2007-02-11 18:31:01 +010054 val = __raw_readl(reg);
55 val &= ~(0xff << ((pin & 3) * 8));
56 val |= config << ((pin & 3) * 8);
57 __raw_writel(val, reg);
58
59 /* update filter enable */
60
61 val = __raw_readl(S3C24XX_EXTINT2);
62 val &= ~(1 << ((pin * 4) + 3));
63 val |= on << ((pin * 4) + 3);
64 __raw_writel(val, S3C24XX_EXTINT2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 local_irq_restore(flags);
Ben Dooksa21765a2007-02-11 18:31:01 +010067
68 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
Ben Dooksa21765a2007-02-11 18:31:01 +010071EXPORT_SYMBOL(s3c2410_gpio_irqfilter);