irq-eint.c 5.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* linux/arch/arm/plat-s5p/irq-eint.c
 *
 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com
 *
 * S5P - IRQ EINT support
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
*/

#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/io.h>
K
Kay Sievers 已提交
17
#include <linux/device.h>
18 19 20 21 22 23 24 25 26 27 28 29 30
#include <linux/gpio.h>

#include <asm/hardware/vic.h>

#include <plat/regs-irqtype.h>

#include <mach/map.h>
#include <plat/cpu.h>
#include <plat/pm.h>

#include <plat/gpio-cfg.h>
#include <mach/regs-gpio.h>

31
static inline void s5p_irq_eint_mask(struct irq_data *data)
32 33 34
{
	u32 mask;

35 36 37
	mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
	mask |= eint_irq_to_bit(data->irq);
	__raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
38 39
}

40
static void s5p_irq_eint_unmask(struct irq_data *data)
41 42 43
{
	u32 mask;

44 45 46
	mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq)));
	mask &= ~(eint_irq_to_bit(data->irq));
	__raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq)));
47 48
}

49
static inline void s5p_irq_eint_ack(struct irq_data *data)
50
{
51 52
	__raw_writel(eint_irq_to_bit(data->irq),
		     S5P_EINT_PEND(EINT_REG_NR(data->irq)));
53 54
}

55
static void s5p_irq_eint_maskack(struct irq_data *data)
56 57
{
	/* compiler should in-line these */
58 59
	s5p_irq_eint_mask(data);
	s5p_irq_eint_ack(data);
60 61
}

62
static int s5p_irq_eint_set_type(struct irq_data *data, unsigned int type)
63
{
64
	int offs = EINT_OFFSET(data->irq);
65 66 67 68 69 70
	int shift;
	u32 ctrl, mask;
	u32 newvalue = 0;

	switch (type) {
	case IRQ_TYPE_EDGE_RISING:
71
		newvalue = S5P_IRQ_TYPE_EDGE_RISING;
72 73 74
		break;

	case IRQ_TYPE_EDGE_FALLING:
75
		newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
76 77 78
		break;

	case IRQ_TYPE_EDGE_BOTH:
79
		newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
80 81 82
		break;

	case IRQ_TYPE_LEVEL_LOW:
83
		newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
84 85 86
		break;

	case IRQ_TYPE_LEVEL_HIGH:
87
		newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
88 89 90 91 92 93 94 95 96 97
		break;

	default:
		printk(KERN_ERR "No such irq type %d", type);
		return -EINVAL;
	}

	shift = (offs & 0x7) * 4;
	mask = 0x7 << shift;

98
	ctrl = __raw_readl(S5P_EINT_CON(EINT_REG_NR(data->irq)));
99 100
	ctrl &= ~mask;
	ctrl |= newvalue << shift;
101
	__raw_writel(ctrl, S5P_EINT_CON(EINT_REG_NR(data->irq)));
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

	if ((0 <= offs) && (offs < 8))
		s3c_gpio_cfgpin(EINT_GPIO_0(offs & 0x7), EINT_MODE);

	else if ((8 <= offs) && (offs < 16))
		s3c_gpio_cfgpin(EINT_GPIO_1(offs & 0x7), EINT_MODE);

	else if ((16 <= offs) && (offs < 24))
		s3c_gpio_cfgpin(EINT_GPIO_2(offs & 0x7), EINT_MODE);

	else if ((24 <= offs) && (offs < 32))
		s3c_gpio_cfgpin(EINT_GPIO_3(offs & 0x7), EINT_MODE);

	else
		printk(KERN_ERR "No such irq number %d", offs);

	return 0;
}

static struct irq_chip s5p_irq_eint = {
	.name		= "s5p-eint",
123 124 125 126 127
	.irq_mask	= s5p_irq_eint_mask,
	.irq_unmask	= s5p_irq_eint_unmask,
	.irq_mask_ack	= s5p_irq_eint_maskack,
	.irq_ack	= s5p_irq_eint_ack,
	.irq_set_type	= s5p_irq_eint_set_type,
128
#ifdef CONFIG_PM
129
	.irq_set_wake	= s3c_irqext_wake,
130 131 132 133 134 135 136 137 138 139 140 141 142
#endif
};

/* s5p_irq_demux_eint
 *
 * This function demuxes the IRQ from the group0 external interrupts,
 * from EINTs 16 to 31. It is designed to be inlined into the specific
 * handler s5p_irq_demux_eintX_Y.
 *
 * Each EINT pend/mask registers handle eight of them.
 */
static inline void s5p_irq_demux_eint(unsigned int start)
{
143
	u32 status = __raw_readl(S5P_EINT_PEND(EINT_REG_NR(start)));
144 145 146 147 148 149 150
	u32 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(start)));
	unsigned int irq;

	status &= ~mask;
	status &= 0xff;

	while (status) {
151 152
		irq = fls(status) - 1;
		generic_handle_irq(irq + start);
153 154 155 156 157 158 159 160 161 162
		status &= ~(1 << irq);
	}
}

static void s5p_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
{
	s5p_irq_demux_eint(IRQ_EINT(16));
	s5p_irq_demux_eint(IRQ_EINT(24));
}

163
static inline void s5p_irq_vic_eint_mask(struct irq_data *data)
164
{
165
	void __iomem *base = irq_data_get_irq_chip_data(data);
166

167 168
	s5p_irq_eint_mask(data);
	writel(1 << EINT_OFFSET(data->irq), base + VIC_INT_ENABLE_CLEAR);
169 170
}

171
static void s5p_irq_vic_eint_unmask(struct irq_data *data)
172
{
173
	void __iomem *base = irq_data_get_irq_chip_data(data);
174

175 176
	s5p_irq_eint_unmask(data);
	writel(1 << EINT_OFFSET(data->irq), base + VIC_INT_ENABLE);
177 178
}

179
static inline void s5p_irq_vic_eint_ack(struct irq_data *data)
180
{
181 182
	__raw_writel(eint_irq_to_bit(data->irq),
		     S5P_EINT_PEND(EINT_REG_NR(data->irq)));
183 184
}

185
static void s5p_irq_vic_eint_maskack(struct irq_data *data)
186
{
187 188
	s5p_irq_vic_eint_mask(data);
	s5p_irq_vic_eint_ack(data);
189 190 191 192
}

static struct irq_chip s5p_irq_vic_eint = {
	.name		= "s5p_vic_eint",
193 194 195 196 197
	.irq_mask	= s5p_irq_vic_eint_mask,
	.irq_unmask	= s5p_irq_vic_eint_unmask,
	.irq_mask_ack	= s5p_irq_vic_eint_maskack,
	.irq_ack	= s5p_irq_vic_eint_ack,
	.irq_set_type	= s5p_irq_eint_set_type,
198
#ifdef CONFIG_PM
199
	.irq_set_wake	= s3c_irqext_wake,
200 201 202 203 204 205 206 207
#endif
};

int __init s5p_init_irq_eint(void)
{
	int irq;

	for (irq = IRQ_EINT(0); irq <= IRQ_EINT(15); irq++)
T
Thomas Gleixner 已提交
208
		irq_set_chip(irq, &s5p_irq_vic_eint);
209 210

	for (irq = IRQ_EINT(16); irq <= IRQ_EINT(31); irq++) {
211
		irq_set_chip_and_handler(irq, &s5p_irq_eint, handle_level_irq);
212 213 214
		set_irq_flags(irq, IRQF_VALID);
	}

T
Thomas Gleixner 已提交
215
	irq_set_chained_handler(IRQ_EINT16_31, s5p_irq_demux_eint16_31);
216 217 218 219
	return 0;
}

arch_initcall(s5p_init_irq_eint);