hd64461.c 2.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*
 *	Copyright (C) 2000 YAEGASHI Takeshi
 *	Hitachi HD64461 companion chip support
 */

#include <linux/sched.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/param.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/irq.h>
13
#include <linux/io.h>
L
Linus Torvalds 已提交
14
#include <asm/irq.h>
15
#include <asm/hd64461.h>
L
Linus Torvalds 已提交
16

17 18 19
/* This belongs in cpu specific */
#define INTC_ICR1 0xA4140010UL

P
Paul Mundt 已提交
20
static void hd64461_mask_irq(struct irq_data *data)
L
Linus Torvalds 已提交
21
{
P
Paul Mundt 已提交
22
	unsigned int irq = data->irq;
L
Linus Torvalds 已提交
23 24 25
	unsigned short nimr;
	unsigned short mask = 1 << (irq - HD64461_IRQBASE);

26
	nimr = __raw_readw(HD64461_NIMR);
L
Linus Torvalds 已提交
27
	nimr |= mask;
28
	__raw_writew(nimr, HD64461_NIMR);
L
Linus Torvalds 已提交
29 30
}

P
Paul Mundt 已提交
31
static void hd64461_unmask_irq(struct irq_data *data)
L
Linus Torvalds 已提交
32
{
P
Paul Mundt 已提交
33
	unsigned int irq = data->irq;
L
Linus Torvalds 已提交
34 35 36
	unsigned short nimr;
	unsigned short mask = 1 << (irq - HD64461_IRQBASE);

37
	nimr = __raw_readw(HD64461_NIMR);
L
Linus Torvalds 已提交
38
	nimr &= ~mask;
39
	__raw_writew(nimr, HD64461_NIMR);
L
Linus Torvalds 已提交
40 41
}

P
Paul Mundt 已提交
42
static void hd64461_mask_and_ack_irq(struct irq_data *data)
L
Linus Torvalds 已提交
43
{
P
Paul Mundt 已提交
44 45
	hd64461_mask_irq(data);

L
Linus Torvalds 已提交
46
#ifdef CONFIG_HD64461_ENABLER
P
Paul Mundt 已提交
47
	if (data->irq == HD64461_IRQBASE + 13)
48
		__raw_writeb(0x00, HD64461_PCC1CSCR);
L
Linus Torvalds 已提交
49 50 51
#endif
}

52 53
static struct irq_chip hd64461_irq_chip = {
	.name		= "HD64461-IRQ",
P
Paul Mundt 已提交
54 55 56
	.irq_mask	= hd64461_mask_irq,
	.irq_mask_ack	= hd64461_mask_and_ack_irq,
	.irq_unmask	= hd64461_unmask_irq,
L
Linus Torvalds 已提交
57 58
};

59
static void hd64461_irq_demux(unsigned int irq, struct irq_desc *desc)
L
Linus Torvalds 已提交
60
{
61
	unsigned short intv = __raw_readw(HD64461_NIRR);
62 63 64 65
	unsigned int ext_irq = HD64461_IRQBASE;

	intv &= (1 << HD64461_IRQ_NUM) - 1;

P
Paul Mundt 已提交
66 67 68 69 70
	for (; intv; intv >>= 1, ext_irq++) {
		if (!(intv & 1))
			continue;

		generic_handle_irq(ext_irq);
L
Linus Torvalds 已提交
71 72 73 74 75
	}
}

int __init setup_hd64461(void)
{
P
Paul Mundt 已提交
76
	int i, nid = cpu_to_node(boot_cpu_data);
L
Linus Torvalds 已提交
77 78 79 80 81 82

	if (!MACH_HD64461)
		return 0;

	printk(KERN_INFO
	       "HD64461 configured at 0x%x on irq %d(mapped into %d to %d)\n",
83
	       HD64461_IOBASE, CONFIG_HD64461_IRQ, HD64461_IRQBASE,
L
Linus Torvalds 已提交
84 85
	       HD64461_IRQBASE + 15);

86 87 88
/* Should be at processor specific part.. */
#if defined(CONFIG_CPU_SUBTYPE_SH7709)
	__raw_writew(0x2240, INTC_ICR1);
L
Linus Torvalds 已提交
89
#endif
90
	__raw_writew(0xffff, HD64461_NIMR);
L
Linus Torvalds 已提交
91

92
	/*  IRQ 80 -> 95 belongs to HD64461  */
P
Paul Mundt 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
	for (i = HD64461_IRQBASE; i < HD64461_IRQBASE + 16; i++) {
		unsigned int irq;

		irq = create_irq_nr(i, nid);
		if (unlikely(irq == 0)) {
			pr_err("%s: failed hooking irq %d for HD64461\n",
			       __func__, i);
			return -EBUSY;
		}

		if (unlikely(irq != i)) {
			pr_err("%s: got irq %d but wanted %d, bailing.\n",
			       __func__, irq, i);
			destroy_irq(irq);
			return -EINVAL;
		}

110
		irq_set_chip_and_handler(i, &hd64461_irq_chip,
111
					 handle_level_irq);
P
Paul Mundt 已提交
112
	}
L
Linus Torvalds 已提交
113

114 115
	irq_set_chained_handler(CONFIG_HD64461_IRQ, hd64461_irq_demux);
	irq_set_irq_type(CONFIG_HD64461_IRQ, IRQ_TYPE_LEVEL_LOW);
116

L
Linus Torvalds 已提交
117 118
#ifdef CONFIG_HD64461_ENABLER
	printk(KERN_INFO "HD64461: enabling PCMCIA devices\n");
119 120
	__raw_writeb(0x4c, HD64461_PCC1CSCIER);
	__raw_writeb(0x00, HD64461_PCC1CSCR);
L
Linus Torvalds 已提交
121 122 123 124 125 126
#endif

	return 0;
}

module_init(setup_hd64461);