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_cyrix_chipinit(device_t dev);
29a1917f14Szrj static void ata_cyrix_setmode(device_t dev, int mode);
30a1917f14Szrj
31a1917f14Szrj /*
32a1917f14Szrj * Cyrix chipset support functions
33a1917f14Szrj */
34a1917f14Szrj int
ata_cyrix_ident(device_t dev)35a1917f14Szrj ata_cyrix_ident(device_t dev)
36a1917f14Szrj {
37a1917f14Szrj struct ata_pci_controller *ctlr = device_get_softc(dev);
38a1917f14Szrj
39a1917f14Szrj if (pci_get_devid(dev) == ATA_CYRIX_5530) {
40a1917f14Szrj device_set_desc(dev, "Cyrix 5530 ATA33 controller");
41a1917f14Szrj ctlr->chipinit = ata_cyrix_chipinit;
42a1917f14Szrj return 0;
43a1917f14Szrj }
44a1917f14Szrj return ENXIO;
45a1917f14Szrj }
46a1917f14Szrj
47a1917f14Szrj static int
ata_cyrix_chipinit(device_t dev)48a1917f14Szrj ata_cyrix_chipinit(device_t dev)
49a1917f14Szrj {
50a1917f14Szrj struct ata_pci_controller *ctlr = device_get_softc(dev);
51a1917f14Szrj
5243156ad7Szrj if (ata_setup_interrupt(dev, ata_generic_intr))
53a1917f14Szrj return ENXIO;
54a1917f14Szrj
55a1917f14Szrj ctlr->setmode = ata_cyrix_setmode;
56a1917f14Szrj return 0;
57a1917f14Szrj }
58a1917f14Szrj
59a1917f14Szrj static void
ata_cyrix_setmode(device_t dev,int mode)60a1917f14Szrj ata_cyrix_setmode(device_t dev, int mode)
61a1917f14Szrj {
6243156ad7Szrj struct ata_pci_controller *ctlr = device_get_softc(GRANDPARENT(dev));
63a1917f14Szrj struct ata_channel *ch = device_get_softc(device_get_parent(dev));
64a1917f14Szrj struct ata_device *atadev = device_get_softc(dev);
65*2458a87aSzrj int devno = (ch->unit << 1) + atadev->unit;
66a1917f14Szrj int error;
6759503772Szrj static const uint32_t piotiming[] =
6859503772Szrj { 0x00009172, 0x00012171, 0x00020080, 0x00032010, 0x00040010 };
6959503772Szrj static const uint32_t dmatiming[] =
7059503772Szrj { 0x00077771, 0x00012121, 0x00002020 };
7159503772Szrj static const uint32_t udmatiming[] =
7259503772Szrj { 0x00921250, 0x00911140, 0x00911030 };
73a1917f14Szrj
74a1917f14Szrj mode = ata_limit_mode(dev, mode, ATA_UDMA2);
75a1917f14Szrj
76a1917f14Szrj error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
77a1917f14Szrj
78a1917f14Szrj if (bootverbose)
79a1917f14Szrj device_printf(dev, "%ssetting %s on Cyrix chip\n",
80a1917f14Szrj (error) ? "FAILURE " : "", ata_mode2str(mode));
81a1917f14Szrj
82a1917f14Szrj if (!error) {
8343156ad7Szrj /* dont try to set the mode if we dont have the resource */
8443156ad7Szrj if (ctlr->r_res1) {
8543156ad7Szrj ch->dma->alignment = 16;
86878a3234Szrj ch->dma->max_iosize = 64 * DEV_BSIZE;
8743156ad7Szrj
88a1917f14Szrj if (mode >= ATA_UDMA0) {
89a1917f14Szrj ATA_OUTL(ch->r_io[ATA_BMCMD_PORT].res,
90a1917f14Szrj 0x24 + (devno << 3), udmatiming[mode & ATA_MODE_MASK]);
91a1917f14Szrj }
92a1917f14Szrj else if (mode >= ATA_WDMA0) {
93a1917f14Szrj ATA_OUTL(ch->r_io[ATA_BMCMD_PORT].res,
94a1917f14Szrj 0x24 + (devno << 3), dmatiming[mode & ATA_MODE_MASK]);
95a1917f14Szrj }
96a1917f14Szrj else {
97a1917f14Szrj ATA_OUTL(ch->r_io[ATA_BMCMD_PORT].res,
98a1917f14Szrj 0x20 + (devno << 3), piotiming[mode & ATA_MODE_MASK]);
99a1917f14Szrj }
10043156ad7Szrj }
101a1917f14Szrj atadev->mode = mode;
102a1917f14Szrj }
103a1917f14Szrj }
104