xref: /openbsd-src/sys/dev/isa/wdc_isapnp.c (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: wdc_isapnp.c,v 1.10 2011/06/29 12:17:40 tedu Exp $	*/
2 /*	$NetBSD: wdc_isapnp.c,v 1.13 1999/03/22 10:00:12 mycroft Exp $	*/
3 
4 /*-
5  * Copyright (c) 1998 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Charles M. Hannum and by Onno van der Linden.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37 #include <sys/malloc.h>
38 
39 #include <machine/bus.h>
40 #include <machine/intr.h>
41 
42 #include <dev/isa/isavar.h>
43 #include <dev/isa/isadmavar.h>
44 
45 #include <dev/ata/atavar.h>
46 #include <dev/ic/wdcreg.h>
47 #include <dev/ic/wdcvar.h>
48 
49 struct wdc_isapnp_softc {
50 	struct	wdc_softc sc_wdcdev;
51 	struct	channel_softc *wdc_chanptr;
52 	struct	channel_softc wdc_channel;
53 	isa_chipset_tag_t sc_ic;
54 	void	*sc_ih;
55 	int	sc_drq;
56 };
57 
58 int	wdc_isapnp_match(struct device *, void *, void *);
59 void	wdc_isapnp_attach(struct device *, struct device *, void *);
60 
61 struct cfattach wdc_isapnp_ca = {
62 	sizeof(struct wdc_isapnp_softc), wdc_isapnp_match, wdc_isapnp_attach
63 };
64 
65 int
66 wdc_isapnp_match(parent, match, aux)
67 	struct device *parent;
68 	void *match;
69 	void *aux;
70 {
71 	struct isa_attach_args *ipa = aux;
72 
73 	if (ipa->ipa_nio != 2 ||
74 	    ipa->ipa_nmem != 0 ||
75 	    ipa->ipa_nmem32 != 0 ||
76 	    ipa->ipa_nirq != 1 ||
77 	    ipa->ipa_ndrq > 1)
78 		return 0;
79 
80 	return (1);
81 }
82 
83 void
84 wdc_isapnp_attach(parent, self, aux)
85 	struct device *parent, *self;
86 	void *aux;
87 {
88 	struct wdc_isapnp_softc *sc = (void *)self;
89 	struct isa_attach_args *ipa = aux;
90 
91 
92 	sc->wdc_channel.cmd_iot = ipa->ia_iot;
93 	sc->wdc_channel.ctl_iot = ipa->ia_iot;
94 
95 	/*
96 	 * An IDE controller can feed us the regions in any order. Pass
97 	 * them along with the 8-byte region in sc_ad.ioh, and the other
98 	 * (2 byte) region in auxioh.
99 	 */
100 	if (ipa->ipa_io[0].length == 8) {
101 		sc->wdc_channel.cmd_ioh = ipa->ipa_io[0].h;
102 		sc->wdc_channel.ctl_ioh = ipa->ipa_io[1].h;
103 	} else {
104 		sc->wdc_channel.cmd_ioh = ipa->ipa_io[1].h;
105 		sc->wdc_channel.ctl_ioh = ipa->ipa_io[0].h;
106 	}
107 	sc->wdc_channel.data32iot = sc->wdc_channel.cmd_iot;
108 	sc->wdc_channel.data32ioh = sc->wdc_channel.cmd_ioh;
109 
110 	sc->sc_ic = ipa->ia_ic;
111 	sc->sc_ih = isa_intr_establish(ipa->ia_ic, ipa->ipa_irq[0].num,
112 	    ipa->ipa_irq[0].type, IPL_BIO, wdcintr, &sc->wdc_channel,
113 	    sc->sc_wdcdev.sc_dev.dv_xname);
114 
115 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32;
116 	sc->sc_wdcdev.PIO_cap = 0;
117 	sc->wdc_chanptr = &sc->wdc_channel;
118 	sc->sc_wdcdev.channels = &sc->wdc_chanptr;
119 	sc->sc_wdcdev.nchannels = 1;
120 	sc->wdc_channel.channel = 0;
121 	sc->wdc_channel.wdc = &sc->sc_wdcdev;
122 	sc->wdc_channel.ch_queue = wdc_alloc_queue();
123 	if (sc->wdc_channel.ch_queue == NULL) {
124 		printf(": cannot allocate channel queue\n");
125 		return;
126 	}
127 
128 	printf("\n");
129 	wdcattach(&sc->wdc_channel);
130 	wdc_print_current_modes(&sc->wdc_channel);
131 }
132