1/* 2 * Zalon 53c7xx device driver. 3 * By Richard Hirst (rhirst@linuxcare.com) 4 */ 5 6#include <linux/init.h> 7#include <linux/interrupt.h> 8#include <linux/module.h> 9#include <linux/types.h> 10#include <asm/hardware.h> 11#include <asm/io.h> 12 13#include "../parisc/gsc.h" 14 15#include "ncr53c8xx.h" 16 17MODULE_AUTHOR("Richard Hirst"); 18MODULE_DESCRIPTION("Bluefish/Zalon 720 SCSI Driver"); 19MODULE_LICENSE("GPL"); 20 21#define GSC_SCSI_ZALON_OFFSET 0x800 22 23#define IO_MODULE_EIM (1*4) 24#define IO_MODULE_DC_ADATA (2*4) 25#define IO_MODULE_II_CDATA (3*4) 26#define IO_MODULE_IO_COMMAND (12*4) 27#define IO_MODULE_IO_STATUS (13*4) 28 29#define IOSTATUS_RY 0x40 30#define IOSTATUS_FE 0x80 31#define IOIIDATA_SMINT5L 0x40000000 32#define IOIIDATA_MINT5EN 0x20000000 33#define IOIIDATA_PACKEN 0x10000000 34#define IOIIDATA_PREFETCHEN 0x08000000 35#define IOIIDATA_IOII 0x00000020 36 37#define CMD_RESET 5 38 39static struct ncr_chip zalon720_chip __initdata = { 40 .revision_id = 0x0f, 41 .burst_max = 3, 42 .offset_max = 8, 43 .nr_divisor = 4, 44 .features = FE_WIDE | FE_DIFF | FE_EHP| FE_MUX | FE_EA, 45}; 46 47 48 49 50static struct scsi_host_template zalon7xx_template = { 51 .module = THIS_MODULE, 52 .proc_name = "zalon7xx", 53}; 54 55static int __init 56zalon_probe(struct parisc_device *dev) 57{ 58 struct gsc_irq gsc_irq; 59 u32 zalon_vers; 60 int error = -ENODEV; 61 void __iomem *zalon = ioremap_nocache(dev->hpa.start, 4096); 62 void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET; 63 static int unit = 0; 64 struct Scsi_Host *host; 65 struct ncr_device device; 66 67 __raw_writel(CMD_RESET, zalon + IO_MODULE_IO_COMMAND); 68 while (!(__raw_readl(zalon + IO_MODULE_IO_STATUS) & IOSTATUS_RY)) 69 cpu_relax(); 70 __raw_writel(IOIIDATA_MINT5EN | IOIIDATA_PACKEN | IOIIDATA_PREFETCHEN, 71 zalon + IO_MODULE_II_CDATA); 72 73 zalon_vers = (__raw_readl(zalon + IO_MODULE_II_CDATA) >> 24) & 0x07; 74 75 /* Setup the interrupts first. 76 ** Later on request_irq() will register the handler. 77 */ 78 dev->irq = gsc_alloc_irq(&gsc_irq); 79 80 printk(KERN_INFO "%s: Zalon version %d, IRQ %d\n", __FUNCTION__, 81 zalon_vers, dev->irq); 82 83 __raw_writel(gsc_irq.txn_addr | gsc_irq.txn_data, zalon + IO_MODULE_EIM); 84 85 if (zalon_vers == 0) 86 printk(KERN_WARNING "%s: Zalon 1.1 or earlier\n", __FUNCTION__); 87 88 memset(&device, 0, sizeof(struct ncr_device)); 89 90 /* The following three are needed before any other access. */ 91 __raw_writeb(0x20, io_port + 0x38); /* DCNTL_REG, EA */ 92 __raw_writeb(0x04, io_port + 0x1b); /* CTEST0_REG, EHP */ 93 __raw_writeb(0x80, io_port + 0x22); /* CTEST4_REG, MUX */ 94 95 /* Initialise ncr_device structure with items required by ncr_attach. */ 96 device.chip = zalon720_chip; 97 device.host_id = 7; 98 device.dev = &dev->dev; 99 device.slot.base = dev->hpa.start + GSC_SCSI_ZALON_OFFSET; 100 device.slot.base_v = io_port; 101 device.slot.irq = dev->irq; 102 device.differential = 2; 103 104 host = ncr_attach(&zalon7xx_template, unit, &device); 105 if (!host) 106 goto fail; 107 108 if (request_irq(dev->irq, ncr53c8xx_intr, IRQF_SHARED, "zalon", host)) { 109 printk(KERN_ERR "%s: irq problem with %d, detaching\n ", 110 dev->dev.bus_id, dev->irq); 111 goto fail; 112 } 113 114 unit++; 115 116 dev_set_drvdata(&dev->dev, host); 117 118 error = scsi_add_host(host, &dev->dev); 119 if (error) 120 goto fail_free_irq; 121 122 scsi_scan_host(host); 123 return 0; 124 125 fail_free_irq: 126 free_irq(dev->irq, host); 127 fail: 128 ncr53c8xx_release(host); 129 return error; 130} 131 132static struct parisc_device_id zalon_tbl[] = { 133 { HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00089 }, 134 { 0, } 135}; 136 137MODULE_DEVICE_TABLE(parisc, zalon_tbl); 138 139static int __exit zalon_remove(struct parisc_device *dev) 140{ 141 struct Scsi_Host *host = dev_get_drvdata(&dev->dev); 142 143 scsi_remove_host(host); 144 ncr53c8xx_release(host); 145 free_irq(dev->irq, host); 146 147 return 0; 148} 149 150static struct parisc_driver zalon_driver = { 151 .name = "zalon", 152 .id_table = zalon_tbl, 153 .probe = zalon_probe, 154 .remove = __devexit_p(zalon_remove), 155}; 156 157static int __init zalon7xx_init(void) 158{ 159 int ret = ncr53c8xx_init(); 160 if (!ret) 161 ret = register_parisc_driver(&zalon_driver); 162 if (ret) 163 ncr53c8xx_exit(); 164 return ret; 165} 166 167static void __exit zalon7xx_exit(void) 168{ 169 unregister_parisc_driver(&zalon_driver); 170 ncr53c8xx_exit(); 171} 172 173module_init(zalon7xx_init); 174module_exit(zalon7xx_exit); 175