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