| 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 | */ | 
|  | 10 |  | 
|  | 11 | #include <linux/init.h> | 
|  | 12 | #include <linux/module.h> | 
|  | 13 |  | 
|  | 14 | #include <asm/gpio.h> | 
| Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 15 | #include <mach/hardware.h> | 
| Dmitry Baryshkov | 45528e3 | 2008-04-10 13:31:47 +0100 | [diff] [blame] | 16 | #include "generic.h" | 
|  | 17 |  | 
|  | 18 | static int sa1100_gpio_get(struct gpio_chip *chip, unsigned offset) | 
|  | 19 | { | 
|  | 20 | return GPLR & GPIO_GPIO(offset); | 
|  | 21 | } | 
|  | 22 |  | 
|  | 23 | static void sa1100_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | 
|  | 24 | { | 
|  | 25 | if (value) | 
|  | 26 | GPSR = GPIO_GPIO(offset); | 
|  | 27 | else | 
|  | 28 | GPCR = GPIO_GPIO(offset); | 
|  | 29 | } | 
|  | 30 |  | 
|  | 31 | static int sa1100_direction_input(struct gpio_chip *chip, unsigned offset) | 
|  | 32 | { | 
|  | 33 | unsigned long flags; | 
|  | 34 |  | 
|  | 35 | local_irq_save(flags); | 
|  | 36 | GPDR &= ~GPIO_GPIO(offset); | 
|  | 37 | local_irq_restore(flags); | 
|  | 38 | return 0; | 
|  | 39 | } | 
|  | 40 |  | 
|  | 41 | static int sa1100_direction_output(struct gpio_chip *chip, unsigned offset, int value) | 
|  | 42 | { | 
|  | 43 | unsigned long flags; | 
|  | 44 |  | 
|  | 45 | local_irq_save(flags); | 
|  | 46 | sa1100_gpio_set(chip, offset, value); | 
|  | 47 | GPDR |= GPIO_GPIO(offset); | 
|  | 48 | local_irq_restore(flags); | 
|  | 49 | return 0; | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | static struct gpio_chip sa1100_gpio_chip = { | 
|  | 53 | .label			= "gpio", | 
|  | 54 | .direction_input	= sa1100_direction_input, | 
|  | 55 | .direction_output	= sa1100_direction_output, | 
|  | 56 | .set			= sa1100_gpio_set, | 
|  | 57 | .get			= sa1100_gpio_get, | 
|  | 58 | .base			= 0, | 
|  | 59 | .ngpio			= GPIO_MAX + 1, | 
|  | 60 | }; | 
|  | 61 |  | 
|  | 62 | void __init sa1100_init_gpio(void) | 
|  | 63 | { | 
|  | 64 | gpiochip_add(&sa1100_gpio_chip); | 
|  | 65 | } |