[s3c24xx] bump to 2.6.30-rc6
[openwrt.git] / target / linux / s3c24xx / files-2.6.30 / drivers / mfd / glamo / glamo-gpio.c
1
2 #include <linux/kernel.h>
3 #include <linux/module.h>
4 #include <linux/spinlock.h>
5 #include <linux/io.h>
6
7 #include <linux/glamo-gpio.h>
8
9 #include "glamo-core.h"
10 #include "glamo-regs.h"
11
12 void glamo_gpio_setpin(struct glamo_core *glamo, unsigned int pin,
13                        unsigned int value)
14 {
15         unsigned int reg = REG_OF_GPIO(pin);
16         u_int16_t tmp;
17
18         spin_lock(&glamo->lock);
19         tmp = readw(glamo->base + reg);
20         if (value)
21                 tmp |= OUTPUT_BIT(pin);
22         else
23                 tmp &= ~OUTPUT_BIT(pin);
24         writew(tmp, glamo->base + reg);
25         spin_unlock(&glamo->lock);
26 }
27 EXPORT_SYMBOL(glamo_gpio_setpin);
28
29 int glamo_gpio_getpin(struct glamo_core *glamo, unsigned int pin)
30 {
31         return readw(REG_OF_GPIO(pin)) & INPUT_BIT(pin) ? 1 : 0;
32 }
33 EXPORT_SYMBOL(glamo_gpio_getpin);
34
35 void glamo_gpio_cfgpin(struct glamo_core *glamo, unsigned int pinfunc)
36 {
37         unsigned int reg = REG_OF_GPIO(pinfunc);
38         u_int16_t tmp;
39
40         spin_lock(&glamo->lock);
41         tmp = readw(glamo->base + reg);
42
43         if ((pinfunc & 0x00f0) == GLAMO_GPIO_F_FUNC) {
44                 /* pin is a function pin: clear gpio bit */
45                 tmp &= ~FUNC_BIT(pinfunc);
46         } else {
47                 /* pin is gpio: set gpio bit */
48                 tmp |= FUNC_BIT(pinfunc);
49
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);
56                 }
57         }
58         writew(tmp, glamo->base + reg);
59         spin_unlock(&glamo->lock);
60 }
61 EXPORT_SYMBOL(glamo_gpio_cfgpin);
62