Home | History | Annotate | Line # | Download | only in gemini
gemini_com.c revision 1.1
      1 /*	$NetBSD: gemini_com.c,v 1.1 2008/10/24 04:23:18 matt Exp $	*/
      2 
      3 /* adapted from:
      4  *	NetBSD: omap_com.c,v 1.2 2008/03/14 15:09:09 cube Exp
      5  */
      6 
      7 /*
      8  * Based on arch/arm/xscale/pxa2x0_com.c
      9  *
     10  * Copyright 2003 Wasabi Systems, Inc.
     11  * All rights reserved.
     12  *
     13  * Written by Steve C. Woodford for Wasabi Systems, Inc.
     14  *
     15  * Redistribution and use in source and binary forms, with or without
     16  * modification, are permitted provided that the following conditions
     17  * are met:
     18  * 1. Redistributions of source code must retain the above copyright
     19  *    notice, this list of conditions and the following disclaimer.
     20  * 2. Redistributions in binary form must reproduce the above copyright
     21  *    notice, this list of conditions and the following disclaimer in the
     22  *    documentation and/or other materials provided with the distribution.
     23  * 3. All advertising materials mentioning features or use of this software
     24  *    must display the following acknowledgement:
     25  *      This product includes software developed for the NetBSD Project by
     26  *      Wasabi Systems, Inc.
     27  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     28  *    or promote products derived from this software without specific prior
     29  *    written permission.
     30  *
     31  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     32  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     33  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     34  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     35  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     36  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     37  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     39  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     40  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  * POSSIBILITY OF SUCH DAMAGE.
     42  */
     43 
     44 #include <sys/cdefs.h>
     45 __KERNEL_RCSID(0, "$NetBSD: gemini_com.c,v 1.1 2008/10/24 04:23:18 matt Exp $");
     46 
     47 #include "opt_com.h"
     48 
     49 #include <sys/param.h>
     50 #include <sys/systm.h>
     51 #include <sys/device.h>
     52 #include <sys/termios.h>
     53 
     54 #include <machine/intr.h>
     55 #include <machine/bus.h>
     56 
     57 #include <arm/pic/picvar.h>
     58 
     59 #include <dev/ic/comreg.h>
     60 #include <dev/ic/comvar.h>
     61 
     62 #include <arm/gemini/gemini_reg.h>
     63 #include <arm/gemini/gemini_obiovar.h>
     64 
     65 #include <arm/gemini/gemini_com.h>
     66 
     67 #include "locators.h"
     68 
     69 static int	gemini_com_match(device_t, cfdata_t , void *);
     70 static void	gemini_com_attach(device_t, device_t, void *);
     71 
     72 CFATTACH_DECL_NEW(gemini_com, sizeof(struct com_softc),
     73     gemini_com_match, gemini_com_attach, NULL, NULL);
     74 
     75 static int
     76 gemini_com_match(device_t parent, cfdata_t cf, void *aux)
     77 {
     78 	struct obio_attach_args *obio = aux;
     79 	bus_space_handle_t bh;
     80 	int rv;
     81 
     82 	if (obio->obio_addr == -1 || obio->obio_intr == -1)
     83 	    panic("gemini_com must have addr and intr specified in config.");
     84 
     85 	if (obio->obio_size == 0)
     86 		obio->obio_size = GEMINI_UART_SIZE;
     87 
     88 	if (com_is_console(obio->obio_iot, obio->obio_addr, NULL))
     89 		return (1);
     90 
     91 	if (bus_space_map(obio->obio_iot, obio->obio_addr, obio->obio_size,
     92 			  0, &bh))
     93 		return (0);
     94 
     95 	rv = comprobe1(obio->obio_iot, bh);
     96 
     97 	bus_space_unmap(obio->obio_iot, bh, obio->obio_size);
     98 
     99 	return (rv);
    100 }
    101 
    102 static void
    103 gemini_com_attach(device_t parent, device_t self, void *aux)
    104 {
    105 	struct com_softc *sc = device_private(self);
    106 	struct obio_attach_args *obio = aux;
    107 	bus_space_tag_t iot;
    108 	bus_space_handle_t ioh;
    109 	bus_addr_t iobase;
    110 
    111 	sc->sc_dev = self;
    112 	iot = obio->obio_iot;
    113 	iobase = obio->obio_addr;
    114 	sc->sc_frequency = GEMINI_COM_FREQ;
    115 	sc->sc_type = COM_TYPE_NORMAL;
    116 
    117 	if (com_is_console(iot, iobase, &ioh) == 0 &&
    118 	    bus_space_map(iot, iobase, obio->obio_size, 0, &ioh)) {
    119 		panic(": can't map registers\n");
    120 		return;
    121 	}
    122 	COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
    123 
    124 	com_attach_subr(sc);
    125 	aprint_naive("\n");
    126 
    127 	intr_establish(obio->obio_intr, IPL_SERIAL, IST_LEVEL_HIGH,
    128 		comintr, sc);
    129 }
    130