diff options
author | Kukjin Kim <kgene.kim@samsung.com> | 2010-01-19 01:30:54 -0500 |
---|---|---|
committer | Ben Dooks <ben-linux@fluff.org> | 2010-01-19 04:37:18 -0500 |
commit | 1f323cfda5feee4e9c1fc09ededaee849f906468 (patch) | |
tree | 89c288fd8a5fe2c0cad1c39c5b752f162ff69e46 /arch/arm/plat-s3c64xx/gpiolib.c | |
parent | 9717453c40ba9ffbd8c40968df45498059bfec0e (diff) |
ARM: SAMSUNG: Move GPIO common functions to plat-samsung
This patch moves GPIO common functions (from plat-s3c64xx) into plat-samsung.
and adds the config option to build the plat-samsung/gpiolib for Samsung SoCs.
Signed-off-by: Adityapratap Sharma <aditya.ps@samsung.com>
Signed-off-by: Atul Dahiya <atul.dahiya@samsung.com>
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
Diffstat (limited to 'arch/arm/plat-s3c64xx/gpiolib.c')
-rw-r--r-- | arch/arm/plat-s3c64xx/gpiolib.c | 162 |
1 files changed, 2 insertions, 160 deletions
diff --git a/arch/arm/plat-s3c64xx/gpiolib.c b/arch/arm/plat-s3c64xx/gpiolib.c index 778560457277..265e23b6de8e 100644 --- a/arch/arm/plat-s3c64xx/gpiolib.c +++ b/arch/arm/plat-s3c64xx/gpiolib.c | |||
@@ -49,150 +49,6 @@ | |||
49 | * [2] BANK has two control registers, GPxCON0 and GPxCON1 | 49 | * [2] BANK has two control registers, GPxCON0 and GPxCON1 |
50 | */ | 50 | */ |
51 | 51 | ||
52 | #define OFF_GPCON (0x00) | ||
53 | #define OFF_GPDAT (0x04) | ||
54 | |||
55 | #define con_4bit_shift(__off) ((__off) * 4) | ||
56 | |||
57 | #if 1 | ||
58 | #define gpio_dbg(x...) do { } while(0) | ||
59 | #else | ||
60 | #define gpio_dbg(x...) printk(KERN_DEBUG x) | ||
61 | #endif | ||
62 | |||
63 | /* The s3c64xx_gpiolib_4bit routines are to control the gpio banks where | ||
64 | * the gpio configuration register (GPxCON) has 4 bits per GPIO, as the | ||
65 | * following example: | ||
66 | * | ||
67 | * base + 0x00: Control register, 4 bits per gpio | ||
68 | * gpio n: 4 bits starting at (4*n) | ||
69 | * 0000 = input, 0001 = output, others mean special-function | ||
70 | * base + 0x04: Data register, 1 bit per gpio | ||
71 | * bit n: data bit n | ||
72 | * | ||
73 | * Note, since the data register is one bit per gpio and is at base + 0x4 | ||
74 | * we can use s3c_gpiolib_get and s3c_gpiolib_set to change the state of | ||
75 | * the output. | ||
76 | */ | ||
77 | |||
78 | static int s3c64xx_gpiolib_4bit_input(struct gpio_chip *chip, unsigned offset) | ||
79 | { | ||
80 | struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip); | ||
81 | void __iomem *base = ourchip->base; | ||
82 | unsigned long con; | ||
83 | |||
84 | con = __raw_readl(base + OFF_GPCON); | ||
85 | con &= ~(0xf << con_4bit_shift(offset)); | ||
86 | __raw_writel(con, base + OFF_GPCON); | ||
87 | |||
88 | gpio_dbg("%s: %p: CON now %08lx\n", __func__, base, con); | ||
89 | |||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | static int s3c64xx_gpiolib_4bit_output(struct gpio_chip *chip, | ||
94 | unsigned offset, int value) | ||
95 | { | ||
96 | struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip); | ||
97 | void __iomem *base = ourchip->base; | ||
98 | unsigned long con; | ||
99 | unsigned long dat; | ||
100 | |||
101 | con = __raw_readl(base + OFF_GPCON); | ||
102 | con &= ~(0xf << con_4bit_shift(offset)); | ||
103 | con |= 0x1 << con_4bit_shift(offset); | ||
104 | |||
105 | dat = __raw_readl(base + OFF_GPDAT); | ||
106 | if (value) | ||
107 | dat |= 1 << offset; | ||
108 | else | ||
109 | dat &= ~(1 << offset); | ||
110 | |||
111 | __raw_writel(dat, base + OFF_GPDAT); | ||
112 | __raw_writel(con, base + OFF_GPCON); | ||
113 | __raw_writel(dat, base + OFF_GPDAT); | ||
114 | |||
115 | gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat); | ||
116 | |||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | /* The next set of routines are for the case where the GPIO configuration | ||
121 | * registers are 4 bits per GPIO but there is more than one register (the | ||
122 | * bank has more than 8 GPIOs. | ||
123 | * | ||
124 | * This case is the similar to the 4 bit case, but the registers are as | ||
125 | * follows: | ||
126 | * | ||
127 | * base + 0x00: Control register, 4 bits per gpio (lower 8 GPIOs) | ||
128 | * gpio n: 4 bits starting at (4*n) | ||
129 | * 0000 = input, 0001 = output, others mean special-function | ||
130 | * base + 0x04: Control register, 4 bits per gpio (up to 8 additions GPIOs) | ||
131 | * gpio n: 4 bits starting at (4*n) | ||
132 | * 0000 = input, 0001 = output, others mean special-function | ||
133 | * base + 0x08: Data register, 1 bit per gpio | ||
134 | * bit n: data bit n | ||
135 | * | ||
136 | * To allow us to use the s3c_gpiolib_get and s3c_gpiolib_set routines we | ||
137 | * store the 'base + 0x4' address so that these routines see the data | ||
138 | * register at ourchip->base + 0x04. | ||
139 | */ | ||
140 | |||
141 | static int s3c64xx_gpiolib_4bit2_input(struct gpio_chip *chip, unsigned offset) | ||
142 | { | ||
143 | struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip); | ||
144 | void __iomem *base = ourchip->base; | ||
145 | void __iomem *regcon = base; | ||
146 | unsigned long con; | ||
147 | |||
148 | if (offset > 7) | ||
149 | offset -= 8; | ||
150 | else | ||
151 | regcon -= 4; | ||
152 | |||
153 | con = __raw_readl(regcon); | ||
154 | con &= ~(0xf << con_4bit_shift(offset)); | ||
155 | __raw_writel(con, regcon); | ||
156 | |||
157 | gpio_dbg("%s: %p: CON %08lx\n", __func__, base, con); | ||
158 | |||
159 | return 0; | ||
160 | |||
161 | } | ||
162 | |||
163 | static int s3c64xx_gpiolib_4bit2_output(struct gpio_chip *chip, | ||
164 | unsigned offset, int value) | ||
165 | { | ||
166 | struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip); | ||
167 | void __iomem *base = ourchip->base; | ||
168 | void __iomem *regcon = base; | ||
169 | unsigned long con; | ||
170 | unsigned long dat; | ||
171 | |||
172 | if (offset > 7) | ||
173 | offset -= 8; | ||
174 | else | ||
175 | regcon -= 4; | ||
176 | |||
177 | con = __raw_readl(regcon); | ||
178 | con &= ~(0xf << con_4bit_shift(offset)); | ||
179 | con |= 0x1 << con_4bit_shift(offset); | ||
180 | |||
181 | dat = __raw_readl(base + OFF_GPDAT); | ||
182 | if (value) | ||
183 | dat |= 1 << offset; | ||
184 | else | ||
185 | dat &= ~(1 << offset); | ||
186 | |||
187 | __raw_writel(dat, base + OFF_GPDAT); | ||
188 | __raw_writel(con, regcon); | ||
189 | __raw_writel(dat, base + OFF_GPDAT); | ||
190 | |||
191 | gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat); | ||
192 | |||
193 | return 0; | ||
194 | } | ||
195 | |||
196 | static struct s3c_gpio_cfg gpio_4bit_cfg_noint = { | 52 | static struct s3c_gpio_cfg gpio_4bit_cfg_noint = { |
197 | .set_config = s3c_gpio_setcfg_s3c64xx_4bit, | 53 | .set_config = s3c_gpio_setcfg_s3c64xx_4bit, |
198 | .set_pull = s3c_gpio_setpull_updown, | 54 | .set_pull = s3c_gpio_setpull_updown, |
@@ -399,20 +255,6 @@ static struct s3c_gpio_chip gpio_2bit[] = { | |||
399 | }, | 255 | }, |
400 | }; | 256 | }; |
401 | 257 | ||
402 | static __init void s3c64xx_gpiolib_add_4bit(struct s3c_gpio_chip *chip) | ||
403 | { | ||
404 | chip->chip.direction_input = s3c64xx_gpiolib_4bit_input; | ||
405 | chip->chip.direction_output = s3c64xx_gpiolib_4bit_output; | ||
406 | chip->pm = __gpio_pm(&s3c_gpio_pm_4bit); | ||
407 | } | ||
408 | |||
409 | static __init void s3c64xx_gpiolib_add_4bit2(struct s3c_gpio_chip *chip) | ||
410 | { | ||
411 | chip->chip.direction_input = s3c64xx_gpiolib_4bit2_input; | ||
412 | chip->chip.direction_output = s3c64xx_gpiolib_4bit2_output; | ||
413 | chip->pm = __gpio_pm(&s3c_gpio_pm_4bit); | ||
414 | } | ||
415 | |||
416 | static __init void s3c64xx_gpiolib_add_2bit(struct s3c_gpio_chip *chip) | 258 | static __init void s3c64xx_gpiolib_add_2bit(struct s3c_gpio_chip *chip) |
417 | { | 259 | { |
418 | chip->pm = __gpio_pm(&s3c_gpio_pm_2bit); | 260 | chip->pm = __gpio_pm(&s3c_gpio_pm_2bit); |
@@ -432,10 +274,10 @@ static __init void s3c64xx_gpiolib_add(struct s3c_gpio_chip *chips, | |||
432 | static __init int s3c64xx_gpiolib_init(void) | 274 | static __init int s3c64xx_gpiolib_init(void) |
433 | { | 275 | { |
434 | s3c64xx_gpiolib_add(gpio_4bit, ARRAY_SIZE(gpio_4bit), | 276 | s3c64xx_gpiolib_add(gpio_4bit, ARRAY_SIZE(gpio_4bit), |
435 | s3c64xx_gpiolib_add_4bit); | 277 | samsung_gpiolib_add_4bit); |
436 | 278 | ||
437 | s3c64xx_gpiolib_add(gpio_4bit2, ARRAY_SIZE(gpio_4bit2), | 279 | s3c64xx_gpiolib_add(gpio_4bit2, ARRAY_SIZE(gpio_4bit2), |
438 | s3c64xx_gpiolib_add_4bit2); | 280 | samsung_gpiolib_add_4bit2); |
439 | 281 | ||
440 | s3c64xx_gpiolib_add(gpio_2bit, ARRAY_SIZE(gpio_2bit), | 282 | s3c64xx_gpiolib_add(gpio_2bit, ARRAY_SIZE(gpio_2bit), |
441 | s3c64xx_gpiolib_add_2bit); | 283 | s3c64xx_gpiolib_add_2bit); |