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