xref: /linux/drivers/scsi/lasi700.c (revision 53f01bba49938f115237fe43a261c31ac13ae5c6)
11da177e4SLinus Torvalds /* -*- mode: c; c-basic-offset: 8 -*- */
21da177e4SLinus Torvalds 
31da177e4SLinus Torvalds /* PARISC LASI driver for the 53c700 chip
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
61da177e4SLinus Torvalds **-----------------------------------------------------------------------------
71da177e4SLinus Torvalds **
81da177e4SLinus Torvalds **  This program is free software; you can redistribute it and/or modify
91da177e4SLinus Torvalds **  it under the terms of the GNU General Public License as published by
101da177e4SLinus Torvalds **  the Free Software Foundation; either version 2 of the License, or
111da177e4SLinus Torvalds **  (at your option) any later version.
121da177e4SLinus Torvalds **
131da177e4SLinus Torvalds **  This program is distributed in the hope that it will be useful,
141da177e4SLinus Torvalds **  but WITHOUT ANY WARRANTY; without even the implied warranty of
151da177e4SLinus Torvalds **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161da177e4SLinus Torvalds **  GNU General Public License for more details.
171da177e4SLinus Torvalds **
181da177e4SLinus Torvalds **  You should have received a copy of the GNU General Public License
191da177e4SLinus Torvalds **  along with this program; if not, write to the Free Software
201da177e4SLinus Torvalds **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
211da177e4SLinus Torvalds **
221da177e4SLinus Torvalds **-----------------------------------------------------------------------------
231da177e4SLinus Torvalds  */
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds /*
261da177e4SLinus Torvalds  * Many thanks to Richard Hirst <rhirst@linuxcare.com> for patiently
271da177e4SLinus Torvalds  * debugging this driver on the parisc architecture and suggesting
281da177e4SLinus Torvalds  * many improvements and bug fixes.
291da177e4SLinus Torvalds  *
301da177e4SLinus Torvalds  * Thanks also go to Linuxcare Inc. for providing several PARISC
311da177e4SLinus Torvalds  * machines for me to debug the driver on.
321da177e4SLinus Torvalds  */
331da177e4SLinus Torvalds 
341da177e4SLinus Torvalds #include <linux/kernel.h>
351da177e4SLinus Torvalds #include <linux/module.h>
361da177e4SLinus Torvalds #include <linux/init.h>
371da177e4SLinus Torvalds #include <linux/types.h>
381da177e4SLinus Torvalds #include <linux/stat.h>
391da177e4SLinus Torvalds #include <linux/mm.h>
401da177e4SLinus Torvalds #include <linux/blkdev.h>
411da177e4SLinus Torvalds #include <linux/sched.h>
421da177e4SLinus Torvalds #include <linux/ioport.h>
431da177e4SLinus Torvalds #include <linux/dma-mapping.h>
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds #include <asm/page.h>
461da177e4SLinus Torvalds #include <asm/pgtable.h>
471da177e4SLinus Torvalds #include <asm/irq.h>
481da177e4SLinus Torvalds #include <asm/hardware.h>
491da177e4SLinus Torvalds #include <asm/parisc-device.h>
501da177e4SLinus Torvalds #include <asm/delay.h>
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds #include <scsi/scsi_host.h>
531da177e4SLinus Torvalds #include <scsi/scsi_device.h>
541da177e4SLinus Torvalds #include <scsi/scsi_transport.h>
551da177e4SLinus Torvalds #include <scsi/scsi_transport_spi.h>
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds #include "53c700.h"
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds MODULE_AUTHOR("James Bottomley");
601da177e4SLinus Torvalds MODULE_DESCRIPTION("lasi700 SCSI Driver");
611da177e4SLinus Torvalds MODULE_LICENSE("GPL");
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds #define LASI_700_SVERSION 0x00071
641da177e4SLinus Torvalds #define LASI_710_SVERSION 0x00082
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds #define LASI700_ID_TABLE {			\
671da177e4SLinus Torvalds 	.hw_type	= HPHW_FIO,		\
681da177e4SLinus Torvalds 	.sversion	= LASI_700_SVERSION,	\
691da177e4SLinus Torvalds 	.hversion	= HVERSION_ANY_ID,	\
701da177e4SLinus Torvalds 	.hversion_rev	= HVERSION_REV_ANY_ID,	\
711da177e4SLinus Torvalds }
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds #define LASI710_ID_TABLE {			\
741da177e4SLinus Torvalds 	.hw_type	= HPHW_FIO,		\
751da177e4SLinus Torvalds 	.sversion	= LASI_710_SVERSION,	\
761da177e4SLinus Torvalds 	.hversion	= HVERSION_ANY_ID,	\
771da177e4SLinus Torvalds 	.hversion_rev	= HVERSION_REV_ANY_ID,	\
781da177e4SLinus Torvalds }
791da177e4SLinus Torvalds 
801da177e4SLinus Torvalds #define LASI700_CLOCK	25
811da177e4SLinus Torvalds #define LASI710_CLOCK	40
821da177e4SLinus Torvalds #define LASI_SCSI_CORE_OFFSET 0x100
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds static struct parisc_device_id lasi700_ids[] = {
851da177e4SLinus Torvalds 	LASI700_ID_TABLE,
861da177e4SLinus Torvalds 	LASI710_ID_TABLE,
871da177e4SLinus Torvalds 	{ 0 }
881da177e4SLinus Torvalds };
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds static struct scsi_host_template lasi700_template = {
911da177e4SLinus Torvalds 	.name		= "LASI SCSI 53c700",
921da177e4SLinus Torvalds 	.proc_name	= "lasi700",
931da177e4SLinus Torvalds 	.this_id	= 7,
941da177e4SLinus Torvalds 	.module		= THIS_MODULE,
951da177e4SLinus Torvalds };
961da177e4SLinus Torvalds MODULE_DEVICE_TABLE(parisc, lasi700_ids);
971da177e4SLinus Torvalds 
981da177e4SLinus Torvalds static int __init
991da177e4SLinus Torvalds lasi700_probe(struct parisc_device *dev)
1001da177e4SLinus Torvalds {
101*53f01bbaSMatthew Wilcox 	unsigned long base = dev->hpa.start + LASI_SCSI_CORE_OFFSET;
1021da177e4SLinus Torvalds 	struct NCR_700_Host_Parameters *hostdata;
1031da177e4SLinus Torvalds 	struct Scsi_Host *host;
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds 	hostdata = kmalloc(sizeof(*hostdata), GFP_KERNEL);
1061da177e4SLinus Torvalds 	if (!hostdata) {
1071da177e4SLinus Torvalds 		printk(KERN_ERR "%s: Failed to allocate host data\n",
1081da177e4SLinus Torvalds 		       dev->dev.bus_id);
1091da177e4SLinus Torvalds 		return -ENOMEM;
1101da177e4SLinus Torvalds 	}
1111da177e4SLinus Torvalds 	memset(hostdata, 0, sizeof(struct NCR_700_Host_Parameters));
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds 	hostdata->dev = &dev->dev;
1141da177e4SLinus Torvalds 	dma_set_mask(&dev->dev, DMA_32BIT_MASK);
1151da177e4SLinus Torvalds 	hostdata->base = ioremap(base, 0x100);
1161da177e4SLinus Torvalds 	hostdata->differential = 0;
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds 	if (dev->id.sversion == LASI_700_SVERSION) {
1191da177e4SLinus Torvalds 		hostdata->clock = LASI700_CLOCK;
1201da177e4SLinus Torvalds 		hostdata->force_le_on_be = 1;
1211da177e4SLinus Torvalds 	} else {
1221da177e4SLinus Torvalds 		hostdata->clock = LASI710_CLOCK;
1231da177e4SLinus Torvalds 		hostdata->force_le_on_be = 0;
1241da177e4SLinus Torvalds 		hostdata->chip710 = 1;
1251da177e4SLinus Torvalds 		hostdata->dmode_extra = DMODE_FC2;
1261da177e4SLinus Torvalds 	}
1271da177e4SLinus Torvalds 
1281da177e4SLinus Torvalds 	NCR_700_set_mem_mapped(hostdata);
1291da177e4SLinus Torvalds 
1301da177e4SLinus Torvalds 	host = NCR_700_detect(&lasi700_template, hostdata, &dev->dev);
1311da177e4SLinus Torvalds 	if (!host)
1321da177e4SLinus Torvalds 		goto out_kfree;
1331da177e4SLinus Torvalds 	host->this_id = 7;
13456fece20S 	host->base = base;
1351da177e4SLinus Torvalds 	host->irq = dev->irq;
1361da177e4SLinus Torvalds 	if(request_irq(dev->irq, NCR_700_intr, SA_SHIRQ, "lasi700", host)) {
1371da177e4SLinus Torvalds 		printk(KERN_ERR "lasi700: request_irq failed!\n");
1381da177e4SLinus Torvalds 		goto out_put_host;
1391da177e4SLinus Torvalds 	}
1401da177e4SLinus Torvalds 
1411da177e4SLinus Torvalds 	dev_set_drvdata(&dev->dev, host);
1421da177e4SLinus Torvalds 	scsi_scan_host(host);
1431da177e4SLinus Torvalds 
1441da177e4SLinus Torvalds 	return 0;
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds  out_put_host:
1471da177e4SLinus Torvalds 	scsi_host_put(host);
1481da177e4SLinus Torvalds  out_kfree:
1491da177e4SLinus Torvalds 	iounmap(hostdata->base);
1501da177e4SLinus Torvalds 	kfree(hostdata);
1511da177e4SLinus Torvalds 	return -ENODEV;
1521da177e4SLinus Torvalds }
1531da177e4SLinus Torvalds 
1541da177e4SLinus Torvalds static int __exit
1551da177e4SLinus Torvalds lasi700_driver_remove(struct parisc_device *dev)
1561da177e4SLinus Torvalds {
1571da177e4SLinus Torvalds 	struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
1581da177e4SLinus Torvalds 	struct NCR_700_Host_Parameters *hostdata =
1591da177e4SLinus Torvalds 		(struct NCR_700_Host_Parameters *)host->hostdata[0];
1601da177e4SLinus Torvalds 
1611da177e4SLinus Torvalds 	scsi_remove_host(host);
1621da177e4SLinus Torvalds 	NCR_700_release(host);
1631da177e4SLinus Torvalds 	free_irq(host->irq, host);
1641da177e4SLinus Torvalds 	iounmap(hostdata->base);
1651da177e4SLinus Torvalds 	kfree(hostdata);
1661da177e4SLinus Torvalds 
1671da177e4SLinus Torvalds 	return 0;
1681da177e4SLinus Torvalds }
1691da177e4SLinus Torvalds 
1701da177e4SLinus Torvalds static struct parisc_driver lasi700_driver = {
171bdad1f83SMatthew Wilcox 	.name =		"lasi_scsi",
1721da177e4SLinus Torvalds 	.id_table =	lasi700_ids,
1731da177e4SLinus Torvalds 	.probe =	lasi700_probe,
1741da177e4SLinus Torvalds 	.remove =	__devexit_p(lasi700_driver_remove),
1751da177e4SLinus Torvalds };
1761da177e4SLinus Torvalds 
1771da177e4SLinus Torvalds static int __init
1781da177e4SLinus Torvalds lasi700_init(void)
1791da177e4SLinus Torvalds {
1801da177e4SLinus Torvalds 	return register_parisc_driver(&lasi700_driver);
1811da177e4SLinus Torvalds }
1821da177e4SLinus Torvalds 
1831da177e4SLinus Torvalds static void __exit
1841da177e4SLinus Torvalds lasi700_exit(void)
1851da177e4SLinus Torvalds {
1861da177e4SLinus Torvalds 	unregister_parisc_driver(&lasi700_driver);
1871da177e4SLinus Torvalds }
1881da177e4SLinus Torvalds 
1891da177e4SLinus Torvalds module_init(lasi700_init);
1901da177e4SLinus Torvalds module_exit(lasi700_exit);
191