xref: /netbsd/sys/dev/isa/tsdio.c (revision 6550d01e)
1 /*	$NetBSD: tsdio.c,v 1.10 2009/05/12 09:10:16 cegger Exp $	*/
2 
3 /*-
4  * Copyright (c) 2005 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jesse Off
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: tsdio.c,v 1.10 2009/05/12 09:10:16 cegger Exp $");
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 
39 #include <sys/bus.h>
40 #include <sys/intr.h>
41 
42 #include <dev/isa/isareg.h>
43 #include <dev/isa/isavar.h>
44 #include <dev/isa/isadmavar.h>
45 #include <dev/isa/tsdiovar.h>
46 
47 int	tsdio_probe(device_t, cfdata_t, void *);
48 void	tsdio_attach(device_t, device_t, void *);
49 int	tsdio_search(device_t, cfdata_t, const int *, void *);
50 int	tsdio_print(void *, const char *);
51 
52 CFATTACH_DECL(tsdio, sizeof(struct tsdio_softc),
53     tsdio_probe, tsdio_attach, NULL, NULL);
54 
55 int
56 tsdio_probe(device_t parent, cfdata_t cf, void *aux)
57 {
58 	struct isa_attach_args *ia = aux;
59 	bus_space_tag_t iot = ia->ia_iot;
60 	bus_space_handle_t dioh;
61 	int rv = 0, have_io = 0;
62 
63 	if (ia->ia_nio < 1)
64 		return (0);
65 	if (ia->ia_nirq < 1)
66 		return (0);
67 
68 	if (ISA_DIRECT_CONFIG(ia))
69 		return (0);
70 
71 	/*
72 	 * Disallow wildcarded I/O base.
73 	 */
74 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
75 		return (0);
76 
77 	/*
78 	 * Map the I/O space.
79 	 */
80 	if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8,
81 	    0, &dioh))
82 		goto out;
83 	have_io = 1;
84 
85 	if (bus_space_read_1(ia->ia_iot, dioh, 0) != 0x54) {
86 		goto out;
87 	}
88 
89 	rv = 1;
90 	ia->ia_nio = 1;
91 	ia->ia_io[0].ir_size = 8;
92 	ia->ia_niomem = 0;
93 	ia->ia_nirq = 0;
94 	ia->ia_ndrq = 0;
95 
96  out:
97 	if (have_io)
98 		bus_space_unmap(iot, dioh, 8);
99 
100 	return (rv);
101 }
102 
103 void
104 tsdio_attach(device_t parent, device_t self, void *aux)
105 {
106 	struct tsdio_softc *sc = (struct tsdio_softc *) self;
107 	struct isa_attach_args *ia = aux;
108 
109 	sc->sc_iot = ia->ia_iot;
110 
111 	aprint_normal(": Technologic Systems TS-DIO24\n");
112 
113 	/*
114 	 * Map the device.
115 	 */
116 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, 8,
117 	    0, &sc->sc_ioh)) {
118 		aprint_error_dev(&sc->sc_dev, "unable to map i/o space\n");
119 		return;
120 	}
121 
122 	/*
123 	 *  Attach sub-devices
124 	 */
125 	config_search_ia(tsdio_search, self, "tsdio", NULL);
126 }
127 
128 int
129 tsdio_search(device_t parent, cfdata_t cf, const int *l, void *aux)
130 {
131 	struct tsdio_softc *sc = (struct tsdio_softc *)parent;
132 	struct tsdio_attach_args sa;
133 
134 	sa.ta_iot = sc->sc_iot;
135 	sa.ta_ioh = sc->sc_ioh;
136 
137 	if (config_match(parent, cf, &sa) > 0)
138 		config_attach(parent, cf, &sa, tsdio_print);
139 
140 	return (0);
141 }
142 
143 int
144 tsdio_print(void *aux, const char *name)
145 {
146 
147 	return (UNCONF);
148 }
149