1 /* linux/arch/arm/plat-s3c/gpio-config.c
3 * Copyright 2008 Openmoko, Inc.
4 * Copyright 2008 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk>
6 * http://armlinux.simtec.co.uk/
8 * S3C series GPIO configuration core
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/kernel.h>
16 #include <linux/gpio.h>
19 #include <mach/gpio-core.h>
20 #include <plat/gpio-cfg.h>
21 #include <plat/gpio-cfg-helpers.h>
23 int s3c_gpio_cfgpin(unsigned int pin
, unsigned int config
)
25 struct s3c_gpio_chip
*chip
= s3c_gpiolib_getchip(pin
);
33 offset
= pin
- chip
->chip
.base
;
35 local_irq_save(flags
);
36 ret
= s3c_gpio_do_setcfg(chip
, offset
, config
);
37 local_irq_restore(flags
);
42 int s3c_gpio_setpull(unsigned int pin
, s3c_gpio_pull_t pull
)
44 struct s3c_gpio_chip
*chip
= s3c_gpiolib_getchip(pin
);
51 offset
= pin
- chip
->chip
.base
;
53 local_irq_save(flags
);
54 ret
= s3c_gpio_do_setpull(chip
, offset
, pull
);
55 local_irq_restore(flags
);
60 #ifdef CONFIG_S3C_GPIO_CFG_S3C24XX
61 int s3c_gpio_setcfg_s3c24xx_banka(struct s3c_gpio_chip
*chip
,
62 unsigned int off
, unsigned int cfg
)
64 void __iomem
*reg
= chip
->base
;
65 unsigned int shift
= off
;
68 if (s3c_gpio_is_cfg_special(cfg
)) {
71 /* Map output to 0, and SFN2 to 1 */
79 con
= __raw_readl(reg
);
80 con
&= ~(0x1 << shift
);
82 __raw_writel(con
, reg
);
87 int s3c_gpio_setcfg_s3c24xx(struct s3c_gpio_chip
*chip
,
88 unsigned int off
, unsigned int cfg
)
90 void __iomem
*reg
= chip
->base
;
91 unsigned int shift
= off
* 2;
94 if (s3c_gpio_is_cfg_special(cfg
)) {
102 con
= __raw_readl(reg
);
103 con
&= ~(0x3 << shift
);
105 __raw_writel(con
, reg
);
111 #ifdef CONFIG_S3C_GPIO_CFG_S3C64XX
112 int s3c_gpio_setcfg_s3c64xx_4bit(struct s3c_gpio_chip
*chip
,
113 unsigned int off
, unsigned int cfg
)
115 void __iomem
*reg
= chip
->base
;
116 unsigned int shift
= (off
& 7) * 4;
119 if (off
< 8 && chip
->chip
.ngpio
>= 8)
122 if (s3c_gpio_is_cfg_special(cfg
)) {
127 con
= __raw_readl(reg
);
128 con
&= ~(0xf << shift
);
130 __raw_writel(con
, reg
);
134 #endif /* CONFIG_S3C_GPIO_CFG_S3C64XX */
136 #ifdef CONFIG_S3C_GPIO_PULL_UPDOWN
137 int s3c_gpio_setpull_updown(struct s3c_gpio_chip
*chip
,
138 unsigned int off
, s3c_gpio_pull_t pull
)
140 void __iomem
*reg
= chip
->base
+ 0x08;
144 pup
= __raw_readl(reg
);
145 pup
&= ~(3 << shift
);
146 pup
|= pull
<< shift
;
147 __raw_writel(pup
, reg
);
152 s3c_gpio_pull_t
s3c_gpio_getpull_updown(struct s3c_gpio_chip
*chip
,
155 void __iomem
*reg
= chip
->base
+ 0x08;
157 u32 pup
= __raw_readl(reg
);
161 return (__force s3c_gpio_pull_t
)pup
;