Home | History | Annotate | Line # | Download | only in mca
com_mca.c revision 1.9
      1  1.9   thorpej /*	$NetBSD: com_mca.c,v 1.9 2002/10/02 16:34:06 thorpej Exp $	*/
      2  1.1  jdolecek 
      3  1.1  jdolecek /*-
      4  1.2  jdolecek  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.1  jdolecek  * All rights reserved.
      6  1.1  jdolecek  *
      7  1.1  jdolecek  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  jdolecek  * by Charles M. Hannum.
      9  1.1  jdolecek  *
     10  1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     11  1.1  jdolecek  * modification, are permitted provided that the following conditions
     12  1.1  jdolecek  * are met:
     13  1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     14  1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     15  1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     18  1.1  jdolecek  * 3. All advertising materials mentioning features or use of this software
     19  1.1  jdolecek  *    must display the following acknowledgement:
     20  1.1  jdolecek  *        This product includes software developed by the NetBSD
     21  1.1  jdolecek  *        Foundation, Inc. and its contributors.
     22  1.1  jdolecek  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  jdolecek  *    contributors may be used to endorse or promote products derived
     24  1.1  jdolecek  *    from this software without specific prior written permission.
     25  1.1  jdolecek  *
     26  1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  jdolecek  */
     38  1.1  jdolecek 
     39  1.1  jdolecek /*-
     40  1.1  jdolecek  * Copyright (c) 1991 The Regents of the University of California.
     41  1.1  jdolecek  * All rights reserved.
     42  1.1  jdolecek  *
     43  1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     44  1.1  jdolecek  * modification, are permitted provided that the following conditions
     45  1.1  jdolecek  * are met:
     46  1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     47  1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     48  1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     49  1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     50  1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     51  1.1  jdolecek  * 3. All advertising materials mentioning features or use of this software
     52  1.1  jdolecek  *    must display the following acknowledgement:
     53  1.1  jdolecek  *	This product includes software developed by the University of
     54  1.1  jdolecek  *	California, Berkeley and its contributors.
     55  1.1  jdolecek  * 4. Neither the name of the University nor the names of its contributors
     56  1.1  jdolecek  *    may be used to endorse or promote products derived from this software
     57  1.1  jdolecek  *    without specific prior written permission.
     58  1.1  jdolecek  *
     59  1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  1.1  jdolecek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  1.1  jdolecek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  1.1  jdolecek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  1.1  jdolecek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  1.1  jdolecek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  1.1  jdolecek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  1.1  jdolecek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  1.1  jdolecek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  1.1  jdolecek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  1.1  jdolecek  * SUCH DAMAGE.
     70  1.1  jdolecek  *
     71  1.1  jdolecek  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     72  1.1  jdolecek  */
     73  1.1  jdolecek 
     74  1.1  jdolecek /*
     75  1.1  jdolecek  * This driver attaches serial port boards and internal modems.
     76  1.1  jdolecek  */
     77  1.5     lukem 
     78  1.5     lukem #include <sys/cdefs.h>
     79  1.9   thorpej __KERNEL_RCSID(0, "$NetBSD: com_mca.c,v 1.9 2002/10/02 16:34:06 thorpej Exp $");
     80  1.1  jdolecek 
     81  1.1  jdolecek #include <sys/param.h>
     82  1.1  jdolecek #include <sys/systm.h>
     83  1.1  jdolecek #include <sys/ioctl.h>
     84  1.1  jdolecek #include <sys/select.h>
     85  1.1  jdolecek #include <sys/tty.h>
     86  1.1  jdolecek #include <sys/proc.h>
     87  1.1  jdolecek #include <sys/user.h>
     88  1.1  jdolecek #include <sys/file.h>
     89  1.1  jdolecek #include <sys/uio.h>
     90  1.1  jdolecek #include <sys/kernel.h>
     91  1.1  jdolecek #include <sys/syslog.h>
     92  1.1  jdolecek #include <sys/device.h>
     93  1.1  jdolecek 
     94  1.1  jdolecek #include <machine/intr.h>
     95  1.1  jdolecek #include <machine/bus.h>
     96  1.1  jdolecek 
     97  1.1  jdolecek #include <dev/ic/comreg.h>
     98  1.1  jdolecek #include <dev/ic/comvar.h>
     99  1.1  jdolecek 
    100  1.1  jdolecek #include <dev/mca/mcavar.h>
    101  1.1  jdolecek #include <dev/mca/mcadevs.h>
    102  1.1  jdolecek 
    103  1.1  jdolecek struct com_mca_softc {
    104  1.1  jdolecek 	struct	com_softc sc_com;	/* real "com" softc */
    105  1.1  jdolecek 
    106  1.1  jdolecek 	/* MCA-specific goo. */
    107  1.1  jdolecek 	void	*sc_ih;			/* interrupt handler */
    108  1.1  jdolecek };
    109  1.1  jdolecek 
    110  1.1  jdolecek int com_mca_probe __P((struct device *, struct cfdata *, void *));
    111  1.1  jdolecek void com_mca_attach __P((struct device *, struct device *, void *));
    112  1.1  jdolecek void com_mca_cleanup __P((void *));
    113  1.3  jdolecek 
    114  1.1  jdolecek static int ibm_modem_getcfg __P((struct mca_attach_args *, int *, int *));
    115  1.3  jdolecek static int neocom1_getcfg __P((struct mca_attach_args *, int *, int *));
    116  1.4  jdolecek static int ibm_mpcom_getcfg __P((struct mca_attach_args *, int *, int *));
    117  1.1  jdolecek 
    118  1.8   thorpej CFATTACH_DECL(com_mca, sizeof(struct com_mca_softc),
    119  1.9   thorpej     com_mca_probe, com_mca_attach, NULL, NULL);
    120  1.1  jdolecek 
    121  1.1  jdolecek static const struct com_mca_product {
    122  1.1  jdolecek 	u_int32_t	cp_prodid;	/* MCA product ID */
    123  1.1  jdolecek 	const char	*cp_name;	/* device name */
    124  1.1  jdolecek 	int (*cp_getcfg) __P((struct mca_attach_args *, int *iobase, int *irq));
    125  1.1  jdolecek 					/* get device i/o base and irq */
    126  1.1  jdolecek } com_mca_products[] = {
    127  1.1  jdolecek 	{ MCA_PRODUCT_IBM_MOD,	"IBM Internal Modem",	ibm_modem_getcfg },
    128  1.3  jdolecek 	{ MCA_PRODUCT_NEOCOM1,	"NeoTecH Single RS-232 Async. Adapter, SM110",
    129  1.3  jdolecek 		neocom1_getcfg },
    130  1.4  jdolecek 	{ MCA_PRODUCT_IBM_MPCOM,"IBM Multi-Protocol Communications Adapter",
    131  1.4  jdolecek 		ibm_mpcom_getcfg },
    132  1.1  jdolecek 	{ 0,			NULL,			NULL },
    133  1.1  jdolecek };
    134  1.1  jdolecek 
    135  1.1  jdolecek static const struct com_mca_product *com_mca_lookup __P((int));
    136  1.1  jdolecek 
    137  1.1  jdolecek static const struct com_mca_product *
    138  1.1  jdolecek com_mca_lookup(ma_id)
    139  1.1  jdolecek 	int ma_id;
    140  1.1  jdolecek {
    141  1.1  jdolecek 	const struct com_mca_product *cpp;
    142  1.1  jdolecek 
    143  1.1  jdolecek 	for (cpp = com_mca_products; cpp->cp_name != NULL; cpp++)
    144  1.1  jdolecek 		if (cpp->cp_prodid == ma_id)
    145  1.1  jdolecek 			return (cpp);
    146  1.1  jdolecek 
    147  1.1  jdolecek 	return (NULL);
    148  1.1  jdolecek }
    149  1.1  jdolecek 
    150  1.1  jdolecek int
    151  1.1  jdolecek com_mca_probe(parent, match, aux)
    152  1.1  jdolecek 	struct device *parent;
    153  1.1  jdolecek 	struct cfdata *match;
    154  1.1  jdolecek 	void *aux;
    155  1.1  jdolecek {
    156  1.1  jdolecek 	struct mca_attach_args *ma = aux;
    157  1.1  jdolecek 
    158  1.1  jdolecek 	if (com_mca_lookup(ma->ma_id))
    159  1.1  jdolecek 		return (1);
    160  1.1  jdolecek 
    161  1.1  jdolecek 	return (0);
    162  1.1  jdolecek }
    163  1.1  jdolecek 
    164  1.1  jdolecek void
    165  1.1  jdolecek com_mca_attach(parent, self, aux)
    166  1.1  jdolecek 	struct device *parent, *self;
    167  1.1  jdolecek 	void *aux;
    168  1.1  jdolecek {
    169  1.1  jdolecek 	struct com_mca_softc *isc = (void *)self;
    170  1.1  jdolecek 	struct com_softc *sc = &isc->sc_com;
    171  1.1  jdolecek 	int iobase, irq;
    172  1.1  jdolecek 	struct mca_attach_args *ma = aux;
    173  1.1  jdolecek 	const struct com_mca_product *cpp;
    174  1.1  jdolecek 
    175  1.1  jdolecek 	cpp = com_mca_lookup(ma->ma_id);
    176  1.1  jdolecek 
    177  1.1  jdolecek 	/* get iobase and irq */
    178  1.4  jdolecek 	if ((*cpp->cp_getcfg)(ma, &iobase, &irq))
    179  1.1  jdolecek 		return;
    180  1.1  jdolecek 
    181  1.1  jdolecek 	if (bus_space_map(ma->ma_iot, iobase, COM_NPORTS, 0, &sc->sc_ioh)) {
    182  1.1  jdolecek 		printf(": can't map i/o space\n");
    183  1.1  jdolecek 		return;
    184  1.1  jdolecek 	}
    185  1.1  jdolecek 
    186  1.1  jdolecek 	sc->sc_frequency = COM_FREQ;
    187  1.1  jdolecek 	sc->sc_iot = ma->ma_iot;
    188  1.1  jdolecek 	sc->sc_iobase = iobase;
    189  1.1  jdolecek 
    190  1.3  jdolecek 	printf(" slot %d i/o %#x-%#x irq %d", ma->ma_slot + 1,
    191  1.3  jdolecek 		iobase, iobase + COM_NPORTS - 1, irq);
    192  1.3  jdolecek 
    193  1.1  jdolecek 	com_attach_subr(sc);
    194  1.1  jdolecek 
    195  1.3  jdolecek 	printf("%s: %s\n", sc->sc_dev.dv_xname, cpp->cp_name);
    196  1.3  jdolecek 
    197  1.1  jdolecek 	isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_SERIAL,
    198  1.1  jdolecek 			comintr, sc);
    199  1.1  jdolecek 	if (isc->sc_ih == NULL) {
    200  1.1  jdolecek                 printf("%s: couldn't establish interrupt handler\n",
    201  1.1  jdolecek                     sc->sc_dev.dv_xname);
    202  1.1  jdolecek                 return;
    203  1.1  jdolecek         }
    204  1.1  jdolecek 
    205  1.1  jdolecek 	/*
    206  1.1  jdolecek 	 * Shutdown hook for buggy BIOSs that don't recognize the UART
    207  1.1  jdolecek 	 * without a disabled FIFO.
    208  1.1  jdolecek 	 * XXX is this necessary on MCA ? --- jdolecek
    209  1.1  jdolecek 	 */
    210  1.1  jdolecek 	if (shutdownhook_establish(com_mca_cleanup, sc) == NULL)
    211  1.1  jdolecek 		panic("com_mca_attach: could not establish shutdown hook");
    212  1.1  jdolecek }
    213  1.1  jdolecek 
    214  1.1  jdolecek void
    215  1.1  jdolecek com_mca_cleanup(arg)
    216  1.1  jdolecek 	void *arg;
    217  1.1  jdolecek {
    218  1.1  jdolecek 	struct com_softc *sc = arg;
    219  1.1  jdolecek 
    220  1.1  jdolecek 	if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
    221  1.1  jdolecek 		bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_fifo, 0);
    222  1.1  jdolecek }
    223  1.1  jdolecek 
    224  1.1  jdolecek /* map serial_X to iobase and irq */
    225  1.1  jdolecek static const struct {
    226  1.1  jdolecek 	int iobase;
    227  1.1  jdolecek 	int irq;
    228  1.1  jdolecek } MCA_SERIAL[] = {
    229  1.1  jdolecek 	{ 0x03f8,	4 },	/* SERIAL_1 */
    230  1.1  jdolecek 	{ 0x02f8,	3 },	/* SERIAL_2 */
    231  1.1  jdolecek 	{ 0x3220,	3 },	/* SERIAL_3 */
    232  1.1  jdolecek 	{ 0x3228,	3 },	/* SERIAL_4 */
    233  1.1  jdolecek 	{ 0x4220,	3 },	/* SERIAL_5 */
    234  1.1  jdolecek 	{ 0x4228,	3 },	/* SERIAL_6 */
    235  1.1  jdolecek 	{ 0x5220,	3 },	/* SERIAL_7 */
    236  1.1  jdolecek 	{ 0x5228,	3 },	/* SERIAL_8 */
    237  1.1  jdolecek };
    238  1.1  jdolecek 
    239  1.1  jdolecek /*
    240  1.1  jdolecek  * Get config for IBM Internal Modem (ID 0xEDFF). This beast doesn't
    241  1.1  jdolecek  * seem to support even AT commands, it's good as example for adding
    242  1.1  jdolecek  * other stuff though.
    243  1.1  jdolecek  */
    244  1.1  jdolecek static int
    245  1.1  jdolecek ibm_modem_getcfg(ma, iobasep, irqp)
    246  1.1  jdolecek 	struct mca_attach_args *ma;
    247  1.1  jdolecek 	int *iobasep, *irqp;
    248  1.1  jdolecek {
    249  1.1  jdolecek 	int pos2;
    250  1.1  jdolecek 	int snum;
    251  1.1  jdolecek 
    252  1.1  jdolecek 	pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
    253  1.1  jdolecek 
    254  1.1  jdolecek 	/*
    255  1.1  jdolecek 	 * POS register 2: (adf pos0)
    256  1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    257  1.1  jdolecek 	 *         \__/  \__ enable: 0=adapter disabled, 1=adapter enabled
    258  1.1  jdolecek 	 *            \_____ Serial Configuration: XX=SERIAL_XX
    259  1.1  jdolecek 	 */
    260  1.1  jdolecek 
    261  1.1  jdolecek 	snum = (pos2 & 0x0e) >> 1;
    262  1.1  jdolecek 
    263  1.1  jdolecek 	*iobasep = MCA_SERIAL[snum].iobase;
    264  1.1  jdolecek 	*irqp = MCA_SERIAL[snum].irq;
    265  1.3  jdolecek 
    266  1.3  jdolecek 	return (0);
    267  1.3  jdolecek }
    268  1.3  jdolecek 
    269  1.3  jdolecek /*
    270  1.3  jdolecek  * Get configuration for NeoTecH Single RS-232 Async. Adapter, SM110.
    271  1.3  jdolecek  */
    272  1.3  jdolecek static int
    273  1.3  jdolecek neocom1_getcfg(ma, iobasep, irqp)
    274  1.3  jdolecek 	struct mca_attach_args *ma;
    275  1.3  jdolecek 	int *iobasep, *irqp;
    276  1.3  jdolecek {
    277  1.3  jdolecek 	int pos2, pos3, pos4;
    278  1.3  jdolecek 	static const int neotech_irq[] = { 12, 9, 4, 3 };
    279  1.3  jdolecek 
    280  1.3  jdolecek 	pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
    281  1.3  jdolecek 	pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
    282  1.3  jdolecek 	pos4 = mca_conf_read(ma->ma_mc, ma->ma_slot, 4);
    283  1.3  jdolecek 
    284  1.3  jdolecek 	/*
    285  1.3  jdolecek 	 * POS register 2: (adf pos0)
    286  1.3  jdolecek 	 * 7 6 5 4 3 2 1 0
    287  1.3  jdolecek 	 *     1     \_/ \__ enable: 0=adapter disabled, 1=adapter enabled
    288  1.3  jdolecek 	 *             \____ IRQ: 11=3 10=4 01=9 00=12
    289  1.3  jdolecek 	 *
    290  1.3  jdolecek 	 * POS register 3: (adf pos1)
    291  1.3  jdolecek 	 * 7 6 5 4 3 2 1 0
    292  1.3  jdolecek 	 * \______/
    293  1.3  jdolecek 	 *        \_________ I/O Address: bits 7-3
    294  1.3  jdolecek 	 *
    295  1.3  jdolecek 	 * POS register 4: (adf pos2)
    296  1.3  jdolecek 	 * 7 6 5 4 3 2 1 0
    297  1.3  jdolecek 	 * \_____________/
    298  1.3  jdolecek 	 *               \__ I/O Address: bits 15-8
    299  1.3  jdolecek 	 */
    300  1.3  jdolecek 
    301  1.3  jdolecek 	*iobasep = (pos4 << 8) | (pos3 & 0xf8);
    302  1.3  jdolecek 	*irqp = neotech_irq[(pos2 & 0x06) >> 1];
    303  1.4  jdolecek 
    304  1.4  jdolecek 	return (0);
    305  1.4  jdolecek }
    306  1.4  jdolecek 
    307  1.4  jdolecek /*
    308  1.4  jdolecek  * Get configuration for IBM Multi-Protocol Communications Adapter.
    309  1.4  jdolecek  * We only support SERIAL mode, bail out if set to SDLC or BISYNC.
    310  1.4  jdolecek  */
    311  1.4  jdolecek static int
    312  1.4  jdolecek ibm_mpcom_getcfg(ma, iobasep, irqp)
    313  1.4  jdolecek 	struct mca_attach_args *ma;
    314  1.4  jdolecek 	int *iobasep, *irqp;
    315  1.4  jdolecek {
    316  1.4  jdolecek 	int snum, pos2;
    317  1.4  jdolecek 
    318  1.4  jdolecek 	pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
    319  1.4  jdolecek 
    320  1.4  jdolecek 	/*
    321  1.4  jdolecek 	 * For SERIAL mode, bit 4 has to be 0.
    322  1.4  jdolecek 	 *
    323  1.4  jdolecek 	 * POS register 2: (adf pos0)
    324  1.4  jdolecek 	 * 7 6 5 4 3 2 1 0
    325  1.4  jdolecek 	 *       0 \__/  \__ enable: 0=adapter disabled, 1=adapter enabled
    326  1.4  jdolecek 	 *            \_____ Serial Configuration: XX=SERIAL_XX
    327  1.4  jdolecek 	 */
    328  1.4  jdolecek 
    329  1.4  jdolecek 	if (pos2 & 0x10) {
    330  1.4  jdolecek 		printf(": not set to SERIAL mode, ignored\n");
    331  1.4  jdolecek 		return (1);
    332  1.4  jdolecek 	}
    333  1.4  jdolecek 
    334  1.4  jdolecek 	snum = (pos2 & 0x0e) >> 1;
    335  1.4  jdolecek 
    336  1.4  jdolecek 	*iobasep = MCA_SERIAL[snum].iobase;
    337  1.4  jdolecek 	*irqp = MCA_SERIAL[snum].irq;
    338  1.1  jdolecek 
    339  1.1  jdolecek 	return (0);
    340  1.1  jdolecek }
    341