pdcsata.c revision 1.3.2.2 1 /* $NetBSD: pdcsata.c,v 1.3.2.2 2006/02/05 17:13:57 riz Exp $ */
2
3 /*
4 * Copyright (c) 2004, Manuel Bouyer.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Manuel Bouyer.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/types.h>
33 #include <sys/malloc.h>
34 #include <sys/param.h>
35 #include <sys/systm.h>
36
37 #include <dev/pci/pcivar.h>
38 #include <dev/pci/pcidevs.h>
39 #include <dev/pci/pciidereg.h>
40 #include <dev/pci/pciidevar.h>
41 #include <dev/ata/atareg.h>
42 #include <dev/ata/satavar.h>
43 #include <dev/ata/satareg.h>
44
45 #define PDC203xx_NCHANNELS 4
46 #define PDC40718_NCHANNELS 4
47 #define PDC20575_NCHANNELS 3
48
49 #define PDC203xx_BAR_IDEREGS 0x1c /* BAR where the IDE registers are mapped */
50
51 static void pdcsata_chip_map(struct pciide_softc *, struct pci_attach_args *);
52 static void pdc203xx_setup_channel(struct ata_channel *);
53 static int pdc203xx_pci_intr(void *);
54 static void pdc203xx_irqack(struct ata_channel *);
55 static int pdc203xx_dma_init(void *, int, int, void *, size_t, int);
56 static void pdc203xx_dma_start(void *,int ,int);
57 static int pdc203xx_dma_finish(void *, int, int, int);
58
59 /* PDC205xx, PDC405xx and PDC407xx. but tested only pdc40718 */
60 static int pdc205xx_pci_intr(void *);
61 static void pdc205xx_do_reset(struct ata_channel *, int);
62 static void pdc205xx_drv_probe(struct ata_channel *);
63
64 static int pdcsata_match(struct device *, struct cfdata *, void *);
65 static void pdcsata_attach(struct device *, struct device *, void *);
66
67 CFATTACH_DECL(pdcsata, sizeof(struct pciide_softc),
68 pdcsata_match, pdcsata_attach, NULL, NULL);
69
70 static const struct pciide_product_desc pciide_pdcsata_products[] = {
71 { PCI_PRODUCT_PROMISE_PDC20318,
72 0,
73 "Promise PDC20318 SATA150 controller",
74 pdcsata_chip_map,
75 },
76 { PCI_PRODUCT_PROMISE_PDC20319,
77 0,
78 "Promise PDC20319 SATA150 controller",
79 pdcsata_chip_map,
80 },
81 { PCI_PRODUCT_PROMISE_PDC20371,
82 0,
83 "Promise PDC20371 SATA150 controller",
84 pdcsata_chip_map,
85 },
86 { PCI_PRODUCT_PROMISE_PDC20375,
87 0,
88 "Promise PDC20375 SATA150 controller",
89 pdcsata_chip_map,
90 },
91 { PCI_PRODUCT_PROMISE_PDC20376,
92 0,
93 "Promise PDC20376 SATA150 controller",
94 pdcsata_chip_map,
95 },
96 { PCI_PRODUCT_PROMISE_PDC20377,
97 0,
98 "Promise PDC20377 SATA150 controller",
99 pdcsata_chip_map,
100 },
101 { PCI_PRODUCT_PROMISE_PDC20378,
102 0,
103 "Promise PDC20378 SATA150 controller",
104 pdcsata_chip_map,
105 },
106 { PCI_PRODUCT_PROMISE_PDC20379,
107 0,
108 "Promise PDC20379 SATA150 controller",
109 pdcsata_chip_map,
110 },
111 { PCI_PRODUCT_PROMISE_PDC40718,
112 0,
113 "Promise PDC40718 SATA300 controller",
114 pdcsata_chip_map,
115 },
116 { PCI_PRODUCT_PROMISE_PDC40719,
117 0,
118 "Promise PDC40719 SATA300 controller",
119 pdcsata_chip_map,
120 },
121 { PCI_PRODUCT_PROMISE_PDC20571,
122 0,
123 "Promise PDC20571 SATA150 controller",
124 pdcsata_chip_map,
125 },
126 { PCI_PRODUCT_PROMISE_PDC20575,
127 0,
128 "Promise PDC20575 SATA150 controller",
129 pdcsata_chip_map,
130 },
131 { PCI_PRODUCT_PROMISE_PDC20579,
132 0,
133 "Promise PDC20579 SATA150 controller",
134 pdcsata_chip_map,
135 },
136 { 0,
137 0,
138 NULL,
139 NULL
140 }
141 };
142
143 static int
144 pdcsata_match(struct device *parent, struct cfdata *match, void *aux)
145 {
146 struct pci_attach_args *pa = aux;
147
148 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_PROMISE) {
149 if (pciide_lookup_product(pa->pa_id, pciide_pdcsata_products))
150 return (2);
151 }
152 return (0);
153 }
154
155 static void
156 pdcsata_attach(struct device *parent, struct device *self, void *aux)
157 {
158 struct pci_attach_args *pa = aux;
159 struct pciide_softc *sc = (struct pciide_softc *)self;
160
161 pciide_common_attach(sc, pa,
162 pciide_lookup_product(pa->pa_id, pciide_pdcsata_products));
163 }
164
165 static void
166 pdcsata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
167 {
168 struct pciide_channel *cp;
169 struct ata_channel *wdc_cp;
170 struct wdc_regs *wdr;
171 int channel, i;
172 bus_size_t dmasize;
173 pci_intr_handle_t intrhandle;
174 const char *intrstr;
175
176 /*
177 * Promise SATA controllers have 3 or 4 channels,
178 * the usual IDE registers are mapped in I/O space, with offsets.
179 */
180 if (pci_intr_map(pa, &intrhandle) != 0) {
181 aprint_error("%s: couldn't map interrupt\n",
182 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
183 return;
184 }
185 intrstr = pci_intr_string(pa->pa_pc, intrhandle);
186
187 switch (sc->sc_pp->ide_product) {
188 case PCI_PRODUCT_PROMISE_PDC20318:
189 case PCI_PRODUCT_PROMISE_PDC20319:
190 case PCI_PRODUCT_PROMISE_PDC20371:
191 case PCI_PRODUCT_PROMISE_PDC20375:
192 case PCI_PRODUCT_PROMISE_PDC20376:
193 case PCI_PRODUCT_PROMISE_PDC20377:
194 case PCI_PRODUCT_PROMISE_PDC20378:
195 case PCI_PRODUCT_PROMISE_PDC20379:
196 default:
197 sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
198 intrhandle, IPL_BIO, pdc203xx_pci_intr, sc);
199 break;
200
201 case PCI_PRODUCT_PROMISE_PDC40718:
202 case PCI_PRODUCT_PROMISE_PDC40719:
203 case PCI_PRODUCT_PROMISE_PDC20571:
204 case PCI_PRODUCT_PROMISE_PDC20575:
205 case PCI_PRODUCT_PROMISE_PDC20579:
206 sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
207 intrhandle, IPL_BIO, pdc205xx_pci_intr, sc);
208 break;
209 }
210
211 if (sc->sc_pci_ih == NULL) {
212 aprint_error("%s: couldn't establish native-PCI interrupt",
213 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
214 if (intrstr != NULL)
215 aprint_normal(" at %s", intrstr);
216 aprint_normal("\n");
217 return;
218 }
219 aprint_normal("%s: interrupting at %s\n",
220 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
221 intrstr ? intrstr : "unknown interrupt");
222
223 sc->sc_dma_ok = (pci_mapreg_map(pa, PCIIDE_REG_BUS_MASTER_DMA,
224 PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_dma_iot,
225 &sc->sc_dma_ioh, NULL, &dmasize) == 0);
226 if (!sc->sc_dma_ok) {
227 aprint_error("%s: couldn't map bus-master DMA registers\n",
228 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
229 pci_intr_disestablish(pa->pa_pc, sc->sc_pci_ih);
230 return;
231 }
232
233 sc->sc_dmat = pa->pa_dmat;
234
235 if (pci_mapreg_map(pa, PDC203xx_BAR_IDEREGS,
236 PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_ba5_st,
237 &sc->sc_ba5_sh, NULL, NULL) != 0) {
238 aprint_error("%s: couldn't map IDE registers\n",
239 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
240 bus_space_unmap(sc->sc_dma_iot, sc->sc_dma_ioh, dmasize);
241 pci_intr_disestablish(pa->pa_pc, sc->sc_pci_ih);
242 return;
243 }
244
245 aprint_normal("%s: bus-master DMA support present\n",
246 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
247 sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16;
248 if (sc->sc_dma_ok) {
249 sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
250 }
251 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
252 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
253 sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
254 sc->sc_wdcdev.irqack = pdc203xx_irqack;
255 sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
256 sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
257 sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
258 sc->sc_wdcdev.sc_atac.atac_set_modes = pdc203xx_setup_channel;
259 sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
260
261 switch (sc->sc_pp->ide_product) {
262 case PCI_PRODUCT_PROMISE_PDC20318:
263 case PCI_PRODUCT_PROMISE_PDC20319:
264 case PCI_PRODUCT_PROMISE_PDC20371:
265 case PCI_PRODUCT_PROMISE_PDC20375:
266 case PCI_PRODUCT_PROMISE_PDC20376:
267 case PCI_PRODUCT_PROMISE_PDC20377:
268 case PCI_PRODUCT_PROMISE_PDC20378:
269 case PCI_PRODUCT_PROMISE_PDC20379:
270 default:
271 bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x6c, 0x00ff0033);
272 sc->sc_wdcdev.sc_atac.atac_nchannels =
273 (bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x48) & 0x02) ?
274 PDC203xx_NCHANNELS : 3;
275
276 break;
277
278 case PCI_PRODUCT_PROMISE_PDC40718:
279 case PCI_PRODUCT_PROMISE_PDC40719:
280 case PCI_PRODUCT_PROMISE_PDC20571:
281 bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x60, 0x00ff00ff);
282 sc->sc_wdcdev.sc_atac.atac_nchannels = PDC40718_NCHANNELS;
283
284 sc->sc_wdcdev.reset = pdc205xx_do_reset;
285 sc->sc_wdcdev.sc_atac.atac_probe = pdc205xx_drv_probe;
286
287 break;
288 case PCI_PRODUCT_PROMISE_PDC20575:
289 case PCI_PRODUCT_PROMISE_PDC20579:
290 bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x60, 0x00ff00ff);
291 sc->sc_wdcdev.sc_atac.atac_nchannels = PDC20575_NCHANNELS;
292
293 sc->sc_wdcdev.reset = pdc205xx_do_reset;
294 sc->sc_wdcdev.sc_atac.atac_probe = pdc205xx_drv_probe;
295
296 break;
297 }
298
299 wdc_allocate_regs(&sc->sc_wdcdev);
300
301 sc->sc_wdcdev.dma_arg = sc;
302 sc->sc_wdcdev.dma_init = pdc203xx_dma_init;
303 sc->sc_wdcdev.dma_start = pdc203xx_dma_start;
304 sc->sc_wdcdev.dma_finish = pdc203xx_dma_finish;
305
306 for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
307 channel++) {
308 cp = &sc->pciide_channels[channel];
309 sc->wdc_chanarray[channel] = &cp->ata_channel;
310
311 cp->ih = sc->sc_pci_ih;
312 cp->name = NULL;
313 cp->ata_channel.ch_channel = channel;
314 cp->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
315 cp->ata_channel.ch_queue =
316 malloc(sizeof(struct ata_queue), M_DEVBUF, M_NOWAIT);
317 if (cp->ata_channel.ch_queue == NULL) {
318 aprint_error("%s channel %d: "
319 "can't allocate memory for command queue\n",
320 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, channel);
321 goto next_channel;
322 }
323 wdc_cp = &cp->ata_channel;
324 wdr = CHAN_TO_WDC_REGS(wdc_cp);
325
326 wdr->ctl_iot = sc->sc_ba5_st;
327 wdr->cmd_iot = sc->sc_ba5_st;
328
329 if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
330 0x0238 + (channel << 7), 1, &wdr->ctl_ioh) != 0) {
331 aprint_error("%s: couldn't map channel %d ctl regs\n",
332 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
333 channel);
334 goto next_channel;
335 }
336 for (i = 0; i < WDC_NREG; i++) {
337 if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
338 0x0200 + (i << 2) + (channel << 7), i == 0 ? 4 : 1,
339 &wdr->cmd_iohs[i]) != 0) {
340 aprint_error("%s: couldn't map channel %d cmd "
341 "regs\n",
342 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
343 channel);
344 goto next_channel;
345 }
346 }
347 wdc_init_shadow_regs(wdc_cp);
348
349 /*
350 * subregion de busmaster registers. They're spread all over
351 * the controller's register space :(. They are also 4 bytes
352 * sized, with some specific extentions in the extra bits.
353 * It also seems that the IDEDMA_CTL register isn't available.
354 */
355 if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
356 0x260 + (channel << 7), 1,
357 &cp->dma_iohs[IDEDMA_CMD]) != 0) {
358 aprint_normal("%s channel %d: can't subregion DMA "
359 "registers\n",
360 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, channel);
361 goto next_channel;
362 }
363 if (bus_space_subregion(sc->sc_ba5_st, sc->sc_ba5_sh,
364 0x244 + (channel << 7), 4,
365 &cp->dma_iohs[IDEDMA_TBL]) != 0) {
366 aprint_normal("%s channel %d: can't subregion DMA "
367 "registers\n",
368 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, channel);
369 goto next_channel;
370 }
371
372 wdcattach(wdc_cp);
373 bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
374 (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
375 0) & ~0x00003f9f) | (channel + 1));
376 bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh,
377 (channel + 1) << 2, 0x00000001);
378 next_channel:
379 continue;
380 }
381 return;
382 }
383
384 static void
385 pdc203xx_setup_channel(struct ata_channel *chp)
386 {
387 struct ata_drive_datas *drvp;
388 int drive, s;
389 struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
390
391 pciide_channel_dma_setup(cp);
392
393 for (drive = 0; drive < 2; drive++) {
394 drvp = &chp->ch_drive[drive];
395 if ((drvp->drive_flags & DRIVE) == 0)
396 continue;
397 if (drvp->drive_flags & DRIVE_UDMA) {
398 s = splbio();
399 drvp->drive_flags &= ~DRIVE_DMA;
400 splx(s);
401 }
402 }
403 }
404
405 static int
406 pdc203xx_pci_intr(void *arg)
407 {
408 struct pciide_softc *sc = arg;
409 struct pciide_channel *cp;
410 struct ata_channel *wdc_cp;
411 int i, rv, crv;
412 u_int32_t scr;
413
414 rv = 0;
415 scr = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x00040);
416
417 for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
418 cp = &sc->pciide_channels[i];
419 wdc_cp = &cp->ata_channel;
420 if (scr & (1 << (i + 1))) {
421 crv = wdcintr(wdc_cp);
422 if (crv == 0) {
423 printf("%s:%d: bogus intr (reg 0x%x)\n",
424 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
425 i, scr);
426 } else
427 rv = 1;
428 }
429 }
430 return rv;
431 }
432
433 static int
434 pdc205xx_pci_intr(void *arg)
435 {
436 struct pciide_softc *sc = arg;
437 struct pciide_channel *cp;
438 struct ata_channel *wdc_cp;
439 int i, rv, crv;
440 u_int32_t scr, status;
441
442 rv = 0;
443 scr = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x40);
444 bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x40, scr & 0x0000ffff);
445
446 status = bus_space_read_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x60);
447 bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh, 0x60, status & 0x000000ff);
448
449 for (i = 0; i < sc->sc_wdcdev.sc_atac.atac_nchannels; i++) {
450 cp = &sc->pciide_channels[i];
451 wdc_cp = &cp->ata_channel;
452 if (scr & (1 << (i + 1))) {
453 crv = wdcintr(wdc_cp);
454 if (crv == 0) {
455 printf("%s:%d: bogus intr (reg 0x%x)\n",
456 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname,
457 i, scr);
458 } else
459 rv = 1;
460 }
461 }
462 return rv;
463 }
464
465 static void
466 pdc203xx_irqack(struct ata_channel *chp)
467 {
468 struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
469 struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
470
471 bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
472 (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
473 0) & ~0x00003f9f) | (cp->ata_channel.ch_channel + 1));
474 bus_space_write_4(sc->sc_ba5_st, sc->sc_ba5_sh,
475 (cp->ata_channel.ch_channel + 1) << 2, 0x00000001);
476 }
477
478 static int
479 pdc203xx_dma_init(void *v, int channel, int drive, void *databuf,
480 size_t datalen, int flags)
481 {
482 struct pciide_softc *sc = v;
483
484 return pciide_dma_dmamap_setup(sc, channel, drive,
485 databuf, datalen, flags);
486 }
487
488 static void
489 pdc203xx_dma_start(void *v, int channel, int drive)
490 {
491 struct pciide_softc *sc = v;
492 struct pciide_channel *cp = &sc->pciide_channels[channel];
493 struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
494
495 /* Write table addr */
496 bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_TBL], 0,
497 dma_maps->dmamap_table->dm_segs[0].ds_addr);
498 /* start DMA engine */
499 bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
500 (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
501 0) & ~0xc0) | ((dma_maps->dma_flags & WDC_DMA_READ) ? 0x80 : 0xc0));
502 }
503
504 static int
505 pdc203xx_dma_finish(void *v, int channel, int drive, int force)
506 {
507 struct pciide_softc *sc = v;
508 struct pciide_channel *cp = &sc->pciide_channels[channel];
509 struct pciide_dma_maps *dma_maps = &cp->dma_maps[drive];
510
511 /* stop DMA channel */
512 bus_space_write_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD], 0,
513 (bus_space_read_4(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CMD],
514 0) & ~0x80));
515
516 /* Unload the map of the data buffer */
517 bus_dmamap_sync(sc->sc_dmat, dma_maps->dmamap_xfer, 0,
518 dma_maps->dmamap_xfer->dm_mapsize,
519 (dma_maps->dma_flags & WDC_DMA_READ) ?
520 BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
521 bus_dmamap_unload(sc->sc_dmat, dma_maps->dmamap_xfer);
522
523 return 0;
524 }
525
526 #define PDC205_REGADDR(base,ch) ((base)+((ch)<<8))
527 #define PDC205_SSTATUS(ch) PDC205_REGADDR(0x400,ch)
528 #define PDC205_SERROR(ch) PDC205_REGADDR(0x404,ch)
529 #define PDC205_SCONTROL(ch) PDC205_REGADDR(0x408,ch)
530 #define PDC205_MULTIPLIER(ch) PDC205_REGADDR(0x4e8,ch)
531
532
533 #define SCONTROL_WRITE(sc,channel,scontrol) \
534 bus_space_write_4((sc)->sc_ba5_st, (sc)->sc_ba5_sh, \
535 PDC205_SCONTROL(channel), scontrol)
536
537 #define SSTATUS_READ(sc,channel) \
538 bus_space_read_4((sc)->sc_ba5_st, (sc)->sc_ba5_sh, \
539 PDC205_SSTATUS(channel))
540
541
542
543 static void
544 pdc205xx_do_reset(struct ata_channel *chp, int poll)
545 {
546 struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
547 u_int32_t scontrol;
548
549 wdc_do_reset(chp, poll);
550
551 /* reset SATA */
552 scontrol = SControl_DET_INIT | SControl_SPD_ANY | SControl_IPM_NONE;
553 SCONTROL_WRITE(sc, chp->ch_channel, scontrol);
554 delay(50*1000);
555
556 scontrol &= ~SControl_DET_INIT;
557 SCONTROL_WRITE(sc, chp->ch_channel, scontrol);
558 delay(50*1000);
559 }
560
561
562
563 static void
564 pdc205xx_drv_probe(struct ata_channel *chp)
565 {
566 struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
567 struct wdc_regs *wdr = CHAN_TO_WDC_REGS(chp);
568 u_int32_t scontrol, sstatus;
569 u_int16_t scnt, sn, cl, ch;
570 int i, s;
571
572 /* XXX This should be done by other code. */
573 for (i = 0; i < 2; i++) {
574 chp->ch_drive[i].chnl_softc = chp;
575 chp->ch_drive[i].drive = i;
576 }
577
578 SCONTROL_WRITE(sc, chp->ch_channel, 0);
579 delay(50*1000);
580
581 scontrol = SControl_DET_INIT | SControl_SPD_ANY | SControl_IPM_NONE;
582 SCONTROL_WRITE(sc,chp->ch_channel,scontrol);
583 delay(50*1000);
584
585 scontrol &= ~SControl_DET_INIT;
586 SCONTROL_WRITE(sc,chp->ch_channel,scontrol);
587 delay(50*1000);
588
589 sstatus = SSTATUS_READ(sc,chp->ch_channel);
590
591 switch (sstatus & SStatus_DET_mask) {
592 case SStatus_DET_NODEV:
593 /* No Device; be silent. */
594 break;
595
596 case SStatus_DET_DEV_NE:
597 aprint_error("%s: port %d: device connected, but "
598 "communication not established\n",
599 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, chp->ch_channel);
600 break;
601
602 case SStatus_DET_OFFLINE:
603 aprint_error("%s: port %d: PHY offline\n",
604 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, chp->ch_channel);
605 break;
606
607 case SStatus_DET_DEV:
608 bus_space_write_1(wdr->cmd_iot, wdr->cmd_iohs[wd_sdh], 0,
609 WDSD_IBM);
610 delay(10); /* 400ns delay */
611 scnt = bus_space_read_2(wdr->cmd_iot,
612 wdr->cmd_iohs[wd_seccnt], 0);
613 sn = bus_space_read_2(wdr->cmd_iot,
614 wdr->cmd_iohs[wd_sector], 0);
615 cl = bus_space_read_2(wdr->cmd_iot,
616 wdr->cmd_iohs[wd_cyl_lo], 0);
617 ch = bus_space_read_2(wdr->cmd_iot,
618 wdr->cmd_iohs[wd_cyl_hi], 0);
619 #if 0
620 printf("%s: port %d: scnt=0x%x sn=0x%x cl=0x%x ch=0x%x\n",
621 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, chp->ch_channel,
622 scnt, sn, cl, ch);
623 #endif
624 /*
625 * scnt and sn are supposed to be 0x1 for ATAPI, but in some
626 * cases we get wrong values here, so ignore it.
627 */
628 s = splbio();
629 if (cl == 0x14 && ch == 0xeb)
630 chp->ch_drive[0].drive_flags |= DRIVE_ATAPI;
631 else
632 chp->ch_drive[0].drive_flags |= DRIVE_ATA;
633 splx(s);
634 #if 0
635 aprint_normal("%s: port %d: device present, speed: %s\n",
636 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, chp->ch_channel,
637 sata_speed(sstatus));
638 #endif
639 break;
640
641 default:
642 aprint_error("%s: port %d: unknown SStatus: 0x%08x\n",
643 sc->sc_wdcdev.sc_atac.atac_dev.dv_xname, chp->ch_channel,
644 sstatus);
645 }
646 }
647