Home | History | Annotate | Line # | Download | only in dev
it8368.c revision 1.9.4.1
      1  1.9.4.1  fvdl /*	$NetBSD: it8368.c,v 1.9.4.1 2001/10/01 12:38:51 fvdl Exp $ */
      2      1.1   uch 
      3  1.9.4.1  fvdl /*-
      4  1.9.4.1  fvdl  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
      5      1.1   uch  * All rights reserved.
      6      1.1   uch  *
      7  1.9.4.1  fvdl  * This code is derived from software contributed to The NetBSD Foundation
      8  1.9.4.1  fvdl  * by UCHIYAMA Yasushi.
      9  1.9.4.1  fvdl  *
     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.9.4.1  fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.9.4.1  fvdl  *    notice, this list of conditions and the following disclaimer in the
     17  1.9.4.1  fvdl  *    documentation and/or other materials provided with the distribution.
     18  1.9.4.1  fvdl  * 3. All advertising materials mentioning features or use of this software
     19  1.9.4.1  fvdl  *    must display the following acknowledgement:
     20  1.9.4.1  fvdl  *        This product includes software developed by the NetBSD
     21  1.9.4.1  fvdl  *        Foundation, Inc. and its contributors.
     22  1.9.4.1  fvdl  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.9.4.1  fvdl  *    contributors may be used to endorse or promote products derived
     24  1.9.4.1  fvdl  *    from this software without specific prior written permission.
     25      1.1   uch  *
     26  1.9.4.1  fvdl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.9.4.1  fvdl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.9.4.1  fvdl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.9.4.1  fvdl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.9.4.1  fvdl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.9.4.1  fvdl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.9.4.1  fvdl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.9.4.1  fvdl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.9.4.1  fvdl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.9.4.1  fvdl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.9.4.1  fvdl  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1   uch  */
     38  1.9.4.1  fvdl 
     39      1.8   uch #undef WINCE_DEFAULT_SETTING /* for debug */
     40      1.8   uch #undef IT8368DEBUG
     41      1.1   uch #include "opt_tx39_debug.h"
     42      1.1   uch 
     43      1.1   uch #include <sys/param.h>
     44      1.1   uch #include <sys/systm.h>
     45      1.1   uch #include <sys/device.h>
     46      1.1   uch 
     47      1.1   uch #include <machine/bus.h>
     48      1.1   uch 
     49      1.1   uch #include <dev/pcmcia/pcmciareg.h>
     50      1.1   uch #include <dev/pcmcia/pcmciavar.h>
     51      1.1   uch #include <dev/pcmcia/pcmciachip.h>
     52      1.1   uch 
     53      1.1   uch #include <hpcmips/tx/tx39var.h>
     54      1.1   uch #include <hpcmips/tx/txcsbusvar.h>
     55      1.6   uch #include <hpcmips/tx/tx39biureg.h> /* legacy mode requires BIU access */
     56      1.6   uch #include <hpcmips/dev/it8368var.h>
     57      1.1   uch #include <hpcmips/dev/it8368reg.h>
     58      1.1   uch 
     59      1.1   uch #ifdef IT8368DEBUG
     60      1.8   uch int	it8368debug = 1;
     61      1.8   uch #define	DPRINTF(arg) if (it8368debug) printf arg;
     62      1.8   uch #define	DPRINTFN(n, arg) if (it8368debug > (n)) printf arg;
     63      1.1   uch #else
     64      1.1   uch #define	DPRINTF(arg)
     65      1.8   uch #define DPRINTFN(n, arg)
     66      1.1   uch #endif
     67      1.1   uch 
     68  1.9.4.1  fvdl int it8368e_match(struct device *, struct cfdata *, void *);
     69  1.9.4.1  fvdl void it8368e_attach(struct device *, struct device *, void *);
     70  1.9.4.1  fvdl int it8368_print(void *, const char *);
     71  1.9.4.1  fvdl int it8368_submatch(struct device *, struct cfdata *, void *);
     72      1.1   uch 
     73      1.4   uch #define IT8368_LASTSTATE_PRESENT	0x0002
     74      1.4   uch #define IT8368_LASTSTATE_HALF		0x0001
     75      1.7   uch #define IT8368_LASTSTATE_EMPTY		0x0000
     76      1.4   uch 
     77      1.1   uch struct it8368e_softc {
     78      1.1   uch 	struct device	sc_dev;
     79      1.1   uch 	struct device	*sc_pcmcia;
     80      1.1   uch 	tx_chipset_tag_t sc_tc;
     81      1.1   uch 
     82      1.1   uch 	/* Register space */
     83      1.4   uch 	bus_space_tag_t		sc_csregt;
     84      1.4   uch 	bus_space_handle_t	sc_csregh;
     85      1.1   uch 	/* I/O, attribute space */
     86      1.4   uch 	bus_space_tag_t		sc_csiot;
     87      1.4   uch 	bus_addr_t		sc_csiobase;
     88      1.4   uch 	bus_size_t		sc_csiosize;
     89      1.3   uch 	/*
     90      1.3   uch 	 *  XXX theses means attribute memory. not memory space.
     91      1.3   uch 	 *	memory space is 0x64000000.
     92      1.3   uch 	 */
     93      1.4   uch 	bus_space_tag_t		sc_csmemt;
     94      1.4   uch 	bus_addr_t		sc_csmembase;
     95      1.4   uch 	bus_size_t		sc_csmemsize;
     96      1.1   uch 
     97      1.1   uch 	/* Separate I/O and attribute space mode */
     98      1.1   uch 	int sc_fixattr;
     99      1.1   uch 
    100      1.1   uch 	/* Card interrupt handler */
    101  1.9.4.1  fvdl 	int	(*sc_card_fun)(void *);
    102      1.4   uch 	void	*sc_card_arg;
    103      1.4   uch 	void	*sc_card_ih;
    104      1.4   uch 	int	sc_card_irq;
    105      1.4   uch 
    106      1.4   uch 	/* Card status change */
    107      1.4   uch 	int	sc_irq;
    108      1.4   uch 	void	*sc_ih;
    109      1.4   uch 	int	sc_laststate;
    110      1.1   uch };
    111      1.1   uch 
    112  1.9.4.1  fvdl void it8368_init_socket(struct it8368e_softc*);
    113  1.9.4.1  fvdl void it8368_attach_socket(struct it8368e_softc *);
    114  1.9.4.1  fvdl int it8368_intr(void *);
    115  1.9.4.1  fvdl int it8368_chip_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
    116  1.9.4.1  fvdl     struct pcmcia_mem_handle *);
    117  1.9.4.1  fvdl void it8368_chip_mem_free(pcmcia_chipset_handle_t, struct pcmcia_mem_handle *);
    118  1.9.4.1  fvdl int it8368_chip_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t, bus_size_t,
    119  1.9.4.1  fvdl     struct pcmcia_mem_handle *, bus_addr_t *, int *);
    120  1.9.4.1  fvdl void it8368_chip_mem_unmap(pcmcia_chipset_handle_t, int);
    121  1.9.4.1  fvdl int it8368_chip_io_alloc(pcmcia_chipset_handle_t, bus_addr_t, bus_size_t,
    122  1.9.4.1  fvdl     bus_size_t, struct pcmcia_io_handle *);
    123  1.9.4.1  fvdl void it8368_chip_io_free(pcmcia_chipset_handle_t, struct pcmcia_io_handle *);
    124  1.9.4.1  fvdl int it8368_chip_io_map(pcmcia_chipset_handle_t, int, bus_addr_t, bus_size_t,
    125  1.9.4.1  fvdl     struct pcmcia_io_handle *, int *);
    126  1.9.4.1  fvdl void it8368_chip_io_unmap(pcmcia_chipset_handle_t, int);
    127  1.9.4.1  fvdl void it8368_chip_socket_enable(pcmcia_chipset_handle_t);
    128  1.9.4.1  fvdl void it8368_chip_socket_disable(pcmcia_chipset_handle_t);
    129  1.9.4.1  fvdl void *it8368_chip_intr_establish(pcmcia_chipset_handle_t,
    130  1.9.4.1  fvdl     struct pcmcia_function *, int, int (*) (void *), void *);
    131  1.9.4.1  fvdl void it8368_chip_intr_disestablish(pcmcia_chipset_handle_t, void *);
    132      1.1   uch 
    133      1.8   uch #ifdef IT8368DEBUG
    134  1.9.4.1  fvdl void it8368_dump(struct it8368e_softc *);
    135      1.8   uch #endif
    136      1.8   uch 
    137      1.1   uch static struct pcmcia_chip_functions it8368_functions = {
    138      1.1   uch 	it8368_chip_mem_alloc,
    139      1.1   uch 	it8368_chip_mem_free,
    140      1.1   uch 	it8368_chip_mem_map,
    141      1.1   uch 	it8368_chip_mem_unmap,
    142      1.1   uch 	it8368_chip_io_alloc,
    143      1.1   uch 	it8368_chip_io_free,
    144      1.1   uch 	it8368_chip_io_map,
    145      1.1   uch 	it8368_chip_io_unmap,
    146      1.1   uch 	it8368_chip_intr_establish,
    147      1.1   uch 	it8368_chip_intr_disestablish,
    148      1.1   uch 	it8368_chip_socket_enable,
    149      1.1   uch 	it8368_chip_socket_disable
    150      1.1   uch };
    151      1.1   uch 
    152      1.1   uch struct cfattach it8368e_ca = {
    153      1.1   uch 	sizeof(struct it8368e_softc), it8368e_match, it8368e_attach
    154      1.1   uch };
    155      1.1   uch 
    156      1.1   uch /*
    157      1.1   uch  *	IT8368 configuration register is big-endian.
    158      1.1   uch  */
    159  1.9.4.1  fvdl static __inline__ u_int16_t it8368_reg_read(bus_space_tag_t,
    160  1.9.4.1  fvdl     bus_space_handle_t, int);
    161  1.9.4.1  fvdl static __inline__ void it8368_reg_write(bus_space_tag_t, bus_space_handle_t,
    162  1.9.4.1  fvdl     int, u_int16_t);
    163      1.1   uch 
    164      1.8   uch #ifdef IT8368E_DESTRUCTIVE_CHECK
    165  1.9.4.1  fvdl int	it8368e_id_check(void *);
    166      1.8   uch 
    167      1.8   uch /*
    168      1.8   uch  *	IT8368E don't have identification method. this is destructive check.
    169      1.8   uch  */
    170      1.8   uch int
    171  1.9.4.1  fvdl it8368e_id_check(void *aux)
    172      1.8   uch {
    173      1.8   uch 	struct cs_attach_args *ca = aux;
    174      1.8   uch 	tx_chipset_tag_t tc;
    175      1.8   uch 	bus_space_tag_t csregt;
    176      1.8   uch 	bus_space_handle_t csregh;
    177      1.8   uch 	u_int16_t oreg, reg;
    178      1.8   uch 	int match = 0;
    179      1.8   uch 
    180      1.8   uch 	tc = ca->ca_tc;
    181      1.8   uch 	csregt = ca->ca_csreg.cstag;
    182      1.8   uch 
    183      1.8   uch 	bus_space_map(csregt, ca->ca_csreg.csbase, ca->ca_csreg.cssize,
    184  1.9.4.1  fvdl 	    0, &csregh);
    185      1.8   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
    186      1.8   uch 	oreg = reg;
    187      1.8   uch 	bitdisp(reg);
    188      1.8   uch 
    189      1.8   uch 	reg &= ~IT8368_CTRL_BYTESWAP;
    190      1.8   uch 	it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, reg);
    191      1.8   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
    192      1.8   uch 	if (reg & IT8368_CTRL_BYTESWAP)
    193      1.8   uch 		goto nomatch;
    194      1.8   uch 
    195      1.8   uch 	reg |= IT8368_CTRL_BYTESWAP;
    196      1.8   uch 	it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, reg);
    197      1.8   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
    198      1.8   uch 	if (!(reg & IT8368_CTRL_BYTESWAP))
    199      1.8   uch 		goto nomatch;
    200      1.8   uch 
    201      1.8   uch 	match = 1;
    202      1.8   uch  nomatch:
    203      1.8   uch 	it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, oreg);
    204      1.8   uch 	bus_space_unmap(csregt, csregh, ca->ca_csreg.cssize);
    205      1.8   uch 
    206      1.8   uch 	return (match);
    207      1.8   uch }
    208      1.8   uch #endif /* IT8368E_DESTRUCTIVE_CHECK */
    209      1.4   uch 
    210      1.1   uch int
    211  1.9.4.1  fvdl it8368e_match(struct device *parent, struct cfdata *cf, void *aux)
    212      1.1   uch {
    213      1.8   uch #ifdef IT8368E_DESTRUCTIVE_CHECK
    214      1.8   uch 	return (it8368e_id_check(aux));
    215      1.8   uch #else
    216      1.8   uch 	return (1);
    217      1.8   uch #endif
    218      1.1   uch }
    219      1.1   uch 
    220      1.1   uch void
    221  1.9.4.1  fvdl it8368e_attach(struct device *parent, struct device *self, void *aux)
    222      1.1   uch {
    223      1.1   uch 	struct cs_attach_args *ca = aux;
    224      1.1   uch 	struct it8368e_softc *sc = (void*)self;
    225      1.1   uch 	tx_chipset_tag_t tc;
    226      1.1   uch 	bus_space_tag_t csregt;
    227      1.1   uch 	bus_space_handle_t csregh;
    228      1.1   uch 	u_int16_t reg;
    229      1.1   uch 
    230      1.1   uch 	sc->sc_tc = tc = ca->ca_tc;
    231      1.1   uch 	sc->sc_csregt = csregt = ca->ca_csreg.cstag;
    232      1.1   uch 
    233      1.1   uch 	bus_space_map(csregt, ca->ca_csreg.csbase, ca->ca_csreg.cssize,
    234  1.9.4.1  fvdl 	    0, &sc->sc_csregh);
    235      1.1   uch 	csregh = sc->sc_csregh;
    236      1.1   uch 	sc->sc_csiot = ca->ca_csio.cstag;
    237      1.1   uch 	sc->sc_csiobase = ca->ca_csio.csbase;
    238      1.1   uch 	sc->sc_csiosize = ca->ca_csio.cssize;
    239      1.1   uch 
    240      1.3   uch #ifdef IT8368DEBUG
    241      1.4   uch 	printf("\n\t[Windows CE setting]\n");
    242      1.1   uch 	it8368_dump(sc); /* print WindowsCE setting */
    243      1.3   uch #endif
    244      1.1   uch 	/* LHA[14:13] <= HA[14:13]	*/
    245      1.1   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
    246      1.1   uch 	reg &= ~IT8368_CTRL_ADDRSEL;
    247      1.1   uch 	it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, reg);
    248      1.1   uch 
    249      1.1   uch 	/* Set all MFIO direction as LHA[23:13] output pins */
    250      1.1   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_MFIODIR_REG);
    251      1.1   uch 	reg |= IT8368_MFIODIR_MASK;
    252      1.1   uch 	it8368_reg_write(csregt, csregh, IT8368_MFIODIR_REG, reg);
    253      1.1   uch 
    254      1.1   uch 	/* Set all MFIO functions as LHA */
    255      1.1   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_MFIOSEL_REG);
    256      1.1   uch 	reg &= ~IT8368_MFIOSEL_MASK;
    257      1.1   uch 	it8368_reg_write(csregt, csregh, IT8368_MFIOSEL_REG, reg);
    258      1.1   uch 
    259      1.1   uch 	/* Disable MFIO interrupt */
    260      1.1   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_MFIOPOSINTEN_REG);
    261      1.1   uch 	reg &= ~IT8368_MFIOPOSINTEN_MASK;
    262      1.1   uch 	it8368_reg_write(csregt, csregh, IT8368_MFIOPOSINTEN_REG, reg);
    263      1.1   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_MFIONEGINTEN_REG);
    264      1.1   uch 	reg &= ~IT8368_MFIONEGINTEN_MASK;
    265      1.1   uch 	it8368_reg_write(csregt, csregh, IT8368_MFIONEGINTEN_REG, reg);
    266      1.1   uch 
    267      1.1   uch 	/* Port direction */
    268      1.1   uch 	reg = IT8368_PIN_CRDVCCON1 | IT8368_PIN_CRDVCCON0 |
    269  1.9.4.1  fvdl 	    IT8368_PIN_CRDVPPON1 | IT8368_PIN_CRDVPPON0 |
    270  1.9.4.1  fvdl 	    IT8368_PIN_BCRDRST;
    271      1.1   uch 	it8368_reg_write(csregt, csregh, IT8368_GPIODIR_REG, reg);
    272      1.5   uch 	printf("\n");
    273      1.5   uch 
    274      1.1   uch 	/*
    275      1.1   uch 	 *	Separate I/O and attribute memory region
    276      1.1   uch 	 */
    277      1.1   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
    278      1.8   uch 
    279      1.1   uch 	reg |= IT8368_CTRL_FIXATTRIO;
    280      1.1   uch 	it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, reg);
    281      1.8   uch 
    282      1.6   uch 	if (IT8368_CTRL_FIXATTRIO &
    283      1.6   uch 	    it8368_reg_read(csregt, csregh, IT8368_CTRL_REG)) {
    284      1.1   uch 		sc->sc_fixattr = 1;
    285      1.5   uch 		printf("%s: fix attr mode\n", sc->sc_dev.dv_xname);
    286      1.1   uch 	} else {
    287      1.1   uch 		sc->sc_fixattr = 0;
    288      1.6   uch 		printf("%s: legacy attr mode\n", sc->sc_dev.dv_xname);
    289      1.1   uch 	}
    290      1.8   uch 
    291      1.6   uch 	sc->sc_csmemt = sc->sc_csiot;
    292      1.6   uch 	sc->sc_csiosize /= 2;
    293      1.6   uch 	sc->sc_csmemsize = sc->sc_csiosize;
    294      1.6   uch 	sc->sc_csmembase = sc->sc_csiosize;
    295      1.6   uch 
    296      1.7   uch #ifdef IT8368DEBUG
    297      1.1   uch 	it8368_dump(sc);
    298      1.7   uch #endif
    299      1.4   uch 	/* Enable card and interrupt driving. */
    300      1.4   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
    301      1.4   uch 	reg |= (IT8368_CTRL_GLOBALEN | IT8368_CTRL_CARDEN);
    302      1.4   uch 	if (sc->sc_fixattr)
    303      1.4   uch 		reg |= IT8368_CTRL_FIXATTRIO;
    304      1.4   uch 	it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, reg);
    305      1.4   uch 
    306      1.4   uch 	sc->sc_irq = ca->ca_irq1;
    307      1.1   uch 	sc->sc_card_irq = ca->ca_irq3;
    308      1.1   uch 
    309      1.1   uch 	it8368_attach_socket(sc);
    310      1.1   uch }
    311      1.1   uch 
    312      1.7   uch __inline__ u_int16_t
    313  1.9.4.1  fvdl it8368_reg_read(bus_space_tag_t t, bus_space_handle_t h, int ofs)
    314      1.1   uch {
    315      1.1   uch 	u_int16_t val;
    316      1.1   uch 
    317      1.1   uch 	val = bus_space_read_2(t, h, ofs);
    318  1.9.4.1  fvdl 	return (0xffff & (((val >> 8) & 0xff)|((val << 8) & 0xff00)));
    319      1.1   uch }
    320      1.1   uch 
    321      1.7   uch __inline__ void
    322  1.9.4.1  fvdl it8368_reg_write(bus_space_tag_t t, bus_space_handle_t h, int ofs, u_int16_t v)
    323      1.1   uch {
    324      1.1   uch 	u_int16_t val;
    325      1.1   uch 
    326      1.1   uch 	val = 0xffff & (((v >> 8) & 0xff)|((v << 8) & 0xff00));
    327      1.1   uch 	bus_space_write_2(t, h, ofs, val);
    328      1.1   uch }
    329      1.1   uch 
    330      1.1   uch int
    331  1.9.4.1  fvdl it8368_intr(void *arg)
    332      1.1   uch {
    333      1.1   uch 	struct it8368e_softc *sc = arg;
    334      1.4   uch 	bus_space_tag_t csregt = sc->sc_csregt;
    335      1.4   uch 	bus_space_handle_t csregh = sc->sc_csregh;
    336      1.4   uch 	u_int16_t reg;
    337      1.3   uch 
    338      1.4   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_GPIONEGINTSTAT_REG);
    339      1.3   uch 
    340      1.4   uch 	if (reg & IT8368_PIN_BCRDRDY) {
    341      1.4   uch 		if (sc->sc_card_fun) {
    342      1.4   uch 			/* clear interrupt */
    343      1.4   uch 			it8368_reg_write(csregt, csregh,
    344  1.9.4.1  fvdl 			    IT8368_GPIONEGINTSTAT_REG,
    345  1.9.4.1  fvdl 			    IT8368_PIN_BCRDRDY);
    346      1.4   uch 
    347      1.4   uch 			/* Dispatch card interrupt handler */
    348      1.4   uch 			(*sc->sc_card_fun)(sc->sc_card_arg);
    349      1.4   uch 		}
    350      1.4   uch 	} else if (reg & IT8368_PIN_CRDDET2) {
    351      1.4   uch 		it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTSTAT_REG,
    352  1.9.4.1  fvdl 		    IT8368_PIN_CRDDET2);
    353      1.4   uch 		printf("[CSC]\n");
    354      1.7   uch #ifdef IT8368DEBUG
    355      1.4   uch 		it8368_dump(sc);
    356      1.7   uch #endif
    357      1.4   uch 		it8368_chip_socket_disable(sc);
    358      1.4   uch 	} else {
    359      1.7   uch #ifdef IT8368DEBUG
    360      1.8   uch 		u_int16_t reg2;
    361      1.8   uch 		reg2 = reg & ~(IT8368_PIN_BCRDRDY|IT8368_PIN_CRDDET2);
    362      1.8   uch 		printf("unknown it8368 interrupt: ");
    363      1.8   uch 		bitdisp(reg2);
    364      1.8   uch 		it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTSTAT_REG,
    365  1.9.4.1  fvdl 		    reg);
    366      1.7   uch #endif
    367      1.1   uch 	}
    368      1.4   uch 
    369  1.9.4.1  fvdl 	return (0);
    370      1.1   uch }
    371      1.1   uch 
    372      1.1   uch int
    373  1.9.4.1  fvdl it8368_print(void *arg, const char *pnp)
    374      1.1   uch {
    375      1.3   uch 	if (pnp)
    376      1.1   uch 		printf("pcmcia at %s", pnp);
    377      1.1   uch 
    378  1.9.4.1  fvdl 	return (UNCONF);
    379      1.1   uch }
    380      1.1   uch 
    381      1.1   uch int
    382  1.9.4.1  fvdl it8368_submatch(struct device *parent, struct cfdata *cf, void *aux)
    383      1.1   uch {
    384  1.9.4.1  fvdl 
    385      1.1   uch 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    386      1.1   uch }
    387      1.1   uch 
    388      1.1   uch void
    389  1.9.4.1  fvdl it8368_attach_socket(struct it8368e_softc *sc)
    390      1.1   uch {
    391      1.1   uch 	struct pcmciabus_attach_args paa;
    392      1.1   uch 
    393      1.1   uch 	paa.paa_busname = "pcmcia";
    394      1.1   uch 	paa.pct = (pcmcia_chipset_tag_t)&it8368_functions;
    395      1.1   uch 	paa.pch = (pcmcia_chipset_handle_t)sc;
    396      1.9   uch 	paa.iobase = 0;
    397      1.9   uch 	paa.iosize = sc->sc_csiosize;
    398      1.1   uch 
    399      1.1   uch 	if ((sc->sc_pcmcia = config_found_sm((void*)sc, &paa, it8368_print,
    400  1.9.4.1  fvdl 	    it8368_submatch))) {
    401      1.4   uch 
    402      1.4   uch 		it8368_init_socket(sc);
    403      1.4   uch 	}
    404      1.4   uch }
    405      1.4   uch 
    406      1.4   uch void
    407  1.9.4.1  fvdl it8368_init_socket(struct it8368e_softc *sc)
    408      1.4   uch {
    409      1.4   uch 	bus_space_tag_t csregt = sc->sc_csregt;
    410      1.4   uch 	bus_space_handle_t csregh = sc->sc_csregh;
    411      1.4   uch 	u_int16_t reg;
    412      1.4   uch 
    413      1.4   uch 	/*
    414      1.4   uch 	 *  set up the card to interrupt on card detect
    415      1.4   uch 	 */
    416      1.4   uch 	reg = IT8368_PIN_CRDDET2; /* CSC */
    417      1.4   uch 	/* enable negative edge */
    418      1.4   uch 	it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTEN_REG, reg);
    419      1.4   uch 	/* disable positive edge */
    420      1.4   uch 	it8368_reg_write(csregt, csregh, IT8368_GPIOPOSINTEN_REG, 0);
    421      1.4   uch 
    422      1.4   uch 	sc->sc_ih = tx_intr_establish(sc->sc_tc, sc->sc_irq,
    423  1.9.4.1  fvdl 	    IST_EDGE, IPL_BIO, it8368_intr, sc);
    424      1.4   uch 	if (sc->sc_ih == NULL) {
    425      1.4   uch 		printf("%s: can't establish interrupt\n",
    426  1.9.4.1  fvdl 		    sc->sc_dev.dv_xname);
    427      1.4   uch 		return;
    428      1.4   uch 	}
    429      1.4   uch 
    430      1.4   uch 	/*
    431      1.4   uch 	 *  if there's a card there, then attach it.
    432      1.4   uch 	 */
    433      1.4   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAIN_REG);
    434      1.4   uch 
    435      1.4   uch 	if (reg & (IT8368_PIN_CRDDET2|IT8368_PIN_CRDDET1)) {
    436      1.4   uch 		sc->sc_laststate = IT8368_LASTSTATE_EMPTY;
    437      1.4   uch 	} else {
    438      1.4   uch 		pcmcia_card_attach(sc->sc_pcmcia);
    439      1.4   uch 		sc->sc_laststate = IT8368_LASTSTATE_PRESENT;
    440      1.1   uch 	}
    441      1.1   uch }
    442      1.1   uch 
    443      1.1   uch void *
    444  1.9.4.1  fvdl it8368_chip_intr_establish(pcmcia_chipset_handle_t pch,
    445  1.9.4.1  fvdl     struct pcmcia_function *pf, int ipl, int (*ih_fun)(void *), void *ih_arg)
    446      1.1   uch {
    447      1.1   uch 	struct it8368e_softc *sc = (struct it8368e_softc*) pch;
    448      1.4   uch 	bus_space_tag_t csregt = sc->sc_csregt;
    449      1.4   uch 	bus_space_handle_t csregh = sc->sc_csregh;
    450      1.4   uch 	u_int16_t reg;
    451      1.1   uch 
    452      1.4   uch 	if (sc->sc_card_fun)
    453      1.3   uch 		panic("it8368_chip_intr_establish: "
    454  1.9.4.1  fvdl 		    "duplicate card interrupt handler.");
    455      1.4   uch 
    456      1.1   uch 	sc->sc_card_fun = ih_fun;
    457      1.1   uch 	sc->sc_card_arg = ih_arg;
    458      1.1   uch 
    459      1.4   uch 	sc->sc_card_ih = tx_intr_establish(sc->sc_tc, sc->sc_card_irq,
    460  1.9.4.1  fvdl 	    IST_EDGE, IPL_BIO, it8368_intr,
    461  1.9.4.1  fvdl 	    sc);
    462      1.4   uch 
    463      1.4   uch 	/* enable card interrupt */
    464      1.4   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_GPIONEGINTEN_REG);
    465      1.4   uch 	reg |= IT8368_PIN_BCRDRDY;
    466      1.4   uch 	it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTEN_REG, reg);
    467      1.4   uch 
    468  1.9.4.1  fvdl 	return (sc->sc_card_ih);
    469      1.1   uch }
    470      1.1   uch 
    471      1.1   uch void
    472  1.9.4.1  fvdl it8368_chip_intr_disestablish(pcmcia_chipset_handle_t pch, void *ih)
    473      1.1   uch {
    474      1.1   uch 	struct it8368e_softc *sc = (struct it8368e_softc*) pch;
    475      1.4   uch 	bus_space_tag_t csregt = sc->sc_csregt;
    476      1.4   uch 	bus_space_handle_t csregh = sc->sc_csregh;
    477      1.4   uch 	u_int16_t reg;
    478      1.1   uch 
    479      1.4   uch 	if (!sc->sc_card_fun)
    480      1.3   uch 		panic("it8368_chip_intr_disestablish:"
    481  1.9.4.1  fvdl 		    "no handler established.");
    482      1.4   uch 	assert(ih == sc->sc_card_ih);
    483      1.4   uch 
    484      1.1   uch 	sc->sc_card_fun = 0;
    485      1.1   uch 	sc->sc_card_arg = 0;
    486      1.1   uch 
    487      1.4   uch 	/* disable card interrupt */
    488      1.4   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_GPIONEGINTEN_REG);
    489      1.4   uch 	reg &= ~IT8368_PIN_BCRDRDY;
    490      1.4   uch 	it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTEN_REG, reg);
    491      1.4   uch 
    492      1.1   uch 	tx_intr_disestablish(sc->sc_tc, ih);
    493      1.1   uch }
    494      1.1   uch 
    495      1.1   uch int
    496  1.9.4.1  fvdl it8368_chip_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t size,
    497  1.9.4.1  fvdl     struct pcmcia_mem_handle *pcmhp)
    498      1.1   uch {
    499      1.1   uch 	struct it8368e_softc *sc = (struct it8368e_softc*) pch;
    500      1.1   uch 
    501      1.6   uch 	if (bus_space_alloc(sc->sc_csmemt, sc->sc_csmembase,
    502  1.9.4.1  fvdl 	    sc->sc_csmembase + sc->sc_csmemsize, size,
    503  1.9.4.1  fvdl 	    size, 0, 0, 0, &pcmhp->memh)) {
    504      1.6   uch 		DPRINTF(("it8368_chip_mem_alloc: failed\n"));
    505  1.9.4.1  fvdl 		return (1);
    506      1.1   uch 	}
    507      1.3   uch 
    508      1.6   uch 	if (!sc->sc_fixattr) /* XXX IT8368 brain damaged spec */
    509      1.6   uch 		pcmhp->memh -= sc->sc_csmembase;
    510      1.6   uch 
    511      1.6   uch 	pcmhp->memt = sc->sc_csmemt;
    512      1.1   uch 	pcmhp->addr = pcmhp->memh;
    513      1.1   uch 	pcmhp->size = size;
    514      1.1   uch 	pcmhp->realsize = size;
    515      1.3   uch 
    516      1.8   uch 	DPRINTF(("it8368_chip_mem_alloc: %#x+%#x\n",
    517  1.9.4.1  fvdl 	    (unsigned)pcmhp->memh, (unsigned)size));
    518      1.1   uch 
    519  1.9.4.1  fvdl 	return (0);
    520      1.1   uch }
    521      1.1   uch 
    522      1.1   uch void
    523  1.9.4.1  fvdl it8368_chip_mem_free(pcmcia_chipset_handle_t pch,
    524  1.9.4.1  fvdl     struct pcmcia_mem_handle *pcmhp)
    525      1.1   uch {
    526      1.6   uch 	struct it8368e_softc *sc = (struct it8368e_softc*) pch;
    527      1.6   uch 
    528      1.8   uch 	DPRINTF(("it8368_chip_mem_free: %#x+%#x\n",
    529  1.9.4.1  fvdl 	    (unsigned)pcmhp->memh, (unsigned)pcmhp->size));
    530      1.8   uch 
    531      1.6   uch 	if (!sc->sc_fixattr) /* XXX IT8368 brain damaged spec */
    532      1.6   uch 		pcmhp->memh += sc->sc_csmembase;
    533      1.6   uch 
    534      1.1   uch 	bus_space_unmap(pcmhp->memt, pcmhp->memh, pcmhp->size);
    535      1.1   uch }
    536      1.1   uch 
    537      1.1   uch int
    538  1.9.4.1  fvdl it8368_chip_mem_map(pcmcia_chipset_handle_t pch, int kind,
    539  1.9.4.1  fvdl     bus_addr_t card_addr, bus_size_t size, struct pcmcia_mem_handle *pcmhp,
    540  1.9.4.1  fvdl     bus_addr_t *offsetp, int *windowp)
    541      1.1   uch {
    542      1.6   uch 	/* attribute mode */
    543      1.6   uch 	it8368_mode(pch, IT8368_ATTR_MODE, IT8368_WIDTH_16);
    544      1.1   uch 
    545      1.3   uch 	*offsetp = card_addr;
    546      1.8   uch 	DPRINTF(("it8368_chip_mem_map %#x+%#x\n",
    547  1.9.4.1  fvdl 	    (unsigned)pcmhp->memh, (unsigned)size));
    548      1.3   uch 
    549  1.9.4.1  fvdl 	return (0);
    550      1.1   uch }
    551      1.1   uch 
    552      1.1   uch void
    553  1.9.4.1  fvdl it8368_chip_mem_unmap(pcmcia_chipset_handle_t pch, int window)
    554      1.1   uch {
    555      1.6   uch 	/* return to I/O mode */
    556      1.6   uch 	it8368_mode(pch, IT8368_IO_MODE, IT8368_WIDTH_16);
    557      1.1   uch }
    558      1.1   uch 
    559      1.1   uch void
    560  1.9.4.1  fvdl it8368_mode(pcmcia_chipset_handle_t pch, int io, int width)
    561      1.1   uch {
    562      1.6   uch 	struct it8368e_softc *sc = (struct it8368e_softc*) pch;
    563      1.1   uch 	txreg_t reg32;
    564      1.1   uch 
    565      1.6   uch 	DPRINTF(("it8368_mode: change access space to "));
    566      1.8   uch 	DPRINTF((io ? "I/O (%dbit)\n" : "attribute (%dbit)...\n",
    567  1.9.4.1  fvdl 	    width == IT8368_WIDTH_8 ? 8 : 16));
    568      1.6   uch 
    569      1.1   uch 	reg32 = tx_conf_read(sc->sc_tc, TX39_MEMCONFIG3_REG);
    570      1.8   uch 
    571      1.6   uch 	if (io) {
    572      1.8   uch 		if (width == IT8368_WIDTH_8)
    573      1.6   uch 			reg32 |= TX39_MEMCONFIG3_PORT8SEL;
    574      1.6   uch 		else
    575      1.6   uch 			reg32 &= ~TX39_MEMCONFIG3_PORT8SEL;
    576      1.1   uch 	}
    577      1.6   uch 
    578      1.1   uch 	if (!sc->sc_fixattr) {
    579      1.6   uch 		if (io)
    580      1.1   uch 			reg32 |= TX39_MEMCONFIG3_CARD1IOEN;
    581      1.6   uch 		else
    582      1.1   uch 			reg32 &= ~TX39_MEMCONFIG3_CARD1IOEN;
    583      1.1   uch 	}
    584      1.1   uch 	tx_conf_write(sc->sc_tc, TX39_MEMCONFIG3_REG, reg32);
    585      1.1   uch 
    586      1.8   uch #ifdef IT8368DEBUG
    587      1.8   uch 	if (sc->sc_fixattr)
    588      1.8   uch 		return; /* No need to report BIU status */
    589      1.8   uch 
    590      1.8   uch 	/* check BIU status */
    591      1.1   uch 	reg32 = tx_conf_read(sc->sc_tc, TX39_MEMCONFIG3_REG);
    592      1.8   uch 	if (reg32 & TX39_MEMCONFIG3_CARD1IOEN) {
    593      1.8   uch 		DPRINTF(("it8368_mode: I/O space (%dbit) enabled\n",
    594  1.9.4.1  fvdl 		    reg32 & TX39_MEMCONFIG3_PORT8SEL ? 8 : 16));
    595      1.8   uch 	} else {
    596      1.6   uch 		DPRINTF(("it8368_mode: atttribute space enabled\n"));
    597      1.8   uch 	}
    598      1.8   uch #endif /* IT8368DEBUG */
    599      1.1   uch }
    600      1.1   uch 
    601      1.1   uch int
    602  1.9.4.1  fvdl it8368_chip_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start,
    603  1.9.4.1  fvdl     bus_size_t size, bus_size_t align, struct pcmcia_io_handle *pcihp)
    604      1.1   uch {
    605      1.1   uch 	struct it8368e_softc *sc = (struct it8368e_softc*) pch;
    606      1.1   uch 
    607      1.1   uch 	if (start) {
    608      1.3   uch 		if (bus_space_map(sc->sc_csiot, start, size, 0,
    609  1.9.4.1  fvdl 		    &pcihp->ioh)) {
    610  1.9.4.1  fvdl 			return (1);
    611      1.1   uch 		}
    612      1.1   uch 		DPRINTF(("it8368_chip_io_alloc map port %#x+%#x\n",
    613  1.9.4.1  fvdl 		    (unsigned)start, (unsigned)size));
    614      1.1   uch 	} else {
    615      1.1   uch 		if (bus_space_alloc(sc->sc_csiot, sc->sc_csiobase,
    616  1.9.4.1  fvdl 		    sc->sc_csiobase + sc->sc_csiosize,
    617  1.9.4.1  fvdl 		    size, align, 0, 0, &pcihp->addr,
    618  1.9.4.1  fvdl 		    &pcihp->ioh)) {
    619      1.3   uch 
    620  1.9.4.1  fvdl 			return (1);
    621      1.1   uch 		}
    622      1.1   uch 		pcihp->flags = PCMCIA_IO_ALLOCATED;
    623      1.1   uch 		DPRINTF(("it8368_chip_io_alloc alloc %#x from %#x\n",
    624  1.9.4.1  fvdl 		    (unsigned)size, (unsigned)pcihp->addr));
    625      1.2   uch 	}
    626      1.1   uch 
    627      1.1   uch 	pcihp->iot = sc->sc_csiot;
    628      1.1   uch 	pcihp->size = size;
    629      1.1   uch 
    630  1.9.4.1  fvdl 	return (0);
    631      1.1   uch }
    632      1.1   uch 
    633      1.1   uch int
    634  1.9.4.1  fvdl it8368_chip_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset,
    635  1.9.4.1  fvdl     bus_size_t size, struct pcmcia_io_handle *pcihp, int *windowp)
    636      1.1   uch {
    637      1.6   uch 	/* I/O mode */
    638      1.6   uch 	it8368_mode(pch, IT8368_IO_MODE, IT8368_WIDTH_16);
    639      1.1   uch 
    640      1.8   uch 	DPRINTF(("it8368_chip_io_map %#x:%#x+%#x\n",
    641  1.9.4.1  fvdl 	    (unsigned)pcihp->ioh, (unsigned)offset, (unsigned)size));
    642      1.1   uch 
    643  1.9.4.1  fvdl 	return (0);
    644      1.1   uch }
    645      1.1   uch 
    646      1.1   uch void
    647  1.9.4.1  fvdl it8368_chip_io_free(pcmcia_chipset_handle_t pch,
    648  1.9.4.1  fvdl     struct pcmcia_io_handle *pcihp)
    649      1.1   uch {
    650      1.6   uch 	if (pcihp->flags & PCMCIA_IO_ALLOCATED)
    651      1.1   uch 		bus_space_free(pcihp->iot, pcihp->ioh, pcihp->size);
    652      1.6   uch 	else
    653      1.1   uch 		bus_space_unmap(pcihp->iot, pcihp->ioh, pcihp->size);
    654      1.6   uch 
    655      1.8   uch 	DPRINTF(("it8368_chip_io_free %#x+%#x\n",
    656  1.9.4.1  fvdl 	    (unsigned)pcihp->ioh, (unsigned)pcihp->size));
    657      1.1   uch }
    658      1.1   uch 
    659      1.1   uch void
    660  1.9.4.1  fvdl it8368_chip_io_unmap(pcmcia_chipset_handle_t pch, int window)
    661      1.1   uch {
    662  1.9.4.1  fvdl 
    663      1.1   uch }
    664      1.1   uch 
    665      1.1   uch void
    666  1.9.4.1  fvdl it8368_chip_socket_enable(pcmcia_chipset_handle_t pch)
    667      1.1   uch {
    668      1.8   uch #ifndef WINCE_DEFAULT_SETTING
    669      1.1   uch 	struct it8368e_softc *sc = (struct it8368e_softc*)pch;
    670      1.1   uch 	bus_space_tag_t csregt = sc->sc_csregt;
    671      1.1   uch 	bus_space_handle_t csregh = sc->sc_csregh;
    672      1.1   uch 	volatile u_int16_t reg;
    673      1.3   uch 
    674      1.1   uch 	/* Power off */
    675      1.1   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
    676      1.1   uch 	reg &= ~(IT8368_PIN_CRDVCCMASK | IT8368_PIN_CRDVPPMASK);
    677      1.1   uch 	reg |= (IT8368_PIN_CRDVCC_0V | IT8368_PIN_CRDVPP_0V);
    678      1.1   uch 	it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
    679      1.1   uch 	delay(20000);
    680      1.1   uch 
    681      1.1   uch 	/*
    682      1.1   uch 	 * wait 300ms until power fails (Tpf).  Then, wait 100ms since
    683      1.1   uch 	 * we are changing Vcc (Toff).
    684      1.1   uch 	 */
    685      1.1   uch 	delay((300 + 100) * 1000);
    686      1.1   uch 
    687      1.1   uch 	/* Supply Vcc */
    688      1.1   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
    689      1.1   uch 	reg &= ~(IT8368_PIN_CRDVCCMASK | IT8368_PIN_CRDVPPMASK);
    690      1.1   uch 	reg |= IT8368_PIN_CRDVCC_5V; /* XXX */
    691      1.1   uch 	it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
    692      1.1   uch 
    693      1.1   uch 	/*
    694      1.1   uch 	 * wait 100ms until power raise (Tpr) and 20ms to become
    695      1.1   uch 	 * stable (Tsu(Vcc)).
    696      1.1   uch 	 *
    697      1.1   uch 	 * some machines require some more time to be settled
    698      1.1   uch 	 * (300ms is added here).
    699      1.1   uch 	 */
    700      1.1   uch 	delay((100 + 20 + 300) * 1000);
    701      1.1   uch 
    702      1.1   uch 	/* Assert reset signal */
    703      1.1   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
    704      1.1   uch 	reg |= IT8368_PIN_BCRDRST;
    705      1.1   uch 	it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
    706      1.4   uch 
    707      1.1   uch 	/*
    708      1.1   uch 	 * hold RESET at least 10us.
    709      1.1   uch 	 */
    710      1.1   uch 	delay(10);
    711      1.4   uch 
    712      1.8   uch 	/* deassert reset signal */
    713      1.1   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
    714      1.1   uch 	reg &= ~IT8368_PIN_BCRDRST;
    715      1.1   uch 	it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
    716      1.1   uch 	delay(20000);
    717      1.1   uch 
    718      1.6   uch 	DPRINTF(("it8368_chip_socket_enable: socket enabled\n"));
    719      1.8   uch #endif /* !WINCE_DEFAULT_SETTING */
    720      1.1   uch }
    721      1.1   uch 
    722      1.1   uch void
    723  1.9.4.1  fvdl it8368_chip_socket_disable(pcmcia_chipset_handle_t pch)
    724      1.1   uch {
    725      1.8   uch #ifndef WINCE_DEFAULT_SETTING
    726      1.1   uch 	struct it8368e_softc *sc = (struct it8368e_softc*) pch;
    727      1.1   uch 	bus_space_tag_t csregt = sc->sc_csregt;
    728      1.1   uch 	bus_space_handle_t csregh = sc->sc_csregh;
    729      1.1   uch 	u_int16_t reg;
    730      1.1   uch 
    731      1.1   uch 	/* Power down */
    732      1.1   uch 	reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
    733      1.1   uch 	reg &= ~(IT8368_PIN_CRDVCCMASK | IT8368_PIN_CRDVPPMASK);
    734      1.1   uch 	reg |= (IT8368_PIN_CRDVCC_0V | IT8368_PIN_CRDVPP_0V);
    735      1.1   uch 	it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
    736      1.1   uch 	delay(20000);
    737      1.1   uch 
    738      1.1   uch 	/*
    739      1.1   uch 	 * wait 300ms until power fails (Tpf).
    740      1.1   uch 	 */
    741      1.1   uch 	delay(300 * 1000);
    742      1.4   uch 
    743      1.6   uch 	DPRINTF(("it8368_chip_socket_disable: socket disabled\n"));
    744      1.8   uch #endif /* !WINCE_DEFAULT_SETTING */
    745      1.1   uch }
    746      1.1   uch 
    747      1.7   uch #ifdef IT8368DEBUG
    748      1.8   uch #define PRINTGPIO(m) __bitdisp(it8368_reg_read(csregt, csregh,		\
    749      1.8   uch 	IT8368_GPIO##m##_REG), 0, IT8368_GPIO_MAX, #m, 1)
    750      1.8   uch #define PRINTMFIO(m) __bitdisp(it8368_reg_read(csregt, csregh,		\
    751      1.8   uch 	IT8368_MFIO##m##_REG), 0, IT8368_MFIO_MAX, #m, 1)
    752      1.1   uch void
    753  1.9.4.1  fvdl it8368_dump(struct it8368e_softc *sc)
    754      1.1   uch {
    755      1.1   uch 	bus_space_tag_t csregt = sc->sc_csregt;
    756      1.1   uch 	bus_space_handle_t csregh = sc->sc_csregh;
    757      1.1   uch 
    758      1.1   uch 	printf("[GPIO]\n");
    759      1.1   uch 	PRINTGPIO(DIR);
    760      1.1   uch 	PRINTGPIO(DATAIN);
    761      1.1   uch 	PRINTGPIO(DATAOUT);
    762      1.1   uch 	PRINTGPIO(POSINTEN);
    763      1.1   uch 	PRINTGPIO(NEGINTEN);
    764      1.1   uch 	PRINTGPIO(POSINTSTAT);
    765      1.1   uch 	PRINTGPIO(NEGINTSTAT);
    766      1.1   uch 	printf("[MFIO]\n");
    767      1.1   uch 	PRINTMFIO(SEL);
    768      1.1   uch 	PRINTMFIO(DIR);
    769      1.1   uch 	PRINTMFIO(DATAIN);
    770      1.1   uch 	PRINTMFIO(DATAOUT);
    771      1.1   uch 	PRINTMFIO(POSINTEN);
    772      1.1   uch 	PRINTMFIO(NEGINTEN);
    773      1.1   uch 	PRINTMFIO(POSINTSTAT);
    774      1.1   uch 	PRINTMFIO(NEGINTSTAT);
    775      1.3   uch 	__bitdisp(it8368_reg_read(csregt, csregh, IT8368_CTRL_REG), 0, 15,
    776  1.9.4.1  fvdl 	    "CTRL", 1);
    777      1.3   uch 	__bitdisp(it8368_reg_read(csregt, csregh, IT8368_GPIODATAIN_REG),
    778  1.9.4.1  fvdl 	    8, 11, "]CRDDET/SENSE[", 1);
    779      1.1   uch }
    780      1.7   uch #endif /* IT8368DEBUG */
    781