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", 841da177e4SLinus Torvalds }; 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds static int __init 871da177e4SLinus Torvalds zalon_probe(struct parisc_device *dev) 881da177e4SLinus Torvalds { 891da177e4SLinus Torvalds struct gsc_irq gsc_irq; 901da177e4SLinus Torvalds u32 zalon_vers; 911da177e4SLinus Torvalds int error = -ENODEV; 924bdc0d67SChristoph Hellwig void __iomem *zalon = ioremap(dev->hpa.start, 4096); 931da177e4SLinus Torvalds void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET; 941da177e4SLinus Torvalds static int unit = 0; 951da177e4SLinus Torvalds struct Scsi_Host *host; 961da177e4SLinus Torvalds struct ncr_device device; 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds __raw_writel(CMD_RESET, zalon + IO_MODULE_IO_COMMAND); 991da177e4SLinus Torvalds while (!(__raw_readl(zalon + IO_MODULE_IO_STATUS) & IOSTATUS_RY)) 1001da177e4SLinus Torvalds cpu_relax(); 1011da177e4SLinus Torvalds __raw_writel(IOIIDATA_MINT5EN | IOIIDATA_PACKEN | IOIIDATA_PREFETCHEN, 1021da177e4SLinus Torvalds zalon + IO_MODULE_II_CDATA); 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds /* XXX: Save the Zalon version for bug workarounds? */ 1051da177e4SLinus Torvalds zalon_vers = (__raw_readl(zalon + IO_MODULE_II_CDATA) >> 24) & 0x07; 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds /* Setup the interrupts first. 1081da177e4SLinus Torvalds ** Later on request_irq() will register the handler. 1091da177e4SLinus Torvalds */ 1101da177e4SLinus Torvalds dev->irq = gsc_alloc_irq(&gsc_irq); 1111da177e4SLinus Torvalds 112cadbd4a5SHarvey Harrison printk(KERN_INFO "%s: Zalon version %d, IRQ %d\n", __func__, 1131da177e4SLinus Torvalds zalon_vers, dev->irq); 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds __raw_writel(gsc_irq.txn_addr | gsc_irq.txn_data, zalon + IO_MODULE_EIM); 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds if (zalon_vers == 0) 118cadbd4a5SHarvey Harrison printk(KERN_WARNING "%s: Zalon 1.1 or earlier\n", __func__); 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds memset(&device, 0, sizeof(struct ncr_device)); 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds /* The following three are needed before any other access. */ 1231da177e4SLinus Torvalds __raw_writeb(0x20, io_port + 0x38); /* DCNTL_REG, EA */ 1241da177e4SLinus Torvalds __raw_writeb(0x04, io_port + 0x1b); /* CTEST0_REG, EHP */ 1251da177e4SLinus Torvalds __raw_writeb(0x80, io_port + 0x22); /* CTEST4_REG, MUX */ 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds /* Initialise ncr_device structure with items required by ncr_attach. */ 1281da177e4SLinus Torvalds device.chip = zalon720_chip; 1291da177e4SLinus Torvalds device.host_id = 7; 1301da177e4SLinus Torvalds device.dev = &dev->dev; 13153f01bbaSMatthew Wilcox device.slot.base = dev->hpa.start + GSC_SCSI_ZALON_OFFSET; 1321da177e4SLinus Torvalds device.slot.base_v = io_port; 1331da177e4SLinus Torvalds device.slot.irq = dev->irq; 1341da177e4SLinus Torvalds device.differential = 2; 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds host = ncr_attach(&zalon7xx_template, unit, &device); 1371da177e4SLinus Torvalds if (!host) 138d3a263a8SJames Bottomley return -ENODEV; 1391da177e4SLinus Torvalds 1401d6f359aSThomas Gleixner if (request_irq(dev->irq, ncr53c8xx_intr, IRQF_SHARED, "zalon", host)) { 1417f384ce7SHelge Deller dev_printk(KERN_ERR, &dev->dev, "irq problem with %d, detaching\n ", 14271610f55SKay Sievers dev->irq); 1431da177e4SLinus Torvalds goto fail; 1441da177e4SLinus Torvalds } 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds unit++; 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds dev_set_drvdata(&dev->dev, host); 1491da177e4SLinus Torvalds 1501da177e4SLinus Torvalds error = scsi_add_host(host, &dev->dev); 1511da177e4SLinus Torvalds if (error) 1521da177e4SLinus Torvalds goto fail_free_irq; 1531da177e4SLinus Torvalds 1541da177e4SLinus Torvalds scsi_scan_host(host); 1551da177e4SLinus Torvalds return 0; 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds fail_free_irq: 1581da177e4SLinus Torvalds free_irq(dev->irq, host); 1591da177e4SLinus Torvalds fail: 1601da177e4SLinus Torvalds ncr53c8xx_release(host); 1611da177e4SLinus Torvalds return error; 1621da177e4SLinus Torvalds } 1631da177e4SLinus Torvalds 1645898aa13SHelge Deller static const struct parisc_device_id zalon_tbl[] __initconst = { 1651da177e4SLinus Torvalds { HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00089 }, 1661da177e4SLinus Torvalds { 0, } 1671da177e4SLinus Torvalds }; 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds MODULE_DEVICE_TABLE(parisc, zalon_tbl); 1701da177e4SLinus Torvalds 171*87875c10SUwe Kleine-König static void __exit zalon_remove(struct parisc_device *dev) 1721da177e4SLinus Torvalds { 1731da177e4SLinus Torvalds struct Scsi_Host *host = dev_get_drvdata(&dev->dev); 1741da177e4SLinus Torvalds 1751da177e4SLinus Torvalds scsi_remove_host(host); 1761da177e4SLinus Torvalds ncr53c8xx_release(host); 1771da177e4SLinus Torvalds free_irq(dev->irq, host); 1781da177e4SLinus Torvalds } 1791da177e4SLinus Torvalds 1805898aa13SHelge Deller static struct parisc_driver zalon_driver __refdata = { 1811da177e4SLinus Torvalds .name = "zalon", 1821da177e4SLinus Torvalds .id_table = zalon_tbl, 1831da177e4SLinus Torvalds .probe = zalon_probe, 1845898aa13SHelge Deller .remove = __exit_p(zalon_remove), 1851da177e4SLinus Torvalds }; 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds static int __init zalon7xx_init(void) 1881da177e4SLinus Torvalds { 1891da177e4SLinus Torvalds int ret = ncr53c8xx_init(); 1901da177e4SLinus Torvalds if (!ret) 1911da177e4SLinus Torvalds ret = register_parisc_driver(&zalon_driver); 1921da177e4SLinus Torvalds if (ret) 1931da177e4SLinus Torvalds ncr53c8xx_exit(); 1941da177e4SLinus Torvalds return ret; 1951da177e4SLinus Torvalds } 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds static void __exit zalon7xx_exit(void) 1981da177e4SLinus Torvalds { 1991da177e4SLinus Torvalds unregister_parisc_driver(&zalon_driver); 2001da177e4SLinus Torvalds ncr53c8xx_exit(); 2011da177e4SLinus Torvalds } 2021da177e4SLinus Torvalds 2031da177e4SLinus Torvalds module_init(zalon7xx_init); 2041da177e4SLinus Torvalds module_exit(zalon7xx_exit); 205