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