blob: 45126d3aafc6d83a0385a9e969c4fa4686b77839 [file] [log] [blame]
Ben Dooksa21765a2007-02-11 18:31:01 +01001/* linux/arch/arm/plat-s3c24xx/gpio.c
2 *
Ben Dooks31da46d2010-05-06 11:21:05 +09003 * Copyright (c) 2004-2010 Simtec Electronics
Ben Dooksa21765a2007-02-11 18:31:01 +01004 * 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>
Ben Dooks31da46d2010-05-06 11:21:05 +090028#include <linux/gpio.h>
Russell Kingfced80c2008-09-06 12:10:45 +010029#include <linux/io.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010030
Russell Kinga09e64f2008-08-05 16:14:15 +010031#include <mach/hardware.h>
Ben Dooks365854a2009-10-26 21:17:15 +000032#include <mach/gpio-fns.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010033#include <asm/irq.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010034
Russell Kinga09e64f2008-08-05 16:14:15 +010035#include <mach/regs-gpio.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010036
Ben Dooks31da46d2010-05-06 11:21:05 +090037/* gpiolib wrappers until these are totally eliminated */
38
Ben Dooksa21765a2007-02-11 18:31:01 +010039void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
40{
Ben Dooks31da46d2010-05-06 11:21:05 +090041 int ret;
Ben Dooksa21765a2007-02-11 18:31:01 +010042
Ben Dooks31da46d2010-05-06 11:21:05 +090043 WARN_ON(to); /* should be none of these left */
Ben Dooksa21765a2007-02-11 18:31:01 +010044
Ben Dooks31da46d2010-05-06 11:21:05 +090045 if (!to) {
46 /* if pull is enabled, try first with up, and if that
47 * fails, try using down */
Ben Dooksa21765a2007-02-11 18:31:01 +010048
Ben Dooks31da46d2010-05-06 11:21:05 +090049 ret = s3c_gpio_setpull(pin, S3C_GPIO_PULL_UP);
50 if (ret)
51 s3c_gpio_setpull(pin, S3C_GPIO_PULL_DOWN);
52 } else {
53 s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
54 }
Ben Dooksa21765a2007-02-11 18:31:01 +010055}
Ben Dooksa21765a2007-02-11 18:31:01 +010056EXPORT_SYMBOL(s3c2410_gpio_pullup);
57
Ben Dooksa21765a2007-02-11 18:31:01 +010058void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
59{
Ben Dooks31da46d2010-05-06 11:21:05 +090060 /* do this via gpiolib until all users removed */
Ben Dooksa21765a2007-02-11 18:31:01 +010061
Ben Dooks31da46d2010-05-06 11:21:05 +090062 gpio_request(pin, "temporary");
63 gpio_set_value(pin, to);
64 gpio_free(pin);
Ben Dooksa21765a2007-02-11 18:31:01 +010065}
66
67EXPORT_SYMBOL(s3c2410_gpio_setpin);
68
69unsigned int s3c2410_gpio_getpin(unsigned int pin)
70{
71 void __iomem *base = S3C24XX_GPIO_BASE(pin);
72 unsigned long offs = S3C2410_GPIO_OFFSET(pin);
73
74 return __raw_readl(base + 0x04) & (1<< offs);
75}
76
77EXPORT_SYMBOL(s3c2410_gpio_getpin);
78
79unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
80{
81 unsigned long flags;
82 unsigned long misccr;
83
84 local_irq_save(flags);
85 misccr = __raw_readl(S3C24XX_MISCCR);
86 misccr &= ~clear;
87 misccr ^= change;
88 __raw_writel(misccr, S3C24XX_MISCCR);
89 local_irq_restore(flags);
90
91 return misccr;
92}
93
94EXPORT_SYMBOL(s3c2410_modify_misccr);