18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Linux driver attachment glue for aic7770 based controllers.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (c) 2000-2003 Adaptec Inc.
58c2ecf20Sopenharmony_ci * All rights reserved.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
88c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
98c2ecf20Sopenharmony_ci * are met:
108c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
118c2ecf20Sopenharmony_ci *    notice, this list of conditions, and the following disclaimer,
128c2ecf20Sopenharmony_ci *    without modification.
138c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer
148c2ecf20Sopenharmony_ci *    substantially similar to the "NO WARRANTY" disclaimer below
158c2ecf20Sopenharmony_ci *    ("Disclaimer") and any redistribution must be conditioned upon
168c2ecf20Sopenharmony_ci *    including a substantially similar Disclaimer requirement for further
178c2ecf20Sopenharmony_ci *    binary redistribution.
188c2ecf20Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names
198c2ecf20Sopenharmony_ci *    of any contributors may be used to endorse or promote products derived
208c2ecf20Sopenharmony_ci *    from this software without specific prior written permission.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
238c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
248c2ecf20Sopenharmony_ci * Software Foundation.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci * NO WARRANTY
278c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
288c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
298c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
308c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
318c2ecf20Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
328c2ecf20Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
338c2ecf20Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
348c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
358c2ecf20Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
368c2ecf20Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
378c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES.
388c2ecf20Sopenharmony_ci *
398c2ecf20Sopenharmony_ci * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7770_osm.c#14 $
408c2ecf20Sopenharmony_ci */
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#include "aic7xxx_osm.h"
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#include <linux/device.h>
458c2ecf20Sopenharmony_ci#include <linux/eisa.h>
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciint
488c2ecf20Sopenharmony_ciaic7770_map_registers(struct ahc_softc *ahc, u_int port)
498c2ecf20Sopenharmony_ci{
508c2ecf20Sopenharmony_ci	/*
518c2ecf20Sopenharmony_ci	 * Lock out other contenders for our i/o space.
528c2ecf20Sopenharmony_ci	 */
538c2ecf20Sopenharmony_ci	if (!request_region(port, AHC_EISA_IOSIZE, "aic7xxx"))
548c2ecf20Sopenharmony_ci		return (ENOMEM);
558c2ecf20Sopenharmony_ci	ahc->tag = BUS_SPACE_PIO;
568c2ecf20Sopenharmony_ci	ahc->bsh.ioport = port;
578c2ecf20Sopenharmony_ci	return (0);
588c2ecf20Sopenharmony_ci}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ciint
618c2ecf20Sopenharmony_ciaic7770_map_int(struct ahc_softc *ahc, u_int irq)
628c2ecf20Sopenharmony_ci{
638c2ecf20Sopenharmony_ci	int error;
648c2ecf20Sopenharmony_ci	int shared;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	shared = 0;
678c2ecf20Sopenharmony_ci	if ((ahc->flags & AHC_EDGE_INTERRUPT) == 0)
688c2ecf20Sopenharmony_ci		shared = IRQF_SHARED;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	error = request_irq(irq, ahc_linux_isr, shared, "aic7xxx", ahc);
718c2ecf20Sopenharmony_ci	if (error == 0)
728c2ecf20Sopenharmony_ci		ahc->platform_data->irq = irq;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	return (-error);
758c2ecf20Sopenharmony_ci}
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_cistatic int
788c2ecf20Sopenharmony_ciaic7770_probe(struct device *dev)
798c2ecf20Sopenharmony_ci{
808c2ecf20Sopenharmony_ci	struct eisa_device *edev = to_eisa_device(dev);
818c2ecf20Sopenharmony_ci	u_int eisaBase = edev->base_addr+AHC_EISA_SLOT_OFFSET;
828c2ecf20Sopenharmony_ci	struct	ahc_softc *ahc;
838c2ecf20Sopenharmony_ci	char	buf[80];
848c2ecf20Sopenharmony_ci	char   *name;
858c2ecf20Sopenharmony_ci	int	error;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	sprintf(buf, "ahc_eisa:%d", eisaBase >> 12);
888c2ecf20Sopenharmony_ci	name = kstrdup(buf, GFP_ATOMIC);
898c2ecf20Sopenharmony_ci	if (name == NULL)
908c2ecf20Sopenharmony_ci		return (ENOMEM);
918c2ecf20Sopenharmony_ci	ahc = ahc_alloc(&aic7xxx_driver_template, name);
928c2ecf20Sopenharmony_ci	if (ahc == NULL)
938c2ecf20Sopenharmony_ci		return (ENOMEM);
948c2ecf20Sopenharmony_ci	ahc->dev = dev;
958c2ecf20Sopenharmony_ci	error = aic7770_config(ahc, aic7770_ident_table + edev->id.driver_data,
968c2ecf20Sopenharmony_ci			       eisaBase);
978c2ecf20Sopenharmony_ci	if (error != 0) {
988c2ecf20Sopenharmony_ci		ahc->bsh.ioport = 0;
998c2ecf20Sopenharmony_ci		ahc_free(ahc);
1008c2ecf20Sopenharmony_ci		return (error);
1018c2ecf20Sopenharmony_ci	}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci 	dev_set_drvdata(dev, ahc);
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	error = ahc_linux_register_host(ahc, &aic7xxx_driver_template);
1068c2ecf20Sopenharmony_ci	return (error);
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cistatic int
1108c2ecf20Sopenharmony_ciaic7770_remove(struct device *dev)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	struct ahc_softc *ahc = dev_get_drvdata(dev);
1138c2ecf20Sopenharmony_ci	u_long s;
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	if (ahc->platform_data && ahc->platform_data->host)
1168c2ecf20Sopenharmony_ci			scsi_remove_host(ahc->platform_data->host);
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	ahc_lock(ahc, &s);
1198c2ecf20Sopenharmony_ci	ahc_intr_enable(ahc, FALSE);
1208c2ecf20Sopenharmony_ci	ahc_unlock(ahc, &s);
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	ahc_free(ahc);
1238c2ecf20Sopenharmony_ci	return 0;
1248c2ecf20Sopenharmony_ci}
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistatic struct eisa_device_id aic7770_ids[] = {
1278c2ecf20Sopenharmony_ci	{ "ADP7771", 0 }, /* AHA 274x */
1288c2ecf20Sopenharmony_ci	{ "ADP7756", 1 }, /* AHA 284x BIOS enabled */
1298c2ecf20Sopenharmony_ci	{ "ADP7757", 2 }, /* AHA 284x BIOS disabled */
1308c2ecf20Sopenharmony_ci	{ "ADP7782", 3 }, /* AHA 274x Olivetti OEM */
1318c2ecf20Sopenharmony_ci	{ "ADP7783", 4 }, /* AHA 274x Olivetti OEM (Differential) */
1328c2ecf20Sopenharmony_ci	{ "ADP7770", 5 }, /* AIC7770 generic */
1338c2ecf20Sopenharmony_ci	{ "" }
1348c2ecf20Sopenharmony_ci};
1358c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(eisa, aic7770_ids);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistatic struct eisa_driver aic7770_driver = {
1388c2ecf20Sopenharmony_ci	.id_table	= aic7770_ids,
1398c2ecf20Sopenharmony_ci	.driver = {
1408c2ecf20Sopenharmony_ci		.name   = "aic7xxx",
1418c2ecf20Sopenharmony_ci		.probe  = aic7770_probe,
1428c2ecf20Sopenharmony_ci		.remove = aic7770_remove,
1438c2ecf20Sopenharmony_ci	}
1448c2ecf20Sopenharmony_ci};
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ciint
1478c2ecf20Sopenharmony_ciahc_linux_eisa_init(void)
1488c2ecf20Sopenharmony_ci{
1498c2ecf20Sopenharmony_ci	return eisa_driver_register(&aic7770_driver);
1508c2ecf20Sopenharmony_ci}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_civoid
1538c2ecf20Sopenharmony_ciahc_linux_eisa_exit(void)
1548c2ecf20Sopenharmony_ci{
1558c2ecf20Sopenharmony_ci	eisa_driver_unregister(&aic7770_driver);
1568c2ecf20Sopenharmony_ci}
157