| Dmitry Baryshkov | 45528e3 | 2008-04-10 13:31:47 +0100 | [diff] [blame] | 1 | /* | 
 | 2 |  * linux/arch/arm/mach-sa1100/gpio.c | 
 | 3 |  * | 
 | 4 |  * Generic SA-1100 GPIO handling | 
 | 5 |  * | 
 | 6 |  * This program is free software; you can redistribute it and/or modify | 
 | 7 |  * it under the terms of the GNU General Public License version 2 as | 
 | 8 |  * published by the Free Software Foundation. | 
 | 9 |  */ | 
| Russell King | 2f8163b | 2011-07-26 10:53:52 +0100 | [diff] [blame] | 10 | #include <linux/gpio.h> | 
| Dmitry Baryshkov | 45528e3 | 2008-04-10 13:31:47 +0100 | [diff] [blame] | 11 | #include <linux/init.h> | 
 | 12 | #include <linux/module.h> | 
 | 13 |  | 
| Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 14 | #include <mach/hardware.h> | 
| Rob Herring | f314f33 | 2012-02-24 00:06:51 +0100 | [diff] [blame] | 15 | #include <mach/irqs.h> | 
| Dmitry Baryshkov | 45528e3 | 2008-04-10 13:31:47 +0100 | [diff] [blame] | 16 |  | 
 | 17 | static int sa1100_gpio_get(struct gpio_chip *chip, unsigned offset) | 
 | 18 | { | 
 | 19 | 	return GPLR & GPIO_GPIO(offset); | 
 | 20 | } | 
 | 21 |  | 
 | 22 | static void sa1100_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | 
 | 23 | { | 
 | 24 | 	if (value) | 
 | 25 | 		GPSR = GPIO_GPIO(offset); | 
 | 26 | 	else | 
 | 27 | 		GPCR = GPIO_GPIO(offset); | 
 | 28 | } | 
 | 29 |  | 
 | 30 | static int sa1100_direction_input(struct gpio_chip *chip, unsigned offset) | 
 | 31 | { | 
 | 32 | 	unsigned long flags; | 
 | 33 |  | 
 | 34 | 	local_irq_save(flags); | 
 | 35 | 	GPDR &= ~GPIO_GPIO(offset); | 
 | 36 | 	local_irq_restore(flags); | 
 | 37 | 	return 0; | 
 | 38 | } | 
 | 39 |  | 
 | 40 | static int sa1100_direction_output(struct gpio_chip *chip, unsigned offset, int value) | 
 | 41 | { | 
 | 42 | 	unsigned long flags; | 
 | 43 |  | 
 | 44 | 	local_irq_save(flags); | 
 | 45 | 	sa1100_gpio_set(chip, offset, value); | 
 | 46 | 	GPDR |= GPIO_GPIO(offset); | 
 | 47 | 	local_irq_restore(flags); | 
 | 48 | 	return 0; | 
 | 49 | } | 
 | 50 |  | 
| Russell King | f408c98 | 2011-12-18 18:24:57 +0000 | [diff] [blame] | 51 | static int sa1100_to_irq(struct gpio_chip *chip, unsigned offset) | 
 | 52 | { | 
 | 53 | 	return offset < 11 ? (IRQ_GPIO0 + offset) : (IRQ_GPIO11 - 11 + offset); | 
 | 54 | } | 
 | 55 |  | 
| Dmitry Baryshkov | 45528e3 | 2008-04-10 13:31:47 +0100 | [diff] [blame] | 56 | static struct gpio_chip sa1100_gpio_chip = { | 
 | 57 | 	.label			= "gpio", | 
 | 58 | 	.direction_input	= sa1100_direction_input, | 
 | 59 | 	.direction_output	= sa1100_direction_output, | 
 | 60 | 	.set			= sa1100_gpio_set, | 
 | 61 | 	.get			= sa1100_gpio_get, | 
| Russell King | f408c98 | 2011-12-18 18:24:57 +0000 | [diff] [blame] | 62 | 	.to_irq			= sa1100_to_irq, | 
| Dmitry Baryshkov | 45528e3 | 2008-04-10 13:31:47 +0100 | [diff] [blame] | 63 | 	.base			= 0, | 
 | 64 | 	.ngpio			= GPIO_MAX + 1, | 
 | 65 | }; | 
 | 66 |  | 
 | 67 | void __init sa1100_init_gpio(void) | 
 | 68 | { | 
 | 69 | 	gpiochip_add(&sa1100_gpio_chip); | 
 | 70 | } |