Home | History | Annotate | Line # | Download | only in nvidia
tegra_com.c revision 1.1.2.2
      1 /* $NetBSD: tegra_com.c,v 1.1.2.2 2015/04/06 15:17:53 skrll Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2013 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Matt Thomas of 3am Software Foundry.
      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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include "locators.h"
     33 
     34 #include <sys/cdefs.h>
     35 
     36 __KERNEL_RCSID(1, "$NetBSD: tegra_com.c,v 1.1.2.2 2015/04/06 15:17:53 skrll Exp $");
     37 
     38 #include <sys/param.h>
     39 #include <sys/bus.h>
     40 #include <sys/device.h>
     41 #include <sys/intr.h>
     42 #include <sys/systm.h>
     43 #include <sys/time.h>
     44 #include <sys/termios.h>
     45 
     46 #include <arm/nvidia/tegra_reg.h>
     47 #include <arm/nvidia/tegra_var.h>
     48 
     49 #include <dev/ic/comvar.h>
     50 
     51 static int tegra_com_match(device_t, cfdata_t, void *);
     52 static void tegra_com_attach(device_t, device_t, void *);
     53 
     54 struct tegra_com_softc {
     55 	struct com_softc tsc_sc;
     56 	void *tsc_ih;
     57 };
     58 
     59 CFATTACH_DECL_NEW(tegra_com, sizeof(struct tegra_com_softc),
     60 	tegra_com_match, tegra_com_attach, NULL, NULL);
     61 
     62 static int
     63 tegra_com_match(device_t parent, cfdata_t cf, void *aux)
     64 {
     65 	struct tegraio_attach_args * const tio = aux;
     66 	const struct tegra_locators * const loc = &tio->tio_loc;
     67 	bus_space_tag_t bst = tio->tio_a4x_bst;
     68 	bus_space_handle_t bsh;
     69 
     70 	if (com_is_console(bst, TEGRA_APB_BASE + loc->loc_offset, NULL))
     71 		return 1;
     72 
     73 	bus_space_subregion(bst, tio->tio_bsh,
     74 	    loc->loc_offset, loc->loc_size, &bsh);
     75 
     76 	return comprobe1(bst, bsh);
     77 }
     78 
     79 static void
     80 tegra_com_attach(device_t parent, device_t self, void *aux)
     81 {
     82 	struct tegra_com_softc * const tsc = device_private(self);
     83 	struct com_softc * const sc = &tsc->tsc_sc;
     84 	struct tegraio_attach_args * const tio = aux;
     85 	const struct tegra_locators * const loc = &tio->tio_loc;
     86 	bus_space_tag_t bst = tio->tio_a4x_bst;
     87 	const bus_addr_t iobase = TEGRA_APB_BASE + loc->loc_offset;
     88 	bus_space_handle_t bsh;
     89 
     90 	sc->sc_dev = self;
     91 	sc->sc_frequency = TEGRA_UART_FREQ;
     92 	sc->sc_type = COM_TYPE_NORMAL;
     93 
     94 	if (com_is_console(bst, iobase, &bsh) == 0
     95 	    && bus_space_subregion(bst, tio->tio_bsh,
     96 		loc->loc_offset / 4, loc->loc_size, &bsh)) {
     97 		panic(": can't map registers");
     98 	}
     99 	COM_INIT_REGS(sc->sc_regs, bst, bsh, iobase);
    100 
    101 	com_attach_subr(sc);
    102 	aprint_naive("\n");
    103 
    104 	tsc->tsc_ih = intr_establish(loc->loc_intr, IPL_SERIAL,
    105 	    IST_LEVEL | IST_MPSAFE, comintr, sc);
    106 	if (tsc->tsc_ih == NULL)
    107 		panic("%s: failed to establish interrupt %d",
    108 		    device_xname(self), loc->loc_intr);
    109 }
    110