geodeide.c revision 1.1 1 /* $NetBSD: geodeide.c,v 1.1 2004/07/09 18:38:37 bouyer Exp $ */
2
3 /*
4 * Copyright (c) 2004 Manuel Bouyer.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Manuel Bouyer.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32
33 /*
34 * Driver for the IDE part of the AMD Geode CS5530A compagnion chip
35 * Docs available from AMD's web site
36 */
37
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: geodeide.c,v 1.1 2004/07/09 18:38:37 bouyer Exp $");
40
41 #include <sys/param.h>
42 #include <sys/systm.h>
43
44 #include <dev/pci/pcivar.h>
45 #include <dev/pci/pcidevs.h>
46 #include <dev/pci/pciidereg.h>
47 #include <dev/pci/pciidevar.h>
48
49 #include <dev/pci/pciide_geode_reg.h>
50
51 static void geodeide_chip_map(struct pciide_softc *,
52 struct pci_attach_args *);
53 static void geodeide_setup_channel(struct wdc_channel *);
54
55 static int geodeide_match(struct device *, struct cfdata *, void *);
56 static void geodeide_attach(struct device *, struct device *, void *);
57
58 CFATTACH_DECL(geodeide, sizeof(struct pciide_softc),
59 geodeide_match, geodeide_attach, NULL, NULL);
60
61 static const struct pciide_product_desc pciide_geode_products[] = {
62 { PCI_PRODUCT_CYRIX_CX5530_IDE,
63 0,
64 "AMD Geode CX5530 IDE controller",
65 geodeide_chip_map,
66 },
67 { 0,
68 0,
69 NULL,
70 NULL,
71 },
72 };
73
74 static int
75 geodeide_match(struct device *parent, struct cfdata *match, void *aux)
76 {
77 struct pci_attach_args *pa = aux;
78
79 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CYRIX &&
80 PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
81 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_IDE &&
82 pciide_lookup_product(pa->pa_id, pciide_geode_products))
83 return(2);
84 return (0);
85 }
86
87 static void
88 geodeide_attach(struct device *parent, struct device *self, void *aux)
89 {
90 struct pci_attach_args *pa = aux;
91 struct pciide_softc *sc = (void *)self;
92
93 pciide_common_attach(sc, pa,
94 pciide_lookup_product(pa->pa_id, pciide_geode_products));
95 }
96
97 static void
98 geodeide_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
99 {
100 struct pciide_channel *cp;
101 int channel;
102 bus_size_t cmdsize, ctlsize;
103
104 if (pciide_chipen(sc, pa) == 0)
105 return;
106
107 aprint_normal("%s: bus-master DMA support present",
108 sc->sc_wdcdev.sc_dev.dv_xname);
109 pciide_mapreg_dma(sc, pa);
110 aprint_normal("\n");
111 if (sc->sc_dma_ok) {
112 sc->sc_wdcdev.cap = WDC_CAPABILITY_DMA | WDC_CAPABILITY_UDMA |
113 WDC_CAPABILITY_IRQACK;
114 sc->sc_wdcdev.irqack = pciide_irqack;
115 }
116 sc->sc_wdcdev.PIO_cap = 4;
117 sc->sc_wdcdev.DMA_cap = 2;
118 sc->sc_wdcdev.UDMA_cap = 2;
119 sc->sc_wdcdev.set_modes = geodeide_setup_channel;
120 sc->sc_wdcdev.channels = sc->wdc_chanarray;
121 sc->sc_wdcdev.nchannels = PCIIDE_NUM_CHANNELS;
122 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32 |
123 WDC_CAPABILITY_MODE;
124
125 for (channel = 0; channel < sc->sc_wdcdev.nchannels; channel++) {
126 cp = &sc->pciide_channels[channel];
127 /* controller is compat-only */
128 if (pciide_chansetup(sc, channel, 0) == 0)
129 continue;
130 pciide_mapchan(pa, cp, 0, &cmdsize, &ctlsize, pciide_pci_intr);
131 }
132 }
133
134 static void
135 geodeide_setup_channel(struct wdc_channel *chp)
136 {
137 struct ata_drive_datas *drvp;
138 struct pciide_channel *cp = (struct pciide_channel*)chp;
139 struct pciide_softc *sc = (struct pciide_softc *)cp->wdc_channel.ch_wdc;
140 int channel = chp->ch_channel;
141 int drive;
142 u_int32_t dma_timing;
143 u_int8_t idedma_ctl;
144
145 /* setup DMA if needed */
146 pciide_channel_dma_setup(cp);
147
148 idedma_ctl = 0;
149
150 /* Per drive settings */
151 for (drive = 0; drive < 2; drive++) {
152 drvp = &chp->ch_drive[drive];
153 /* If no drive, skip */
154 if ((drvp->drive_flags & DRIVE) == 0)
155 continue;
156 dma_timing = DMA_REG_PIO_FORMAT;
157 /* add timing values, setup DMA if needed */
158 if (drvp->drive_flags & DRIVE_UDMA) {
159 /* Use Ultra-DMA */
160 dma_timing |= geode_udma[drvp->UDMA_mode];
161 idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
162 } else if (drvp->drive_flags & DRIVE_DMA) {
163 /* use Multiword DMA */
164 dma_timing |= geode_dma[drvp->DMA_mode];
165 idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
166 } else {
167 /* PIO only */
168 drvp->drive_flags &= ~(DRIVE_UDMA | DRIVE_DMA);
169 }
170 bus_space_write_4(sc->sc_dma_iot, sc->sc_dma_ioh,
171 DMA_REG(channel, drive), dma_timing);
172 bus_space_write_4(sc->sc_dma_iot, sc->sc_dma_ioh,
173 PIO_REG(channel, drive), geode_pio[drvp->PIO_mode]);
174 }
175
176 if (idedma_ctl != 0) {
177 /* Add software bits in status register */
178 bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
179 idedma_ctl);
180 }
181 }
182