xref: /netbsd/sys/arch/mmeye/dev/com_mainbus.c (revision c4a72b64)
1 /*	$NetBSD: com_mainbus.c,v 1.3 2002/10/02 05:39:04 thorpej 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 CFATTACH_DECL(com_mainbus, sizeof(struct com_mainbus_softc),
72     com_mainbus_match, com_mainbus_attach, NULL, NULL);
73 
74 int
75 com_mainbus_match(struct device *parent, struct cfdata *match, void *aux)
76 {
77 	extern struct cfdriver com_cd;
78 	struct mainbus_attach_args *ma = aux;
79 
80 	if (strcmp(ma->ma_name, com_cd.cd_name) == 0)
81 		return (1);
82 
83 	return (0);
84 }
85 
86 void
87 com_mainbus_attach(struct device *parent, struct device *self, void *aux)
88 {
89 	struct mainbus_attach_args *ma = aux;
90 	struct com_mainbus_softc *sc = (void *)self;
91 	struct com_softc *csc = &sc->sc_com;
92 
93 	csc->sc_iot = 0;
94 	csc->sc_ioh = ma->ma_addr1;
95 	csc->sc_iobase = 0;
96 	csc->sc_frequency = COM_FREQ;
97 
98 	/* sanity check */
99 	if (!comprobe1(csc->sc_iot, csc->sc_ioh)) {
100 		printf(": device problem. don't attach.\n");
101 		return;
102 	}
103 
104 	com_attach_subr(csc);
105 
106 	mmeye_intr_establish(ma->ma_irq1, IST_LEVEL, IPL_SERIAL, comintr, sc);
107 }
108 
109 void
110 comcnprobe(struct consdev *cp)
111 {
112 
113 #ifdef  COMCONSOLE
114 	cp->cn_pri = CN_REMOTE;	/* Force a serial port console */
115 #else
116 	cp->cn_pri = CN_NORMAL;
117 #endif
118 }
119 
120 void
121 comcninit(cp)
122 	struct consdev *cp;
123 {
124 
125 	comcnattach(0, CONADDR, COMCN_SPEED, COM_FREQ, CONMODE);
126 }
127