hd64465.c revision 1.3.6.3 1 1.3.6.3 nathanw /* $NetBSD: hd64465.c,v 1.3.6.3 2002/11/11 21:58:46 nathanw Exp $ */
2 1.3.6.2 nathanw
3 1.3.6.2 nathanw /*-
4 1.3.6.2 nathanw * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.3.6.2 nathanw * All rights reserved.
6 1.3.6.2 nathanw *
7 1.3.6.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.3.6.2 nathanw * by UCHIYAMA Yasushi.
9 1.3.6.2 nathanw *
10 1.3.6.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.3.6.2 nathanw * modification, are permitted provided that the following conditions
12 1.3.6.2 nathanw * are met:
13 1.3.6.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.3.6.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.3.6.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.3.6.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.3.6.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.3.6.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.3.6.2 nathanw * must display the following acknowledgement:
20 1.3.6.2 nathanw * This product includes software developed by the NetBSD
21 1.3.6.2 nathanw * Foundation, Inc. and its contributors.
22 1.3.6.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.3.6.2 nathanw * contributors may be used to endorse or promote products derived
24 1.3.6.2 nathanw * from this software without specific prior written permission.
25 1.3.6.2 nathanw *
26 1.3.6.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.3.6.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.3.6.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.3.6.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.3.6.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.3.6.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.3.6.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.3.6.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.3.6.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.3.6.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.3.6.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.3.6.2 nathanw */
38 1.3.6.2 nathanw
39 1.3.6.2 nathanw #include <sys/param.h>
40 1.3.6.2 nathanw #include <sys/systm.h>
41 1.3.6.2 nathanw #include <sys/device.h>
42 1.3.6.2 nathanw #include <sys/boot_flag.h>
43 1.3.6.2 nathanw
44 1.3.6.2 nathanw #include <machine/bus.h>
45 1.3.6.2 nathanw #include <machine/intr.h>
46 1.3.6.2 nathanw #include <machine/debug.h>
47 1.3.6.2 nathanw
48 1.3.6.2 nathanw #include <sh3/intcreg.h>
49 1.3.6.2 nathanw #include <hpcsh/dev/hd64465/hd64465var.h>
50 1.3.6.2 nathanw #include <hpcsh/dev/hd64465/hd64465reg.h>
51 1.3.6.2 nathanw #include <hpcsh/dev/hd64465/hd64465intcreg.h>
52 1.3.6.2 nathanw
53 1.3.6.2 nathanw /* HD64465 modules. */
54 1.3.6.2 nathanw STATIC const struct hd64465_module {
55 1.3.6.2 nathanw const char *name;
56 1.3.6.2 nathanw } hd64465_modules[] = {
57 1.3.6.2 nathanw [HD64465_MODULE_PS2IF] = { "hd64465ps2if" },
58 1.3.6.2 nathanw [HD64465_MODULE_PCMCIA] = { "hd64465pcmcia" },
59 1.3.6.2 nathanw [HD64465_MODULE_AFE] = { "hd64465afe" },
60 1.3.6.2 nathanw [HD64465_MODULE_GPIO] = { "hd64465gpio" },
61 1.3.6.2 nathanw [HD64465_MODULE_KBC] = { "hd64465kbc" },
62 1.3.6.2 nathanw [HD64465_MODULE_IRDA] = { "hd64465irda" },
63 1.3.6.2 nathanw [HD64465_MODULE_UART] = { "hd64465uart" },
64 1.3.6.2 nathanw [HD64465_MODULE_PARALEL] = { "hd64465paralel" },
65 1.3.6.2 nathanw [HD64465_MODULE_CODEC] = { "hd64465codec" },
66 1.3.6.2 nathanw [HD64465_MODULE_OHCI] = { "hd64465ohci" },
67 1.3.6.2 nathanw [HD64465_MODULE_ADC] = { "hd64465adc" }
68 1.3.6.2 nathanw };
69 1.3.6.2 nathanw #define HD64465_NMODULE \
70 1.3.6.2 nathanw (sizeof hd64465_modules / sizeof(struct hd64465_module))
71 1.3.6.2 nathanw
72 1.3.6.2 nathanw STATIC int hd64465_match(struct device *, struct cfdata *, void *);
73 1.3.6.2 nathanw STATIC void hd64465_attach(struct device *, struct device *, void *);
74 1.3.6.2 nathanw STATIC int hd64465_print(void *, const char *);
75 1.3.6.2 nathanw #ifdef DEBUG
76 1.3.6.2 nathanw STATIC void hd64465_info(void);
77 1.3.6.2 nathanw #endif
78 1.3.6.2 nathanw
79 1.3.6.2 nathanw CFATTACH_DECL(hd64465if, sizeof(struct device),
80 1.3.6.3 nathanw hd64465_match, hd64465_attach, NULL, NULL);
81 1.3.6.2 nathanw
82 1.3.6.2 nathanw int
83 1.3.6.2 nathanw hd64465_match(struct device *parent, struct cfdata *cf, void *aux)
84 1.3.6.2 nathanw {
85 1.3.6.2 nathanw
86 1.3.6.2 nathanw if (strcmp("hd64465if", cf->cf_name))
87 1.3.6.2 nathanw return (0);
88 1.3.6.2 nathanw
89 1.3.6.2 nathanw if (hd64465_reg_read_2(HD64465_SDIDR) != 0x8122) {
90 1.3.6.2 nathanw /* not HD64465 */
91 1.3.6.2 nathanw return (0);
92 1.3.6.2 nathanw }
93 1.3.6.2 nathanw
94 1.3.6.2 nathanw return (1);
95 1.3.6.2 nathanw }
96 1.3.6.2 nathanw
97 1.3.6.2 nathanw void
98 1.3.6.2 nathanw hd64465_attach(struct device *parent, struct device *self, void *aux)
99 1.3.6.2 nathanw {
100 1.3.6.2 nathanw const struct hd64465_module *module;
101 1.3.6.2 nathanw struct hd64465_attach_args ha;
102 1.3.6.2 nathanw u_int16_t r;
103 1.3.6.2 nathanw int i;
104 1.3.6.2 nathanw
105 1.3.6.2 nathanw printf("\n");
106 1.3.6.2 nathanw #ifdef DEBUG
107 1.3.6.2 nathanw if (bootverbose)
108 1.3.6.2 nathanw hd64465_info();
109 1.3.6.2 nathanw #endif
110 1.3.6.2 nathanw
111 1.3.6.2 nathanw r = hd64465_reg_read_2(HD64465_SRR);
112 1.3.6.2 nathanw printf("%s: HITACHI HD64465 rev. %d.%d\n", self->dv_xname,
113 1.3.6.2 nathanw (r >> 8) & 0xff, r & 0xff);
114 1.3.6.2 nathanw
115 1.3.6.2 nathanw /* Mask all interrupt */
116 1.3.6.2 nathanw hd64465_reg_write_2(HD64465_NIMR, 0xffff);
117 1.3.6.2 nathanw /* Edge trigger mode to clear pending interrupt. */
118 1.3.6.2 nathanw hd64465_reg_write_2(HD64465_NITR, 0xffff);
119 1.3.6.2 nathanw /* Clear pending interrupt */
120 1.3.6.2 nathanw hd64465_reg_write_2(HD64465_NIRR, 0x0000);
121 1.3.6.2 nathanw
122 1.3.6.2 nathanw /* Attach all sub modules */
123 1.3.6.2 nathanw for (i = 0, module = hd64465_modules; i < HD64465_NMODULE;
124 1.3.6.2 nathanw i++, module++) {
125 1.3.6.2 nathanw if (module->name == 0)
126 1.3.6.2 nathanw continue;
127 1.3.6.2 nathanw ha.ha_module_id = i;
128 1.3.6.2 nathanw config_found(self, &ha, hd64465_print);
129 1.3.6.2 nathanw }
130 1.3.6.2 nathanw }
131 1.3.6.2 nathanw
132 1.3.6.2 nathanw int
133 1.3.6.2 nathanw hd64465_print(void *aux, const char *pnp)
134 1.3.6.2 nathanw {
135 1.3.6.2 nathanw struct hd64465_attach_args *ha = aux;
136 1.3.6.2 nathanw
137 1.3.6.2 nathanw if (pnp)
138 1.3.6.2 nathanw printf("%s at %s", hd64465_modules[ha->ha_module_id].name, pnp);
139 1.3.6.2 nathanw
140 1.3.6.2 nathanw return (UNCONF);
141 1.3.6.2 nathanw }
142 1.3.6.2 nathanw
143 1.3.6.2 nathanw void *
144 1.3.6.2 nathanw hd64465_intr_establish(int irq, int mode, int level,
145 1.3.6.2 nathanw int (*func)(void *), void *arg)
146 1.3.6.2 nathanw {
147 1.3.6.2 nathanw u_int16_t r;
148 1.3.6.2 nathanw int s;
149 1.3.6.2 nathanw
150 1.3.6.2 nathanw s = splhigh();
151 1.3.6.2 nathanw /* Trigger type */
152 1.3.6.2 nathanw r = hd64465_reg_read_2(HD64465_NITR);
153 1.3.6.2 nathanw switch (mode) {
154 1.3.6.2 nathanw case IST_PULSE:
155 1.3.6.2 nathanw /* FALLTHROUGH */
156 1.3.6.2 nathanw case IST_EDGE:
157 1.3.6.2 nathanw r |= irq;
158 1.3.6.2 nathanw break;
159 1.3.6.2 nathanw case IST_LEVEL:
160 1.3.6.2 nathanw r &= ~irq;
161 1.3.6.2 nathanw break;
162 1.3.6.2 nathanw }
163 1.3.6.2 nathanw hd64465_reg_write_2(HD64465_NITR, r);
164 1.3.6.2 nathanw
165 1.3.6.2 nathanw hd6446x_intr_establish(irq, mode, level, func, arg);
166 1.3.6.2 nathanw splx(s);
167 1.3.6.2 nathanw
168 1.3.6.2 nathanw return (void *)irq;
169 1.3.6.2 nathanw }
170 1.3.6.2 nathanw
171 1.3.6.2 nathanw void
172 1.3.6.2 nathanw hd64465_intr_disestablish(void *handle)
173 1.3.6.2 nathanw {
174 1.3.6.2 nathanw
175 1.3.6.2 nathanw hd6446x_intr_disestablish(handle);
176 1.3.6.2 nathanw }
177 1.3.6.2 nathanw
178 1.3.6.2 nathanw /* For the sake of Windows CE reboot clearly. */
179 1.3.6.2 nathanw void
180 1.3.6.2 nathanw hd64465_shutdown()
181 1.3.6.2 nathanw {
182 1.3.6.2 nathanw
183 1.3.6.2 nathanw /* Enable all interrupt */
184 1.3.6.2 nathanw hd64465_reg_write_2(HD64465_NIMR, 0x0000);
185 1.3.6.2 nathanw
186 1.3.6.2 nathanw /* Level trigger mode */
187 1.3.6.2 nathanw hd64465_reg_write_2(HD64465_NITR, 0x0000);
188 1.3.6.2 nathanw }
189 1.3.6.2 nathanw
190 1.3.6.2 nathanw void
191 1.3.6.2 nathanw hd64465_info()
192 1.3.6.2 nathanw {
193 1.3.6.2 nathanw u_int16_t r;
194 1.3.6.2 nathanw
195 1.3.6.2 nathanw dbg_bit_print_msg(_reg_read_2(SH4_ICR), "SH4_ICR");
196 1.3.6.2 nathanw r = hd64465_reg_read_2(HD64465_NIMR);
197 1.3.6.2 nathanw dbg_bit_print_msg(r, "NIMR");
198 1.3.6.2 nathanw r = hd64465_reg_read_2(HD64465_NIRR);
199 1.3.6.2 nathanw dbg_bit_print_msg(r, "NIRR");
200 1.3.6.2 nathanw r = hd64465_reg_read_2(HD64465_NITR);
201 1.3.6.2 nathanw dbg_bit_print_msg(r, "NITR");
202 1.3.6.2 nathanw }
203