2007-02-11 10:31:01 -07:00
|
|
|
/* linux/arch/arm/plat-s3c24xx/gpio.c
|
|
|
|
*
|
2010-05-05 20:21:05 -06:00
|
|
|
* Copyright (c) 2004-2010 Simtec Electronics
|
2007-02-11 10:31:01 -07:00
|
|
|
* Ben Dooks <ben@simtec.co.uk>
|
|
|
|
*
|
|
|
|
* S3C24XX GPIO support
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/ioport.h>
|
2010-05-05 20:21:05 -06:00
|
|
|
#include <linux/gpio.h>
|
2008-09-06 05:10:45 -06:00
|
|
|
#include <linux/io.h>
|
2007-02-11 10:31:01 -07:00
|
|
|
|
2008-08-05 09:14:15 -06:00
|
|
|
#include <mach/hardware.h>
|
2009-10-26 15:17:15 -06:00
|
|
|
#include <mach/gpio-fns.h>
|
2007-02-11 10:31:01 -07:00
|
|
|
#include <asm/irq.h>
|
|
|
|
|
2008-08-05 09:14:15 -06:00
|
|
|
#include <mach/regs-gpio.h>
|
2007-02-11 10:31:01 -07:00
|
|
|
|
2010-05-16 23:28:44 -06:00
|
|
|
#include <plat/gpio-core.h>
|
|
|
|
|
2010-05-05 20:21:05 -06:00
|
|
|
/* gpiolib wrappers until these are totally eliminated */
|
|
|
|
|
2007-02-11 10:31:01 -07:00
|
|
|
void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
|
|
|
|
{
|
2010-05-05 20:21:05 -06:00
|
|
|
int ret;
|
2007-02-11 10:31:01 -07:00
|
|
|
|
2010-05-05 20:21:05 -06:00
|
|
|
WARN_ON(to); /* should be none of these left */
|
2007-02-11 10:31:01 -07:00
|
|
|
|
2010-05-05 20:21:05 -06:00
|
|
|
if (!to) {
|
|
|
|
/* if pull is enabled, try first with up, and if that
|
|
|
|
* fails, try using down */
|
2007-02-11 10:31:01 -07:00
|
|
|
|
2010-05-05 20:21:05 -06:00
|
|
|
ret = s3c_gpio_setpull(pin, S3C_GPIO_PULL_UP);
|
|
|
|
if (ret)
|
|
|
|
s3c_gpio_setpull(pin, S3C_GPIO_PULL_DOWN);
|
|
|
|
} else {
|
|
|
|
s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
|
|
|
|
}
|
2007-02-11 10:31:01 -07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(s3c2410_gpio_pullup);
|
|
|
|
|
|
|
|
void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
|
|
|
|
{
|
2010-05-05 20:21:05 -06:00
|
|
|
/* do this via gpiolib until all users removed */
|
2007-02-11 10:31:01 -07:00
|
|
|
|
2010-05-05 20:21:05 -06:00
|
|
|
gpio_request(pin, "temporary");
|
|
|
|
gpio_set_value(pin, to);
|
|
|
|
gpio_free(pin);
|
2007-02-11 10:31:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(s3c2410_gpio_setpin);
|
|
|
|
|
|
|
|
unsigned int s3c2410_gpio_getpin(unsigned int pin)
|
|
|
|
{
|
2010-05-16 23:28:44 -06:00
|
|
|
struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
|
|
|
|
unsigned long offs = pin - chip->chip.base;
|
2007-02-11 10:31:01 -07:00
|
|
|
|
2010-05-16 23:28:44 -06:00
|
|
|
return __raw_readl(chip->base + 0x04) & (1<< offs);
|
2007-02-11 10:31:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(s3c2410_gpio_getpin);
|
|
|
|
|
|
|
|
unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long misccr;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
misccr = __raw_readl(S3C24XX_MISCCR);
|
|
|
|
misccr &= ~clear;
|
|
|
|
misccr ^= change;
|
|
|
|
__raw_writel(misccr, S3C24XX_MISCCR);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
return misccr;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(s3c2410_modify_misccr);
|