blob: 3cbec6d3f38187520466bcddfa89fedbd14b5fd0 [file] [log] [blame]
Ben Dooksf348a2a2008-07-03 11:24:25 +01001/* linux/arch/arm/plat-s3c24xx/gpiolib.c
2 *
3 * Copyright (c) 2008 Simtec Electronics
4 * http://armlinux.simtec.co.uk/
5 * Ben Dooks <ben@simtec.co.uk>
6 *
7 * S3C24XX GPIOlib support
8 *
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.
12*/
13
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/interrupt.h>
Ben Dooks86c03c52009-05-17 22:47:07 +010018#include <linux/sysdev.h>
Ben Dooksf348a2a2008-07-03 11:24:25 +010019#include <linux/ioport.h>
20#include <linux/io.h>
21#include <linux/gpio.h>
22
Ben Dooksec5cfbf2009-04-17 12:36:43 +010023#include <mach/gpio-core.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010024#include <mach/hardware.h>
Ben Dooksf348a2a2008-07-03 11:24:25 +010025#include <asm/irq.h>
Ben Dooksd87964c2008-12-12 00:24:30 +000026#include <plat/pm.h>
Ben Dooksf348a2a2008-07-03 11:24:25 +010027
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/regs-gpio.h>
Ben Dooksf348a2a2008-07-03 11:24:25 +010029
Ben Dooksf348a2a2008-07-03 11:24:25 +010030static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset)
31{
32 return -EINVAL;
33}
34
35static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip,
36 unsigned offset, int value)
37{
Ben Dooks7db6c822008-10-31 16:14:31 +000038 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
Ben Dooksf348a2a2008-07-03 11:24:25 +010039 void __iomem *base = ourchip->base;
40 unsigned long flags;
41 unsigned long dat;
42 unsigned long con;
43
44 local_irq_save(flags);
45
46 con = __raw_readl(base + 0x00);
47 dat = __raw_readl(base + 0x04);
48
49 dat &= ~(1 << offset);
50 if (value)
51 dat |= 1 << offset;
52
53 __raw_writel(dat, base + 0x04);
54
55 con &= ~(1 << offset);
56
57 __raw_writel(con, base + 0x00);
58 __raw_writel(dat, base + 0x04);
59
60 local_irq_restore(flags);
61 return 0;
62}
63
Ben Dooks43ae6592009-01-08 12:40:50 +000064static int s3c24xx_gpiolib_bankf_toirq(struct gpio_chip *chip, unsigned offset)
65{
66 if (offset < 4)
67 return IRQ_EINT0 + offset;
68
69 if (offset < 8)
70 return IRQ_EINT4 + offset - 4;
71
72 return -EINVAL;
73}
74
75static int s3c24xx_gpiolib_bankg_toirq(struct gpio_chip *chip, unsigned offset)
76{
77 return IRQ_EINT8 + offset;
78}
79
Ben Dooks21b23662008-10-31 16:14:34 +000080struct s3c_gpio_chip s3c24xx_gpios[] = {
Ben Dooksf348a2a2008-07-03 11:24:25 +010081 [0] = {
82 .base = S3C24XX_GPIO_BASE(S3C2410_GPA0),
Ben Dooksd87964c2008-12-12 00:24:30 +000083 .pm = __gpio_pm(&s3c_gpio_pm_1bit),
Ben Dooksf348a2a2008-07-03 11:24:25 +010084 .chip = {
85 .base = S3C2410_GPA0,
86 .owner = THIS_MODULE,
87 .label = "GPIOA",
88 .ngpio = 24,
89 .direction_input = s3c24xx_gpiolib_banka_input,
90 .direction_output = s3c24xx_gpiolib_banka_output,
Ben Dooksf348a2a2008-07-03 11:24:25 +010091 },
92 },
93 [1] = {
94 .base = S3C24XX_GPIO_BASE(S3C2410_GPB0),
Ben Dooksd87964c2008-12-12 00:24:30 +000095 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
Ben Dooksf348a2a2008-07-03 11:24:25 +010096 .chip = {
97 .base = S3C2410_GPB0,
98 .owner = THIS_MODULE,
99 .label = "GPIOB",
100 .ngpio = 16,
Ben Dooksf348a2a2008-07-03 11:24:25 +0100101 },
102 },
103 [2] = {
104 .base = S3C24XX_GPIO_BASE(S3C2410_GPC0),
Ben Dooksd87964c2008-12-12 00:24:30 +0000105 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100106 .chip = {
107 .base = S3C2410_GPC0,
108 .owner = THIS_MODULE,
109 .label = "GPIOC",
110 .ngpio = 16,
Ben Dooksf348a2a2008-07-03 11:24:25 +0100111 },
112 },
113 [3] = {
114 .base = S3C24XX_GPIO_BASE(S3C2410_GPD0),
Ben Dooksd87964c2008-12-12 00:24:30 +0000115 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100116 .chip = {
117 .base = S3C2410_GPD0,
118 .owner = THIS_MODULE,
119 .label = "GPIOD",
120 .ngpio = 16,
Ben Dooksf348a2a2008-07-03 11:24:25 +0100121 },
122 },
123 [4] = {
124 .base = S3C24XX_GPIO_BASE(S3C2410_GPE0),
Ben Dooksd87964c2008-12-12 00:24:30 +0000125 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100126 .chip = {
127 .base = S3C2410_GPE0,
128 .label = "GPIOE",
129 .owner = THIS_MODULE,
130 .ngpio = 16,
Ben Dooksf348a2a2008-07-03 11:24:25 +0100131 },
132 },
133 [5] = {
134 .base = S3C24XX_GPIO_BASE(S3C2410_GPF0),
Ben Dooksd87964c2008-12-12 00:24:30 +0000135 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100136 .chip = {
137 .base = S3C2410_GPF0,
138 .owner = THIS_MODULE,
139 .label = "GPIOF",
140 .ngpio = 8,
Ben Dooks43ae6592009-01-08 12:40:50 +0000141 .to_irq = s3c24xx_gpiolib_bankf_toirq,
Ben Dooksf348a2a2008-07-03 11:24:25 +0100142 },
143 },
144 [6] = {
145 .base = S3C24XX_GPIO_BASE(S3C2410_GPG0),
Ben Dooksd87964c2008-12-12 00:24:30 +0000146 .pm = __gpio_pm(&s3c_gpio_pm_2bit),
Ben Dooksf348a2a2008-07-03 11:24:25 +0100147 .chip = {
148 .base = S3C2410_GPG0,
149 .owner = THIS_MODULE,
150 .label = "GPIOG",
151 .ngpio = 10,
Ben Dooks43ae6592009-01-08 12:40:50 +0000152 .to_irq = s3c24xx_gpiolib_bankg_toirq,
Ben Dooksf348a2a2008-07-03 11:24:25 +0100153 },
154 },
155};
156
157static __init int s3c24xx_gpiolib_init(void)
158{
Ben Dooks21b23662008-10-31 16:14:34 +0000159 struct s3c_gpio_chip *chip = s3c24xx_gpios;
Ben Dooksf348a2a2008-07-03 11:24:25 +0100160 int gpn;
161
Ben Dooks21b23662008-10-31 16:14:34 +0000162 for (gpn = 0; gpn < ARRAY_SIZE(s3c24xx_gpios); gpn++, chip++)
Ben Dooks7db6c822008-10-31 16:14:31 +0000163 s3c_gpiolib_add(chip);
Ben Dooksf348a2a2008-07-03 11:24:25 +0100164
165 return 0;
166}
167
168arch_initcall(s3c24xx_gpiolib_init);