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