i82365.c revision 1.1.2.14       1  1.1.2.14  thorpej /*	$NetBSD: i82365.c,v 1.1.2.14 1997/10/16 19:41:51 thorpej Exp $	*/
      2  1.1.2.12  thorpej 
      3  1.1.2.12  thorpej #define	PCICDEBUG
      4   1.1.2.1     marc 
      5   1.1.2.1     marc #include <sys/types.h>
      6   1.1.2.1     marc #include <sys/param.h>
      7   1.1.2.1     marc #include <sys/systm.h>
      8   1.1.2.1     marc #include <sys/device.h>
      9   1.1.2.1     marc #include <sys/extent.h>
     10   1.1.2.1     marc #include <sys/malloc.h>
     11   1.1.2.1     marc 
     12   1.1.2.1     marc #include <vm/vm.h>
     13   1.1.2.1     marc 
     14   1.1.2.1     marc #include <machine/bus.h>
     15   1.1.2.1     marc #include <machine/intr.h>
     16   1.1.2.1     marc 
     17   1.1.2.1     marc #include <dev/pcmcia/pcmciareg.h>
     18   1.1.2.4  thorpej #include <dev/pcmcia/pcmciavar.h>
     19   1.1.2.1     marc 
     20   1.1.2.1     marc #include <dev/ic/i82365reg.h>
     21   1.1.2.8     marc #include <dev/ic/i82365var.h>
     22   1.1.2.1     marc 
     23   1.1.2.1     marc #ifdef PCICDEBUG
     24   1.1.2.2  thorpej int	pcic_debug = 0;
     25  1.1.2.12  thorpej #define	DPRINTF(arg) if (pcic_debug) printf arg;
     26   1.1.2.1     marc #else
     27  1.1.2.12  thorpej #define	DPRINTF(arg)
     28   1.1.2.1     marc #endif
     29   1.1.2.1     marc 
     30  1.1.2.12  thorpej #define	PCIC_VENDOR_UNKNOWN		0
     31  1.1.2.12  thorpej #define	PCIC_VENDOR_I82365SLR0		1
     32  1.1.2.12  thorpej #define	PCIC_VENDOR_I82365SLR1		2
     33  1.1.2.12  thorpej #define	PCIC_VENDOR_CIRRUS_PD6710	3
     34  1.1.2.12  thorpej #define	PCIC_VENDOR_CIRRUS_PD672X	4
     35  1.1.2.12  thorpej 
     36  1.1.2.12  thorpej /*
     37  1.1.2.12  thorpej  * Individual drivers will allocate their own memory and io regions. Memory
     38  1.1.2.12  thorpej  * regions must be a multiple of 4k, aligned on a 4k boundary.
     39  1.1.2.12  thorpej  */
     40   1.1.2.1     marc 
     41  1.1.2.12  thorpej #define	PCIC_MEM_ALIGN	PCIC_MEM_PAGESIZE
     42   1.1.2.1     marc 
     43  1.1.2.12  thorpej void	pcic_attach_socket __P((struct pcic_handle *));
     44  1.1.2.12  thorpej void	pcic_init_socket __P((struct pcic_handle *));
     45   1.1.2.1     marc 
     46   1.1.2.1     marc #ifdef __BROKEN_INDIRECT_CONFIG
     47  1.1.2.12  thorpej int	pcic_submatch __P((struct device *, void *, void *));
     48   1.1.2.1     marc #else
     49  1.1.2.12  thorpej int	pcic_submatch __P((struct device *, struct cfdata *, void *));
     50   1.1.2.1     marc #endif
     51  1.1.2.12  thorpej int	pcic_print  __P((void *arg, const char *pnp));
     52  1.1.2.12  thorpej int	pcic_intr_socket __P((struct pcic_handle *));
     53   1.1.2.1     marc 
     54  1.1.2.12  thorpej void	pcic_attach_card __P((struct pcic_handle *));
     55  1.1.2.12  thorpej void	pcic_detach_card __P((struct pcic_handle *));
     56  1.1.2.10     marc 
     57  1.1.2.12  thorpej void	pcic_chip_do_mem_map __P((struct pcic_handle *, int));
     58  1.1.2.12  thorpej void	pcic_chip_do_io_map __P((struct pcic_handle *, int));
     59   1.1.2.1     marc 
     60   1.1.2.1     marc struct cfdriver pcic_cd = {
     61   1.1.2.1     marc 	NULL, "pcic", DV_DULL
     62   1.1.2.1     marc };
     63   1.1.2.1     marc 
     64   1.1.2.1     marc int
     65   1.1.2.1     marc pcic_ident_ok(ident)
     66  1.1.2.12  thorpej 	int ident;
     67   1.1.2.1     marc {
     68  1.1.2.12  thorpej 	/* this is very empirical and heuristic */
     69   1.1.2.1     marc 
     70  1.1.2.12  thorpej 	if ((ident == 0) || (ident == 0xff) || (ident & PCIC_IDENT_ZERO))
     71  1.1.2.12  thorpej 		return (0);
     72   1.1.2.1     marc 
     73  1.1.2.12  thorpej 	if ((ident & PCIC_IDENT_IFTYPE_MASK) != PCIC_IDENT_IFTYPE_MEM_AND_IO) {
     74   1.1.2.1     marc #ifdef DIAGNOSTIC
     75  1.1.2.12  thorpej 		printf("pcic: does not support memory and I/O cards, "
     76  1.1.2.12  thorpej 		    "ignored (ident=%0x)\n", ident);
     77   1.1.2.1     marc #endif
     78  1.1.2.12  thorpej 		return (0);
     79  1.1.2.12  thorpej 	}
     80  1.1.2.12  thorpej 	return (1);
     81   1.1.2.1     marc }
     82   1.1.2.1     marc 
     83   1.1.2.1     marc int
     84   1.1.2.1     marc pcic_vendor(h)
     85  1.1.2.12  thorpej 	struct pcic_handle *h;
     86   1.1.2.1     marc {
     87  1.1.2.12  thorpej 	int reg;
     88   1.1.2.1     marc 
     89  1.1.2.12  thorpej 	/*
     90  1.1.2.12  thorpej 	 * the chip_id of the cirrus toggles between 11 and 00 after a write.
     91  1.1.2.12  thorpej 	 * weird.
     92  1.1.2.12  thorpej 	 */
     93   1.1.2.1     marc 
     94  1.1.2.12  thorpej 	pcic_write(h, PCIC_CIRRUS_CHIP_INFO, 0);
     95   1.1.2.1     marc 	reg = pcic_read(h, -1);
     96   1.1.2.1     marc 
     97  1.1.2.12  thorpej 	if ((reg & PCIC_CIRRUS_CHIP_INFO_CHIP_ID) ==
     98  1.1.2.12  thorpej 	    PCIC_CIRRUS_CHIP_INFO_CHIP_ID) {
     99  1.1.2.12  thorpej 		reg = pcic_read(h, -1);
    100  1.1.2.12  thorpej 		if ((reg & PCIC_CIRRUS_CHIP_INFO_CHIP_ID) == 0) {
    101  1.1.2.12  thorpej 			if (reg & PCIC_CIRRUS_CHIP_INFO_SLOTS)
    102  1.1.2.12  thorpej 				return (PCIC_VENDOR_CIRRUS_PD672X);
    103  1.1.2.12  thorpej 			else
    104  1.1.2.12  thorpej 				return (PCIC_VENDOR_CIRRUS_PD6710);
    105  1.1.2.12  thorpej 		}
    106  1.1.2.12  thorpej 	}
    107  1.1.2.12  thorpej 	/* XXX how do I identify the GD6729? */
    108   1.1.2.8     marc 
    109  1.1.2.12  thorpej 	reg = pcic_read(h, PCIC_IDENT);
    110   1.1.2.1     marc 
    111  1.1.2.12  thorpej 	if ((reg & PCIC_IDENT_REV_MASK) == PCIC_IDENT_REV_I82365SLR0)
    112  1.1.2.12  thorpej 		return (PCIC_VENDOR_I82365SLR0);
    113  1.1.2.12  thorpej 	else
    114  1.1.2.12  thorpej 		return (PCIC_VENDOR_I82365SLR1);
    115   1.1.2.1     marc 
    116  1.1.2.12  thorpej 	return (PCIC_VENDOR_UNKNOWN);
    117   1.1.2.1     marc }
    118   1.1.2.1     marc 
    119   1.1.2.1     marc char *
    120   1.1.2.1     marc pcic_vendor_to_string(vendor)
    121  1.1.2.12  thorpej 	int vendor;
    122   1.1.2.1     marc {
    123  1.1.2.12  thorpej 	switch (vendor) {
    124  1.1.2.12  thorpej 	case PCIC_VENDOR_I82365SLR0:
    125  1.1.2.12  thorpej 		return ("Intel 82365SL Revision 0");
    126  1.1.2.12  thorpej 	case PCIC_VENDOR_I82365SLR1:
    127  1.1.2.12  thorpej 		return ("Intel 82365SL Revision 1");
    128  1.1.2.12  thorpej 	case PCIC_VENDOR_CIRRUS_PD6710:
    129  1.1.2.12  thorpej 		return ("Cirrus PD6710");
    130  1.1.2.12  thorpej 	case PCIC_VENDOR_CIRRUS_PD672X:
    131  1.1.2.12  thorpej 		return ("Cirrus PD672X");
    132  1.1.2.12  thorpej 	}
    133   1.1.2.1     marc 
    134  1.1.2.12  thorpej 	return ("Unknown controller");
    135   1.1.2.1     marc }
    136   1.1.2.1     marc 
    137   1.1.2.1     marc void
    138   1.1.2.8     marc pcic_attach(sc)
    139  1.1.2.12  thorpej 	struct pcic_softc *sc;
    140   1.1.2.1     marc {
    141  1.1.2.12  thorpej 	int vendor, count, i, reg;
    142   1.1.2.1     marc 
    143  1.1.2.12  thorpej 	/* now check for each controller/socket */
    144   1.1.2.1     marc 
    145  1.1.2.12  thorpej 	/*
    146  1.1.2.12  thorpej 	 * this could be done with a loop, but it would violate the
    147  1.1.2.12  thorpej 	 * abstraction
    148  1.1.2.12  thorpej 	 */
    149   1.1.2.1     marc 
    150  1.1.2.12  thorpej 	count = 0;
    151   1.1.2.1     marc 
    152  1.1.2.12  thorpej 	DPRINTF(("pcic ident regs:"));
    153  1.1.2.10     marc 
    154  1.1.2.12  thorpej 	sc->handle[0].sc = sc;
    155  1.1.2.12  thorpej 	sc->handle[0].sock = C0SA;
    156  1.1.2.12  thorpej 	if (pcic_ident_ok(reg = pcic_read(&sc->handle[0], PCIC_IDENT))) {
    157  1.1.2.12  thorpej 		sc->handle[0].flags = PCIC_FLAG_SOCKETP;
    158  1.1.2.12  thorpej 		count++;
    159  1.1.2.12  thorpej 	} else {
    160  1.1.2.12  thorpej 		sc->handle[0].flags = 0;
    161  1.1.2.12  thorpej 	}
    162   1.1.2.1     marc 
    163  1.1.2.12  thorpej 	DPRINTF((" 0x%02x", reg));
    164  1.1.2.10     marc 
    165  1.1.2.12  thorpej 	sc->handle[1].sc = sc;
    166  1.1.2.12  thorpej 	sc->handle[1].sock = C0SB;
    167  1.1.2.12  thorpej 	if (pcic_ident_ok(reg = pcic_read(&sc->handle[1], PCIC_IDENT))) {
    168  1.1.2.12  thorpej 		sc->handle[1].flags = PCIC_FLAG_SOCKETP;
    169  1.1.2.12  thorpej 		count++;
    170  1.1.2.12  thorpej 	} else {
    171  1.1.2.12  thorpej 		sc->handle[1].flags = 0;
    172  1.1.2.12  thorpej 	}
    173   1.1.2.1     marc 
    174  1.1.2.12  thorpej 	DPRINTF((" 0x%02x", reg));
    175  1.1.2.10     marc 
    176  1.1.2.12  thorpej 	sc->handle[2].sc = sc;
    177  1.1.2.12  thorpej 	sc->handle[2].sock = C1SA;
    178  1.1.2.12  thorpej 	if (pcic_ident_ok(reg = pcic_read(&sc->handle[2], PCIC_IDENT))) {
    179  1.1.2.12  thorpej 		sc->handle[2].flags = PCIC_FLAG_SOCKETP;
    180  1.1.2.12  thorpej 		count++;
    181  1.1.2.12  thorpej 	} else {
    182  1.1.2.12  thorpej 		sc->handle[2].flags = 0;
    183  1.1.2.12  thorpej 	}
    184   1.1.2.1     marc 
    185  1.1.2.12  thorpej 	DPRINTF((" 0x%02x", reg));
    186  1.1.2.10     marc 
    187  1.1.2.12  thorpej 	sc->handle[3].sc = sc;
    188  1.1.2.12  thorpej 	sc->handle[3].sock = C1SB;
    189  1.1.2.12  thorpej 	if (pcic_ident_ok(reg = pcic_read(&sc->handle[3], PCIC_IDENT))) {
    190  1.1.2.12  thorpej 		sc->handle[3].flags = PCIC_FLAG_SOCKETP;
    191  1.1.2.12  thorpej 		count++;
    192  1.1.2.12  thorpej 	} else {
    193  1.1.2.12  thorpej 		sc->handle[3].flags = 0;
    194  1.1.2.12  thorpej 	}
    195   1.1.2.1     marc 
    196  1.1.2.12  thorpej 	DPRINTF((" 0x%02x\n", reg));
    197  1.1.2.10     marc 
    198  1.1.2.12  thorpej 	if (count == 0)
    199  1.1.2.12  thorpej 		panic("pcic_attach: attach found no sockets");
    200   1.1.2.1     marc 
    201  1.1.2.12  thorpej 	/* establish the interrupt */
    202   1.1.2.1     marc 
    203  1.1.2.12  thorpej 	/* XXX block interrupts? */
    204   1.1.2.1     marc 
    205  1.1.2.12  thorpej 	for (i = 0; i < PCIC_NSLOTS; i++) {
    206  1.1.2.10     marc #if 0
    207  1.1.2.12  thorpej 		/*
    208  1.1.2.12  thorpej 		 * this should work, but w/o it, setting tty flags hangs at
    209  1.1.2.12  thorpej 		 * boot time.
    210  1.1.2.12  thorpej 		 */
    211  1.1.2.12  thorpej 		if (sc->handle[i].flags & PCIC_FLAG_SOCKETP)
    212  1.1.2.10     marc #endif
    213  1.1.2.12  thorpej 		{
    214  1.1.2.12  thorpej 			pcic_write(&sc->handle[i], PCIC_CSC_INTR, 0);
    215  1.1.2.12  thorpej 			pcic_read(&sc->handle[i], PCIC_CSC);
    216  1.1.2.12  thorpej 		}
    217  1.1.2.12  thorpej 	}
    218   1.1.2.1     marc 
    219  1.1.2.12  thorpej 	if ((sc->handle[0].flags & PCIC_FLAG_SOCKETP) ||
    220  1.1.2.12  thorpej 	    (sc->handle[1].flags & PCIC_FLAG_SOCKETP)) {
    221  1.1.2.12  thorpej 		vendor = pcic_vendor(&sc->handle[0]);
    222  1.1.2.12  thorpej 
    223  1.1.2.12  thorpej 		printf("%s: controller 0 (%s) has ", sc->dev.dv_xname,
    224  1.1.2.12  thorpej 		       pcic_vendor_to_string(vendor));
    225  1.1.2.12  thorpej 
    226  1.1.2.12  thorpej 		if ((sc->handle[0].flags & PCIC_FLAG_SOCKETP) &&
    227  1.1.2.12  thorpej 		    (sc->handle[1].flags & PCIC_FLAG_SOCKETP))
    228  1.1.2.12  thorpej 			printf("sockets A and B\n");
    229  1.1.2.12  thorpej 		else if (sc->handle[0].flags & PCIC_FLAG_SOCKETP)
    230  1.1.2.12  thorpej 			printf("socket A only\n");
    231  1.1.2.12  thorpej 		else
    232  1.1.2.12  thorpej 			printf("socket B only\n");
    233  1.1.2.12  thorpej 
    234  1.1.2.12  thorpej 		if (sc->handle[0].flags & PCIC_FLAG_SOCKETP)
    235  1.1.2.12  thorpej 			sc->handle[0].vendor = vendor;
    236  1.1.2.12  thorpej 		if (sc->handle[1].flags & PCIC_FLAG_SOCKETP)
    237  1.1.2.12  thorpej 			sc->handle[1].vendor = vendor;
    238  1.1.2.12  thorpej 	}
    239  1.1.2.12  thorpej 	if ((sc->handle[2].flags & PCIC_FLAG_SOCKETP) ||
    240  1.1.2.12  thorpej 	    (sc->handle[3].flags & PCIC_FLAG_SOCKETP)) {
    241  1.1.2.12  thorpej 		vendor = pcic_vendor(&sc->handle[2]);
    242  1.1.2.12  thorpej 
    243  1.1.2.12  thorpej 		printf("%s: controller 1 (%s) has ", sc->dev.dv_xname,
    244  1.1.2.12  thorpej 		       pcic_vendor_to_string(vendor));
    245  1.1.2.12  thorpej 
    246  1.1.2.12  thorpej 		if ((sc->handle[2].flags & PCIC_FLAG_SOCKETP) &&
    247  1.1.2.12  thorpej 		    (sc->handle[3].flags & PCIC_FLAG_SOCKETP))
    248  1.1.2.12  thorpej 			printf("sockets A and B\n");
    249  1.1.2.12  thorpej 		else if (sc->handle[2].flags & PCIC_FLAG_SOCKETP)
    250  1.1.2.12  thorpej 			printf("socket A only\n");
    251  1.1.2.12  thorpej 		else
    252  1.1.2.12  thorpej 			printf("socket B only\n");
    253  1.1.2.12  thorpej 
    254  1.1.2.12  thorpej 		if (sc->handle[2].flags & PCIC_FLAG_SOCKETP)
    255  1.1.2.12  thorpej 			sc->handle[2].vendor = vendor;
    256  1.1.2.12  thorpej 		if (sc->handle[3].flags & PCIC_FLAG_SOCKETP)
    257  1.1.2.12  thorpej 			sc->handle[3].vendor = vendor;
    258  1.1.2.12  thorpej 	}
    259   1.1.2.1     marc }
    260   1.1.2.1     marc 
    261   1.1.2.1     marc void
    262   1.1.2.8     marc pcic_attach_sockets(sc)
    263  1.1.2.12  thorpej 	struct pcic_softc *sc;
    264   1.1.2.8     marc {
    265  1.1.2.12  thorpej 	int i;
    266   1.1.2.8     marc 
    267  1.1.2.12  thorpej 	for (i = 0; i < PCIC_NSLOTS; i++)
    268  1.1.2.12  thorpej 		if (sc->handle[i].flags & PCIC_FLAG_SOCKETP)
    269  1.1.2.12  thorpej 			pcic_attach_socket(&sc->handle[i]);
    270   1.1.2.8     marc }
    271   1.1.2.8     marc 
    272   1.1.2.8     marc void
    273   1.1.2.1     marc pcic_attach_socket(h)
    274  1.1.2.12  thorpej 	struct pcic_handle *h;
    275   1.1.2.1     marc {
    276  1.1.2.12  thorpej 	struct pcmciabus_attach_args paa;
    277   1.1.2.1     marc 
    278  1.1.2.12  thorpej 	/* initialize the rest of the handle */
    279   1.1.2.1     marc 
    280  1.1.2.12  thorpej 	h->memalloc = 0;
    281  1.1.2.12  thorpej 	h->ioalloc = 0;
    282  1.1.2.12  thorpej 	h->ih_irq = 0;
    283   1.1.2.1     marc 
    284  1.1.2.12  thorpej 	/* now, config one pcmcia device per socket */
    285   1.1.2.1     marc 
    286  1.1.2.12  thorpej 	paa.pct = (pcmcia_chipset_tag_t) h->sc->pct;
    287  1.1.2.12  thorpej 	paa.pch = (pcmcia_chipset_handle_t) h;
    288  1.1.2.14  thorpej 	paa.iobase = h->sc->iobase;
    289  1.1.2.14  thorpej 	paa.iosize = h->sc->iosize;
    290   1.1.2.1     marc 
    291  1.1.2.12  thorpej 	h->pcmcia = config_found_sm(&h->sc->dev, &paa, pcic_print,
    292  1.1.2.12  thorpej 	    pcic_submatch);
    293   1.1.2.1     marc 
    294  1.1.2.12  thorpej 	/* if there's actually a pcmcia device attached, initialize the slot */
    295   1.1.2.1     marc 
    296  1.1.2.12  thorpej 	if (h->pcmcia)
    297  1.1.2.12  thorpej 		pcic_init_socket(h);
    298   1.1.2.1     marc }
    299   1.1.2.1     marc 
    300   1.1.2.1     marc void
    301   1.1.2.1     marc pcic_init_socket(h)
    302  1.1.2.12  thorpej 	struct pcic_handle *h;
    303   1.1.2.1     marc {
    304  1.1.2.12  thorpej 	int reg;
    305   1.1.2.1     marc 
    306  1.1.2.12  thorpej 	/* set up the card to interrupt on card detect */
    307   1.1.2.1     marc 
    308  1.1.2.12  thorpej 	pcic_write(h, PCIC_CSC_INTR, (h->sc->irq << PCIC_CSC_INTR_IRQ_SHIFT) |
    309  1.1.2.12  thorpej 	    PCIC_CSC_INTR_CD_ENABLE);
    310  1.1.2.12  thorpej 	pcic_write(h, PCIC_INTR, 0);
    311  1.1.2.12  thorpej 	pcic_read(h, PCIC_CSC);
    312  1.1.2.12  thorpej 
    313  1.1.2.12  thorpej 	/* unsleep the cirrus controller */
    314  1.1.2.12  thorpej 
    315  1.1.2.12  thorpej 	if ((h->vendor == PCIC_VENDOR_CIRRUS_PD6710) ||
    316  1.1.2.12  thorpej 	    (h->vendor == PCIC_VENDOR_CIRRUS_PD672X)) {
    317  1.1.2.12  thorpej 		reg = pcic_read(h, PCIC_CIRRUS_MISC_CTL_2);
    318  1.1.2.12  thorpej 		if (reg & PCIC_CIRRUS_MISC_CTL_2_SUSPEND) {
    319  1.1.2.12  thorpej 			DPRINTF(("%s: socket %02x was suspended\n",
    320  1.1.2.12  thorpej 			    h->sc->dev.dv_xname, h->sock));
    321  1.1.2.12  thorpej 			reg &= ~PCIC_CIRRUS_MISC_CTL_2_SUSPEND;
    322  1.1.2.12  thorpej 			pcic_write(h, PCIC_CIRRUS_MISC_CTL_2, reg);
    323  1.1.2.12  thorpej 		}
    324   1.1.2.1     marc 	}
    325  1.1.2.12  thorpej 	/* if there's a card there, then attach it. */
    326   1.1.2.1     marc 
    327  1.1.2.12  thorpej 	reg = pcic_read(h, PCIC_IF_STATUS);
    328   1.1.2.1     marc 
    329  1.1.2.12  thorpej 	if ((reg & PCIC_IF_STATUS_CARDDETECT_MASK) ==
    330  1.1.2.12  thorpej 	    PCIC_IF_STATUS_CARDDETECT_PRESENT)
    331  1.1.2.12  thorpej 		pcic_attach_card(h);
    332   1.1.2.1     marc }
    333   1.1.2.1     marc 
    334   1.1.2.1     marc int
    335   1.1.2.1     marc #ifdef __BROKEN_INDIRECT_CONFIG
    336   1.1.2.1     marc pcic_submatch(parent, match, aux)
    337   1.1.2.1     marc #else
    338   1.1.2.1     marc pcic_submatch(parent, cf, aux)
    339   1.1.2.1     marc #endif
    340  1.1.2.12  thorpej 	struct device *parent;
    341   1.1.2.1     marc #ifdef __BROKEN_INDIRECT_CONFIG
    342  1.1.2.12  thorpej 	void *match;
    343   1.1.2.1     marc #else
    344  1.1.2.12  thorpej 	struct cfdata *cf;
    345   1.1.2.1     marc #endif
    346  1.1.2.12  thorpej 	void *aux;
    347   1.1.2.1     marc {
    348   1.1.2.1     marc #ifdef __BROKEN_INDIRECT_CONFIG
    349  1.1.2.12  thorpej 	struct cfdata *cf = match;
    350   1.1.2.1     marc #endif
    351   1.1.2.1     marc 
    352  1.1.2.12  thorpej 	struct pcmciabus_attach_args *paa =
    353  1.1.2.12  thorpej 	    (struct pcmciabus_attach_args *) aux;
    354  1.1.2.12  thorpej 	struct pcic_handle *h = (struct pcic_handle *) paa->pch;
    355  1.1.2.12  thorpej 
    356  1.1.2.12  thorpej 	switch (h->sock) {
    357  1.1.2.12  thorpej 	case C0SA:
    358  1.1.2.12  thorpej 		if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != 0)
    359  1.1.2.12  thorpej 			return 0;
    360  1.1.2.12  thorpej 		if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != 0)
    361  1.1.2.12  thorpej 			return 0;
    362  1.1.2.12  thorpej 
    363  1.1.2.12  thorpej 		break;
    364  1.1.2.12  thorpej 	case C0SB:
    365  1.1.2.12  thorpej 		if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != 0)
    366  1.1.2.12  thorpej 			return 0;
    367  1.1.2.12  thorpej 		if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != 1)
    368  1.1.2.12  thorpej 			return 0;
    369  1.1.2.12  thorpej 
    370  1.1.2.12  thorpej 		break;
    371  1.1.2.12  thorpej 	case C1SA:
    372  1.1.2.12  thorpej 		if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != 1)
    373  1.1.2.12  thorpej 			return 0;
    374  1.1.2.12  thorpej 		if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != 0)
    375  1.1.2.12  thorpej 			return 0;
    376  1.1.2.12  thorpej 
    377  1.1.2.12  thorpej 		break;
    378  1.1.2.12  thorpej 	case C1SB:
    379  1.1.2.12  thorpej 		if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != 1)
    380  1.1.2.12  thorpej 			return 0;
    381  1.1.2.12  thorpej 		if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != 1)
    382  1.1.2.12  thorpej 			return 0;
    383  1.1.2.12  thorpej 
    384  1.1.2.12  thorpej 		break;
    385  1.1.2.12  thorpej 	default:
    386  1.1.2.12  thorpej 		panic("unknown pcic socket");
    387  1.1.2.12  thorpej 	}
    388   1.1.2.1     marc 
    389  1.1.2.12  thorpej 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    390   1.1.2.1     marc }
    391   1.1.2.1     marc 
    392   1.1.2.1     marc int
    393   1.1.2.1     marc pcic_print(arg, pnp)
    394  1.1.2.12  thorpej 	void *arg;
    395  1.1.2.12  thorpej 	const char *pnp;
    396   1.1.2.1     marc {
    397  1.1.2.12  thorpej 	struct pcmciabus_attach_args *paa =
    398  1.1.2.12  thorpej 	    (struct pcmciabus_attach_args *) arg;
    399  1.1.2.12  thorpej 	struct pcic_handle *h = (struct pcic_handle *) paa->pch;
    400  1.1.2.12  thorpej 
    401  1.1.2.12  thorpej 	/* Only "pcmcia"s can attach to "pcic"s... easy. */
    402  1.1.2.12  thorpej 	if (pnp)
    403  1.1.2.12  thorpej 		printf("pcmcia at %s", pnp);
    404  1.1.2.12  thorpej 
    405  1.1.2.12  thorpej 	switch (h->sock) {
    406  1.1.2.12  thorpej 	case C0SA:
    407  1.1.2.12  thorpej 		printf(" controller 0 socket 0");
    408  1.1.2.12  thorpej 		break;
    409  1.1.2.12  thorpej 	case C0SB:
    410  1.1.2.12  thorpej 		printf(" controller 0 socket 1");
    411  1.1.2.12  thorpej 		break;
    412  1.1.2.12  thorpej 	case C1SA:
    413  1.1.2.12  thorpej 		printf(" controller 1 socket 0");
    414  1.1.2.12  thorpej 		break;
    415  1.1.2.12  thorpej 	case C1SB:
    416  1.1.2.12  thorpej 		printf(" controller 1 socket 1");
    417  1.1.2.12  thorpej 		break;
    418  1.1.2.12  thorpej 	default:
    419  1.1.2.12  thorpej 		panic("unknown pcic socket");
    420  1.1.2.12  thorpej 	}
    421   1.1.2.1     marc 
    422  1.1.2.12  thorpej 	return (UNCONF);
    423   1.1.2.1     marc }
    424   1.1.2.1     marc 
    425   1.1.2.1     marc int
    426   1.1.2.1     marc pcic_intr(arg)
    427  1.1.2.12  thorpej 	void *arg;
    428   1.1.2.1     marc {
    429  1.1.2.12  thorpej 	struct pcic_softc *sc = (struct pcic_softc *) arg;
    430  1.1.2.12  thorpej 	int i, ret = 0;
    431   1.1.2.1     marc 
    432  1.1.2.12  thorpej 	DPRINTF(("%s: intr\n", sc->dev.dv_xname));
    433   1.1.2.1     marc 
    434  1.1.2.12  thorpej 	for (i = 0; i < PCIC_NSLOTS; i++)
    435  1.1.2.12  thorpej 		if (sc->handle[i].flags & PCIC_FLAG_SOCKETP)
    436  1.1.2.12  thorpej 			ret += pcic_intr_socket(&sc->handle[i]);
    437   1.1.2.1     marc 
    438  1.1.2.12  thorpej 	return (ret ? 1 : 0);
    439   1.1.2.1     marc }
    440   1.1.2.1     marc 
    441   1.1.2.1     marc int
    442   1.1.2.1     marc pcic_intr_socket(h)
    443  1.1.2.12  thorpej 	struct pcic_handle *h;
    444   1.1.2.1     marc {
    445  1.1.2.12  thorpej 	int cscreg;
    446   1.1.2.1     marc 
    447  1.1.2.12  thorpej 	cscreg = pcic_read(h, PCIC_CSC);
    448   1.1.2.1     marc 
    449  1.1.2.12  thorpej 	cscreg &= (PCIC_CSC_GPI |
    450  1.1.2.12  thorpej 		   PCIC_CSC_CD |
    451  1.1.2.12  thorpej 		   PCIC_CSC_READY |
    452  1.1.2.12  thorpej 		   PCIC_CSC_BATTWARN |
    453  1.1.2.12  thorpej 		   PCIC_CSC_BATTDEAD);
    454   1.1.2.1     marc 
    455  1.1.2.12  thorpej 	if (cscreg & PCIC_CSC_GPI) {
    456  1.1.2.12  thorpej 		DPRINTF(("%s: %02x GPI\n", h->sc->dev.dv_xname, h->sock));
    457  1.1.2.12  thorpej 	}
    458  1.1.2.12  thorpej 	if (cscreg & PCIC_CSC_CD) {
    459  1.1.2.12  thorpej 		int statreg;
    460   1.1.2.1     marc 
    461  1.1.2.12  thorpej 		statreg = pcic_read(h, PCIC_IF_STATUS);
    462   1.1.2.1     marc 
    463  1.1.2.12  thorpej 		DPRINTF(("%s: %02x CD %x\n", h->sc->dev.dv_xname, h->sock,
    464  1.1.2.12  thorpej 		    statreg));
    465   1.1.2.8     marc 
    466  1.1.2.12  thorpej 		/*
    467  1.1.2.12  thorpej 		 * XXX This should probably schedule something to happen
    468  1.1.2.12  thorpej 		 * after the interrupt handler completes
    469  1.1.2.12  thorpej 		 */
    470  1.1.2.12  thorpej 
    471  1.1.2.12  thorpej 		if ((statreg & PCIC_IF_STATUS_CARDDETECT_MASK) ==
    472  1.1.2.12  thorpej 		    PCIC_IF_STATUS_CARDDETECT_PRESENT) {
    473  1.1.2.12  thorpej 			if (!(h->flags & PCIC_FLAG_CARDP))
    474  1.1.2.12  thorpej 				pcic_attach_card(h);
    475  1.1.2.12  thorpej 		} else {
    476  1.1.2.12  thorpej 			if (h->flags & PCIC_FLAG_CARDP)
    477  1.1.2.12  thorpej 				pcic_detach_card(h);
    478  1.1.2.12  thorpej 		}
    479   1.1.2.1     marc 	}
    480  1.1.2.12  thorpej 	if (cscreg & PCIC_CSC_READY) {
    481  1.1.2.12  thorpej 		DPRINTF(("%s: %02x READY\n", h->sc->dev.dv_xname, h->sock));
    482  1.1.2.12  thorpej 		/* shouldn't happen */
    483  1.1.2.12  thorpej 	}
    484  1.1.2.12  thorpej 	if (cscreg & PCIC_CSC_BATTWARN) {
    485  1.1.2.12  thorpej 		DPRINTF(("%s: %02x BATTWARN\n", h->sc->dev.dv_xname, h->sock));
    486  1.1.2.12  thorpej 	}
    487  1.1.2.12  thorpej 	if (cscreg & PCIC_CSC_BATTDEAD) {
    488  1.1.2.12  thorpej 		DPRINTF(("%s: %02x BATTDEAD\n", h->sc->dev.dv_xname, h->sock));
    489  1.1.2.12  thorpej 	}
    490  1.1.2.12  thorpej 	return (cscreg ? 1 : 0);
    491   1.1.2.1     marc }
    492   1.1.2.1     marc 
    493   1.1.2.1     marc void
    494   1.1.2.1     marc pcic_attach_card(h)
    495  1.1.2.12  thorpej 	struct pcic_handle *h;
    496   1.1.2.1     marc {
    497  1.1.2.12  thorpej 	if (h->flags & PCIC_FLAG_CARDP)
    498  1.1.2.12  thorpej 		panic("pcic_attach_card: already attached");
    499   1.1.2.1     marc 
    500  1.1.2.12  thorpej 	/* call the MI attach function */
    501   1.1.2.1     marc 
    502  1.1.2.12  thorpej 	pcmcia_card_attach(h->pcmcia);
    503   1.1.2.1     marc 
    504  1.1.2.12  thorpej 	h->flags |= PCIC_FLAG_CARDP;
    505   1.1.2.1     marc }
    506   1.1.2.1     marc 
    507   1.1.2.1     marc void
    508   1.1.2.1     marc pcic_detach_card(h)
    509  1.1.2.12  thorpej 	struct pcic_handle *h;
    510   1.1.2.1     marc {
    511  1.1.2.12  thorpej 	if (!(h->flags & PCIC_FLAG_CARDP))
    512  1.1.2.12  thorpej 		panic("pcic_attach_card: already detached");
    513   1.1.2.1     marc 
    514  1.1.2.12  thorpej 	h->flags &= ~PCIC_FLAG_CARDP;
    515   1.1.2.1     marc 
    516  1.1.2.12  thorpej 	/* call the MI attach function */
    517   1.1.2.1     marc 
    518  1.1.2.12  thorpej 	pcmcia_card_detach(h->pcmcia);
    519   1.1.2.1     marc 
    520  1.1.2.12  thorpej 	/* disable card detect resume and configuration reset */
    521   1.1.2.1     marc 
    522  1.1.2.12  thorpej 	/* power down the socket */
    523   1.1.2.1     marc 
    524  1.1.2.12  thorpej 	pcic_write(h, PCIC_PWRCTL, 0);
    525   1.1.2.1     marc 
    526  1.1.2.12  thorpej 	/* reset the card */
    527   1.1.2.1     marc 
    528  1.1.2.12  thorpej 	pcic_write(h, PCIC_INTR, 0);
    529   1.1.2.1     marc }
    530   1.1.2.1     marc 
    531  1.1.2.12  thorpej int
    532  1.1.2.12  thorpej pcic_chip_mem_alloc(pch, size, pcmhp)
    533  1.1.2.12  thorpej 	pcmcia_chipset_handle_t pch;
    534  1.1.2.12  thorpej 	bus_size_t size;
    535  1.1.2.12  thorpej 	struct pcmcia_mem_handle *pcmhp;
    536   1.1.2.1     marc {
    537  1.1.2.12  thorpej 	struct pcic_handle *h = (struct pcic_handle *) pch;
    538  1.1.2.12  thorpej 	bus_space_handle_t memh;
    539  1.1.2.12  thorpej 	bus_addr_t addr;
    540  1.1.2.12  thorpej 	bus_size_t sizepg;
    541  1.1.2.12  thorpej 	int i, mask, mhandle;
    542   1.1.2.1     marc 
    543  1.1.2.12  thorpej 	/* out of sc->memh, allocate as many pages as necessary */
    544   1.1.2.1     marc 
    545  1.1.2.12  thorpej 	/* convert size to PCIC pages */
    546  1.1.2.12  thorpej 	sizepg = (size + (PCIC_MEM_ALIGN - 1)) / PCIC_MEM_ALIGN;
    547   1.1.2.1     marc 
    548  1.1.2.12  thorpej 	mask = (1 << sizepg) - 1;
    549   1.1.2.1     marc 
    550  1.1.2.12  thorpej 	addr = 0;		/* XXX gcc -Wuninitialized */
    551  1.1.2.12  thorpej 	mhandle = 0;		/* XXX gcc -Wuninitialized */
    552   1.1.2.8     marc 
    553  1.1.2.12  thorpej 	for (i = 0; i < (PCIC_MEM_PAGES + 1 - sizepg); i++) {
    554  1.1.2.12  thorpej 		if ((h->sc->subregionmask & (mask << i)) == (mask << i)) {
    555  1.1.2.12  thorpej 			if (bus_space_subregion(h->sc->memt, h->sc->memh,
    556  1.1.2.12  thorpej 			    i * PCIC_MEM_PAGESIZE,
    557  1.1.2.12  thorpej 			    sizepg * PCIC_MEM_PAGESIZE, &memh))
    558  1.1.2.12  thorpej 				return (1);
    559  1.1.2.12  thorpej 			mhandle = mask << i;
    560  1.1.2.12  thorpej 			addr = h->sc->membase + (i * PCIC_MEM_PAGESIZE);
    561  1.1.2.12  thorpej 			h->sc->subregionmask &= ~(mhandle);
    562  1.1.2.12  thorpej 			break;
    563  1.1.2.12  thorpej 		}
    564   1.1.2.1     marc 	}
    565   1.1.2.1     marc 
    566  1.1.2.12  thorpej 	if (i == (PCIC_MEM_PAGES + 1 - size))
    567  1.1.2.12  thorpej 		return (1);
    568   1.1.2.1     marc 
    569  1.1.2.12  thorpej 	DPRINTF(("pcic_chip_mem_alloc bus addr 0x%lx+0x%lx\n", (u_long) addr,
    570  1.1.2.12  thorpej 		 (u_long) size));
    571   1.1.2.4  thorpej 
    572  1.1.2.12  thorpej 	pcmhp->memt = h->sc->memt;
    573  1.1.2.12  thorpej 	pcmhp->memh = memh;
    574  1.1.2.12  thorpej 	pcmhp->addr = addr;
    575  1.1.2.12  thorpej 	pcmhp->size = size;
    576  1.1.2.12  thorpej 	pcmhp->mhandle = mhandle;
    577  1.1.2.12  thorpej 	pcmhp->realsize = sizepg * PCIC_MEM_PAGESIZE;
    578   1.1.2.1     marc 
    579  1.1.2.12  thorpej 	return (0);
    580   1.1.2.1     marc }
    581   1.1.2.1     marc 
    582  1.1.2.12  thorpej void
    583  1.1.2.12  thorpej pcic_chip_mem_free(pch, pcmhp)
    584  1.1.2.12  thorpej 	pcmcia_chipset_handle_t pch;
    585  1.1.2.12  thorpej 	struct pcmcia_mem_handle *pcmhp;
    586   1.1.2.1     marc {
    587  1.1.2.12  thorpej 	struct pcic_handle *h = (struct pcic_handle *) pch;
    588   1.1.2.1     marc 
    589  1.1.2.12  thorpej 	h->sc->subregionmask |= pcmhp->mhandle;
    590   1.1.2.1     marc }
    591   1.1.2.1     marc 
    592   1.1.2.1     marc static struct mem_map_index_st {
    593  1.1.2.12  thorpej 	int	sysmem_start_lsb;
    594  1.1.2.12  thorpej 	int	sysmem_start_msb;
    595  1.1.2.12  thorpej 	int	sysmem_stop_lsb;
    596  1.1.2.12  thorpej 	int	sysmem_stop_msb;
    597  1.1.2.12  thorpej 	int	cardmem_lsb;
    598  1.1.2.12  thorpej 	int	cardmem_msb;
    599  1.1.2.12  thorpej 	int	memenable;
    600   1.1.2.1     marc } mem_map_index[] = {
    601  1.1.2.12  thorpej 	{
    602  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR0_START_LSB,
    603  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR0_START_MSB,
    604  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR0_STOP_LSB,
    605  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR0_STOP_MSB,
    606  1.1.2.12  thorpej 		PCIC_CARDMEM_ADDR0_LSB,
    607  1.1.2.12  thorpej 		PCIC_CARDMEM_ADDR0_MSB,
    608  1.1.2.12  thorpej 		PCIC_ADDRWIN_ENABLE_MEM0,
    609  1.1.2.12  thorpej 	},
    610  1.1.2.12  thorpej 	{
    611  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR1_START_LSB,
    612  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR1_START_MSB,
    613  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR1_STOP_LSB,
    614  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR1_STOP_MSB,
    615  1.1.2.12  thorpej 		PCIC_CARDMEM_ADDR1_LSB,
    616  1.1.2.12  thorpej 		PCIC_CARDMEM_ADDR1_MSB,
    617  1.1.2.12  thorpej 		PCIC_ADDRWIN_ENABLE_MEM1,
    618  1.1.2.12  thorpej 	},
    619  1.1.2.12  thorpej 	{
    620  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR2_START_LSB,
    621  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR2_START_MSB,
    622  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR2_STOP_LSB,
    623  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR2_STOP_MSB,
    624  1.1.2.12  thorpej 		PCIC_CARDMEM_ADDR2_LSB,
    625  1.1.2.12  thorpej 		PCIC_CARDMEM_ADDR2_MSB,
    626  1.1.2.12  thorpej 		PCIC_ADDRWIN_ENABLE_MEM2,
    627  1.1.2.12  thorpej 	},
    628  1.1.2.12  thorpej 	{
    629  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR3_START_LSB,
    630  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR3_START_MSB,
    631  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR3_STOP_LSB,
    632  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR3_STOP_MSB,
    633  1.1.2.12  thorpej 		PCIC_CARDMEM_ADDR3_LSB,
    634  1.1.2.12  thorpej 		PCIC_CARDMEM_ADDR3_MSB,
    635  1.1.2.12  thorpej 		PCIC_ADDRWIN_ENABLE_MEM3,
    636  1.1.2.12  thorpej 	},
    637  1.1.2.12  thorpej 	{
    638  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR4_START_LSB,
    639  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR4_START_MSB,
    640  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR4_STOP_LSB,
    641  1.1.2.12  thorpej 		PCIC_SYSMEM_ADDR4_STOP_MSB,
    642  1.1.2.12  thorpej 		PCIC_CARDMEM_ADDR4_LSB,
    643  1.1.2.12  thorpej 		PCIC_CARDMEM_ADDR4_MSB,
    644  1.1.2.12  thorpej 		PCIC_ADDRWIN_ENABLE_MEM4,
    645  1.1.2.12  thorpej 	},
    646   1.1.2.1     marc };
    647   1.1.2.1     marc 
    648  1.1.2.12  thorpej void
    649  1.1.2.12  thorpej pcic_chip_do_mem_map(h, win)
    650  1.1.2.12  thorpej 	struct pcic_handle *h;
    651  1.1.2.12  thorpej 	int win;
    652  1.1.2.12  thorpej {
    653  1.1.2.12  thorpej 	int reg;
    654  1.1.2.12  thorpej 
    655  1.1.2.12  thorpej 	pcic_write(h, mem_map_index[win].sysmem_start_lsb,
    656  1.1.2.12  thorpej 	    (h->mem[win].addr >> PCIC_SYSMEM_ADDRX_SHIFT) & 0xff);
    657  1.1.2.12  thorpej 	pcic_write(h, mem_map_index[win].sysmem_start_msb,
    658  1.1.2.12  thorpej 	    ((h->mem[win].addr >> (PCIC_SYSMEM_ADDRX_SHIFT + 8)) &
    659  1.1.2.12  thorpej 	    PCIC_SYSMEM_ADDRX_START_MSB_ADDR_MASK));
    660  1.1.2.10     marc 
    661  1.1.2.10     marc #if 0
    662  1.1.2.12  thorpej 	/* XXX do I want 16 bit all the time? */
    663  1.1.2.12  thorpej 	PCIC_SYSMEM_ADDRX_START_MSB_DATASIZE_16BIT;
    664  1.1.2.10     marc #endif
    665  1.1.2.10     marc 
    666  1.1.2.12  thorpej 	pcic_write(h, mem_map_index[win].sysmem_stop_lsb,
    667  1.1.2.12  thorpej 	    ((h->mem[win].addr + h->mem[win].size) >>
    668  1.1.2.12  thorpej 	    PCIC_SYSMEM_ADDRX_SHIFT) & 0xff);
    669  1.1.2.12  thorpej 	pcic_write(h, mem_map_index[win].sysmem_stop_msb,
    670  1.1.2.12  thorpej 	    (((h->mem[win].addr + h->mem[win].size) >>
    671  1.1.2.12  thorpej 	    (PCIC_SYSMEM_ADDRX_SHIFT + 8)) &
    672  1.1.2.12  thorpej 	    PCIC_SYSMEM_ADDRX_STOP_MSB_ADDR_MASK) |
    673  1.1.2.12  thorpej 	    PCIC_SYSMEM_ADDRX_STOP_MSB_WAIT2);
    674  1.1.2.12  thorpej 
    675  1.1.2.12  thorpej 	pcic_write(h, mem_map_index[win].cardmem_lsb,
    676  1.1.2.12  thorpej 	    (h->mem[win].offset >> PCIC_CARDMEM_ADDRX_SHIFT) & 0xff);
    677  1.1.2.12  thorpej 	pcic_write(h, mem_map_index[win].cardmem_msb,
    678  1.1.2.12  thorpej 	    ((h->mem[win].offset >> (PCIC_CARDMEM_ADDRX_SHIFT + 8)) &
    679  1.1.2.12  thorpej 	    PCIC_CARDMEM_ADDRX_MSB_ADDR_MASK) |
    680  1.1.2.12  thorpej 	    ((h->mem[win].kind == PCMCIA_MEM_ATTR) ?
    681  1.1.2.12  thorpej 	    PCIC_CARDMEM_ADDRX_MSB_REGACTIVE_ATTR : 0));
    682  1.1.2.12  thorpej 
    683  1.1.2.12  thorpej 	reg = pcic_read(h, PCIC_ADDRWIN_ENABLE);
    684  1.1.2.12  thorpej 	reg |= (mem_map_index[win].memenable | PCIC_ADDRWIN_ENABLE_MEMCS16);
    685  1.1.2.12  thorpej 	pcic_write(h, PCIC_ADDRWIN_ENABLE, reg);
    686  1.1.2.10     marc 
    687  1.1.2.10     marc #ifdef PCICDEBUG
    688  1.1.2.12  thorpej 	{
    689  1.1.2.12  thorpej 		int r1, r2, r3, r4, r5, r6;
    690  1.1.2.12  thorpej 
    691  1.1.2.12  thorpej 		r1 = pcic_read(h, mem_map_index[win].sysmem_start_msb);
    692  1.1.2.12  thorpej 		r2 = pcic_read(h, mem_map_index[win].sysmem_start_lsb);
    693  1.1.2.12  thorpej 		r3 = pcic_read(h, mem_map_index[win].sysmem_stop_msb);
    694  1.1.2.12  thorpej 		r4 = pcic_read(h, mem_map_index[win].sysmem_stop_lsb);
    695  1.1.2.12  thorpej 		r5 = pcic_read(h, mem_map_index[win].cardmem_msb);
    696  1.1.2.12  thorpej 		r6 = pcic_read(h, mem_map_index[win].cardmem_lsb);
    697  1.1.2.10     marc 
    698  1.1.2.12  thorpej 		DPRINTF(("pcic_chip_do_mem_map window %d: %02x%02x %02x%02x "
    699  1.1.2.12  thorpej 		    "%02x%02x\n", win, r1, r2, r3, r4, r5, r6));
    700  1.1.2.12  thorpej 	}
    701  1.1.2.10     marc #endif
    702  1.1.2.10     marc }
    703  1.1.2.10     marc 
    704  1.1.2.12  thorpej int
    705  1.1.2.12  thorpej pcic_chip_mem_map(pch, kind, card_addr, size, pcmhp, offsetp, windowp)
    706  1.1.2.12  thorpej 	pcmcia_chipset_handle_t pch;
    707  1.1.2.12  thorpej 	int kind;
    708  1.1.2.12  thorpej 	bus_addr_t card_addr;
    709  1.1.2.12  thorpej 	bus_size_t size;
    710  1.1.2.12  thorpej 	struct pcmcia_mem_handle *pcmhp;
    711  1.1.2.12  thorpej 	bus_addr_t *offsetp;
    712  1.1.2.12  thorpej 	int *windowp;
    713  1.1.2.12  thorpej {
    714  1.1.2.12  thorpej 	struct pcic_handle *h = (struct pcic_handle *) pch;
    715  1.1.2.12  thorpej 	bus_addr_t busaddr;
    716  1.1.2.12  thorpej 	long card_offset;
    717  1.1.2.12  thorpej 	int i, win;
    718  1.1.2.12  thorpej 
    719  1.1.2.12  thorpej 	win = -1;
    720  1.1.2.12  thorpej 	for (i = 0; i < (sizeof(mem_map_index) / sizeof(mem_map_index[0]));
    721  1.1.2.12  thorpej 	    i++) {
    722  1.1.2.12  thorpej 		if ((h->memalloc & (1 << i)) == 0) {
    723  1.1.2.12  thorpej 			win = i;
    724  1.1.2.12  thorpej 			h->memalloc |= (1 << i);
    725  1.1.2.12  thorpej 			break;
    726  1.1.2.12  thorpej 		}
    727   1.1.2.1     marc 	}
    728   1.1.2.1     marc 
    729  1.1.2.12  thorpej 	if (win == -1)
    730  1.1.2.12  thorpej 		return (1);
    731   1.1.2.1     marc 
    732  1.1.2.12  thorpej 	*windowp = win;
    733   1.1.2.1     marc 
    734  1.1.2.12  thorpej 	/* XXX this is pretty gross */
    735   1.1.2.1     marc 
    736  1.1.2.12  thorpej 	if (h->sc->memt != pcmhp->memt)
    737  1.1.2.12  thorpej 		panic("pcic_chip_mem_map memt is bogus");
    738   1.1.2.1     marc 
    739  1.1.2.12  thorpej 	busaddr = pcmhp->addr;
    740   1.1.2.1     marc 
    741  1.1.2.12  thorpej 	/*
    742  1.1.2.12  thorpej 	 * compute the address offset to the pcmcia address space for the
    743  1.1.2.12  thorpej 	 * pcic.  this is intentionally signed.  The masks and shifts below
    744  1.1.2.12  thorpej 	 * will cause TRT to happen in the pcic registers.  Deal with making
    745  1.1.2.12  thorpej 	 * sure the address is aligned, and return the alignment offset.
    746  1.1.2.12  thorpej 	 */
    747   1.1.2.1     marc 
    748  1.1.2.12  thorpej 	*offsetp = card_addr % PCIC_MEM_ALIGN;
    749  1.1.2.12  thorpej 	card_addr -= *offsetp;
    750   1.1.2.1     marc 
    751  1.1.2.12  thorpej 	DPRINTF(("pcic_chip_mem_map window %d bus %lx+%lx+%lx at card addr "
    752  1.1.2.12  thorpej 	    "%lx\n", win, (u_long) busaddr, (u_long) * offsetp, (u_long) size,
    753  1.1.2.12  thorpej 	    (u_long) card_addr));
    754   1.1.2.1     marc 
    755  1.1.2.12  thorpej 	/*
    756  1.1.2.12  thorpej 	 * include the offset in the size, and decrement size by one, since
    757  1.1.2.12  thorpej 	 * the hw wants start/stop
    758  1.1.2.12  thorpej 	 */
    759  1.1.2.12  thorpej 	size += *offsetp - 1;
    760   1.1.2.1     marc 
    761  1.1.2.12  thorpej 	card_offset = (((long) card_addr) - ((long) busaddr));
    762   1.1.2.1     marc 
    763  1.1.2.12  thorpej 	h->mem[win].addr = busaddr;
    764  1.1.2.12  thorpej 	h->mem[win].size = size;
    765  1.1.2.12  thorpej 	h->mem[win].offset = card_offset;
    766  1.1.2.12  thorpej 	h->mem[win].kind = kind;
    767   1.1.2.1     marc 
    768  1.1.2.12  thorpej 	pcic_chip_do_mem_map(h, win);
    769   1.1.2.1     marc 
    770  1.1.2.12  thorpej 	return (0);
    771   1.1.2.1     marc }
    772   1.1.2.1     marc 
    773  1.1.2.12  thorpej void
    774  1.1.2.12  thorpej pcic_chip_mem_unmap(pch, window)
    775  1.1.2.12  thorpej 	pcmcia_chipset_handle_t pch;
    776  1.1.2.12  thorpej 	int window;
    777   1.1.2.1     marc {
    778  1.1.2.12  thorpej 	struct pcic_handle *h = (struct pcic_handle *) pch;
    779  1.1.2.12  thorpej 	int reg;
    780  1.1.2.12  thorpej 
    781  1.1.2.12  thorpej 	if (window >= (sizeof(mem_map_index) / sizeof(mem_map_index[0])))
    782  1.1.2.12  thorpej 		panic("pcic_chip_mem_unmap: window out of range");
    783   1.1.2.1     marc 
    784  1.1.2.12  thorpej 	reg = pcic_read(h, PCIC_ADDRWIN_ENABLE);
    785  1.1.2.12  thorpej 	reg &= ~mem_map_index[window].memenable;
    786  1.1.2.12  thorpej 	pcic_write(h, PCIC_ADDRWIN_ENABLE, reg);
    787   1.1.2.1     marc 
    788  1.1.2.12  thorpej 	h->memalloc &= ~(1 << window);
    789   1.1.2.1     marc }
    790   1.1.2.1     marc 
    791  1.1.2.12  thorpej int
    792  1.1.2.12  thorpej pcic_chip_io_alloc(pch, start, size, align, pcihp)
    793  1.1.2.12  thorpej 	pcmcia_chipset_handle_t pch;
    794  1.1.2.12  thorpej 	bus_addr_t start;
    795  1.1.2.12  thorpej 	bus_size_t size;
    796  1.1.2.12  thorpej 	bus_size_t align;
    797  1.1.2.12  thorpej 	struct pcmcia_io_handle *pcihp;
    798   1.1.2.1     marc {
    799  1.1.2.12  thorpej 	struct pcic_handle *h = (struct pcic_handle *) pch;
    800  1.1.2.12  thorpej 	bus_space_tag_t iot;
    801  1.1.2.12  thorpej 	bus_space_handle_t ioh;
    802  1.1.2.12  thorpej 	bus_addr_t ioaddr;
    803  1.1.2.12  thorpej 	int flags = 0;
    804   1.1.2.1     marc 
    805  1.1.2.12  thorpej 	/*
    806  1.1.2.12  thorpej 	 * Allocate some arbitrary I/O space.
    807  1.1.2.12  thorpej 	 */
    808   1.1.2.1     marc 
    809  1.1.2.12  thorpej 	iot = h->sc->iot;
    810   1.1.2.4  thorpej 
    811  1.1.2.12  thorpej 	if (start) {
    812  1.1.2.12  thorpej 		ioaddr = start;
    813  1.1.2.12  thorpej 		if (bus_space_map(iot, start, size, 0, &ioh))
    814  1.1.2.12  thorpej 			return (1);
    815  1.1.2.12  thorpej 		DPRINTF(("pcic_chip_io_alloc map port %lx+%lx\n",
    816  1.1.2.12  thorpej 		    (u_long) ioaddr, (u_long) size));
    817  1.1.2.12  thorpej 	} else {
    818  1.1.2.12  thorpej 		flags |= PCMCIA_IO_ALLOCATED;
    819  1.1.2.12  thorpej 		if (bus_space_alloc(iot, h->sc->iobase,
    820  1.1.2.12  thorpej 		    h->sc->iobase + h->sc->iosize, size, align, 0, 0,
    821  1.1.2.12  thorpej 		    &ioaddr, &ioh))
    822  1.1.2.12  thorpej 			return (1);
    823  1.1.2.12  thorpej 		DPRINTF(("pcic_chip_io_alloc alloc port %lx+%lx\n",
    824  1.1.2.12  thorpej 		    (u_long) ioaddr, (u_long) size));
    825  1.1.2.12  thorpej 	}
    826   1.1.2.1     marc 
    827  1.1.2.12  thorpej 	pcihp->iot = iot;
    828  1.1.2.12  thorpej 	pcihp->ioh = ioh;
    829  1.1.2.12  thorpej 	pcihp->addr = ioaddr;
    830  1.1.2.12  thorpej 	pcihp->size = size;
    831  1.1.2.12  thorpej 	pcihp->flags = flags;
    832  1.1.2.12  thorpej 
    833  1.1.2.12  thorpej 	return (0);
    834  1.1.2.12  thorpej }
    835  1.1.2.12  thorpej 
    836  1.1.2.12  thorpej void
    837  1.1.2.12  thorpej pcic_chip_io_free(pch, pcihp)
    838  1.1.2.12  thorpej 	pcmcia_chipset_handle_t pch;
    839  1.1.2.12  thorpej 	struct pcmcia_io_handle *pcihp;
    840  1.1.2.12  thorpej {
    841  1.1.2.12  thorpej 	bus_space_tag_t iot = pcihp->iot;
    842  1.1.2.12  thorpej 	bus_space_handle_t ioh = pcihp->ioh;
    843  1.1.2.12  thorpej 	bus_size_t size = pcihp->size;
    844   1.1.2.4  thorpej 
    845  1.1.2.12  thorpej 	if (pcihp->flags & PCMCIA_IO_ALLOCATED)
    846  1.1.2.12  thorpej 		bus_space_free(iot, ioh, size);
    847  1.1.2.12  thorpej 	else
    848  1.1.2.12  thorpej 		bus_space_unmap(iot, ioh, size);
    849   1.1.2.1     marc }
    850   1.1.2.1     marc 
    851   1.1.2.1     marc 
    852   1.1.2.1     marc static struct io_map_index_st {
    853  1.1.2.12  thorpej 	int	start_lsb;
    854  1.1.2.12  thorpej 	int	start_msb;
    855  1.1.2.12  thorpej 	int	stop_lsb;
    856  1.1.2.12  thorpej 	int	stop_msb;
    857  1.1.2.12  thorpej 	int	ioenable;
    858  1.1.2.12  thorpej 	int	ioctlmask;
    859  1.1.2.13    enami 	int	ioctlbits[3];		/* indexed by PCMCIA_WIDTH_* */
    860  1.1.2.12  thorpej }               io_map_index[] = {
    861  1.1.2.12  thorpej 	{
    862  1.1.2.12  thorpej 		PCIC_IOADDR0_START_LSB,
    863  1.1.2.12  thorpej 		PCIC_IOADDR0_START_MSB,
    864  1.1.2.12  thorpej 		PCIC_IOADDR0_STOP_LSB,
    865  1.1.2.12  thorpej 		PCIC_IOADDR0_STOP_MSB,
    866  1.1.2.12  thorpej 		PCIC_ADDRWIN_ENABLE_IO0,
    867  1.1.2.12  thorpej 		PCIC_IOCTL_IO0_WAITSTATE | PCIC_IOCTL_IO0_ZEROWAIT |
    868  1.1.2.12  thorpej 		PCIC_IOCTL_IO0_IOCS16SRC_MASK | PCIC_IOCTL_IO0_DATASIZE_MASK,
    869  1.1.2.13    enami 		{
    870  1.1.2.13    enami 			PCIC_IOCTL_IO0_IOCS16SRC_CARD,
    871  1.1.2.13    enami 			PCIC_IOCTL_IO0_IOCS16SRC_DATASIZE
    872  1.1.2.13    enami 			    | PCIC_IOCTL_IO0_DATASIZE_8BIT,
    873  1.1.2.13    enami 			PCIC_IOCTL_IO0_IOCS16SRC_DATASIZE
    874  1.1.2.13    enami 			    | PCIC_IOCTL_IO0_DATASIZE_16BIT,
    875  1.1.2.13    enami 		},
    876  1.1.2.12  thorpej 	},
    877  1.1.2.12  thorpej 	{
    878  1.1.2.12  thorpej 		PCIC_IOADDR1_START_LSB,
    879  1.1.2.12  thorpej 		PCIC_IOADDR1_START_MSB,
    880  1.1.2.12  thorpej 		PCIC_IOADDR1_STOP_LSB,
    881  1.1.2.12  thorpej 		PCIC_IOADDR1_STOP_MSB,
    882  1.1.2.12  thorpej 		PCIC_ADDRWIN_ENABLE_IO1,
    883  1.1.2.12  thorpej 		PCIC_IOCTL_IO1_WAITSTATE | PCIC_IOCTL_IO1_ZEROWAIT |
    884  1.1.2.12  thorpej 		PCIC_IOCTL_IO1_IOCS16SRC_MASK | PCIC_IOCTL_IO1_DATASIZE_MASK,
    885  1.1.2.13    enami 		{
    886  1.1.2.13    enami 			PCIC_IOCTL_IO1_IOCS16SRC_CARD,
    887  1.1.2.13    enami 			PCIC_IOCTL_IO1_IOCS16SRC_DATASIZE |
    888  1.1.2.13    enami 			    PCIC_IOCTL_IO1_DATASIZE_8BIT,
    889  1.1.2.13    enami 			PCIC_IOCTL_IO1_IOCS16SRC_DATASIZE |
    890  1.1.2.13    enami 			    PCIC_IOCTL_IO1_DATASIZE_16BIT,
    891  1.1.2.13    enami 		},
    892  1.1.2.12  thorpej 	},
    893   1.1.2.1     marc };
    894   1.1.2.1     marc 
    895  1.1.2.12  thorpej void
    896  1.1.2.12  thorpej pcic_chip_do_io_map(h, win)
    897  1.1.2.12  thorpej 	struct pcic_handle *h;
    898  1.1.2.12  thorpej 	int win;
    899  1.1.2.12  thorpej {
    900  1.1.2.12  thorpej 	int reg;
    901  1.1.2.12  thorpej 
    902  1.1.2.12  thorpej 	DPRINTF(("pcic_chip_do_io_map win %d addr %lx size %lx width %d\n",
    903  1.1.2.12  thorpej 	    win, (long) h->io[win].addr, (long) h->io[win].size,
    904  1.1.2.12  thorpej 	    h->io[win].width * 8));
    905  1.1.2.12  thorpej 
    906  1.1.2.12  thorpej 	pcic_write(h, io_map_index[win].start_lsb, h->io[win].addr & 0xff);
    907  1.1.2.12  thorpej 	pcic_write(h, io_map_index[win].start_msb,
    908  1.1.2.12  thorpej 	    (h->io[win].addr >> 8) & 0xff);
    909  1.1.2.12  thorpej 
    910  1.1.2.12  thorpej 	pcic_write(h, io_map_index[win].stop_lsb,
    911  1.1.2.12  thorpej 	    (h->io[win].addr + h->io[win].size - 1) & 0xff);
    912  1.1.2.12  thorpej 	pcic_write(h, io_map_index[win].stop_msb,
    913  1.1.2.12  thorpej 	    ((h->io[win].addr + h->io[win].size - 1) >> 8) & 0xff);
    914  1.1.2.12  thorpej 
    915  1.1.2.12  thorpej 	reg = pcic_read(h, PCIC_IOCTL);
    916  1.1.2.12  thorpej 	reg &= ~io_map_index[win].ioctlmask;
    917  1.1.2.13    enami 	reg |= io_map_index[win].ioctlbits[h->io[win].width];
    918  1.1.2.12  thorpej 	pcic_write(h, PCIC_IOCTL, reg);
    919   1.1.2.4  thorpej 
    920  1.1.2.12  thorpej 	reg = pcic_read(h, PCIC_ADDRWIN_ENABLE);
    921  1.1.2.12  thorpej 	reg |= io_map_index[win].ioenable;
    922  1.1.2.12  thorpej 	pcic_write(h, PCIC_ADDRWIN_ENABLE, reg);
    923  1.1.2.12  thorpej }
    924  1.1.2.12  thorpej 
    925  1.1.2.12  thorpej int
    926  1.1.2.12  thorpej pcic_chip_io_map(pch, width, offset, size, pcihp, windowp)
    927  1.1.2.12  thorpej 	pcmcia_chipset_handle_t pch;
    928  1.1.2.12  thorpej 	int width;
    929  1.1.2.12  thorpej 	bus_addr_t offset;
    930  1.1.2.12  thorpej 	bus_size_t size;
    931  1.1.2.12  thorpej 	struct pcmcia_io_handle *pcihp;
    932  1.1.2.12  thorpej 	int *windowp;
    933  1.1.2.12  thorpej {
    934  1.1.2.12  thorpej 	struct pcic_handle *h = (struct pcic_handle *) pch;
    935  1.1.2.12  thorpej 	bus_addr_t ioaddr = pcihp->addr + offset;
    936  1.1.2.13    enami 	static char *width_names[] = { "auto", "io8", "io16" };
    937  1.1.2.12  thorpej 	int i, win;
    938  1.1.2.12  thorpej 
    939  1.1.2.12  thorpej 	/* XXX Sanity check offset/size. */
    940  1.1.2.12  thorpej 
    941  1.1.2.12  thorpej 	win = -1;
    942  1.1.2.12  thorpej 	for (i = 0; i < (sizeof(io_map_index) / sizeof(io_map_index[0])); i++) {
    943  1.1.2.12  thorpej 		if ((h->ioalloc & (1 << i)) == 0) {
    944  1.1.2.12  thorpej 			win = i;
    945  1.1.2.12  thorpej 			h->ioalloc |= (1 << i);
    946  1.1.2.12  thorpej 			break;
    947  1.1.2.12  thorpej 		}
    948   1.1.2.1     marc 	}
    949   1.1.2.1     marc 
    950  1.1.2.12  thorpej 	if (win == -1)
    951  1.1.2.12  thorpej 		return (1);
    952   1.1.2.1     marc 
    953  1.1.2.12  thorpej 	*windowp = win;
    954   1.1.2.1     marc 
    955  1.1.2.12  thorpej 	/* XXX this is pretty gross */
    956   1.1.2.1     marc 
    957  1.1.2.12  thorpej 	if (h->sc->iot != pcihp->iot)
    958  1.1.2.12  thorpej 		panic("pcic_chip_io_map iot is bogus");
    959   1.1.2.1     marc 
    960  1.1.2.12  thorpej 	DPRINTF(("pcic_chip_io_map window %d %s port %lx+%lx\n",
    961  1.1.2.13    enami 		 win, width_names[width], (u_long) ioaddr, (u_long) size));
    962   1.1.2.1     marc 
    963  1.1.2.12  thorpej 	/* XXX wtf is this doing here? */
    964  1.1.2.10     marc 
    965  1.1.2.12  thorpej 	printf(" port 0x%lx", (u_long) ioaddr);
    966  1.1.2.12  thorpej 	if (size > 1)
    967  1.1.2.12  thorpej 		printf("-0x%lx", (u_long) ioaddr + (u_long) size - 1);
    968   1.1.2.6      jtk 
    969  1.1.2.12  thorpej 	h->io[win].addr = ioaddr;
    970  1.1.2.12  thorpej 	h->io[win].size = size;
    971  1.1.2.12  thorpej 	h->io[win].width = width;
    972   1.1.2.1     marc 
    973  1.1.2.12  thorpej 	pcic_chip_do_io_map(h, win);
    974   1.1.2.1     marc 
    975  1.1.2.12  thorpej 	return (0);
    976   1.1.2.1     marc }
    977   1.1.2.1     marc 
    978  1.1.2.12  thorpej void
    979  1.1.2.12  thorpej pcic_chip_io_unmap(pch, window)
    980  1.1.2.12  thorpej 	pcmcia_chipset_handle_t pch;
    981  1.1.2.12  thorpej 	int window;
    982   1.1.2.1     marc {
    983  1.1.2.12  thorpej 	struct pcic_handle *h = (struct pcic_handle *) pch;
    984  1.1.2.12  thorpej 	int reg;
    985  1.1.2.12  thorpej 
    986  1.1.2.12  thorpej 	if (window >= (sizeof(io_map_index) / sizeof(io_map_index[0])))
    987  1.1.2.12  thorpej 		panic("pcic_chip_io_unmap: window out of range");
    988   1.1.2.1     marc 
    989  1.1.2.12  thorpej 	reg = pcic_read(h, PCIC_ADDRWIN_ENABLE);
    990  1.1.2.12  thorpej 	reg &= ~io_map_index[window].ioenable;
    991  1.1.2.12  thorpej 	pcic_write(h, PCIC_ADDRWIN_ENABLE, reg);
    992   1.1.2.1     marc 
    993  1.1.2.12  thorpej 	h->ioalloc &= ~(1 << window);
    994   1.1.2.7  thorpej }
    995   1.1.2.7  thorpej 
    996   1.1.2.7  thorpej void
    997   1.1.2.7  thorpej pcic_chip_socket_enable(pch)
    998  1.1.2.12  thorpej 	pcmcia_chipset_handle_t pch;
    999   1.1.2.7  thorpej {
   1000  1.1.2.12  thorpej 	struct pcic_handle *h = (struct pcic_handle *) pch;
   1001  1.1.2.12  thorpej 	int cardtype, reg, win;
   1002  1.1.2.10     marc 
   1003  1.1.2.12  thorpej 	/* this bit is mostly stolen from pcic_attach_card */
   1004  1.1.2.10     marc 
   1005  1.1.2.12  thorpej 	/* power down the socket to reset it, clear the card reset pin */
   1006  1.1.2.10     marc 
   1007  1.1.2.12  thorpej 	pcic_write(h, PCIC_PWRCTL, 0);
   1008  1.1.2.10     marc 
   1009  1.1.2.12  thorpej 	/* power up the socket */
   1010  1.1.2.10     marc 
   1011  1.1.2.12  thorpej 	pcic_write(h, PCIC_PWRCTL, PCIC_PWRCTL_PWR_ENABLE);
   1012  1.1.2.12  thorpej 	delay(10000);
   1013  1.1.2.12  thorpej 	pcic_write(h, PCIC_PWRCTL, PCIC_PWRCTL_PWR_ENABLE | PCIC_PWRCTL_OE);
   1014  1.1.2.10     marc 
   1015  1.1.2.12  thorpej 	/* clear the reset flag */
   1016  1.1.2.10     marc 
   1017  1.1.2.12  thorpej 	pcic_write(h, PCIC_INTR, PCIC_INTR_RESET);
   1018  1.1.2.10     marc 
   1019  1.1.2.12  thorpej 	/* wait 20ms as per pc card standard (r2.01) section 4.3.6 */
   1020  1.1.2.10     marc 
   1021  1.1.2.12  thorpej 	delay(20000);
   1022  1.1.2.10     marc 
   1023  1.1.2.12  thorpej 	/* wait for the chip to finish initializing */
   1024  1.1.2.10     marc 
   1025  1.1.2.12  thorpej 	pcic_wait_ready(h);
   1026  1.1.2.10     marc 
   1027  1.1.2.12  thorpej 	/* zero out the address windows */
   1028  1.1.2.10     marc 
   1029  1.1.2.12  thorpej 	pcic_write(h, PCIC_ADDRWIN_ENABLE, 0);
   1030  1.1.2.10     marc 
   1031  1.1.2.12  thorpej 	/* set the card type */
   1032  1.1.2.10     marc 
   1033  1.1.2.12  thorpej 	cardtype = pcmcia_card_gettype(h->pcmcia);
   1034  1.1.2.10     marc 
   1035  1.1.2.12  thorpej 	reg = pcic_read(h, PCIC_INTR);
   1036  1.1.2.12  thorpej 	reg &= ~PCIC_INTR_CARDTYPE_MASK;
   1037  1.1.2.12  thorpej 	reg |= ((cardtype == PCMCIA_IFTYPE_IO) ?
   1038  1.1.2.12  thorpej 		PCIC_INTR_CARDTYPE_IO :
   1039  1.1.2.12  thorpej 		PCIC_INTR_CARDTYPE_MEM);
   1040  1.1.2.12  thorpej 	reg |= h->ih_irq;
   1041  1.1.2.12  thorpej 	pcic_write(h, PCIC_INTR, reg);
   1042  1.1.2.10     marc 
   1043  1.1.2.12  thorpej 	DPRINTF(("%s: pcic_chip_socket_enable %02x cardtype %s %02x\n",
   1044  1.1.2.12  thorpej 	    h->sc->dev.dv_xname, h->sock,
   1045  1.1.2.12  thorpej 	    ((cardtype == PCMCIA_IFTYPE_IO) ? "io" : "mem"), reg));
   1046  1.1.2.10     marc 
   1047  1.1.2.12  thorpej 	/* reinstall all the memory and io mappings */
   1048  1.1.2.10     marc 
   1049  1.1.2.12  thorpej 	for (win = 0; win < PCIC_MEM_WINS; win++)
   1050  1.1.2.12  thorpej 		if (h->memalloc & (1 << win))
   1051  1.1.2.12  thorpej 			pcic_chip_do_mem_map(h, win);
   1052  1.1.2.10     marc 
   1053  1.1.2.12  thorpej 	for (win = 0; win < PCIC_IO_WINS; win++)
   1054  1.1.2.12  thorpej 		if (h->ioalloc & (1 << win))
   1055  1.1.2.12  thorpej 			pcic_chip_do_io_map(h, win);
   1056   1.1.2.7  thorpej }
   1057   1.1.2.7  thorpej 
   1058   1.1.2.7  thorpej void
   1059   1.1.2.7  thorpej pcic_chip_socket_disable(pch)
   1060  1.1.2.12  thorpej 	pcmcia_chipset_handle_t pch;
   1061   1.1.2.7  thorpej {
   1062  1.1.2.12  thorpej 	struct pcic_handle *h = (struct pcic_handle *) pch;
   1063  1.1.2.10     marc 
   1064  1.1.2.12  thorpej 	DPRINTF(("pcic_chip_socket_disable\n"));
   1065  1.1.2.10     marc 
   1066  1.1.2.12  thorpej 	/* power down the socket */
   1067  1.1.2.10     marc 
   1068  1.1.2.12  thorpej 	pcic_write(h, PCIC_PWRCTL, 0);
   1069   1.1.2.1     marc }
   1070