gpiolib.c 3.4 KB
Newer Older
B
Ben Dooks 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* linux/arch/arm/plat-s3c24xx/gpiolib.c
 *
 * Copyright (c) 2008 Simtec Electronics
 *	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 <mach/gpio-core.h>
24
#include <mach/hardware.h>
B
Ben Dooks 已提交
25
#include <asm/irq.h>
26
#include <plat/pm.h>
B
Ben Dooks 已提交
27

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

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)
{
38
	struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
B
Ben Dooks 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
	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;
}

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
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;
}

80
struct s3c_gpio_chip s3c24xx_gpios[] = {
B
Ben Dooks 已提交
81
	[0] = {
82
		.base	= S3C2410_GPACON,
83
		.pm	= __gpio_pm(&s3c_gpio_pm_1bit),
B
Ben Dooks 已提交
84
		.chip	= {
85
			.base			= S3C2410_GPA(0),
B
Ben Dooks 已提交
86 87 88 89 90 91 92 93
			.owner			= THIS_MODULE,
			.label			= "GPIOA",
			.ngpio			= 24,
			.direction_input	= s3c24xx_gpiolib_banka_input,
			.direction_output	= s3c24xx_gpiolib_banka_output,
		},
	},
	[1] = {
94
		.base	= S3C2410_GPBCON,
95
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
B
Ben Dooks 已提交
96
		.chip	= {
97
			.base			= S3C2410_GPB(0),
B
Ben Dooks 已提交
98 99 100 101 102 103
			.owner			= THIS_MODULE,
			.label			= "GPIOB",
			.ngpio			= 16,
		},
	},
	[2] = {
104
		.base	= S3C2410_GPCCON,
105
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
B
Ben Dooks 已提交
106
		.chip	= {
107
			.base			= S3C2410_GPC(0),
B
Ben Dooks 已提交
108 109 110 111 112 113
			.owner			= THIS_MODULE,
			.label			= "GPIOC",
			.ngpio			= 16,
		},
	},
	[3] = {
114
		.base	= S3C2410_GPDCON,
115
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
B
Ben Dooks 已提交
116
		.chip	= {
117
			.base			= S3C2410_GPD(0),
B
Ben Dooks 已提交
118 119 120 121 122 123
			.owner			= THIS_MODULE,
			.label			= "GPIOD",
			.ngpio			= 16,
		},
	},
	[4] = {
124
		.base	= S3C2410_GPECON,
125
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
B
Ben Dooks 已提交
126
		.chip	= {
127
			.base			= S3C2410_GPE(0),
B
Ben Dooks 已提交
128 129 130 131 132 133
			.label			= "GPIOE",
			.owner			= THIS_MODULE,
			.ngpio			= 16,
		},
	},
	[5] = {
134
		.base	= S3C2410_GPFCON,
135
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
B
Ben Dooks 已提交
136
		.chip	= {
137
			.base			= S3C2410_GPF(0),
B
Ben Dooks 已提交
138 139 140
			.owner			= THIS_MODULE,
			.label			= "GPIOF",
			.ngpio			= 8,
141
			.to_irq			= s3c24xx_gpiolib_bankf_toirq,
B
Ben Dooks 已提交
142 143 144
		},
	},
	[6] = {
145
		.base	= S3C2410_GPGCON,
146
		.pm	= __gpio_pm(&s3c_gpio_pm_2bit),
B
Ben Dooks 已提交
147
		.chip	= {
148
			.base			= S3C2410_GPG(0),
B
Ben Dooks 已提交
149 150 151
			.owner			= THIS_MODULE,
			.label			= "GPIOG",
			.ngpio			= 10,
152
			.to_irq			= s3c24xx_gpiolib_bankg_toirq,
B
Ben Dooks 已提交
153 154 155 156 157 158
		},
	},
};

static __init int s3c24xx_gpiolib_init(void)
{
159
	struct s3c_gpio_chip *chip = s3c24xx_gpios;
B
Ben Dooks 已提交
160 161
	int gpn;

162
	for (gpn = 0; gpn < ARRAY_SIZE(s3c24xx_gpios); gpn++, chip++)
163
		s3c_gpiolib_add(chip);
B
Ben Dooks 已提交
164 165 166 167 168

	return 0;
}

arch_initcall(s3c24xx_gpiolib_init);