xref: /openbsd/sys/arch/sparc64/dev/lpt_ebus.c (revision db3296cf)
1 /*	$OpenBSD: lpt_ebus.c,v 1.7 2003/02/17 01:29:20 henric Exp $	*/
2 /*	$NetBSD: lpt_ebus.c,v 1.8 2002/03/01 11:51:00 martin Exp $	*/
3 
4 /*
5  * Copyright (c) 1999, 2000 Matthew R. Green
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 /*
33  * NS Super I/O PC87332VLJ "lpt" to ebus attachment
34  */
35 
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 #include <sys/tty.h>
41 
42 #include <machine/bus.h>
43 
44 #include <sparc64/dev/ebusreg.h>
45 #include <sparc64/dev/ebusvar.h>
46 
47 #include <dev/ic/lptvar.h>
48 
49 struct lpt_ebus_softc {
50 	struct lpt_softc sc_lpt;
51 	bus_space_handle_t sc_ctrl;
52 };
53 
54 int	lpt_ebus_match(struct device *, void *, void *);
55 void	lpt_ebus_attach(struct device *, struct device *, void *);
56 
57 struct cfattach lpt_ebus_ca = {
58 	sizeof(struct lpt_ebus_softc), lpt_ebus_match, lpt_ebus_attach
59 };
60 
61 int
62 lpt_ebus_match(parent, match, aux)
63 	struct device *parent;
64 	void *match;
65 	void *aux;
66 {
67 	struct ebus_attach_args *ea = aux;
68 
69 	if (!strcmp(ea->ea_name, "ecpp") ||
70 	    !strcmp(ea->ea_name, "parallel"))
71 		return (1);
72 	return (0);
73 }
74 
75 void
76 lpt_ebus_attach(parent, self, aux)
77 	struct device *parent, *self;
78 	void *aux;
79 {
80 	struct lpt_ebus_softc *sc = (void *)self;
81 	struct ebus_attach_args *ea = aux;
82 
83 
84 	if (ebus_bus_map(ea->ea_memtag, 0,
85 	    EBUS_PADDR_FROM_REG(&ea->ea_regs[0]), ea->ea_regs[0].size,
86 	    0, 0, &sc->sc_lpt.sc_ioh) == 0) {
87 		sc->sc_lpt.sc_iot = ea->ea_memtag;
88 	} else if (ebus_bus_map(ea->ea_iotag, 0,
89 		    EBUS_PADDR_FROM_REG(&ea->ea_regs[0]), ea->ea_regs[0].size,
90 		    0, 0, &sc->sc_lpt.sc_ioh) == 0) {
91 		sc->sc_lpt.sc_iot = ea->ea_iotag;
92 	} else {
93 		printf(": can't map register space\n");
94 		return;
95 	}
96 
97 	if (ebus_bus_map(sc->sc_lpt.sc_iot, 0,
98 	    EBUS_PADDR_FROM_REG(&ea->ea_regs[1]), ea->ea_regs[1].size,
99 	    BUS_SPACE_MAP_LINEAR, 0, &sc->sc_ctrl) != 0) {
100 		printf(": can't map control space\n");
101 		bus_space_unmap(sc->sc_lpt.sc_iot, sc->sc_lpt.sc_ioh,
102 		    ea->ea_regs[0].size);
103 		return;
104 	}
105 
106 	sc->sc_lpt.sc_flags |= LPT_POLLED;
107 	printf(": polled");
108 
109 	lpt_attach_common(&sc->sc_lpt);
110 }
111