Home | History | Annotate | Line # | Download | only in pci
slide.c revision 1.20.22.2
      1  1.20.22.1     rmind /*	$NetBSD: slide.c,v 1.20.22.2 2011/04/21 01:42:01 rmind Exp $	*/
      2        1.1    bouyer 
      3        1.1    bouyer /*-
      4        1.1    bouyer  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5        1.1    bouyer  * All rights reserved.
      6        1.1    bouyer  *
      7        1.1    bouyer  * This code is derived from software contributed to The NetBSD Foundation
      8        1.1    bouyer  * by Jason R. Thorpe.
      9        1.1    bouyer  *
     10        1.1    bouyer  * Redistribution and use in source and binary forms, with or without
     11        1.1    bouyer  * modification, are permitted provided that the following conditions
     12        1.1    bouyer  * are met:
     13        1.1    bouyer  * 1. Redistributions of source code must retain the above copyright
     14        1.1    bouyer  *    notice, this list of conditions and the following disclaimer.
     15        1.1    bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1    bouyer  *    notice, this list of conditions and the following disclaimer in the
     17        1.1    bouyer  *    documentation and/or other materials provided with the distribution.
     18        1.1    bouyer  *
     19        1.1    bouyer  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1    bouyer  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1    bouyer  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1    bouyer  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1    bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1    bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1    bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1    bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1    bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1    bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1    bouyer  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1    bouyer  */
     31        1.1    bouyer 
     32       1.11     lukem #include <sys/cdefs.h>
     33  1.20.22.1     rmind __KERNEL_RCSID(0, "$NetBSD: slide.c,v 1.20.22.2 2011/04/21 01:42:01 rmind Exp $");
     34       1.11     lukem 
     35        1.1    bouyer #include <sys/param.h>
     36        1.1    bouyer #include <sys/systm.h>
     37        1.1    bouyer 
     38        1.1    bouyer #include <dev/pci/pcivar.h>
     39        1.1    bouyer #include <dev/pci/pcidevs.h>
     40        1.1    bouyer #include <dev/pci/pciidereg.h>
     41        1.1    bouyer #include <dev/pci/pciidevar.h>
     42        1.1    bouyer #include <dev/pci/pciide_sl82c105_reg.h>
     43        1.1    bouyer 
     44  1.20.22.2     rmind static void sl82c105_chip_map(struct pciide_softc*,
     45  1.20.22.2     rmind     const struct pci_attach_args*);
     46        1.6   thorpej static void sl82c105_setup_channel(struct ata_channel*);
     47        1.1    bouyer 
     48       1.19      cube static int  slide_match(device_t, cfdata_t, void *);
     49       1.19      cube static void slide_attach(device_t, device_t, void *);
     50        1.1    bouyer 
     51       1.19      cube CFATTACH_DECL_NEW(slide, sizeof(struct pciide_softc),
     52        1.1    bouyer     slide_match, slide_attach, NULL, NULL);
     53        1.1    bouyer 
     54        1.2   thorpej static const struct pciide_product_desc pciide_symphony_products[] = {
     55        1.1    bouyer 	{ PCI_PRODUCT_SYMPHONY_82C105,
     56        1.1    bouyer 	  0,
     57        1.1    bouyer 	  "Symphony Labs 82C105 IDE controller",
     58        1.1    bouyer 	  sl82c105_chip_map,
     59        1.1    bouyer 	},
     60        1.1    bouyer 	{ 0,
     61        1.1    bouyer 	  0,
     62        1.1    bouyer 	  NULL,
     63       1.13  christos 	  NULL,
     64        1.1    bouyer 	}
     65        1.1    bouyer };
     66        1.1    bouyer 
     67        1.2   thorpej static const struct pciide_product_desc pciide_winbond_products[] =  {
     68        1.1    bouyer 	{ PCI_PRODUCT_WINBOND_W83C553F_1,
     69        1.1    bouyer 	  0,
     70        1.1    bouyer 	  "Winbond W83C553F IDE controller",
     71        1.1    bouyer 	  sl82c105_chip_map,
     72        1.1    bouyer 	},
     73        1.1    bouyer 	{ 0,
     74        1.1    bouyer 	  0,
     75        1.1    bouyer 	  NULL,
     76       1.13  christos 	  NULL,
     77        1.1    bouyer 	}
     78        1.1    bouyer };
     79        1.1    bouyer 
     80        1.2   thorpej static int
     81       1.19      cube slide_match(device_t parent, cfdata_t match, void *aux)
     82        1.1    bouyer {
     83        1.1    bouyer 	struct pci_attach_args *pa = aux;
     84        1.1    bouyer 
     85        1.1    bouyer 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SYMPHONY) {
     86        1.1    bouyer 		if (pciide_lookup_product(pa->pa_id, pciide_symphony_products))
     87        1.1    bouyer 			return (2);
     88        1.1    bouyer 	}
     89        1.1    bouyer 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_WINBOND) {
     90        1.1    bouyer 		if (pciide_lookup_product(pa->pa_id, pciide_winbond_products))
     91        1.1    bouyer 			return (2);
     92        1.1    bouyer 	}
     93        1.1    bouyer 	return (0);
     94        1.1    bouyer }
     95        1.1    bouyer 
     96        1.2   thorpej static void
     97       1.19      cube slide_attach(device_t parent, device_t self, void *aux)
     98        1.1    bouyer {
     99        1.1    bouyer 	struct pci_attach_args *pa = aux;
    100       1.19      cube 	struct pciide_softc *sc = device_private(self);
    101        1.1    bouyer 	const struct pciide_product_desc *pp = NULL;
    102        1.1    bouyer 
    103       1.19      cube 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    104       1.19      cube 
    105        1.1    bouyer 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SYMPHONY)
    106        1.1    bouyer 		pp = pciide_lookup_product(pa->pa_id, pciide_symphony_products);
    107        1.1    bouyer 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_WINBOND)
    108        1.1    bouyer 		pp = pciide_lookup_product(pa->pa_id, pciide_winbond_products);
    109        1.1    bouyer 	if (pp == NULL)
    110        1.1    bouyer 		panic("slide_attach");
    111        1.1    bouyer 	pciide_common_attach(sc, pa, pp);
    112        1.1    bouyer }
    113        1.1    bouyer 
    114        1.1    bouyer static int
    115  1.20.22.2     rmind sl82c105_bugchk(const struct pci_attach_args *pa)
    116        1.1    bouyer {
    117        1.1    bouyer 
    118        1.1    bouyer 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_WINBOND ||
    119        1.1    bouyer 	    PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_WINBOND_W83C553F_0)
    120        1.1    bouyer 		return (0);
    121        1.1    bouyer 
    122        1.1    bouyer 	if (PCI_REVISION(pa->pa_class) <= 0x05)
    123        1.1    bouyer 		return (1);
    124        1.1    bouyer 
    125        1.1    bouyer 	return (0);
    126        1.1    bouyer }
    127        1.1    bouyer 
    128        1.2   thorpej static void
    129  1.20.22.2     rmind sl82c105_chip_map(struct pciide_softc *sc, const struct pci_attach_args *pa)
    130        1.1    bouyer {
    131  1.20.22.2     rmind 	struct pci_attach_args pa0;
    132        1.1    bouyer 	struct pciide_channel *cp;
    133        1.1    bouyer 	pcireg_t interface, idecr;
    134        1.1    bouyer 	int channel;
    135        1.1    bouyer 
    136        1.1    bouyer 	if (pciide_chipen(sc, pa) == 0)
    137        1.1    bouyer 		return;
    138        1.1    bouyer 
    139       1.19      cube 	aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    140       1.19      cube 	    "bus-master DMA support present");
    141        1.1    bouyer 
    142        1.1    bouyer 	/*
    143        1.1    bouyer 	 * Check to see if we're part of the Winbond 83c553 Southbridge.
    144        1.1    bouyer 	 * If so, we need to disable DMA on rev. <= 5 of that chip.
    145        1.1    bouyer 	 */
    146  1.20.22.2     rmind 	if (pci_find_device(&pa0, sl82c105_bugchk)) {
    147  1.20.22.2     rmind 		pa = &pa0;
    148       1.16        ad 		aprint_verbose(" but disabled due to 83c553 rev. <= 0x05");
    149        1.1    bouyer 		sc->sc_dma_ok = 0;
    150        1.1    bouyer 	} else
    151        1.1    bouyer 		pciide_mapreg_dma(sc, pa);
    152       1.16        ad 	aprint_verbose("\n");
    153        1.1    bouyer 
    154        1.8   thorpej 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA32 | ATAC_CAP_DATA16;
    155        1.8   thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    156        1.1    bouyer 	if (sc->sc_dma_ok) {
    157        1.8   thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
    158        1.1    bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    159        1.8   thorpej 		sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    160        1.1    bouyer 	}
    161        1.8   thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = sl82c105_setup_channel;
    162        1.1    bouyer 
    163        1.8   thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    164        1.8   thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    165        1.1    bouyer 
    166        1.1    bouyer 	idecr = pci_conf_read(sc->sc_pc, sc->sc_tag, SYMPH_IDECSR);
    167        1.1    bouyer 
    168        1.1    bouyer 	interface = PCI_INTERFACE(pa->pa_class);
    169        1.1    bouyer 
    170        1.6   thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    171        1.6   thorpej 
    172        1.8   thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    173        1.8   thorpej 	     channel++) {
    174        1.1    bouyer 		cp = &sc->pciide_channels[channel];
    175       1.10     perry 		if (pciide_chansetup(sc, channel, interface) == 0)
    176        1.1    bouyer 			continue;
    177        1.1    bouyer 		if ((channel == 0 && (idecr & IDECR_P0EN) == 0) ||
    178        1.1    bouyer 		    (channel == 1 && (idecr & IDECR_P1EN) == 0)) {
    179       1.19      cube 			aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
    180       1.19      cube 			    "%s channel ignored (disabled)\n", cp->name);
    181        1.6   thorpej 			cp->ata_channel.ch_flags |= ATACH_DISABLED;
    182        1.1    bouyer 			continue;
    183        1.1    bouyer 		}
    184  1.20.22.1     rmind 		pciide_mapchan(pa, cp, interface, pciide_pci_intr);
    185        1.1    bouyer 	}
    186        1.1    bouyer }
    187        1.1    bouyer 
    188        1.2   thorpej static void
    189        1.6   thorpej sl82c105_setup_channel(struct ata_channel *chp)
    190        1.1    bouyer {
    191        1.1    bouyer 	struct ata_drive_datas *drvp;
    192        1.7   thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    193        1.7   thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    194        1.9   thorpej 	int pxdx_reg, drive, s;
    195        1.1    bouyer 	pcireg_t pxdx;
    196        1.1    bouyer 
    197        1.1    bouyer 	/* Set up DMA if needed. */
    198        1.1    bouyer 	pciide_channel_dma_setup(cp);
    199        1.1    bouyer 
    200        1.1    bouyer 	for (drive = 0; drive < 2; drive++) {
    201        1.4   thorpej 		pxdx_reg = ((chp->ch_channel == 0) ? SYMPH_P0D0CR
    202        1.4   thorpej 						   : SYMPH_P1D0CR) +
    203        1.4   thorpej 			    (drive * 4);
    204        1.1    bouyer 
    205        1.1    bouyer 		pxdx = pci_conf_read(sc->sc_pc, sc->sc_tag, pxdx_reg);
    206        1.1    bouyer 
    207        1.1    bouyer 		pxdx &= ~(PxDx_CMD_ON_MASK|PxDx_CMD_OFF_MASK);
    208        1.1    bouyer 		pxdx &= ~(PxDx_PWEN|PxDx_RDYEN|PxDx_RAEN);
    209        1.1    bouyer 
    210        1.1    bouyer 		drvp = &chp->ch_drive[drive];
    211        1.1    bouyer 		/* If no drive, skip. */
    212        1.1    bouyer 		if ((drvp->drive_flags & DRIVE) == 0) {
    213        1.1    bouyer 			pci_conf_write(sc->sc_pc, sc->sc_tag, pxdx_reg, pxdx);
    214        1.1    bouyer 			continue;
    215        1.1    bouyer 		}
    216        1.1    bouyer 
    217        1.1    bouyer 		if (drvp->drive_flags & DRIVE_DMA) {
    218        1.1    bouyer 			/*
    219        1.1    bouyer 			 * Timings will be used for both PIO and DMA,
    220        1.1    bouyer 			 * so adjust DMA mode if needed.
    221        1.1    bouyer 			 */
    222        1.1    bouyer 			if (drvp->PIO_mode >= 3) {
    223        1.1    bouyer 				if ((drvp->DMA_mode + 2) > drvp->PIO_mode)
    224        1.1    bouyer 					drvp->DMA_mode = drvp->PIO_mode - 2;
    225        1.1    bouyer 				if (drvp->DMA_mode < 1) {
    226        1.1    bouyer 					/*
    227        1.1    bouyer 					 * Can't mix both PIO and DMA.
    228        1.1    bouyer 					 * Disable DMA.
    229        1.1    bouyer 					 */
    230        1.9   thorpej 					s = splbio();
    231        1.1    bouyer 					drvp->drive_flags &= ~DRIVE_DMA;
    232        1.9   thorpej 					splx(s);
    233        1.1    bouyer 				}
    234        1.1    bouyer 			} else {
    235        1.1    bouyer 				/*
    236        1.1    bouyer 				 * Can't mix both PIO and DMA.  Disable
    237        1.1    bouyer 				 * DMA.
    238        1.1    bouyer 				 */
    239        1.9   thorpej 				s = splbio();
    240        1.1    bouyer 				drvp->drive_flags &= ~DRIVE_DMA;
    241        1.9   thorpej 				splx(s);
    242        1.1    bouyer 			}
    243        1.1    bouyer 		}
    244        1.1    bouyer 
    245        1.1    bouyer 		if (drvp->drive_flags & DRIVE_DMA) {
    246        1.1    bouyer 			/* Use multi-word DMA. */
    247        1.1    bouyer 			pxdx |= symph_mw_dma_times[drvp->DMA_mode].cmd_on <<
    248        1.1    bouyer 			    PxDx_CMD_ON_SHIFT;
    249        1.1    bouyer 			pxdx |= symph_mw_dma_times[drvp->DMA_mode].cmd_off;
    250        1.1    bouyer 		} else {
    251        1.1    bouyer 			pxdx |= symph_pio_times[drvp->PIO_mode].cmd_on <<
    252        1.1    bouyer 			    PxDx_CMD_ON_SHIFT;
    253        1.1    bouyer 			pxdx |= symph_pio_times[drvp->PIO_mode].cmd_off;
    254        1.1    bouyer 		}
    255        1.1    bouyer 
    256        1.1    bouyer 		/* XXX PxDx_PWEN? PxDx_RDYEN? PxDx_RAEN? */
    257        1.1    bouyer 
    258        1.1    bouyer 		/* ...and set the mode for this drive. */
    259        1.1    bouyer 		pci_conf_write(sc->sc_pc, sc->sc_tag, pxdx_reg, pxdx);
    260        1.1    bouyer 	}
    261        1.1    bouyer }
    262