xref: /linux/drivers/scsi/lasi700.c (revision 762f99f4f3cb41a775b5157dd761217beba65873)
174ba9207SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
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 **
91da177e4SLinus Torvalds **-----------------------------------------------------------------------------
101da177e4SLinus Torvalds  */
111da177e4SLinus Torvalds 
121da177e4SLinus Torvalds /*
131da177e4SLinus Torvalds  * Many thanks to Richard Hirst <rhirst@linuxcare.com> for patiently
141da177e4SLinus Torvalds  * debugging this driver on the parisc architecture and suggesting
151da177e4SLinus Torvalds  * many improvements and bug fixes.
161da177e4SLinus Torvalds  *
171da177e4SLinus Torvalds  * Thanks also go to Linuxcare Inc. for providing several PARISC
181da177e4SLinus Torvalds  * machines for me to debug the driver on.
191da177e4SLinus Torvalds  */
201da177e4SLinus Torvalds 
211da177e4SLinus Torvalds #include <linux/kernel.h>
221da177e4SLinus Torvalds #include <linux/module.h>
231da177e4SLinus Torvalds #include <linux/init.h>
241da177e4SLinus Torvalds #include <linux/types.h>
251da177e4SLinus Torvalds #include <linux/stat.h>
261da177e4SLinus Torvalds #include <linux/mm.h>
271da177e4SLinus Torvalds #include <linux/blkdev.h>
281da177e4SLinus Torvalds #include <linux/ioport.h>
291da177e4SLinus Torvalds #include <linux/dma-mapping.h>
305a0e3ad6STejun Heo #include <linux/slab.h>
311da177e4SLinus Torvalds 
321da177e4SLinus Torvalds #include <asm/page.h>
331da177e4SLinus Torvalds #include <asm/irq.h>
341da177e4SLinus Torvalds #include <asm/hardware.h>
351da177e4SLinus Torvalds #include <asm/parisc-device.h>
361da177e4SLinus Torvalds #include <asm/delay.h>
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds #include <scsi/scsi_host.h>
391da177e4SLinus Torvalds #include <scsi/scsi_device.h>
401da177e4SLinus Torvalds #include <scsi/scsi_transport.h>
411da177e4SLinus Torvalds #include <scsi/scsi_transport_spi.h>
421da177e4SLinus Torvalds 
431da177e4SLinus Torvalds #include "53c700.h"
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds MODULE_AUTHOR("James Bottomley");
461da177e4SLinus Torvalds MODULE_DESCRIPTION("lasi700 SCSI Driver");
471da177e4SLinus Torvalds MODULE_LICENSE("GPL");
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds #define LASI_700_SVERSION 0x00071
501da177e4SLinus Torvalds #define LASI_710_SVERSION 0x00082
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds #define LASI700_ID_TABLE {			\
531da177e4SLinus Torvalds 	.hw_type	= HPHW_FIO,		\
541da177e4SLinus Torvalds 	.sversion	= LASI_700_SVERSION,	\
551da177e4SLinus Torvalds 	.hversion	= HVERSION_ANY_ID,	\
561da177e4SLinus Torvalds 	.hversion_rev	= HVERSION_REV_ANY_ID,	\
571da177e4SLinus Torvalds }
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds #define LASI710_ID_TABLE {			\
601da177e4SLinus Torvalds 	.hw_type	= HPHW_FIO,		\
611da177e4SLinus Torvalds 	.sversion	= LASI_710_SVERSION,	\
621da177e4SLinus Torvalds 	.hversion	= HVERSION_ANY_ID,	\
631da177e4SLinus Torvalds 	.hversion_rev	= HVERSION_REV_ANY_ID,	\
641da177e4SLinus Torvalds }
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds #define LASI700_CLOCK	25
671da177e4SLinus Torvalds #define LASI710_CLOCK	40
681da177e4SLinus Torvalds #define LASI_SCSI_CORE_OFFSET 0x100
691da177e4SLinus Torvalds 
706ade2a0bSHelge Deller static const struct parisc_device_id lasi700_ids[] __initconst = {
711da177e4SLinus Torvalds 	LASI700_ID_TABLE,
721da177e4SLinus Torvalds 	LASI710_ID_TABLE,
731da177e4SLinus Torvalds 	{ 0 }
741da177e4SLinus Torvalds };
751da177e4SLinus Torvalds 
761da177e4SLinus Torvalds static struct scsi_host_template lasi700_template = {
771da177e4SLinus Torvalds 	.name		= "LASI SCSI 53c700",
781da177e4SLinus Torvalds 	.proc_name	= "lasi700",
791da177e4SLinus Torvalds 	.this_id	= 7,
801da177e4SLinus Torvalds 	.module		= THIS_MODULE,
811da177e4SLinus Torvalds };
821da177e4SLinus Torvalds MODULE_DEVICE_TABLE(parisc, lasi700_ids);
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds static int __init
lasi700_probe(struct parisc_device * dev)851da177e4SLinus Torvalds lasi700_probe(struct parisc_device *dev)
861da177e4SLinus Torvalds {
8753f01bbaSMatthew Wilcox 	unsigned long base = dev->hpa.start + LASI_SCSI_CORE_OFFSET;
881da177e4SLinus Torvalds 	struct NCR_700_Host_Parameters *hostdata;
891da177e4SLinus Torvalds 	struct Scsi_Host *host;
901da177e4SLinus Torvalds 
91dd00cc48SYoann Padioleau 	hostdata = kzalloc(sizeof(*hostdata), GFP_KERNEL);
921da177e4SLinus Torvalds 	if (!hostdata) {
937f384ce7SHelge Deller 		dev_printk(KERN_ERR, &dev->dev, "Failed to allocate host data\n");
941da177e4SLinus Torvalds 		return -ENOMEM;
951da177e4SLinus Torvalds 	}
961da177e4SLinus Torvalds 
971da177e4SLinus Torvalds 	hostdata->dev = &dev->dev;
98284901a9SYang Hongyang 	dma_set_mask(&dev->dev, DMA_BIT_MASK(32));
994bdc0d67SChristoph Hellwig 	hostdata->base = ioremap(base, 0x100);
1001da177e4SLinus Torvalds 	hostdata->differential = 0;
1011da177e4SLinus Torvalds 
1021da177e4SLinus Torvalds 	if (dev->id.sversion == LASI_700_SVERSION) {
1031da177e4SLinus Torvalds 		hostdata->clock = LASI700_CLOCK;
1041da177e4SLinus Torvalds 		hostdata->force_le_on_be = 1;
1051da177e4SLinus Torvalds 	} else {
1061da177e4SLinus Torvalds 		hostdata->clock = LASI710_CLOCK;
1071da177e4SLinus Torvalds 		hostdata->force_le_on_be = 0;
1081da177e4SLinus Torvalds 		hostdata->chip710 = 1;
1091da177e4SLinus Torvalds 		hostdata->dmode_extra = DMODE_FC2;
110f67a9c15SThomas Bogendoerfer 		hostdata->burst_length = 8;
1111da177e4SLinus Torvalds 	}
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds 	host = NCR_700_detect(&lasi700_template, hostdata, &dev->dev);
1141da177e4SLinus Torvalds 	if (!host)
1151da177e4SLinus Torvalds 		goto out_kfree;
1161da177e4SLinus Torvalds 	host->this_id = 7;
11756fece20S 	host->base = base;
1181da177e4SLinus Torvalds 	host->irq = dev->irq;
1191d6f359aSThomas Gleixner 	if(request_irq(dev->irq, NCR_700_intr, IRQF_SHARED, "lasi700", host)) {
1201da177e4SLinus Torvalds 		printk(KERN_ERR "lasi700: request_irq failed!\n");
1211da177e4SLinus Torvalds 		goto out_put_host;
1221da177e4SLinus Torvalds 	}
1231da177e4SLinus Torvalds 
1241da177e4SLinus Torvalds 	dev_set_drvdata(&dev->dev, host);
1251da177e4SLinus Torvalds 	scsi_scan_host(host);
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds 	return 0;
1281da177e4SLinus Torvalds 
1291da177e4SLinus Torvalds  out_put_host:
1301da177e4SLinus Torvalds 	scsi_host_put(host);
1311da177e4SLinus Torvalds  out_kfree:
1321da177e4SLinus Torvalds 	iounmap(hostdata->base);
1331da177e4SLinus Torvalds 	kfree(hostdata);
1341da177e4SLinus Torvalds 	return -ENODEV;
1351da177e4SLinus Torvalds }
1361da177e4SLinus Torvalds 
137*87875c10SUwe Kleine-König static void __exit
lasi700_driver_remove(struct parisc_device * dev)1381da177e4SLinus Torvalds lasi700_driver_remove(struct parisc_device *dev)
1391da177e4SLinus Torvalds {
1401da177e4SLinus Torvalds 	struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
1411da177e4SLinus Torvalds 	struct NCR_700_Host_Parameters *hostdata =
1421da177e4SLinus Torvalds 		(struct NCR_700_Host_Parameters *)host->hostdata[0];
1431da177e4SLinus Torvalds 
1441da177e4SLinus Torvalds 	scsi_remove_host(host);
1451da177e4SLinus Torvalds 	NCR_700_release(host);
1461da177e4SLinus Torvalds 	free_irq(host->irq, host);
1471da177e4SLinus Torvalds 	iounmap(hostdata->base);
1481da177e4SLinus Torvalds 	kfree(hostdata);
1491da177e4SLinus Torvalds }
1501da177e4SLinus Torvalds 
1516ade2a0bSHelge Deller static struct parisc_driver lasi700_driver __refdata = {
152bdad1f83SMatthew Wilcox 	.name =		"lasi_scsi",
1531da177e4SLinus Torvalds 	.id_table =	lasi700_ids,
1541da177e4SLinus Torvalds 	.probe =	lasi700_probe,
1556ade2a0bSHelge Deller 	.remove =	__exit_p(lasi700_driver_remove),
1561da177e4SLinus Torvalds };
1571da177e4SLinus Torvalds 
1581da177e4SLinus Torvalds static int __init
lasi700_init(void)1591da177e4SLinus Torvalds lasi700_init(void)
1601da177e4SLinus Torvalds {
1611da177e4SLinus Torvalds 	return register_parisc_driver(&lasi700_driver);
1621da177e4SLinus Torvalds }
1631da177e4SLinus Torvalds 
1641da177e4SLinus Torvalds static void __exit
lasi700_exit(void)1651da177e4SLinus Torvalds lasi700_exit(void)
1661da177e4SLinus Torvalds {
1671da177e4SLinus Torvalds 	unregister_parisc_driver(&lasi700_driver);
1681da177e4SLinus Torvalds }
1691da177e4SLinus Torvalds 
1701da177e4SLinus Torvalds module_init(lasi700_init);
1711da177e4SLinus Torvalds module_exit(lasi700_exit);
172