pdcide.c revision 1.34.2.2 1 1.34.2.2 tls /* $NetBSD: pdcide.c,v 1.34.2.2 2014/08/20 00:03:48 tls Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*
4 1.1 bouyer * Copyright (c) 1999, 2000, 2001 Manuel Bouyer.
5 1.1 bouyer *
6 1.1 bouyer * Redistribution and use in source and binary forms, with or without
7 1.1 bouyer * modification, are permitted provided that the following conditions
8 1.1 bouyer * are met:
9 1.1 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.1 bouyer * notice, this list of conditions and the following disclaimer.
11 1.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 bouyer * notice, this list of conditions and the following disclaimer in the
13 1.1 bouyer * documentation and/or other materials provided with the distribution.
14 1.1 bouyer *
15 1.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.20 perry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.1 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.1 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.1 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.1 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.1 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1 bouyer */
26 1.1 bouyer
27 1.21 lukem #include <sys/cdefs.h>
28 1.34.2.2 tls __KERNEL_RCSID(0, "$NetBSD: pdcide.c,v 1.34.2.2 2014/08/20 00:03:48 tls Exp $");
29 1.21 lukem
30 1.1 bouyer #include <sys/param.h>
31 1.1 bouyer #include <sys/systm.h>
32 1.1 bouyer
33 1.1 bouyer #include <dev/pci/pcivar.h>
34 1.1 bouyer #include <dev/pci/pcidevs.h>
35 1.1 bouyer #include <dev/pci/pciidereg.h>
36 1.1 bouyer #include <dev/pci/pciidevar.h>
37 1.1 bouyer #include <dev/pci/pciide_pdc202xx_reg.h>
38 1.1 bouyer
39 1.29 dyoung static void pdc202xx_chip_map(struct pciide_softc *,
40 1.29 dyoung const struct pci_attach_args *);
41 1.15 thorpej static void pdc202xx_setup_channel(struct ata_channel *);
42 1.15 thorpej static void pdc20268_setup_channel(struct ata_channel *);
43 1.2 thorpej static int pdc202xx_pci_intr(void *);
44 1.2 thorpej static int pdc20265_pci_intr(void *);
45 1.2 thorpej static void pdc20262_dma_start(void *, int, int);
46 1.2 thorpej static int pdc20262_dma_finish(void *, int, int, int);
47 1.1 bouyer
48 1.26 cube static int pdcide_match(device_t, cfdata_t, void *);
49 1.26 cube static void pdcide_attach(device_t, device_t, void *);
50 1.1 bouyer
51 1.26 cube CFATTACH_DECL_NEW(pdcide, sizeof(struct pciide_softc),
52 1.34.2.2 tls pdcide_match, pdcide_attach, pciide_detach, NULL);
53 1.1 bouyer
54 1.2 thorpej static const struct pciide_product_desc pciide_promise_products[] = {
55 1.8 fvdl { PCI_PRODUCT_PROMISE_PDC20246,
56 1.4 mycroft 0,
57 1.1 bouyer "Promise Ultra33/ATA Bus Master IDE Accelerator",
58 1.1 bouyer pdc202xx_chip_map,
59 1.1 bouyer },
60 1.8 fvdl { PCI_PRODUCT_PROMISE_PDC20262,
61 1.4 mycroft 0,
62 1.1 bouyer "Promise Ultra66/ATA Bus Master IDE Accelerator",
63 1.1 bouyer pdc202xx_chip_map,
64 1.1 bouyer },
65 1.8 fvdl { PCI_PRODUCT_PROMISE_PDC20267,
66 1.4 mycroft 0,
67 1.1 bouyer "Promise Ultra100/ATA Bus Master IDE Accelerator",
68 1.1 bouyer pdc202xx_chip_map,
69 1.1 bouyer },
70 1.8 fvdl { PCI_PRODUCT_PROMISE_PDC20265,
71 1.4 mycroft 0,
72 1.1 bouyer "Promise Ultra100/ATA Bus Master IDE Accelerator",
73 1.1 bouyer pdc202xx_chip_map,
74 1.1 bouyer },
75 1.8 fvdl { PCI_PRODUCT_PROMISE_PDC20268,
76 1.4 mycroft 0,
77 1.1 bouyer "Promise Ultra100TX2/ATA Bus Master IDE Accelerator",
78 1.1 bouyer pdc202xx_chip_map,
79 1.1 bouyer },
80 1.8 fvdl { PCI_PRODUCT_PROMISE_PDC20270,
81 1.4 mycroft 0,
82 1.1 bouyer "Promise Ultra100TX2v2/ATA Bus Master IDE Accelerator",
83 1.1 bouyer pdc202xx_chip_map,
84 1.1 bouyer },
85 1.8 fvdl { PCI_PRODUCT_PROMISE_PDC20269,
86 1.4 mycroft 0,
87 1.1 bouyer "Promise Ultra133/ATA Bus Master IDE Accelerator",
88 1.1 bouyer pdc202xx_chip_map,
89 1.1 bouyer },
90 1.8 fvdl { PCI_PRODUCT_PROMISE_PDC20276,
91 1.4 mycroft 0,
92 1.1 bouyer "Promise Ultra133TX2/ATA Bus Master IDE Accelerator",
93 1.1 bouyer pdc202xx_chip_map,
94 1.1 bouyer },
95 1.8 fvdl { PCI_PRODUCT_PROMISE_PDC20275,
96 1.4 mycroft 0,
97 1.1 bouyer "Promise Ultra133/ATA Bus Master IDE Accelerator (MB)",
98 1.1 bouyer pdc202xx_chip_map,
99 1.1 bouyer },
100 1.8 fvdl { PCI_PRODUCT_PROMISE_PDC20271,
101 1.4 mycroft 0,
102 1.1 bouyer "Promise Ultra133TX2v2/ATA Bus Master IDE Accelerator",
103 1.1 bouyer pdc202xx_chip_map,
104 1.1 bouyer },
105 1.8 fvdl { PCI_PRODUCT_PROMISE_PDC20277,
106 1.4 mycroft 0,
107 1.1 bouyer "Promise Fasttrak133 Lite Bus Master IDE Accelerator",
108 1.1 bouyer pdc202xx_chip_map,
109 1.1 bouyer },
110 1.1 bouyer { 0,
111 1.1 bouyer 0,
112 1.1 bouyer NULL,
113 1.1 bouyer NULL
114 1.1 bouyer }
115 1.1 bouyer };
116 1.1 bouyer
117 1.2 thorpej static int
118 1.26 cube pdcide_match(device_t parent, cfdata_t match, void *aux)
119 1.1 bouyer {
120 1.1 bouyer struct pci_attach_args *pa = aux;
121 1.1 bouyer
122 1.1 bouyer if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_PROMISE) {
123 1.1 bouyer if (pciide_lookup_product(pa->pa_id, pciide_promise_products))
124 1.1 bouyer return (2);
125 1.1 bouyer }
126 1.1 bouyer return (0);
127 1.1 bouyer }
128 1.1 bouyer
129 1.2 thorpej static void
130 1.26 cube pdcide_attach(device_t parent, device_t self, void *aux)
131 1.1 bouyer {
132 1.1 bouyer struct pci_attach_args *pa = aux;
133 1.26 cube struct pciide_softc *sc = device_private(self);
134 1.26 cube
135 1.34.2.1 bouyer self->dv_maxphys = MIN(parent->dv_maxphys, MACHINE_MAXPHYS);
136 1.34.2.1 bouyer
137 1.26 cube sc->sc_wdcdev.sc_atac.atac_dev = self;
138 1.1 bouyer
139 1.1 bouyer pciide_common_attach(sc, pa,
140 1.1 bouyer pciide_lookup_product(pa->pa_id, pciide_promise_products));
141 1.1 bouyer
142 1.1 bouyer }
143 1.1 bouyer
144 1.1 bouyer /* Macros to test product */
145 1.1 bouyer #define PDC_IS_262(sc) \
146 1.8 fvdl ((sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20262 || \
147 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20267 || \
148 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20265 || \
149 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20268 || \
150 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20270 || \
151 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20269 || \
152 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20276 || \
153 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20275 || \
154 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20271 || \
155 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20277)
156 1.1 bouyer #define PDC_IS_265(sc) \
157 1.8 fvdl ((sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20267 || \
158 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20265 || \
159 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20268 || \
160 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20270 || \
161 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20269 || \
162 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20276 || \
163 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20275 || \
164 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20271 || \
165 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20277)
166 1.1 bouyer #define PDC_IS_268(sc) \
167 1.8 fvdl ((sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20268 || \
168 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20270 || \
169 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20269 || \
170 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20276 || \
171 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20275 || \
172 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20271 || \
173 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20277)
174 1.1 bouyer #define PDC_IS_276(sc) \
175 1.8 fvdl ((sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20269 || \
176 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20276 || \
177 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20275 || \
178 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20271 || \
179 1.8 fvdl (sc)->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20277)
180 1.1 bouyer
181 1.2 thorpej static void
182 1.29 dyoung pdc202xx_chip_map(struct pciide_softc *sc, const struct pci_attach_args *pa)
183 1.1 bouyer {
184 1.1 bouyer struct pciide_channel *cp;
185 1.1 bouyer int channel;
186 1.6 mycroft pcireg_t interface, st, mode;
187 1.1 bouyer
188 1.1 bouyer if (!PDC_IS_268(sc)) {
189 1.1 bouyer st = pci_conf_read(sc->sc_pc, sc->sc_tag, PDC2xx_STATE);
190 1.14 thorpej ATADEBUG_PRINT(("pdc202xx_setup_chip: controller state 0x%x\n",
191 1.1 bouyer st), DEBUG_PROBE);
192 1.6 mycroft /* turn off RAID mode */
193 1.6 mycroft if (st & PDC2xx_STATE_IDERAID) {
194 1.14 thorpej ATADEBUG_PRINT(("pdc202xx_setup_chip: turning off RAID mode\n"), DEBUG_PROBE);
195 1.6 mycroft st &= ~PDC2xx_STATE_IDERAID;
196 1.6 mycroft pci_conf_write(sc->sc_pc, sc->sc_tag, PDC2xx_STATE, st);
197 1.6 mycroft }
198 1.6 mycroft } else
199 1.6 mycroft st = PDC2xx_STATE_NATIVE | PDC262_STATE_EN(0) | PDC262_STATE_EN(1);
200 1.6 mycroft
201 1.1 bouyer if (pciide_chipen(sc, pa) == 0)
202 1.1 bouyer return;
203 1.1 bouyer
204 1.1 bouyer /*
205 1.1 bouyer * can't rely on the PCI_CLASS_REG content if the chip was in raid
206 1.1 bouyer * mode. We have to fake interface
207 1.1 bouyer */
208 1.1 bouyer interface = PCIIDE_INTERFACE_SETTABLE(0) | PCIIDE_INTERFACE_SETTABLE(1);
209 1.6 mycroft if (st & PDC2xx_STATE_NATIVE)
210 1.1 bouyer interface |= PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
211 1.1 bouyer
212 1.26 cube aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
213 1.26 cube "bus-master DMA support present");
214 1.1 bouyer pciide_mapreg_dma(sc, pa);
215 1.25 ad aprint_verbose("\n");
216 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
217 1.1 bouyer if (sc->sc_dma_ok) {
218 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
219 1.1 bouyer sc->sc_wdcdev.irqack = pciide_irqack;
220 1.1 bouyer }
221 1.1 bouyer if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
222 1.1 bouyer PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
223 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
224 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
225 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
226 1.1 bouyer if (PDC_IS_276(sc))
227 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
228 1.1 bouyer else if (PDC_IS_265(sc))
229 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
230 1.1 bouyer else if (PDC_IS_262(sc))
231 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
232 1.1 bouyer else
233 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
234 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_set_modes = PDC_IS_268(sc) ?
235 1.1 bouyer pdc20268_setup_channel : pdc202xx_setup_channel;
236 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
237 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
238 1.34 bouyer sc->sc_wdcdev.wdc_maxdrives = 2;
239 1.1 bouyer
240 1.15 thorpej wdc_allocate_regs(&sc->sc_wdcdev);
241 1.15 thorpej
242 1.8 fvdl if (sc->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20262 ||
243 1.8 fvdl sc->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20267 ||
244 1.8 fvdl sc->sc_pp->ide_product == PCI_PRODUCT_PROMISE_PDC20265) {
245 1.1 bouyer sc->sc_wdcdev.dma_start = pdc20262_dma_start;
246 1.1 bouyer sc->sc_wdcdev.dma_finish = pdc20262_dma_finish;
247 1.1 bouyer }
248 1.1 bouyer
249 1.1 bouyer if (!PDC_IS_268(sc)) {
250 1.1 bouyer /* setup failsafe defaults */
251 1.1 bouyer mode = 0;
252 1.1 bouyer mode = PDC2xx_TIM_SET_PA(mode, pdc2xx_pa[0]);
253 1.1 bouyer mode = PDC2xx_TIM_SET_PB(mode, pdc2xx_pb[0]);
254 1.1 bouyer mode = PDC2xx_TIM_SET_MB(mode, pdc2xx_dma_mb[0]);
255 1.1 bouyer mode = PDC2xx_TIM_SET_MC(mode, pdc2xx_dma_mc[0]);
256 1.1 bouyer for (channel = 0;
257 1.17 thorpej channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
258 1.1 bouyer channel++) {
259 1.14 thorpej ATADEBUG_PRINT(("pdc202xx_setup_chip: channel %d "
260 1.1 bouyer "drive 0 initial timings 0x%x, now 0x%x\n",
261 1.1 bouyer channel, pci_conf_read(sc->sc_pc, sc->sc_tag,
262 1.1 bouyer PDC2xx_TIM(channel, 0)), mode | PDC2xx_TIM_IORDYp),
263 1.1 bouyer DEBUG_PROBE);
264 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag,
265 1.1 bouyer PDC2xx_TIM(channel, 0), mode | PDC2xx_TIM_IORDYp);
266 1.14 thorpej ATADEBUG_PRINT(("pdc202xx_setup_chip: channel %d "
267 1.1 bouyer "drive 1 initial timings 0x%x, now 0x%x\n",
268 1.1 bouyer channel, pci_conf_read(sc->sc_pc, sc->sc_tag,
269 1.1 bouyer PDC2xx_TIM(channel, 1)), mode), DEBUG_PROBE);
270 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag,
271 1.1 bouyer PDC2xx_TIM(channel, 1), mode);
272 1.1 bouyer }
273 1.1 bouyer
274 1.1 bouyer mode = PDC2xx_SCR_DMA;
275 1.1 bouyer if (PDC_IS_265(sc)) {
276 1.1 bouyer mode = PDC2xx_SCR_SET_GEN(mode, PDC265_SCR_GEN_LAT);
277 1.1 bouyer } else if (PDC_IS_262(sc)) {
278 1.1 bouyer mode = PDC2xx_SCR_SET_GEN(mode, PDC262_SCR_GEN_LAT);
279 1.1 bouyer } else {
280 1.1 bouyer /* the BIOS set it up this way */
281 1.1 bouyer mode = PDC2xx_SCR_SET_GEN(mode, 0x1);
282 1.1 bouyer }
283 1.1 bouyer mode = PDC2xx_SCR_SET_I2C(mode, 0x3); /* ditto */
284 1.1 bouyer mode = PDC2xx_SCR_SET_POLL(mode, 0x1); /* ditto */
285 1.14 thorpej ATADEBUG_PRINT(("pdc202xx_setup_chip: initial SCR 0x%x, "
286 1.1 bouyer "now 0x%x\n",
287 1.1 bouyer bus_space_read_4(sc->sc_dma_iot, sc->sc_dma_ioh,
288 1.1 bouyer PDC2xx_SCR),
289 1.1 bouyer mode), DEBUG_PROBE);
290 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, sc->sc_dma_ioh,
291 1.1 bouyer PDC2xx_SCR, mode);
292 1.1 bouyer
293 1.1 bouyer /* controller initial state register is OK even without BIOS */
294 1.1 bouyer /* Set DMA mode to IDE DMA compatibility */
295 1.1 bouyer mode =
296 1.1 bouyer bus_space_read_1(sc->sc_dma_iot, sc->sc_dma_ioh, PDC2xx_PM);
297 1.14 thorpej ATADEBUG_PRINT(("pdc202xx_setup_chip: primary mode 0x%x", mode),
298 1.1 bouyer DEBUG_PROBE);
299 1.1 bouyer bus_space_write_1(sc->sc_dma_iot, sc->sc_dma_ioh, PDC2xx_PM,
300 1.1 bouyer mode | 0x1);
301 1.1 bouyer mode =
302 1.1 bouyer bus_space_read_1(sc->sc_dma_iot, sc->sc_dma_ioh, PDC2xx_SM);
303 1.14 thorpej ATADEBUG_PRINT((", secondary mode 0x%x\n", mode ), DEBUG_PROBE);
304 1.1 bouyer bus_space_write_1(sc->sc_dma_iot, sc->sc_dma_ioh, PDC2xx_SM,
305 1.1 bouyer mode | 0x1);
306 1.1 bouyer }
307 1.17 thorpej for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
308 1.17 thorpej channel++) {
309 1.1 bouyer cp = &sc->pciide_channels[channel];
310 1.1 bouyer if (pciide_chansetup(sc, channel, interface) == 0)
311 1.1 bouyer continue;
312 1.6 mycroft if ((st & (PDC_IS_262(sc) ?
313 1.1 bouyer PDC262_STATE_EN(channel):PDC246_STATE_EN(channel))) == 0) {
314 1.26 cube aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
315 1.26 cube "%s channel ignored (disabled)\n", cp->name);
316 1.15 thorpej cp->ata_channel.ch_flags |= ATACH_DISABLED;
317 1.1 bouyer continue;
318 1.1 bouyer }
319 1.28 jakllsch pciide_mapchan(pa, cp, interface,
320 1.1 bouyer PDC_IS_265(sc) ? pdc20265_pci_intr : pdc202xx_pci_intr);
321 1.7 bouyer /* clear interrupt, in case there is one pending */
322 1.9 fvdl bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
323 1.9 fvdl IDEDMA_CTL_INTR);
324 1.1 bouyer }
325 1.1 bouyer return;
326 1.1 bouyer }
327 1.1 bouyer
328 1.2 thorpej static void
329 1.15 thorpej pdc202xx_setup_channel(struct ata_channel *chp)
330 1.1 bouyer {
331 1.1 bouyer struct ata_drive_datas *drvp;
332 1.18 thorpej int drive, s;
333 1.1 bouyer pcireg_t mode, st;
334 1.1 bouyer u_int32_t idedma_ctl, scr, atapi;
335 1.16 thorpej struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
336 1.16 thorpej struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
337 1.11 thorpej int channel = chp->ch_channel;
338 1.1 bouyer
339 1.1 bouyer /* setup DMA if needed */
340 1.1 bouyer pciide_channel_dma_setup(cp);
341 1.1 bouyer
342 1.1 bouyer idedma_ctl = 0;
343 1.14 thorpej ATADEBUG_PRINT(("pdc202xx_setup_channel %s: scr 0x%x\n",
344 1.26 cube device_xname(sc->sc_wdcdev.sc_atac.atac_dev),
345 1.1 bouyer bus_space_read_1(sc->sc_dma_iot, sc->sc_dma_ioh, PDC262_U66)),
346 1.1 bouyer DEBUG_PROBE);
347 1.1 bouyer
348 1.1 bouyer /* Per channel settings */
349 1.1 bouyer if (PDC_IS_262(sc)) {
350 1.1 bouyer scr = bus_space_read_1(sc->sc_dma_iot, sc->sc_dma_ioh,
351 1.1 bouyer PDC262_U66);
352 1.1 bouyer st = pci_conf_read(sc->sc_pc, sc->sc_tag, PDC2xx_STATE);
353 1.1 bouyer /* Trim UDMA mode */
354 1.1 bouyer if ((st & PDC262_STATE_80P(channel)) != 0 ||
355 1.34 bouyer (chp->ch_drive[0].drive_flags & ATA_DRIVE_UDMA &&
356 1.1 bouyer chp->ch_drive[0].UDMA_mode <= 2) ||
357 1.34 bouyer (chp->ch_drive[1].drive_flags & ATA_DRIVE_UDMA &&
358 1.1 bouyer chp->ch_drive[1].UDMA_mode <= 2)) {
359 1.1 bouyer if (chp->ch_drive[0].UDMA_mode > 2)
360 1.1 bouyer chp->ch_drive[0].UDMA_mode = 2;
361 1.1 bouyer if (chp->ch_drive[1].UDMA_mode > 2)
362 1.1 bouyer chp->ch_drive[1].UDMA_mode = 2;
363 1.1 bouyer }
364 1.1 bouyer /* Set U66 if needed */
365 1.34 bouyer if ((chp->ch_drive[0].drive_flags & ATA_DRIVE_UDMA &&
366 1.1 bouyer chp->ch_drive[0].UDMA_mode > 2) ||
367 1.34 bouyer (chp->ch_drive[1].drive_flags & ATA_DRIVE_UDMA &&
368 1.1 bouyer chp->ch_drive[1].UDMA_mode > 2))
369 1.1 bouyer scr |= PDC262_U66_EN(channel);
370 1.1 bouyer else
371 1.1 bouyer scr &= ~PDC262_U66_EN(channel);
372 1.1 bouyer bus_space_write_1(sc->sc_dma_iot, sc->sc_dma_ioh,
373 1.1 bouyer PDC262_U66, scr);
374 1.14 thorpej ATADEBUG_PRINT(("pdc202xx_setup_channel %s:%d: ATAPI 0x%x\n",
375 1.26 cube device_xname(sc->sc_wdcdev.sc_atac.atac_dev), channel,
376 1.1 bouyer bus_space_read_4(sc->sc_dma_iot, sc->sc_dma_ioh,
377 1.1 bouyer PDC262_ATAPI(channel))), DEBUG_PROBE);
378 1.34 bouyer if (chp->ch_drive[0].drive_type == ATA_DRIVET_ATAPI ||
379 1.34 bouyer chp->ch_drive[1].drive_type == ATA_DRIVET_ATAPI) {
380 1.34 bouyer if (((chp->ch_drive[0].drive_flags & ATA_DRIVE_UDMA) &&
381 1.34 bouyer !(chp->ch_drive[1].drive_flags & ATA_DRIVE_UDMA) &&
382 1.34 bouyer (chp->ch_drive[1].drive_flags & ATA_DRIVE_DMA)) ||
383 1.34 bouyer ((chp->ch_drive[1].drive_flags & ATA_DRIVE_UDMA) &&
384 1.34 bouyer !(chp->ch_drive[0].drive_flags & ATA_DRIVE_UDMA) &&
385 1.34 bouyer (chp->ch_drive[0].drive_flags & ATA_DRIVE_DMA)))
386 1.1 bouyer atapi = 0;
387 1.1 bouyer else
388 1.1 bouyer atapi = PDC262_ATAPI_UDMA;
389 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, sc->sc_dma_ioh,
390 1.1 bouyer PDC262_ATAPI(channel), atapi);
391 1.1 bouyer }
392 1.1 bouyer }
393 1.1 bouyer for (drive = 0; drive < 2; drive++) {
394 1.1 bouyer drvp = &chp->ch_drive[drive];
395 1.1 bouyer /* If no drive, skip */
396 1.34 bouyer if (drvp->drive_type == ATA_DRIVET_NONE)
397 1.1 bouyer continue;
398 1.1 bouyer mode = 0;
399 1.34 bouyer if (drvp->drive_flags & ATA_DRIVE_UDMA) {
400 1.1 bouyer /* use Ultra/DMA */
401 1.18 thorpej s = splbio();
402 1.34 bouyer drvp->drive_flags &= ~ATA_DRIVE_DMA;
403 1.18 thorpej splx(s);
404 1.1 bouyer mode = PDC2xx_TIM_SET_MB(mode,
405 1.1 bouyer pdc2xx_udma_mb[drvp->UDMA_mode]);
406 1.1 bouyer mode = PDC2xx_TIM_SET_MC(mode,
407 1.1 bouyer pdc2xx_udma_mc[drvp->UDMA_mode]);
408 1.1 bouyer idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
409 1.34 bouyer } else if (drvp->drive_flags & ATA_DRIVE_DMA) {
410 1.1 bouyer mode = PDC2xx_TIM_SET_MB(mode,
411 1.1 bouyer pdc2xx_dma_mb[drvp->DMA_mode]);
412 1.1 bouyer mode = PDC2xx_TIM_SET_MC(mode,
413 1.1 bouyer pdc2xx_dma_mc[drvp->DMA_mode]);
414 1.1 bouyer idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
415 1.1 bouyer } else {
416 1.1 bouyer mode = PDC2xx_TIM_SET_MB(mode,
417 1.1 bouyer pdc2xx_dma_mb[0]);
418 1.1 bouyer mode = PDC2xx_TIM_SET_MC(mode,
419 1.1 bouyer pdc2xx_dma_mc[0]);
420 1.1 bouyer }
421 1.1 bouyer mode = PDC2xx_TIM_SET_PA(mode, pdc2xx_pa[drvp->PIO_mode]);
422 1.1 bouyer mode = PDC2xx_TIM_SET_PB(mode, pdc2xx_pb[drvp->PIO_mode]);
423 1.34 bouyer if (drvp->drive_type == ATA_DRIVET_ATA)
424 1.1 bouyer mode |= PDC2xx_TIM_PRE;
425 1.1 bouyer mode |= PDC2xx_TIM_SYNC | PDC2xx_TIM_ERRDY;
426 1.1 bouyer if (drvp->PIO_mode >= 3) {
427 1.1 bouyer mode |= PDC2xx_TIM_IORDY;
428 1.1 bouyer if (drive == 0)
429 1.1 bouyer mode |= PDC2xx_TIM_IORDYp;
430 1.1 bouyer }
431 1.14 thorpej ATADEBUG_PRINT(("pdc202xx_setup_channel: %s:%d:%d "
432 1.1 bouyer "timings 0x%x\n",
433 1.26 cube device_xname(sc->sc_wdcdev.sc_atac.atac_dev),
434 1.11 thorpej chp->ch_channel, drive, mode), DEBUG_PROBE);
435 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag,
436 1.11 thorpej PDC2xx_TIM(chp->ch_channel, drive), mode);
437 1.1 bouyer }
438 1.1 bouyer if (idedma_ctl != 0) {
439 1.1 bouyer /* Add software bits in status register */
440 1.9 fvdl bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL],
441 1.9 fvdl 0, idedma_ctl);
442 1.1 bouyer }
443 1.1 bouyer }
444 1.1 bouyer
445 1.2 thorpej static void
446 1.15 thorpej pdc20268_setup_channel(struct ata_channel *chp)
447 1.1 bouyer {
448 1.1 bouyer struct ata_drive_datas *drvp;
449 1.18 thorpej int drive, s;
450 1.1 bouyer u_int32_t idedma_ctl;
451 1.16 thorpej struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
452 1.16 thorpej struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
453 1.1 bouyer int u100;
454 1.1 bouyer
455 1.20 perry /* setup DMA if needed */
456 1.20 perry pciide_channel_dma_setup(cp);
457 1.1 bouyer
458 1.1 bouyer idedma_ctl = 0;
459 1.1 bouyer
460 1.1 bouyer /* I don't know what this is for, FreeBSD does it ... */
461 1.1 bouyer bus_space_write_1(sc->sc_dma_iot, sc->sc_dma_ioh,
462 1.11 thorpej IDEDMA_CMD + 0x1 + IDEDMA_SCH_OFFSET * chp->ch_channel, 0x0b);
463 1.1 bouyer
464 1.1 bouyer /*
465 1.1 bouyer * cable type detect, from FreeBSD
466 1.1 bouyer */
467 1.1 bouyer u100 = (bus_space_read_1(sc->sc_dma_iot, sc->sc_dma_ioh,
468 1.11 thorpej IDEDMA_CMD + 0x3 + IDEDMA_SCH_OFFSET * chp->ch_channel) & 0x04) ?
469 1.1 bouyer 0 : 1;
470 1.1 bouyer
471 1.1 bouyer for (drive = 0; drive < 2; drive++) {
472 1.1 bouyer drvp = &chp->ch_drive[drive];
473 1.1 bouyer /* If no drive, skip */
474 1.34 bouyer if (drvp->drive_type == ATA_DRIVET_NONE)
475 1.1 bouyer continue;
476 1.34 bouyer if (drvp->drive_flags & ATA_DRIVE_UDMA) {
477 1.1 bouyer /* use Ultra/DMA */
478 1.18 thorpej s = splbio();
479 1.34 bouyer drvp->drive_flags &= ~ATA_DRIVE_DMA;
480 1.18 thorpej splx(s);
481 1.1 bouyer idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
482 1.1 bouyer if (drvp->UDMA_mode > 2 && u100 == 0)
483 1.1 bouyer drvp->UDMA_mode = 2;
484 1.34 bouyer } else if (drvp->drive_flags & ATA_DRIVE_DMA) {
485 1.1 bouyer idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
486 1.1 bouyer }
487 1.1 bouyer }
488 1.1 bouyer /* nothing to do to setup modes, the controller snoop SET_FEATURE cmd */
489 1.1 bouyer if (idedma_ctl != 0) {
490 1.1 bouyer /* Add software bits in status register */
491 1.9 fvdl bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL],
492 1.9 fvdl 0, idedma_ctl);
493 1.1 bouyer }
494 1.1 bouyer }
495 1.1 bouyer
496 1.2 thorpej static int
497 1.2 thorpej pdc202xx_pci_intr(void *arg)
498 1.1 bouyer {
499 1.1 bouyer struct pciide_softc *sc = arg;
500 1.1 bouyer struct pciide_channel *cp;
501 1.15 thorpej struct ata_channel *wdc_cp;
502 1.20 perry int i, rv, crv;
503 1.1 bouyer u_int32_t scr;
504 1.1 bouyer
505 1.1 bouyer rv = 0;
506 1.1 bouyer scr = bus_space_read_4(sc->sc_dma_iot, sc->sc_dma_ioh, PDC2xx_SCR);
507 1.17 thorpej for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
508 1.1 bouyer cp = &sc->pciide_channels[i];
509 1.15 thorpej wdc_cp = &cp->ata_channel;
510 1.1 bouyer /* If a compat channel skip. */
511 1.1 bouyer if (cp->compat)
512 1.1 bouyer continue;
513 1.1 bouyer if (scr & PDC2xx_SCR_INT(i)) {
514 1.1 bouyer crv = wdcintr(wdc_cp);
515 1.19 bouyer if (crv == 0)
516 1.26 cube aprint_error("%s:%d: bogus intr (reg 0x%x)\n",
517 1.26 cube device_xname(
518 1.26 cube sc->sc_wdcdev.sc_atac.atac_dev), i, scr);
519 1.19 bouyer else
520 1.1 bouyer rv = 1;
521 1.1 bouyer }
522 1.1 bouyer }
523 1.1 bouyer return rv;
524 1.1 bouyer }
525 1.1 bouyer
526 1.2 thorpej static int
527 1.2 thorpej pdc20265_pci_intr(void *arg)
528 1.1 bouyer {
529 1.1 bouyer struct pciide_softc *sc = arg;
530 1.1 bouyer struct pciide_channel *cp;
531 1.15 thorpej struct ata_channel *wdc_cp;
532 1.20 perry int i, rv, crv;
533 1.1 bouyer u_int32_t dmastat;
534 1.1 bouyer
535 1.1 bouyer rv = 0;
536 1.17 thorpej for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
537 1.1 bouyer cp = &sc->pciide_channels[i];
538 1.15 thorpej wdc_cp = &cp->ata_channel;
539 1.1 bouyer /* If a compat channel skip. */
540 1.1 bouyer if (cp->compat)
541 1.1 bouyer continue;
542 1.1 bouyer #if 0
543 1.1 bouyer bus_space_write_1(sc->sc_dma_iot, sc->sc_dma_ioh, IDEDMA_CMD + 0x1 + IDEDMA_SCH_OFFSET * i, 0x0b);
544 1.1 bouyer if ((bus_space_read_1(sc->sc_dma_iot, sc->sc_dma_ioh, IDEDMA_CMD + 0x3 + IDEDMA_SCH_OFFSET * i) & 0x20) == 0)
545 1.1 bouyer continue;
546 1.1 bouyer #endif
547 1.1 bouyer /*
548 1.1 bouyer * The Ultra/100 seems to assert PDC2xx_SCR_INT * spuriously,
549 1.1 bouyer * however it asserts INT in IDEDMA_CTL even for non-DMA ops.
550 1.1 bouyer * So use it instead (requires 2 reg reads instead of 1,
551 1.1 bouyer * but we can't do it another way).
552 1.1 bouyer */
553 1.1 bouyer dmastat = bus_space_read_1(sc->sc_dma_iot,
554 1.9 fvdl cp->dma_iohs[IDEDMA_CTL], 0);
555 1.1 bouyer if((dmastat & IDEDMA_CTL_INTR) == 0)
556 1.1 bouyer continue;
557 1.1 bouyer crv = wdcintr(wdc_cp);
558 1.1 bouyer if (crv == 0)
559 1.26 cube aprint_error("%s:%d: bogus intr\n",
560 1.26 cube device_xname(sc->sc_wdcdev.sc_atac.atac_dev), i);
561 1.1 bouyer else
562 1.1 bouyer rv = 1;
563 1.1 bouyer }
564 1.1 bouyer return rv;
565 1.1 bouyer }
566 1.1 bouyer
567 1.1 bouyer static void
568 1.2 thorpej pdc20262_dma_start(void *v, int channel, int drive)
569 1.1 bouyer {
570 1.1 bouyer struct pciide_softc *sc = v;
571 1.1 bouyer struct pciide_dma_maps *dma_maps =
572 1.1 bouyer &sc->pciide_channels[channel].dma_maps[drive];
573 1.1 bouyer int atapi;
574 1.1 bouyer
575 1.1 bouyer if (dma_maps->dma_flags & WDC_DMA_LBA48) {
576 1.1 bouyer atapi = (dma_maps->dma_flags & WDC_DMA_READ) ?
577 1.1 bouyer PDC262_ATAPI_LBA48_READ : PDC262_ATAPI_LBA48_WRITE;
578 1.1 bouyer atapi |= dma_maps->dmamap_xfer->dm_mapsize >> 1;
579 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, sc->sc_dma_ioh,
580 1.1 bouyer PDC262_ATAPI(channel), atapi);
581 1.1 bouyer }
582 1.1 bouyer
583 1.1 bouyer pciide_dma_start(v, channel, drive);
584 1.1 bouyer }
585 1.1 bouyer
586 1.2 thorpej static int
587 1.2 thorpej pdc20262_dma_finish(void *v, int channel, int drive, int force)
588 1.1 bouyer {
589 1.1 bouyer struct pciide_softc *sc = v;
590 1.1 bouyer struct pciide_dma_maps *dma_maps =
591 1.1 bouyer &sc->pciide_channels[channel].dma_maps[drive];
592 1.15 thorpej struct ata_channel *chp;
593 1.1 bouyer int atapi, error;
594 1.1 bouyer
595 1.1 bouyer error = pciide_dma_finish(v, channel, drive, force);
596 1.1 bouyer
597 1.1 bouyer if (dma_maps->dma_flags & WDC_DMA_LBA48) {
598 1.1 bouyer chp = sc->wdc_chanarray[channel];
599 1.1 bouyer atapi = 0;
600 1.34 bouyer if (chp->ch_drive[0].drive_type == ATA_DRIVET_ATAPI ||
601 1.34 bouyer chp->ch_drive[1].drive_type == ATA_DRIVET_ATAPI) {
602 1.34 bouyer if ((!(chp->ch_drive[0].drive_flags & ATA_DRIVE_UDMA) ||
603 1.34 bouyer (chp->ch_drive[1].drive_flags & ATA_DRIVE_UDMA) ||
604 1.34 bouyer !(chp->ch_drive[1].drive_flags & ATA_DRIVE_DMA)) &&
605 1.34 bouyer (!(chp->ch_drive[1].drive_flags & ATA_DRIVE_UDMA) ||
606 1.34 bouyer (chp->ch_drive[0].drive_flags & ATA_DRIVE_UDMA) ||
607 1.34 bouyer !(chp->ch_drive[0].drive_flags & ATA_DRIVE_DMA)))
608 1.1 bouyer atapi = PDC262_ATAPI_UDMA;
609 1.1 bouyer }
610 1.1 bouyer bus_space_write_4(sc->sc_dma_iot, sc->sc_dma_ioh,
611 1.1 bouyer PDC262_ATAPI(channel), atapi);
612 1.1 bouyer }
613 1.1 bouyer
614 1.1 bouyer return error;
615 1.1 bouyer }
616