aic7xxx_seeprom.c revision 1.6 1 1.6 lukem /* $NetBSD: aic7xxx_seeprom.c,v 1.6 2001/11/13 13:14:34 lukem Exp $ */
2 1.1 thorpej
3 1.2 fvdl /*
4 1.2 fvdl * Product specific probe and attach routines for:
5 1.2 fvdl * 3940, 2940, aic7895, aic7890, aic7880,
6 1.2 fvdl * aic7870, aic7860 and aic7850 SCSI controllers
7 1.1 thorpej *
8 1.1 thorpej * These are the SEEPROM-reading functions only. They were split off from
9 1.1 thorpej * the PCI-specific support by Jason R. Thorpe <thorpej (at) netbsd.org>.
10 1.1 thorpej *
11 1.2 fvdl * Copyright (c) 1994, 1995, 1996, 1997, 1998, 1999, 2000 Justin T. Gibbs.
12 1.1 thorpej * All rights reserved.
13 1.1 thorpej *
14 1.1 thorpej * Redistribution and use in source and binary forms, with or without
15 1.1 thorpej * modification, are permitted provided that the following conditions
16 1.1 thorpej * are met:
17 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
18 1.2 fvdl * notice, this list of conditions, and the following disclaimer,
19 1.2 fvdl * without modification.
20 1.2 fvdl * 2. The name of the author may not be used to endorse or promote products
21 1.1 thorpej * derived from this software without specific prior written permission.
22 1.1 thorpej *
23 1.2 fvdl * Alternatively, this software may be distributed under the terms of the
24 1.2 fvdl * the GNU Public License ("GPL").
25 1.2 fvdl *
26 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
27 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
30 1.1 thorpej * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 thorpej * SUCH DAMAGE.
37 1.1 thorpej *
38 1.2 fvdl * $FreeBSD: src/sys/dev/aic7xxx/ahc_pci.c,v 1.27 2000/01/10 01:47:51 gibbs Exp
39 1.2 fvdl $
40 1.2 fvdl */
41 1.6 lukem
42 1.6 lukem #include <sys/cdefs.h>
43 1.6 lukem __KERNEL_RCSID(0, "$NetBSD: aic7xxx_seeprom.c,v 1.6 2001/11/13 13:14:34 lukem Exp $");
44 1.1 thorpej
45 1.1 thorpej #include <sys/param.h>
46 1.1 thorpej #include <sys/systm.h>
47 1.1 thorpej #include <sys/malloc.h>
48 1.1 thorpej #include <sys/kernel.h>
49 1.1 thorpej #include <sys/queue.h>
50 1.1 thorpej #include <sys/device.h>
51 1.4 jdolecek #include <sys/reboot.h> /* for AB_* needed by bootverbose */
52 1.1 thorpej
53 1.1 thorpej #include <machine/bus.h>
54 1.1 thorpej #include <machine/intr.h>
55 1.1 thorpej
56 1.1 thorpej #include <dev/scsipi/scsi_all.h>
57 1.1 thorpej #include <dev/scsipi/scsipi_all.h>
58 1.1 thorpej #include <dev/scsipi/scsiconf.h>
59 1.1 thorpej
60 1.2 fvdl #include <dev/microcode/aic7xxx/aic7xxx_reg.h>
61 1.1 thorpej #include <dev/ic/aic7xxxvar.h>
62 1.1 thorpej #include <dev/ic/smc93cx6var.h>
63 1.1 thorpej
64 1.2 fvdl static void configure_termination(struct ahc_softc *,
65 1.2 fvdl struct seeprom_descriptor *, u_int, u_int *);
66 1.1 thorpej
67 1.2 fvdl static void ahc_new_term_detect(struct ahc_softc *, int *, int *, int *,
68 1.2 fvdl int *, int *);
69 1.2 fvdl static void aic787X_cable_detect(struct ahc_softc *, int *, int *, int *,
70 1.2 fvdl int *);
71 1.2 fvdl static void aic785X_cable_detect(struct ahc_softc *, int *, int *, int *);
72 1.2 fvdl static int acquire_seeprom(struct ahc_softc *, struct seeprom_descriptor *);
73 1.2 fvdl static void release_seeprom(struct seeprom_descriptor *);
74 1.2 fvdl static void write_brdctl(struct ahc_softc *, u_int8_t);
75 1.2 fvdl static u_int8_t read_brdctl(struct ahc_softc *);
76 1.1 thorpej
77 1.1 thorpej /*
78 1.2 fvdl * Check the external port logic for a serial eeprom
79 1.2 fvdl * and termination/cable detection contrls.
80 1.1 thorpej */
81 1.2 fvdl void
82 1.2 fvdl check_extport(struct ahc_softc *ahc, u_int *sxfrctl1)
83 1.2 fvdl {
84 1.2 fvdl struct seeprom_descriptor sd;
85 1.2 fvdl struct seeprom_config sc;
86 1.2 fvdl u_int scsi_conf;
87 1.2 fvdl u_int adapter_control;
88 1.2 fvdl int have_seeprom;
89 1.2 fvdl int have_autoterm;
90 1.2 fvdl
91 1.2 fvdl sd.sd_tag = ahc->tag;
92 1.2 fvdl sd.sd_bsh = ahc->bsh;
93 1.2 fvdl sd.sd_control_offset = SEECTL;
94 1.2 fvdl sd.sd_status_offset = SEECTL;
95 1.2 fvdl sd.sd_dataout_offset = SEECTL;
96 1.1 thorpej
97 1.2 fvdl /*
98 1.2 fvdl * For some multi-channel devices, the c46 is simply too
99 1.2 fvdl * small to work. For the other controller types, we can
100 1.2 fvdl * get our information from either SEEPROM type. Set the
101 1.2 fvdl * type to start our probe with accordingly.
102 1.2 fvdl */
103 1.2 fvdl if (ahc->flags & AHC_LARGE_SEEPROM)
104 1.2 fvdl sd.sd_chip = C56_66;
105 1.2 fvdl else
106 1.2 fvdl sd.sd_chip = C46;
107 1.1 thorpej
108 1.1 thorpej sd.sd_MS = SEEMS;
109 1.1 thorpej sd.sd_RDY = SEERDY;
110 1.1 thorpej sd.sd_CS = SEECS;
111 1.1 thorpej sd.sd_CK = SEECK;
112 1.1 thorpej sd.sd_DO = SEEDO;
113 1.1 thorpej sd.sd_DI = SEEDI;
114 1.1 thorpej
115 1.2 fvdl have_seeprom = acquire_seeprom(ahc, &sd);
116 1.1 thorpej if (have_seeprom) {
117 1.2 fvdl
118 1.2 fvdl if (bootverbose)
119 1.2 fvdl printf("%s: Reading SEEPROM...", ahc_name(ahc));
120 1.2 fvdl
121 1.2 fvdl for (;;) {
122 1.2 fvdl bus_size_t start_addr;
123 1.2 fvdl
124 1.2 fvdl start_addr = 32 * (ahc->channel - 'A');
125 1.2 fvdl
126 1.2 fvdl have_seeprom = read_seeprom(&sd, (u_int16_t *)&sc,
127 1.2 fvdl start_addr, sizeof(sc)/2);
128 1.2 fvdl
129 1.2 fvdl if (have_seeprom) {
130 1.2 fvdl /* Check checksum */
131 1.2 fvdl int i;
132 1.2 fvdl int maxaddr;
133 1.2 fvdl u_int32_t checksum;
134 1.2 fvdl u_int16_t *scarray;
135 1.2 fvdl
136 1.2 fvdl maxaddr = (sizeof(sc)/2) - 1;
137 1.2 fvdl checksum = 0;
138 1.2 fvdl scarray = (u_int16_t *)≻
139 1.2 fvdl
140 1.2 fvdl for (i = 0; i < maxaddr; i++)
141 1.2 fvdl checksum = checksum + scarray[i];
142 1.2 fvdl if (checksum == 0
143 1.2 fvdl || (checksum & 0xFFFF) != sc.checksum) {
144 1.2 fvdl if (bootverbose && sd.sd_chip == C56_66)
145 1.2 fvdl printf ("checksum error\n");
146 1.2 fvdl have_seeprom = 0;
147 1.2 fvdl } else {
148 1.2 fvdl if (bootverbose)
149 1.2 fvdl printf("done.\n");
150 1.2 fvdl break;
151 1.2 fvdl }
152 1.1 thorpej }
153 1.2 fvdl
154 1.2 fvdl if (sd.sd_chip == C56_66)
155 1.2 fvdl break;
156 1.2 fvdl sd.sd_chip = C56_66;
157 1.1 thorpej }
158 1.1 thorpej }
159 1.2 fvdl
160 1.1 thorpej if (!have_seeprom) {
161 1.2 fvdl if (bootverbose)
162 1.3 soren printf("%s: No SEEPROM available\n", ahc_name(ahc));
163 1.1 thorpej ahc->flags |= AHC_USEDEFAULTS;
164 1.2 fvdl } else {
165 1.1 thorpej /*
166 1.1 thorpej * Put the data we've collected down into SRAM
167 1.1 thorpej * where ahc_init will find it.
168 1.1 thorpej */
169 1.1 thorpej int i;
170 1.1 thorpej int max_targ = sc.max_targets & CFMAXTARG;
171 1.2 fvdl u_int16_t discenable;
172 1.2 fvdl u_int16_t ultraenb;
173 1.1 thorpej
174 1.2 fvdl discenable = 0;
175 1.2 fvdl ultraenb = 0;
176 1.2 fvdl if ((sc.adapter_control & CFULTRAEN) != 0) {
177 1.2 fvdl /*
178 1.2 fvdl * Determine if this adapter has a "newstyle"
179 1.2 fvdl * SEEPROM format.
180 1.2 fvdl */
181 1.2 fvdl for (i = 0; i < max_targ; i++) {
182 1.2 fvdl if ((sc.device_flags[i] & CFSYNCHISULTRA) != 0){
183 1.2 fvdl ahc->flags |= AHC_NEWEEPROM_FMT;
184 1.2 fvdl break;
185 1.2 fvdl }
186 1.2 fvdl }
187 1.2 fvdl }
188 1.2 fvdl
189 1.2 fvdl for (i = 0; i < max_targ; i++) {
190 1.2 fvdl u_int scsirate;
191 1.2 fvdl u_int16_t target_mask;
192 1.2 fvdl
193 1.2 fvdl target_mask = 0x01 << i;
194 1.1 thorpej if (sc.device_flags[i] & CFDISC)
195 1.2 fvdl discenable |= target_mask;
196 1.2 fvdl if ((ahc->flags & AHC_NEWEEPROM_FMT) != 0) {
197 1.2 fvdl if ((sc.device_flags[i] & CFSYNCHISULTRA) != 0)
198 1.2 fvdl ultraenb |= target_mask;
199 1.2 fvdl } else if ((sc.adapter_control & CFULTRAEN) != 0) {
200 1.2 fvdl ultraenb |= target_mask;
201 1.2 fvdl }
202 1.2 fvdl if ((sc.device_flags[i] & CFXFER) == 0x04
203 1.2 fvdl && (ultraenb & target_mask) != 0) {
204 1.2 fvdl /* Treat 10MHz as a non-ultra speed */
205 1.2 fvdl sc.device_flags[i] &= ~CFXFER;
206 1.2 fvdl ultraenb &= ~target_mask;
207 1.2 fvdl }
208 1.2 fvdl if ((ahc->features & AHC_ULTRA2) != 0) {
209 1.2 fvdl u_int offset;
210 1.2 fvdl
211 1.2 fvdl if (sc.device_flags[i] & CFSYNCH)
212 1.2 fvdl offset = MAX_OFFSET_ULTRA2;
213 1.2 fvdl else
214 1.2 fvdl offset = 0;
215 1.2 fvdl ahc_outb(ahc, TARG_OFFSET + i, offset);
216 1.2 fvdl
217 1.2 fvdl scsirate = (sc.device_flags[i] & CFXFER)
218 1.2 fvdl | ((ultraenb & target_mask)
219 1.2 fvdl ? 0x8 : 0x0);
220 1.2 fvdl if (sc.device_flags[i] & CFWIDEB)
221 1.2 fvdl scsirate |= WIDEXFER;
222 1.2 fvdl } else {
223 1.2 fvdl scsirate = (sc.device_flags[i] & CFXFER) << 4;
224 1.2 fvdl if (sc.device_flags[i] & CFSYNCH)
225 1.2 fvdl scsirate |= SOFS;
226 1.2 fvdl if (sc.device_flags[i] & CFWIDEB)
227 1.2 fvdl scsirate |= WIDEXFER;
228 1.2 fvdl }
229 1.2 fvdl ahc_outb(ahc, TARG_SCSIRATE + i, scsirate);
230 1.1 thorpej }
231 1.2 fvdl ahc->our_id = sc.brtime_id & CFSCSIID;
232 1.1 thorpej
233 1.2 fvdl scsi_conf = (ahc->our_id & 0x7);
234 1.2 fvdl if (sc.adapter_control & CFSPARITY)
235 1.1 thorpej scsi_conf |= ENSPCHK;
236 1.2 fvdl if (sc.adapter_control & CFRESETB)
237 1.1 thorpej scsi_conf |= RESET_SCSI;
238 1.1 thorpej
239 1.2 fvdl if (sc.bios_control & CFEXTEND)
240 1.2 fvdl ahc->flags |= AHC_EXTENDED_TRANS_A;
241 1.2 fvdl if (ahc->features & AHC_ULTRA
242 1.2 fvdl && (ahc->flags & AHC_NEWEEPROM_FMT) == 0) {
243 1.1 thorpej /* Should we enable Ultra mode? */
244 1.2 fvdl if (!(sc.adapter_control & CFULTRAEN))
245 1.1 thorpej /* Treat us as a non-ultra card */
246 1.2 fvdl ultraenb = 0;
247 1.2 fvdl }
248 1.2 fvdl /* Set SCSICONF info */
249 1.2 fvdl ahc_outb(ahc, SCSICONF, scsi_conf);
250 1.2 fvdl ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
251 1.2 fvdl ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
252 1.2 fvdl ahc_outb(ahc, ULTRA_ENB, ultraenb & 0xff);
253 1.2 fvdl ahc_outb(ahc, ULTRA_ENB + 1, (ultraenb >> 8) & 0xff);
254 1.2 fvdl }
255 1.2 fvdl
256 1.2 fvdl /*
257 1.2 fvdl * Cards that have the external logic necessary to talk to
258 1.2 fvdl * a SEEPROM, are almost certain to have the remaining logic
259 1.2 fvdl * necessary for auto-termination control. This assumption
260 1.2 fvdl * hasn't failed yet...
261 1.2 fvdl */
262 1.2 fvdl have_autoterm = have_seeprom;
263 1.2 fvdl if (have_seeprom)
264 1.2 fvdl adapter_control = sc.adapter_control;
265 1.2 fvdl else
266 1.2 fvdl adapter_control = CFAUTOTERM;
267 1.2 fvdl
268 1.2 fvdl /*
269 1.2 fvdl * Some low-cost chips have SEEPROM and auto-term control built
270 1.2 fvdl * in, instead of using a GAL. They can tell us directly
271 1.2 fvdl * if the termination logic is enabled.
272 1.2 fvdl */
273 1.2 fvdl if ((ahc->features & AHC_SPIOCAP) != 0) {
274 1.2 fvdl if ((ahc_inb(ahc, SPIOCAP) & SSPIOCPS) != 0)
275 1.2 fvdl have_autoterm = TRUE;
276 1.2 fvdl else
277 1.2 fvdl have_autoterm = FALSE;
278 1.2 fvdl }
279 1.2 fvdl
280 1.2 fvdl if (have_autoterm)
281 1.2 fvdl configure_termination(ahc, &sd, adapter_control, sxfrctl1);
282 1.2 fvdl
283 1.2 fvdl release_seeprom(&sd);
284 1.2 fvdl }
285 1.2 fvdl
286 1.2 fvdl static void
287 1.2 fvdl configure_termination(struct ahc_softc *ahc,
288 1.2 fvdl struct seeprom_descriptor *sd,
289 1.2 fvdl u_int adapter_control,
290 1.2 fvdl u_int *sxfrctl1)
291 1.2 fvdl {
292 1.2 fvdl u_int8_t brddat;
293 1.2 fvdl
294 1.2 fvdl brddat = 0;
295 1.2 fvdl
296 1.2 fvdl /*
297 1.2 fvdl * Update the settings in sxfrctl1 to match the
298 1.2 fvdl * termination settings
299 1.2 fvdl */
300 1.2 fvdl *sxfrctl1 = 0;
301 1.2 fvdl
302 1.2 fvdl /*
303 1.2 fvdl * SEECS must be on for the GALS to latch
304 1.2 fvdl * the data properly. Be sure to leave MS
305 1.2 fvdl * on or we will release the seeprom.
306 1.2 fvdl */
307 1.2 fvdl SEEPROM_OUTB(sd, sd->sd_MS | sd->sd_CS);
308 1.2 fvdl if ((adapter_control & CFAUTOTERM) != 0
309 1.2 fvdl || (ahc->features & AHC_NEW_TERMCTL) != 0) {
310 1.2 fvdl int internal50_present;
311 1.2 fvdl int internal68_present;
312 1.2 fvdl int externalcable_present;
313 1.2 fvdl int eeprom_present;
314 1.2 fvdl int enableSEC_low;
315 1.2 fvdl int enableSEC_high;
316 1.2 fvdl int enablePRI_low;
317 1.2 fvdl int enablePRI_high;
318 1.2 fvdl
319 1.2 fvdl enableSEC_low = 0;
320 1.2 fvdl enableSEC_high = 0;
321 1.2 fvdl enablePRI_low = 0;
322 1.2 fvdl enablePRI_high = 0;
323 1.2 fvdl if ((ahc->features & AHC_NEW_TERMCTL) != 0) {
324 1.2 fvdl ahc_new_term_detect(ahc, &enableSEC_low,
325 1.2 fvdl &enableSEC_high,
326 1.2 fvdl &enablePRI_low,
327 1.2 fvdl &enablePRI_high,
328 1.2 fvdl &eeprom_present);
329 1.2 fvdl if ((adapter_control & CFSEAUTOTERM) == 0) {
330 1.2 fvdl if (bootverbose)
331 1.2 fvdl printf("%s: Manual SE Termination\n",
332 1.2 fvdl ahc_name(ahc));
333 1.2 fvdl enableSEC_low = (adapter_control & CFSTERM);
334 1.2 fvdl enableSEC_high = (adapter_control & CFWSTERM);
335 1.2 fvdl }
336 1.2 fvdl if ((adapter_control & CFAUTOTERM) == 0) {
337 1.2 fvdl if (bootverbose)
338 1.2 fvdl printf("%s: Manual LVD Termination\n",
339 1.2 fvdl ahc_name(ahc));
340 1.2 fvdl enablePRI_low = enablePRI_high =
341 1.2 fvdl (adapter_control & CFLVDSTERM);
342 1.2 fvdl }
343 1.2 fvdl /* Make the table calculations below happy */
344 1.2 fvdl internal50_present = 0;
345 1.2 fvdl internal68_present = 1;
346 1.2 fvdl externalcable_present = 1;
347 1.2 fvdl } else if ((ahc->features & AHC_SPIOCAP) != 0) {
348 1.2 fvdl aic785X_cable_detect(ahc, &internal50_present,
349 1.2 fvdl &externalcable_present,
350 1.2 fvdl &eeprom_present);
351 1.2 fvdl } else {
352 1.2 fvdl aic787X_cable_detect(ahc, &internal50_present,
353 1.2 fvdl &internal68_present,
354 1.2 fvdl &externalcable_present,
355 1.2 fvdl &eeprom_present);
356 1.2 fvdl }
357 1.2 fvdl
358 1.2 fvdl if ((ahc->features & AHC_WIDE) == 0)
359 1.2 fvdl internal68_present = 0;
360 1.2 fvdl
361 1.2 fvdl if (bootverbose) {
362 1.2 fvdl if ((ahc->features & AHC_ULTRA2) == 0) {
363 1.2 fvdl printf("%s: internal 50 cable %s present, "
364 1.2 fvdl "internal 68 cable %s present\n",
365 1.2 fvdl ahc_name(ahc),
366 1.2 fvdl internal50_present ? "is":"not",
367 1.2 fvdl internal68_present ? "is":"not");
368 1.2 fvdl
369 1.2 fvdl printf("%s: external cable %s present\n",
370 1.2 fvdl ahc_name(ahc),
371 1.2 fvdl externalcable_present ? "is":"not");
372 1.2 fvdl }
373 1.2 fvdl printf("%s: BIOS eeprom %s present\n",
374 1.2 fvdl ahc_name(ahc), eeprom_present ? "is" : "not");
375 1.1 thorpej }
376 1.2 fvdl
377 1.2 fvdl if ((ahc->flags & AHC_INT50_SPEEDFLEX) != 0) {
378 1.2 fvdl /*
379 1.2 fvdl * The 50 pin connector is a separate bus,
380 1.2 fvdl * so force it to always be terminated.
381 1.2 fvdl * In the future, perform current sensing
382 1.2 fvdl * to determine if we are in the middle of
383 1.2 fvdl * a properly terminated bus.
384 1.2 fvdl */
385 1.2 fvdl internal50_present = 0;
386 1.2 fvdl }
387 1.2 fvdl
388 1.2 fvdl /*
389 1.2 fvdl * Now set the termination based on what
390 1.2 fvdl * we found.
391 1.2 fvdl * Flash Enable = BRDDAT7
392 1.2 fvdl * Secondary High Term Enable = BRDDAT6
393 1.2 fvdl * Secondary Low Term Enable = BRDDAT5 (7890)
394 1.2 fvdl * Primary High Term Enable = BRDDAT4 (7890)
395 1.2 fvdl */
396 1.2 fvdl if ((ahc->features & AHC_ULTRA2) == 0
397 1.2 fvdl && (internal50_present != 0)
398 1.2 fvdl && (internal68_present != 0)
399 1.2 fvdl && (externalcable_present != 0)) {
400 1.2 fvdl printf("%s: Illegal cable configuration!!. "
401 1.2 fvdl "Only two connectors on the "
402 1.2 fvdl "adapter may be used at a "
403 1.2 fvdl "time!\n", ahc_name(ahc));
404 1.2 fvdl }
405 1.2 fvdl
406 1.2 fvdl if ((ahc->features & AHC_WIDE) != 0
407 1.2 fvdl && ((externalcable_present == 0)
408 1.2 fvdl || (internal68_present == 0)
409 1.2 fvdl || (enableSEC_high != 0))) {
410 1.2 fvdl brddat |= BRDDAT6;
411 1.2 fvdl if (bootverbose) {
412 1.2 fvdl if ((ahc->flags & AHC_INT50_SPEEDFLEX) != 0)
413 1.2 fvdl printf("%s: 68 pin termination "
414 1.2 fvdl "Enabled\n", ahc_name(ahc));
415 1.2 fvdl else
416 1.2 fvdl printf("%s: %sHigh byte termination "
417 1.2 fvdl "Enabled\n", ahc_name(ahc),
418 1.2 fvdl enableSEC_high ? "Secondary "
419 1.2 fvdl : "");
420 1.2 fvdl }
421 1.2 fvdl }
422 1.2 fvdl
423 1.2 fvdl if (((internal50_present ? 1 : 0)
424 1.2 fvdl + (internal68_present ? 1 : 0)
425 1.2 fvdl + (externalcable_present ? 1 : 0)) <= 1
426 1.2 fvdl || (enableSEC_low != 0)) {
427 1.2 fvdl if ((ahc->features & AHC_ULTRA2) != 0)
428 1.2 fvdl brddat |= BRDDAT5;
429 1.2 fvdl else
430 1.2 fvdl *sxfrctl1 |= STPWEN;
431 1.2 fvdl if (bootverbose) {
432 1.2 fvdl if ((ahc->flags & AHC_INT50_SPEEDFLEX) != 0)
433 1.2 fvdl printf("%s: 50 pin termination "
434 1.2 fvdl "Enabled\n", ahc_name(ahc));
435 1.2 fvdl else
436 1.2 fvdl printf("%s: %sLow byte termination "
437 1.2 fvdl "Enabled\n", ahc_name(ahc),
438 1.2 fvdl enableSEC_low ? "Secondary "
439 1.2 fvdl : "");
440 1.2 fvdl }
441 1.2 fvdl }
442 1.2 fvdl
443 1.2 fvdl if (enablePRI_low != 0) {
444 1.2 fvdl *sxfrctl1 |= STPWEN;
445 1.2 fvdl if (bootverbose)
446 1.2 fvdl printf("%s: Primary Low Byte termination "
447 1.2 fvdl "Enabled\n", ahc_name(ahc));
448 1.2 fvdl }
449 1.2 fvdl
450 1.2 fvdl /*
451 1.2 fvdl * Setup STPWEN before setting up the rest of
452 1.2 fvdl * the termination per the tech note on the U160 cards.
453 1.2 fvdl */
454 1.2 fvdl ahc_outb(ahc, SXFRCTL1, *sxfrctl1);
455 1.2 fvdl
456 1.2 fvdl if (enablePRI_high != 0) {
457 1.2 fvdl brddat |= BRDDAT4;
458 1.2 fvdl if (bootverbose)
459 1.2 fvdl printf("%s: Primary High Byte "
460 1.2 fvdl "termination Enabled\n",
461 1.2 fvdl ahc_name(ahc));
462 1.2 fvdl }
463 1.2 fvdl
464 1.2 fvdl write_brdctl(ahc, brddat);
465 1.2 fvdl
466 1.2 fvdl } else {
467 1.2 fvdl if ((adapter_control & CFSTERM) != 0) {
468 1.2 fvdl *sxfrctl1 |= STPWEN;
469 1.2 fvdl
470 1.2 fvdl if (bootverbose)
471 1.2 fvdl printf("%s: %sLow byte termination Enabled\n",
472 1.2 fvdl ahc_name(ahc),
473 1.2 fvdl (ahc->features & AHC_ULTRA2) ? "Primary "
474 1.2 fvdl : "");
475 1.2 fvdl }
476 1.2 fvdl
477 1.2 fvdl if ((adapter_control & CFWSTERM) != 0) {
478 1.2 fvdl brddat |= BRDDAT6;
479 1.2 fvdl if (bootverbose)
480 1.2 fvdl printf("%s: %sHigh byte termination Enabled\n",
481 1.2 fvdl ahc_name(ahc),
482 1.2 fvdl (ahc->features & AHC_ULTRA2)
483 1.2 fvdl ? "Secondary " : "");
484 1.2 fvdl }
485 1.2 fvdl
486 1.2 fvdl /*
487 1.2 fvdl * Setup STPWEN before setting up the rest of
488 1.2 fvdl * the termination per the tech note on the U160 cards.
489 1.2 fvdl */
490 1.2 fvdl ahc_outb(ahc, SXFRCTL1, *sxfrctl1);
491 1.2 fvdl
492 1.2 fvdl write_brdctl(ahc, brddat);
493 1.1 thorpej }
494 1.2 fvdl SEEPROM_OUTB(sd, sd->sd_MS); /* Clear CS */
495 1.2 fvdl }
496 1.2 fvdl
497 1.2 fvdl static void
498 1.2 fvdl ahc_new_term_detect(struct ahc_softc *ahc, int *enableSEC_low,
499 1.2 fvdl int *enableSEC_high, int *enablePRI_low,
500 1.2 fvdl int *enablePRI_high, int *eeprom_present)
501 1.2 fvdl {
502 1.2 fvdl u_int8_t brdctl;
503 1.2 fvdl
504 1.2 fvdl /*
505 1.2 fvdl * BRDDAT7 = Eeprom
506 1.2 fvdl * BRDDAT6 = Enable Secondary High Byte termination
507 1.2 fvdl * BRDDAT5 = Enable Secondary Low Byte termination
508 1.2 fvdl * BRDDAT4 = Enable Primary high byte termination
509 1.2 fvdl * BRDDAT3 = Enable Primary low byte termination
510 1.2 fvdl */
511 1.2 fvdl brdctl = read_brdctl(ahc);
512 1.2 fvdl *eeprom_present = brdctl & BRDDAT7;
513 1.2 fvdl *enableSEC_high = (brdctl & BRDDAT6);
514 1.2 fvdl *enableSEC_low = (brdctl & BRDDAT5);
515 1.2 fvdl *enablePRI_high = (brdctl & BRDDAT4);
516 1.2 fvdl *enablePRI_low = (brdctl & BRDDAT3);
517 1.2 fvdl }
518 1.2 fvdl
519 1.2 fvdl static void
520 1.2 fvdl aic787X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
521 1.2 fvdl int *internal68_present, int *externalcable_present,
522 1.2 fvdl int *eeprom_present)
523 1.2 fvdl {
524 1.2 fvdl u_int8_t brdctl;
525 1.2 fvdl
526 1.2 fvdl /*
527 1.2 fvdl * First read the status of our cables.
528 1.2 fvdl * Set the rom bank to 0 since the
529 1.2 fvdl * bank setting serves as a multiplexor
530 1.2 fvdl * for the cable detection logic.
531 1.2 fvdl * BRDDAT5 controls the bank switch.
532 1.2 fvdl */
533 1.2 fvdl write_brdctl(ahc, 0);
534 1.2 fvdl
535 1.2 fvdl /*
536 1.2 fvdl * Now read the state of the internal
537 1.2 fvdl * connectors. BRDDAT6 is INT50 and
538 1.2 fvdl * BRDDAT7 is INT68.
539 1.2 fvdl */
540 1.2 fvdl brdctl = read_brdctl(ahc);
541 1.2 fvdl *internal50_present = !(brdctl & BRDDAT6);
542 1.2 fvdl *internal68_present = !(brdctl & BRDDAT7);
543 1.2 fvdl
544 1.2 fvdl /*
545 1.2 fvdl * Set the rom bank to 1 and determine
546 1.2 fvdl * the other signals.
547 1.2 fvdl */
548 1.2 fvdl write_brdctl(ahc, BRDDAT5);
549 1.2 fvdl
550 1.2 fvdl /*
551 1.2 fvdl * Now read the state of the external
552 1.2 fvdl * connectors. BRDDAT6 is EXT68 and
553 1.2 fvdl * BRDDAT7 is EPROMPS.
554 1.2 fvdl */
555 1.2 fvdl brdctl = read_brdctl(ahc);
556 1.2 fvdl *externalcable_present = !(brdctl & BRDDAT6);
557 1.2 fvdl *eeprom_present = brdctl & BRDDAT7;
558 1.1 thorpej }
559 1.1 thorpej
560 1.2 fvdl static void
561 1.2 fvdl aic785X_cable_detect(struct ahc_softc *ahc, int *internal50_present,
562 1.2 fvdl int *externalcable_present, int *eeprom_present)
563 1.2 fvdl {
564 1.2 fvdl u_int8_t brdctl;
565 1.2 fvdl
566 1.2 fvdl ahc_outb(ahc, BRDCTL, BRDRW|BRDCS);
567 1.2 fvdl ahc_outb(ahc, BRDCTL, 0);
568 1.2 fvdl brdctl = ahc_inb(ahc, BRDCTL);
569 1.2 fvdl *internal50_present = !(brdctl & BRDDAT5);
570 1.2 fvdl *externalcable_present = !(brdctl & BRDDAT6);
571 1.2 fvdl
572 1.2 fvdl *eeprom_present = (ahc_inb(ahc, SPIOCAP) & EEPROM) != 0;
573 1.2 fvdl }
574 1.2 fvdl
575 1.2 fvdl static int
576 1.2 fvdl acquire_seeprom(struct ahc_softc *ahc, struct seeprom_descriptor *sd)
577 1.1 thorpej {
578 1.1 thorpej int wait;
579 1.1 thorpej
580 1.2 fvdl if ((ahc->features & AHC_SPIOCAP) != 0
581 1.2 fvdl && (ahc_inb(ahc, SPIOCAP) & SEEPROM) == 0)
582 1.2 fvdl return (0);
583 1.2 fvdl
584 1.1 thorpej /*
585 1.1 thorpej * Request access of the memory port. When access is
586 1.3 soren * granted, SEERDY will go high. We use a 100 msec
587 1.3 soren * timeout which should be near 100 msecs more than
588 1.1 thorpej * is needed. Reason: after the chip reset, there
589 1.1 thorpej * should be no contention.
590 1.1 thorpej */
591 1.1 thorpej SEEPROM_OUTB(sd, sd->sd_MS);
592 1.3 soren wait = 100; /* 100 msec timeout */
593 1.2 fvdl while (--wait && ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0)) {
594 1.2 fvdl DELAY(1000); /* delay 1 msec */
595 1.2 fvdl }
596 1.2 fvdl if ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0) {
597 1.1 thorpej SEEPROM_OUTB(sd, 0);
598 1.1 thorpej return (0);
599 1.2 fvdl }
600 1.1 thorpej return(1);
601 1.1 thorpej }
602 1.1 thorpej
603 1.2 fvdl static void
604 1.5 lukem release_seeprom(struct seeprom_descriptor *sd)
605 1.1 thorpej {
606 1.1 thorpej /* Release access to the memory port and the serial EEPROM. */
607 1.1 thorpej SEEPROM_OUTB(sd, 0);
608 1.2 fvdl }
609 1.2 fvdl
610 1.2 fvdl static void
611 1.5 lukem write_brdctl(struct ahc_softc *ahc, u_int8_t value)
612 1.2 fvdl {
613 1.2 fvdl u_int8_t brdctl;
614 1.2 fvdl
615 1.2 fvdl if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7895) {
616 1.2 fvdl brdctl = BRDSTB;
617 1.2 fvdl if (ahc->channel == 'B')
618 1.2 fvdl brdctl |= BRDCS;
619 1.2 fvdl } else if ((ahc->features & AHC_ULTRA2) != 0) {
620 1.2 fvdl brdctl = 0;
621 1.2 fvdl } else {
622 1.2 fvdl brdctl = BRDSTB|BRDCS;
623 1.2 fvdl }
624 1.2 fvdl ahc_outb(ahc, BRDCTL, brdctl);
625 1.2 fvdl DELAY(20);
626 1.2 fvdl brdctl |= value;
627 1.2 fvdl ahc_outb(ahc, BRDCTL, brdctl);
628 1.2 fvdl DELAY(20);
629 1.2 fvdl if ((ahc->features & AHC_ULTRA2) != 0)
630 1.2 fvdl brdctl |= BRDSTB_ULTRA2;
631 1.2 fvdl else
632 1.2 fvdl brdctl &= ~BRDSTB;
633 1.2 fvdl ahc_outb(ahc, BRDCTL, brdctl);
634 1.2 fvdl DELAY(20);
635 1.2 fvdl if ((ahc->features & AHC_ULTRA2) != 0)
636 1.2 fvdl brdctl = 0;
637 1.2 fvdl else
638 1.2 fvdl brdctl &= ~BRDCS;
639 1.2 fvdl ahc_outb(ahc, BRDCTL, brdctl);
640 1.2 fvdl }
641 1.2 fvdl
642 1.2 fvdl static u_int8_t
643 1.5 lukem read_brdctl(struct ahc_softc *ahc)
644 1.2 fvdl {
645 1.2 fvdl u_int8_t brdctl;
646 1.2 fvdl u_int8_t value;
647 1.2 fvdl
648 1.2 fvdl if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7895) {
649 1.2 fvdl brdctl = BRDRW;
650 1.2 fvdl if (ahc->channel == 'B')
651 1.2 fvdl brdctl |= BRDCS;
652 1.2 fvdl } else if ((ahc->features & AHC_ULTRA2) != 0) {
653 1.2 fvdl brdctl = BRDRW_ULTRA2;
654 1.2 fvdl } else {
655 1.2 fvdl brdctl = BRDRW|BRDCS;
656 1.2 fvdl }
657 1.2 fvdl ahc_outb(ahc, BRDCTL, brdctl);
658 1.2 fvdl DELAY(20);
659 1.2 fvdl value = ahc_inb(ahc, BRDCTL);
660 1.2 fvdl ahc_outb(ahc, BRDCTL, 0);
661 1.2 fvdl return (value);
662 1.1 thorpej }
663