xref: /netbsd-src/sys/arch/evbarm/npwr_fc/com_obio.c (revision 6d4870476f69938cdd065da8ea9ad989cef459f4)
1*6d487047Sthorpej /*	$NetBSD: com_obio.c,v 1.6 2018/12/08 17:46:10 thorpej Exp $	*/
223dfb2cdSbriggs 
323dfb2cdSbriggs /*-
423dfb2cdSbriggs  * Copyright (c) 2001 The NetBSD Foundation, Inc.
523dfb2cdSbriggs  * All rights reserved.
623dfb2cdSbriggs  *
723dfb2cdSbriggs  * This code is derived from software contributed to The NetBSD Foundation
823dfb2cdSbriggs  * by Matt Thomas <matt@3am-software.com>.
923dfb2cdSbriggs  *
1023dfb2cdSbriggs  * Redistribution and use in source and binary forms, with or without
1123dfb2cdSbriggs  * modification, are permitted provided that the following conditions
1223dfb2cdSbriggs  * are met:
1323dfb2cdSbriggs  * 1. Redistributions of source code must retain the above copyright
1423dfb2cdSbriggs  *    notice, this list of conditions and the following disclaimer.
1523dfb2cdSbriggs  * 2. Redistributions in binary form must reproduce the above copyright
1623dfb2cdSbriggs  *    notice, this list of conditions and the following disclaimer in the
1723dfb2cdSbriggs  *    documentation and/or other materials provided with the distribution.
1823dfb2cdSbriggs  *
1923dfb2cdSbriggs  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2023dfb2cdSbriggs  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2123dfb2cdSbriggs  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2223dfb2cdSbriggs  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2323dfb2cdSbriggs  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2423dfb2cdSbriggs  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2523dfb2cdSbriggs  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2623dfb2cdSbriggs  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2723dfb2cdSbriggs  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2823dfb2cdSbriggs  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2923dfb2cdSbriggs  * POSSIBILITY OF SUCH DAMAGE.
3023dfb2cdSbriggs  */
3123dfb2cdSbriggs 
3223dfb2cdSbriggs #include <sys/cdefs.h>
33*6d487047Sthorpej __KERNEL_RCSID(0, "$NetBSD: com_obio.c,v 1.6 2018/12/08 17:46:10 thorpej Exp $");
3423dfb2cdSbriggs 
3523dfb2cdSbriggs #include <sys/param.h>
3623dfb2cdSbriggs #include <sys/systm.h>
3723dfb2cdSbriggs #include <sys/device.h>
3823dfb2cdSbriggs #include <sys/termios.h>
3923dfb2cdSbriggs 
40fea15f47Sdyoung #include <sys/bus.h>
4123dfb2cdSbriggs 
4223dfb2cdSbriggs #include <arm/xscale/i80321var.h>
4323dfb2cdSbriggs 
4423dfb2cdSbriggs #include <evbarm/iq80321/obiovar.h>
4523dfb2cdSbriggs 
4623dfb2cdSbriggs #include <dev/ic/comreg.h>
4723dfb2cdSbriggs #include <dev/ic/comvar.h>
4823dfb2cdSbriggs 
4923dfb2cdSbriggs struct com_obio_softc {
5023dfb2cdSbriggs 	struct com_softc sc_com;
5123dfb2cdSbriggs 
5223dfb2cdSbriggs 	void *sc_ih;
5323dfb2cdSbriggs };
5423dfb2cdSbriggs 
55607ead0eScube int	com_obio_match(device_t, cfdata_t , void *);
56607ead0eScube void	com_obio_attach(device_t, device_t, void *);
5723dfb2cdSbriggs 
58607ead0eScube CFATTACH_DECL_NEW(com_obio, sizeof(struct com_obio_softc),
5923dfb2cdSbriggs     com_obio_match, com_obio_attach, NULL, NULL);
6023dfb2cdSbriggs 
6123dfb2cdSbriggs int
com_obio_match(device_t parent,cfdata_t cf,void * aux)62607ead0eScube com_obio_match(device_t parent, cfdata_t cf, void *aux)
6323dfb2cdSbriggs {
6423dfb2cdSbriggs 
6523dfb2cdSbriggs 	/* We take it on faith that the device is there. */
6623dfb2cdSbriggs 	return (1);
6723dfb2cdSbriggs }
6823dfb2cdSbriggs 
6923dfb2cdSbriggs void
com_obio_attach(device_t parent,device_t self,void * aux)70607ead0eScube com_obio_attach(device_t parent, device_t self, void *aux)
7123dfb2cdSbriggs {
7223dfb2cdSbriggs 	struct obio_attach_args *oba = aux;
73607ead0eScube 	struct com_obio_softc *osc = device_private(self);
7423dfb2cdSbriggs 	struct com_softc *sc = &osc->sc_com;
7534537908Sgdamore 	bus_space_handle_t ioh;
7623dfb2cdSbriggs 	int error;
7723dfb2cdSbriggs 
78607ead0eScube 	sc->sc_dev = self;
7923dfb2cdSbriggs 	sc->sc_frequency = COM_FREQ;
8023dfb2cdSbriggs 	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);
8323dfb2cdSbriggs 
8423dfb2cdSbriggs 	if (error) {
8523dfb2cdSbriggs 		aprint_error(": failed to map registers: %d\n", error);
8623dfb2cdSbriggs 		return;
8723dfb2cdSbriggs 	}
8823dfb2cdSbriggs 
8923dfb2cdSbriggs 	com_attach_subr(sc);
9023dfb2cdSbriggs 
9123dfb2cdSbriggs 	osc->sc_ih = i80321_intr_establish(oba->oba_irq, IPL_SERIAL,
9223dfb2cdSbriggs 	    comintr, sc);
9323dfb2cdSbriggs 	if (osc->sc_ih == NULL)
94607ead0eScube 		aprint_error_dev(self,
95607ead0eScube 		    "unable to establish interrupt at irq %d\n", oba->oba_irq);
9623dfb2cdSbriggs }
97