xref: /netbsd-src/sys/arch/evbppc/explora/dev/com_elb.c (revision 18d34ecae7b659c307699164b9c70d0f49a00b25)
1*18d34ecaSrin /*	$NetBSD: com_elb.c,v 1.12 2021/03/16 08:16:53 rin Exp $	*/
2249e0067Shannken 
3249e0067Shannken /*-
4249e0067Shannken  * Copyright (c) 2003 The NetBSD Foundation, Inc.
5249e0067Shannken  * All rights reserved.
6249e0067Shannken  *
7249e0067Shannken  * This code is derived from software contributed to The NetBSD Foundation
8249e0067Shannken  * by Juergen Hannken-Illjes.
9249e0067Shannken  *
10249e0067Shannken  * Redistribution and use in source and binary forms, with or without
11249e0067Shannken  * modification, are permitted provided that the following conditions
12249e0067Shannken  * are met:
13249e0067Shannken  * 1. Redistributions of source code must retain the above copyright
14249e0067Shannken  *    notice, this list of conditions and the following disclaimer.
15249e0067Shannken  * 2. Redistributions in binary form must reproduce the above copyright
16249e0067Shannken  *    notice, this list of conditions and the following disclaimer in the
17249e0067Shannken  *    documentation and/or other materials provided with the distribution.
18249e0067Shannken  *
19249e0067Shannken  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20249e0067Shannken  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21249e0067Shannken  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22249e0067Shannken  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23249e0067Shannken  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24249e0067Shannken  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25249e0067Shannken  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26249e0067Shannken  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27249e0067Shannken  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28249e0067Shannken  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29249e0067Shannken  * POSSIBILITY OF SUCH DAMAGE.
30249e0067Shannken  */
31249e0067Shannken 
3214172728Slukem #include <sys/cdefs.h>
33*18d34ecaSrin __KERNEL_RCSID(0, "$NetBSD: com_elb.c,v 1.12 2021/03/16 08:16:53 rin Exp $");
3414172728Slukem 
35249e0067Shannken #include <sys/param.h>
36249e0067Shannken #include <sys/conf.h>
37249e0067Shannken #include <sys/device.h>
38249e0067Shannken #include <sys/systm.h>
39249e0067Shannken #include <sys/tty.h>
40249e0067Shannken 
41cf10107dSdyoung #include <sys/bus.h>
42249e0067Shannken 
43249e0067Shannken #include <dev/ic/comreg.h>
44249e0067Shannken #include <dev/ic/comvar.h>
45249e0067Shannken 
46249e0067Shannken #include <evbppc/explora/dev/elbvar.h>
47249e0067Shannken 
48249e0067Shannken struct com_elb_softc {
49249e0067Shannken 	struct com_softc sc_com;
50249e0067Shannken 	void *sc_ih;
51249e0067Shannken };
52249e0067Shannken 
53607ead0eScube static int	com_elb_probe(device_t, cfdata_t , void *);
54607ead0eScube static void	com_elb_attach(device_t, device_t, void *);
55249e0067Shannken 
56607ead0eScube CFATTACH_DECL_NEW(com_elb, sizeof(struct com_elb_softc),
57249e0067Shannken     com_elb_probe, com_elb_attach, NULL, NULL);
58249e0067Shannken 
59249e0067Shannken int
com_elb_probe(device_t parent,cfdata_t cf,void * aux)60607ead0eScube com_elb_probe(device_t parent, cfdata_t cf, void *aux)
61249e0067Shannken {
62*18d34ecaSrin 	struct elb_attach_args *eaa = aux;
63249e0067Shannken 
64*18d34ecaSrin 	if (strcmp(eaa->elb_name, cf->cf_name) != 0)
65249e0067Shannken 		return 0;
66249e0067Shannken 
67*18d34ecaSrin 	return 1;
68249e0067Shannken }
69249e0067Shannken 
70249e0067Shannken void
com_elb_attach(device_t parent,device_t self,void * aux)71607ead0eScube com_elb_attach(device_t parent, device_t self, void *aux)
72249e0067Shannken {
73607ead0eScube 	struct com_elb_softc *msc = device_private(self);
74249e0067Shannken 	struct com_softc *sc = &msc->sc_com;
75249e0067Shannken 	struct elb_attach_args *eaa = aux;
7634537908Sgdamore 	bus_space_handle_t ioh;
77249e0067Shannken 
78607ead0eScube 	sc->sc_dev = self;
79607ead0eScube 
808b992330Shannken 	bus_space_map(eaa->elb_bt,
818b992330Shannken 	    _BUS_SPACE_UNSTRIDE(eaa->elb_bt, eaa->elb_base),
828b992330Shannken 	    COM_NPORTS, 0, &ioh);
836d487047Sthorpej 	com_init_regs(&sc->sc_regs, eaa->elb_bt, ioh,
84b05e82aaShannken 	    _BUS_SPACE_UNSTRIDE(eaa->elb_bt, eaa->elb_base));
85249e0067Shannken 
86249e0067Shannken 	sc->sc_frequency = COM_FREQ;
87249e0067Shannken 
88249e0067Shannken 	com_attach_subr(sc);
89249e0067Shannken 
90dea2c7b8Srin 	intr_establish_xname(eaa->elb_irq, IST_LEVEL, IPL_SERIAL, comintr, sc,
91dea2c7b8Srin 	    device_xname(self));
92249e0067Shannken }
93