xref: /netbsd-src/sys/arch/evbarm/hdl_g/com_obio.c (revision 6d4870476f69938cdd065da8ea9ad989cef459f4)
1*6d487047Sthorpej /*	$NetBSD: com_obio.c,v 1.6 2018/12/08 17:46:10 thorpej Exp $	*/
2407f05e7Snonaka 
3407f05e7Snonaka /*-
4407f05e7Snonaka  * Copyright (c) 2001 The NetBSD Foundation, Inc.
5407f05e7Snonaka  * All rights reserved.
6407f05e7Snonaka  *
7407f05e7Snonaka  * This code is derived from software contributed to The NetBSD Foundation
8407f05e7Snonaka  * by Matt Thomas <matt@3am-software.com>.
9407f05e7Snonaka  *
10407f05e7Snonaka  * Redistribution and use in source and binary forms, with or without
11407f05e7Snonaka  * modification, are permitted provided that the following conditions
12407f05e7Snonaka  * are met:
13407f05e7Snonaka  * 1. Redistributions of source code must retain the above copyright
14407f05e7Snonaka  *    notice, this list of conditions and the following disclaimer.
15407f05e7Snonaka  * 2. Redistributions in binary form must reproduce the above copyright
16407f05e7Snonaka  *    notice, this list of conditions and the following disclaimer in the
17407f05e7Snonaka  *    documentation and/or other materials provided with the distribution.
18407f05e7Snonaka  *
19407f05e7Snonaka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20407f05e7Snonaka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21407f05e7Snonaka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22407f05e7Snonaka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23407f05e7Snonaka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24407f05e7Snonaka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25407f05e7Snonaka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26407f05e7Snonaka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27407f05e7Snonaka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28407f05e7Snonaka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29407f05e7Snonaka  * POSSIBILITY OF SUCH DAMAGE.
30407f05e7Snonaka  */
31407f05e7Snonaka 
32407f05e7Snonaka #include <sys/cdefs.h>
33*6d487047Sthorpej __KERNEL_RCSID(0, "$NetBSD: com_obio.c,v 1.6 2018/12/08 17:46:10 thorpej Exp $");
34407f05e7Snonaka 
35407f05e7Snonaka #include <sys/param.h>
36407f05e7Snonaka #include <sys/systm.h>
37407f05e7Snonaka #include <sys/device.h>
38407f05e7Snonaka #include <sys/termios.h>
39407f05e7Snonaka 
40fea15f47Sdyoung #include <sys/bus.h>
41407f05e7Snonaka 
42407f05e7Snonaka #include <arm/xscale/i80321var.h>
43407f05e7Snonaka 
44407f05e7Snonaka #include <evbarm/hdl_g/obiovar.h>
45407f05e7Snonaka 
46407f05e7Snonaka #include <dev/ic/comreg.h>
47407f05e7Snonaka #include <dev/ic/comvar.h>
48407f05e7Snonaka 
49407f05e7Snonaka struct com_obio_softc {
50407f05e7Snonaka 	struct com_softc sc_com;
51407f05e7Snonaka 
52407f05e7Snonaka 	void *sc_ih;
53407f05e7Snonaka };
54407f05e7Snonaka 
55607ead0eScube int	com_obio_match(device_t, cfdata_t , void *);
56607ead0eScube void	com_obio_attach(device_t, device_t, void *);
57407f05e7Snonaka 
58607ead0eScube CFATTACH_DECL_NEW(com_obio, sizeof(struct com_obio_softc),
59407f05e7Snonaka     com_obio_match, com_obio_attach, NULL, NULL);
60407f05e7Snonaka 
61407f05e7Snonaka int
com_obio_match(device_t parent,cfdata_t cf,void * aux)62607ead0eScube com_obio_match(device_t parent, cfdata_t cf, void *aux)
63407f05e7Snonaka {
64407f05e7Snonaka 
65407f05e7Snonaka 	/* We take it on faith that the device is there. */
66407f05e7Snonaka 	return 1;
67407f05e7Snonaka }
68407f05e7Snonaka 
69407f05e7Snonaka void
com_obio_attach(device_t parent,device_t self,void * aux)70607ead0eScube com_obio_attach(device_t parent, device_t self, void *aux)
71407f05e7Snonaka {
72407f05e7Snonaka 	struct obio_attach_args *oba = aux;
73607ead0eScube 	struct com_obio_softc *osc = device_private(self);
74407f05e7Snonaka 	struct com_softc *sc = &osc->sc_com;
7534537908Sgdamore 	bus_space_handle_t ioh;
76407f05e7Snonaka 	int error;
77407f05e7Snonaka 
78607ead0eScube 	sc->sc_dev = self;
79407f05e7Snonaka 	sc->sc_frequency = COM_FREQ;
80407f05e7Snonaka 	sc->sc_hwflags = COM_HW_NO_TXPRELOAD;
8134537908Sgdamore 	error = bus_space_map(oba->oba_st, oba->oba_addr, 8, 0, &ioh);
82*6d487047Sthorpej 	com_init_regs(&sc->sc_regs, oba->oba_st, ioh, oba->oba_addr);
83407f05e7Snonaka 
84407f05e7Snonaka 	if (error) {
85407f05e7Snonaka 		aprint_error(": failed to map registers: %d\n", error);
86407f05e7Snonaka 		return;
87407f05e7Snonaka 	}
88407f05e7Snonaka 
89407f05e7Snonaka 	com_attach_subr(sc);
90407f05e7Snonaka 
91407f05e7Snonaka 	osc->sc_ih = i80321_intr_establish(oba->oba_irq, IPL_SERIAL,
92407f05e7Snonaka 	    comintr, sc);
93407f05e7Snonaka 	if (osc->sc_ih == NULL)
94607ead0eScube 		aprint_error_dev(self,
95607ead0eScube 		    "unable to establish interrupt at irq %d\n", oba->oba_irq);
96407f05e7Snonaka }
97