tx39io.c revision 1.9.8.4 1 1.9.8.4 nathanw /* $NetBSD: tx39io.c,v 1.9.8.4 2002/10/18 02:37:13 nathanw Exp $ */
2 1.9.8.2 nathanw
3 1.9.8.2 nathanw /*-
4 1.9.8.2 nathanw * Copyright (c) 1999-2001 The NetBSD Foundation, Inc.
5 1.9.8.2 nathanw * All rights reserved.
6 1.9.8.2 nathanw *
7 1.9.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.9.8.2 nathanw * by UCHIYAMA Yasushi.
9 1.9.8.2 nathanw *
10 1.9.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.9.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.9.8.2 nathanw * are met:
13 1.9.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.9.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.9.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.9.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.9.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.9.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.9.8.2 nathanw * must display the following acknowledgement:
20 1.9.8.2 nathanw * This product includes software developed by the NetBSD
21 1.9.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.9.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.9.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.9.8.2 nathanw * from this software without specific prior written permission.
25 1.9.8.2 nathanw *
26 1.9.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.9.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.9.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.9.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.9.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.9.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.9.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.9.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.9.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.9.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.9.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.9.8.2 nathanw */
38 1.9.8.2 nathanw
39 1.9.8.2 nathanw #include <sys/param.h>
40 1.9.8.2 nathanw #include <sys/systm.h>
41 1.9.8.2 nathanw #include <sys/device.h>
42 1.9.8.2 nathanw
43 1.9.8.2 nathanw #include <machine/bus.h>
44 1.9.8.2 nathanw
45 1.9.8.2 nathanw #include <hpcmips/tx/tx39var.h>
46 1.9.8.2 nathanw #include <hpcmips/tx/tx39icureg.h>
47 1.9.8.2 nathanw #define __TX39IO_PRIVATE
48 1.9.8.2 nathanw #include <hpcmips/tx/tx39iovar.h>
49 1.9.8.2 nathanw #include <hpcmips/tx/tx39ioreg.h>
50 1.9.8.2 nathanw
51 1.9.8.2 nathanw #ifdef TX39IO_DEBUG
52 1.9.8.2 nathanw #define DPRINTF_ENABLE
53 1.9.8.2 nathanw #define DPRINTF_DEBUG tx39io_debug
54 1.9.8.2 nathanw #endif
55 1.9.8.2 nathanw #include <machine/debug.h>
56 1.9.8.2 nathanw
57 1.9.8.2 nathanw #define ISSET(x, s) ((x) & (1 << (s)))
58 1.9.8.2 nathanw
59 1.9.8.2 nathanw int tx39io_match(struct device *, struct cfdata *, void *);
60 1.9.8.2 nathanw void tx39io_attach(struct device *, struct device *, void *);
61 1.9.8.2 nathanw
62 1.9.8.4 nathanw CFATTACH_DECL(tx39io, sizeof(struct tx39io_softc),
63 1.9.8.4 nathanw tx39io_match, tx39io_attach, NULL, NULL);
64 1.9.8.2 nathanw
65 1.9.8.2 nathanw /* IO/MFIO common */
66 1.9.8.2 nathanw static void port_intr_disestablish(hpcio_chip_t, hpcio_intr_handle_t);
67 1.9.8.2 nathanw static void port_intr_clear(hpcio_chip_t, hpcio_intr_handle_t);
68 1.9.8.2 nathanw /* MFIO */
69 1.9.8.2 nathanw static void *mfio_intr_establish(hpcio_chip_t, int, int, int (*)(void *),
70 1.9.8.2 nathanw void *);
71 1.9.8.2 nathanw static int mfio_in(hpcio_chip_t, int);
72 1.9.8.2 nathanw static void mfio_out(hpcio_chip_t, int, int);
73 1.9.8.2 nathanw static int mfio_intr_map(int *, int, int);
74 1.9.8.2 nathanw static void mfio_dump(hpcio_chip_t);
75 1.9.8.2 nathanw static void mfio_update(hpcio_chip_t);
76 1.9.8.2 nathanw /* IO */
77 1.9.8.2 nathanw static void *io_intr_establish(hpcio_chip_t, int, int, int (*)(void *),
78 1.9.8.2 nathanw void *);
79 1.9.8.2 nathanw #ifdef TX391X
80 1.9.8.2 nathanw static int tx391x_io_in(hpcio_chip_t, int);
81 1.9.8.2 nathanw static void tx391x_io_out(hpcio_chip_t, int, int);
82 1.9.8.2 nathanw static void tx391x_io_update(hpcio_chip_t);
83 1.9.8.2 nathanw static int tx391x_io_intr_map(int *, int, int);
84 1.9.8.2 nathanw #endif
85 1.9.8.2 nathanw #ifdef TX392X
86 1.9.8.2 nathanw static int tx392x_io_in(hpcio_chip_t, int);
87 1.9.8.2 nathanw static void tx392x_io_out(hpcio_chip_t, int, int);
88 1.9.8.2 nathanw static void tx392x_io_update(hpcio_chip_t);
89 1.9.8.2 nathanw static int tx392x_io_intr_map(int *, int, int);
90 1.9.8.2 nathanw #endif
91 1.9.8.2 nathanw #if defined TX391X && defined TX392X
92 1.9.8.2 nathanw #define tx39_io_intr_map(t, s, p, m) \
93 1.9.8.2 nathanw (IS_TX391X(t)
94 1.9.8.2 nathanw ? tx391x_io_intr_map(s, p, m) : tx392x_io_intr_map(s, p, m))
95 1.9.8.2 nathanw #elif defined TX391X
96 1.9.8.2 nathanw #define tx39io_intr_map(t, s, p, m) tx391x_io_intr_map(s, p, m)
97 1.9.8.2 nathanw #elif defined TX392X
98 1.9.8.2 nathanw #define tx39io_intr_map(t, s, p, m) tx392x_io_intr_map(s, p, m)
99 1.9.8.2 nathanw #endif
100 1.9.8.2 nathanw static void io_dump(hpcio_chip_t);
101 1.9.8.2 nathanw
102 1.9.8.2 nathanw static void __print_port_status(struct tx39io_port_status *, int);
103 1.9.8.2 nathanw
104 1.9.8.2 nathanw int
105 1.9.8.2 nathanw tx39io_match(struct device *parent, struct cfdata *cf, void *aux)
106 1.9.8.2 nathanw {
107 1.9.8.2 nathanw return (ATTACH_FIRST); /* 1st attach group of txsim */
108 1.9.8.2 nathanw }
109 1.9.8.2 nathanw
110 1.9.8.2 nathanw void
111 1.9.8.2 nathanw tx39io_attach(struct device *parent, struct device *self, void *aux)
112 1.9.8.2 nathanw {
113 1.9.8.2 nathanw struct txsim_attach_args *ta = aux;
114 1.9.8.2 nathanw struct tx39io_softc *sc = (void *)self;
115 1.9.8.2 nathanw tx_chipset_tag_t tc;
116 1.9.8.2 nathanw struct hpcio_chip *io_hc = &sc->sc_io_ops;
117 1.9.8.2 nathanw struct hpcio_chip *mfio_hc = &sc->sc_mfio_ops;
118 1.9.8.2 nathanw
119 1.9.8.2 nathanw tc = sc->sc_tc = ta->ta_tc;
120 1.9.8.2 nathanw
121 1.9.8.2 nathanw printf("\n");
122 1.9.8.2 nathanw sc->sc_stat_io_mask = ~(1 << 5); /* exclude Plum2 INT */
123 1.9.8.2 nathanw sc->sc_stat_mfio_mask = ~(0x3|(0x3 << 23));
124 1.9.8.2 nathanw
125 1.9.8.2 nathanw /* IO */
126 1.9.8.2 nathanw io_hc->hc_chipid = IO;
127 1.9.8.2 nathanw io_hc->hc_name = "IO";
128 1.9.8.2 nathanw io_hc->hc_sc = sc;
129 1.9.8.2 nathanw io_hc->hc_intr_establish = io_intr_establish;
130 1.9.8.2 nathanw io_hc->hc_intr_disestablish = port_intr_disestablish;
131 1.9.8.2 nathanw io_hc->hc_intr_clear = port_intr_clear;
132 1.9.8.2 nathanw io_hc->hc_dump = io_dump;
133 1.9.8.2 nathanw if (IS_TX391X(tc)) {
134 1.9.8.2 nathanw #ifdef TX391X
135 1.9.8.2 nathanw io_hc->hc_portread = tx391x_io_in;
136 1.9.8.2 nathanw io_hc->hc_portwrite = tx391x_io_out;
137 1.9.8.2 nathanw io_hc->hc_update = tx391x_io_update;
138 1.9.8.2 nathanw #endif
139 1.9.8.2 nathanw } else if (IS_TX392X(tc)) {
140 1.9.8.2 nathanw #ifdef TX392X
141 1.9.8.2 nathanw io_hc->hc_portread = tx392x_io_in;
142 1.9.8.2 nathanw io_hc->hc_portwrite = tx392x_io_out;
143 1.9.8.2 nathanw io_hc->hc_update = tx392x_io_update;
144 1.9.8.2 nathanw #endif
145 1.9.8.2 nathanw }
146 1.9.8.2 nathanw tx_conf_register_ioman(tc, io_hc);
147 1.9.8.2 nathanw
148 1.9.8.2 nathanw /* MFIO */
149 1.9.8.2 nathanw mfio_hc->hc_chipid = MFIO;
150 1.9.8.2 nathanw mfio_hc->hc_name = "MFIO";
151 1.9.8.2 nathanw mfio_hc->hc_sc = sc;
152 1.9.8.2 nathanw mfio_hc->hc_portread = mfio_in;
153 1.9.8.2 nathanw mfio_hc->hc_portwrite = mfio_out;
154 1.9.8.2 nathanw mfio_hc->hc_intr_establish = mfio_intr_establish;
155 1.9.8.2 nathanw mfio_hc->hc_intr_disestablish = port_intr_disestablish;
156 1.9.8.2 nathanw mfio_hc->hc_update = mfio_update;
157 1.9.8.2 nathanw mfio_hc->hc_dump = mfio_dump;
158 1.9.8.2 nathanw
159 1.9.8.2 nathanw tx_conf_register_ioman(tc, mfio_hc);
160 1.9.8.2 nathanw
161 1.9.8.2 nathanw hpcio_update(io_hc);
162 1.9.8.2 nathanw hpcio_update(mfio_hc);
163 1.9.8.2 nathanw
164 1.9.8.2 nathanw #ifdef TX39IO_DEBUG
165 1.9.8.2 nathanw hpcio_dump(io_hc);
166 1.9.8.2 nathanw hpcio_dump(mfio_hc);
167 1.9.8.2 nathanw printf("IO i0x%08x o0x%08x MFIO i0x%08x o0x%08x\n",
168 1.9.8.2 nathanw sc->sc_stat_io.in, sc->sc_stat_io.out,
169 1.9.8.2 nathanw sc->sc_stat_mfio.in, sc->sc_stat_mfio.out);
170 1.9.8.2 nathanw #endif /* TX39IO_DEBUG */
171 1.9.8.2 nathanw }
172 1.9.8.2 nathanw
173 1.9.8.2 nathanw /*
174 1.9.8.2 nathanw * TX391X, TX392X common
175 1.9.8.2 nathanw */
176 1.9.8.2 nathanw static void *
177 1.9.8.2 nathanw io_intr_establish(hpcio_chip_t arg, int port, int mode, int (*func)(void *),
178 1.9.8.2 nathanw void *func_arg)
179 1.9.8.2 nathanw {
180 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
181 1.9.8.2 nathanw int src;
182 1.9.8.2 nathanw
183 1.9.8.2 nathanw if (tx39io_intr_map(sc->sc_tc, &src, port, mode) != 0)
184 1.9.8.2 nathanw return (0);
185 1.9.8.2 nathanw
186 1.9.8.2 nathanw return (tx_intr_establish(sc->sc_tc, src, IST_EDGE, IPL_CLOCK, func,
187 1.9.8.2 nathanw func_arg));
188 1.9.8.2 nathanw }
189 1.9.8.2 nathanw
190 1.9.8.2 nathanw static void *
191 1.9.8.2 nathanw mfio_intr_establish(hpcio_chip_t arg, int port, int mode, int (*func)(void *),
192 1.9.8.2 nathanw void *func_arg)
193 1.9.8.2 nathanw {
194 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
195 1.9.8.2 nathanw int src;
196 1.9.8.2 nathanw
197 1.9.8.2 nathanw if (mfio_intr_map(&src, port, mode) != 0)
198 1.9.8.2 nathanw return (0);
199 1.9.8.2 nathanw
200 1.9.8.2 nathanw return (tx_intr_establish(sc->sc_tc, src, IST_EDGE, IPL_CLOCK, func,
201 1.9.8.2 nathanw func_arg));
202 1.9.8.2 nathanw }
203 1.9.8.2 nathanw
204 1.9.8.2 nathanw static void
205 1.9.8.2 nathanw port_intr_disestablish(hpcio_chip_t arg, void *ih)
206 1.9.8.2 nathanw {
207 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
208 1.9.8.2 nathanw tx_intr_disestablish(sc->sc_tc, ih);
209 1.9.8.2 nathanw }
210 1.9.8.2 nathanw
211 1.9.8.2 nathanw static void
212 1.9.8.2 nathanw port_intr_clear(hpcio_chip_t arg, void *ih)
213 1.9.8.2 nathanw {
214 1.9.8.2 nathanw }
215 1.9.8.2 nathanw
216 1.9.8.2 nathanw static void
217 1.9.8.2 nathanw mfio_out(hpcio_chip_t arg, int port, int onoff)
218 1.9.8.2 nathanw {
219 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
220 1.9.8.2 nathanw tx_chipset_tag_t tc;
221 1.9.8.2 nathanw txreg_t reg, pos;
222 1.9.8.2 nathanw
223 1.9.8.2 nathanw DPRINTF("port #%d\n", port);
224 1.9.8.2 nathanw tc = sc->sc_tc;
225 1.9.8.2 nathanw /* MFIO */
226 1.9.8.2 nathanw pos = 1 << port;
227 1.9.8.2 nathanw #ifdef DIAGNOSTIC
228 1.9.8.2 nathanw if (!(sc->sc_stat_mfio.dir & pos)) {
229 1.9.8.4 nathanw panic("%s: MFIO%d is not output port.",
230 1.9.8.2 nathanw sc->sc_dev.dv_xname, port);
231 1.9.8.2 nathanw }
232 1.9.8.2 nathanw #endif
233 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_IOMFIODATAOUT_REG);
234 1.9.8.2 nathanw if (onoff)
235 1.9.8.2 nathanw reg |= pos;
236 1.9.8.2 nathanw else
237 1.9.8.2 nathanw reg &= ~pos;
238 1.9.8.2 nathanw tx_conf_write(tc, TX39_IOMFIODATAOUT_REG, reg);
239 1.9.8.2 nathanw }
240 1.9.8.2 nathanw
241 1.9.8.2 nathanw static int
242 1.9.8.2 nathanw mfio_in(hpcio_chip_t arg, int port)
243 1.9.8.2 nathanw {
244 1.9.8.2 nathanw struct tx39io_softc *sc __attribute__((__unused__)) = arg->hc_sc ;
245 1.9.8.2 nathanw
246 1.9.8.2 nathanw DPRINTF("port #%d\n", port);
247 1.9.8.2 nathanw return (tx_conf_read(sc->sc_tc, TX39_IOMFIODATAIN_REG) & (1 << port));
248 1.9.8.2 nathanw }
249 1.9.8.2 nathanw
250 1.9.8.2 nathanw static int
251 1.9.8.2 nathanw mfio_intr_map(int *src, int port, int mode)
252 1.9.8.2 nathanw {
253 1.9.8.2 nathanw
254 1.9.8.2 nathanw if (mode & HPCIO_INTR_POSEDGE) {
255 1.9.8.2 nathanw *src = MAKEINTR(3, (1 << port));
256 1.9.8.2 nathanw return (0);
257 1.9.8.2 nathanw } else if (mode & HPCIO_INTR_NEGEDGE) {
258 1.9.8.2 nathanw *src = MAKEINTR(4, (1 << port));
259 1.9.8.2 nathanw return (0);
260 1.9.8.2 nathanw }
261 1.9.8.2 nathanw
262 1.9.8.2 nathanw DPRINTF("invalid interrupt mode.\n");
263 1.9.8.2 nathanw
264 1.9.8.2 nathanw return (1);
265 1.9.8.2 nathanw }
266 1.9.8.2 nathanw
267 1.9.8.2 nathanw static void
268 1.9.8.2 nathanw mfio_update(hpcio_chip_t arg)
269 1.9.8.2 nathanw {
270 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
271 1.9.8.2 nathanw tx_chipset_tag_t tc = sc->sc_tc;
272 1.9.8.2 nathanw struct tx39io_port_status *stat_mfio = &sc->sc_stat_mfio;
273 1.9.8.2 nathanw
274 1.9.8.2 nathanw sc->sc_ostat_mfio = *stat_mfio; /* save old status */
275 1.9.8.2 nathanw stat_mfio->dir = tx_conf_read(tc, TX39_IOMFIODATADIR_REG);
276 1.9.8.2 nathanw stat_mfio->in = tx_conf_read(tc, TX39_IOMFIODATAIN_REG);
277 1.9.8.2 nathanw stat_mfio->out = tx_conf_read(tc, TX39_IOMFIODATAOUT_REG);
278 1.9.8.2 nathanw stat_mfio->power = tx_conf_read(tc, TX39_IOMFIOPOWERDWN_REG);
279 1.9.8.2 nathanw stat_mfio->u.select = tx_conf_read(tc, TX39_IOMFIODATASEL_REG);
280 1.9.8.2 nathanw }
281 1.9.8.2 nathanw
282 1.9.8.2 nathanw #ifdef TX391X
283 1.9.8.2 nathanw /*
284 1.9.8.2 nathanw * TMPR3912 specific
285 1.9.8.2 nathanw */
286 1.9.8.2 nathanw int
287 1.9.8.2 nathanw tx391x_io_in(hpcio_chip_t arg, int port)
288 1.9.8.2 nathanw {
289 1.9.8.2 nathanw struct tx39io_softc *sc __attribute__((__unused__)) = arg->hc_sc;
290 1.9.8.2 nathanw txreg_t reg = tx_conf_read(sc->sc_tc, TX39_IOCTRL_REG);
291 1.9.8.2 nathanw
292 1.9.8.2 nathanw DPRINTF("port #%d\n", port);
293 1.9.8.2 nathanw return (TX391X_IOCTRL_IODIN(reg) & (1 << port));
294 1.9.8.2 nathanw }
295 1.9.8.2 nathanw
296 1.9.8.2 nathanw void
297 1.9.8.2 nathanw tx391x_io_out(hpcio_chip_t arg, int port, int onoff)
298 1.9.8.2 nathanw {
299 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
300 1.9.8.2 nathanw tx_chipset_tag_t tc;
301 1.9.8.2 nathanw txreg_t reg, pos, iostat;
302 1.9.8.2 nathanw
303 1.9.8.2 nathanw KASSERT(sc);
304 1.9.8.2 nathanw DPRINTF("port #%d\n", port);
305 1.9.8.2 nathanw
306 1.9.8.2 nathanw tc = sc->sc_tc;
307 1.9.8.2 nathanw
308 1.9.8.2 nathanw /* IO [0:6] */
309 1.9.8.2 nathanw pos = 1 << port;
310 1.9.8.2 nathanw #ifdef DIAGNOSTIC
311 1.9.8.2 nathanw if (!(sc->sc_stat_io.dir & pos))
312 1.9.8.4 nathanw panic("%s: IO%d is not output port.", sc->sc_dev.dv_xname,
313 1.9.8.2 nathanw port);
314 1.9.8.2 nathanw #endif
315 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_IOCTRL_REG);
316 1.9.8.2 nathanw iostat = TX391X_IOCTRL_IODOUT(reg);
317 1.9.8.2 nathanw if (onoff)
318 1.9.8.2 nathanw iostat |= pos;
319 1.9.8.2 nathanw else
320 1.9.8.2 nathanw iostat &= ~pos;
321 1.9.8.2 nathanw TX391X_IOCTRL_IODOUT_CLR(reg);
322 1.9.8.2 nathanw reg = TX391X_IOCTRL_IODOUT_SET(reg, iostat);
323 1.9.8.2 nathanw tx_conf_write(tc, TX39_IOCTRL_REG, reg);
324 1.9.8.2 nathanw }
325 1.9.8.2 nathanw
326 1.9.8.2 nathanw void
327 1.9.8.2 nathanw tx391x_io_update(hpcio_chip_t arg)
328 1.9.8.2 nathanw {
329 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
330 1.9.8.2 nathanw struct tx39io_port_status *stat_io = &sc->sc_stat_io;
331 1.9.8.2 nathanw tx_chipset_tag_t tc = sc->sc_tc;
332 1.9.8.2 nathanw txreg_t reg;
333 1.9.8.2 nathanw
334 1.9.8.2 nathanw /* IO [0:6] */
335 1.9.8.2 nathanw sc->sc_ostat_io = *stat_io; /* save old status */
336 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_IOCTRL_REG);
337 1.9.8.2 nathanw stat_io->dir = TX391X_IOCTRL_IODIREC(reg);
338 1.9.8.2 nathanw stat_io->in = TX391X_IOCTRL_IODIN(reg);
339 1.9.8.2 nathanw stat_io->out = TX391X_IOCTRL_IODOUT(reg);
340 1.9.8.2 nathanw stat_io->u.debounce = TX391X_IOCTRL_IODEBSEL(reg);
341 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_IOIOPOWERDWN_REG);
342 1.9.8.2 nathanw stat_io->power = TX391X_IOIOPOWERDWN_IOPD(reg);
343 1.9.8.2 nathanw }
344 1.9.8.2 nathanw
345 1.9.8.2 nathanw int
346 1.9.8.2 nathanw tx391x_io_intr_map(int *src, int port, int mode)
347 1.9.8.2 nathanw {
348 1.9.8.2 nathanw
349 1.9.8.2 nathanw if (mode & HPCIO_INTR_POSEDGE) {
350 1.9.8.2 nathanw *src = MAKEINTR(5, (1 << (port + 7)));
351 1.9.8.2 nathanw return (0);
352 1.9.8.2 nathanw } else if (mode & HPCIO_INTR_NEGEDGE) {
353 1.9.8.2 nathanw *src = MAKEINTR(5, (1 << port));
354 1.9.8.2 nathanw return (0);
355 1.9.8.2 nathanw }
356 1.9.8.2 nathanw
357 1.9.8.2 nathanw DPRINTF("invalid interrupt mode.\n");
358 1.9.8.2 nathanw
359 1.9.8.2 nathanw return (1);
360 1.9.8.2 nathanw }
361 1.9.8.2 nathanw #endif /* TX391X */
362 1.9.8.2 nathanw
363 1.9.8.2 nathanw #ifdef TX392X
364 1.9.8.2 nathanw /*
365 1.9.8.2 nathanw * TMPR3922 specific
366 1.9.8.2 nathanw */
367 1.9.8.2 nathanw int
368 1.9.8.2 nathanw tx392x_io_in(hpcio_chip_t arg, int port)
369 1.9.8.2 nathanw {
370 1.9.8.2 nathanw struct tx39io_softc *sc __attribute__((__unused__)) = arg->hc_sc;
371 1.9.8.2 nathanw txreg_t reg = tx_conf_read(sc->sc_tc, TX392X_IODATAINOUT_REG);
372 1.9.8.2 nathanw
373 1.9.8.2 nathanw DPRINTF("port #%d\n", port);
374 1.9.8.2 nathanw
375 1.9.8.2 nathanw return (TX392X_IODATAINOUT_DIN(reg) & (1 << port));
376 1.9.8.2 nathanw }
377 1.9.8.2 nathanw
378 1.9.8.2 nathanw void
379 1.9.8.2 nathanw tx392x_io_out(hpcio_chip_t arg, int port, int onoff)
380 1.9.8.2 nathanw {
381 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
382 1.9.8.2 nathanw #ifdef DIAGNOSTIC
383 1.9.8.2 nathanw const char *devname = sc->sc_dev.dv_xname;
384 1.9.8.2 nathanw #endif
385 1.9.8.2 nathanw tx_chipset_tag_t tc = sc->sc_tc;
386 1.9.8.2 nathanw txreg_t reg, pos, iostat;
387 1.9.8.2 nathanw
388 1.9.8.2 nathanw DPRINTF("port #%d\n", port);
389 1.9.8.2 nathanw /* IO [0:15] */
390 1.9.8.2 nathanw pos = 1 << port;
391 1.9.8.2 nathanw #ifdef DIAGNOSTIC
392 1.9.8.3 nathanw if (!(sc->sc_stat_io.dir & pos))
393 1.9.8.4 nathanw panic("%s: IO%d is not output port.", devname, port);
394 1.9.8.2 nathanw #endif
395 1.9.8.2 nathanw reg = tx_conf_read(tc, TX392X_IODATAINOUT_REG);
396 1.9.8.2 nathanw iostat = TX392X_IODATAINOUT_DOUT(reg);
397 1.9.8.2 nathanw if (onoff)
398 1.9.8.2 nathanw iostat |= pos;
399 1.9.8.2 nathanw else
400 1.9.8.2 nathanw iostat &= ~pos;
401 1.9.8.2 nathanw TX392X_IODATAINOUT_DOUT_CLR(reg);
402 1.9.8.2 nathanw reg = TX392X_IODATAINOUT_DOUT_SET(reg, iostat);
403 1.9.8.2 nathanw tx_conf_write(tc, TX392X_IODATAINOUT_REG, reg);
404 1.9.8.2 nathanw }
405 1.9.8.2 nathanw
406 1.9.8.2 nathanw int
407 1.9.8.2 nathanw tx392x_io_intr_map(int *src, int port, int mode)
408 1.9.8.2 nathanw {
409 1.9.8.2 nathanw
410 1.9.8.2 nathanw if (mode & HPCIO_INTR_POSEDGE) {
411 1.9.8.2 nathanw *src = MAKEINTR(8, (1 << (port + 16)));
412 1.9.8.2 nathanw return (0);
413 1.9.8.2 nathanw } else if (mode & HPCIO_INTR_NEGEDGE) {
414 1.9.8.2 nathanw *src = MAKEINTR(8, (1 << port));
415 1.9.8.2 nathanw return (0);
416 1.9.8.2 nathanw }
417 1.9.8.2 nathanw
418 1.9.8.2 nathanw DPRINTF("invalid interrupt mode.\n");
419 1.9.8.2 nathanw
420 1.9.8.2 nathanw return (1);
421 1.9.8.2 nathanw }
422 1.9.8.2 nathanw
423 1.9.8.2 nathanw void
424 1.9.8.2 nathanw tx392x_io_update(hpcio_chip_t arg)
425 1.9.8.2 nathanw {
426 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
427 1.9.8.2 nathanw struct tx39io_port_status *stat_io = &sc->sc_stat_io;
428 1.9.8.2 nathanw tx_chipset_tag_t tc = sc->sc_tc;
429 1.9.8.2 nathanw txreg_t reg;
430 1.9.8.2 nathanw
431 1.9.8.2 nathanw sc->sc_ostat_io = *stat_io; /* save old status */
432 1.9.8.2 nathanw /* IO [0:15] */
433 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_IOCTRL_REG);
434 1.9.8.2 nathanw stat_io->dir = TX392X_IOCTRL_IODIREC(reg);
435 1.9.8.2 nathanw stat_io->u.debounce = TX392X_IOCTRL_IODEBSEL(reg);
436 1.9.8.2 nathanw reg = tx_conf_read(tc, TX392X_IODATAINOUT_REG);
437 1.9.8.2 nathanw stat_io->in = TX392X_IODATAINOUT_DIN(reg);
438 1.9.8.2 nathanw stat_io->out = TX392X_IODATAINOUT_DOUT(reg);
439 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_IOIOPOWERDWN_REG);
440 1.9.8.2 nathanw stat_io->power = TX392X_IOIOPOWERDWN_IOPD(reg);
441 1.9.8.2 nathanw }
442 1.9.8.2 nathanw
443 1.9.8.2 nathanw #endif /* TX392X */
444 1.9.8.2 nathanw
445 1.9.8.2 nathanw static const char *line = "--------------------------------------------------"
446 1.9.8.2 nathanw "------------\n";
447 1.9.8.2 nathanw static void
448 1.9.8.2 nathanw mfio_dump(hpcio_chip_t arg)
449 1.9.8.2 nathanw {
450 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
451 1.9.8.2 nathanw const struct tx39io_mfio_map *map = tx39io_get_mfio_map(tc);
452 1.9.8.2 nathanw struct tx39io_port_status *stat;
453 1.9.8.2 nathanw int i;
454 1.9.8.2 nathanw
455 1.9.8.2 nathanw printf("%s", line);
456 1.9.8.2 nathanw stat = &sc->sc_stat_mfio;
457 1.9.8.2 nathanw for (i = TX39_IO_MFIO_MAX - 1; i >= 0 ; i--) {
458 1.9.8.2 nathanw /* MFIO port has power down state */
459 1.9.8.2 nathanw printf("MFIO %2d: - ", i);
460 1.9.8.2 nathanw __print_port_status(stat, i);
461 1.9.8.2 nathanw printf(ISSET(stat->u.select, i) ? " MFIO(%s)\n" : " %s\n",
462 1.9.8.2 nathanw map[i].std_pin_name);
463 1.9.8.2 nathanw }
464 1.9.8.2 nathanw printf("%s", line);
465 1.9.8.2 nathanw }
466 1.9.8.2 nathanw
467 1.9.8.2 nathanw static void
468 1.9.8.2 nathanw io_dump(hpcio_chip_t arg)
469 1.9.8.2 nathanw {
470 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
471 1.9.8.2 nathanw struct tx39io_port_status *stat;
472 1.9.8.2 nathanw int i;
473 1.9.8.2 nathanw
474 1.9.8.2 nathanw printf("%s Debounce Direction DataOut DataIn PowerDown Select"
475 1.9.8.2 nathanw "\n%s", line, line);
476 1.9.8.2 nathanw stat = &sc->sc_stat_io;
477 1.9.8.2 nathanw for (i = tx39io_get_io_max(tc) - 1; i >= 0 ; i--) {
478 1.9.8.2 nathanw /* IO port has debouncer */
479 1.9.8.2 nathanw printf("IO %2d: %s ", i,
480 1.9.8.2 nathanw ISSET(stat->u.debounce, i) ? "On " : "Off");
481 1.9.8.2 nathanw __print_port_status(stat, i);
482 1.9.8.2 nathanw printf(" -\n");
483 1.9.8.2 nathanw }
484 1.9.8.2 nathanw }
485 1.9.8.2 nathanw
486 1.9.8.2 nathanw static void
487 1.9.8.2 nathanw __print_port_status(struct tx39io_port_status *stat, int i)
488 1.9.8.2 nathanw {
489 1.9.8.2 nathanw printf("%s %d %d %s",
490 1.9.8.2 nathanw ISSET(stat->dir, i) ? "Out" : "In ",
491 1.9.8.2 nathanw ISSET(stat->out, i) ? 1 : 0,
492 1.9.8.2 nathanw ISSET(stat->in, i) ? 1 : 0,
493 1.9.8.2 nathanw ISSET(stat->power, i) ? "Down ": "Active");
494 1.9.8.2 nathanw }
495