hd64465.c revision 1.14 1 1.14 matt /* $NetBSD: hd64465.c,v 1.14 2011/06/06 17:27:42 matt 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 *
19 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 uch * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 uch * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 uch * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 uch * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 uch * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 uch * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 uch * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 uch * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 uch * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 uch * POSSIBILITY OF SUCH DAMAGE.
30 1.1 uch */
31 1.10 lukem
32 1.10 lukem #include <sys/cdefs.h>
33 1.14 matt __KERNEL_RCSID(0, "$NetBSD: hd64465.c,v 1.14 2011/06/06 17:27:42 matt Exp $");
34 1.1 uch
35 1.1 uch #include <sys/param.h>
36 1.1 uch #include <sys/systm.h>
37 1.1 uch #include <sys/device.h>
38 1.1 uch #include <sys/boot_flag.h>
39 1.1 uch
40 1.1 uch #include <machine/bus.h>
41 1.1 uch #include <machine/intr.h>
42 1.1 uch #include <machine/debug.h>
43 1.1 uch
44 1.3 uch #include <sh3/intcreg.h>
45 1.1 uch #include <hpcsh/dev/hd64465/hd64465var.h>
46 1.1 uch #include <hpcsh/dev/hd64465/hd64465reg.h>
47 1.1 uch #include <hpcsh/dev/hd64465/hd64465intcreg.h>
48 1.1 uch
49 1.1 uch /* HD64465 modules. */
50 1.1 uch STATIC const struct hd64465_module {
51 1.1 uch const char *name;
52 1.1 uch } hd64465_modules[] = {
53 1.1 uch [HD64465_MODULE_PS2IF] = { "hd64465ps2if" },
54 1.1 uch [HD64465_MODULE_PCMCIA] = { "hd64465pcmcia" },
55 1.1 uch [HD64465_MODULE_AFE] = { "hd64465afe" },
56 1.1 uch [HD64465_MODULE_GPIO] = { "hd64465gpio" },
57 1.1 uch [HD64465_MODULE_KBC] = { "hd64465kbc" },
58 1.1 uch [HD64465_MODULE_IRDA] = { "hd64465irda" },
59 1.1 uch [HD64465_MODULE_UART] = { "hd64465uart" },
60 1.1 uch [HD64465_MODULE_PARALEL] = { "hd64465paralel" },
61 1.1 uch [HD64465_MODULE_CODEC] = { "hd64465codec" },
62 1.1 uch [HD64465_MODULE_OHCI] = { "hd64465ohci" },
63 1.1 uch [HD64465_MODULE_ADC] = { "hd64465adc" }
64 1.1 uch };
65 1.1 uch
66 1.14 matt STATIC int hd64465_match(device_t, cfdata_t, void *);
67 1.14 matt STATIC void hd64465_attach(device_t, device_t, void *);
68 1.1 uch STATIC int hd64465_print(void *, const char *);
69 1.3 uch #ifdef DEBUG
70 1.3 uch STATIC void hd64465_info(void);
71 1.3 uch #endif
72 1.1 uch
73 1.14 matt CFATTACH_DECL_NEW(hd64465if, 0,
74 1.8 uch hd64465_match, hd64465_attach, NULL, NULL);
75 1.1 uch
76 1.1 uch int
77 1.14 matt hd64465_match(device_t parent, cfdata_t cf, void *aux)
78 1.1 uch {
79 1.1 uch
80 1.4 thorpej if (strcmp("hd64465if", cf->cf_name))
81 1.1 uch return (0);
82 1.1 uch
83 1.1 uch if (hd64465_reg_read_2(HD64465_SDIDR) != 0x8122) {
84 1.1 uch /* not HD64465 */
85 1.1 uch return (0);
86 1.1 uch }
87 1.1 uch
88 1.1 uch return (1);
89 1.1 uch }
90 1.1 uch
91 1.1 uch void
92 1.14 matt hd64465_attach(device_t parent, device_t self, void *aux)
93 1.1 uch {
94 1.1 uch const struct hd64465_module *module;
95 1.1 uch struct hd64465_attach_args ha;
96 1.12 uwe uint16_t r;
97 1.14 matt size_t i;
98 1.1 uch
99 1.1 uch printf("\n");
100 1.3 uch #ifdef DEBUG
101 1.3 uch if (bootverbose)
102 1.3 uch hd64465_info();
103 1.3 uch #endif
104 1.1 uch
105 1.1 uch r = hd64465_reg_read_2(HD64465_SRR);
106 1.1 uch printf("%s: HITACHI HD64465 rev. %d.%d\n", self->dv_xname,
107 1.1 uch (r >> 8) & 0xff, r & 0xff);
108 1.1 uch
109 1.3 uch /* Mask all interrupt */
110 1.3 uch hd64465_reg_write_2(HD64465_NIMR, 0xffff);
111 1.3 uch /* Edge trigger mode to clear pending interrupt. */
112 1.3 uch hd64465_reg_write_2(HD64465_NITR, 0xffff);
113 1.3 uch /* Clear pending interrupt */
114 1.3 uch hd64465_reg_write_2(HD64465_NIRR, 0x0000);
115 1.1 uch
116 1.1 uch /* Attach all sub modules */
117 1.14 matt for (i = 0, module = hd64465_modules;
118 1.14 matt i < __arraycount(hd64465_modules);
119 1.1 uch i++, module++) {
120 1.1 uch if (module->name == 0)
121 1.1 uch continue;
122 1.1 uch ha.ha_module_id = i;
123 1.1 uch config_found(self, &ha, hd64465_print);
124 1.1 uch }
125 1.1 uch }
126 1.1 uch
127 1.1 uch int
128 1.1 uch hd64465_print(void *aux, const char *pnp)
129 1.1 uch {
130 1.1 uch struct hd64465_attach_args *ha = aux;
131 1.1 uch
132 1.1 uch if (pnp)
133 1.9 thorpej aprint_normal("%s at %s",
134 1.9 thorpej hd64465_modules[ha->ha_module_id].name, pnp);
135 1.1 uch
136 1.1 uch return (UNCONF);
137 1.1 uch }
138 1.1 uch
139 1.1 uch void *
140 1.3 uch hd64465_intr_establish(int irq, int mode, int level,
141 1.1 uch int (*func)(void *), void *arg)
142 1.1 uch {
143 1.12 uwe uint16_t r;
144 1.1 uch int s;
145 1.1 uch
146 1.1 uch s = splhigh();
147 1.1 uch /* Trigger type */
148 1.1 uch r = hd64465_reg_read_2(HD64465_NITR);
149 1.1 uch switch (mode) {
150 1.1 uch case IST_PULSE:
151 1.1 uch /* FALLTHROUGH */
152 1.1 uch case IST_EDGE:
153 1.3 uch r |= irq;
154 1.1 uch break;
155 1.1 uch case IST_LEVEL:
156 1.3 uch r &= ~irq;
157 1.1 uch break;
158 1.1 uch }
159 1.1 uch hd64465_reg_write_2(HD64465_NITR, r);
160 1.1 uch
161 1.3 uch hd6446x_intr_establish(irq, mode, level, func, arg);
162 1.1 uch splx(s);
163 1.1 uch
164 1.1 uch return (void *)irq;
165 1.1 uch }
166 1.1 uch
167 1.1 uch void
168 1.1 uch hd64465_intr_disestablish(void *handle)
169 1.1 uch {
170 1.1 uch
171 1.3 uch hd6446x_intr_disestablish(handle);
172 1.1 uch }
173 1.1 uch
174 1.3 uch /* For the sake of Windows CE reboot clearly. */
175 1.1 uch void
176 1.3 uch hd64465_shutdown()
177 1.1 uch {
178 1.1 uch
179 1.3 uch /* Enable all interrupt */
180 1.3 uch hd64465_reg_write_2(HD64465_NIMR, 0x0000);
181 1.1 uch
182 1.3 uch /* Level trigger mode */
183 1.3 uch hd64465_reg_write_2(HD64465_NITR, 0x0000);
184 1.1 uch }
185 1.1 uch
186 1.1 uch void
187 1.3 uch hd64465_info()
188 1.1 uch {
189 1.12 uwe uint16_t r;
190 1.1 uch
191 1.3 uch dbg_bit_print_msg(_reg_read_2(SH4_ICR), "SH4_ICR");
192 1.3 uch r = hd64465_reg_read_2(HD64465_NIMR);
193 1.3 uch dbg_bit_print_msg(r, "NIMR");
194 1.3 uch r = hd64465_reg_read_2(HD64465_NIRR);
195 1.3 uch dbg_bit_print_msg(r, "NIRR");
196 1.3 uch r = hd64465_reg_read_2(HD64465_NITR);
197 1.3 uch dbg_bit_print_msg(r, "NITR");
198 1.1 uch }
199