11.15Sthorpej/*	$NetBSD: com_obio.c,v 1.15 2018/12/08 17:46:10 thorpej Exp $	*/
21.2Sthorpej
31.1Smatt/*-
41.1Smatt * Copyright (c) 2001 The NetBSD Foundation, Inc.
51.1Smatt * All rights reserved.
61.1Smatt *
71.1Smatt * This code is derived from software contributed to The NetBSD Foundation
81.1Smatt * by Matt Thomas <matt@3am-software.com>.
91.1Smatt *
101.1Smatt * Redistribution and use in source and binary forms, with or without
111.1Smatt * modification, are permitted provided that the following conditions
121.1Smatt * are met:
131.1Smatt * 1. Redistributions of source code must retain the above copyright
141.1Smatt *    notice, this list of conditions and the following disclaimer.
151.1Smatt * 2. Redistributions in binary form must reproduce the above copyright
161.1Smatt *    notice, this list of conditions and the following disclaimer in the
171.1Smatt *    documentation and/or other materials provided with the distribution.
181.1Smatt *
191.1Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Smatt * POSSIBILITY OF SUCH DAMAGE.
301.1Smatt */
311.9Slukem
321.9Slukem#include <sys/cdefs.h>
331.15Sthorpej__KERNEL_RCSID(0, "$NetBSD: com_obio.c,v 1.15 2018/12/08 17:46:10 thorpej Exp $");
341.1Smatt
351.1Smatt#include <sys/param.h>
361.1Smatt#include <sys/systm.h>
371.1Smatt#include <sys/device.h>
381.1Smatt#include <sys/termios.h>
391.1Smatt
401.14Sdyoung#include <sys/bus.h>
411.2Sthorpej
421.2Sthorpej#include <evbarm/iq80310/iq80310var.h>
431.2Sthorpej#include <evbarm/iq80310/obiovar.h>
441.1Smatt
451.1Smatt#include <dev/ic/comreg.h>
461.1Smatt#include <dev/ic/comvar.h>
471.1Smatt
481.2Sthorpejstruct com_obio_softc {
491.2Sthorpej	struct com_softc sc_com;
501.2Sthorpej
511.2Sthorpej	void *sc_ih;
521.2Sthorpej};
531.2Sthorpej
541.12Scubeint	com_obio_match(device_t, cfdata_t , void *);
551.12Scubevoid	com_obio_attach(device_t, device_t, void *);
561.1Smatt
571.12ScubeCFATTACH_DECL_NEW(com_obio, sizeof(struct com_obio_softc),
581.7Sthorpej    com_obio_match, com_obio_attach, NULL, NULL);
591.1Smatt
601.2Sthorpejint
611.12Scubecom_obio_match(device_t parent, cfdata_t cf, void *aux)
621.1Smatt{
631.2Sthorpej
641.8Sthorpej	/* We take it on faith that the device is there. */
651.8Sthorpej	return (1);
661.1Smatt}
671.1Smatt
681.2Sthorpejvoid
691.12Scubecom_obio_attach(device_t parent, device_t self, void *aux)
701.1Smatt{
711.2Sthorpej	struct obio_attach_args *oba = aux;
721.12Scube	struct com_obio_softc *osc = device_private(self);
731.2Sthorpej	struct com_softc *sc = &osc->sc_com;
741.11Sgdamore	bus_space_handle_t ioh;
751.1Smatt	int error;
761.1Smatt
771.12Scube	sc->sc_dev = self;
781.1Smatt	sc->sc_frequency = COM_FREQ;
791.4Sthorpej	sc->sc_hwflags = COM_HW_NO_TXPRELOAD;
801.11Sgdamore	error = bus_space_map(oba->oba_st, oba->oba_addr, 8, 0, &ioh);
811.1Smatt
821.1Smatt	if (error) {
831.12Scube		aprint_error(": failed to map registers: %d\n", error);
841.1Smatt		return;
851.1Smatt	}
861.15Sthorpej	com_init_regs(&sc->sc_regs, oba->oba_st, ioh, oba->oba_addr);
871.1Smatt	com_attach_subr(sc);
881.2Sthorpej
891.2Sthorpej	osc->sc_ih = iq80310_intr_establish(oba->oba_irq, IPL_SERIAL,
901.2Sthorpej	    comintr, sc);
911.2Sthorpej	if (osc->sc_ih == NULL)
921.12Scube		aprint_error_dev(self,
931.12Scube		    "unable to establish interrupt at CPLD irq %d\n",
941.12Scube		    oba->oba_irq);
951.1Smatt}
96