No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / arm / gemini / gemini_com.c
blob9aaaa3451b19853780a43f078c06988210b78d48
1 /* $NetBSD: gemini_com.c,v 1.1 2008/10/24 04:23:18 matt Exp $ */
3 /* adapted from:
4 * NetBSD: omap_com.c,v 1.2 2008/03/14 15:09:09 cube Exp
5 */
7 /*
8 * Based on arch/arm/xscale/pxa2x0_com.c
10 * Copyright 2003 Wasabi Systems, Inc.
11 * All rights reserved.
13 * Written by Steve C. Woodford for Wasabi Systems, Inc.
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.
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.
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: gemini_com.c,v 1.1 2008/10/24 04:23:18 matt Exp $");
47 #include "opt_com.h"
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/device.h>
52 #include <sys/termios.h>
54 #include <machine/intr.h>
55 #include <machine/bus.h>
57 #include <arm/pic/picvar.h>
59 #include <dev/ic/comreg.h>
60 #include <dev/ic/comvar.h>
62 #include <arm/gemini/gemini_reg.h>
63 #include <arm/gemini/gemini_obiovar.h>
65 #include <arm/gemini/gemini_com.h>
67 #include "locators.h"
69 static int gemini_com_match(device_t, cfdata_t , void *);
70 static void gemini_com_attach(device_t, device_t, void *);
72 CFATTACH_DECL_NEW(gemini_com, sizeof(struct com_softc),
73 gemini_com_match, gemini_com_attach, NULL, NULL);
75 static int
76 gemini_com_match(device_t parent, cfdata_t cf, void *aux)
78 struct obio_attach_args *obio = aux;
79 bus_space_handle_t bh;
80 int rv;
82 if (obio->obio_addr == -1 || obio->obio_intr == -1)
83 panic("gemini_com must have addr and intr specified in config.");
85 if (obio->obio_size == 0)
86 obio->obio_size = GEMINI_UART_SIZE;
88 if (com_is_console(obio->obio_iot, obio->obio_addr, NULL))
89 return (1);
91 if (bus_space_map(obio->obio_iot, obio->obio_addr, obio->obio_size,
92 0, &bh))
93 return (0);
95 rv = comprobe1(obio->obio_iot, bh);
97 bus_space_unmap(obio->obio_iot, bh, obio->obio_size);
99 return (rv);
102 static void
103 gemini_com_attach(device_t parent, device_t self, void *aux)
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;
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_16550_NOERS;
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;
122 COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
124 com_attach_subr(sc);
125 aprint_naive("\n");
127 intr_establish(obio->obio_intr, IPL_SERIAL, IST_LEVEL_HIGH,
128 comintr, sc);