blob: c7c0cd73b946834dc91bb747c886b2ac89ebbed8 [file] [log] [blame]
Ben Dooksa21765a2007-02-11 18:31:01 +01001/* 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 Dooksa21765a2007-02-11 18:31:01 +010023#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>
Ben Dooksa21765a2007-02-11 18:31:01 +010029
Russell Kinga09e64f2008-08-05 16:14:15 +010030#include <mach/hardware.h>
Ben Dooks365854a2009-10-26 21:17:15 +000031#include <mach/gpio-fns.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010032#include <asm/irq.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010033
Russell Kinga09e64f2008-08-05 16:14:15 +010034#include <mach/regs-gpio.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010035
Ben Dooksa21765a2007-02-11 18:31:01 +010036void 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
56EXPORT_SYMBOL(s3c2410_gpio_pullup);
57
Ben Dooksbb6d9b52008-01-28 13:01:23 +010058
Ben Dooksa21765a2007-02-11 18:31:01 +010059void 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
76EXPORT_SYMBOL(s3c2410_gpio_setpin);
77
78unsigned 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
86EXPORT_SYMBOL(s3c2410_gpio_getpin);
87
88unsigned 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
103EXPORT_SYMBOL(s3c2410_modify_misccr);