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