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