diff options
author | mokopatches <mokopatches@openmoko.org> | 2008-11-19 17:03:14 +0000 |
---|---|---|
committer | warmcat <andy@warmcat.com> | 2008-11-19 17:03:14 +0000 |
commit | 66dc9f9d0164aee9df0a637f01e8d88bbf3d893f (patch) | |
tree | cab08beb2929c78ad3f95e1f3b4b6daaf2262b38 /drivers/mfd/glamo/glamo-gpio.c | |
parent | 3622d39f2cb0a85ef890cc02c5d11a0c0a00978f (diff) |
smedia-glamo.patch
[ FIXME:
include/asm-arm/arch-s3c2410/irqs.h shouldn't contain device-specific
changes. ]
This is a Linux kernel driver for the Smedia Glamo336x / Glamo337x
multi-function peripheral device.
Signed-off-by: Harald Welte <laforge@openmoko.org>
Diffstat (limited to 'drivers/mfd/glamo/glamo-gpio.c')
-rw-r--r-- | drivers/mfd/glamo/glamo-gpio.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/drivers/mfd/glamo/glamo-gpio.c b/drivers/mfd/glamo/glamo-gpio.c new file mode 100644 index 00000000000..45d0bf91268 --- /dev/null +++ b/drivers/mfd/glamo/glamo-gpio.c @@ -0,0 +1,62 @@ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/spinlock.h> +#include <linux/io.h> + +#include <linux/glamo-gpio.h> + +#include "glamo-core.h" +#include "glamo-regs.h" + +void glamo_gpio_setpin(struct glamo_core *glamo, unsigned int pin, + unsigned int value) +{ + unsigned int reg = REG_OF_GPIO(pin); + u_int16_t tmp; + + spin_lock(&glamo->lock); + tmp = readw(glamo->base + reg); + if (value) + tmp |= OUTPUT_BIT(pin); + else + tmp &= ~OUTPUT_BIT(pin); + writew(tmp, glamo->base + reg); + spin_unlock(&glamo->lock); +} +EXPORT_SYMBOL(glamo_gpio_setpin); + +int glamo_gpio_getpin(struct glamo_core *glamo, unsigned int pin) +{ + return readw(REG_OF_GPIO(pin)) & INPUT_BIT(pin) ? 1 : 0; +} +EXPORT_SYMBOL(glamo_gpio_getpin); + +void glamo_gpio_cfgpin(struct glamo_core *glamo, unsigned int pinfunc) +{ + unsigned int reg = REG_OF_GPIO(pinfunc); + u_int16_t tmp; + + spin_lock(&glamo->lock); + tmp = readw(glamo->base + reg); + + if ((pinfunc & 0x00f0) == GLAMO_GPIO_F_FUNC) { + /* pin is a function pin: clear gpio bit */ + tmp &= ~FUNC_BIT(pinfunc); + } else { + /* pin is gpio: set gpio bit */ + tmp |= FUNC_BIT(pinfunc); + + if (pinfunc & GLAMO_GPIO_F_IN) { + /* gpio input: set bit to disable output mode */ + tmp |= GPIO_OUT_BIT(pinfunc); + } else if (pinfunc & GLAMO_GPIO_F_OUT) { + /* gpio output: clear bit to enable output mode */ + tmp &= ~GPIO_OUT_BIT(pinfunc); + } + } + writew(tmp, glamo->base + reg); + spin_unlock(&glamo->lock); +} +EXPORT_SYMBOL(glamo_gpio_cfgpin); + |