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