18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Product specific probe and attach routines for:
38c2ecf20Sopenharmony_ci * 	27/284X and aic7770 motherboard SCSI controllers
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 1994-1998, 2000, 2001 Justin T. Gibbs.
68c2ecf20Sopenharmony_ci * All rights reserved.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
98c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
108c2ecf20Sopenharmony_ci * are met:
118c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
128c2ecf20Sopenharmony_ci *    notice, this list of conditions, and the following disclaimer,
138c2ecf20Sopenharmony_ci *    without modification.
148c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer
158c2ecf20Sopenharmony_ci *    substantially similar to the "NO WARRANTY" disclaimer below
168c2ecf20Sopenharmony_ci *    ("Disclaimer") and any redistribution must be conditioned upon
178c2ecf20Sopenharmony_ci *    including a substantially similar Disclaimer requirement for further
188c2ecf20Sopenharmony_ci *    binary redistribution.
198c2ecf20Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names
208c2ecf20Sopenharmony_ci *    of any contributors may be used to endorse or promote products derived
218c2ecf20Sopenharmony_ci *    from this software without specific prior written permission.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
248c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
258c2ecf20Sopenharmony_ci * Software Foundation.
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * NO WARRANTY
288c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
298c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
308c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
318c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
328c2ecf20Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
338c2ecf20Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
348c2ecf20Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
358c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
368c2ecf20Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
378c2ecf20Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
388c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES.
398c2ecf20Sopenharmony_ci *
408c2ecf20Sopenharmony_ci * $Id: //depot/aic7xxx/aic7xxx/aic7770.c#32 $
418c2ecf20Sopenharmony_ci *
428c2ecf20Sopenharmony_ci * $FreeBSD$
438c2ecf20Sopenharmony_ci */
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#include "aic7xxx_osm.h"
468c2ecf20Sopenharmony_ci#include "aic7xxx_inline.h"
478c2ecf20Sopenharmony_ci#include "aic7xxx_93cx6.h"
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define ID_AIC7770	0x04907770
508c2ecf20Sopenharmony_ci#define ID_AHA_274x	0x04907771
518c2ecf20Sopenharmony_ci#define ID_AHA_284xB	0x04907756 /* BIOS enabled */
528c2ecf20Sopenharmony_ci#define ID_AHA_284x	0x04907757 /* BIOS disabled*/
538c2ecf20Sopenharmony_ci#define	ID_OLV_274x	0x04907782 /* Olivetti OEM */
548c2ecf20Sopenharmony_ci#define	ID_OLV_274xD	0x04907783 /* Olivetti OEM (Differential) */
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic int aic7770_chip_init(struct ahc_softc *ahc);
578c2ecf20Sopenharmony_cistatic int aha2840_load_seeprom(struct ahc_softc *ahc);
588c2ecf20Sopenharmony_cistatic ahc_device_setup_t ahc_aic7770_VL_setup;
598c2ecf20Sopenharmony_cistatic ahc_device_setup_t ahc_aic7770_EISA_setup;
608c2ecf20Sopenharmony_cistatic ahc_device_setup_t ahc_aic7770_setup;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistruct aic7770_identity aic7770_ident_table[] =
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	{
658c2ecf20Sopenharmony_ci		ID_AHA_274x,
668c2ecf20Sopenharmony_ci		0xFFFFFFFF,
678c2ecf20Sopenharmony_ci		"Adaptec 274X SCSI adapter",
688c2ecf20Sopenharmony_ci		ahc_aic7770_EISA_setup
698c2ecf20Sopenharmony_ci	},
708c2ecf20Sopenharmony_ci	{
718c2ecf20Sopenharmony_ci		ID_AHA_284xB,
728c2ecf20Sopenharmony_ci		0xFFFFFFFE,
738c2ecf20Sopenharmony_ci		"Adaptec 284X SCSI adapter",
748c2ecf20Sopenharmony_ci		ahc_aic7770_VL_setup
758c2ecf20Sopenharmony_ci	},
768c2ecf20Sopenharmony_ci	{
778c2ecf20Sopenharmony_ci		ID_AHA_284x,
788c2ecf20Sopenharmony_ci		0xFFFFFFFE,
798c2ecf20Sopenharmony_ci		"Adaptec 284X SCSI adapter (BIOS Disabled)",
808c2ecf20Sopenharmony_ci		ahc_aic7770_VL_setup
818c2ecf20Sopenharmony_ci	},
828c2ecf20Sopenharmony_ci	{
838c2ecf20Sopenharmony_ci		ID_OLV_274x,
848c2ecf20Sopenharmony_ci		0xFFFFFFFF,
858c2ecf20Sopenharmony_ci		"Adaptec (Olivetti OEM) 274X SCSI adapter",
868c2ecf20Sopenharmony_ci		ahc_aic7770_EISA_setup
878c2ecf20Sopenharmony_ci	},
888c2ecf20Sopenharmony_ci	{
898c2ecf20Sopenharmony_ci		ID_OLV_274xD,
908c2ecf20Sopenharmony_ci		0xFFFFFFFF,
918c2ecf20Sopenharmony_ci		"Adaptec (Olivetti OEM) 274X Differential SCSI adapter",
928c2ecf20Sopenharmony_ci		ahc_aic7770_EISA_setup
938c2ecf20Sopenharmony_ci	},
948c2ecf20Sopenharmony_ci	/* Generic chip probes for devices we don't know 'exactly' */
958c2ecf20Sopenharmony_ci	{
968c2ecf20Sopenharmony_ci		ID_AIC7770,
978c2ecf20Sopenharmony_ci		0xFFFFFFFF,
988c2ecf20Sopenharmony_ci		"Adaptec aic7770 SCSI adapter",
998c2ecf20Sopenharmony_ci		ahc_aic7770_EISA_setup
1008c2ecf20Sopenharmony_ci	}
1018c2ecf20Sopenharmony_ci};
1028c2ecf20Sopenharmony_ciconst int ahc_num_aic7770_devs = ARRAY_SIZE(aic7770_ident_table);
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistruct aic7770_identity *
1058c2ecf20Sopenharmony_ciaic7770_find_device(uint32_t id)
1068c2ecf20Sopenharmony_ci{
1078c2ecf20Sopenharmony_ci	struct	aic7770_identity *entry;
1088c2ecf20Sopenharmony_ci	int	i;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	for (i = 0; i < ahc_num_aic7770_devs; i++) {
1118c2ecf20Sopenharmony_ci		entry = &aic7770_ident_table[i];
1128c2ecf20Sopenharmony_ci		if (entry->full_id == (id & entry->id_mask))
1138c2ecf20Sopenharmony_ci			return (entry);
1148c2ecf20Sopenharmony_ci	}
1158c2ecf20Sopenharmony_ci	return (NULL);
1168c2ecf20Sopenharmony_ci}
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ciint
1198c2ecf20Sopenharmony_ciaic7770_config(struct ahc_softc *ahc, struct aic7770_identity *entry, u_int io)
1208c2ecf20Sopenharmony_ci{
1218c2ecf20Sopenharmony_ci	int	error;
1228c2ecf20Sopenharmony_ci	int	have_seeprom;
1238c2ecf20Sopenharmony_ci	u_int	hostconf;
1248c2ecf20Sopenharmony_ci	u_int   irq;
1258c2ecf20Sopenharmony_ci	u_int	intdef;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	error = entry->setup(ahc);
1288c2ecf20Sopenharmony_ci	have_seeprom = 0;
1298c2ecf20Sopenharmony_ci	if (error != 0)
1308c2ecf20Sopenharmony_ci		return (error);
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	error = aic7770_map_registers(ahc, io);
1338c2ecf20Sopenharmony_ci	if (error != 0)
1348c2ecf20Sopenharmony_ci		return (error);
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	/*
1378c2ecf20Sopenharmony_ci	 * Before we continue probing the card, ensure that
1388c2ecf20Sopenharmony_ci	 * its interrupts are *disabled*.  We don't want
1398c2ecf20Sopenharmony_ci	 * a misstep to hang the machine in an interrupt
1408c2ecf20Sopenharmony_ci	 * storm.
1418c2ecf20Sopenharmony_ci	 */
1428c2ecf20Sopenharmony_ci	ahc_intr_enable(ahc, FALSE);
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	ahc->description = entry->name;
1458c2ecf20Sopenharmony_ci	error = ahc_softc_init(ahc);
1468c2ecf20Sopenharmony_ci	if (error != 0)
1478c2ecf20Sopenharmony_ci		return (error);
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	ahc->bus_chip_init = aic7770_chip_init;
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	error = ahc_reset(ahc, /*reinit*/FALSE);
1528c2ecf20Sopenharmony_ci	if (error != 0)
1538c2ecf20Sopenharmony_ci		return (error);
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	/* Make sure we have a valid interrupt vector */
1568c2ecf20Sopenharmony_ci	intdef = ahc_inb(ahc, INTDEF);
1578c2ecf20Sopenharmony_ci	irq = intdef & VECTOR;
1588c2ecf20Sopenharmony_ci	switch (irq) {
1598c2ecf20Sopenharmony_ci	case 9:
1608c2ecf20Sopenharmony_ci	case 10:
1618c2ecf20Sopenharmony_ci	case 11:
1628c2ecf20Sopenharmony_ci	case 12:
1638c2ecf20Sopenharmony_ci	case 14:
1648c2ecf20Sopenharmony_ci	case 15:
1658c2ecf20Sopenharmony_ci		break;
1668c2ecf20Sopenharmony_ci	default:
1678c2ecf20Sopenharmony_ci		printk("aic7770_config: invalid irq setting %d\n", intdef);
1688c2ecf20Sopenharmony_ci		return (ENXIO);
1698c2ecf20Sopenharmony_ci	}
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	if ((intdef & EDGE_TRIG) != 0)
1728c2ecf20Sopenharmony_ci		ahc->flags |= AHC_EDGE_INTERRUPT;
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	switch (ahc->chip & (AHC_EISA|AHC_VL)) {
1758c2ecf20Sopenharmony_ci	case AHC_EISA:
1768c2ecf20Sopenharmony_ci	{
1778c2ecf20Sopenharmony_ci		u_int biosctrl;
1788c2ecf20Sopenharmony_ci		u_int scsiconf;
1798c2ecf20Sopenharmony_ci		u_int scsiconf1;
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci		biosctrl = ahc_inb(ahc, HA_274_BIOSCTRL);
1828c2ecf20Sopenharmony_ci		scsiconf = ahc_inb(ahc, SCSICONF);
1838c2ecf20Sopenharmony_ci		scsiconf1 = ahc_inb(ahc, SCSICONF + 1);
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci		/* Get the primary channel information */
1868c2ecf20Sopenharmony_ci		if ((biosctrl & CHANNEL_B_PRIMARY) != 0)
1878c2ecf20Sopenharmony_ci			ahc->flags |= 1;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci		if ((biosctrl & BIOSMODE) == BIOSDISABLED) {
1908c2ecf20Sopenharmony_ci			ahc->flags |= AHC_USEDEFAULTS;
1918c2ecf20Sopenharmony_ci		} else {
1928c2ecf20Sopenharmony_ci			if ((ahc->features & AHC_WIDE) != 0) {
1938c2ecf20Sopenharmony_ci				ahc->our_id = scsiconf1 & HWSCSIID;
1948c2ecf20Sopenharmony_ci				if (scsiconf & TERM_ENB)
1958c2ecf20Sopenharmony_ci					ahc->flags |= AHC_TERM_ENB_A;
1968c2ecf20Sopenharmony_ci			} else {
1978c2ecf20Sopenharmony_ci				ahc->our_id = scsiconf & HSCSIID;
1988c2ecf20Sopenharmony_ci				ahc->our_id_b = scsiconf1 & HSCSIID;
1998c2ecf20Sopenharmony_ci				if (scsiconf & TERM_ENB)
2008c2ecf20Sopenharmony_ci					ahc->flags |= AHC_TERM_ENB_A;
2018c2ecf20Sopenharmony_ci				if (scsiconf1 & TERM_ENB)
2028c2ecf20Sopenharmony_ci					ahc->flags |= AHC_TERM_ENB_B;
2038c2ecf20Sopenharmony_ci			}
2048c2ecf20Sopenharmony_ci		}
2058c2ecf20Sopenharmony_ci		if ((ahc_inb(ahc, HA_274_BIOSGLOBAL) & HA_274_EXTENDED_TRANS))
2068c2ecf20Sopenharmony_ci			ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B;
2078c2ecf20Sopenharmony_ci		break;
2088c2ecf20Sopenharmony_ci	}
2098c2ecf20Sopenharmony_ci	case AHC_VL:
2108c2ecf20Sopenharmony_ci	{
2118c2ecf20Sopenharmony_ci		have_seeprom = aha2840_load_seeprom(ahc);
2128c2ecf20Sopenharmony_ci		break;
2138c2ecf20Sopenharmony_ci	}
2148c2ecf20Sopenharmony_ci	default:
2158c2ecf20Sopenharmony_ci		break;
2168c2ecf20Sopenharmony_ci	}
2178c2ecf20Sopenharmony_ci	if (have_seeprom == 0) {
2188c2ecf20Sopenharmony_ci		kfree(ahc->seep_config);
2198c2ecf20Sopenharmony_ci		ahc->seep_config = NULL;
2208c2ecf20Sopenharmony_ci	}
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci	/*
2238c2ecf20Sopenharmony_ci	 * Ensure autoflush is enabled
2248c2ecf20Sopenharmony_ci	 */
2258c2ecf20Sopenharmony_ci	ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~AUTOFLUSHDIS);
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	/* Setup the FIFO threshold and the bus off time */
2288c2ecf20Sopenharmony_ci	hostconf = ahc_inb(ahc, HOSTCONF);
2298c2ecf20Sopenharmony_ci	ahc_outb(ahc, BUSSPD, hostconf & DFTHRSH);
2308c2ecf20Sopenharmony_ci	ahc_outb(ahc, BUSTIME, (hostconf << 2) & BOFF);
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	ahc->bus_softc.aic7770_softc.busspd = hostconf & DFTHRSH;
2338c2ecf20Sopenharmony_ci	ahc->bus_softc.aic7770_softc.bustime = (hostconf << 2) & BOFF;
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci	/*
2368c2ecf20Sopenharmony_ci	 * Generic aic7xxx initialization.
2378c2ecf20Sopenharmony_ci	 */
2388c2ecf20Sopenharmony_ci	error = ahc_init(ahc);
2398c2ecf20Sopenharmony_ci	if (error != 0)
2408c2ecf20Sopenharmony_ci		return (error);
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci	error = aic7770_map_int(ahc, irq);
2438c2ecf20Sopenharmony_ci	if (error != 0)
2448c2ecf20Sopenharmony_ci		return (error);
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci	ahc->init_level++;
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	/*
2498c2ecf20Sopenharmony_ci	 * Enable the board's BUS drivers
2508c2ecf20Sopenharmony_ci	 */
2518c2ecf20Sopenharmony_ci	ahc_outb(ahc, BCTL, ENABLE);
2528c2ecf20Sopenharmony_ci	return (0);
2538c2ecf20Sopenharmony_ci}
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_cistatic int
2568c2ecf20Sopenharmony_ciaic7770_chip_init(struct ahc_softc *ahc)
2578c2ecf20Sopenharmony_ci{
2588c2ecf20Sopenharmony_ci	ahc_outb(ahc, BUSSPD, ahc->bus_softc.aic7770_softc.busspd);
2598c2ecf20Sopenharmony_ci	ahc_outb(ahc, BUSTIME, ahc->bus_softc.aic7770_softc.bustime);
2608c2ecf20Sopenharmony_ci	ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~AUTOFLUSHDIS);
2618c2ecf20Sopenharmony_ci	ahc_outb(ahc, BCTL, ENABLE);
2628c2ecf20Sopenharmony_ci	return (ahc_chip_init(ahc));
2638c2ecf20Sopenharmony_ci}
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci/*
2668c2ecf20Sopenharmony_ci * Read the 284x SEEPROM.
2678c2ecf20Sopenharmony_ci */
2688c2ecf20Sopenharmony_cistatic int
2698c2ecf20Sopenharmony_ciaha2840_load_seeprom(struct ahc_softc *ahc)
2708c2ecf20Sopenharmony_ci{
2718c2ecf20Sopenharmony_ci	struct	seeprom_descriptor sd;
2728c2ecf20Sopenharmony_ci	struct	seeprom_config *sc;
2738c2ecf20Sopenharmony_ci	int	have_seeprom;
2748c2ecf20Sopenharmony_ci	uint8_t scsi_conf;
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	sd.sd_ahc = ahc;
2778c2ecf20Sopenharmony_ci	sd.sd_control_offset = SEECTL_2840;
2788c2ecf20Sopenharmony_ci	sd.sd_status_offset = STATUS_2840;
2798c2ecf20Sopenharmony_ci	sd.sd_dataout_offset = STATUS_2840;
2808c2ecf20Sopenharmony_ci	sd.sd_chip = C46;
2818c2ecf20Sopenharmony_ci	sd.sd_MS = 0;
2828c2ecf20Sopenharmony_ci	sd.sd_RDY = EEPROM_TF;
2838c2ecf20Sopenharmony_ci	sd.sd_CS = CS_2840;
2848c2ecf20Sopenharmony_ci	sd.sd_CK = CK_2840;
2858c2ecf20Sopenharmony_ci	sd.sd_DO = DO_2840;
2868c2ecf20Sopenharmony_ci	sd.sd_DI = DI_2840;
2878c2ecf20Sopenharmony_ci	sc = ahc->seep_config;
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci	if (bootverbose)
2908c2ecf20Sopenharmony_ci		printk("%s: Reading SEEPROM...", ahc_name(ahc));
2918c2ecf20Sopenharmony_ci	have_seeprom = ahc_read_seeprom(&sd, (uint16_t *)sc,
2928c2ecf20Sopenharmony_ci					/*start_addr*/0, sizeof(*sc)/2);
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	if (have_seeprom) {
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci		if (ahc_verify_cksum(sc) == 0) {
2978c2ecf20Sopenharmony_ci			if(bootverbose)
2988c2ecf20Sopenharmony_ci				printk ("checksum error\n");
2998c2ecf20Sopenharmony_ci			have_seeprom = 0;
3008c2ecf20Sopenharmony_ci		} else if (bootverbose) {
3018c2ecf20Sopenharmony_ci			printk("done.\n");
3028c2ecf20Sopenharmony_ci		}
3038c2ecf20Sopenharmony_ci	}
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	if (!have_seeprom) {
3068c2ecf20Sopenharmony_ci		if (bootverbose)
3078c2ecf20Sopenharmony_ci			printk("%s: No SEEPROM available\n", ahc_name(ahc));
3088c2ecf20Sopenharmony_ci		ahc->flags |= AHC_USEDEFAULTS;
3098c2ecf20Sopenharmony_ci	} else {
3108c2ecf20Sopenharmony_ci		/*
3118c2ecf20Sopenharmony_ci		 * Put the data we've collected down into SRAM
3128c2ecf20Sopenharmony_ci		 * where ahc_init will find it.
3138c2ecf20Sopenharmony_ci		 */
3148c2ecf20Sopenharmony_ci		int	 i;
3158c2ecf20Sopenharmony_ci		int	 max_targ;
3168c2ecf20Sopenharmony_ci		uint16_t discenable;
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci		max_targ = (ahc->features & AHC_WIDE) != 0 ? 16 : 8;
3198c2ecf20Sopenharmony_ci		discenable = 0;
3208c2ecf20Sopenharmony_ci		for (i = 0; i < max_targ; i++){
3218c2ecf20Sopenharmony_ci			uint8_t target_settings;
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci			target_settings = (sc->device_flags[i] & CFXFER) << 4;
3248c2ecf20Sopenharmony_ci			if (sc->device_flags[i] & CFSYNCH)
3258c2ecf20Sopenharmony_ci				target_settings |= SOFS;
3268c2ecf20Sopenharmony_ci			if (sc->device_flags[i] & CFWIDEB)
3278c2ecf20Sopenharmony_ci				target_settings |= WIDEXFER;
3288c2ecf20Sopenharmony_ci			if (sc->device_flags[i] & CFDISC)
3298c2ecf20Sopenharmony_ci				discenable |= (0x01 << i);
3308c2ecf20Sopenharmony_ci			ahc_outb(ahc, TARG_SCSIRATE + i, target_settings);
3318c2ecf20Sopenharmony_ci		}
3328c2ecf20Sopenharmony_ci		ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
3338c2ecf20Sopenharmony_ci		ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci		ahc->our_id = sc->brtime_id & CFSCSIID;
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci		scsi_conf = (ahc->our_id & 0x7);
3388c2ecf20Sopenharmony_ci		if (sc->adapter_control & CFSPARITY)
3398c2ecf20Sopenharmony_ci			scsi_conf |= ENSPCHK;
3408c2ecf20Sopenharmony_ci		if (sc->adapter_control & CFRESETB)
3418c2ecf20Sopenharmony_ci			scsi_conf |= RESET_SCSI;
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci		if (sc->bios_control & CF284XEXTEND)
3448c2ecf20Sopenharmony_ci			ahc->flags |= AHC_EXTENDED_TRANS_A;
3458c2ecf20Sopenharmony_ci		/* Set SCSICONF info */
3468c2ecf20Sopenharmony_ci		ahc_outb(ahc, SCSICONF, scsi_conf);
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci		if (sc->adapter_control & CF284XSTERM)
3498c2ecf20Sopenharmony_ci			ahc->flags |= AHC_TERM_ENB_A;
3508c2ecf20Sopenharmony_ci	}
3518c2ecf20Sopenharmony_ci	return (have_seeprom);
3528c2ecf20Sopenharmony_ci}
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_cistatic int
3558c2ecf20Sopenharmony_ciahc_aic7770_VL_setup(struct ahc_softc *ahc)
3568c2ecf20Sopenharmony_ci{
3578c2ecf20Sopenharmony_ci	int error;
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci	error = ahc_aic7770_setup(ahc);
3608c2ecf20Sopenharmony_ci	ahc->chip |= AHC_VL;
3618c2ecf20Sopenharmony_ci	return (error);
3628c2ecf20Sopenharmony_ci}
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_cistatic int
3658c2ecf20Sopenharmony_ciahc_aic7770_EISA_setup(struct ahc_softc *ahc)
3668c2ecf20Sopenharmony_ci{
3678c2ecf20Sopenharmony_ci	int error;
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	error = ahc_aic7770_setup(ahc);
3708c2ecf20Sopenharmony_ci	ahc->chip |= AHC_EISA;
3718c2ecf20Sopenharmony_ci	return (error);
3728c2ecf20Sopenharmony_ci}
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_cistatic int
3758c2ecf20Sopenharmony_ciahc_aic7770_setup(struct ahc_softc *ahc)
3768c2ecf20Sopenharmony_ci{
3778c2ecf20Sopenharmony_ci	ahc->channel = 'A';
3788c2ecf20Sopenharmony_ci	ahc->channel_b = 'B';
3798c2ecf20Sopenharmony_ci	ahc->chip = AHC_AIC7770;
3808c2ecf20Sopenharmony_ci	ahc->features = AHC_AIC7770_FE;
3818c2ecf20Sopenharmony_ci	ahc->bugs |= AHC_TMODE_WIDEODD_BUG;
3828c2ecf20Sopenharmony_ci	ahc->flags |= AHC_PAGESCBS;
3838c2ecf20Sopenharmony_ci	ahc->instruction_ram_size = 448;
3848c2ecf20Sopenharmony_ci	return (0);
3858c2ecf20Sopenharmony_ci}
386