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