GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / arm / plat-samsung / gpio.c
blobb83a83351cea9dc456c6a7e5d660ecd273c057bb
1 /* linux/arch/arm/plat-s3c/gpio.c
3 * Copyright 2008 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 * http://armlinux.simtec.co.uk/
7 * S3C series GPIO core
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/io.h>
17 #include <linux/gpio.h>
18 #include <linux/spinlock.h>
20 #include <plat/gpio-core.h>
22 #ifdef CONFIG_S3C_GPIO_TRACK
23 struct s3c_gpio_chip *s3c_gpios[S3C_GPIO_END];
25 static __init void s3c_gpiolib_track(struct s3c_gpio_chip *chip)
27 unsigned int gpn;
28 int i;
30 gpn = chip->chip.base;
31 for (i = 0; i < chip->chip.ngpio; i++, gpn++) {
32 BUG_ON(gpn >= ARRAY_SIZE(s3c_gpios));
33 s3c_gpios[gpn] = chip;
36 #endif /* CONFIG_S3C_GPIO_TRACK */
38 /* Default routines for controlling GPIO, based on the original S3C24XX
39 * GPIO functions which deal with the case where each gpio bank of the
40 * chip is as following:
42 * base + 0x00: Control register, 2 bits per gpio
43 * gpio n: 2 bits starting at (2*n)
44 * 00 = input, 01 = output, others mean special-function
45 * base + 0x04: Data register, 1 bit per gpio
46 * bit n: data bit n
49 static int s3c_gpiolib_input(struct gpio_chip *chip, unsigned offset)
51 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
52 void __iomem *base = ourchip->base;
53 unsigned long flags;
54 unsigned long con;
56 s3c_gpio_lock(ourchip, flags);
58 con = __raw_readl(base + 0x00);
59 con &= ~(3 << (offset * 2));
61 __raw_writel(con, base + 0x00);
63 s3c_gpio_unlock(ourchip, flags);
64 return 0;
67 static int s3c_gpiolib_output(struct gpio_chip *chip,
68 unsigned offset, int value)
70 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
71 void __iomem *base = ourchip->base;
72 unsigned long flags;
73 unsigned long dat;
74 unsigned long con;
76 s3c_gpio_lock(ourchip, flags);
78 dat = __raw_readl(base + 0x04);
79 dat &= ~(1 << offset);
80 if (value)
81 dat |= 1 << offset;
82 __raw_writel(dat, base + 0x04);
84 con = __raw_readl(base + 0x00);
85 con &= ~(3 << (offset * 2));
86 con |= 1 << (offset * 2);
88 __raw_writel(con, base + 0x00);
89 __raw_writel(dat, base + 0x04);
91 s3c_gpio_unlock(ourchip, flags);
92 return 0;
95 static void s3c_gpiolib_set(struct gpio_chip *chip,
96 unsigned offset, int value)
98 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
99 void __iomem *base = ourchip->base;
100 unsigned long flags;
101 unsigned long dat;
103 s3c_gpio_lock(ourchip, flags);
105 dat = __raw_readl(base + 0x04);
106 dat &= ~(1 << offset);
107 if (value)
108 dat |= 1 << offset;
109 __raw_writel(dat, base + 0x04);
111 s3c_gpio_unlock(ourchip, flags);
114 static int s3c_gpiolib_get(struct gpio_chip *chip, unsigned offset)
116 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
117 unsigned long val;
119 val = __raw_readl(ourchip->base + 0x04);
120 val >>= offset;
121 val &= 1;
123 return val;
126 __init void s3c_gpiolib_add(struct s3c_gpio_chip *chip)
128 struct gpio_chip *gc = &chip->chip;
129 int ret;
131 BUG_ON(!chip->base);
132 BUG_ON(!gc->label);
133 BUG_ON(!gc->ngpio);
135 spin_lock_init(&chip->lock);
137 if (!gc->direction_input)
138 gc->direction_input = s3c_gpiolib_input;
139 if (!gc->direction_output)
140 gc->direction_output = s3c_gpiolib_output;
141 if (!gc->set)
142 gc->set = s3c_gpiolib_set;
143 if (!gc->get)
144 gc->get = s3c_gpiolib_get;
146 #ifdef CONFIG_PM
147 if (chip->pm != NULL) {
148 if (!chip->pm->save || !chip->pm->resume)
149 printk(KERN_ERR "gpio: %s has missing PM functions\n",
150 gc->label);
151 } else
152 printk(KERN_ERR "gpio: %s has no PM function\n", gc->label);
153 #endif
155 /* gpiochip_add() prints own failure message on error. */
156 ret = gpiochip_add(gc);
157 if (ret >= 0)
158 s3c_gpiolib_track(chip);