Home | History | Annotate | Line # | Download | only in pci
geodeide.c revision 1.7
      1  1.7  thorpej /*	$NetBSD: geodeide.c,v 1.7 2004/08/21 00:28:34 thorpej Exp $	*/
      2  1.1   bouyer 
      3  1.1   bouyer /*
      4  1.1   bouyer  * Copyright (c) 2004 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  * 3. All advertising materials mentioning features or use of this software
     15  1.1   bouyer  *    must display the following acknowledgement:
     16  1.1   bouyer  *	This product includes software developed by Manuel Bouyer.
     17  1.1   bouyer  * 4. The name of the author may not be used to endorse or promote products
     18  1.1   bouyer  *    derived from this software without specific prior written permission.
     19  1.1   bouyer  *
     20  1.1   bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1   bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1   bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1   bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1   bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1   bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1   bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1   bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1   bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1   bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1   bouyer  *
     31  1.1   bouyer  */
     32  1.1   bouyer 
     33  1.1   bouyer /*
     34  1.2   rumble  * Driver for the IDE part of the AMD Geode CS5530A companion chip
     35  1.2   rumble  * and AMD Geode SC1100.
     36  1.1   bouyer  * Docs available from AMD's web site
     37  1.1   bouyer  */
     38  1.1   bouyer 
     39  1.1   bouyer #include <sys/cdefs.h>
     40  1.7  thorpej __KERNEL_RCSID(0, "$NetBSD: geodeide.c,v 1.7 2004/08/21 00:28:34 thorpej Exp $");
     41  1.1   bouyer 
     42  1.1   bouyer #include <sys/param.h>
     43  1.1   bouyer #include <sys/systm.h>
     44  1.1   bouyer 
     45  1.2   rumble #include <uvm/uvm_extern.h>
     46  1.2   rumble 
     47  1.1   bouyer #include <dev/pci/pcivar.h>
     48  1.1   bouyer #include <dev/pci/pcidevs.h>
     49  1.1   bouyer #include <dev/pci/pciidereg.h>
     50  1.1   bouyer #include <dev/pci/pciidevar.h>
     51  1.1   bouyer 
     52  1.1   bouyer #include <dev/pci/pciide_geode_reg.h>
     53  1.1   bouyer 
     54  1.1   bouyer static void geodeide_chip_map(struct pciide_softc *,
     55  1.1   bouyer 				 struct pci_attach_args *);
     56  1.4  thorpej static void geodeide_setup_channel(struct ata_channel *);
     57  1.1   bouyer 
     58  1.1   bouyer static int  geodeide_match(struct device *, struct cfdata *, void *);
     59  1.1   bouyer static void geodeide_attach(struct device *, struct device *, void *);
     60  1.1   bouyer 
     61  1.1   bouyer CFATTACH_DECL(geodeide, sizeof(struct pciide_softc),
     62  1.1   bouyer     geodeide_match, geodeide_attach, NULL, NULL);
     63  1.1   bouyer 
     64  1.1   bouyer static const struct pciide_product_desc pciide_geode_products[] = {
     65  1.1   bouyer 	{ PCI_PRODUCT_CYRIX_CX5530_IDE,
     66  1.1   bouyer 	  0,
     67  1.1   bouyer 	  "AMD Geode CX5530 IDE controller",
     68  1.1   bouyer 	  geodeide_chip_map,
     69  1.1   bouyer 	},
     70  1.2   rumble 	{ PCI_PRODUCT_NS_SC1100_IDE,
     71  1.2   rumble 	  0,
     72  1.2   rumble 	  "AMD Geode SC1100 IDE controller",
     73  1.2   rumble 	  geodeide_chip_map,
     74  1.2   rumble 	},
     75  1.1   bouyer 	{ 0,
     76  1.1   bouyer 	  0,
     77  1.1   bouyer 	  NULL,
     78  1.1   bouyer 	  NULL,
     79  1.1   bouyer 	},
     80  1.1   bouyer };
     81  1.1   bouyer 
     82  1.1   bouyer static int
     83  1.1   bouyer geodeide_match(struct device *parent, struct cfdata *match, void *aux)
     84  1.1   bouyer {
     85  1.1   bouyer 	struct pci_attach_args *pa = aux;
     86  1.1   bouyer 
     87  1.2   rumble 	if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CYRIX ||
     88  1.2   rumble 	     PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NS) &&
     89  1.2   rumble 	     PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
     90  1.2   rumble 	     PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_IDE &&
     91  1.2   rumble 	     pciide_lookup_product(pa->pa_id, pciide_geode_products))
     92  1.1   bouyer 		return(2);
     93  1.1   bouyer 	return (0);
     94  1.1   bouyer }
     95  1.1   bouyer 
     96  1.1   bouyer static void
     97  1.1   bouyer geodeide_attach(struct device *parent, struct device *self, void *aux)
     98  1.1   bouyer {
     99  1.1   bouyer 	struct pci_attach_args *pa = aux;
    100  1.1   bouyer 	struct pciide_softc *sc = (void *)self;
    101  1.1   bouyer 
    102  1.1   bouyer 	pciide_common_attach(sc, pa,
    103  1.1   bouyer 	    pciide_lookup_product(pa->pa_id, pciide_geode_products));
    104  1.1   bouyer }
    105  1.1   bouyer 
    106  1.1   bouyer static void
    107  1.1   bouyer geodeide_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
    108  1.1   bouyer {
    109  1.1   bouyer 	struct pciide_channel *cp;
    110  1.1   bouyer 	int channel;
    111  1.1   bouyer 	bus_size_t cmdsize, ctlsize;
    112  1.1   bouyer 
    113  1.1   bouyer 	if (pciide_chipen(sc, pa) == 0)
    114  1.1   bouyer 		return;
    115  1.1   bouyer 
    116  1.1   bouyer 	aprint_normal("%s: bus-master DMA support present",
    117  1.6  thorpej 	    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    118  1.1   bouyer 	pciide_mapreg_dma(sc, pa);
    119  1.1   bouyer 	aprint_normal("\n");
    120  1.1   bouyer 	if (sc->sc_dma_ok) {
    121  1.6  thorpej 		sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DMA | ATAC_CAP_UDMA;
    122  1.1   bouyer 		sc->sc_wdcdev.irqack = pciide_irqack;
    123  1.1   bouyer 	}
    124  1.6  thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
    125  1.6  thorpej 	sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
    126  1.6  thorpej 	sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
    127  1.6  thorpej 	sc->sc_wdcdev.sc_atac.atac_set_modes = geodeide_setup_channel;
    128  1.6  thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    129  1.6  thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
    130  1.6  thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
    131  1.1   bouyer 
    132  1.2   rumble 	/*
    133  1.2   rumble 	 * Soekris Engineering Issue #0003:
    134  1.2   rumble 	 * 	"The SC1100 built in busmaster IDE controller is pretty
    135  1.2   rumble 	 *	 standard, but have two bugs: data transfers need to be
    136  1.2   rumble 	 *	 dword aligned and it cannot do an exact 64Kbyte data
    137  1.2   rumble 	 *	 transfer."
    138  1.2   rumble 	 */
    139  1.2   rumble 	if (sc->sc_pp->ide_product == PCI_PRODUCT_NS_SC1100_IDE) {
    140  1.2   rumble 		if (sc->sc_dma_boundary == 0x10000)
    141  1.2   rumble 			sc->sc_dma_boundary -= PAGE_SIZE;
    142  1.2   rumble 
    143  1.2   rumble 		if (sc->sc_dma_maxsegsz == 0x10000)
    144  1.2   rumble 			sc->sc_dma_maxsegsz -= PAGE_SIZE;
    145  1.2   rumble 	}
    146  1.2   rumble 
    147  1.4  thorpej 	wdc_allocate_regs(&sc->sc_wdcdev);
    148  1.4  thorpej 
    149  1.6  thorpej 	for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
    150  1.6  thorpej 	     channel++) {
    151  1.1   bouyer 		cp = &sc->pciide_channels[channel];
    152  1.1   bouyer 		/* controller is compat-only */
    153  1.1   bouyer 		if (pciide_chansetup(sc, channel, 0) == 0)
    154  1.1   bouyer 			continue;
    155  1.1   bouyer 		pciide_mapchan(pa, cp, 0, &cmdsize, &ctlsize, pciide_pci_intr);
    156  1.1   bouyer 	}
    157  1.1   bouyer }
    158  1.1   bouyer 
    159  1.1   bouyer static void
    160  1.4  thorpej geodeide_setup_channel(struct ata_channel *chp)
    161  1.1   bouyer {
    162  1.1   bouyer 	struct ata_drive_datas *drvp;
    163  1.5  thorpej 	struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
    164  1.5  thorpej 	struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
    165  1.1   bouyer 	int channel = chp->ch_channel;
    166  1.7  thorpej 	int drive, s;
    167  1.1   bouyer 	u_int32_t dma_timing;
    168  1.1   bouyer 	u_int8_t idedma_ctl;
    169  1.2   rumble 	const int32_t *geode_pio;
    170  1.2   rumble 	const int32_t *geode_dma;
    171  1.2   rumble 	const int32_t *geode_udma;
    172  1.2   rumble 	bus_size_t dmaoff, piooff;
    173  1.2   rumble 
    174  1.2   rumble 	switch (sc->sc_pp->ide_product) {
    175  1.2   rumble 	case PCI_PRODUCT_CYRIX_CX5530_IDE:
    176  1.2   rumble 		geode_pio = geode_cs5530_pio;
    177  1.2   rumble 		geode_dma = geode_cs5530_dma;
    178  1.2   rumble 		geode_udma = geode_cs5530_udma;
    179  1.2   rumble 		break;
    180  1.2   rumble 
    181  1.2   rumble 	case PCI_PRODUCT_NS_SC1100_IDE:
    182  1.2   rumble 	default: /* XXX gcc */
    183  1.2   rumble 		geode_pio = geode_sc1100_pio;
    184  1.2   rumble 		geode_dma = geode_sc1100_dma;
    185  1.2   rumble 		geode_udma = geode_sc1100_udma;
    186  1.2   rumble 		break;
    187  1.2   rumble 	}
    188  1.1   bouyer 
    189  1.1   bouyer 	/* setup DMA if needed */
    190  1.1   bouyer 	pciide_channel_dma_setup(cp);
    191  1.1   bouyer 
    192  1.1   bouyer 	idedma_ctl = 0;
    193  1.1   bouyer 
    194  1.1   bouyer 	/* Per drive settings */
    195  1.1   bouyer 	for (drive = 0; drive < 2; drive++) {
    196  1.1   bouyer 		drvp = &chp->ch_drive[drive];
    197  1.1   bouyer 		/* If no drive, skip */
    198  1.1   bouyer 		if ((drvp->drive_flags & DRIVE) == 0)
    199  1.1   bouyer 			continue;
    200  1.2   rumble 
    201  1.2   rumble 		switch (sc->sc_pp->ide_product) {
    202  1.2   rumble 		case PCI_PRODUCT_CYRIX_CX5530_IDE:
    203  1.2   rumble 			dmaoff = CS5530_DMA_REG(channel, drive);
    204  1.2   rumble 			piooff = CS5530_PIO_REG(channel, drive);
    205  1.2   rumble 			dma_timing = CS5530_DMA_REG_PIO_FORMAT;
    206  1.2   rumble 			break;
    207  1.2   rumble 
    208  1.2   rumble 		case PCI_PRODUCT_NS_SC1100_IDE:
    209  1.2   rumble 		default: /* XXX gcc */
    210  1.2   rumble 			dmaoff = SC1100_DMA_REG(channel, drive);
    211  1.2   rumble 			piooff = SC1100_PIO_REG(channel, drive);
    212  1.2   rumble 			dma_timing = 0;
    213  1.2   rumble 			break;
    214  1.2   rumble 		}
    215  1.2   rumble 
    216  1.1   bouyer 		/* add timing values, setup DMA if needed */
    217  1.1   bouyer 		if (drvp->drive_flags & DRIVE_UDMA) {
    218  1.1   bouyer 			/* Use Ultra-DMA */
    219  1.1   bouyer 			dma_timing |= geode_udma[drvp->UDMA_mode];
    220  1.1   bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    221  1.1   bouyer 		} else if (drvp->drive_flags & DRIVE_DMA) {
    222  1.1   bouyer 			/* use Multiword DMA */
    223  1.1   bouyer 			dma_timing |= geode_dma[drvp->DMA_mode];
    224  1.1   bouyer 			idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
    225  1.1   bouyer 		} else {
    226  1.1   bouyer 			/* PIO only */
    227  1.7  thorpej 			s = splbio();
    228  1.1   bouyer 			drvp->drive_flags &= ~(DRIVE_UDMA | DRIVE_DMA);
    229  1.7  thorpej 			splx(s);
    230  1.1   bouyer 		}
    231  1.2   rumble 
    232  1.2   rumble 		switch (sc->sc_pp->ide_product) {
    233  1.2   rumble 		case PCI_PRODUCT_CYRIX_CX5530_IDE:
    234  1.2   rumble 			bus_space_write_4(sc->sc_dma_iot, sc->sc_dma_ioh,
    235  1.2   rumble 			    dmaoff, dma_timing);
    236  1.2   rumble 			bus_space_write_4(sc->sc_dma_iot, sc->sc_dma_ioh,
    237  1.2   rumble 			    piooff, geode_pio[drvp->PIO_mode]);
    238  1.2   rumble 			break;
    239  1.2   rumble 
    240  1.2   rumble 		case PCI_PRODUCT_NS_SC1100_IDE:
    241  1.2   rumble 			pci_conf_write(sc->sc_pc, sc->sc_tag, dmaoff,
    242  1.2   rumble 			    dma_timing);
    243  1.2   rumble 			pci_conf_write(sc->sc_pc, sc->sc_tag, piooff,
    244  1.2   rumble 			    geode_pio[drvp->PIO_mode]);
    245  1.2   rumble 			break;
    246  1.2   rumble 		}
    247  1.1   bouyer 	}
    248  1.1   bouyer 
    249  1.1   bouyer 	if (idedma_ctl != 0) {
    250  1.1   bouyer 		/* Add software bits in status register */
    251  1.1   bouyer 		bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
    252  1.1   bouyer 		    idedma_ctl);
    253  1.1   bouyer 	}
    254  1.1   bouyer }
    255