1*3a45360bSdyoung /* $NetBSD: lpt_supio.c,v 1.14 2011/07/19 15:55:27 dyoung Exp $ */
23ad599d7Sis
33ad599d7Sis /*-
42c7fa23cSis * Copyright (c) 1997 The NetBSD Foundation, Inc.
5dc068e0dSis * All rights reserved.
6dc068e0dSis *
7dc068e0dSis * This code is derived from software contributed to The NetBSD Foundation
8dc068e0dSis * by Ignatios Souvatzis.
93ad599d7Sis *
103ad599d7Sis * Redistribution and use in source and binary forms, with or without
113ad599d7Sis * modification, are permitted provided that the following conditions
123ad599d7Sis * are met:
133ad599d7Sis * 1. Redistributions of source code must retain the above copyright
143ad599d7Sis * notice, this list of conditions and the following disclaimer.
153ad599d7Sis * 2. Redistributions in binary form must reproduce the above copyright
163ad599d7Sis * notice, this list of conditions and the following disclaimer in the
173ad599d7Sis * documentation and/or other materials provided with the distribution.
183ad599d7Sis *
19dc068e0dSis * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20dc068e0dSis * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21dc068e0dSis * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22dc068e0dSis * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23dc068e0dSis * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24dc068e0dSis * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25dc068e0dSis * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26dc068e0dSis * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27dc068e0dSis * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28dc068e0dSis * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29dc068e0dSis * POSSIBILITY OF SUCH DAMAGE.
303ad599d7Sis */
313ad599d7Sis
321ea4df81Saymeric #include <sys/cdefs.h>
33*3a45360bSdyoung __KERNEL_RCSID(0, "$NetBSD: lpt_supio.c,v 1.14 2011/07/19 15:55:27 dyoung Exp $");
341ea4df81Saymeric
353ad599d7Sis #include <sys/param.h>
363ad599d7Sis #include <sys/systm.h>
373ad599d7Sis #include <sys/ioctl.h>
383ad599d7Sis #include <sys/select.h>
393ad599d7Sis #include <sys/tty.h>
403ad599d7Sis #include <sys/proc.h>
413ad599d7Sis #include <sys/conf.h>
423ad599d7Sis #include <sys/file.h>
433ad599d7Sis #include <sys/uio.h>
443ad599d7Sis #include <sys/kernel.h>
453ad599d7Sis #include <sys/syslog.h>
463ad599d7Sis #include <sys/types.h>
473ad599d7Sis #include <sys/device.h>
48*3a45360bSdyoung #include <sys/bus.h>
493ad599d7Sis
503ad599d7Sis #include <machine/intr.h>
513ad599d7Sis
523ad599d7Sis #include <dev/ic/lptreg.h>
533ad599d7Sis #include <dev/ic/lptvar.h>
543ad599d7Sis
553ad599d7Sis #include <amiga/dev/supio.h>
563ad599d7Sis
573ad599d7Sis struct lptsupio_softc {
583ad599d7Sis struct lpt_softc sc_lpt;
593ad599d7Sis struct isr sc_isr;
609382c873Saymeric void (*sc_intack)(void *);
613ad599d7Sis };
623ad599d7Sis
638ecf8999Scube int lpt_supio_match(device_t, cfdata_t , void *);
648ecf8999Scube void lpt_supio_attach(device_t, device_t, void *);
659382c873Saymeric int lpt_supio_intr(void *p);
663ad599d7Sis
678ecf8999Scube CFATTACH_DECL_NEW(lpt_supio, sizeof(struct lptsupio_softc),
68c5e91d44Sthorpej lpt_supio_match, lpt_supio_attach, NULL, NULL);
693ad599d7Sis
703ad599d7Sis int
lpt_supio_match(device_t parent,cfdata_t match,void * aux)718ecf8999Scube lpt_supio_match(device_t parent, cfdata_t match, void *aux)
723ad599d7Sis {
733ad599d7Sis struct supio_attach_args *supa = aux;
743ad599d7Sis
753ad599d7Sis if (strcmp(supa->supio_name,"lpt"))
763ad599d7Sis return 0;
773ad599d7Sis
783ad599d7Sis return (1);
793ad599d7Sis }
803ad599d7Sis
813ad599d7Sis int
lpt_supio_intr(void * p)829382c873Saymeric lpt_supio_intr(void *p)
833ad599d7Sis {
843ad599d7Sis struct lptsupio_softc *sc = (void *)p;
853ad599d7Sis int rc;
863ad599d7Sis
873ad599d7Sis rc = lptintr(&sc->sc_lpt);
883ad599d7Sis if (sc->sc_intack)
893ad599d7Sis (*sc->sc_intack)(p);
903ad599d7Sis return (rc);
913ad599d7Sis }
923ad599d7Sis
933ad599d7Sis void
lpt_supio_attach(device_t parent,device_t self,void * aux)948ecf8999Scube lpt_supio_attach(device_t parent, device_t self, void *aux)
953ad599d7Sis {
968ecf8999Scube struct lptsupio_softc *sc = device_private(self);
973ad599d7Sis struct lpt_softc *lsc = &sc->sc_lpt;
983ad599d7Sis int iobase;
993ad599d7Sis bus_space_tag_t iot;
1003ad599d7Sis struct supio_attach_args *supa = aux;
1013ad599d7Sis
1023ad599d7Sis /*
1033ad599d7Sis * We're living on a superio chip.
1043ad599d7Sis */
1058ecf8999Scube lsc->sc_dev = self;
1063ad599d7Sis iobase = supa->supio_iobase;
1073ad599d7Sis iot = lsc->sc_iot = supa->supio_iot;
1083ad599d7Sis sc->sc_intack = (void *)supa->supio_arg;
1093ad599d7Sis
1108ecf8999Scube aprint_normal(" port 0x%04x ipl %d\n", iobase, supa->supio_ipl);
1118ecf8999Scube if (bus_space_map(iot, iobase, LPT_NPORTS, 0, &lsc->sc_ioh)) {
1128ecf8999Scube aprint_error_dev(self, "io mapping failed\n");
1138ecf8999Scube return;
1148ecf8999Scube }
1153ad599d7Sis
1163ad599d7Sis lpt_attach_subr(lsc);
1173ad599d7Sis
1183ad599d7Sis sc->sc_isr.isr_intr = lpt_supio_intr;
1193ad599d7Sis sc->sc_isr.isr_arg = sc;
1203ad599d7Sis sc->sc_isr.isr_ipl = supa->supio_ipl;
1213ad599d7Sis add_isr(&sc->sc_isr);
1223ad599d7Sis }
123