xref: /netbsd-src/sys/arch/sparc/dev/com_ebus.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: com_ebus.c,v 1.13 2006/07/13 22:56:02 gdamore Exp $ */
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Charles M. Hannum.
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  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: com_ebus.c,v 1.13 2006/07/13 22:56:02 gdamore Exp $");
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/termios.h>
46 
47 #include <machine/bus.h>
48 #include <machine/autoconf.h>
49 #include <machine/intr.h>
50 
51 #include <dev/ebus/ebusreg.h>
52 #include <dev/ebus/ebusvar.h>
53 
54 #include <dev/ic/comreg.h>
55 #include <dev/ic/comvar.h>
56 
57 struct com_ebus_softc {
58 	struct com_softc ebsc_com;	/* real "com" softc */
59 
60 	/* this space for rent */
61 };
62 
63 static int com_ebus_match(struct device *, struct cfdata *, void *);
64 static void com_ebus_attach(struct device *, struct device *, void *);
65 
66 CFATTACH_DECL(com_ebus, sizeof(struct com_ebus_softc),
67     com_ebus_match, com_ebus_attach, NULL, NULL);
68 
69 static int
70 com_ebus_match(struct device *parent, struct cfdata *cf, void *aux)
71 {
72 	struct ebus_attach_args *ea = aux;
73 	bus_space_handle_t ioh;
74 	int match;
75 
76 	if (strcmp(ea->ea_name, "su") != 0)
77 		return (0);
78 
79 	match = 0;
80 	if (bus_space_map(ea->ea_bustag, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
81 			  ea->ea_reg[0].size, 0, &ioh) == 0)
82 	{
83 		match = comprobe1(ea->ea_bustag, ioh);
84 		bus_space_unmap(ea->ea_bustag, ioh, ea->ea_reg[0].size);
85 	}
86 
87 	return (match);
88 }
89 
90 static void
91 com_ebus_attach(struct device *parent, struct device *self, void *aux)
92 {
93 	struct com_ebus_softc *ebsc = (void *)self;
94 	struct com_softc *sc = &ebsc->ebsc_com;
95 	struct ebus_attach_args *ea = aux;
96 	bus_space_tag_t iot;
97 	bus_space_handle_t ioh;
98 	bus_addr_t iobase;
99 
100 	iot = ea->ea_bustag;
101 	iobase = EBUS_ADDR_FROM_REG(&ea->ea_reg[0]);
102 	sc->sc_frequency = COM_FREQ;
103 	sc->sc_hwflags = COM_HW_NO_TXPRELOAD;
104 
105 	/*
106 	 * XXX: It would be nice to be able to split console input and
107 	 * output to different devices.  For now switch to serial
108 	 * console if PROM stdin is on serial (so that we can use DDB).
109 	 */
110 	if (prom_instance_to_package(prom_stdin()) == ea->ea_node)
111 		comcnattach(iot, iobase, B9600, sc->sc_frequency,
112 		    COM_TYPE_NORMAL, (CLOCAL | CREAD | CS8));
113 
114 	if (!com_is_console(iot, iobase, &ioh)
115 	    && bus_space_map(iot, iobase, ea->ea_reg[0].size,
116 			     0, &ioh) != 0)
117 	{
118 		printf(": unable to map device registers\n");
119 		return;
120 	}
121 
122 	COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
123 
124 	com_attach_subr(sc);
125 
126 	if (ea->ea_nintr != 0)
127 		(void)bus_intr_establish(iot, ea->ea_intr[0], IPL_SERIAL,
128 					 comintr, sc);
129 }
130