slide.c revision 1.1 1 /* $NetBSD: slide.c,v 1.1 2003/10/08 11:51:59 bouyer Exp $ */
2
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
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/param.h>
40 #include <sys/systm.h>
41
42 #include <dev/pci/pcivar.h>
43 #include <dev/pci/pcidevs.h>
44 #include <dev/pci/pciidereg.h>
45 #include <dev/pci/pciidevar.h>
46 #include <dev/pci/pciide_sl82c105_reg.h>
47
48 void sl82c105_chip_map __P((struct pciide_softc*, struct pci_attach_args*));
49 void sl82c105_setup_channel __P((struct channel_softc*));
50
51 int slide_match __P((struct device *, struct cfdata *, void *));
52 void slide_attach __P((struct device *, struct device *, void *));
53
54 CFATTACH_DECL(slide, sizeof(struct pciide_softc),
55 slide_match, slide_attach, NULL, NULL);
56
57 const struct pciide_product_desc pciide_symphony_products[] = {
58 { PCI_PRODUCT_SYMPHONY_82C105,
59 0,
60 "Symphony Labs 82C105 IDE controller",
61 sl82c105_chip_map,
62 },
63 { 0,
64 0,
65 NULL,
66 }
67 };
68
69 const struct pciide_product_desc pciide_winbond_products[] = {
70 { PCI_PRODUCT_WINBOND_W83C553F_1,
71 0,
72 "Winbond W83C553F IDE controller",
73 sl82c105_chip_map,
74 },
75 { 0,
76 0,
77 NULL,
78 }
79 };
80
81 int
82 slide_match(parent, match, aux)
83 struct device *parent;
84 struct cfdata *match;
85 void *aux;
86 {
87 struct pci_attach_args *pa = aux;
88
89 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SYMPHONY) {
90 if (pciide_lookup_product(pa->pa_id, pciide_symphony_products))
91 return (2);
92 }
93 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_WINBOND) {
94 if (pciide_lookup_product(pa->pa_id, pciide_winbond_products))
95 return (2);
96 }
97 return (0);
98 }
99
100 void
101 slide_attach(parent, self, aux)
102 struct device *parent, *self;
103 void *aux;
104 {
105 struct pci_attach_args *pa = aux;
106 struct pciide_softc *sc = (struct pciide_softc *)self;
107 const struct pciide_product_desc *pp = NULL;
108
109 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SYMPHONY)
110 pp = pciide_lookup_product(pa->pa_id, pciide_symphony_products);
111 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_WINBOND)
112 pp = pciide_lookup_product(pa->pa_id, pciide_winbond_products);
113 if (pp == NULL)
114 panic("slide_attach");
115 pciide_common_attach(sc, pa, pp);
116 }
117
118 static int
119 sl82c105_bugchk(struct pci_attach_args *pa)
120 {
121
122 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_WINBOND ||
123 PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_WINBOND_W83C553F_0)
124 return (0);
125
126 if (PCI_REVISION(pa->pa_class) <= 0x05)
127 return (1);
128
129 return (0);
130 }
131
132 void
133 sl82c105_chip_map(sc, pa)
134 struct pciide_softc *sc;
135 struct pci_attach_args *pa;
136 {
137 struct pciide_channel *cp;
138 bus_size_t cmdsize, ctlsize;
139 pcireg_t interface, idecr;
140 int channel;
141
142 if (pciide_chipen(sc, pa) == 0)
143 return;
144
145 aprint_normal("%s: bus-master DMA support present",
146 sc->sc_wdcdev.sc_dev.dv_xname);
147
148 /*
149 * Check to see if we're part of the Winbond 83c553 Southbridge.
150 * If so, we need to disable DMA on rev. <= 5 of that chip.
151 */
152 if (pci_find_device(pa, sl82c105_bugchk)) {
153 aprint_normal(" but disabled due to 83c553 rev. <= 0x05");
154 sc->sc_dma_ok = 0;
155 } else
156 pciide_mapreg_dma(sc, pa);
157 aprint_normal("\n");
158
159 sc->sc_wdcdev.cap = WDC_CAPABILITY_DATA32 | WDC_CAPABILITY_DATA16 |
160 WDC_CAPABILITY_MODE;
161 sc->sc_wdcdev.PIO_cap = 4;
162 if (sc->sc_dma_ok) {
163 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA | WDC_CAPABILITY_IRQACK;
164 sc->sc_wdcdev.irqack = pciide_irqack;
165 sc->sc_wdcdev.DMA_cap = 2;
166 }
167 sc->sc_wdcdev.set_modes = sl82c105_setup_channel;
168
169 sc->sc_wdcdev.channels = sc->wdc_chanarray;
170 sc->sc_wdcdev.nchannels = PCIIDE_NUM_CHANNELS;
171
172 idecr = pci_conf_read(sc->sc_pc, sc->sc_tag, SYMPH_IDECSR);
173
174 interface = PCI_INTERFACE(pa->pa_class);
175
176 for (channel = 0; channel < sc->sc_wdcdev.nchannels; channel++) {
177 cp = &sc->pciide_channels[channel];
178 if (pciide_chansetup(sc, channel, interface) == 0)
179 continue;
180 if ((channel == 0 && (idecr & IDECR_P0EN) == 0) ||
181 (channel == 1 && (idecr & IDECR_P1EN) == 0)) {
182 aprint_normal("%s: %s channel ignored (disabled)\n",
183 sc->sc_wdcdev.sc_dev.dv_xname, cp->name);
184 cp->wdc_channel.ch_flags |= WDCF_DISABLED;
185 continue;
186 }
187 pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
188 pciide_pci_intr);
189 }
190 }
191
192 void
193 sl82c105_setup_channel(chp)
194 struct channel_softc *chp;
195 {
196 struct ata_drive_datas *drvp;
197 struct pciide_channel *cp = (struct pciide_channel*)chp;
198 struct pciide_softc *sc = (struct pciide_softc *)cp->wdc_channel.wdc;
199 int pxdx_reg, drive;
200 pcireg_t pxdx;
201
202 /* Set up DMA if needed. */
203 pciide_channel_dma_setup(cp);
204
205 for (drive = 0; drive < 2; drive++) {
206 pxdx_reg = ((chp->channel == 0) ? SYMPH_P0D0CR
207 : SYMPH_P1D0CR) + (drive * 4);
208
209 pxdx = pci_conf_read(sc->sc_pc, sc->sc_tag, pxdx_reg);
210
211 pxdx &= ~(PxDx_CMD_ON_MASK|PxDx_CMD_OFF_MASK);
212 pxdx &= ~(PxDx_PWEN|PxDx_RDYEN|PxDx_RAEN);
213
214 drvp = &chp->ch_drive[drive];
215 /* If no drive, skip. */
216 if ((drvp->drive_flags & DRIVE) == 0) {
217 pci_conf_write(sc->sc_pc, sc->sc_tag, pxdx_reg, pxdx);
218 continue;
219 }
220
221 if (drvp->drive_flags & DRIVE_DMA) {
222 /*
223 * Timings will be used for both PIO and DMA,
224 * so adjust DMA mode if needed.
225 */
226 if (drvp->PIO_mode >= 3) {
227 if ((drvp->DMA_mode + 2) > drvp->PIO_mode)
228 drvp->DMA_mode = drvp->PIO_mode - 2;
229 if (drvp->DMA_mode < 1) {
230 /*
231 * Can't mix both PIO and DMA.
232 * Disable DMA.
233 */
234 drvp->drive_flags &= ~DRIVE_DMA;
235 }
236 } else {
237 /*
238 * Can't mix both PIO and DMA. Disable
239 * DMA.
240 */
241 drvp->drive_flags &= ~DRIVE_DMA;
242 }
243 }
244
245 if (drvp->drive_flags & DRIVE_DMA) {
246 /* Use multi-word DMA. */
247 pxdx |= symph_mw_dma_times[drvp->DMA_mode].cmd_on <<
248 PxDx_CMD_ON_SHIFT;
249 pxdx |= symph_mw_dma_times[drvp->DMA_mode].cmd_off;
250 } else {
251 pxdx |= symph_pio_times[drvp->PIO_mode].cmd_on <<
252 PxDx_CMD_ON_SHIFT;
253 pxdx |= symph_pio_times[drvp->PIO_mode].cmd_off;
254 }
255
256 /* XXX PxDx_PWEN? PxDx_RDYEN? PxDx_RAEN? */
257
258 /* ...and set the mode for this drive. */
259 pci_conf_write(sc->sc_pc, sc->sc_tag, pxdx_reg, pxdx);
260 }
261 }
262