slide.c revision 1.3 1 1.3 thorpej /* $NetBSD: slide.c,v 1.3 2004/01/03 01:50:53 thorpej Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*-
4 1.1 bouyer * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.1 bouyer * All rights reserved.
6 1.1 bouyer *
7 1.1 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.1 bouyer * by Jason R. Thorpe.
9 1.1 bouyer *
10 1.1 bouyer * Redistribution and use in source and binary forms, with or without
11 1.1 bouyer * modification, are permitted provided that the following conditions
12 1.1 bouyer * are met:
13 1.1 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.1 bouyer * notice, this list of conditions and the following disclaimer.
15 1.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.1 bouyer * documentation and/or other materials provided with the distribution.
18 1.1 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.1 bouyer * must display the following acknowledgement:
20 1.1 bouyer * This product includes software developed by the NetBSD
21 1.1 bouyer * Foundation, Inc. and its contributors.
22 1.1 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 bouyer * contributors may be used to endorse or promote products derived
24 1.1 bouyer * from this software without specific prior written permission.
25 1.1 bouyer *
26 1.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.1 bouyer */
38 1.1 bouyer
39 1.1 bouyer #include <sys/param.h>
40 1.1 bouyer #include <sys/systm.h>
41 1.1 bouyer
42 1.1 bouyer #include <dev/pci/pcivar.h>
43 1.1 bouyer #include <dev/pci/pcidevs.h>
44 1.1 bouyer #include <dev/pci/pciidereg.h>
45 1.1 bouyer #include <dev/pci/pciidevar.h>
46 1.1 bouyer #include <dev/pci/pciide_sl82c105_reg.h>
47 1.1 bouyer
48 1.2 thorpej static void sl82c105_chip_map(struct pciide_softc*, struct pci_attach_args*);
49 1.3 thorpej static void sl82c105_setup_channel(struct wdc_channel*);
50 1.1 bouyer
51 1.2 thorpej static int slide_match(struct device *, struct cfdata *, void *);
52 1.2 thorpej static void slide_attach(struct device *, struct device *, void *);
53 1.1 bouyer
54 1.1 bouyer CFATTACH_DECL(slide, sizeof(struct pciide_softc),
55 1.1 bouyer slide_match, slide_attach, NULL, NULL);
56 1.1 bouyer
57 1.2 thorpej static const struct pciide_product_desc pciide_symphony_products[] = {
58 1.1 bouyer { PCI_PRODUCT_SYMPHONY_82C105,
59 1.1 bouyer 0,
60 1.1 bouyer "Symphony Labs 82C105 IDE controller",
61 1.1 bouyer sl82c105_chip_map,
62 1.1 bouyer },
63 1.1 bouyer { 0,
64 1.1 bouyer 0,
65 1.1 bouyer NULL,
66 1.1 bouyer }
67 1.1 bouyer };
68 1.1 bouyer
69 1.2 thorpej static const struct pciide_product_desc pciide_winbond_products[] = {
70 1.1 bouyer { PCI_PRODUCT_WINBOND_W83C553F_1,
71 1.1 bouyer 0,
72 1.1 bouyer "Winbond W83C553F IDE controller",
73 1.1 bouyer sl82c105_chip_map,
74 1.1 bouyer },
75 1.1 bouyer { 0,
76 1.1 bouyer 0,
77 1.1 bouyer NULL,
78 1.1 bouyer }
79 1.1 bouyer };
80 1.1 bouyer
81 1.2 thorpej static int
82 1.2 thorpej slide_match(struct device *parent, struct cfdata *match, void *aux)
83 1.1 bouyer {
84 1.1 bouyer struct pci_attach_args *pa = aux;
85 1.1 bouyer
86 1.1 bouyer if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SYMPHONY) {
87 1.1 bouyer if (pciide_lookup_product(pa->pa_id, pciide_symphony_products))
88 1.1 bouyer return (2);
89 1.1 bouyer }
90 1.1 bouyer if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_WINBOND) {
91 1.1 bouyer if (pciide_lookup_product(pa->pa_id, pciide_winbond_products))
92 1.1 bouyer return (2);
93 1.1 bouyer }
94 1.1 bouyer return (0);
95 1.1 bouyer }
96 1.1 bouyer
97 1.2 thorpej static void
98 1.2 thorpej slide_attach(struct device *parent, struct device *self, void *aux)
99 1.1 bouyer {
100 1.1 bouyer struct pci_attach_args *pa = aux;
101 1.1 bouyer struct pciide_softc *sc = (struct pciide_softc *)self;
102 1.1 bouyer const struct pciide_product_desc *pp = NULL;
103 1.1 bouyer
104 1.1 bouyer if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SYMPHONY)
105 1.1 bouyer pp = pciide_lookup_product(pa->pa_id, pciide_symphony_products);
106 1.1 bouyer if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_WINBOND)
107 1.1 bouyer pp = pciide_lookup_product(pa->pa_id, pciide_winbond_products);
108 1.1 bouyer if (pp == NULL)
109 1.1 bouyer panic("slide_attach");
110 1.1 bouyer pciide_common_attach(sc, pa, pp);
111 1.1 bouyer }
112 1.1 bouyer
113 1.1 bouyer static int
114 1.1 bouyer sl82c105_bugchk(struct pci_attach_args *pa)
115 1.1 bouyer {
116 1.1 bouyer
117 1.1 bouyer if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_WINBOND ||
118 1.1 bouyer PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_WINBOND_W83C553F_0)
119 1.1 bouyer return (0);
120 1.1 bouyer
121 1.1 bouyer if (PCI_REVISION(pa->pa_class) <= 0x05)
122 1.1 bouyer return (1);
123 1.1 bouyer
124 1.1 bouyer return (0);
125 1.1 bouyer }
126 1.1 bouyer
127 1.2 thorpej static void
128 1.2 thorpej sl82c105_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
129 1.1 bouyer {
130 1.1 bouyer struct pciide_channel *cp;
131 1.1 bouyer bus_size_t cmdsize, ctlsize;
132 1.1 bouyer pcireg_t interface, idecr;
133 1.1 bouyer int channel;
134 1.1 bouyer
135 1.1 bouyer if (pciide_chipen(sc, pa) == 0)
136 1.1 bouyer return;
137 1.1 bouyer
138 1.1 bouyer aprint_normal("%s: bus-master DMA support present",
139 1.1 bouyer sc->sc_wdcdev.sc_dev.dv_xname);
140 1.1 bouyer
141 1.1 bouyer /*
142 1.1 bouyer * Check to see if we're part of the Winbond 83c553 Southbridge.
143 1.1 bouyer * If so, we need to disable DMA on rev. <= 5 of that chip.
144 1.1 bouyer */
145 1.1 bouyer if (pci_find_device(pa, sl82c105_bugchk)) {
146 1.1 bouyer aprint_normal(" but disabled due to 83c553 rev. <= 0x05");
147 1.1 bouyer sc->sc_dma_ok = 0;
148 1.1 bouyer } else
149 1.1 bouyer pciide_mapreg_dma(sc, pa);
150 1.1 bouyer aprint_normal("\n");
151 1.1 bouyer
152 1.1 bouyer sc->sc_wdcdev.cap = WDC_CAPABILITY_DATA32 | WDC_CAPABILITY_DATA16 |
153 1.1 bouyer WDC_CAPABILITY_MODE;
154 1.1 bouyer sc->sc_wdcdev.PIO_cap = 4;
155 1.1 bouyer if (sc->sc_dma_ok) {
156 1.1 bouyer sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA | WDC_CAPABILITY_IRQACK;
157 1.1 bouyer sc->sc_wdcdev.irqack = pciide_irqack;
158 1.1 bouyer sc->sc_wdcdev.DMA_cap = 2;
159 1.1 bouyer }
160 1.1 bouyer sc->sc_wdcdev.set_modes = sl82c105_setup_channel;
161 1.1 bouyer
162 1.1 bouyer sc->sc_wdcdev.channels = sc->wdc_chanarray;
163 1.1 bouyer sc->sc_wdcdev.nchannels = PCIIDE_NUM_CHANNELS;
164 1.1 bouyer
165 1.1 bouyer idecr = pci_conf_read(sc->sc_pc, sc->sc_tag, SYMPH_IDECSR);
166 1.1 bouyer
167 1.1 bouyer interface = PCI_INTERFACE(pa->pa_class);
168 1.1 bouyer
169 1.1 bouyer for (channel = 0; channel < sc->sc_wdcdev.nchannels; channel++) {
170 1.1 bouyer cp = &sc->pciide_channels[channel];
171 1.1 bouyer if (pciide_chansetup(sc, channel, interface) == 0)
172 1.1 bouyer continue;
173 1.1 bouyer if ((channel == 0 && (idecr & IDECR_P0EN) == 0) ||
174 1.1 bouyer (channel == 1 && (idecr & IDECR_P1EN) == 0)) {
175 1.1 bouyer aprint_normal("%s: %s channel ignored (disabled)\n",
176 1.1 bouyer sc->sc_wdcdev.sc_dev.dv_xname, cp->name);
177 1.1 bouyer cp->wdc_channel.ch_flags |= WDCF_DISABLED;
178 1.1 bouyer continue;
179 1.1 bouyer }
180 1.1 bouyer pciide_mapchan(pa, cp, interface, &cmdsize, &ctlsize,
181 1.1 bouyer pciide_pci_intr);
182 1.1 bouyer }
183 1.1 bouyer }
184 1.1 bouyer
185 1.2 thorpej static void
186 1.3 thorpej sl82c105_setup_channel(struct wdc_channel *chp)
187 1.1 bouyer {
188 1.1 bouyer struct ata_drive_datas *drvp;
189 1.1 bouyer struct pciide_channel *cp = (struct pciide_channel*)chp;
190 1.1 bouyer struct pciide_softc *sc = (struct pciide_softc *)cp->wdc_channel.wdc;
191 1.1 bouyer int pxdx_reg, drive;
192 1.1 bouyer pcireg_t pxdx;
193 1.1 bouyer
194 1.1 bouyer /* Set up DMA if needed. */
195 1.1 bouyer pciide_channel_dma_setup(cp);
196 1.1 bouyer
197 1.1 bouyer for (drive = 0; drive < 2; drive++) {
198 1.1 bouyer pxdx_reg = ((chp->channel == 0) ? SYMPH_P0D0CR
199 1.1 bouyer : SYMPH_P1D0CR) + (drive * 4);
200 1.1 bouyer
201 1.1 bouyer pxdx = pci_conf_read(sc->sc_pc, sc->sc_tag, pxdx_reg);
202 1.1 bouyer
203 1.1 bouyer pxdx &= ~(PxDx_CMD_ON_MASK|PxDx_CMD_OFF_MASK);
204 1.1 bouyer pxdx &= ~(PxDx_PWEN|PxDx_RDYEN|PxDx_RAEN);
205 1.1 bouyer
206 1.1 bouyer drvp = &chp->ch_drive[drive];
207 1.1 bouyer /* If no drive, skip. */
208 1.1 bouyer if ((drvp->drive_flags & DRIVE) == 0) {
209 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag, pxdx_reg, pxdx);
210 1.1 bouyer continue;
211 1.1 bouyer }
212 1.1 bouyer
213 1.1 bouyer if (drvp->drive_flags & DRIVE_DMA) {
214 1.1 bouyer /*
215 1.1 bouyer * Timings will be used for both PIO and DMA,
216 1.1 bouyer * so adjust DMA mode if needed.
217 1.1 bouyer */
218 1.1 bouyer if (drvp->PIO_mode >= 3) {
219 1.1 bouyer if ((drvp->DMA_mode + 2) > drvp->PIO_mode)
220 1.1 bouyer drvp->DMA_mode = drvp->PIO_mode - 2;
221 1.1 bouyer if (drvp->DMA_mode < 1) {
222 1.1 bouyer /*
223 1.1 bouyer * Can't mix both PIO and DMA.
224 1.1 bouyer * Disable DMA.
225 1.1 bouyer */
226 1.1 bouyer drvp->drive_flags &= ~DRIVE_DMA;
227 1.1 bouyer }
228 1.1 bouyer } else {
229 1.1 bouyer /*
230 1.1 bouyer * Can't mix both PIO and DMA. Disable
231 1.1 bouyer * DMA.
232 1.1 bouyer */
233 1.1 bouyer drvp->drive_flags &= ~DRIVE_DMA;
234 1.1 bouyer }
235 1.1 bouyer }
236 1.1 bouyer
237 1.1 bouyer if (drvp->drive_flags & DRIVE_DMA) {
238 1.1 bouyer /* Use multi-word DMA. */
239 1.1 bouyer pxdx |= symph_mw_dma_times[drvp->DMA_mode].cmd_on <<
240 1.1 bouyer PxDx_CMD_ON_SHIFT;
241 1.1 bouyer pxdx |= symph_mw_dma_times[drvp->DMA_mode].cmd_off;
242 1.1 bouyer } else {
243 1.1 bouyer pxdx |= symph_pio_times[drvp->PIO_mode].cmd_on <<
244 1.1 bouyer PxDx_CMD_ON_SHIFT;
245 1.1 bouyer pxdx |= symph_pio_times[drvp->PIO_mode].cmd_off;
246 1.1 bouyer }
247 1.1 bouyer
248 1.1 bouyer /* XXX PxDx_PWEN? PxDx_RDYEN? PxDx_RAEN? */
249 1.1 bouyer
250 1.1 bouyer /* ...and set the mode for this drive. */
251 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag, pxdx_reg, pxdx);
252 1.1 bouyer }
253 1.1 bouyer }
254