tsdio.c revision 1.1
1/*	$NetBSD: tsdio.c,v 1.1 2005/08/14 03:50:34 joff 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 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *	This product includes software developed by the NetBSD
21 *	Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 *    contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#include <sys/cdefs.h>
40__KERNEL_RCSID(0, "$NetBSD: tsdio.c,v 1.1 2005/08/14 03:50:34 joff Exp $");
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/device.h>
45
46#include <machine/bus.h>
47#include <machine/intr.h>
48
49#include <dev/isa/isareg.h>
50#include <dev/isa/isavar.h>
51#include <dev/isa/isadmavar.h>
52#include <dev/isa/tsdiovar.h>
53
54int	tsdio_probe(struct device *, struct cfdata *, void *);
55void	tsdio_attach(struct device *, struct device *, void *);
56int	tsdio_search(struct device *, struct cfdata *, const locdesc_t *, void *);
57int	tsdio_print(void *, const char *);
58
59CFATTACH_DECL(tsdio, sizeof(struct tsdio_softc),
60    tsdio_probe, tsdio_attach, NULL, NULL);
61
62int
63tsdio_probe(parent, cf, aux)
64	struct device *parent;
65	struct cfdata *cf;
66	void *aux;
67{
68	struct isa_attach_args *ia = aux;
69	bus_space_tag_t iot = ia->ia_iot;
70	bus_space_handle_t dioh;
71	int rv = 0, have_io = 0;
72
73	if (ia->ia_nio < 1)
74		return (0);
75	if (ia->ia_nirq < 1)
76		return (0);
77
78	if (ISA_DIRECT_CONFIG(ia))
79		return (0);
80
81	/*
82	 * Disallow wildcarded I/O base.
83	 */
84	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
85		return (0);
86
87	/*
88	 * Map the I/O space.
89	 */
90	if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8,
91	    0, &dioh))
92		goto out;
93	have_io = 1;
94
95	if (bus_space_read_1(ia->ia_iot, dioh, 0) != 0x54) {
96		goto out;
97	}
98
99	rv = 1;
100	ia->ia_nio = 1;
101	ia->ia_io[0].ir_size = 8;
102	ia->ia_niomem = 0;
103	ia->ia_nirq = 0;
104	ia->ia_ndrq = 0;
105
106 out:
107	if (have_io)
108		bus_space_unmap(iot, dioh, 8);
109
110	return (rv);
111}
112
113void
114tsdio_attach(parent, self, aux)
115	struct device *parent, *self;
116	void *aux;
117{
118	struct tsdio_softc *sc = (struct tsdio_softc *) self;
119	struct isa_attach_args *ia = aux;
120
121	sc->sc_iot = ia->ia_iot;
122
123	aprint_normal(": Technologic Systems TS-DIO24\n");
124
125	/*
126	 * Map the device.
127	 */
128	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, 8,
129	    0, &sc->sc_ioh)) {
130		aprint_error("%s: unable to map i/o space\n", sc->sc_dev.dv_xname);
131		return;
132	}
133
134	/*
135	 *  Attach sub-devices
136	 */
137	config_search_ia(tsdio_search, self, "tsdio", NULL);
138}
139
140int
141tsdio_search(parent, cf, l, aux)
142	struct device *parent;
143	struct cfdata *cf;
144	const locdesc_t *l;
145	void *aux;
146{
147	struct tsdio_softc *sc = (struct tsdio_softc *)parent;
148	struct tsdio_attach_args sa;
149
150	sa.ta_iot = sc->sc_iot;
151	sa.ta_ioh = sc->sc_ioh;
152
153	if (config_match(parent, cf, &sa) > 0)
154		config_attach(parent, cf, &sa, tsdio_print);
155
156	return (0);
157}
158
159int
160tsdio_print(aux, name)
161	void *aux;
162	const char *name;
163{
164
165	return (UNCONF);
166}
167