gpiolib.c 4.9 KB
Newer Older
B
Ben Dooks 已提交
1 2
/* linux/arch/arm/plat-s3c24xx/gpiolib.c
 *
3
 * Copyright (c) 2008-2010 Simtec Electronics
B
Ben Dooks 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *	http://armlinux.simtec.co.uk/
 *	Ben Dooks <ben@simtec.co.uk>
 *
 * S3C24XX GPIOlib support
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License.
*/

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/interrupt.h>
18
#include <linux/sysdev.h>
B
Ben Dooks 已提交
19 20 21 22
#include <linux/ioport.h>
#include <linux/io.h>
#include <linux/gpio.h>

23
#include <plat/gpio-core.h>
24 25
#include <plat/gpio-cfg.h>
#include <plat/gpio-cfg-helpers.h>
26
#include <mach/hardware.h>
B
Ben Dooks 已提交
27
#include <asm/irq.h>
28
#include <plat/pm.h>
B
Ben Dooks 已提交
29

30
#include <mach/regs-gpio.h>
B
Ben Dooks 已提交
31 32 33 34 35 36 37 38 39

static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset)
{
	return -EINVAL;
}

static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip,
					unsigned offset, int value)
{
40
	struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
B
Ben Dooks 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
	void __iomem *base = ourchip->base;
	unsigned long flags;
	unsigned long dat;
	unsigned long con;

	local_irq_save(flags);

	con = __raw_readl(base + 0x00);
	dat = __raw_readl(base + 0x04);

	dat &= ~(1 << offset);
	if (value)
		dat |= 1 << offset;

	__raw_writel(dat, base + 0x04);

	con &= ~(1 << offset);

	__raw_writel(con, base + 0x00);
	__raw_writel(dat, base + 0x04);

	local_irq_restore(flags);
	return 0;
}

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
static int s3c24xx_gpiolib_bankf_toirq(struct gpio_chip *chip, unsigned offset)
{
	if (offset < 4)
		return IRQ_EINT0 + offset;
	
	if (offset < 8)
		return IRQ_EINT4 + offset - 4;
	
	return -EINVAL;
}

static int s3c24xx_gpiolib_bankg_toirq(struct gpio_chip *chip, unsigned offset)
{
	return IRQ_EINT8 + offset;
}

82 83
static struct s3c_gpio_cfg s3c24xx_gpiocfg_banka = {
	.set_config	= s3c_gpio_setcfg_s3c24xx_a,
84
	.get_config	= s3c_gpio_getcfg_s3c24xx_a,
85 86 87 88
};

struct s3c_gpio_cfg s3c24xx_gpiocfg_default = {
	.set_config	= s3c_gpio_setcfg_s3c24xx,
89
	.get_config	= s3c_gpio_getcfg_s3c24xx,
90 91
	.set_pull	= s3c_gpio_setpull_1up,
	.get_pull	= s3c_gpio_getpull_1up,
92 93
};

94
struct s3c_gpio_chip s3c24xx_gpios[] = {
B
Ben Dooks 已提交
95
	[0] = {
96
		.base	= S3C2410_GPACON,
97
		.pm	= __gpio_pm(&s3c_gpio_pm_1bit),
98
		.config	= &s3c24xx_gpiocfg_banka,
B
Ben Dooks 已提交
99
		.chip	= {
100
			.base			= S3C2410_GPA(0),
B
Ben Dooks 已提交
101 102 103 104 105 106 107 108
			.owner			= THIS_MODULE,
			.label			= "GPIOA",
			.ngpio			= 24,
			.direction_input	= s3c24xx_gpiolib_banka_input,
			.direction_output	= s3c24xx_gpiolib_banka_output,
		},
	},
	[1] = {
109
		.base	= S3C2410_GPBCON,
110
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
B
Ben Dooks 已提交
111
		.chip	= {
112
			.base			= S3C2410_GPB(0),
B
Ben Dooks 已提交
113 114 115 116 117 118
			.owner			= THIS_MODULE,
			.label			= "GPIOB",
			.ngpio			= 16,
		},
	},
	[2] = {
119
		.base	= S3C2410_GPCCON,
120
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
B
Ben Dooks 已提交
121
		.chip	= {
122
			.base			= S3C2410_GPC(0),
B
Ben Dooks 已提交
123 124 125 126 127 128
			.owner			= THIS_MODULE,
			.label			= "GPIOC",
			.ngpio			= 16,
		},
	},
	[3] = {
129
		.base	= S3C2410_GPDCON,
130
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
B
Ben Dooks 已提交
131
		.chip	= {
132
			.base			= S3C2410_GPD(0),
B
Ben Dooks 已提交
133 134 135 136 137 138
			.owner			= THIS_MODULE,
			.label			= "GPIOD",
			.ngpio			= 16,
		},
	},
	[4] = {
139
		.base	= S3C2410_GPECON,
140
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
B
Ben Dooks 已提交
141
		.chip	= {
142
			.base			= S3C2410_GPE(0),
B
Ben Dooks 已提交
143 144 145 146 147 148
			.label			= "GPIOE",
			.owner			= THIS_MODULE,
			.ngpio			= 16,
		},
	},
	[5] = {
149
		.base	= S3C2410_GPFCON,
150
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
B
Ben Dooks 已提交
151
		.chip	= {
152
			.base			= S3C2410_GPF(0),
B
Ben Dooks 已提交
153 154 155
			.owner			= THIS_MODULE,
			.label			= "GPIOF",
			.ngpio			= 8,
156
			.to_irq			= s3c24xx_gpiolib_bankf_toirq,
B
Ben Dooks 已提交
157 158 159
		},
	},
	[6] = {
160
		.base	= S3C2410_GPGCON,
161
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
B
Ben Dooks 已提交
162
		.chip	= {
163
			.base			= S3C2410_GPG(0),
B
Ben Dooks 已提交
164 165
			.owner			= THIS_MODULE,
			.label			= "GPIOG",
166
			.ngpio			= 16,
167
			.to_irq			= s3c24xx_gpiolib_bankg_toirq,
B
Ben Dooks 已提交
168
		},
169 170 171 172 173 174 175 176 177
	}, {
		.base	= S3C2410_GPHCON,
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
		.chip	= {
			.base			= S3C2410_GPH(0),
			.owner			= THIS_MODULE,
			.label			= "GPIOH",
			.ngpio			= 11,
		},
B
Ben Dooks 已提交
178
	},
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
		/* GPIOS for the S3C2443 and later devices. */
	{
		.base	= S3C2440_GPJCON,
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
		.chip	= {
			.base			= S3C2410_GPJ(0),
			.owner			= THIS_MODULE,
			.label			= "GPIOJ",
			.ngpio			= 16,
		},
	}, {
		.base	= S3C2443_GPKCON,
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
		.chip	= {
			.base			= S3C2410_GPK(0),
			.owner			= THIS_MODULE,
			.label			= "GPIOK",
			.ngpio			= 16,
		},
	}, {
		.base	= S3C2443_GPLCON,
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
		.chip	= {
			.base			= S3C2410_GPL(0),
			.owner			= THIS_MODULE,
			.label			= "GPIOL",
			.ngpio			= 15,
		},
	}, {
		.base	= S3C2443_GPMCON,
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
		.chip	= {
			.base			= S3C2410_GPM(0),
			.owner			= THIS_MODULE,
			.label			= "GPIOM",
			.ngpio			= 2,
		},
	},
B
Ben Dooks 已提交
217 218
};

219

B
Ben Dooks 已提交
220 221
static __init int s3c24xx_gpiolib_init(void)
{
222
	struct s3c_gpio_chip *chip = s3c24xx_gpios;
B
Ben Dooks 已提交
223 224
	int gpn;

225 226 227 228
	for (gpn = 0; gpn < ARRAY_SIZE(s3c24xx_gpios); gpn++, chip++) {
		if (!chip->config)
			chip->config = &s3c24xx_gpiocfg_default;

229
		s3c_gpiolib_add(chip);
230
	}
B
Ben Dooks 已提交
231 232 233 234

	return 0;
}

235
core_initcall(s3c24xx_gpiolib_init);