blob: 4526f6ba31a8741924e7e75ec5b63a2b8ce4c440 [file] [log] [blame]
Ben Dooks67d729a2008-01-28 13:01:19 +01001/* linux/arch/arm/mach-s3c2412/gpio.c
2 *
3 * Copyright (c) 2007 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * http://armlinux.simtec.co.uk/.
7 *
8 * S3C2412/S3C2413 specific GPIO support
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13*/
14
15#include <linux/kernel.h>
16#include <linux/types.h>
17#include <linux/module.h>
18#include <linux/interrupt.h>
Ben Dooks7987bd72010-05-17 14:28:44 +090019#include <linux/gpio.h>
Ben Dooks67d729a2008-01-28 13:01:19 +010020
21#include <asm/mach/arch.h>
22#include <asm/mach/map.h>
23
Russell Kinga09e64f2008-08-05 16:14:15 +010024#include <mach/regs-gpio.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010025#include <mach/hardware.h>
Ben Dooks67d729a2008-01-28 13:01:19 +010026
Ben Dooks7987bd72010-05-17 14:28:44 +090027#include <plat/gpio-core.h>
28
Ben Dooks67d729a2008-01-28 13:01:19 +010029int s3c2412_gpio_set_sleepcfg(unsigned int pin, unsigned int state)
30{
Kukjin Kim782d8a32011-08-30 20:47:32 +090031 struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
Ben Dooks7987bd72010-05-17 14:28:44 +090032 unsigned long offs = pin - chip->chip.base;
Ben Dooks67d729a2008-01-28 13:01:19 +010033 unsigned long flags;
34 unsigned long slpcon;
35
36 offs *= 2;
37
Ben Dooks2c8fcfb2010-05-17 14:13:16 +090038 if (pin < S3C2410_GPB(0))
Ben Dooks67d729a2008-01-28 13:01:19 +010039 return -EINVAL;
40
Ben Dooks2c8fcfb2010-05-17 14:13:16 +090041 if (pin >= S3C2410_GPF(0) &&
42 pin <= S3C2410_GPG(16))
Ben Dooks67d729a2008-01-28 13:01:19 +010043 return -EINVAL;
44
Ben Dooks2c8fcfb2010-05-17 14:13:16 +090045 if (pin > S3C2410_GPH(16))
Ben Dooks67d729a2008-01-28 13:01:19 +010046 return -EINVAL;
47
48 local_irq_save(flags);
49
Ben Dooks7987bd72010-05-17 14:28:44 +090050 slpcon = __raw_readl(chip->base + 0x0C);
Ben Dooks67d729a2008-01-28 13:01:19 +010051
52 slpcon &= ~(3 << offs);
53 slpcon |= state << offs;
54
Ben Dooks7987bd72010-05-17 14:28:44 +090055 __raw_writel(slpcon, chip->base + 0x0C);
Ben Dooks67d729a2008-01-28 13:01:19 +010056
57 local_irq_restore(flags);
58
59 return 0;
60}
61
62EXPORT_SYMBOL(s3c2412_gpio_set_sleepcfg);