gcscide.c revision 1.5
11.5Sxtraeme/* $NetBSD: gcscide.c,v 1.5 2007/09/03 11:16:28 xtraeme Exp $ */ 21.1Sxtraeme 31.1Sxtraeme/* 41.1Sxtraeme * Copyright (c) 2007 The NetBSD Foundation. 51.1Sxtraeme * All rights reserved. 61.1Sxtraeme * 71.1Sxtraeme * This code is derived from software contributed to the NetBSD Foundation 81.1Sxtraeme * by Juan Romero Pardines. 91.1Sxtraeme * 101.1Sxtraeme * Redistribution and use in source and binary forms, with or without 111.1Sxtraeme * modification, are permitted provided that the following conditions 121.1Sxtraeme * are met: 131.1Sxtraeme * 1. Redistributions of source code must retain the above copyright 141.1Sxtraeme * notice, this list of conditions and the following disclaimer. 151.1Sxtraeme * 2. Redistributions in binary form must reproduce the above copyright 161.1Sxtraeme * notice, this list of conditions and the following disclaimer in the 171.1Sxtraeme * documentation and/or other materials provided with the distribution. 181.1Sxtraeme * 3. All advertising materials mentioning features or use of this software 191.1Sxtraeme * must display the following acknowledgement: 201.1Sxtraeme * This product includes software developed by Juan Romero Pardines 211.1Sxtraeme * for the NetBSD Foundation, Inc. and its contributors. 221.1Sxtraeme * 4. Neither the name of The NetBSD Foundation nor the names of its 231.1Sxtraeme * contributors may be used to endorse or promote products derived 241.1Sxtraeme * from this software without specific prior written permission. 251.1Sxtraeme * 261.1Sxtraeme * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.1Sxtraeme * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.1Sxtraeme * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.1Sxtraeme * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.1Sxtraeme * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.1Sxtraeme * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.1Sxtraeme * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.1Sxtraeme * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.1Sxtraeme * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.1Sxtraeme * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.1Sxtraeme * POSSIBILITY OF SUCH DAMAGE. 371.1Sxtraeme */ 381.1Sxtraeme 391.1Sxtraeme/* 401.3Sxtraeme * Driver for the IDE Controller of the National Semiconductor/AMD 411.3Sxtraeme * CS5535 Companion device. Available on systems with an AMD Geode GX2 421.3Sxtraeme * CPU, for example the decTOP. 431.1Sxtraeme * 441.1Sxtraeme * Datasheet at: 451.1Sxtraeme * 461.1Sxtraeme * http://www.amd.com/files/connectivitysolutions/geode/geode_gx/31506_cs5535_databook.pdf 471.1Sxtraeme */ 481.1Sxtraeme 491.1Sxtraeme#include <sys/cdefs.h> 501.5Sxtraeme__KERNEL_RCSID(0, "$NetBSD: gcscide.c,v 1.5 2007/09/03 11:16:28 xtraeme Exp $"); 511.1Sxtraeme 521.1Sxtraeme#include <sys/param.h> 531.1Sxtraeme#include <sys/systm.h> 541.1Sxtraeme 551.1Sxtraeme#include <dev/pci/pcivar.h> 561.1Sxtraeme#include <dev/pci/pcidevs.h> 571.1Sxtraeme#include <dev/pci/pciidereg.h> 581.1Sxtraeme#include <dev/pci/pciidevar.h> 591.1Sxtraeme 601.1Sxtraeme#include <machine/cpufunc.h> 611.1Sxtraeme 621.5Sxtraeme/* 631.5Sxtraeme * 6.4 - ATA-5 Controller Register Definitions. 641.5Sxtraeme */ 651.1Sxtraeme#define GCSCIDE_MSR_ATAC_BASE 0x51300000 661.1Sxtraeme#define GCSCIDE_ATAC_GLD_MSR_CAP (GCSCIDE_MSR_ATAC_BASE + 0) 671.1Sxtraeme#define GCSCIDE_ATAC_GLD_MSR_CONFIG (GCSCIDE_MSR_ATAC_BASE + 0x01) 681.1Sxtraeme#define GCSCIDE_ATAC_GLD_MSR_SMI (GCSCIDE_MSR_ATAC_BASE + 0x02) 691.1Sxtraeme#define GCSCIDE_ATAC_GLD_MSR_ERROR (GCSCIDE_MSR_ATAC_BASE + 0x03) 701.1Sxtraeme#define GCSCIDE_ATAC_GLD_MSR_PM (GCSCIDE_MSR_ATAC_BASE + 0x04) 711.1Sxtraeme#define GCSCIDE_ATAC_GLD_MSR_DIAG (GCSCIDE_MSR_ATAC_BASE + 0x05) 721.1Sxtraeme#define GCSCIDE_ATAC_IO_BAR (GCSCIDE_MSR_ATAC_BASE + 0x08) 731.1Sxtraeme#define GCSCIDE_ATAC_RESET (GCSCIDE_MSR_ATAC_BASE + 0x10) 741.1Sxtraeme#define GCSCIDE_ATAC_CH0D0_PIO (GCSCIDE_MSR_ATAC_BASE + 0x20) 751.1Sxtraeme#define GCSCIDE_ATAC_CH0D0_DMA (GCSCIDE_MSR_ATAC_BASE + 0x21) 761.1Sxtraeme#define GCSCIDE_ATAC_CH0D1_PIO (GCSCIDE_MSR_ATAC_BASE + 0x22) 771.1Sxtraeme#define GCSCIDE_ATAC_CH0D1_DMA (GCSCIDE_MSR_ATAC_BASE + 0x23) 781.1Sxtraeme#define GCSCIDE_ATAC_PCI_ABRTERR (GCSCIDE_MSR_ATAC_BASE + 0x24) 791.1Sxtraeme#define GCSCIDE_ATAC_BM0_CMD_PRIM 0x00 801.1Sxtraeme#define GCSCIDE_ATAC_BM0_STS_PRIM 0x02 811.1Sxtraeme#define GCSCIDE_ATAC_BM0_PRD 0x04 821.5Sxtraeme/* 831.5Sxtraeme * ATAC_CH0D0_DMA registers: 841.5Sxtraeme * 851.5Sxtraeme * PIO Format (bit 31): Format 1 allows independent control of command 861.5Sxtraeme * and data per drive, while Format 0 selects the slowest speed 871.5Sxtraeme * of the two drives. 881.5Sxtraeme */ 891.5Sxtraeme#define GCSCIDE_ATAC_PIO_FORMAT (1 << 31) /* PIO Mode Format 1 */ 901.5Sxtraeme/* 911.5Sxtraeme * DMA_SEL (bit 20): sets Ultra DMA mode (if enabled) or Multi-word 921.5Sxtraeme * DMA mode (if disabled). 931.5Sxtraeme */ 941.5Sxtraeme#define GCSCIDE_ATAC_DMA_SEL (1 << 20) 951.1Sxtraeme 961.1Sxtraemestatic int gcscide_match(struct device *, struct cfdata *, void *); 971.1Sxtraemestatic void gcscide_attach(struct device *, struct device *, void *); 981.1Sxtraeme 991.1Sxtraemestatic void gcscide_chip_map(struct pciide_softc *, struct pci_attach_args *); 1001.1Sxtraemestatic void gcscide_setup_channel(struct ata_channel *); 1011.1Sxtraeme 1021.5Sxtraeme/* PIO Format 1 settings */ 1031.1Sxtraemestatic const uint32_t gcscide_pio_timings[] = { 1041.1Sxtraeme 0xf7f4f7f4, /* PIO Mode 0 */ 1051.1Sxtraeme 0x53f3f173, /* PIO Mode 1 */ 1061.1Sxtraeme 0x13f18141, /* PIO Mode 2 */ 1071.1Sxtraeme 0x51315131, /* PIO Mode 3 */ 1081.1Sxtraeme 0x11311131 /* PIO Mode 4 */ 1091.1Sxtraeme}; 1101.1Sxtraeme 1111.1Sxtraemestatic const uint32_t gcscide_mdma_timings[] = { 1121.1Sxtraeme 0x7f0ffff3, /* MDMA Mode 0 */ 1131.1Sxtraeme 0x7f035352, /* MDMA Mode 1 */ 1141.1Sxtraeme 0x7f024241 /* MDMA Mode 2 */ 1151.1Sxtraeme}; 1161.1Sxtraeme 1171.1Sxtraemestatic const uint32_t gcscide_udma_timings[] = { 1181.1Sxtraeme 0x7f7436a1, /* Ultra DMA Mode 0 */ 1191.1Sxtraeme 0x7f733481, /* Ultra DMA Mode 1 */ 1201.1Sxtraeme 0x7f723261, /* Ultra DMA Mode 2 */ 1211.1Sxtraeme 0x7f713161, /* Ultra DMA Mode 3 */ 1221.1Sxtraeme 0x7f703061 /* Ultra DMA Mode 4 */ 1231.1Sxtraeme}; 1241.1Sxtraeme 1251.1SxtraemeCFATTACH_DECL(gcscide, sizeof(struct pciide_softc), 1261.1Sxtraeme gcscide_match, gcscide_attach, NULL, NULL); 1271.1Sxtraeme 1281.1Sxtraemestatic const struct pciide_product_desc pciide_gcscide_products[] = { 1291.1Sxtraeme { 1301.1Sxtraeme PCI_PRODUCT_NS_CS5535_IDE, 1311.1Sxtraeme 0, 1321.1Sxtraeme "National Semiconductor/AMD CS5535 IDE Controller", 1331.1Sxtraeme gcscide_chip_map 1341.1Sxtraeme }, 1351.1Sxtraeme { 0, 0, NULL, NULL } 1361.1Sxtraeme}; 1371.1Sxtraeme 1381.1Sxtraemestatic int 1391.1Sxtraemegcscide_match(struct device *parent, struct cfdata *cfdata, void *aux) 1401.1Sxtraeme{ 1411.1Sxtraeme struct pci_attach_args *pa = (struct pci_attach_args *)aux; 1421.1Sxtraeme 1431.1Sxtraeme if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NS && 1441.1Sxtraeme PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE && 1451.1Sxtraeme PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_IDE && 1461.1Sxtraeme pciide_lookup_product(pa->pa_id, pciide_gcscide_products)) 1471.1Sxtraeme return 2; 1481.1Sxtraeme return 0; 1491.1Sxtraeme} 1501.1Sxtraeme 1511.1Sxtraemestatic void 1521.1Sxtraemegcscide_attach(struct device *parent, struct device *self, void *aux) 1531.1Sxtraeme{ 1541.1Sxtraeme struct pci_attach_args *pa = aux; 1551.1Sxtraeme struct pciide_softc *sc = (struct pciide_softc *)self; 1561.1Sxtraeme 1571.1Sxtraeme pciide_common_attach(sc, pa, 1581.1Sxtraeme pciide_lookup_product(pa->pa_id, pciide_gcscide_products)); 1591.1Sxtraeme} 1601.1Sxtraeme 1611.1Sxtraemestatic void 1621.1Sxtraemegcscide_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa) 1631.1Sxtraeme{ 1641.1Sxtraeme pcireg_t interface; 1651.1Sxtraeme bus_size_t cmdsize, ctlsize; 1661.1Sxtraeme 1671.1Sxtraeme if (pciide_chipen(sc, pa) == 0) 1681.1Sxtraeme return; 1691.1Sxtraeme 1701.1Sxtraeme aprint_verbose("%s: bus-master DMA support present", 1711.1Sxtraeme sc->sc_wdcdev.sc_atac.atac_dev.dv_xname); 1721.1Sxtraeme pciide_mapreg_dma(sc, pa); 1731.1Sxtraeme aprint_verbose("\n"); 1741.1Sxtraeme 1751.1Sxtraeme sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32; 1761.1Sxtraeme if (sc->sc_dma_ok) { 1771.1Sxtraeme sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA; 1781.1Sxtraeme sc->sc_wdcdev.irqack = pciide_irqack; 1791.1Sxtraeme } 1801.1Sxtraeme 1811.1Sxtraeme sc->sc_wdcdev.sc_atac.atac_pio_cap = 4; 1821.1Sxtraeme sc->sc_wdcdev.sc_atac.atac_dma_cap = 2; 1831.1Sxtraeme sc->sc_wdcdev.sc_atac.atac_udma_cap = 4; 1841.1Sxtraeme sc->sc_wdcdev.sc_atac.atac_set_modes = gcscide_setup_channel; 1851.1Sxtraeme sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray; 1861.1Sxtraeme sc->sc_wdcdev.sc_atac.atac_nchannels = 1; 1871.1Sxtraeme 1881.1Sxtraeme interface = PCI_INTERFACE(pa->pa_class); 1891.1Sxtraeme 1901.1Sxtraeme wdc_allocate_regs(&sc->sc_wdcdev); 1911.1Sxtraeme 1921.1Sxtraeme if (pciide_chansetup(sc, 0, interface) == 0) 1931.1Sxtraeme return; 1941.1Sxtraeme 1951.1Sxtraeme pciide_mapchan(pa, &sc->pciide_channels[0], interface, 1961.1Sxtraeme &cmdsize, &ctlsize, pciide_pci_intr); 1971.1Sxtraeme} 1981.1Sxtraeme 1991.1Sxtraemestatic void 2001.1Sxtraemegcscide_setup_channel(struct ata_channel *chp) 2011.1Sxtraeme{ 2021.1Sxtraeme struct pciide_channel *cp = CHAN_TO_PCHAN(chp); 2031.1Sxtraeme struct ata_drive_datas *drvp; 2041.1Sxtraeme uint64_t reg = 0; 2051.1Sxtraeme int drive, s; 2061.1Sxtraeme 2071.1Sxtraeme pciide_channel_dma_setup(cp); 2081.1Sxtraeme 2091.1Sxtraeme for (drive = 0; drive < 2; drive++) { 2101.1Sxtraeme drvp = &chp->ch_drive[drive]; 2111.1Sxtraeme if ((drvp->drive_flags & DRIVE) == 0) 2121.1Sxtraeme continue; 2131.5Sxtraeme 2141.5Sxtraeme reg = rdmsr(drive ? GCSCIDE_ATAC_CH0D1_DMA : 2151.5Sxtraeme GCSCIDE_ATAC_CH0D0_DMA); 2161.1Sxtraeme 2171.1Sxtraeme if (drvp->drive_flags & DRIVE_UDMA) { 2181.1Sxtraeme s = splbio(); 2191.1Sxtraeme drvp->drive_flags &= ~DRIVE_DMA; 2201.1Sxtraeme splx(s); 2211.5Sxtraeme /* Enable the Ultra DMA mode bit */ 2221.5Sxtraeme reg |= GCSCIDE_ATAC_DMA_SEL; 2231.5Sxtraeme /* set the Ultra DMA mode */ 2241.1Sxtraeme reg |= gcscide_udma_timings[drvp->UDMA_mode]; 2251.1Sxtraeme 2261.1Sxtraeme wrmsr(drive ? GCSCIDE_ATAC_CH0D1_DMA : 2271.1Sxtraeme GCSCIDE_ATAC_CH0D0_DMA, reg); 2281.1Sxtraeme 2291.1Sxtraeme } else if (drvp->drive_flags & DRIVE_DMA) { 2301.5Sxtraeme /* Enable the Multi-word DMA bit */ 2311.5Sxtraeme reg &= ~GCSCIDE_ATAC_DMA_SEL; 2321.5Sxtraeme /* set the Multi-word DMA mode */ 2331.1Sxtraeme reg |= gcscide_mdma_timings[drvp->DMA_mode]; 2341.1Sxtraeme 2351.1Sxtraeme wrmsr(drive ? GCSCIDE_ATAC_CH0D1_DMA : 2361.1Sxtraeme GCSCIDE_ATAC_CH0D0_DMA, reg); 2371.1Sxtraeme } 2381.5Sxtraeme 2391.5Sxtraeme /* Always use PIO Format 1. */ 2401.5Sxtraeme wrmsr(drive ? GCSCIDE_ATAC_CH0D1_DMA : 2411.5Sxtraeme GCSCIDE_ATAC_CH0D0_DMA, reg | GCSCIDE_ATAC_PIO_FORMAT); 2421.5Sxtraeme 2431.5Sxtraeme /* Set PIO mode */ 2441.4Sxtraeme wrmsr(drive ? GCSCIDE_ATAC_CH0D1_PIO : GCSCIDE_ATAC_CH0D0_PIO, 2451.1Sxtraeme gcscide_pio_timings[drvp->PIO_mode]); 2461.1Sxtraeme } 2471.1Sxtraeme} 248