1 /* linux/arch/arm/plat-s3c24xx/gpiolib.c
3 * Copyright (c) 2008 Simtec Electronics
4 * http://armlinux.simtec.co.uk/
5 * Ben Dooks <ben@simtec.co.uk>
7 * S3C24XX GPIOlib support
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License.
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/interrupt.h>
18 #include <linux/ioport.h>
20 #include <linux/gpio.h>
22 #include <mach/gpio-core.h>
23 #include <mach/hardware.h>
27 #include <mach/regs-gpio.h>
29 static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset)
34 static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip,
35 unsigned offset, int value)
37 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
38 void __iomem *base = ourchip->base;
43 local_irq_save(flags);
45 con = __raw_readl(base + 0x00);
46 dat = __raw_readl(base + 0x04);
48 dat &= ~(1 << offset);
52 __raw_writel(dat, base + 0x04);
54 con &= ~(1 << offset);
56 __raw_writel(con, base + 0x00);
57 __raw_writel(dat, base + 0x04);
59 local_irq_restore(flags);
63 static int s3c24xx_gpiolib_bankf_toirq(struct gpio_chip *chip, unsigned offset)
66 return IRQ_EINT0 + offset;
69 return IRQ_EINT4 + offset - 4;
74 static int s3c24xx_gpiolib_bankg_toirq(struct gpio_chip *chip, unsigned offset)
76 return IRQ_EINT8 + offset;
79 struct s3c_gpio_chip s3c24xx_gpios[] = {
81 .base = S3C24XX_GPIO_BASE(S3C2410_GPA0),
82 .pm = __gpio_pm(&s3c_gpio_pm_1bit),
88 .direction_input = s3c24xx_gpiolib_banka_input,
89 .direction_output = s3c24xx_gpiolib_banka_output,
93 .base = S3C24XX_GPIO_BASE(S3C2410_GPB0),
94 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
103 .base = S3C24XX_GPIO_BASE(S3C2410_GPC0),
104 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
106 .base = S3C2410_GPC0,
107 .owner = THIS_MODULE,
113 .base = S3C24XX_GPIO_BASE(S3C2410_GPD0),
114 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
116 .base = S3C2410_GPD0,
117 .owner = THIS_MODULE,
123 .base = S3C24XX_GPIO_BASE(S3C2410_GPE0),
124 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
126 .base = S3C2410_GPE0,
128 .owner = THIS_MODULE,
133 .base = S3C24XX_GPIO_BASE(S3C2410_GPF0),
134 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
136 .base = S3C2410_GPF0,
137 .owner = THIS_MODULE,
140 .to_irq = s3c24xx_gpiolib_bankf_toirq,
144 .base = S3C24XX_GPIO_BASE(S3C2410_GPG0),
145 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
147 .base = S3C2410_GPG0,
148 .owner = THIS_MODULE,
151 .to_irq = s3c24xx_gpiolib_bankg_toirq,
156 static __init int s3c24xx_gpiolib_init(void)
158 struct s3c_gpio_chip *chip = s3c24xx_gpios;
161 for (gpn = 0; gpn < ARRAY_SIZE(s3c24xx_gpios); gpn++, chip++)
162 s3c_gpiolib_add(chip);
167 arch_initcall(s3c24xx_gpiolib_init);