irq.c 3.54 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-or-later
2 3 4 5 6 7 8 9 10 11 12
/*
 * arch/arm/mach-ks8695/irq.c
 *
 * Copyright (C) 2006 Ben Dooks <ben@simtec.co.uk>
 * Copyright (C) 2006 Simtec Electronics
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
13
#include <linux/device.h>
14
#include <linux/io.h>
15

16
#include <mach/hardware.h>
17 18 19 20
#include <asm/irq.h>

#include <asm/mach/irq.h>

21 22
#include <mach/regs-irq.h>
#include <mach/regs-gpio.h>
23

24
static void ks8695_irq_mask(struct irq_data *d)
25 26 27 28
{
	unsigned long inten;

	inten = __raw_readl(KS8695_IRQ_VA + KS8695_INTEN);
29
	inten &= ~(1 << d->irq);
30 31 32 33

	__raw_writel(inten, KS8695_IRQ_VA + KS8695_INTEN);
}

34
static void ks8695_irq_unmask(struct irq_data *d)
35 36 37 38
{
	unsigned long inten;

	inten = __raw_readl(KS8695_IRQ_VA + KS8695_INTEN);
39
	inten |= (1 << d->irq);
40 41 42 43

	__raw_writel(inten, KS8695_IRQ_VA + KS8695_INTEN);
}

44
static void ks8695_irq_ack(struct irq_data *d)
45
{
46
	__raw_writel((1 << d->irq), KS8695_IRQ_VA + KS8695_INTST);
47 48 49 50 51 52 53
}


static struct irq_chip ks8695_irq_level_chip;
static struct irq_chip ks8695_irq_edge_chip;


54
static int ks8695_irq_set_type(struct irq_data *d, unsigned int type)
55 56 57 58 59 60 61
{
	unsigned long ctrl, mode;
	unsigned short level_triggered = 0;

	ctrl = __raw_readl(KS8695_GPIO_VA + KS8695_IOPC);

	switch (type) {
62
		case IRQ_TYPE_LEVEL_HIGH:
63 64 65
			mode = IOPC_TM_HIGH;
			level_triggered = 1;
			break;
66
		case IRQ_TYPE_LEVEL_LOW:
67 68 69
			mode = IOPC_TM_LOW;
			level_triggered = 1;
			break;
70
		case IRQ_TYPE_EDGE_RISING:
71 72
			mode = IOPC_TM_RISING;
			break;
73
		case IRQ_TYPE_EDGE_FALLING:
74 75
			mode = IOPC_TM_FALLING;
			break;
76
		case IRQ_TYPE_EDGE_BOTH:
77 78 79 80 81 82
			mode = IOPC_TM_EDGE;
			break;
		default:
			return -EINVAL;
	}

83
	switch (d->irq) {
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
		case KS8695_IRQ_EXTERN0:
			ctrl &= ~IOPC_IOEINT0TM;
			ctrl |= IOPC_IOEINT0_MODE(mode);
			break;
		case KS8695_IRQ_EXTERN1:
			ctrl &= ~IOPC_IOEINT1TM;
			ctrl |= IOPC_IOEINT1_MODE(mode);
			break;
		case KS8695_IRQ_EXTERN2:
			ctrl &= ~IOPC_IOEINT2TM;
			ctrl |= IOPC_IOEINT2_MODE(mode);
			break;
		case KS8695_IRQ_EXTERN3:
			ctrl &= ~IOPC_IOEINT3TM;
			ctrl |= IOPC_IOEINT3_MODE(mode);
			break;
		default:
			return -EINVAL;
	}

	if (level_triggered) {
105 106
		irq_set_chip_and_handler(d->irq, &ks8695_irq_level_chip,
					 handle_level_irq);
107 108
	}
	else {
109 110
		irq_set_chip_and_handler(d->irq, &ks8695_irq_edge_chip,
					 handle_edge_irq);
111 112 113 114 115 116 117
	}

	__raw_writel(ctrl, KS8695_GPIO_VA + KS8695_IOPC);
	return 0;
}

static struct irq_chip ks8695_irq_level_chip = {
118 119 120 121
	.irq_ack	= ks8695_irq_mask,
	.irq_mask	= ks8695_irq_mask,
	.irq_unmask	= ks8695_irq_unmask,
	.irq_set_type	= ks8695_irq_set_type,
122 123 124
};

static struct irq_chip ks8695_irq_edge_chip = {
125 126 127 128
	.irq_ack	= ks8695_irq_ack,
	.irq_mask	= ks8695_irq_mask,
	.irq_unmask	= ks8695_irq_unmask,
	.irq_set_type	= ks8695_irq_set_type,
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
};

void __init ks8695_init_irq(void)
{
	unsigned int irq;

	/* Disable all interrupts initially */
	__raw_writel(0, KS8695_IRQ_VA + KS8695_INTMC);
	__raw_writel(0, KS8695_IRQ_VA + KS8695_INTEN);

	for (irq = 0; irq < NR_IRQS; irq++) {
		switch (irq) {
			/* Level-triggered interrupts */
			case KS8695_IRQ_BUS_ERROR:
			case KS8695_IRQ_UART_MODEM_STATUS:
			case KS8695_IRQ_UART_LINE_STATUS:
			case KS8695_IRQ_UART_RX:
			case KS8695_IRQ_COMM_TX:
			case KS8695_IRQ_COMM_RX:
148 149 150
				irq_set_chip_and_handler(irq,
							 &ks8695_irq_level_chip,
							 handle_level_irq);
151 152 153 154
				break;

			/* Edge-triggered interrupts */
			default:
155 156
				/* clear pending bit */
				ks8695_irq_ack(irq_get_irq_data(irq));
157 158 159
				irq_set_chip_and_handler(irq,
							 &ks8695_irq_edge_chip,
							 handle_edge_irq);
160 161
		}

162
		irq_clear_status_flags(irq, IRQ_NOREQUEST);
163 164
	}
}