xref: /netbsd/sys/arch/mmeye/dev/com_mainbus.c (revision bf9ec67e)
1 /*	$NetBSD: com_mainbus.c,v 1.1 2002/03/24 18:08:45 uch Exp $	*/
2 
3 /*-
4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *        This product includes software developed by the NetBSD
18  *        Foundation, Inc. and its contributors.
19  * 4. Neither the name of The NetBSD Foundation nor the names of its
20  *    contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 
40 #include <sys/termios.h>
41 #include <dev/cons.h>
42 #include <sys/conf.h>
43 
44 #include <machine/bus.h>
45 #include <machine/intr.h>
46 #include <machine/autoconf.h>
47 #include <machine/mmeye.h>
48 
49 #include <dev/ic/comvar.h>
50 #include <dev/ic/comreg.h>
51 
52 #ifndef COMCN_SPEED
53 #define COMCN_SPEED	19200
54 #endif
55 #ifndef CONADDR
56 #define CONADDR		0xa4000000
57 #endif
58 #ifndef CONMODE
59 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
60 #endif
61 
62 struct com_mainbus_softc {
63 	struct	com_softc sc_com;	/* real "com" softc */
64 };
65 
66 int com_mainbus_match(struct device *, struct cfdata *, void *);
67 void com_mainbus_attach(struct device *, struct device *, void *);
68 void comcnprobe(struct consdev *);
69 void comcninit(struct consdev *);
70 
71 struct cfattach com_mainbus_ca = {
72 	sizeof(struct com_mainbus_softc), com_mainbus_match, com_mainbus_attach
73 };
74 
75 int
76 com_mainbus_match(struct device *parent, struct cfdata *match, void *aux)
77 {
78 	extern struct cfdriver com_cd;
79 	struct mainbus_attach_args *ma = aux;
80 
81 	if (strcmp(ma->ma_name, com_cd.cd_name) == 0)
82 		return (1);
83 
84 	return (0);
85 }
86 
87 void
88 com_mainbus_attach(struct device *parent, struct device *self, void *aux)
89 {
90 	struct mainbus_attach_args *ma = aux;
91 	struct com_mainbus_softc *sc = (void *)self;
92 	struct com_softc *csc = &sc->sc_com;
93 
94 	csc->sc_iot = 0;
95 	csc->sc_ioh = ma->ma_addr1;
96 	csc->sc_iobase = 0;
97 	csc->sc_frequency = COM_FREQ;
98 
99 	/* sanity check */
100 	if (!comprobe1(csc->sc_iot, csc->sc_ioh)) {
101 		printf(": device problem. don't attach.\n");
102 		return;
103 	}
104 
105 	com_attach_subr(csc);
106 
107 	mmeye_intr_establish(ma->ma_irq1, IST_LEVEL, IPL_SERIAL, comintr, sc);
108 }
109 
110 void
111 comcnprobe(struct consdev *cp)
112 {
113 
114 #ifdef  COMCONSOLE
115 	cp->cn_pri = CN_REMOTE;	/* Force a serial port console */
116 #else
117 	cp->cn_pri = CN_NORMAL;
118 #endif
119 }
120 
121 void
122 comcninit(cp)
123 	struct consdev *cp;
124 {
125 
126 	comcnattach(0, CONADDR, COMCN_SPEED, COM_FREQ, CONMODE);
127 }
128