Home | History | Annotate | Line # | Download | only in mainbus
com_pioc.c revision 1.9.16.2
      1 /*	$NetBSD: com_pioc.c,v 1.9.16.2 2008/03/17 09:14:13 yamt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Charles M. Hannum.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*-
     40  * Copyright (c) 1991 The Regents of the University of California.
     41  * All rights reserved.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. Neither the name of the University nor the names of its contributors
     52  *    may be used to endorse or promote products derived from this software
     53  *    without specific prior written permission.
     54  *
     55  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     56  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     57  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     58  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     59  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     60  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     61  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     62  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     63  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     64  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     65  * SUCH DAMAGE.
     66  *
     67  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     68  */
     69 
     70 #include <sys/param.h>
     71 
     72 __KERNEL_RCSID(0, "$NetBSD: com_pioc.c,v 1.9.16.2 2008/03/17 09:14:13 yamt Exp $");
     73 
     74 #include <sys/systm.h>
     75 #include <sys/tty.h>
     76 #include <sys/proc.h>
     77 #include <sys/conf.h>
     78 #include <sys/kernel.h>
     79 #include <sys/device.h>
     80 
     81 #include <machine/intr.h>
     82 #include <machine/bus.h>
     83 #include <machine/io.h>
     84 
     85 #include <acorn32/mainbus/piocvar.h>
     86 #include <dev/ic/comreg.h>
     87 #include <dev/ic/comvar.h>
     88 
     89 #include <dev/cons.h>
     90 
     91 #include "locators.h"
     92 
     93 struct com_pioc_softc {
     94 	struct	com_softc sc_com;	/* real "com" softc */
     95 	void	*sc_ih;			/* interrupt handler */
     96 };
     97 
     98 /* Prototypes for functions */
     99 
    100 cons_decl(com);
    101 
    102 static int  com_pioc_probe   (device_t, cfdata_t , void *);
    103 static void com_pioc_attach  (device_t, device_t, void *);
    104 
    105 /* device attach structure */
    106 
    107 CFATTACH_DECL_NEW(com_pioc, sizeof(struct com_pioc_softc),
    108     com_pioc_probe, com_pioc_attach, NULL, NULL);
    109 
    110 extern bus_space_tag_t comconstag;	/* From pioc.c */
    111 
    112 /*
    113  * int com_pioc_probe(struct device *parent, struct cfdata *cf, void *aux)
    114  *
    115  * Make sure we are trying to attach a com device and then
    116  * probe for one.
    117  */
    118 
    119 static int
    120 com_pioc_probe(device_t parent, cfdata_t cf, void *aux)
    121 {
    122 	bus_space_tag_t iot;
    123 	bus_space_handle_t ioh;
    124 	int iobase;
    125 	int rv = 1;
    126 	struct pioc_attach_args *pa = aux;
    127 
    128 	/* We need an offset */
    129 	if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT)
    130 		return(0);
    131 
    132 	iot = pa->pa_iot;
    133 	iobase = pa->pa_iobase + pa->pa_offset;
    134 
    135 	/* if it's in use as console, it's there. */
    136 	if (!com_is_console(iot, iobase, 0)) {
    137 		if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    138 			return 0;
    139 		}
    140 		rv = comprobe1(iot, ioh);
    141 		bus_space_unmap(iot, ioh, COM_NPORTS);
    142 	}
    143 
    144 	if (rv) {
    145 		pa->pa_iosize = COM_NPORTS;
    146 	}
    147 	return (rv);
    148 }
    149 
    150 /*
    151  * void com_pioc_attach(struct device *parent, struct device *self, void *aux)
    152  *
    153  * attach the com device
    154  */
    155 
    156 static void
    157 com_pioc_attach(device_t parent, device_t self, void *aux)
    158 {
    159 	struct com_pioc_softc *psc = device_private(self);
    160 	struct com_softc *sc = &psc->sc_com;
    161 	u_int iobase;
    162 	bus_space_tag_t iot;
    163 	bus_space_handle_t ioh;
    164 	struct pioc_attach_args *pa = aux;
    165 	int count;
    166 
    167 	sc->sc_dev = self;
    168 	iot = pa->pa_iot;
    169 	iobase = pa->pa_iobase + pa->pa_offset;
    170 
    171 /*
    172 	printf(" (iot = %p, iobase = 0x%08x) ", iot, iobase);
    173 */
    174 	if (!com_is_console(iot, iobase, &ioh)
    175 	    && bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh))
    176 		panic("comattach: io mapping failed");
    177 	COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
    178 
    179 	sc->sc_frequency = COM_FREQ;
    180 
    181 	com_attach_subr(sc);
    182 
    183 	if (pa->pa_irq != MAINBUSCF_IRQ_DEFAULT) {
    184 		psc->sc_ih = intr_claim(pa->pa_irq, IPL_SERIAL, "com",
    185 		    comintr, sc);
    186 	}
    187 
    188 	if (!pmf_device_register1(self, com_suspend, com_resume, com_cleanup)) {
    189 		aprint_error_dev(self,
    190 		    "could not establish shutdown hook");
    191 	}
    192 
    193 	/*
    194 	 * This is a patch for bugged revision 1-4 SMC FDC37C665
    195 	 * I/O controllers.
    196 	 * If there is RX data pending when the FIFO in turned on
    197 	 * the RX register cannot be emptied.
    198 	 *
    199 	 * Solution:
    200 	 *   Make sure FIFO is off.
    201 	 *   Read pending data / int status etc.
    202 	 */
    203 	bus_space_write_1(iot, ioh, com_fifo, 0);
    204 	for (count = 0; count < 8; ++count)
    205 		(void)bus_space_read_1(iot, ioh, count);
    206 
    207 }
    208 
    209 /*
    210  * Console attachment functions
    211  */
    212 
    213 void
    214 comcnprobe(struct consdev *cp)
    215 {
    216 
    217 #ifdef  COMCONSOLE
    218 	cp->cn_pri = CN_REMOTE;	/* Force a serial port console */
    219 #else
    220 	cp->cn_pri = CN_NORMAL;
    221 #endif
    222 }
    223 
    224 void
    225 comcninit(struct consdev *cp)
    226 {
    227 	int result;
    228 
    229 #ifndef CONMODE
    230 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    231 #endif
    232 #ifndef CONSPEED
    233 #define CONSPEED 38400
    234 #endif
    235 #ifndef CONADDR
    236 #define CONADDR	0x3f8
    237 #endif
    238 
    239 	result = comcnattach(comconstag, (IO_CONF_BASE + CONADDR), CONSPEED,
    240 	    COM_FREQ, COM_TYPE_NORMAL, CONMODE);
    241 	if (result) {
    242 		printf("initialising serial; got errornr %d\n", result);
    243 		panic("can't init serial console @%x", CONADDR);
    244 	};
    245 }
    246 
    247 
    248 /* End of com_pioc.c */
    249