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