tx39io.c revision 1.9.8.2 1 1.9.8.2 nathanw /* $NetBSD: tx39io.c,v 1.9.8.2 2002/02/28 04:10:02 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.2 nathanw struct cfattach tx39io_ca = {
63 1.9.8.2 nathanw sizeof(struct tx39io_softc), tx39io_match, tx39io_attach
64 1.9.8.2 nathanw };
65 1.9.8.2 nathanw
66 1.9.8.2 nathanw /* IO/MFIO common */
67 1.9.8.2 nathanw static void port_intr_disestablish(hpcio_chip_t, hpcio_intr_handle_t);
68 1.9.8.2 nathanw static void port_intr_clear(hpcio_chip_t, hpcio_intr_handle_t);
69 1.9.8.2 nathanw /* MFIO */
70 1.9.8.2 nathanw static void *mfio_intr_establish(hpcio_chip_t, int, int, int (*)(void *),
71 1.9.8.2 nathanw void *);
72 1.9.8.2 nathanw static int mfio_in(hpcio_chip_t, int);
73 1.9.8.2 nathanw static void mfio_out(hpcio_chip_t, int, int);
74 1.9.8.2 nathanw static int mfio_intr_map(int *, int, int);
75 1.9.8.2 nathanw static void mfio_dump(hpcio_chip_t);
76 1.9.8.2 nathanw static void mfio_update(hpcio_chip_t);
77 1.9.8.2 nathanw /* IO */
78 1.9.8.2 nathanw static void *io_intr_establish(hpcio_chip_t, int, int, int (*)(void *),
79 1.9.8.2 nathanw void *);
80 1.9.8.2 nathanw #ifdef TX391X
81 1.9.8.2 nathanw static int tx391x_io_in(hpcio_chip_t, int);
82 1.9.8.2 nathanw static void tx391x_io_out(hpcio_chip_t, int, int);
83 1.9.8.2 nathanw static void tx391x_io_update(hpcio_chip_t);
84 1.9.8.2 nathanw static int tx391x_io_intr_map(int *, int, int);
85 1.9.8.2 nathanw #endif
86 1.9.8.2 nathanw #ifdef TX392X
87 1.9.8.2 nathanw static int tx392x_io_in(hpcio_chip_t, int);
88 1.9.8.2 nathanw static void tx392x_io_out(hpcio_chip_t, int, int);
89 1.9.8.2 nathanw static void tx392x_io_update(hpcio_chip_t);
90 1.9.8.2 nathanw static int tx392x_io_intr_map(int *, int, int);
91 1.9.8.2 nathanw #endif
92 1.9.8.2 nathanw #if defined TX391X && defined TX392X
93 1.9.8.2 nathanw #define tx39_io_intr_map(t, s, p, m) \
94 1.9.8.2 nathanw (IS_TX391X(t)
95 1.9.8.2 nathanw ? tx391x_io_intr_map(s, p, m) : tx392x_io_intr_map(s, p, m))
96 1.9.8.2 nathanw #elif defined TX391X
97 1.9.8.2 nathanw #define tx39io_intr_map(t, s, p, m) tx391x_io_intr_map(s, p, m)
98 1.9.8.2 nathanw #elif defined TX392X
99 1.9.8.2 nathanw #define tx39io_intr_map(t, s, p, m) tx392x_io_intr_map(s, p, m)
100 1.9.8.2 nathanw #endif
101 1.9.8.2 nathanw static void io_dump(hpcio_chip_t);
102 1.9.8.2 nathanw
103 1.9.8.2 nathanw static void __print_port_status(struct tx39io_port_status *, int);
104 1.9.8.2 nathanw
105 1.9.8.2 nathanw int
106 1.9.8.2 nathanw tx39io_match(struct device *parent, struct cfdata *cf, void *aux)
107 1.9.8.2 nathanw {
108 1.9.8.2 nathanw return (ATTACH_FIRST); /* 1st attach group of txsim */
109 1.9.8.2 nathanw }
110 1.9.8.2 nathanw
111 1.9.8.2 nathanw void
112 1.9.8.2 nathanw tx39io_attach(struct device *parent, struct device *self, void *aux)
113 1.9.8.2 nathanw {
114 1.9.8.2 nathanw struct txsim_attach_args *ta = aux;
115 1.9.8.2 nathanw struct tx39io_softc *sc = (void *)self;
116 1.9.8.2 nathanw tx_chipset_tag_t tc;
117 1.9.8.2 nathanw struct hpcio_chip *io_hc = &sc->sc_io_ops;
118 1.9.8.2 nathanw struct hpcio_chip *mfio_hc = &sc->sc_mfio_ops;
119 1.9.8.2 nathanw
120 1.9.8.2 nathanw tc = sc->sc_tc = ta->ta_tc;
121 1.9.8.2 nathanw
122 1.9.8.2 nathanw printf("\n");
123 1.9.8.2 nathanw sc->sc_stat_io_mask = ~(1 << 5); /* exclude Plum2 INT */
124 1.9.8.2 nathanw sc->sc_stat_mfio_mask = ~(0x3|(0x3 << 23));
125 1.9.8.2 nathanw
126 1.9.8.2 nathanw /* IO */
127 1.9.8.2 nathanw io_hc->hc_chipid = IO;
128 1.9.8.2 nathanw io_hc->hc_name = "IO";
129 1.9.8.2 nathanw io_hc->hc_sc = sc;
130 1.9.8.2 nathanw io_hc->hc_intr_establish = io_intr_establish;
131 1.9.8.2 nathanw io_hc->hc_intr_disestablish = port_intr_disestablish;
132 1.9.8.2 nathanw io_hc->hc_intr_clear = port_intr_clear;
133 1.9.8.2 nathanw io_hc->hc_dump = io_dump;
134 1.9.8.2 nathanw if (IS_TX391X(tc)) {
135 1.9.8.2 nathanw #ifdef TX391X
136 1.9.8.2 nathanw io_hc->hc_portread = tx391x_io_in;
137 1.9.8.2 nathanw io_hc->hc_portwrite = tx391x_io_out;
138 1.9.8.2 nathanw io_hc->hc_update = tx391x_io_update;
139 1.9.8.2 nathanw #endif
140 1.9.8.2 nathanw } else if (IS_TX392X(tc)) {
141 1.9.8.2 nathanw #ifdef TX392X
142 1.9.8.2 nathanw io_hc->hc_portread = tx392x_io_in;
143 1.9.8.2 nathanw io_hc->hc_portwrite = tx392x_io_out;
144 1.9.8.2 nathanw io_hc->hc_update = tx392x_io_update;
145 1.9.8.2 nathanw #endif
146 1.9.8.2 nathanw }
147 1.9.8.2 nathanw tx_conf_register_ioman(tc, io_hc);
148 1.9.8.2 nathanw
149 1.9.8.2 nathanw /* MFIO */
150 1.9.8.2 nathanw mfio_hc->hc_chipid = MFIO;
151 1.9.8.2 nathanw mfio_hc->hc_name = "MFIO";
152 1.9.8.2 nathanw mfio_hc->hc_sc = sc;
153 1.9.8.2 nathanw mfio_hc->hc_portread = mfio_in;
154 1.9.8.2 nathanw mfio_hc->hc_portwrite = mfio_out;
155 1.9.8.2 nathanw mfio_hc->hc_intr_establish = mfio_intr_establish;
156 1.9.8.2 nathanw mfio_hc->hc_intr_disestablish = port_intr_disestablish;
157 1.9.8.2 nathanw mfio_hc->hc_update = mfio_update;
158 1.9.8.2 nathanw mfio_hc->hc_dump = mfio_dump;
159 1.9.8.2 nathanw
160 1.9.8.2 nathanw tx_conf_register_ioman(tc, mfio_hc);
161 1.9.8.2 nathanw
162 1.9.8.2 nathanw hpcio_update(io_hc);
163 1.9.8.2 nathanw hpcio_update(mfio_hc);
164 1.9.8.2 nathanw
165 1.9.8.2 nathanw #ifdef TX39IO_DEBUG
166 1.9.8.2 nathanw hpcio_dump(io_hc);
167 1.9.8.2 nathanw hpcio_dump(mfio_hc);
168 1.9.8.2 nathanw printf("IO i0x%08x o0x%08x MFIO i0x%08x o0x%08x\n",
169 1.9.8.2 nathanw sc->sc_stat_io.in, sc->sc_stat_io.out,
170 1.9.8.2 nathanw sc->sc_stat_mfio.in, sc->sc_stat_mfio.out);
171 1.9.8.2 nathanw #endif /* TX39IO_DEBUG */
172 1.9.8.2 nathanw }
173 1.9.8.2 nathanw
174 1.9.8.2 nathanw /*
175 1.9.8.2 nathanw * TX391X, TX392X common
176 1.9.8.2 nathanw */
177 1.9.8.2 nathanw static void *
178 1.9.8.2 nathanw io_intr_establish(hpcio_chip_t arg, int port, int mode, int (*func)(void *),
179 1.9.8.2 nathanw void *func_arg)
180 1.9.8.2 nathanw {
181 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
182 1.9.8.2 nathanw int src;
183 1.9.8.2 nathanw
184 1.9.8.2 nathanw if (tx39io_intr_map(sc->sc_tc, &src, port, mode) != 0)
185 1.9.8.2 nathanw return (0);
186 1.9.8.2 nathanw
187 1.9.8.2 nathanw return (tx_intr_establish(sc->sc_tc, src, IST_EDGE, IPL_CLOCK, func,
188 1.9.8.2 nathanw func_arg));
189 1.9.8.2 nathanw }
190 1.9.8.2 nathanw
191 1.9.8.2 nathanw static void *
192 1.9.8.2 nathanw mfio_intr_establish(hpcio_chip_t arg, int port, int mode, int (*func)(void *),
193 1.9.8.2 nathanw void *func_arg)
194 1.9.8.2 nathanw {
195 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
196 1.9.8.2 nathanw int src;
197 1.9.8.2 nathanw
198 1.9.8.2 nathanw if (mfio_intr_map(&src, port, mode) != 0)
199 1.9.8.2 nathanw return (0);
200 1.9.8.2 nathanw
201 1.9.8.2 nathanw return (tx_intr_establish(sc->sc_tc, src, IST_EDGE, IPL_CLOCK, func,
202 1.9.8.2 nathanw func_arg));
203 1.9.8.2 nathanw }
204 1.9.8.2 nathanw
205 1.9.8.2 nathanw static void
206 1.9.8.2 nathanw port_intr_disestablish(hpcio_chip_t arg, void *ih)
207 1.9.8.2 nathanw {
208 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
209 1.9.8.2 nathanw tx_intr_disestablish(sc->sc_tc, ih);
210 1.9.8.2 nathanw }
211 1.9.8.2 nathanw
212 1.9.8.2 nathanw static void
213 1.9.8.2 nathanw port_intr_clear(hpcio_chip_t arg, void *ih)
214 1.9.8.2 nathanw {
215 1.9.8.2 nathanw }
216 1.9.8.2 nathanw
217 1.9.8.2 nathanw static void
218 1.9.8.2 nathanw mfio_out(hpcio_chip_t arg, int port, int onoff)
219 1.9.8.2 nathanw {
220 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
221 1.9.8.2 nathanw tx_chipset_tag_t tc;
222 1.9.8.2 nathanw txreg_t reg, pos;
223 1.9.8.2 nathanw
224 1.9.8.2 nathanw DPRINTF("port #%d\n", port);
225 1.9.8.2 nathanw tc = sc->sc_tc;
226 1.9.8.2 nathanw /* MFIO */
227 1.9.8.2 nathanw pos = 1 << port;
228 1.9.8.2 nathanw #ifdef DIAGNOSTIC
229 1.9.8.2 nathanw if (!(sc->sc_stat_mfio.dir & pos)) {
230 1.9.8.2 nathanw panic("%s: MFIO%d is not output port.\n",
231 1.9.8.2 nathanw sc->sc_dev.dv_xname, port);
232 1.9.8.2 nathanw }
233 1.9.8.2 nathanw #endif
234 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_IOMFIODATAOUT_REG);
235 1.9.8.2 nathanw if (onoff)
236 1.9.8.2 nathanw reg |= pos;
237 1.9.8.2 nathanw else
238 1.9.8.2 nathanw reg &= ~pos;
239 1.9.8.2 nathanw tx_conf_write(tc, TX39_IOMFIODATAOUT_REG, reg);
240 1.9.8.2 nathanw }
241 1.9.8.2 nathanw
242 1.9.8.2 nathanw static int
243 1.9.8.2 nathanw mfio_in(hpcio_chip_t arg, int port)
244 1.9.8.2 nathanw {
245 1.9.8.2 nathanw struct tx39io_softc *sc __attribute__((__unused__)) = arg->hc_sc ;
246 1.9.8.2 nathanw
247 1.9.8.2 nathanw DPRINTF("port #%d\n", port);
248 1.9.8.2 nathanw return (tx_conf_read(sc->sc_tc, TX39_IOMFIODATAIN_REG) & (1 << port));
249 1.9.8.2 nathanw }
250 1.9.8.2 nathanw
251 1.9.8.2 nathanw static int
252 1.9.8.2 nathanw mfio_intr_map(int *src, int port, int mode)
253 1.9.8.2 nathanw {
254 1.9.8.2 nathanw
255 1.9.8.2 nathanw if (mode & HPCIO_INTR_POSEDGE) {
256 1.9.8.2 nathanw *src = MAKEINTR(3, (1 << port));
257 1.9.8.2 nathanw return (0);
258 1.9.8.2 nathanw } else if (mode & HPCIO_INTR_NEGEDGE) {
259 1.9.8.2 nathanw *src = MAKEINTR(4, (1 << port));
260 1.9.8.2 nathanw return (0);
261 1.9.8.2 nathanw }
262 1.9.8.2 nathanw
263 1.9.8.2 nathanw DPRINTF("invalid interrupt mode.\n");
264 1.9.8.2 nathanw
265 1.9.8.2 nathanw return (1);
266 1.9.8.2 nathanw }
267 1.9.8.2 nathanw
268 1.9.8.2 nathanw static void
269 1.9.8.2 nathanw mfio_update(hpcio_chip_t arg)
270 1.9.8.2 nathanw {
271 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
272 1.9.8.2 nathanw tx_chipset_tag_t tc = sc->sc_tc;
273 1.9.8.2 nathanw struct tx39io_port_status *stat_mfio = &sc->sc_stat_mfio;
274 1.9.8.2 nathanw
275 1.9.8.2 nathanw sc->sc_ostat_mfio = *stat_mfio; /* save old status */
276 1.9.8.2 nathanw stat_mfio->dir = tx_conf_read(tc, TX39_IOMFIODATADIR_REG);
277 1.9.8.2 nathanw stat_mfio->in = tx_conf_read(tc, TX39_IOMFIODATAIN_REG);
278 1.9.8.2 nathanw stat_mfio->out = tx_conf_read(tc, TX39_IOMFIODATAOUT_REG);
279 1.9.8.2 nathanw stat_mfio->power = tx_conf_read(tc, TX39_IOMFIOPOWERDWN_REG);
280 1.9.8.2 nathanw stat_mfio->u.select = tx_conf_read(tc, TX39_IOMFIODATASEL_REG);
281 1.9.8.2 nathanw }
282 1.9.8.2 nathanw
283 1.9.8.2 nathanw #ifdef TX391X
284 1.9.8.2 nathanw /*
285 1.9.8.2 nathanw * TMPR3912 specific
286 1.9.8.2 nathanw */
287 1.9.8.2 nathanw int
288 1.9.8.2 nathanw tx391x_io_in(hpcio_chip_t arg, int port)
289 1.9.8.2 nathanw {
290 1.9.8.2 nathanw struct tx39io_softc *sc __attribute__((__unused__)) = arg->hc_sc;
291 1.9.8.2 nathanw txreg_t reg = tx_conf_read(sc->sc_tc, TX39_IOCTRL_REG);
292 1.9.8.2 nathanw
293 1.9.8.2 nathanw DPRINTF("port #%d\n", port);
294 1.9.8.2 nathanw return (TX391X_IOCTRL_IODIN(reg) & (1 << port));
295 1.9.8.2 nathanw }
296 1.9.8.2 nathanw
297 1.9.8.2 nathanw void
298 1.9.8.2 nathanw tx391x_io_out(hpcio_chip_t arg, int port, int onoff)
299 1.9.8.2 nathanw {
300 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
301 1.9.8.2 nathanw tx_chipset_tag_t tc;
302 1.9.8.2 nathanw txreg_t reg, pos, iostat;
303 1.9.8.2 nathanw
304 1.9.8.2 nathanw KASSERT(sc);
305 1.9.8.2 nathanw DPRINTF("port #%d\n", port);
306 1.9.8.2 nathanw
307 1.9.8.2 nathanw tc = sc->sc_tc;
308 1.9.8.2 nathanw
309 1.9.8.2 nathanw /* IO [0:6] */
310 1.9.8.2 nathanw pos = 1 << port;
311 1.9.8.2 nathanw #ifdef DIAGNOSTIC
312 1.9.8.2 nathanw if (!(sc->sc_stat_io.dir & pos))
313 1.9.8.2 nathanw panic("%s: IO%d is not output port.\n", sc->sc_dev.dv_xname,
314 1.9.8.2 nathanw port);
315 1.9.8.2 nathanw #endif
316 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_IOCTRL_REG);
317 1.9.8.2 nathanw iostat = TX391X_IOCTRL_IODOUT(reg);
318 1.9.8.2 nathanw if (onoff)
319 1.9.8.2 nathanw iostat |= pos;
320 1.9.8.2 nathanw else
321 1.9.8.2 nathanw iostat &= ~pos;
322 1.9.8.2 nathanw TX391X_IOCTRL_IODOUT_CLR(reg);
323 1.9.8.2 nathanw reg = TX391X_IOCTRL_IODOUT_SET(reg, iostat);
324 1.9.8.2 nathanw tx_conf_write(tc, TX39_IOCTRL_REG, reg);
325 1.9.8.2 nathanw }
326 1.9.8.2 nathanw
327 1.9.8.2 nathanw void
328 1.9.8.2 nathanw tx391x_io_update(hpcio_chip_t arg)
329 1.9.8.2 nathanw {
330 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
331 1.9.8.2 nathanw struct tx39io_port_status *stat_io = &sc->sc_stat_io;
332 1.9.8.2 nathanw tx_chipset_tag_t tc = sc->sc_tc;
333 1.9.8.2 nathanw txreg_t reg;
334 1.9.8.2 nathanw
335 1.9.8.2 nathanw /* IO [0:6] */
336 1.9.8.2 nathanw sc->sc_ostat_io = *stat_io; /* save old status */
337 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_IOCTRL_REG);
338 1.9.8.2 nathanw stat_io->dir = TX391X_IOCTRL_IODIREC(reg);
339 1.9.8.2 nathanw stat_io->in = TX391X_IOCTRL_IODIN(reg);
340 1.9.8.2 nathanw stat_io->out = TX391X_IOCTRL_IODOUT(reg);
341 1.9.8.2 nathanw stat_io->u.debounce = TX391X_IOCTRL_IODEBSEL(reg);
342 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_IOIOPOWERDWN_REG);
343 1.9.8.2 nathanw stat_io->power = TX391X_IOIOPOWERDWN_IOPD(reg);
344 1.9.8.2 nathanw }
345 1.9.8.2 nathanw
346 1.9.8.2 nathanw int
347 1.9.8.2 nathanw tx391x_io_intr_map(int *src, int port, int mode)
348 1.9.8.2 nathanw {
349 1.9.8.2 nathanw
350 1.9.8.2 nathanw if (mode & HPCIO_INTR_POSEDGE) {
351 1.9.8.2 nathanw *src = MAKEINTR(5, (1 << (port + 7)));
352 1.9.8.2 nathanw return (0);
353 1.9.8.2 nathanw } else if (mode & HPCIO_INTR_NEGEDGE) {
354 1.9.8.2 nathanw *src = MAKEINTR(5, (1 << port));
355 1.9.8.2 nathanw return (0);
356 1.9.8.2 nathanw }
357 1.9.8.2 nathanw
358 1.9.8.2 nathanw DPRINTF("invalid interrupt mode.\n");
359 1.9.8.2 nathanw
360 1.9.8.2 nathanw return (1);
361 1.9.8.2 nathanw }
362 1.9.8.2 nathanw #endif /* TX391X */
363 1.9.8.2 nathanw
364 1.9.8.2 nathanw #ifdef TX392X
365 1.9.8.2 nathanw /*
366 1.9.8.2 nathanw * TMPR3922 specific
367 1.9.8.2 nathanw */
368 1.9.8.2 nathanw int
369 1.9.8.2 nathanw tx392x_io_in(hpcio_chip_t arg, int port)
370 1.9.8.2 nathanw {
371 1.9.8.2 nathanw struct tx39io_softc *sc __attribute__((__unused__)) = arg->hc_sc;
372 1.9.8.2 nathanw txreg_t reg = tx_conf_read(sc->sc_tc, TX392X_IODATAINOUT_REG);
373 1.9.8.2 nathanw
374 1.9.8.2 nathanw DPRINTF("port #%d\n", port);
375 1.9.8.2 nathanw
376 1.9.8.2 nathanw return (TX392X_IODATAINOUT_DIN(reg) & (1 << port));
377 1.9.8.2 nathanw }
378 1.9.8.2 nathanw
379 1.9.8.2 nathanw void
380 1.9.8.2 nathanw tx392x_io_out(hpcio_chip_t arg, int port, int onoff)
381 1.9.8.2 nathanw {
382 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
383 1.9.8.2 nathanw #ifdef DIAGNOSTIC
384 1.9.8.2 nathanw const char *devname = sc->sc_dev.dv_xname;
385 1.9.8.2 nathanw #endif
386 1.9.8.2 nathanw tx_chipset_tag_t tc = sc->sc_tc;
387 1.9.8.2 nathanw txreg_t reg, pos, iostat;
388 1.9.8.2 nathanw
389 1.9.8.2 nathanw DPRINTF("port #%d\n", port);
390 1.9.8.2 nathanw /* IO [0:15] */
391 1.9.8.2 nathanw pos = 1 << port;
392 1.9.8.2 nathanw #ifdef DIAGNOSTIC
393 1.9.8.2 nathanw if (!(sc->sc_status.dir_io & pos))
394 1.9.8.2 nathanw panic("%s: IO%d is not output port.\n", devname, port);
395 1.9.8.2 nathanw #endif
396 1.9.8.2 nathanw reg = tx_conf_read(tc, TX392X_IODATAINOUT_REG);
397 1.9.8.2 nathanw iostat = TX392X_IODATAINOUT_DOUT(reg);
398 1.9.8.2 nathanw if (onoff)
399 1.9.8.2 nathanw iostat |= pos;
400 1.9.8.2 nathanw else
401 1.9.8.2 nathanw iostat &= ~pos;
402 1.9.8.2 nathanw TX392X_IODATAINOUT_DOUT_CLR(reg);
403 1.9.8.2 nathanw reg = TX392X_IODATAINOUT_DOUT_SET(reg, iostat);
404 1.9.8.2 nathanw tx_conf_write(tc, TX392X_IODATAINOUT_REG, reg);
405 1.9.8.2 nathanw }
406 1.9.8.2 nathanw
407 1.9.8.2 nathanw int
408 1.9.8.2 nathanw tx392x_io_intr_map(int *src, int port, int mode)
409 1.9.8.2 nathanw {
410 1.9.8.2 nathanw
411 1.9.8.2 nathanw if (mode & HPCIO_INTR_POSEDGE) {
412 1.9.8.2 nathanw *src = MAKEINTR(8, (1 << (port + 16)));
413 1.9.8.2 nathanw return (0);
414 1.9.8.2 nathanw } else if (mode & HPCIO_INTR_NEGEDGE) {
415 1.9.8.2 nathanw *src = MAKEINTR(8, (1 << port));
416 1.9.8.2 nathanw return (0);
417 1.9.8.2 nathanw }
418 1.9.8.2 nathanw
419 1.9.8.2 nathanw DPRINTF("invalid interrupt mode.\n");
420 1.9.8.2 nathanw
421 1.9.8.2 nathanw return (1);
422 1.9.8.2 nathanw }
423 1.9.8.2 nathanw
424 1.9.8.2 nathanw void
425 1.9.8.2 nathanw tx392x_io_update(hpcio_chip_t arg)
426 1.9.8.2 nathanw {
427 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
428 1.9.8.2 nathanw struct tx39io_port_status *stat_io = &sc->sc_stat_io;
429 1.9.8.2 nathanw tx_chipset_tag_t tc = sc->sc_tc;
430 1.9.8.2 nathanw txreg_t reg;
431 1.9.8.2 nathanw
432 1.9.8.2 nathanw sc->sc_ostat_io = *stat_io; /* save old status */
433 1.9.8.2 nathanw /* IO [0:15] */
434 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_IOCTRL_REG);
435 1.9.8.2 nathanw stat_io->dir = TX392X_IOCTRL_IODIREC(reg);
436 1.9.8.2 nathanw stat_io->u.debounce = TX392X_IOCTRL_IODEBSEL(reg);
437 1.9.8.2 nathanw reg = tx_conf_read(tc, TX392X_IODATAINOUT_REG);
438 1.9.8.2 nathanw stat_io->in = TX392X_IODATAINOUT_DIN(reg);
439 1.9.8.2 nathanw stat_io->out = TX392X_IODATAINOUT_DOUT(reg);
440 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_IOIOPOWERDWN_REG);
441 1.9.8.2 nathanw stat_io->power = TX392X_IOIOPOWERDWN_IOPD(reg);
442 1.9.8.2 nathanw }
443 1.9.8.2 nathanw
444 1.9.8.2 nathanw #endif /* TX392X */
445 1.9.8.2 nathanw
446 1.9.8.2 nathanw static const char *line = "--------------------------------------------------"
447 1.9.8.2 nathanw "------------\n";
448 1.9.8.2 nathanw static void
449 1.9.8.2 nathanw mfio_dump(hpcio_chip_t arg)
450 1.9.8.2 nathanw {
451 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
452 1.9.8.2 nathanw const struct tx39io_mfio_map *map = tx39io_get_mfio_map(tc);
453 1.9.8.2 nathanw struct tx39io_port_status *stat;
454 1.9.8.2 nathanw int i;
455 1.9.8.2 nathanw
456 1.9.8.2 nathanw printf("%s", line);
457 1.9.8.2 nathanw stat = &sc->sc_stat_mfio;
458 1.9.8.2 nathanw for (i = TX39_IO_MFIO_MAX - 1; i >= 0 ; i--) {
459 1.9.8.2 nathanw /* MFIO port has power down state */
460 1.9.8.2 nathanw printf("MFIO %2d: - ", i);
461 1.9.8.2 nathanw __print_port_status(stat, i);
462 1.9.8.2 nathanw printf(ISSET(stat->u.select, i) ? " MFIO(%s)\n" : " %s\n",
463 1.9.8.2 nathanw map[i].std_pin_name);
464 1.9.8.2 nathanw }
465 1.9.8.2 nathanw printf("%s", line);
466 1.9.8.2 nathanw }
467 1.9.8.2 nathanw
468 1.9.8.2 nathanw static void
469 1.9.8.2 nathanw io_dump(hpcio_chip_t arg)
470 1.9.8.2 nathanw {
471 1.9.8.2 nathanw struct tx39io_softc *sc = arg->hc_sc;
472 1.9.8.2 nathanw struct tx39io_port_status *stat;
473 1.9.8.2 nathanw int i;
474 1.9.8.2 nathanw
475 1.9.8.2 nathanw printf("%s Debounce Direction DataOut DataIn PowerDown Select"
476 1.9.8.2 nathanw "\n%s", line, line);
477 1.9.8.2 nathanw stat = &sc->sc_stat_io;
478 1.9.8.2 nathanw for (i = tx39io_get_io_max(tc) - 1; i >= 0 ; i--) {
479 1.9.8.2 nathanw /* IO port has debouncer */
480 1.9.8.2 nathanw printf("IO %2d: %s ", i,
481 1.9.8.2 nathanw ISSET(stat->u.debounce, i) ? "On " : "Off");
482 1.9.8.2 nathanw __print_port_status(stat, i);
483 1.9.8.2 nathanw printf(" -\n");
484 1.9.8.2 nathanw }
485 1.9.8.2 nathanw }
486 1.9.8.2 nathanw
487 1.9.8.2 nathanw static void
488 1.9.8.2 nathanw __print_port_status(struct tx39io_port_status *stat, int i)
489 1.9.8.2 nathanw {
490 1.9.8.2 nathanw printf("%s %d %d %s",
491 1.9.8.2 nathanw ISSET(stat->dir, i) ? "Out" : "In ",
492 1.9.8.2 nathanw ISSET(stat->out, i) ? 1 : 0,
493 1.9.8.2 nathanw ISSET(stat->in, i) ? 1 : 0,
494 1.9.8.2 nathanw ISSET(stat->power, i) ? "Down ": "Active");
495 1.9.8.2 nathanw }
496