xref: /netbsd-src/sys/arch/mmeye/dev/com_mainbus.c (revision 8e6ab8837d8d6b9198e67c1c445300b483e2f304)
1 /*	$NetBSD: com_mainbus.c,v 1.5 2003/07/15 02:43:44 lukem 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/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: com_mainbus.c,v 1.5 2003/07/15 02:43:44 lukem Exp $");
38 
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 
43 #include <sys/termios.h>
44 #include <dev/cons.h>
45 #include <sys/conf.h>
46 
47 #include <machine/bus.h>
48 #include <machine/intr.h>
49 #include <machine/autoconf.h>
50 #include <machine/mmeye.h>
51 
52 #include <dev/ic/comvar.h>
53 #include <dev/ic/comreg.h>
54 
55 #ifndef COMCN_SPEED
56 #define COMCN_SPEED	19200
57 #endif
58 #ifndef CONADDR
59 #define CONADDR		0xa4000000
60 #endif
61 #ifndef CONMODE
62 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
63 #endif
64 
65 struct com_mainbus_softc {
66 	struct	com_softc sc_com;	/* real "com" softc */
67 };
68 
69 int com_mainbus_match(struct device *, struct cfdata *, void *);
70 void com_mainbus_attach(struct device *, struct device *, void *);
71 void comcnprobe(struct consdev *);
72 void comcninit(struct consdev *);
73 
74 CFATTACH_DECL(com_mainbus, sizeof(struct com_mainbus_softc),
75     com_mainbus_match, com_mainbus_attach, NULL, NULL);
76 
77 int
78 com_mainbus_match(struct device *parent, struct cfdata *match, void *aux)
79 {
80 	extern struct cfdriver com_cd;
81 	struct mainbus_attach_args *ma = aux;
82 
83 	if (strcmp(ma->ma_name, com_cd.cd_name) == 0)
84 		return (1);
85 
86 	return (0);
87 }
88 
89 void
90 com_mainbus_attach(struct device *parent, struct device *self, void *aux)
91 {
92 	struct mainbus_attach_args *ma = aux;
93 	struct com_mainbus_softc *sc = (void *)self;
94 	struct com_softc *csc = &sc->sc_com;
95 
96 	csc->sc_iot = 0;
97 	csc->sc_ioh = ma->ma_addr1;
98 	csc->sc_iobase = 0;
99 	csc->sc_frequency = COM_FREQ;
100 
101 	/* sanity check */
102 	if (!comprobe1(csc->sc_iot, csc->sc_ioh)) {
103 		printf(": device problem. don't attach.\n");
104 		return;
105 	}
106 
107 	com_attach_subr(csc);
108 
109 	mmeye_intr_establish(ma->ma_irq1, IST_LEVEL, IPL_SERIAL, comintr, sc);
110 }
111 
112 void
113 comcnprobe(struct consdev *cp)
114 {
115 
116 #ifdef  COMCONSOLE
117 	cp->cn_pri = CN_REMOTE;	/* Force a serial port console */
118 #else
119 	cp->cn_pri = CN_NORMAL;
120 #endif
121 }
122 
123 void
124 comcninit(cp)
125 	struct consdev *cp;
126 {
127 
128 	comcnattach(0, CONADDR, COMCN_SPEED, COM_FREQ, COM_TYPE_NORMAL,
129 	    CONMODE);
130 }
131