Home | History | Annotate | Line # | Download | only in isa
if_ntwoc_isa.c revision 1.3
      1  1.3  thorpej /*	$NetBSD: if_ntwoc_isa.c,v 1.3 2002/01/07 21:47:09 thorpej Exp $	*/
      2  1.1   chopps /*
      3  1.1   chopps  * Copyright (c) 1999 Christian E. Hopps
      4  1.1   chopps  * Copyright (c) 1996 John Hay.
      5  1.1   chopps  * Copyright (c) 1996 SDL Communications, Inc.
      6  1.1   chopps  * All rights reserved.
      7  1.1   chopps  *
      8  1.1   chopps  * Redistribution and use in source and binary forms, with or without
      9  1.1   chopps  * modification, are permitted provided that the following conditions
     10  1.1   chopps  * are met:
     11  1.1   chopps  * 1. Redistributions of source code must retain the above copyright
     12  1.1   chopps  *    notice, this list of conditions and the following disclaimer.
     13  1.1   chopps  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1   chopps  *    notice, this list of conditions and the following disclaimer in the
     15  1.1   chopps  *    documentation and/or other materials provided with the distribution.
     16  1.1   chopps  * 3. Neither the name of the author nor the names of any co-contributors
     17  1.1   chopps  *    may be used to endorse or promote products derived from this software
     18  1.1   chopps  *    without specific prior written permission.
     19  1.1   chopps  *
     20  1.1   chopps  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     21  1.1   chopps  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22  1.1   chopps  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23  1.1   chopps  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     24  1.1   chopps  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25  1.1   chopps  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26  1.1   chopps  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27  1.1   chopps  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28  1.1   chopps  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29  1.1   chopps  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30  1.1   chopps  * SUCH DAMAGE.
     31  1.1   chopps  *
     32  1.3  thorpej  * $Id: if_ntwoc_isa.c,v 1.3 2002/01/07 21:47:09 thorpej Exp $
     33  1.1   chopps  */
     34  1.1   chopps 
     35  1.2    lukem #include <sys/cdefs.h>
     36  1.3  thorpej __KERNEL_RCSID(0, "$NetBSD: if_ntwoc_isa.c,v 1.3 2002/01/07 21:47:09 thorpej Exp $");
     37  1.1   chopps 
     38  1.1   chopps #include <sys/param.h>
     39  1.1   chopps #include <sys/systm.h>
     40  1.1   chopps #include <sys/device.h>
     41  1.1   chopps #include <sys/mbuf.h>
     42  1.1   chopps #include <sys/socket.h>
     43  1.1   chopps 
     44  1.1   chopps #include <net/if.h>
     45  1.1   chopps 
     46  1.1   chopps #include <machine/cpu.h>
     47  1.1   chopps #include <machine/bus.h>
     48  1.1   chopps #include <machine/intr.h>
     49  1.1   chopps 
     50  1.1   chopps #include <dev/isa/isavar.h>
     51  1.1   chopps 
     52  1.1   chopps #include <dev/ic/hd64570reg.h>
     53  1.1   chopps #include <dev/ic/hd64570var.h>
     54  1.1   chopps 
     55  1.1   chopps #include <dev/isa/if_ntwoc_isareg.h>
     56  1.1   chopps 
     57  1.1   chopps #if 1
     58  1.1   chopps #define NTWO_DEBUG
     59  1.1   chopps #endif
     60  1.1   chopps 
     61  1.1   chopps #ifdef NTWO_DEBUG
     62  1.1   chopps #define NTWO_DPRINTF(x) printf x
     63  1.1   chopps #else
     64  1.1   chopps #define NTWO_DPRINTF(x)
     65  1.1   chopps #endif
     66  1.1   chopps 
     67  1.1   chopps #if __NetBSD_Version__ >= 104160000
     68  1.1   chopps static	void ntwoc_isa_config_interrupts __P((struct device *));
     69  1.1   chopps #else
     70  1.1   chopps #define	SCA_BASECLOCK	9830400
     71  1.1   chopps #endif
     72  1.1   chopps 
     73  1.1   chopps /* hard core 16k for now */
     74  1.1   chopps #define	NTWOC_WIN_SIZE	0x4000
     75  1.1   chopps 
     76  1.1   chopps struct ntwoc_isa_softc {
     77  1.1   chopps 	/* Generic device stuff */
     78  1.1   chopps 	struct device sc_dev;		/* Common to all devices */
     79  1.1   chopps 
     80  1.1   chopps 	/* PCI chipset glue */
     81  1.1   chopps 	void		*sc_ih;	/* Interrupt handler */
     82  1.1   chopps 	isa_chipset_tag_t sc_ic;	/* ISA chipset handle */
     83  1.1   chopps 
     84  1.1   chopps 	struct sca_softc sc_sca;	/* the SCA itself */
     85  1.1   chopps };
     86  1.1   chopps 
     87  1.1   chopps static  int ntwoc_isa_probe __P((struct device *, struct cfdata *, void *));
     88  1.1   chopps static  void ntwoc_isa_attach __P((struct device *, struct device *, void *));
     89  1.1   chopps 
     90  1.1   chopps static	void ntwoc_isa_clock_callback __P((void *, int, int));
     91  1.1   chopps static	void ntwoc_isa_dtr_callback __P((void *, int, int));
     92  1.1   chopps static	int ntwoc_isa_intr __P((void *));
     93  1.1   chopps static	void ntwoc_isa_get_clock __P((struct sca_port *, u_int8_t, u_int8_t,
     94  1.1   chopps     u_int8_t, u_int8_t));
     95  1.1   chopps static	void ntwoc_isa_setup_memory(struct sca_softc *sc);
     96  1.1   chopps static	void ntwoc_isa_shutdown __P((void *sc));
     97  1.1   chopps 
     98  1.1   chopps struct cfattach ntwoc_isa_ca = {
     99  1.1   chopps 	sizeof(struct ntwoc_isa_softc), ntwoc_isa_probe, ntwoc_isa_attach,
    100  1.1   chopps };
    101  1.1   chopps 
    102  1.1   chopps /*
    103  1.1   chopps  * Names for daughter card types.  These match the NTWOC_DB_* defines.
    104  1.1   chopps  */
    105  1.1   chopps char *ntwoc_db_names[] = {
    106  1.1   chopps 	"V.35", "Unknown 0x01", "Test", "Unknown 0x03",
    107  1.1   chopps 	"RS232", "Unknown 0x05", "RS422", "None"
    108  1.1   chopps };
    109  1.1   chopps 
    110  1.1   chopps /* some weird offset XXX */
    111  1.1   chopps #define SCA_REG(r)	(((r) & 0xf) + (((r) & 0xf0) << 6))
    112  1.1   chopps 
    113  1.1   chopps /*
    114  1.1   chopps  * functions that read and write to the sca registers
    115  1.1   chopps  */
    116  1.1   chopps static void
    117  1.1   chopps ntwoc_isa_sca_write_1(struct sca_softc *sc, u_int reg, u_int8_t val)
    118  1.1   chopps {
    119  1.1   chopps 	bus_space_write_1(sc->sc_iot, sc->scu_sca_ioh[(reg & 0xf0) >> 4],
    120  1.1   chopps 	    (reg & 0xf), val);
    121  1.1   chopps }
    122  1.1   chopps 
    123  1.1   chopps static void
    124  1.1   chopps ntwoc_isa_sca_write_2(struct sca_softc *sc, u_int reg, u_int16_t val)
    125  1.1   chopps {
    126  1.1   chopps 	bus_space_write_2(sc->sc_iot, sc->scu_sca_ioh[(reg & 0xf0) >> 4],
    127  1.1   chopps 	    (reg & 0xf), val);
    128  1.1   chopps }
    129  1.1   chopps 
    130  1.1   chopps static u_int8_t
    131  1.1   chopps ntwoc_isa_sca_read_1(struct sca_softc *sc, u_int reg)
    132  1.1   chopps {
    133  1.1   chopps 	return
    134  1.1   chopps 	    bus_space_read_1(sc->sc_iot, sc->scu_sca_ioh[(reg & 0xf0) >> 4],
    135  1.1   chopps 	    (reg & 0xf));
    136  1.1   chopps }
    137  1.1   chopps 
    138  1.1   chopps static u_int16_t
    139  1.1   chopps ntwoc_isa_sca_read_2(struct sca_softc *sc, u_int reg)
    140  1.1   chopps {
    141  1.1   chopps 	return
    142  1.1   chopps 	    bus_space_read_2(sc->sc_iot, sc->scu_sca_ioh[(reg & 0xf0) >> 4],
    143  1.1   chopps 	    (reg & 0xf));
    144  1.1   chopps }
    145  1.1   chopps 
    146  1.1   chopps /*
    147  1.1   chopps  * set the correct window/page
    148  1.1   chopps  */
    149  1.1   chopps static void
    150  1.1   chopps ntwoc_isa_set_page(struct sca_softc *sca, bus_addr_t addr)
    151  1.1   chopps {
    152  1.1   chopps 	u_int8_t psr;
    153  1.1   chopps 
    154  1.1   chopps 	/* get old psr value replace old window with new */
    155  1.1   chopps 	psr = bus_space_read_1(sca->sc_iot, sca->sc_ioh, NTWOC_PSR);
    156  1.1   chopps 	psr &= ~NTWOC_PG_MSK;
    157  1.1   chopps 	psr |= ((addr >> sca->scu_pageshift) & NTWOC_PG_MSK);
    158  1.1   chopps 	bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_PSR, psr);
    159  1.1   chopps }
    160  1.1   chopps 
    161  1.1   chopps /*
    162  1.1   chopps  * enable the memory window
    163  1.1   chopps  */
    164  1.1   chopps static void
    165  1.1   chopps ntwoc_isa_set_on(struct sca_softc *sca)
    166  1.1   chopps {
    167  1.1   chopps 	u_int8_t pcr;
    168  1.1   chopps 
    169  1.1   chopps 	/* get old value and add window enable */
    170  1.1   chopps 	pcr = bus_space_read_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR);
    171  1.1   chopps 	pcr |= NTWOC_PCR_MEM_WIN;
    172  1.1   chopps 	bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR, pcr);
    173  1.1   chopps }
    174  1.1   chopps 
    175  1.1   chopps /*
    176  1.1   chopps  * turn off memory window
    177  1.1   chopps  */
    178  1.1   chopps static void
    179  1.1   chopps ntwoc_isa_set_off(struct sca_softc *sca)
    180  1.1   chopps {
    181  1.1   chopps 	u_int8_t pcr;
    182  1.1   chopps 
    183  1.1   chopps 	/* get old value and remove window enable */
    184  1.1   chopps 	pcr = bus_space_read_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR);
    185  1.1   chopps 	pcr &= ~NTWOC_PCR_MEM_WIN;
    186  1.1   chopps 	bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR, pcr);
    187  1.1   chopps }
    188  1.1   chopps 
    189  1.1   chopps static int
    190  1.1   chopps ntwoc_isa_probe(struct device *parent, struct cfdata *match, void *aux)
    191  1.1   chopps {
    192  1.1   chopps 	struct isa_attach_args *ia;
    193  1.1   chopps 	bus_space_tag_t iot, memt;
    194  1.1   chopps 	bus_space_handle_t ioh, memh, sca_ioh[16];
    195  1.1   chopps 	int i, tmp, dbg, rv;
    196  1.1   chopps 	int gotmem, gotsca[16];
    197  1.1   chopps 	u_int32_t ioport;
    198  1.1   chopps 
    199  1.1   chopps 	ia = (struct isa_attach_args *)aux;
    200  1.1   chopps 	iot = ia->ia_iot;
    201  1.1   chopps 	memt = ia->ia_memt;
    202  1.1   chopps 
    203  1.3  thorpej 	if (ia->ia_nio < 1)
    204  1.3  thorpej 		return (0);
    205  1.3  thorpej 	if (ia->ia_niomem < 1)
    206  1.3  thorpej 		return (0);
    207  1.3  thorpej 	if (ia->ia_nirq < 1)
    208  1.3  thorpej 		return (0);
    209  1.3  thorpej 
    210  1.3  thorpej 	if (ISA_DIRECT_CONFIG(ia))
    211  1.3  thorpej 		return (0);
    212  1.3  thorpej 
    213  1.1   chopps 	memset(gotsca, 0, sizeof(gotsca));
    214  1.1   chopps 	gotmem = rv = 0;
    215  1.1   chopps 	dbg = 0;
    216  1.1   chopps 
    217  1.1   chopps 	/* disallow wildcarded I/O base */
    218  1.3  thorpej 	if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT) {
    219  1.1   chopps 		printf("ntwoc_isa_probe: must specify port address\n");
    220  1.1   chopps 		return (0);
    221  1.1   chopps 	}
    222  1.1   chopps 
    223  1.3  thorpej 	if (ia->ia_irq[0].ir_irq == ISACF_IRQ_DEFAULT) {
    224  1.1   chopps 		printf("ntwoc_isa_probe: must specify irq\n");
    225  1.1   chopps 		return (0);
    226  1.1   chopps 	}
    227  1.1   chopps 
    228  1.3  thorpej 	if (ia->ia_iomem[0].ir_addr == ISACF_IOMEM_DEFAULT) {
    229  1.1   chopps 		printf("ntwoc_isa_probe: must specify iomem\n");
    230  1.1   chopps 		return (0);
    231  1.1   chopps 	}
    232  1.1   chopps 
    233  1.1   chopps 	tmp = (match->cf_flags & NTWOC_FLAGS_NPORT_MASK) + 1;
    234  1.1   chopps 	if (tmp < 1 || tmp > 2) {
    235  1.1   chopps 		printf("ntwoc_isa_probe: only 1 or 2 ports allowed\n");
    236  1.1   chopps 		return (0);
    237  1.1   chopps 	}
    238  1.1   chopps 
    239  1.1   chopps 	/* map the isa io addresses */
    240  1.3  thorpej 	if ((tmp = bus_space_map(iot, ia->ia_io[0].ir_addr,
    241  1.3  thorpej 	     NTWOC_SRC_IOPORT_SIZE, 0, &ioh))) {
    242  1.1   chopps 		printf("ntwoc_isa_probe: mapping port 0x%x sz %d failed: %d\n",
    243  1.3  thorpej 		    ia->ia_io[0].ir_addr, NTWOC_SRC_IOPORT_SIZE, tmp);
    244  1.1   chopps 		return (0);
    245  1.1   chopps 	}
    246  1.1   chopps 
    247  1.3  thorpej 	ioport = ia->ia_io[0].ir_addr + 0x8000;
    248  1.1   chopps 	for (i = 0; i < 16; ioport += (0x10 << 6), i++) {
    249  1.1   chopps 		/* map the isa io addresses */
    250  1.1   chopps 		if ((tmp = bus_space_map(iot, ioport, 16, 0, &sca_ioh[i]))) {
    251  1.1   chopps 			printf(
    252  1.1   chopps 			 "ntwoc_isa_probe: mapping sca 0x%x sz %d failed: %d\n",
    253  1.1   chopps 			    ioport, 16, tmp);
    254  1.1   chopps 			goto out;
    255  1.1   chopps 		}
    256  1.1   chopps 		gotsca[i] = 1;
    257  1.1   chopps 	}
    258  1.1   chopps 
    259  1.1   chopps 	/* map the isa memory addresses */
    260  1.1   chopps 	/* XXX we really want the user to select this */
    261  1.3  thorpej 	if ((tmp = bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr,
    262  1.3  thorpej 	     NTWOC_WIN_SIZE, 0, &memh))) {
    263  1.1   chopps 		printf("ntwoc_isa_probe: mapping mem 0x%x sz %d failed: %d\n",
    264  1.3  thorpej 		    ia->ia_iomem[0].ir_addr, NTWOC_WIN_SIZE, tmp);
    265  1.1   chopps 		goto out;
    266  1.1   chopps 	}
    267  1.1   chopps 	gotmem = 1;
    268  1.1   chopps 
    269  1.1   chopps 	/* turn off the card */
    270  1.1   chopps 	bus_space_write_1(iot, ioh, NTWOC_PCR, 0);
    271  1.1   chopps 
    272  1.1   chopps 	/*
    273  1.1   chopps 	 * Next, we'll test the Base Address Register to retension of
    274  1.1   chopps 	 * data... ... seeing if we're *really* talking to an N2.
    275  1.1   chopps 	 */
    276  1.1   chopps 	for (i = 0; i < 0x100; i++) {
    277  1.1   chopps 		bus_space_write_1(iot, ioh, NTWOC_BAR, i);
    278  1.1   chopps 		(void)bus_space_read_1(iot, ioh, NTWOC_PCR);
    279  1.1   chopps 		if (bus_space_read_1(iot, ioh, NTWOC_BAR) != i) {
    280  1.1   chopps 			printf("ntwoc_isa_probe failed (BAR %x, %x)\n", i, tmp);
    281  1.1   chopps 			goto out;
    282  1.1   chopps 		}
    283  1.1   chopps 	}
    284  1.1   chopps 
    285  1.1   chopps 	/* XXX XXX update the calls to SCA_REG to use our mapping */
    286  1.1   chopps 
    287  1.1   chopps 	/*
    288  1.1   chopps 	 * Now see if we can see the SCA.
    289  1.1   chopps 	 */
    290  1.1   chopps 	bus_space_write_1(iot, ioh, NTWOC_PCR,
    291  1.1   chopps 	     NTWOC_PCR_SCARUN | bus_space_read_1(iot, ioh, NTWOC_PCR));
    292  1.1   chopps 	bus_space_write_1(iot, sca_ioh[0], SCA_REG(SCA_WCRL), 0);
    293  1.1   chopps 	bus_space_write_1(iot, sca_ioh[0], SCA_REG(SCA_WCRM), 0);
    294  1.1   chopps 	bus_space_write_1(iot, sca_ioh[0], SCA_REG(SCA_WCRH), 0);
    295  1.1   chopps 	bus_space_write_1(iot, sca_ioh[0], SCA_REG(SCA_PCR), 0);
    296  1.1   chopps 
    297  1.1   chopps 	bus_space_write_1(iot, sca_ioh[0], SCA_REG(SCA_TMC0), 0);
    298  1.1   chopps 	(void)bus_space_read_1(iot, ioh, 0);
    299  1.1   chopps 	if ((tmp = bus_space_read_1(iot, sca_ioh[0], SCA_REG(SCA_TMC0))) != 0) {
    300  1.1   chopps 		printf("ntwoc_isa_probe: Error reading SCA (TMC0 0, %x)\n",
    301  1.1   chopps 		   tmp);
    302  1.1   chopps 		goto out;
    303  1.1   chopps 	}
    304  1.1   chopps 
    305  1.1   chopps 	bus_space_write_1(iot, sca_ioh[0], SCA_REG(SCA_TMC0), 0x5A);
    306  1.1   chopps 	(void)bus_space_read_1(iot, ioh, 0);
    307  1.1   chopps 
    308  1.1   chopps 	tmp = bus_space_read_1(iot, sca_ioh[0], SCA_REG(SCA_TMC0));
    309  1.1   chopps 	if (tmp != 0x5A) {
    310  1.1   chopps 		printf("ntwoc_isa_probe: Error reading SCA (TMC0 5A, %x)\n",
    311  1.1   chopps 		    tmp);
    312  1.1   chopps 		goto out;
    313  1.1   chopps 	}
    314  1.1   chopps 
    315  1.1   chopps 	bus_space_write_2(iot, sca_ioh[0], SCA_REG(SCA_CDAL0), 0);
    316  1.1   chopps 	(void)bus_space_read_1(iot, ioh, 0);
    317  1.1   chopps 	tmp = bus_space_read_2(iot, sca_ioh[0], SCA_REG(SCA_CDAL0));
    318  1.1   chopps 	if (tmp != 0) {
    319  1.1   chopps 		printf("ntwoc_isa_probe: Error reading SCA (CDAL0 0, %x)\n",
    320  1.1   chopps 		    tmp);
    321  1.1   chopps 		goto out;
    322  1.1   chopps 	}
    323  1.1   chopps 
    324  1.1   chopps 	bus_space_write_2(iot, sca_ioh[0], SCA_REG(SCA_CDAL0), 0x55AA);
    325  1.1   chopps 	(void)bus_space_read_1(iot, ioh, 0);
    326  1.1   chopps 	tmp = bus_space_read_2(iot, sca_ioh[0], SCA_REG(SCA_CDAL0));
    327  1.1   chopps 	if (tmp != 0x55AA) {
    328  1.1   chopps 		printf("ntwoc_isa_probe: Error reading SCA (CDAL0 55AA, %x)\n",
    329  1.1   chopps 		    tmp);
    330  1.1   chopps 		goto out;
    331  1.1   chopps 	}
    332  1.1   chopps 
    333  1.1   chopps 	/*
    334  1.1   chopps 	 * I had a weird card that didn't function correctly on a certain
    335  1.1   chopps 	 * newer MB.  I suspect it was the whacky port addresses.
    336  1.1   chopps 	 * The following correctly failed it.
    337  1.1   chopps 	 */
    338  1.1   chopps 	bus_space_write_2(iot, sca_ioh[0], SCA_REG(SCA_TCNTL0), 0x0);
    339  1.1   chopps 	(void)bus_space_read_1(iot, ioh, 0);
    340  1.1   chopps 	tmp = bus_space_read_2(iot, sca_ioh[0], SCA_REG(SCA_TCNTL0));
    341  1.1   chopps 	if (tmp != 0) {
    342  1.1   chopps 		printf("ntwoc_isa_probe: Error reading SCA (TCNTL0 0, %x)\n",
    343  1.1   chopps 		    tmp);
    344  1.1   chopps 		goto out;
    345  1.1   chopps 	}
    346  1.1   chopps 
    347  1.1   chopps 	bus_space_write_2(iot, sca_ioh[0], SCA_REG(SCA_TCNTL0), 0x55AA);
    348  1.1   chopps 	(void)bus_space_read_1(iot, ioh, 0);
    349  1.1   chopps 	tmp = bus_space_read_2(iot, sca_ioh[0], SCA_REG(SCA_TCNTL0));
    350  1.1   chopps 	if (tmp != 0x55AA) {
    351  1.1   chopps 		printf("ntwoc_isa_probe: Error reading SCA (TCNTL0 55AA, %x)\n",
    352  1.1   chopps 		    tmp);
    353  1.1   chopps 		goto out;
    354  1.1   chopps 	}
    355  1.1   chopps 
    356  1.3  thorpej 	ia->ia_nio = 1;
    357  1.3  thorpej 	ia->ia_io[0].ir_size = NTWOC_SRC_IOPORT_SIZE;
    358  1.3  thorpej 
    359  1.3  thorpej 	ia->ia_niomem = 1;
    360  1.3  thorpej 	ia->ia_iomem[0].ir_size = NTWOC_WIN_SIZE;
    361  1.3  thorpej 
    362  1.3  thorpej 	ia->ia_nirq = 1;
    363  1.3  thorpej 
    364  1.3  thorpej 	ia->ia_ndrq = 0;
    365  1.3  thorpej 
    366  1.1   chopps 	rv = 1;
    367  1.1   chopps out:
    368  1.1   chopps 	/* turn off the card */
    369  1.1   chopps 	bus_space_write_1(iot, ioh, NTWOC_PCR, 0);
    370  1.1   chopps 
    371  1.1   chopps 	if (gotmem)
    372  1.1   chopps 		bus_space_unmap(memt, memh, NTWOC_WIN_SIZE);
    373  1.1   chopps 	for (i = 0; i < 16; i++) {
    374  1.1   chopps 		if (gotsca[i])
    375  1.1   chopps 			bus_space_unmap(iot, sca_ioh[i], 16);
    376  1.1   chopps 	}
    377  1.1   chopps 	bus_space_unmap(iot, ioh, NTWOC_SRC_IOPORT_SIZE);
    378  1.1   chopps 	return (rv);
    379  1.1   chopps }
    380  1.1   chopps 
    381  1.1   chopps /*
    382  1.1   chopps  * we win! attach the card
    383  1.1   chopps  */
    384  1.1   chopps static void
    385  1.1   chopps ntwoc_isa_attach(struct device *parent, struct device *self, void *aux)
    386  1.1   chopps {
    387  1.1   chopps 	struct ntwoc_isa_softc *sc;
    388  1.1   chopps 	struct isa_attach_args *ia;
    389  1.1   chopps 	struct sca_softc *sca;
    390  1.1   chopps 	bus_addr_t addr;
    391  1.1   chopps 	u_int8_t rdiv, tdiv, tmc;
    392  1.1   chopps 	u_int32_t flags, ioport;
    393  1.1   chopps 	u_int16_t tmp;
    394  1.1   chopps 	int i, dbg, pgs, rv;
    395  1.1   chopps 
    396  1.1   chopps 	ia = (struct isa_attach_args *)aux;
    397  1.1   chopps 	sc = (struct ntwoc_isa_softc *)self;
    398  1.1   chopps 	sca = &sc->sc_sca;
    399  1.1   chopps 	dbg = 0;
    400  1.1   chopps 
    401  1.1   chopps 	printf(": N2 Serial Interface\n");
    402  1.1   chopps 	flags = sc->sc_dev.dv_cfdata->cf_flags;
    403  1.1   chopps 
    404  1.1   chopps 	sc->sc_ic = ia->ia_ic;
    405  1.1   chopps 	sca->sc_parent = &sc->sc_dev;
    406  1.1   chopps 	sca->sc_numports = (flags & NTWOC_FLAGS_NPORT_MASK) + 1;
    407  1.1   chopps 	sca->sc_usedma = 0;
    408  1.1   chopps 	sca->sc_aux = sc;
    409  1.1   chopps 	sca->sc_dtr_callback = ntwoc_isa_dtr_callback;
    410  1.1   chopps 	sca->sc_clock_callback = ntwoc_isa_clock_callback;
    411  1.1   chopps 	sca->sc_read_1 = ntwoc_isa_sca_read_1;
    412  1.1   chopps 	sca->sc_read_2 = ntwoc_isa_sca_read_2;
    413  1.1   chopps 	sca->sc_write_1 = ntwoc_isa_sca_write_1;
    414  1.1   chopps 	sca->sc_write_2 = ntwoc_isa_sca_write_2;
    415  1.1   chopps 	sca->scu_set_page = ntwoc_isa_set_page;
    416  1.1   chopps 	sca->scu_page_on = ntwoc_isa_set_on;
    417  1.1   chopps 	sca->scu_page_off = ntwoc_isa_set_off;
    418  1.1   chopps 
    419  1.1   chopps 	/* map the io */
    420  1.1   chopps 	sca->sc_iot = ia->ia_iot;
    421  1.3  thorpej 	if ((rv = bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr,
    422  1.1   chopps 	    NTWOC_SRC_IOPORT_SIZE, 0, &sca->sc_ioh))) {
    423  1.1   chopps 		printf("%s: can't map io 0x%x sz %d, %d\n",
    424  1.3  thorpej 		    sc->sc_dev.dv_xname, ia->ia_io[0].ir_addr,
    425  1.3  thorpej 		    NTWOC_SRC_IOPORT_SIZE, rv);
    426  1.1   chopps 		return;
    427  1.1   chopps 	}
    428  1.1   chopps 
    429  1.1   chopps 	/* support weird mapping (they used this to avoid 10-bit aliasing) */
    430  1.3  thorpej 	ioport = ia->ia_io[0].ir_addr + 0x8000;
    431  1.1   chopps 	for (i = 0; i < 16; ioport += (0x10 << 6), i++) {
    432  1.1   chopps 		/* map the isa io addresses */
    433  1.1   chopps 		if ((tmp = bus_space_map(ia->ia_iot, ioport, 16, 0,
    434  1.1   chopps 		    &sca->scu_sca_ioh[i]))) {
    435  1.1   chopps 			printf("%s: mapping sca 0x%x sz %d failed: %d\n",
    436  1.1   chopps 			    sc->sc_dev.dv_xname, ioport, 16, tmp);
    437  1.1   chopps 			return;
    438  1.1   chopps 		}
    439  1.1   chopps 	}
    440  1.1   chopps 
    441  1.1   chopps 	/* map the isa memory */
    442  1.1   chopps 	sca->scu_memt = ia->ia_memt;
    443  1.1   chopps 	sca->scu_pagesize = 0x4000;	/* force 16k for now */
    444  1.1   chopps 	if (sca->scu_pagesize < 0x8000) {
    445  1.1   chopps 		/* round down to 16k */
    446  1.1   chopps 		sca->scu_pagesize = 0x4000;
    447  1.1   chopps 		sca->scu_pageshift = 14;
    448  1.1   chopps 		tmp = NTWOC_PSR_WIN_16K;
    449  1.1   chopps 	} else if (sca->scu_pagesize < 0x10000) {
    450  1.1   chopps 		/* round down to 32k */
    451  1.1   chopps 		sca->scu_pagesize = 0x8000;
    452  1.1   chopps 		sca->scu_pageshift = 15;
    453  1.1   chopps 		tmp = NTWOC_PSR_WIN_32K;
    454  1.1   chopps 	} else if (sca->scu_pagesize < 0x20000) {
    455  1.1   chopps 		/* round down to 64k */
    456  1.1   chopps 		sca->scu_pagesize = 0x10000;
    457  1.1   chopps 		sca->scu_pageshift = 16;
    458  1.1   chopps 		tmp = NTWOC_PSR_WIN_64K;
    459  1.1   chopps 	} else {
    460  1.1   chopps 		sca->scu_pagesize = 0x20000;
    461  1.1   chopps 		sca->scu_pageshift = 17;
    462  1.1   chopps 		tmp = NTWOC_PSR_WIN_128K;
    463  1.1   chopps 	}
    464  1.1   chopps 	sca->scu_pagemask = sca->scu_pagesize - 1;
    465  1.3  thorpej 	if ((rv = bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr,
    466  1.3  thorpej 	     sca->scu_pagesize, 0, &sca->scu_memh))) {
    467  1.1   chopps 		printf("%s: can't map mem 0x%x sz %ld, %d\n",
    468  1.3  thorpej 		    sc->sc_dev.dv_xname, ia->ia_iomem[0].ir_addr,
    469  1.3  thorpej 		    sca->scu_pagesize, rv);
    470  1.1   chopps 		return;
    471  1.1   chopps 	}
    472  1.1   chopps 
    473  1.1   chopps 	/* turn the card on!! */
    474  1.1   chopps 	bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR,
    475  1.1   chopps 	    bus_space_read_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR)
    476  1.1   chopps 	    | NTWOC_PCR_SCARUN);
    477  1.1   chopps 
    478  1.1   chopps 	/* set the window size to 16k */
    479  1.1   chopps 	bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_PSR, tmp);
    480  1.1   chopps 
    481  1.1   chopps 	/* reset mcr */
    482  1.1   chopps 	bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_MCR,
    483  1.1   chopps 	    NTWOC_MCR_DTR0 | NTWOC_MCR_DTR1 | NTWOC_MCR_TE0 | NTWOC_MCR_TE1);
    484  1.1   chopps 
    485  1.1   chopps 
    486  1.1   chopps 	/* allow for address above 1M and 16 bit i/o */
    487  1.1   chopps #if 0
    488  1.1   chopps 	bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR,
    489  1.1   chopps 	    bus_space_read_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR)
    490  1.1   chopps 	    | NTWOC_PCR_EN_VPM | NTWOC_PCR_ISA16);
    491  1.1   chopps #endif
    492  1.1   chopps 	bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR,
    493  1.1   chopps 	    bus_space_read_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR)
    494  1.1   chopps 	    | NTWOC_PCR_ISA16);
    495  1.1   chopps 
    496  1.1   chopps 	/* program the card with the io address */
    497  1.1   chopps 	bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR,
    498  1.3  thorpej 	    ((ia->ia_iomem[0].ir_addr >> 16) & NTWOC_PCR_16M_SEL)
    499  1.1   chopps 	    |
    500  1.1   chopps 	    (bus_space_read_1(sca->sc_iot, sca->sc_ioh, NTWOC_PCR)
    501  1.1   chopps 	    & ~NTWOC_PCR_16M_SEL));
    502  1.1   chopps 	bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_BAR,
    503  1.3  thorpej 	    (ia->ia_iomem[0].ir_addr >> 12));
    504  1.1   chopps 
    505  1.1   chopps 	/* enable the memory window */
    506  1.1   chopps 	ntwoc_isa_set_on(sca);
    507  1.1   chopps 
    508  1.1   chopps 	/*
    509  1.1   chopps 	 * write a magic value into each possible page of memory
    510  1.1   chopps 	 * incrementing by our window size
    511  1.1   chopps 	 */
    512  1.1   chopps 	addr = 0;
    513  1.1   chopps 	for (i = 0; i <= NTWOC_PSR_PG_SEL; addr += sca->scu_pagesize, i++) {
    514  1.1   chopps 		/* select the page */
    515  1.1   chopps 		ntwoc_isa_set_page(sca, addr);
    516  1.1   chopps 		bus_space_write_2(sca->scu_memt, sca->scu_memh, 0, 0xAA55);
    517  1.1   chopps 	}
    518  1.1   chopps 
    519  1.1   chopps 	/*
    520  1.1   chopps 	 * go back through pages and verify that value is different
    521  1.1   chopps 	 * after writing to previous page
    522  1.1   chopps 	 */
    523  1.1   chopps 	addr = 0;
    524  1.1   chopps 	for (i = 0; i <= NTWOC_PSR_PG_SEL; addr += sca->scu_pagesize, i++) {
    525  1.1   chopps 		ntwoc_isa_set_page(sca, addr);
    526  1.1   chopps 
    527  1.1   chopps 		tmp = bus_space_read_2(sca->scu_memt, sca->scu_memh, 0);
    528  1.1   chopps 		if (tmp != 0xAA55)
    529  1.1   chopps 			break;
    530  1.1   chopps 
    531  1.1   chopps 		/* write a different value into this page now */
    532  1.1   chopps 		bus_space_write_2(sca->scu_memt, sca->scu_memh, 0, i);
    533  1.1   chopps 	}
    534  1.1   chopps 	sca->scu_npages = pgs = i;	/* final count of 16K pages */
    535  1.1   chopps 
    536  1.1   chopps 	/* erase the pages */
    537  1.1   chopps 	addr = 0;
    538  1.1   chopps 	for (i = 0; i <= pgs; addr += sca->scu_pagesize, i++) {
    539  1.1   chopps 		ntwoc_isa_set_page(sca, addr);
    540  1.1   chopps 		bus_space_set_region_1(sca->scu_memt, sca->scu_memh, 0, 0,
    541  1.1   chopps 		    sca->scu_pagesize);
    542  1.1   chopps 	}
    543  1.1   chopps 
    544  1.1   chopps #if 0
    545  1.1   chopps 	printf("%s: sca port 0x%x-0x%x dpram %ldk %d serial port%s\n",
    546  1.3  thorpej 	    sc->sc_dev.dv_xname, ia->ia_io[0].ir_addr | 0x8000,
    547  1.3  thorpej 	    (ia->ia_io[0].ir_addr | 0x8000) + NTWOC_SRC_ASIC_SIZE - 1,
    548  1.1   chopps 	    pgs * (sca->scu_pagesize / 1024), sca->sc_numports,
    549  1.1   chopps 	    (sca->sc_numports > 1 ? "s" : ""));
    550  1.1   chopps #else
    551  1.1   chopps 	printf("%s: dpram %ldk %d serial port%s\n",
    552  1.1   chopps 	    sc->sc_dev.dv_xname, pgs * (sca->scu_pagesize / 1024),
    553  1.1   chopps 	    sca->sc_numports, (sca->sc_numports > 1 ? "s" : ""));
    554  1.1   chopps #endif
    555  1.1   chopps 
    556  1.1   chopps 	/* disable the memory window */
    557  1.1   chopps 	ntwoc_isa_set_off(sca);
    558  1.1   chopps 
    559  1.1   chopps 	/* enabled sca dma */
    560  1.1   chopps 	bus_space_write_1(sca->sc_iot, sca->sc_ioh, NTWOC_PSR,
    561  1.1   chopps 	    bus_space_read_1(sca->sc_iot, sca->sc_ioh, NTWOC_PSR)
    562  1.1   chopps 	    | NTWOC_PSR_EN_SCA_DMA);
    563  1.1   chopps 
    564  1.1   chopps 	/* now establish our irq -- perhaps sanity check the value */
    565  1.3  thorpej 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
    566  1.3  thorpej 	    IST_EDGE, IPL_NET, ntwoc_isa_intr, sc);
    567  1.1   chopps 	if (sc->sc_ih == NULL) {
    568  1.1   chopps 		printf("%s: can't establish interrupt\n",
    569  1.1   chopps 		    sc->sc_dev.dv_xname);
    570  1.1   chopps 		return;
    571  1.1   chopps 	}
    572  1.1   chopps 
    573  1.1   chopps 	/* make sure we have 2 pages for each port */
    574  1.1   chopps 	if (pgs < 2 * sca->sc_numports) {
    575  1.1   chopps 		printf("%s: %d less than required pages of memory of %d\n",
    576  1.1   chopps 		    sc->sc_dev.dv_xname, pgs, 2 * sca->sc_numports);
    577  1.1   chopps 		return;
    578  1.1   chopps 	}
    579  1.1   chopps 
    580  1.1   chopps 	/* sca_get_base_clock(sca); */
    581  1.1   chopps 
    582  1.1   chopps 	/*
    583  1.1   chopps 	 * get clock information from user
    584  1.1   chopps 	 */
    585  1.1   chopps 	rdiv = (flags & NTWOC_FLAGS_RXDIV_MASK) >> NTWOC_FLAGS_RXDIV_SHIFT;
    586  1.1   chopps 	if (rdiv > 9)
    587  1.1   chopps 		panic("bad rx divisor in flags");
    588  1.1   chopps 
    589  1.1   chopps 	tdiv = (flags & NTWOC_FLAGS_TXDIV_MASK) >> NTWOC_FLAGS_TXDIV_SHIFT;
    590  1.1   chopps 	if (tdiv > 9)
    591  1.1   chopps 		panic("bad tx divisor in flags");
    592  1.1   chopps 	tmc = (flags & NTWOC_FLAGS_TMC_MASK) >> NTWOC_FLAGS_TMC_SHIFT;
    593  1.1   chopps 
    594  1.1   chopps 	ntwoc_isa_get_clock(&sca->sc_ports[0],
    595  1.1   chopps 	    flags & NTWOC_FLAGS_CLK0_MASK, tmc, rdiv, tdiv);
    596  1.1   chopps 	if (sca->sc_numports > 1)
    597  1.1   chopps 		ntwoc_isa_get_clock(&sca->sc_ports[1],
    598  1.1   chopps 		    (flags & NTWOC_FLAGS_CLK1_MASK) >> NTWOC_FLAGS_CLK1_SHIFT,
    599  1.1   chopps 		    tmc, rdiv, tdiv);
    600  1.1   chopps 
    601  1.1   chopps 	ntwoc_isa_setup_memory(sca);
    602  1.1   chopps 
    603  1.1   chopps 	sca_init(sca);
    604  1.1   chopps 
    605  1.1   chopps 	/* attach configured ports */
    606  1.1   chopps 	sca_port_attach(sca, 0);
    607  1.1   chopps 	if (sca->sc_numports == 2)
    608  1.1   chopps 		sca_port_attach(sca, 1);
    609  1.1   chopps 
    610  1.1   chopps 	/*
    611  1.1   chopps 	 * Add shutdown hook so that DMA is disabled prior to reboot. Not
    612  1.1   chopps 	 * doing do could allow DMA to corrupt kernel memory during the
    613  1.1   chopps 	 * reboot before the driver initializes.
    614  1.1   chopps 	 */
    615  1.1   chopps 	shutdownhook_establish(ntwoc_isa_shutdown, sc);
    616  1.1   chopps 
    617  1.1   chopps #if __NetBSD_Version__ >= 104160000
    618  1.1   chopps 	/*
    619  1.1   chopps 	 * defer getting the base clock until interrupts are enabled
    620  1.1   chopps 	 * (and thus we have microtime())
    621  1.1   chopps 	 */
    622  1.1   chopps 	config_interrupts(self, ntwoc_isa_config_interrupts);
    623  1.1   chopps #else
    624  1.1   chopps 	/* no callback pre 1.4-mumble */
    625  1.1   chopps 	sca->sc_baseclock = SCA_BASECLOCK;
    626  1.1   chopps 	sca_print_clock_info(&sc->sc_sca);
    627  1.1   chopps #endif
    628  1.1   chopps }
    629  1.1   chopps 
    630  1.1   chopps /*
    631  1.1   chopps  * extract the clock information for a port from the flags field
    632  1.1   chopps  */
    633  1.1   chopps static void
    634  1.1   chopps ntwoc_isa_get_clock(struct sca_port *scp, u_int8_t flags, u_int8_t tmc,
    635  1.1   chopps     u_int8_t rdiv, u_int8_t tdiv)
    636  1.1   chopps {
    637  1.1   chopps 	scp->sp_eclock =
    638  1.1   chopps 	    (flags & NTWOC_FLAGS_ECLOCK_MASK) >> NTWOC_FLAGS_ECLOCK_SHIFT;
    639  1.1   chopps 	scp->sp_rxs = rdiv;
    640  1.1   chopps 	scp->sp_txs = tdiv;
    641  1.1   chopps 	scp->sp_tmc = tmc;
    642  1.1   chopps 
    643  1.1   chopps 	/* get rx source */
    644  1.1   chopps 	switch ((flags & NTWOC_FLAGS_RXS_MASK) >> NTWOC_FLAGS_RXS_SHIFT) {
    645  1.1   chopps 	case NTWOC_FLAGS_RXS_LINE:
    646  1.1   chopps 		scp->sp_rxs = 0;
    647  1.1   chopps 		break;
    648  1.1   chopps 	case NTWOC_FLAGS_RXS_LINE_SN:
    649  1.1   chopps 		scp->sp_rxs |= SCA_RXS_CLK_LINE_SN;
    650  1.1   chopps 		break;
    651  1.1   chopps 	case NTWOC_FLAGS_RXS_INTERNAL:
    652  1.1   chopps 		scp->sp_rxs |= SCA_RXS_CLK_INTERNAL;
    653  1.1   chopps 		break;
    654  1.1   chopps 	case NTWOC_FLAGS_RXS_ADPLL_OUT:
    655  1.1   chopps 		scp->sp_rxs |= SCA_RXS_CLK_ADPLL_OUT;
    656  1.1   chopps 		break;
    657  1.1   chopps 	case NTWOC_FLAGS_RXS_ADPLL_IN:
    658  1.1   chopps 		scp->sp_rxs |= SCA_RXS_CLK_ADPLL_IN;
    659  1.1   chopps 		break;
    660  1.1   chopps 	default:
    661  1.1   chopps 		panic("bad rx source in flags");
    662  1.1   chopps 	}
    663  1.1   chopps 
    664  1.1   chopps 	/* get tx source */
    665  1.1   chopps 	switch ((flags & NTWOC_FLAGS_TXS_MASK) >> NTWOC_FLAGS_TXS_SHIFT) {
    666  1.1   chopps 	case NTWOC_FLAGS_TXS_LINE:
    667  1.1   chopps 		scp->sp_txs = 0;
    668  1.1   chopps 		break;
    669  1.1   chopps 	case NTWOC_FLAGS_TXS_INTERNAL:
    670  1.1   chopps 		scp->sp_txs |= SCA_TXS_CLK_INTERNAL;
    671  1.1   chopps 		break;
    672  1.1   chopps 	case NTWOC_FLAGS_TXS_RXCLOCK:
    673  1.1   chopps 		scp->sp_txs |= SCA_TXS_CLK_RXCLK;
    674  1.1   chopps 		break;
    675  1.1   chopps 	default:
    676  1.1   chopps 		panic("bad rx source in flags");
    677  1.1   chopps 	}
    678  1.1   chopps }
    679  1.1   chopps 
    680  1.1   chopps 
    681  1.1   chopps static int
    682  1.1   chopps ntwoc_isa_intr(void *arg)
    683  1.1   chopps {
    684  1.1   chopps 	struct ntwoc_isa_softc *sc = (struct ntwoc_isa_softc *)arg;
    685  1.1   chopps 
    686  1.1   chopps 	return sca_hardintr(&sc->sc_sca);
    687  1.1   chopps }
    688  1.1   chopps 
    689  1.1   chopps /*
    690  1.1   chopps  * shut down interrupts and DMA, so we don't trash the kernel on warm
    691  1.1   chopps  * boot.  Also, lower DTR on each port and disable card interrupts.
    692  1.1   chopps  */
    693  1.1   chopps static void
    694  1.1   chopps ntwoc_isa_shutdown(void *aux)
    695  1.1   chopps {
    696  1.1   chopps 	struct ntwoc_isa_softc *sc = aux;
    697  1.1   chopps 	u_int16_t mcr;
    698  1.1   chopps 
    699  1.1   chopps 	/*
    700  1.1   chopps 	 * shut down the SCA ports
    701  1.1   chopps 	 */
    702  1.1   chopps 	sca_shutdown(&sc->sc_sca);
    703  1.1   chopps 
    704  1.1   chopps 	/*
    705  1.1   chopps 	 * lower DTR on both ports
    706  1.1   chopps 	 */
    707  1.1   chopps 	mcr = bus_space_read_1(sc->sc_sca.sc_iot, sc->sc_sca.sc_ioh, NTWOC_MCR);
    708  1.1   chopps 	mcr |= (NTWOC_MCR_DTR0 | NTWOC_MCR_DTR1);
    709  1.1   chopps 	bus_space_write_1(sc->sc_sca.sc_iot, sc->sc_sca.sc_ioh, NTWOC_MCR, mcr);
    710  1.1   chopps }
    711  1.1   chopps 
    712  1.1   chopps static void
    713  1.1   chopps ntwoc_isa_dtr_callback(void *aux, int port, int state)
    714  1.1   chopps {
    715  1.1   chopps 	struct ntwoc_isa_softc *sc = aux;
    716  1.1   chopps 	u_int8_t mcr;
    717  1.1   chopps 
    718  1.1   chopps 	mcr = bus_space_read_1(sc->sc_sca.sc_iot, sc->sc_sca.sc_ioh, NTWOC_MCR);
    719  1.1   chopps 
    720  1.1   chopps 	NTWO_DPRINTF(("port == %d, state == %d, old mcr:  0x%02x\n",
    721  1.1   chopps 	    port, state, mcr));
    722  1.1   chopps 
    723  1.1   chopps 	if (port == 0) {
    724  1.1   chopps 		if (state == 0)
    725  1.1   chopps 			mcr |= NTWOC_MCR_DTR0;
    726  1.1   chopps 		else
    727  1.1   chopps 			mcr &= ~NTWOC_MCR_DTR0;
    728  1.1   chopps 	} else {
    729  1.1   chopps 		if (state == 0)
    730  1.1   chopps 			mcr |= NTWOC_MCR_DTR1;
    731  1.1   chopps 		else
    732  1.1   chopps 			mcr &= ~NTWOC_MCR_DTR1;
    733  1.1   chopps 	}
    734  1.1   chopps 
    735  1.1   chopps 	NTWO_DPRINTF(("new mcr:  0x%02x\n", mcr));
    736  1.1   chopps 
    737  1.1   chopps 	bus_space_write_1(sc->sc_sca.sc_iot, sc->sc_sca.sc_ioh, NTWOC_MCR, mcr);
    738  1.1   chopps }
    739  1.1   chopps 
    740  1.1   chopps static void
    741  1.1   chopps ntwoc_isa_clock_callback(void *aux, int port, int enable)
    742  1.1   chopps {
    743  1.1   chopps 	struct ntwoc_isa_softc *sc = aux;
    744  1.1   chopps 	u_int8_t mcr;
    745  1.1   chopps 
    746  1.1   chopps 	mcr = bus_space_read_1(sc->sc_sca.sc_iot, sc->sc_sca.sc_ioh, NTWOC_MCR);
    747  1.1   chopps 
    748  1.1   chopps 	NTWO_DPRINTF(("clock: port == %d, enable == %d, old mcr:  0x%02x\n",
    749  1.1   chopps 	    port, enable, mcr));
    750  1.1   chopps 
    751  1.1   chopps 	if (port == 0) {
    752  1.1   chopps 		if (enable == 0)
    753  1.1   chopps 			mcr &= ~NTWOC_MCR_ETC0;
    754  1.1   chopps 		else
    755  1.1   chopps 			mcr |= NTWOC_MCR_ETC0;
    756  1.1   chopps 	} else {
    757  1.1   chopps 		if (enable == 0)
    758  1.1   chopps 			mcr &= ~NTWOC_MCR_ETC1;
    759  1.1   chopps 		else
    760  1.1   chopps 			mcr |= NTWOC_MCR_ETC1;
    761  1.1   chopps 	}
    762  1.1   chopps 
    763  1.1   chopps 	NTWO_DPRINTF(("clock: new mcr:  0x%02x\n", mcr));
    764  1.1   chopps 
    765  1.1   chopps 	bus_space_write_1(sc->sc_sca.sc_iot, sc->sc_sca.sc_ioh, NTWOC_MCR, mcr);
    766  1.1   chopps }
    767  1.1   chopps 
    768  1.1   chopps static void
    769  1.1   chopps ntwoc_isa_setup_memory(struct sca_softc *sc)
    770  1.1   chopps {
    771  1.1   chopps 	struct sca_port *scp;
    772  1.1   chopps 	u_int i, j;
    773  1.1   chopps 
    774  1.1   chopps 	/* allocate enough descriptors for a full page */
    775  1.1   chopps 
    776  1.1   chopps 	sc->sc_ports[0].sp_ntxdesc = (sc->scu_pagesize / SCA_BSIZE) - 1;
    777  1.1   chopps 	sc->sc_ports[0].sp_nrxdesc = (sc->scu_pagesize / SCA_BSIZE) - 1;
    778  1.1   chopps 	if (sc->sc_numports == 2) {
    779  1.1   chopps 		sc->sc_ports[1].sp_ntxdesc = sc->sc_ports[0].sp_ntxdesc;
    780  1.1   chopps 		sc->sc_ports[1].sp_nrxdesc = sc->sc_ports[0].sp_nrxdesc;
    781  1.1   chopps 	}
    782  1.1   chopps 
    783  1.1   chopps 	j = 0;
    784  1.1   chopps 	for (i = 0; i < sc->sc_numports; i++) {
    785  1.1   chopps 		scp = &sc->sc_ports[i];
    786  1.1   chopps 		scp->sp_txdesc_p = (bus_addr_t)(j * sc->scu_pagesize);
    787  1.1   chopps 		scp->sp_txdesc = (void *)scp->sp_txdesc_p;
    788  1.1   chopps 		scp->sp_txbuf_p = scp->sp_txdesc_p;
    789  1.1   chopps 		scp->sp_txbuf_p += SCA_BSIZE;
    790  1.1   chopps 		scp->sp_txbuf = (void *)scp->sp_txbuf_p;
    791  1.1   chopps 		j++;
    792  1.1   chopps 
    793  1.1   chopps 		scp->sp_rxdesc_p = (bus_addr_t)(j * sc->scu_pagesize);
    794  1.1   chopps 		scp->sp_rxdesc = (void *)scp->sp_txdesc_p;
    795  1.1   chopps 		scp->sp_rxbuf_p = scp->sp_rxdesc_p;
    796  1.1   chopps 		scp->sp_rxbuf_p += SCA_BSIZE;
    797  1.1   chopps 		scp->sp_rxbuf = (void *)scp->sp_rxbuf_p;
    798  1.1   chopps 		j++;
    799  1.1   chopps 	}
    800  1.1   chopps }
    801  1.1   chopps 
    802  1.1   chopps #if __NetBSD_Version__ >= 104160000
    803  1.1   chopps /*
    804  1.1   chopps  * get the base clock frequency
    805  1.1   chopps  */
    806  1.1   chopps static void
    807  1.1   chopps ntwoc_isa_config_interrupts(self)
    808  1.1   chopps 	struct device *self;
    809  1.1   chopps {
    810  1.1   chopps 	struct ntwoc_isa_softc *sc;
    811  1.1   chopps 
    812  1.1   chopps 	sc = (void *)self;
    813  1.1   chopps 	sca_get_base_clock(&sc->sc_sca);
    814  1.1   chopps 	sca_print_clock_info(&sc->sc_sca);
    815  1.1   chopps }
    816  1.1   chopps #endif
    817