No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / arm / omap / omap_com.c
blobc931b64f95ab2705cf2d6d224df753e0deea1275
1 /* $NetBSD: omap_com.c,v 1.2 2008/03/14 15:09:09 cube Exp $ */
3 /*
4 * Based on arch/arm/xscale/pxa2x0_com.c
6 * Copyright 2003 Wasabi Systems, Inc.
7 * All rights reserved.
9 * Written by Steve C. Woodford for Wasabi Systems, Inc.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed for the NetBSD Project by
22 * Wasabi Systems, Inc.
23 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
24 * or promote products derived from this software without specific prior
25 * written permission.
27 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: omap_com.c,v 1.2 2008/03/14 15:09:09 cube Exp $");
43 #include "opt_com.h"
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/device.h>
48 #include <sys/termios.h>
50 #include <machine/intr.h>
51 #include <machine/bus.h>
53 #include <dev/ic/comreg.h>
54 #include <dev/ic/comvar.h>
56 #include <arm/omap/omap_reg.h>
57 #include <arm/omap/omap_tipb.h>
58 #include <arm/omap/omap_com.h>
60 #include "locators.h"
62 static int omapuart_match(device_t, cfdata_t , void *);
63 static void omapuart_attach(device_t, device_t, void *);
65 CFATTACH_DECL_NEW(omapuart, sizeof(struct com_softc),
66 omapuart_match, omapuart_attach, NULL, NULL);
68 static int
69 omapuart_match(device_t parent, cfdata_t cf, void *aux)
71 struct tipb_attach_args *tipb = aux;
72 bus_space_handle_t bh;
73 int rv;
75 if (tipb->tipb_addr == -1 || tipb->tipb_intr == -1)
76 panic("omapuart must have addr and intr specified in config.");
78 if (tipb->tipb_size == 0)
79 tipb->tipb_size = OMAP_COM_SIZE;
81 if (com_is_console(tipb->tipb_iot, tipb->tipb_addr, NULL))
82 return (1);
84 if (bus_space_map(tipb->tipb_iot, tipb->tipb_addr, tipb->tipb_size,
85 0, &bh))
86 return (0);
89 * The TRM says the mode should be disabled while dll and dlh are
90 * being changed so we disable before probing, then enable.
92 bus_space_write_1(tipb->tipb_iot, bh,
93 OMAP_COM_MDR1, OMAP_COM_MDR1_MODE_DISABLE);
95 rv = comprobe1(tipb->tipb_iot, bh);
97 bus_space_write_1(tipb->tipb_iot, bh,
98 OMAP_COM_MDR1, OMAP_COM_MDR1_MODE_UART_16X);
100 bus_space_unmap(tipb->tipb_iot, bh, tipb->tipb_size);
102 return (rv);
105 static void
106 omapuart_attach(device_t parent, device_t self, void *aux)
108 struct com_softc *sc = device_private(self);
109 struct tipb_attach_args *tipb = aux;
110 bus_space_tag_t iot;
111 bus_space_handle_t ioh;
112 bus_addr_t iobase;
114 sc->sc_dev = self;
115 iot = tipb->tipb_iot;
116 iobase = tipb->tipb_addr;
117 sc->sc_frequency = OMAP_COM_FREQ;
118 sc->sc_type = COM_TYPE_NORMAL;
120 if (com_is_console(iot, iobase, &ioh) == 0 &&
121 bus_space_map(iot, iobase, tipb->tipb_size, 0, &ioh)) {
122 panic(": can't map registers\n");
123 return;
125 COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
127 com_attach_subr(sc);
128 aprint_naive("\n");
130 omap_intr_establish(tipb->tipb_intr, IPL_SERIAL,
131 device_xname(sc->sc_dev), comintr, sc);