2 #include <linux/kernel.h>
3 #include <linux/module.h>
4 #include <linux/spinlock.h>
7 #include <linux/glamo-gpio.h>
9 #include "glamo-core.h"
10 #include "glamo-regs.h"
12 void glamo_gpio_setpin(struct glamo_core *glamo, unsigned int pin,
15 unsigned int reg = REG_OF_GPIO(pin);
18 spin_lock(&glamo->lock);
19 tmp = readw(glamo->base + reg);
21 tmp |= OUTPUT_BIT(pin);
23 tmp &= ~OUTPUT_BIT(pin);
24 writew(tmp, glamo->base + reg);
25 spin_unlock(&glamo->lock);
27 EXPORT_SYMBOL(glamo_gpio_setpin);
29 int glamo_gpio_getpin(struct glamo_core *glamo, unsigned int pin)
31 return readw(REG_OF_GPIO(pin)) & INPUT_BIT(pin) ? 1 : 0;
33 EXPORT_SYMBOL(glamo_gpio_getpin);
35 void glamo_gpio_cfgpin(struct glamo_core *glamo, unsigned int pinfunc)
37 unsigned int reg = REG_OF_GPIO(pinfunc);
40 spin_lock(&glamo->lock);
41 tmp = readw(glamo->base + reg);
43 if ((pinfunc & 0x00f0) == GLAMO_GPIO_F_FUNC) {
44 /* pin is a function pin: clear gpio bit */
45 tmp &= ~FUNC_BIT(pinfunc);
47 /* pin is gpio: set gpio bit */
48 tmp |= FUNC_BIT(pinfunc);
50 if (pinfunc & GLAMO_GPIO_F_IN) {
51 /* gpio input: set bit to disable output mode */
52 tmp |= GPIO_OUT_BIT(pinfunc);
53 } else if (pinfunc & GLAMO_GPIO_F_OUT) {
54 /* gpio output: clear bit to enable output mode */
55 tmp &= ~GPIO_OUT_BIT(pinfunc);
58 writew(tmp, glamo->base + reg);
59 spin_unlock(&glamo->lock);
61 EXPORT_SYMBOL(glamo_gpio_cfgpin);