xref: /netbsd-src/sys/arch/amiga/dev/lpt_supio.c (revision 3a45360b72fe65e0ce848c7147e49645eebc8bad)
1 /*	$NetBSD: lpt_supio.c,v 1.14 2011/07/19 15:55:27 dyoung Exp $ */
2 
3 /*-
4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Ignatios Souvatzis.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: lpt_supio.c,v 1.14 2011/07/19 15:55:27 dyoung Exp $");
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/ioctl.h>
38 #include <sys/select.h>
39 #include <sys/tty.h>
40 #include <sys/proc.h>
41 #include <sys/conf.h>
42 #include <sys/file.h>
43 #include <sys/uio.h>
44 #include <sys/kernel.h>
45 #include <sys/syslog.h>
46 #include <sys/types.h>
47 #include <sys/device.h>
48 #include <sys/bus.h>
49 
50 #include <machine/intr.h>
51 
52 #include <dev/ic/lptreg.h>
53 #include <dev/ic/lptvar.h>
54 
55 #include <amiga/dev/supio.h>
56 
57 struct lptsupio_softc {
58 	struct lpt_softc sc_lpt;
59 	struct isr sc_isr;
60 	void (*sc_intack)(void *);
61 };
62 
63 int lpt_supio_match(device_t, cfdata_t , void *);
64 void lpt_supio_attach(device_t, device_t, void *);
65 int lpt_supio_intr(void *p);
66 
67 CFATTACH_DECL_NEW(lpt_supio, sizeof(struct lptsupio_softc),
68     lpt_supio_match, lpt_supio_attach, NULL, NULL);
69 
70 int
lpt_supio_match(device_t parent,cfdata_t match,void * aux)71 lpt_supio_match(device_t parent, cfdata_t match, void *aux)
72 {
73 	struct supio_attach_args *supa = aux;
74 
75 	if (strcmp(supa->supio_name,"lpt"))
76 		return 0;
77 
78 	return (1);
79 }
80 
81 int
lpt_supio_intr(void * p)82 lpt_supio_intr(void *p)
83 {
84 	struct lptsupio_softc *sc = (void *)p;
85 	int rc;
86 
87 	rc = lptintr(&sc->sc_lpt);
88 	if (sc->sc_intack)
89 		(*sc->sc_intack)(p);
90 	return (rc);
91 }
92 
93 void
lpt_supio_attach(device_t parent,device_t self,void * aux)94 lpt_supio_attach(device_t parent, device_t self, void *aux)
95 {
96 	struct lptsupio_softc *sc = device_private(self);
97 	struct lpt_softc *lsc = &sc->sc_lpt;
98 	int iobase;
99 	bus_space_tag_t iot;
100 	struct supio_attach_args *supa = aux;
101 
102 	/*
103 	 * We're living on a superio chip.
104 	 */
105 	lsc->sc_dev = self;
106 	iobase = supa->supio_iobase;
107 	iot = lsc->sc_iot = supa->supio_iot;
108 	sc->sc_intack = (void *)supa->supio_arg;
109 
110 	aprint_normal(" port 0x%04x ipl %d\n", iobase, supa->supio_ipl);
111         if (bus_space_map(iot, iobase, LPT_NPORTS, 0, &lsc->sc_ioh)) {
112 		aprint_error_dev(self, "io mapping failed\n");
113 		return;
114 	}
115 
116 	lpt_attach_subr(lsc);
117 
118 	sc->sc_isr.isr_intr = lpt_supio_intr;
119 	sc->sc_isr.isr_arg = sc;
120 	sc->sc_isr.isr_ipl = supa->supio_ipl;
121 	add_isr(&sc->sc_isr);
122 }
123