xref: /openbsd/sys/arch/sparc64/dev/lpt_ebus.c (revision 47c47fea)
1 /*	$OpenBSD: lpt_ebus.c,v 1.12 2022/10/16 01:22:39 jsg 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  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 /*
31  * NS Super I/O PC87332VLJ "lpt" to ebus attachment
32  */
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37 #include <sys/tty.h>
38 
39 #include <machine/bus.h>
40 
41 #include <sparc64/dev/ebusreg.h>
42 #include <sparc64/dev/ebusvar.h>
43 
44 #include <dev/ic/lptvar.h>
45 
46 struct lpt_ebus_softc {
47 	struct lpt_softc sc_lpt;
48 	bus_space_handle_t sc_ctrl;
49 };
50 
51 int	lpt_ebus_match(struct device *, void *, void *);
52 void	lpt_ebus_attach(struct device *, struct device *, void *);
53 
54 const struct cfattach lpt_ebus_ca = {
55 	sizeof(struct lpt_ebus_softc), lpt_ebus_match, lpt_ebus_attach
56 };
57 
58 int
lpt_ebus_match(struct device * parent,void * match,void * aux)59 lpt_ebus_match(struct device *parent, void *match, void *aux)
60 {
61 	struct ebus_attach_args *ea = aux;
62 
63 	if (!strcmp(ea->ea_name, "ecpp") ||
64 	    !strcmp(ea->ea_name, "parallel"))
65 		return (1);
66 	return (0);
67 }
68 
69 void
lpt_ebus_attach(struct device * parent,struct device * self,void * aux)70 lpt_ebus_attach(struct device *parent, struct device *self, void *aux)
71 {
72 	struct lpt_ebus_softc *sc = (void *)self;
73 	struct ebus_attach_args *ea = aux;
74 
75 
76 	if (ebus_bus_map(ea->ea_memtag, 0,
77 	    EBUS_PADDR_FROM_REG(&ea->ea_regs[0]), ea->ea_regs[0].size,
78 	    0, 0, &sc->sc_lpt.sc_ioh) == 0) {
79 		sc->sc_lpt.sc_iot = ea->ea_memtag;
80 	} else if (ebus_bus_map(ea->ea_iotag, 0,
81 		    EBUS_PADDR_FROM_REG(&ea->ea_regs[0]), ea->ea_regs[0].size,
82 		    0, 0, &sc->sc_lpt.sc_ioh) == 0) {
83 		sc->sc_lpt.sc_iot = ea->ea_iotag;
84 	} else {
85 		printf(": can't map register space\n");
86 		return;
87 	}
88 
89 	if (ebus_bus_map(sc->sc_lpt.sc_iot, 0,
90 	    EBUS_PADDR_FROM_REG(&ea->ea_regs[1]), ea->ea_regs[1].size, 0, 0,
91 	    &sc->sc_ctrl) != 0) {
92 		printf(": can't map control space\n");
93 		bus_space_unmap(sc->sc_lpt.sc_iot, sc->sc_lpt.sc_ioh,
94 		    ea->ea_regs[0].size);
95 		return;
96 	}
97 
98 	sc->sc_lpt.sc_flags |= LPT_POLLED;
99 	printf(": polled");
100 
101 	lpt_attach_common(&sc->sc_lpt);
102 }
103