1 /*- 2 * Copyright (c) 1998 - 2008 Søren Schmidt <sos@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer, 10 * without modification, immediately at the beginning of the file. 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 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 /* local prototypes */ 28 static int ata_national_chipinit(device_t dev); 29 static void ata_national_setmode(device_t dev, int mode); 30 31 /* 32 * National chipset support functions 33 */ 34 int 35 ata_national_ident(device_t dev) 36 { 37 struct ata_pci_controller *ctlr = device_get_softc(dev); 38 39 /* this chip is a clone of the Cyrix chip, bugs and all */ 40 if (pci_get_devid(dev) == ATA_SC1100) { 41 device_set_desc(dev, "National Geode SC1100 ATA33 controller"); 42 ctlr->chipinit = ata_national_chipinit; 43 return 0; 44 } 45 return ENXIO; 46 } 47 48 static int 49 ata_national_chipinit(device_t dev) 50 { 51 struct ata_pci_controller *ctlr = device_get_softc(dev); 52 53 if (ata_setup_interrupt(dev, ata_generic_intr)) 54 return ENXIO; 55 56 ctlr->setmode = ata_national_setmode; 57 return 0; 58 } 59 60 static void 61 ata_national_setmode(device_t dev, int mode) 62 { 63 device_t gparent = GRANDPARENT(dev); 64 struct ata_channel *ch = device_get_softc(device_get_parent(dev)); 65 struct ata_device *atadev = device_get_softc(dev); 66 int devno = (ch->unit << 1) + atadev->unit; 67 static const uint32_t piotiming[] = 68 { 0x9172d132, 0x21717121, 0x00803020, 0x20102010, 0x00100010, 69 0x00803020, 0x20102010, 0x00100010, 70 0x00100010, 0x00100010, 0x00100010 }; 71 static const uint32_t dmatiming[] = 72 { 0x80077771, 0x80012121, 0x80002020 }; 73 static const uint32_t udmatiming[] = 74 { 0x80921250, 0x80911140, 0x80911030 }; 75 int error; 76 77 ch->dma->alignment = 16; 78 ch->dma->max_iosize = 64 * DEV_BSIZE; 79 80 mode = ata_limit_mode(dev, mode, ATA_UDMA2); 81 82 error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); 83 84 if (bootverbose) 85 device_printf(dev, "%s setting %s on National chip\n", 86 (error) ? "failed" : "success", ata_mode2str(mode)); 87 if (!error) { 88 if (mode >= ATA_UDMA0) { 89 pci_write_config(gparent, 0x44 + (devno << 3), 90 udmatiming[mode & ATA_MODE_MASK], 4); 91 } 92 else if (mode >= ATA_WDMA0) { 93 pci_write_config(gparent, 0x44 + (devno << 3), 94 dmatiming[mode & ATA_MODE_MASK], 4); 95 } 96 else { 97 pci_write_config(gparent, 0x44 + (devno << 3), 98 pci_read_config(gparent, 0x44 + (devno << 3), 4) | 99 0x80000000, 4); 100 } 101 pci_write_config(gparent, 0x40 + (devno << 3), 102 piotiming[ata_mode2idx(mode)], 4); 103 atadev->mode = mode; 104 } 105 } 106