2 * Copyright (c) 1998 - 2008 Søren Schmidt <sos@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/module.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
36 #include <sys/endian.h>
37 #include <sys/malloc.h>
39 #include <sys/mutex.h>
41 #include <sys/taskqueue.h>
43 #include <machine/stdarg.h>
44 #include <machine/resource.h>
45 #include <machine/bus.h>
47 #include <dev/pci/pcivar.h>
48 #include <dev/pci/pcireg.h>
49 #include <dev/ata/ata-all.h>
50 #include <dev/ata/ata-pci.h>
53 /* local prototypes */
54 static int ata_marvell_chipinit(device_t dev);
55 static int ata_marvell_ch_attach(device_t dev);
56 static int ata_marvell_setmode(device_t dev, int target, int mode);
57 static int ata_marvell_dummy_chipinit(device_t dev);
64 * Marvell chipset support functions
66 #define ATA_MV_HOST_BASE(ch) \
67 ((ch->unit & 3) * 0x0100) + (ch->unit > 3 ? 0x30000 : 0x20000)
68 #define ATA_MV_EDMA_BASE(ch) \
69 ((ch->unit & 3) * 0x2000) + (ch->unit > 3 ? 0x30000 : 0x20000)
71 struct ata_marvell_response {
78 struct ata_marvell_dma_prdentry {
86 ata_marvell_probe(device_t dev)
88 struct ata_pci_controller *ctlr = device_get_softc(dev);
89 static const struct ata_chip_id ids[] =
90 {{ ATA_M88SE6101, 0, 0, MV_61XX, ATA_UDMA6, "88SE6101" },
91 { ATA_M88SE6102, 0, 0, MV_61XX, ATA_UDMA6, "88SE6102" },
92 { ATA_M88SE6111, 0, 1, MV_61XX, ATA_UDMA6, "88SE6111" },
93 { ATA_M88SE6121, 0, 2, MV_61XX, ATA_UDMA6, "88SE6121" },
94 { ATA_M88SE6141, 0, 4, MV_61XX, ATA_UDMA6, "88SE6141" },
95 { ATA_M88SE6145, 0, 4, MV_61XX, ATA_UDMA6, "88SE6145" },
96 { 0x91a41b4b, 0, 0, MV_91XX, ATA_UDMA6, "88SE912x" },
99 if (pci_get_vendor(dev) != ATA_MARVELL_ID &&
100 pci_get_vendor(dev) != ATA_MARVELL2_ID)
103 if (!(ctlr->chip = ata_match_chip(dev, ids)))
108 switch (ctlr->chip->cfg2) {
110 ctlr->chipinit = ata_marvell_chipinit;
113 ctlr->chipinit = ata_marvell_dummy_chipinit;
116 return (BUS_PROBE_LOW_PRIORITY);
120 ata_marvell_chipinit(device_t dev)
122 struct ata_pci_controller *ctlr = device_get_softc(dev);
125 if (ata_setup_interrupt(dev, ata_generic_intr))
127 /* Create AHCI subdevice if AHCI part present. */
128 if (ctlr->chip->cfg1) {
129 child = device_add_child(dev, NULL, -1);
131 device_set_ivars(child, (void *)(intptr_t)-1);
132 bus_generic_attach(dev);
135 ctlr->ch_attach = ata_marvell_ch_attach;
136 ctlr->ch_detach = ata_pci_ch_detach;
137 ctlr->reset = ata_generic_reset;
138 ctlr->setmode = ata_marvell_setmode;
144 ata_marvell_ch_attach(device_t dev)
146 struct ata_channel *ch = device_get_softc(dev);
149 error = ata_pci_ch_attach(dev);
150 /* dont use 32 bit PIO transfers */
151 ch->flags |= ATA_USE_16BIT;
152 ch->flags |= ATA_CHECKS_CABLE;
157 ata_marvell_setmode(device_t dev, int target, int mode)
159 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
160 struct ata_channel *ch = device_get_softc(dev);
162 mode = min(mode, ctlr->chip->max_dma);
163 /* Check for 80pin cable present. */
164 if (ata_dma_check_80pin && mode > ATA_UDMA2 &&
165 ATA_IDX_INB(ch, ATA_BMDEVSPEC_0) & 0x01) {
166 ata_print_cable(dev, "controller");
169 /* Nothing to do to setup mode, the controller snoop SET_FEATURE cmd. */
174 ata_marvell_dummy_chipinit(device_t dev)
176 struct ata_pci_controller *ctlr = device_get_softc(dev);
182 ATA_DECLARE_DRIVER(ata_marvell);