xref: /netbsd-src/sys/arch/mmeye/dev/com_mainbus.c (revision 6d4870476f69938cdd065da8ea9ad989cef459f4)
1 /*	$NetBSD: com_mainbus.c,v 1.13 2018/12/08 17:46:12 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  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: com_mainbus.c,v 1.13 2018/12/08 17:46:12 thorpej Exp $");
31 
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/device.h>
35 
36 #include <sys/termios.h>
37 #include <dev/cons.h>
38 #include <sys/conf.h>
39 #include <sys/bus.h>
40 
41 #include <machine/intr.h>
42 #include <machine/autoconf.h>
43 #include <machine/mmeye.h>
44 
45 #include <dev/ic/comvar.h>
46 #include <dev/ic/comreg.h>
47 
48 #ifndef COMCN_SPEED
49 #define COMCN_SPEED	19200
50 #endif
51 #ifndef CONADDR
52 #define CONADDR		0xa4000000
53 #endif
54 #ifndef CONMODE
55 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
56 #endif
57 
58 struct com_mainbus_softc {
59 	struct	com_softc sc_com;	/* real "com" softc */
60 };
61 
62 int com_mainbus_match(device_t, cfdata_t , void *);
63 void com_mainbus_attach(device_t, device_t, void *);
64 void comcnprobe(struct consdev *);
65 void comcninit(struct consdev *);
66 
67 CFATTACH_DECL_NEW(com_mainbus, sizeof(struct com_mainbus_softc),
68     com_mainbus_match, com_mainbus_attach, NULL, NULL);
69 
70 int
com_mainbus_match(device_t parent,cfdata_t match,void * aux)71 com_mainbus_match(device_t parent, cfdata_t match, void *aux)
72 {
73 	struct mainbus_attach_args *ma = aux;
74 
75 	if (strcmp(ma->ma_name, match->cf_name) == 0)
76 		return (1);
77 
78 	return (0);
79 }
80 
81 void
com_mainbus_attach(device_t parent,device_t self,void * aux)82 com_mainbus_attach(device_t parent, device_t self, void *aux)
83 {
84 	struct mainbus_attach_args *ma = aux;
85 	struct com_mainbus_softc *sc = device_private(self);
86 	struct com_softc *csc = &sc->sc_com;
87 #if defined(SH7750R)
88 	const bus_space_tag_t iot = SH3_BUS_SPACE_PCMCIA_IO8;
89 #else
90 	const bus_space_tag_t iot = 0;
91 #endif
92 	bus_space_handle_t ioh;
93 
94 	if (!com_is_console(iot, ma->ma_addr1, &ioh))
95 		if (bus_space_map(iot, ma->ma_addr1, COM_NPORTS, 0, &ioh)) {
96 			aprint_error(": can't map i/o space\n");
97 			return;
98 		}
99 	csc->sc_dev = self;
100 	csc->sc_frequency = COM_FREQ;
101 	com_init_regs(&csc->sc_regs, iot, ioh, ma->ma_addr1);
102 
103 	/* sanity check */
104 	if (!comprobe1(iot, ioh)) {
105 		aprint_error(": device problem. don't attach.\n");
106 		return;
107 	}
108 
109 	com_attach_subr(csc);
110 
111 	mmeye_intr_establish(ma->ma_irq1, IST_LEVEL, IPL_SERIAL, comintr, sc);
112 }
113 
114 void
comcnprobe(struct consdev * cp)115 comcnprobe(struct consdev *cp)
116 {
117 
118 #ifdef  COMCONSOLE
119 	cp->cn_pri = CN_REMOTE;	/* Force a serial port console */
120 #else
121 	cp->cn_pri = CN_NORMAL;
122 #endif
123 }
124 
125 void
comcninit(struct consdev * cp)126 comcninit(struct consdev *cp)
127 {
128 #if defined(SH7750R)
129 	const bus_space_tag_t iot = SH3_BUS_SPACE_PCMCIA_IO8;
130 #else
131 	const bus_space_tag_t iot = 0;
132 #endif
133 
134 	comcnattach(iot, CONADDR, COMCN_SPEED, COM_FREQ, COM_TYPE_NORMAL,
135 	    CONMODE);
136 }
137