xref: /dflybsd-src/sys/dev/disk/nata/chipsets/ata-cypress.c (revision 43156ad7e979abd3a534fd3bce2c5e6e6dc65372)
1a1917f14Szrj /*-
2a1917f14Szrj  * Copyright (c) 1998 - 2008 Søren Schmidt <sos@FreeBSD.org>
3a1917f14Szrj  * All rights reserved.
4a1917f14Szrj  *
5a1917f14Szrj  * Redistribution and use in source and binary forms, with or without
6a1917f14Szrj  * modification, are permitted provided that the following conditions
7a1917f14Szrj  * are met:
8a1917f14Szrj  * 1. Redistributions of source code must retain the above copyright
9a1917f14Szrj  *    notice, this list of conditions and the following disclaimer,
10a1917f14Szrj  *    without modification, immediately at the beginning of the file.
11a1917f14Szrj  * 2. Redistributions in binary form must reproduce the above copyright
12a1917f14Szrj  *    notice, this list of conditions and the following disclaimer in the
13a1917f14Szrj  *    documentation and/or other materials provided with the distribution.
14a1917f14Szrj  *
15a1917f14Szrj  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16a1917f14Szrj  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17a1917f14Szrj  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18a1917f14Szrj  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19a1917f14Szrj  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20a1917f14Szrj  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21a1917f14Szrj  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22a1917f14Szrj  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23a1917f14Szrj  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24a1917f14Szrj  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25a1917f14Szrj  */
26a1917f14Szrj 
27a1917f14Szrj /* local prototypes */
28a1917f14Szrj static int ata_cypress_chipinit(device_t dev);
29a1917f14Szrj static void ata_cypress_setmode(device_t dev, int mode);
30a1917f14Szrj 
31a1917f14Szrj /*
32a1917f14Szrj  * Cypress chipset support functions
33a1917f14Szrj  */
34a1917f14Szrj int
ata_cypress_ident(device_t dev)35a1917f14Szrj ata_cypress_ident(device_t dev)
36a1917f14Szrj {
37a1917f14Szrj     struct ata_pci_controller *ctlr = device_get_softc(dev);
38a1917f14Szrj 
39a1917f14Szrj     /*
40a1917f14Szrj      * the Cypress chip is a mess, it contains two ATA functions, but
41a1917f14Szrj      * both channels are visible on the first one.
42a1917f14Szrj      * simply ignore the second function for now, as the right
43a1917f14Szrj      * solution (ignoring the second channel on the first function)
44a1917f14Szrj      * doesn't work with the crappy ATA interrupt setup on the alpha.
45a1917f14Szrj      */
46a1917f14Szrj     if (pci_get_devid(dev) == ATA_CYPRESS_82C693 &&
47a1917f14Szrj 	pci_get_function(dev) == 1 &&
48a1917f14Szrj 	pci_get_subclass(dev) == PCIS_STORAGE_IDE) {
49a1917f14Szrj 	device_set_desc(dev, "Cypress 82C693 ATA controller");
50a1917f14Szrj 	ctlr->chipinit = ata_cypress_chipinit;
51a1917f14Szrj 	return 0;
52a1917f14Szrj     }
53a1917f14Szrj     return ENXIO;
54a1917f14Szrj }
55a1917f14Szrj 
56a1917f14Szrj static int
ata_cypress_chipinit(device_t dev)57a1917f14Szrj ata_cypress_chipinit(device_t dev)
58a1917f14Szrj {
59a1917f14Szrj     struct ata_pci_controller *ctlr = device_get_softc(dev);
60a1917f14Szrj 
61*43156ad7Szrj     if (ata_setup_interrupt(dev, ata_generic_intr))
62a1917f14Szrj 	return ENXIO;
63a1917f14Szrj 
64a1917f14Szrj     ctlr->setmode = ata_cypress_setmode;
65a1917f14Szrj     return 0;
66a1917f14Szrj }
67a1917f14Szrj 
68a1917f14Szrj static void
ata_cypress_setmode(device_t dev,int mode)69a1917f14Szrj ata_cypress_setmode(device_t dev, int mode)
70a1917f14Szrj {
71a1917f14Szrj     device_t gparent = GRANDPARENT(dev);
72a1917f14Szrj     struct ata_channel *ch = device_get_softc(device_get_parent(dev));
73a1917f14Szrj     struct ata_device *atadev = device_get_softc(dev);
74a1917f14Szrj     int error;
75a1917f14Szrj 
76a1917f14Szrj     mode = ata_limit_mode(dev, mode, ATA_WDMA2);
77a1917f14Szrj 
78a1917f14Szrj     /* XXX SOS missing WDMA0+1 + PIO modes */
79a1917f14Szrj     if (mode == ATA_WDMA2) {
80a1917f14Szrj 	error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
81a1917f14Szrj 	if (bootverbose)
82a1917f14Szrj 	    device_printf(dev, "%ssetting WDMA2 on Cypress chip\n",
83a1917f14Szrj 			  error ? "FAILURE " : "");
84a1917f14Szrj 	if (!error) {
85a1917f14Szrj 	    pci_write_config(gparent, ch->unit ? 0x4e : 0x4c, 0x2020, 2);
86a1917f14Szrj 	    atadev->mode = mode;
87a1917f14Szrj 	    return;
88a1917f14Szrj 	}
89a1917f14Szrj     }
90a1917f14Szrj     /* we could set PIO mode timings, but we assume the BIOS did that */
91a1917f14Szrj }
92