Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 1 | /* linux/arch/arm/plat-s3c24xx/gpio.c |
| 2 | * |
Ben Dooks | 31da46d | 2010-05-06 11:21:05 +0900 | [diff] [blame] | 3 | * Copyright (c) 2004-2010 Simtec Electronics |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 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 Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 23 | #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 Dooks | 31da46d | 2010-05-06 11:21:05 +0900 | [diff] [blame] | 28 | #include <linux/gpio.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 29 | #include <linux/io.h> |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 30 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 31 | #include <mach/hardware.h> |
Ben Dooks | 365854a | 2009-10-26 21:17:15 +0000 | [diff] [blame] | 32 | #include <mach/gpio-fns.h> |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 33 | #include <asm/irq.h> |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 34 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 35 | #include <mach/regs-gpio.h> |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 36 | |
Ben Dooks | 7987bd7 | 2010-05-17 14:28:44 +0900 | [diff] [blame] | 37 | #include <plat/gpio-core.h> |
| 38 | |
Ben Dooks | 31da46d | 2010-05-06 11:21:05 +0900 | [diff] [blame] | 39 | /* gpiolib wrappers until these are totally eliminated */ |
| 40 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 41 | void s3c2410_gpio_pullup(unsigned int pin, unsigned int to) |
| 42 | { |
Ben Dooks | 31da46d | 2010-05-06 11:21:05 +0900 | [diff] [blame] | 43 | int ret; |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 44 | |
Ben Dooks | 31da46d | 2010-05-06 11:21:05 +0900 | [diff] [blame] | 45 | WARN_ON(to); /* should be none of these left */ |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 46 | |
Ben Dooks | 31da46d | 2010-05-06 11:21:05 +0900 | [diff] [blame] | 47 | if (!to) { |
| 48 | /* if pull is enabled, try first with up, and if that |
| 49 | * fails, try using down */ |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 50 | |
Ben Dooks | 31da46d | 2010-05-06 11:21:05 +0900 | [diff] [blame] | 51 | ret = s3c_gpio_setpull(pin, S3C_GPIO_PULL_UP); |
| 52 | if (ret) |
| 53 | s3c_gpio_setpull(pin, S3C_GPIO_PULL_DOWN); |
| 54 | } else { |
| 55 | s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE); |
| 56 | } |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 57 | } |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 58 | EXPORT_SYMBOL(s3c2410_gpio_pullup); |
| 59 | |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 60 | void s3c2410_gpio_setpin(unsigned int pin, unsigned int to) |
| 61 | { |
Ben Dooks | 31da46d | 2010-05-06 11:21:05 +0900 | [diff] [blame] | 62 | /* do this via gpiolib until all users removed */ |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 63 | |
Ben Dooks | 31da46d | 2010-05-06 11:21:05 +0900 | [diff] [blame] | 64 | gpio_request(pin, "temporary"); |
| 65 | gpio_set_value(pin, to); |
| 66 | gpio_free(pin); |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | EXPORT_SYMBOL(s3c2410_gpio_setpin); |
| 70 | |
| 71 | unsigned int s3c2410_gpio_getpin(unsigned int pin) |
| 72 | { |
Ben Dooks | 7987bd7 | 2010-05-17 14:28:44 +0900 | [diff] [blame] | 73 | struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin); |
| 74 | unsigned long offs = pin - chip->chip.base; |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 75 | |
Ben Dooks | 7987bd7 | 2010-05-17 14:28:44 +0900 | [diff] [blame] | 76 | return __raw_readl(chip->base + 0x04) & (1<< offs); |
Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | EXPORT_SYMBOL(s3c2410_gpio_getpin); |
| 80 | |
| 81 | unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change) |
| 82 | { |
| 83 | unsigned long flags; |
| 84 | unsigned long misccr; |
| 85 | |
| 86 | local_irq_save(flags); |
| 87 | misccr = __raw_readl(S3C24XX_MISCCR); |
| 88 | misccr &= ~clear; |
| 89 | misccr ^= change; |
| 90 | __raw_writel(misccr, S3C24XX_MISCCR); |
| 91 | local_irq_restore(flags); |
| 92 | |
| 93 | return misccr; |
| 94 | } |
| 95 | |
| 96 | EXPORT_SYMBOL(s3c2410_modify_misccr); |