OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [arch/] [sh/] [kernel/] [setup_hd64465.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * $Id: setup_hd64465.c,v 1.1.1.1 2004-04-15 01:17:27 phoenix Exp $
3
 *
4
 * Setup and IRQ handling code for the HD64465 companion chip.
5
 * by Greg Banks <gbanks@pocketpenguins.com>
6
 * Copyright (c) 2000 PocketPenguins Inc
7
 *
8
 * Derived from setup_hd64461.c which bore the message:
9
 * Copyright (C) 2000 YAEGASHI Takeshi
10
 */
11
 
12
#include <linux/config.h>
13
#include <linux/sched.h>
14
#include <linux/module.h>
15
#include <linux/kernel.h>
16
#include <linux/param.h>
17
#include <linux/ioport.h>
18
#include <linux/interrupt.h>
19
#include <linux/init.h>
20
#include <linux/irq.h>
21
 
22
#include <asm/io.h>
23
#include <asm/irq.h>
24
 
25
#include <asm/hd64465.h>
26
 
27
#undef HD64465_DEBUG
28
 
29
#ifdef HD64465_DEBUG
30
#define DPRINTK(args...)        printk(args)
31
#else
32
#define DPRINTK(args...)
33
#endif
34
 
35
static void disable_hd64465_irq(unsigned int irq)
36
{
37
        unsigned long flags;
38
        unsigned short nimr;
39
        unsigned short mask = 1 << (irq - HD64465_IRQ_BASE);
40
 
41
        DPRINTK("disable_hd64465_irq(%d): mask=%x\n", irq, mask);
42
        save_and_cli(flags);
43
        nimr = inw(HD64465_REG_NIMR);
44
        nimr |= mask;
45
        outw(nimr, HD64465_REG_NIMR);
46
        restore_flags(flags);
47
}
48
 
49
 
50
static void enable_hd64465_irq(unsigned int irq)
51
{
52
        unsigned long flags;
53
        unsigned short nimr;
54
        unsigned short mask = 1 << (irq - HD64465_IRQ_BASE);
55
 
56
        DPRINTK("enable_hd64465_irq(%d): mask=%x\n", irq, mask);
57
        save_and_cli(flags);
58
        nimr = inw(HD64465_REG_NIMR);
59
        nimr &= ~mask;
60
        outw(nimr, HD64465_REG_NIMR);
61
        restore_flags(flags);
62
}
63
 
64
 
65
static void mask_and_ack_hd64465(unsigned int irq)
66
{
67
        disable_hd64465_irq(irq);
68
}
69
 
70
 
71
static void end_hd64465_irq(unsigned int irq)
72
{
73
        if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
74
                enable_hd64465_irq(irq);
75
}
76
 
77
 
78
static unsigned int startup_hd64465_irq(unsigned int irq)
79
{
80
        enable_hd64465_irq(irq);
81
        return 0;
82
}
83
 
84
 
85
static void shutdown_hd64465_irq(unsigned int irq)
86
{
87
        disable_hd64465_irq(irq);
88
}
89
 
90
 
91
static struct hw_interrupt_type hd64465_irq_type = {
92
        typename:       "HD64465-IRQ",
93
        startup:        startup_hd64465_irq,
94
        shutdown:       shutdown_hd64465_irq,
95
        enable:         enable_hd64465_irq,
96
        disable:        disable_hd64465_irq,
97
        ack:            mask_and_ack_hd64465,
98
        end:            end_hd64465_irq
99
};
100
 
101
 
102
static void hd64465_interrupt(int irq, void *dev_id, struct pt_regs *regs)
103
{
104
        printk(KERN_INFO
105
               "HD64465: spurious interrupt, nirr: 0x%x nimr: 0x%x\n",
106
               inw(HD64465_REG_NIRR), inw(HD64465_REG_NIMR));
107
}
108
 
109
 
110
/*====================================================*/
111
 
112
/*
113
 * Support for a secondary IRQ demux step.  This is necessary
114
 * because the HD64465 presents a very thin interface to the
115
 * PCMCIA bus; a lot of features (such as remapping interrupts)
116
 * normally done in hardware by other PCMCIA host bridges is
117
 * instead done in software.
118
 */
119
static struct
120
{
121
    int (*func)(int, void *);
122
    void *dev;
123
} hd64465_demux[HD64465_IRQ_NUM];
124
 
125
void hd64465_register_irq_demux(int irq,
126
                int (*demux)(int irq, void *dev), void *dev)
127
{
128
        hd64465_demux[irq - HD64465_IRQ_BASE].func = demux;
129
        hd64465_demux[irq - HD64465_IRQ_BASE].dev = dev;
130
}
131
EXPORT_SYMBOL(hd64465_register_irq_demux);
132
 
133
void hd64465_unregister_irq_demux(int irq)
134
{
135
        hd64465_demux[irq - HD64465_IRQ_BASE].func = 0;
136
}
137
EXPORT_SYMBOL(hd64465_unregister_irq_demux);
138
 
139
 
140
 
141
int hd64465_irq_demux(int irq)
142
{
143
        if (irq == CONFIG_HD64465_IRQ) {
144
                unsigned short i, bit;
145
                unsigned short nirr = inw(HD64465_REG_NIRR);
146
                unsigned short nimr = inw(HD64465_REG_NIMR);
147
 
148
                DPRINTK("hd64465_irq_demux, nirr=%04x, nimr=%04x\n", nirr, nimr);
149
                nirr &= ~nimr;
150
                for (bit = 1, i = 0 ; i < HD64465_IRQ_NUM ; bit <<= 1, i++)
151
                    if (nirr & bit)
152
                        break;
153
 
154
                if (i < HD64465_IRQ_NUM) {
155
                    irq = HD64465_IRQ_BASE + i;
156
                    if (hd64465_demux[i].func != 0)
157
                        irq = hd64465_demux[i].func(irq, hd64465_demux[i].dev);
158
                }
159
        }
160
        return irq;
161
}
162
 
163
static struct irqaction irq0  = { hd64465_interrupt, SA_INTERRUPT, 0, "HD64465", NULL, NULL};
164
 
165
 
166
static int __init setup_hd64465(void)
167
{
168
        int i;
169
        unsigned short rev;
170
        unsigned short smscr;
171
 
172
        if (!MACH_HD64465)
173
                return 0;
174
 
175
        printk(KERN_INFO "HD64465 configured at 0x%x on irq %d(mapped into %d to %d)\n",
176
               CONFIG_HD64465_IOBASE,
177
               CONFIG_HD64465_IRQ,
178
               HD64465_IRQ_BASE,
179
               HD64465_IRQ_BASE+HD64465_IRQ_NUM-1);
180
 
181
        if (inw(HD64465_REG_SDID) != HD64465_SDID) {
182
                printk(KERN_ERR "HD64465 device ID not found, check base address\n");
183
        }
184
 
185
        rev = inw(HD64465_REG_SRR);
186
        printk(KERN_INFO "HD64465 hardware revision %d.%d\n", (rev >> 8) & 0xff, rev & 0xff);
187
 
188
        outw(0xffff, HD64465_REG_NIMR);         /* mask all interrupts */
189
 
190
        for (i = 0; i < HD64465_IRQ_NUM ; i++) {
191
                irq_desc[HD64465_IRQ_BASE + i].handler = &hd64465_irq_type;
192
        }
193
 
194
        setup_irq(CONFIG_HD64465_IRQ, &irq0);
195
 
196
#ifdef CONFIG_SERIAL
197
        /* wake up the UART from STANDBY at this point */
198
        smscr = inw(HD64465_REG_SMSCR);
199
        outw(smscr & (~HD64465_SMSCR_UARTST), HD64465_REG_SMSCR);
200
 
201
        /* remap IO ports for first ISA serial port to HD64465 UART */
202
        hd64465_port_map(0x3f8, 8, CONFIG_HD64465_IOBASE + 0x8000, 1);
203
#endif
204
 
205
        return 0;
206
}
207
 
208
module_init(setup_hd64465);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.