gpio.c 1.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2
/* linux/arch/arm/mach-s3c2410/gpio.c
 *
3
 * Copyright (c) 2004-2006 Simtec Electronics
L
Linus Torvalds 已提交
4 5
 *	Ben Dooks <ben@simtec.co.uk>
 *
6
 * S3C2410 GPIO support
L
Linus Torvalds 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
 */
L
Linus Torvalds 已提交
22 23 24 25 26 27

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
28
#include <linux/io.h>
L
Linus Torvalds 已提交
29

30
#include <mach/hardware.h>
31
#include <mach/gpio-fns.h>
L
Linus Torvalds 已提交
32 33
#include <asm/irq.h>

34
#include <mach/regs-gpio.h>
L
Linus Torvalds 已提交
35

36 37
int s3c2410_gpio_irqfilter(unsigned int pin, unsigned int on,
			   unsigned int config)
L
Linus Torvalds 已提交
38
{
39
	void __iomem *reg = S3C24XX_EINFLT0;
L
Linus Torvalds 已提交
40
	unsigned long flags;
41
	unsigned long val;
L
Linus Torvalds 已提交
42

43
	if (pin < S3C2410_GPG(8) || pin > S3C2410_GPG(15))
44
		return -EINVAL;
L
Linus Torvalds 已提交
45

46
	config &= 0xff;
L
Linus Torvalds 已提交
47

48
	pin -= S3C2410_GPG(8);
49
	reg += pin & ~3;
L
Linus Torvalds 已提交
50 51 52

	local_irq_save(flags);

53
	/* update filter width and clock source */
L
Linus Torvalds 已提交
54

55 56 57 58
	val = __raw_readl(reg);
	val &= ~(0xff << ((pin & 3) * 8));
	val |= config << ((pin & 3) * 8);
	__raw_writel(val, reg);
L
Linus Torvalds 已提交
59

60
	/* update filter enable */
L
Linus Torvalds 已提交
61

62 63 64 65
	val = __raw_readl(S3C24XX_EXTINT2);
	val &= ~(1 << ((pin * 4) + 3));
	val |= on << ((pin * 4) + 3);
	__raw_writel(val, S3C24XX_EXTINT2);
L
Linus Torvalds 已提交
66 67 68

	local_irq_restore(flags);

69
	return 0;
70 71
}

72
EXPORT_SYMBOL(s3c2410_gpio_irqfilter);