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