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