com_obio.c revision 1.3
11.3Scube/*	$NetBSD: com_obio.c,v 1.3 2008/03/14 15:09:09 cube Exp $	*/
21.1Snonaka
31.1Snonaka/*-
41.1Snonaka * Copyright (c) 2001 The NetBSD Foundation, Inc.
51.1Snonaka * All rights reserved.
61.1Snonaka *
71.1Snonaka * This code is derived from software contributed to The NetBSD Foundation
81.1Snonaka * by Matt Thomas <matt@3am-software.com>.
91.1Snonaka *
101.1Snonaka * Redistribution and use in source and binary forms, with or without
111.1Snonaka * modification, are permitted provided that the following conditions
121.1Snonaka * are met:
131.1Snonaka * 1. Redistributions of source code must retain the above copyright
141.1Snonaka *    notice, this list of conditions and the following disclaimer.
151.1Snonaka * 2. Redistributions in binary form must reproduce the above copyright
161.1Snonaka *    notice, this list of conditions and the following disclaimer in the
171.1Snonaka *    documentation and/or other materials provided with the distribution.
181.1Snonaka * 3. All advertising materials mentioning features or use of this software
191.1Snonaka *    must display the following acknowledgement:
201.1Snonaka *        This product includes software developed by the NetBSD
211.1Snonaka *        Foundation, Inc. and its contributors.
221.1Snonaka * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Snonaka *    contributors may be used to endorse or promote products derived
241.1Snonaka *    from this software without specific prior written permission.
251.1Snonaka *
261.1Snonaka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Snonaka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Snonaka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Snonaka * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Snonaka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Snonaka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Snonaka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Snonaka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Snonaka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Snonaka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Snonaka * POSSIBILITY OF SUCH DAMAGE.
371.1Snonaka */
381.1Snonaka
391.1Snonaka#include <sys/cdefs.h>
401.3Scube__KERNEL_RCSID(0, "$NetBSD: com_obio.c,v 1.3 2008/03/14 15:09:09 cube Exp $");
411.1Snonaka
421.1Snonaka#include <sys/param.h>
431.1Snonaka#include <sys/systm.h>
441.1Snonaka#include <sys/device.h>
451.1Snonaka#include <sys/termios.h>
461.1Snonaka
471.1Snonaka#include <machine/bus.h>
481.1Snonaka
491.1Snonaka#include <arm/xscale/i80321var.h>
501.1Snonaka
511.1Snonaka#include <evbarm/hdl_g/obiovar.h>
521.1Snonaka
531.1Snonaka#include <dev/ic/comreg.h>
541.1Snonaka#include <dev/ic/comvar.h>
551.1Snonaka
561.1Snonakastruct com_obio_softc {
571.1Snonaka	struct com_softc sc_com;
581.1Snonaka
591.1Snonaka	void *sc_ih;
601.1Snonaka};
611.1Snonaka
621.3Scubeint	com_obio_match(device_t, cfdata_t , void *);
631.3Scubevoid	com_obio_attach(device_t, device_t, void *);
641.1Snonaka
651.3ScubeCFATTACH_DECL_NEW(com_obio, sizeof(struct com_obio_softc),
661.1Snonaka    com_obio_match, com_obio_attach, NULL, NULL);
671.1Snonaka
681.1Snonakaint
691.3Scubecom_obio_match(device_t parent, cfdata_t cf, void *aux)
701.1Snonaka{
711.1Snonaka
721.1Snonaka	/* We take it on faith that the device is there. */
731.1Snonaka	return 1;
741.1Snonaka}
751.1Snonaka
761.1Snonakavoid
771.3Scubecom_obio_attach(device_t parent, device_t self, void *aux)
781.1Snonaka{
791.1Snonaka	struct obio_attach_args *oba = aux;
801.3Scube	struct com_obio_softc *osc = device_private(self);
811.1Snonaka	struct com_softc *sc = &osc->sc_com;
821.2Sgdamore	bus_space_handle_t ioh;
831.1Snonaka	int error;
841.1Snonaka
851.3Scube	sc->sc_dev = self;
861.1Snonaka	sc->sc_frequency = COM_FREQ;
871.1Snonaka	sc->sc_hwflags = COM_HW_NO_TXPRELOAD;
881.2Sgdamore	error = bus_space_map(oba->oba_st, oba->oba_addr, 8, 0, &ioh);
891.2Sgdamore	COM_INIT_REGS(sc->sc_regs, oba->oba_st, ioh, oba->oba_addr);
901.1Snonaka
911.1Snonaka	if (error) {
921.1Snonaka		aprint_error(": failed to map registers: %d\n", error);
931.1Snonaka		return;
941.1Snonaka	}
951.1Snonaka
961.1Snonaka	com_attach_subr(sc);
971.1Snonaka
981.1Snonaka	osc->sc_ih = i80321_intr_establish(oba->oba_irq, IPL_SERIAL,
991.1Snonaka	    comintr, sc);
1001.1Snonaka	if (osc->sc_ih == NULL)
1011.3Scube		aprint_error_dev(self,
1021.3Scube		    "unable to establish interrupt at irq %d\n", oba->oba_irq);
1031.1Snonaka}
104