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