xref: /linux/drivers/scsi/zalon.c (revision 5898aa13ab4899d3a12e069f8716f83dd44567eb)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Zalon 53c7xx device driver.
31da177e4SLinus Torvalds  * By Richard Hirst (rhirst@linuxcare.com)
41da177e4SLinus Torvalds  */
51da177e4SLinus Torvalds 
61da177e4SLinus Torvalds #include <linux/init.h>
71da177e4SLinus Torvalds #include <linux/interrupt.h>
81da177e4SLinus Torvalds #include <linux/module.h>
91da177e4SLinus Torvalds #include <linux/types.h>
101da177e4SLinus Torvalds #include <asm/hardware.h>
111da177e4SLinus Torvalds #include <asm/io.h>
121da177e4SLinus Torvalds 
131da177e4SLinus Torvalds #include "../parisc/gsc.h"
141da177e4SLinus Torvalds 
151da177e4SLinus Torvalds #include "ncr53c8xx.h"
161da177e4SLinus Torvalds 
171da177e4SLinus Torvalds MODULE_AUTHOR("Richard Hirst");
181da177e4SLinus Torvalds MODULE_DESCRIPTION("Bluefish/Zalon 720 SCSI Driver");
191da177e4SLinus Torvalds MODULE_LICENSE("GPL");
201da177e4SLinus Torvalds 
211da177e4SLinus Torvalds #define GSC_SCSI_ZALON_OFFSET 0x800
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds #define IO_MODULE_EIM		(1*4)
241da177e4SLinus Torvalds #define IO_MODULE_DC_ADATA	(2*4)
251da177e4SLinus Torvalds #define IO_MODULE_II_CDATA	(3*4)
261da177e4SLinus Torvalds #define IO_MODULE_IO_COMMAND	(12*4)
271da177e4SLinus Torvalds #define IO_MODULE_IO_STATUS	(13*4)
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds #define IOSTATUS_RY		0x40
301da177e4SLinus Torvalds #define IOSTATUS_FE		0x80
311da177e4SLinus Torvalds #define IOIIDATA_SMINT5L	0x40000000
321da177e4SLinus Torvalds #define IOIIDATA_MINT5EN	0x20000000
331da177e4SLinus Torvalds #define IOIIDATA_PACKEN		0x10000000
341da177e4SLinus Torvalds #define IOIIDATA_PREFETCHEN	0x08000000
351da177e4SLinus Torvalds #define IOIIDATA_IOII		0x00000020
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds #define CMD_RESET		5
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds static struct ncr_chip zalon720_chip __initdata = {
401da177e4SLinus Torvalds 	.revision_id =	0x0f,
411da177e4SLinus Torvalds 	.burst_max =	3,
421da177e4SLinus Torvalds 	.offset_max =	8,
431da177e4SLinus Torvalds 	.nr_divisor =	4,
441da177e4SLinus Torvalds 	.features =	FE_WIDE | FE_DIFF | FE_EHP| FE_MUX | FE_EA,
451da177e4SLinus Torvalds };
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds #if 0
501da177e4SLinus Torvalds /* FIXME:
511da177e4SLinus Torvalds  * Is this function dead code? or is someone planning on using it in the
521da177e4SLinus Torvalds  * future.  The clock = (int) pdc_result[16] does not look correct to
531da177e4SLinus Torvalds  * me ... I think it should be iodc_data[16].  Since this cause a compile
541da177e4SLinus Torvalds  * error with the new encapsulated PDC, I'm not compiling in this function.
551da177e4SLinus Torvalds  * - RB
561da177e4SLinus Torvalds  */
571da177e4SLinus Torvalds /* poke SCSI clock out of iodc data */
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds static u8 iodc_data[32] __attribute__ ((aligned (64)));
601da177e4SLinus Torvalds static unsigned long pdc_result[32] __attribute__ ((aligned (16))) ={0,0,0,0};
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds static int
631da177e4SLinus Torvalds lasi_scsi_clock(void * hpa, int defaultclock)
641da177e4SLinus Torvalds {
651da177e4SLinus Torvalds 	int clock, status;
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds 	status = pdc_iodc_read(&pdc_result, hpa, 0, &iodc_data, 32 );
681da177e4SLinus Torvalds 	if (status == PDC_RET_OK) {
691da177e4SLinus Torvalds 		clock = (int) pdc_result[16];
701da177e4SLinus Torvalds 	} else {
71cadbd4a5SHarvey Harrison 		printk(KERN_WARNING "%s: pdc_iodc_read returned %d\n", __func__, status);
721da177e4SLinus Torvalds 		clock = defaultclock;
731da177e4SLinus Torvalds 	}
741da177e4SLinus Torvalds 
75cadbd4a5SHarvey Harrison 	printk(KERN_DEBUG "%s: SCSI clock %d\n", __func__, clock);
761da177e4SLinus Torvalds  	return clock;
771da177e4SLinus Torvalds }
781da177e4SLinus Torvalds #endif
791da177e4SLinus Torvalds 
801da177e4SLinus Torvalds static struct scsi_host_template zalon7xx_template = {
811da177e4SLinus Torvalds 	.module		= THIS_MODULE,
821da177e4SLinus Torvalds 	.proc_name	= "zalon7xx",
831da177e4SLinus Torvalds };
841da177e4SLinus Torvalds 
851da177e4SLinus Torvalds static int __init
861da177e4SLinus Torvalds zalon_probe(struct parisc_device *dev)
871da177e4SLinus Torvalds {
881da177e4SLinus Torvalds 	struct gsc_irq gsc_irq;
891da177e4SLinus Torvalds 	u32 zalon_vers;
901da177e4SLinus Torvalds 	int error = -ENODEV;
915076c158SHelge Deller 	void __iomem *zalon = ioremap_nocache(dev->hpa.start, 4096);
921da177e4SLinus Torvalds 	void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET;
931da177e4SLinus Torvalds 	static int unit = 0;
941da177e4SLinus Torvalds 	struct Scsi_Host *host;
951da177e4SLinus Torvalds 	struct ncr_device device;
961da177e4SLinus Torvalds 
971da177e4SLinus Torvalds 	__raw_writel(CMD_RESET, zalon + IO_MODULE_IO_COMMAND);
981da177e4SLinus Torvalds 	while (!(__raw_readl(zalon + IO_MODULE_IO_STATUS) & IOSTATUS_RY))
991da177e4SLinus Torvalds 		cpu_relax();
1001da177e4SLinus Torvalds 	__raw_writel(IOIIDATA_MINT5EN | IOIIDATA_PACKEN | IOIIDATA_PREFETCHEN,
1011da177e4SLinus Torvalds 		zalon + IO_MODULE_II_CDATA);
1021da177e4SLinus Torvalds 
1031da177e4SLinus Torvalds 	/* XXX: Save the Zalon version for bug workarounds? */
1041da177e4SLinus Torvalds 	zalon_vers = (__raw_readl(zalon + IO_MODULE_II_CDATA) >> 24) & 0x07;
1051da177e4SLinus Torvalds 
1061da177e4SLinus Torvalds 	/* Setup the interrupts first.
1071da177e4SLinus Torvalds 	** Later on request_irq() will register the handler.
1081da177e4SLinus Torvalds 	*/
1091da177e4SLinus Torvalds 	dev->irq = gsc_alloc_irq(&gsc_irq);
1101da177e4SLinus Torvalds 
111cadbd4a5SHarvey Harrison 	printk(KERN_INFO "%s: Zalon version %d, IRQ %d\n", __func__,
1121da177e4SLinus Torvalds 		zalon_vers, dev->irq);
1131da177e4SLinus Torvalds 
1141da177e4SLinus Torvalds 	__raw_writel(gsc_irq.txn_addr | gsc_irq.txn_data, zalon + IO_MODULE_EIM);
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds 	if (zalon_vers == 0)
117cadbd4a5SHarvey Harrison 		printk(KERN_WARNING "%s: Zalon 1.1 or earlier\n", __func__);
1181da177e4SLinus Torvalds 
1191da177e4SLinus Torvalds 	memset(&device, 0, sizeof(struct ncr_device));
1201da177e4SLinus Torvalds 
1211da177e4SLinus Torvalds 	/* The following three are needed before any other access. */
1221da177e4SLinus Torvalds 	__raw_writeb(0x20, io_port + 0x38); /* DCNTL_REG,  EA  */
1231da177e4SLinus Torvalds 	__raw_writeb(0x04, io_port + 0x1b); /* CTEST0_REG, EHP */
1241da177e4SLinus Torvalds 	__raw_writeb(0x80, io_port + 0x22); /* CTEST4_REG, MUX */
1251da177e4SLinus Torvalds 
1261da177e4SLinus Torvalds 	/* Initialise ncr_device structure with items required by ncr_attach. */
1271da177e4SLinus Torvalds 	device.chip		= zalon720_chip;
1281da177e4SLinus Torvalds 	device.host_id		= 7;
1291da177e4SLinus Torvalds 	device.dev		= &dev->dev;
13053f01bbaSMatthew Wilcox 	device.slot.base	= dev->hpa.start + GSC_SCSI_ZALON_OFFSET;
1311da177e4SLinus Torvalds 	device.slot.base_v	= io_port;
1321da177e4SLinus Torvalds 	device.slot.irq		= dev->irq;
1331da177e4SLinus Torvalds 	device.differential	= 2;
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds 	host = ncr_attach(&zalon7xx_template, unit, &device);
1361da177e4SLinus Torvalds 	if (!host)
137d3a263a8SJames Bottomley 		return -ENODEV;
1381da177e4SLinus Torvalds 
1391d6f359aSThomas Gleixner 	if (request_irq(dev->irq, ncr53c8xx_intr, IRQF_SHARED, "zalon", host)) {
1407f384ce7SHelge Deller 	  dev_printk(KERN_ERR, &dev->dev, "irq problem with %d, detaching\n ",
14171610f55SKay Sievers 		     dev->irq);
1421da177e4SLinus Torvalds 		goto fail;
1431da177e4SLinus Torvalds 	}
1441da177e4SLinus Torvalds 
1451da177e4SLinus Torvalds 	unit++;
1461da177e4SLinus Torvalds 
1471da177e4SLinus Torvalds 	dev_set_drvdata(&dev->dev, host);
1481da177e4SLinus Torvalds 
1491da177e4SLinus Torvalds 	error = scsi_add_host(host, &dev->dev);
1501da177e4SLinus Torvalds 	if (error)
1511da177e4SLinus Torvalds 		goto fail_free_irq;
1521da177e4SLinus Torvalds 
1531da177e4SLinus Torvalds 	scsi_scan_host(host);
1541da177e4SLinus Torvalds 	return 0;
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds  fail_free_irq:
1571da177e4SLinus Torvalds 	free_irq(dev->irq, host);
1581da177e4SLinus Torvalds  fail:
1591da177e4SLinus Torvalds 	ncr53c8xx_release(host);
1601da177e4SLinus Torvalds 	return error;
1611da177e4SLinus Torvalds }
1621da177e4SLinus Torvalds 
163*5898aa13SHelge Deller static const struct parisc_device_id zalon_tbl[] __initconst = {
1641da177e4SLinus Torvalds 	{ HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00089 },
1651da177e4SLinus Torvalds 	{ 0, }
1661da177e4SLinus Torvalds };
1671da177e4SLinus Torvalds 
1681da177e4SLinus Torvalds MODULE_DEVICE_TABLE(parisc, zalon_tbl);
1691da177e4SLinus Torvalds 
170*5898aa13SHelge Deller static int __exit zalon_remove(struct parisc_device *dev)
1711da177e4SLinus Torvalds {
1721da177e4SLinus Torvalds 	struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
1731da177e4SLinus Torvalds 
1741da177e4SLinus Torvalds 	scsi_remove_host(host);
1751da177e4SLinus Torvalds 	ncr53c8xx_release(host);
1761da177e4SLinus Torvalds 	free_irq(dev->irq, host);
1771da177e4SLinus Torvalds 
1781da177e4SLinus Torvalds 	return 0;
1791da177e4SLinus Torvalds }
1801da177e4SLinus Torvalds 
181*5898aa13SHelge Deller static struct parisc_driver zalon_driver __refdata = {
1821da177e4SLinus Torvalds 	.name =		"zalon",
1831da177e4SLinus Torvalds 	.id_table =	zalon_tbl,
1841da177e4SLinus Torvalds 	.probe =	zalon_probe,
185*5898aa13SHelge Deller 	.remove =	__exit_p(zalon_remove),
1861da177e4SLinus Torvalds };
1871da177e4SLinus Torvalds 
1881da177e4SLinus Torvalds static int __init zalon7xx_init(void)
1891da177e4SLinus Torvalds {
1901da177e4SLinus Torvalds 	int ret = ncr53c8xx_init();
1911da177e4SLinus Torvalds 	if (!ret)
1921da177e4SLinus Torvalds 		ret = register_parisc_driver(&zalon_driver);
1931da177e4SLinus Torvalds 	if (ret)
1941da177e4SLinus Torvalds 		ncr53c8xx_exit();
1951da177e4SLinus Torvalds 	return ret;
1961da177e4SLinus Torvalds }
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds static void __exit zalon7xx_exit(void)
1991da177e4SLinus Torvalds {
2001da177e4SLinus Torvalds 	unregister_parisc_driver(&zalon_driver);
2011da177e4SLinus Torvalds 	ncr53c8xx_exit();
2021da177e4SLinus Torvalds }
2031da177e4SLinus Torvalds 
2041da177e4SLinus Torvalds module_init(zalon7xx_init);
2051da177e4SLinus Torvalds module_exit(zalon7xx_exit);
206