Home | History | Annotate | Line # | Download | only in pcmcia
com_pcmcia.c revision 1.1.2.8
      1  1.1.2.8  thorpej /*	$NetBSD: com_pcmcia.c,v 1.1.2.8 1997/08/23 01:57:45 thorpej Exp $	*/
      2  1.1.2.1     marc 
      3  1.1.2.1     marc /*-
      4  1.1.2.1     marc  * Copyright (c) 1993, 1994, 1995, 1996
      5  1.1.2.1     marc  *	Charles M. Hannum.  All rights reserved.
      6  1.1.2.1     marc  * Copyright (c) 1991 The Regents of the University of California.
      7  1.1.2.1     marc  * All rights reserved.
      8  1.1.2.1     marc  *
      9  1.1.2.1     marc  * Redistribution and use in source and binary forms, with or without
     10  1.1.2.1     marc  * modification, are permitted provided that the following conditions
     11  1.1.2.1     marc  * are met:
     12  1.1.2.1     marc  * 1. Redistributions of source code must retain the above copyright
     13  1.1.2.1     marc  *    notice, this list of conditions and the following disclaimer.
     14  1.1.2.1     marc  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1.2.1     marc  *    notice, this list of conditions and the following disclaimer in the
     16  1.1.2.1     marc  *    documentation and/or other materials provided with the distribution.
     17  1.1.2.1     marc  * 3. All advertising materials mentioning features or use of this software
     18  1.1.2.1     marc  *    must display the following acknowledgement:
     19  1.1.2.1     marc  *	This product includes software developed by the University of
     20  1.1.2.1     marc  *	California, Berkeley and its contributors.
     21  1.1.2.1     marc  * 4. Neither the name of the University nor the names of its contributors
     22  1.1.2.1     marc  *    may be used to endorse or promote products derived from this software
     23  1.1.2.1     marc  *    without specific prior written permission.
     24  1.1.2.1     marc  *
     25  1.1.2.1     marc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  1.1.2.1     marc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  1.1.2.1     marc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  1.1.2.1     marc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  1.1.2.1     marc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  1.1.2.1     marc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  1.1.2.1     marc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.1.2.1     marc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.1.2.1     marc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.1.2.1     marc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.1.2.1     marc  * SUCH DAMAGE.
     36  1.1.2.1     marc  *
     37  1.1.2.1     marc  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     38  1.1.2.1     marc  */
     39  1.1.2.1     marc 
     40  1.1.2.1     marc #include <sys/param.h>
     41  1.1.2.1     marc #include <sys/systm.h>
     42  1.1.2.1     marc #include <sys/ioctl.h>
     43  1.1.2.1     marc #include <sys/select.h>
     44  1.1.2.1     marc #include <sys/tty.h>
     45  1.1.2.1     marc #include <sys/proc.h>
     46  1.1.2.1     marc #include <sys/user.h>
     47  1.1.2.1     marc #include <sys/conf.h>
     48  1.1.2.1     marc #include <sys/file.h>
     49  1.1.2.1     marc #include <sys/uio.h>
     50  1.1.2.1     marc #include <sys/kernel.h>
     51  1.1.2.1     marc #include <sys/syslog.h>
     52  1.1.2.1     marc #include <sys/types.h>
     53  1.1.2.1     marc #include <sys/device.h>
     54  1.1.2.1     marc 
     55  1.1.2.1     marc #include <machine/intr.h>
     56  1.1.2.1     marc #include <machine/bus.h>
     57  1.1.2.1     marc 
     58  1.1.2.1     marc #include <dev/pcmcia/pcmciavar.h>
     59  1.1.2.1     marc #include <dev/pcmcia/pcmciareg.h>
     60  1.1.2.1     marc 
     61  1.1.2.1     marc #include <dev/isa/comvar.h>
     62  1.1.2.5     matt #include <dev/isa/isareg.h>
     63  1.1.2.1     marc 
     64  1.1.2.1     marc #define PCMCIA_MANUFACTURER_3COM		0x101
     65  1.1.2.1     marc #define PCMCIA_PRODUCT_3COM_3C562		0x562
     66  1.1.2.1     marc 
     67  1.1.2.1     marc #define PCMCIA_MANUFACTURER_MOTOROLA		0x109
     68  1.1.2.1     marc #define PCMCIA_PRODUCT_MOTOROLA_POWER144	0x105
     69  1.1.2.1     marc 
     70  1.1.2.3  thorpej #ifdef __BROKEN_INDIRECT_CONFIG
     71  1.1.2.1     marc int com_pcmcia_match __P((struct device *, void *, void *));
     72  1.1.2.1     marc #else
     73  1.1.2.1     marc int com_pcmcia_match __P((struct device *, struct cfdata *, void *));
     74  1.1.2.1     marc #endif
     75  1.1.2.1     marc void com_pcmcia_attach __P((struct device *, struct device *, void *));
     76  1.1.2.1     marc void com_pcmcia_cleanup __P((void *));
     77  1.1.2.1     marc 
     78  1.1.2.7  thorpej struct com_pcmcia_softc {
     79  1.1.2.7  thorpej 	struct com_softc sc_com;		/* real "com" softc */
     80  1.1.2.7  thorpej 
     81  1.1.2.7  thorpej 	/* PCMCIA-specific goo */
     82  1.1.2.7  thorpej 	struct pcmcia_io_handle sc_pcioh;	/* PCMCIA i/o space info */
     83  1.1.2.7  thorpej 	int sc_io_window;			/* our i/o window */
     84  1.1.2.8  thorpej 	struct pcmcia_function *sc_pf;		/* our PCMCIA function */
     85  1.1.2.7  thorpej };
     86  1.1.2.7  thorpej 
     87  1.1.2.1     marc struct cfattach com_pcmcia_ca = {
     88  1.1.2.7  thorpej 	sizeof(struct com_pcmcia_softc), com_pcmcia_match, com_pcmcia_attach
     89  1.1.2.1     marc };
     90  1.1.2.1     marc 
     91  1.1.2.1     marc int
     92  1.1.2.1     marc com_pcmcia_match(parent, match, aux)
     93  1.1.2.1     marc 	struct device *parent;
     94  1.1.2.3  thorpej #ifdef __BROKEN_INDIRECT_CONFIG
     95  1.1.2.1     marc 	void *match;
     96  1.1.2.1     marc #else
     97  1.1.2.1     marc 	struct cfdata *match;
     98  1.1.2.1     marc #endif
     99  1.1.2.1     marc 	void *aux;
    100  1.1.2.1     marc {
    101  1.1.2.1     marc 	struct pcmcia_attach_args *pa = (struct pcmcia_attach_args *) aux;
    102  1.1.2.5     matt 	struct pcmcia_config_entry *cfe;
    103  1.1.2.1     marc 
    104  1.1.2.1     marc 	if ((pa->manufacturer == PCMCIA_MANUFACTURER_3COM) &&
    105  1.1.2.1     marc 	    (pa->product == PCMCIA_PRODUCT_3COM_3C562) &&
    106  1.1.2.1     marc 	    (pa->pf->number == 1))
    107  1.1.2.1     marc 		return(1);
    108  1.1.2.1     marc 
    109  1.1.2.1     marc 	if ((pa->manufacturer == PCMCIA_MANUFACTURER_MOTOROLA) &&
    110  1.1.2.1     marc 	    (pa->product == PCMCIA_PRODUCT_MOTOROLA_POWER144) &&
    111  1.1.2.1     marc 	    (pa->pf->number == 0))
    112  1.1.2.1     marc 		return(1);
    113  1.1.2.5     matt 
    114  1.1.2.5     matt 	/* find a cfe we can use (if it matches a standard COM port) */
    115  1.1.2.5     matt 
    116  1.1.2.5     matt 	for (cfe = pa->pf->cfe_head.sqh_first; cfe;
    117  1.1.2.5     matt 	     cfe = cfe->cfe_list.sqe_next) {
    118  1.1.2.5     matt 		if (cfe->iospace[0].start == IO_COM1 ||
    119  1.1.2.5     matt 		    cfe->iospace[0].start == IO_COM2 ||
    120  1.1.2.5     matt 		    cfe->iospace[0].start == IO_COM3 ||
    121  1.1.2.5     matt 		    cfe->iospace[0].start == IO_COM4)
    122  1.1.2.5     matt 			return(1);
    123  1.1.2.5     matt 	}
    124  1.1.2.1     marc 
    125  1.1.2.1     marc 	return(0);
    126  1.1.2.1     marc }
    127  1.1.2.1     marc 
    128  1.1.2.1     marc void
    129  1.1.2.1     marc com_pcmcia_attach(parent, self, aux)
    130  1.1.2.1     marc 	struct device *parent, *self;
    131  1.1.2.1     marc 	void *aux;
    132  1.1.2.1     marc {
    133  1.1.2.7  thorpej 	struct com_pcmcia_softc *psc = (void *) self;
    134  1.1.2.7  thorpej 	struct com_softc *sc = &psc->sc_com;
    135  1.1.2.1     marc 	struct pcmcia_attach_args *pa = aux;
    136  1.1.2.1     marc 	struct pcmcia_config_entry *cfe;
    137  1.1.2.1     marc 	char *model;
    138  1.1.2.1     marc 
    139  1.1.2.8  thorpej 	psc->sc_pf = pa->pf;
    140  1.1.2.8  thorpej 
    141  1.1.2.1     marc 	/* find a cfe we can use */
    142  1.1.2.1     marc 
    143  1.1.2.1     marc 	for (cfe = pa->pf->cfe_head.sqh_first; cfe;
    144  1.1.2.1     marc 	     cfe = cfe->cfe_list.sqe_next) {
    145  1.1.2.1     marc 		if (cfe->num_memspace != 0)
    146  1.1.2.1     marc 			continue;
    147  1.1.2.1     marc 
    148  1.1.2.1     marc 		if (cfe->num_iospace != 1)
    149  1.1.2.1     marc 			continue;
    150  1.1.2.1     marc 
    151  1.1.2.1     marc 		if (cfe->iomask == 3) {
    152  1.1.2.1     marc 			if (pcmcia_io_alloc(pa->pf, 0, cfe->iospace[0].length,
    153  1.1.2.7  thorpej 			    &psc->sc_pcioh)) {
    154  1.1.2.1     marc 				continue;
    155  1.1.2.1     marc 			}
    156  1.1.2.1     marc 		} else {
    157  1.1.2.1     marc 			if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
    158  1.1.2.7  thorpej 			    cfe->iospace[0].length, &psc->sc_pcioh)) {
    159  1.1.2.1     marc 				continue;
    160  1.1.2.1     marc 			}
    161  1.1.2.1     marc 		}
    162  1.1.2.1     marc 
    163  1.1.2.1     marc 		break;
    164  1.1.2.1     marc 	}
    165  1.1.2.1     marc 
    166  1.1.2.1     marc 	if (!cfe) {
    167  1.1.2.1     marc 		printf(": can't allocate i/o space\n");
    168  1.1.2.1     marc 		return;
    169  1.1.2.1     marc 	}
    170  1.1.2.1     marc 
    171  1.1.2.7  thorpej 	sc->sc_iot = psc->sc_pcioh.iot;
    172  1.1.2.7  thorpej 	sc->sc_ioh = psc->sc_pcioh.ioh;
    173  1.1.2.7  thorpej 
    174  1.1.2.1     marc 	/* Enable the card. */
    175  1.1.2.8  thorpej 	pcmcia_function_init(pa->pf, cfe);
    176  1.1.2.8  thorpej 	if (pcmcia_function_enable(pa->pf))
    177  1.1.2.1     marc 		printf(": function enable failed\n");
    178  1.1.2.1     marc 
    179  1.1.2.1     marc 	/* turn off the bit which disables the ethernet */
    180  1.1.2.1     marc 	if (pa->product == PCMCIA_PRODUCT_3COM_3C562) {
    181  1.1.2.1     marc 		int reg;
    182  1.1.2.1     marc 
    183  1.1.2.1     marc 		reg = pcmcia_ccr_read(pa->pf, PCMCIA_CCR_OPTION);
    184  1.1.2.1     marc 		reg &= ~0x08;
    185  1.1.2.1     marc 		pcmcia_ccr_write(pa->pf, PCMCIA_CCR_OPTION, reg);
    186  1.1.2.1     marc 	}
    187  1.1.2.1     marc 
    188  1.1.2.1     marc 	/* map in the io space */
    189  1.1.2.1     marc 
    190  1.1.2.7  thorpej 	if (pcmcia_io_map(pa->pf, ((cfe->flags & PCMCIA_CFE_IO16) ?
    191  1.1.2.7  thorpej 	    PCMCIA_WIDTH_IO16 : PCMCIA_WIDTH_IO8), 0, psc->sc_pcioh.size,
    192  1.1.2.7  thorpej 	    &psc->sc_pcioh, &psc->sc_io_window)) {
    193  1.1.2.1     marc 		printf(": can't map i/o space\n");
    194  1.1.2.1     marc 		return;
    195  1.1.2.1     marc 	}
    196  1.1.2.1     marc 
    197  1.1.2.1     marc 	sc->sc_iobase = -1;
    198  1.1.2.1     marc 
    199  1.1.2.1     marc 	com_attach_subr(sc);
    200  1.1.2.1     marc 
    201  1.1.2.1     marc 	switch (pa->product) {
    202  1.1.2.1     marc 	case PCMCIA_PRODUCT_3COM_3C562:
    203  1.1.2.1     marc 		model = "3Com 3C562 Modem";
    204  1.1.2.1     marc 		break;
    205  1.1.2.1     marc 	case PCMCIA_PRODUCT_MOTOROLA_POWER144:
    206  1.1.2.1     marc 		model = "Motorola Power 14.4 Modem";
    207  1.1.2.1     marc 		break;
    208  1.1.2.1     marc 	default:
    209  1.1.2.6     matt 		model = NULL;
    210  1.1.2.1     marc 		break;
    211  1.1.2.1     marc 	}
    212  1.1.2.1     marc 
    213  1.1.2.6     matt 	if (model != NULL)
    214  1.1.2.6     matt 		printf(": %s\n", model);
    215  1.1.2.1     marc 
    216  1.1.2.1     marc 	/* establish the interrupt. */
    217  1.1.2.1     marc 	sc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_SERIAL, comintr, sc);
    218  1.1.2.1     marc 	if (sc->sc_ih == NULL) {
    219  1.1.2.1     marc 		printf("%s: couldn't establish interrupt\n",
    220  1.1.2.1     marc 		       sc->sc_dev.dv_xname);
    221  1.1.2.1     marc 		return;
    222  1.1.2.1     marc 	}
    223  1.1.2.1     marc }
    224