1*1da177e4SLinus Torvalds /* -*- mode: c; c-basic-offset: 8 -*- */ 2*1da177e4SLinus Torvalds 3*1da177e4SLinus Torvalds /* PARISC LASI driver for the 53c700 chip 4*1da177e4SLinus Torvalds * 5*1da177e4SLinus Torvalds * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com 6*1da177e4SLinus Torvalds **----------------------------------------------------------------------------- 7*1da177e4SLinus Torvalds ** 8*1da177e4SLinus Torvalds ** This program is free software; you can redistribute it and/or modify 9*1da177e4SLinus Torvalds ** it under the terms of the GNU General Public License as published by 10*1da177e4SLinus Torvalds ** the Free Software Foundation; either version 2 of the License, or 11*1da177e4SLinus Torvalds ** (at your option) any later version. 12*1da177e4SLinus Torvalds ** 13*1da177e4SLinus Torvalds ** This program is distributed in the hope that it will be useful, 14*1da177e4SLinus Torvalds ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15*1da177e4SLinus Torvalds ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*1da177e4SLinus Torvalds ** GNU General Public License for more details. 17*1da177e4SLinus Torvalds ** 18*1da177e4SLinus Torvalds ** You should have received a copy of the GNU General Public License 19*1da177e4SLinus Torvalds ** along with this program; if not, write to the Free Software 20*1da177e4SLinus Torvalds ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21*1da177e4SLinus Torvalds ** 22*1da177e4SLinus Torvalds **----------------------------------------------------------------------------- 23*1da177e4SLinus Torvalds */ 24*1da177e4SLinus Torvalds 25*1da177e4SLinus Torvalds /* 26*1da177e4SLinus Torvalds * Many thanks to Richard Hirst <rhirst@linuxcare.com> for patiently 27*1da177e4SLinus Torvalds * debugging this driver on the parisc architecture and suggesting 28*1da177e4SLinus Torvalds * many improvements and bug fixes. 29*1da177e4SLinus Torvalds * 30*1da177e4SLinus Torvalds * Thanks also go to Linuxcare Inc. for providing several PARISC 31*1da177e4SLinus Torvalds * machines for me to debug the driver on. 32*1da177e4SLinus Torvalds */ 33*1da177e4SLinus Torvalds 34*1da177e4SLinus Torvalds #include <linux/kernel.h> 35*1da177e4SLinus Torvalds #include <linux/module.h> 36*1da177e4SLinus Torvalds #include <linux/init.h> 37*1da177e4SLinus Torvalds #include <linux/types.h> 38*1da177e4SLinus Torvalds #include <linux/stat.h> 39*1da177e4SLinus Torvalds #include <linux/mm.h> 40*1da177e4SLinus Torvalds #include <linux/blkdev.h> 41*1da177e4SLinus Torvalds #include <linux/sched.h> 42*1da177e4SLinus Torvalds #include <linux/ioport.h> 43*1da177e4SLinus Torvalds #include <linux/dma-mapping.h> 44*1da177e4SLinus Torvalds 45*1da177e4SLinus Torvalds #include <asm/page.h> 46*1da177e4SLinus Torvalds #include <asm/pgtable.h> 47*1da177e4SLinus Torvalds #include <asm/irq.h> 48*1da177e4SLinus Torvalds #include <asm/hardware.h> 49*1da177e4SLinus Torvalds #include <asm/parisc-device.h> 50*1da177e4SLinus Torvalds #include <asm/delay.h> 51*1da177e4SLinus Torvalds 52*1da177e4SLinus Torvalds #include <scsi/scsi_host.h> 53*1da177e4SLinus Torvalds #include <scsi/scsi_device.h> 54*1da177e4SLinus Torvalds #include <scsi/scsi_transport.h> 55*1da177e4SLinus Torvalds #include <scsi/scsi_transport_spi.h> 56*1da177e4SLinus Torvalds 57*1da177e4SLinus Torvalds #include "53c700.h" 58*1da177e4SLinus Torvalds 59*1da177e4SLinus Torvalds MODULE_AUTHOR("James Bottomley"); 60*1da177e4SLinus Torvalds MODULE_DESCRIPTION("lasi700 SCSI Driver"); 61*1da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 62*1da177e4SLinus Torvalds 63*1da177e4SLinus Torvalds #define LASI_700_SVERSION 0x00071 64*1da177e4SLinus Torvalds #define LASI_710_SVERSION 0x00082 65*1da177e4SLinus Torvalds 66*1da177e4SLinus Torvalds #define LASI700_ID_TABLE { \ 67*1da177e4SLinus Torvalds .hw_type = HPHW_FIO, \ 68*1da177e4SLinus Torvalds .sversion = LASI_700_SVERSION, \ 69*1da177e4SLinus Torvalds .hversion = HVERSION_ANY_ID, \ 70*1da177e4SLinus Torvalds .hversion_rev = HVERSION_REV_ANY_ID, \ 71*1da177e4SLinus Torvalds } 72*1da177e4SLinus Torvalds 73*1da177e4SLinus Torvalds #define LASI710_ID_TABLE { \ 74*1da177e4SLinus Torvalds .hw_type = HPHW_FIO, \ 75*1da177e4SLinus Torvalds .sversion = LASI_710_SVERSION, \ 76*1da177e4SLinus Torvalds .hversion = HVERSION_ANY_ID, \ 77*1da177e4SLinus Torvalds .hversion_rev = HVERSION_REV_ANY_ID, \ 78*1da177e4SLinus Torvalds } 79*1da177e4SLinus Torvalds 80*1da177e4SLinus Torvalds #define LASI700_CLOCK 25 81*1da177e4SLinus Torvalds #define LASI710_CLOCK 40 82*1da177e4SLinus Torvalds #define LASI_SCSI_CORE_OFFSET 0x100 83*1da177e4SLinus Torvalds 84*1da177e4SLinus Torvalds static struct parisc_device_id lasi700_ids[] = { 85*1da177e4SLinus Torvalds LASI700_ID_TABLE, 86*1da177e4SLinus Torvalds LASI710_ID_TABLE, 87*1da177e4SLinus Torvalds { 0 } 88*1da177e4SLinus Torvalds }; 89*1da177e4SLinus Torvalds 90*1da177e4SLinus Torvalds static struct scsi_host_template lasi700_template = { 91*1da177e4SLinus Torvalds .name = "LASI SCSI 53c700", 92*1da177e4SLinus Torvalds .proc_name = "lasi700", 93*1da177e4SLinus Torvalds .this_id = 7, 94*1da177e4SLinus Torvalds .module = THIS_MODULE, 95*1da177e4SLinus Torvalds }; 96*1da177e4SLinus Torvalds MODULE_DEVICE_TABLE(parisc, lasi700_ids); 97*1da177e4SLinus Torvalds 98*1da177e4SLinus Torvalds static int __init 99*1da177e4SLinus Torvalds lasi700_probe(struct parisc_device *dev) 100*1da177e4SLinus Torvalds { 101*1da177e4SLinus Torvalds unsigned long base = dev->hpa + LASI_SCSI_CORE_OFFSET; 102*1da177e4SLinus Torvalds struct NCR_700_Host_Parameters *hostdata; 103*1da177e4SLinus Torvalds struct Scsi_Host *host; 104*1da177e4SLinus Torvalds 105*1da177e4SLinus Torvalds hostdata = kmalloc(sizeof(*hostdata), GFP_KERNEL); 106*1da177e4SLinus Torvalds if (!hostdata) { 107*1da177e4SLinus Torvalds printk(KERN_ERR "%s: Failed to allocate host data\n", 108*1da177e4SLinus Torvalds dev->dev.bus_id); 109*1da177e4SLinus Torvalds return -ENOMEM; 110*1da177e4SLinus Torvalds } 111*1da177e4SLinus Torvalds memset(hostdata, 0, sizeof(struct NCR_700_Host_Parameters)); 112*1da177e4SLinus Torvalds 113*1da177e4SLinus Torvalds hostdata->dev = &dev->dev; 114*1da177e4SLinus Torvalds dma_set_mask(&dev->dev, DMA_32BIT_MASK); 115*1da177e4SLinus Torvalds hostdata->base = ioremap(base, 0x100); 116*1da177e4SLinus Torvalds hostdata->differential = 0; 117*1da177e4SLinus Torvalds 118*1da177e4SLinus Torvalds if (dev->id.sversion == LASI_700_SVERSION) { 119*1da177e4SLinus Torvalds hostdata->clock = LASI700_CLOCK; 120*1da177e4SLinus Torvalds hostdata->force_le_on_be = 1; 121*1da177e4SLinus Torvalds } else { 122*1da177e4SLinus Torvalds hostdata->clock = LASI710_CLOCK; 123*1da177e4SLinus Torvalds hostdata->force_le_on_be = 0; 124*1da177e4SLinus Torvalds hostdata->chip710 = 1; 125*1da177e4SLinus Torvalds hostdata->dmode_extra = DMODE_FC2; 126*1da177e4SLinus Torvalds } 127*1da177e4SLinus Torvalds 128*1da177e4SLinus Torvalds NCR_700_set_mem_mapped(hostdata); 129*1da177e4SLinus Torvalds 130*1da177e4SLinus Torvalds host = NCR_700_detect(&lasi700_template, hostdata, &dev->dev); 131*1da177e4SLinus Torvalds if (!host) 132*1da177e4SLinus Torvalds goto out_kfree; 133*1da177e4SLinus Torvalds host->this_id = 7; 134*1da177e4SLinus Torvalds host->irq = dev->irq; 135*1da177e4SLinus Torvalds if(request_irq(dev->irq, NCR_700_intr, SA_SHIRQ, "lasi700", host)) { 136*1da177e4SLinus Torvalds printk(KERN_ERR "lasi700: request_irq failed!\n"); 137*1da177e4SLinus Torvalds goto out_put_host; 138*1da177e4SLinus Torvalds } 139*1da177e4SLinus Torvalds 140*1da177e4SLinus Torvalds dev_set_drvdata(&dev->dev, host); 141*1da177e4SLinus Torvalds scsi_scan_host(host); 142*1da177e4SLinus Torvalds 143*1da177e4SLinus Torvalds return 0; 144*1da177e4SLinus Torvalds 145*1da177e4SLinus Torvalds out_put_host: 146*1da177e4SLinus Torvalds scsi_host_put(host); 147*1da177e4SLinus Torvalds out_kfree: 148*1da177e4SLinus Torvalds iounmap(hostdata->base); 149*1da177e4SLinus Torvalds kfree(hostdata); 150*1da177e4SLinus Torvalds return -ENODEV; 151*1da177e4SLinus Torvalds } 152*1da177e4SLinus Torvalds 153*1da177e4SLinus Torvalds static int __exit 154*1da177e4SLinus Torvalds lasi700_driver_remove(struct parisc_device *dev) 155*1da177e4SLinus Torvalds { 156*1da177e4SLinus Torvalds struct Scsi_Host *host = dev_get_drvdata(&dev->dev); 157*1da177e4SLinus Torvalds struct NCR_700_Host_Parameters *hostdata = 158*1da177e4SLinus Torvalds (struct NCR_700_Host_Parameters *)host->hostdata[0]; 159*1da177e4SLinus Torvalds 160*1da177e4SLinus Torvalds scsi_remove_host(host); 161*1da177e4SLinus Torvalds NCR_700_release(host); 162*1da177e4SLinus Torvalds free_irq(host->irq, host); 163*1da177e4SLinus Torvalds iounmap(hostdata->base); 164*1da177e4SLinus Torvalds kfree(hostdata); 165*1da177e4SLinus Torvalds 166*1da177e4SLinus Torvalds return 0; 167*1da177e4SLinus Torvalds } 168*1da177e4SLinus Torvalds 169*1da177e4SLinus Torvalds static struct parisc_driver lasi700_driver = { 170*1da177e4SLinus Torvalds .name = "Lasi SCSI", 171*1da177e4SLinus Torvalds .id_table = lasi700_ids, 172*1da177e4SLinus Torvalds .probe = lasi700_probe, 173*1da177e4SLinus Torvalds .remove = __devexit_p(lasi700_driver_remove), 174*1da177e4SLinus Torvalds }; 175*1da177e4SLinus Torvalds 176*1da177e4SLinus Torvalds static int __init 177*1da177e4SLinus Torvalds lasi700_init(void) 178*1da177e4SLinus Torvalds { 179*1da177e4SLinus Torvalds return register_parisc_driver(&lasi700_driver); 180*1da177e4SLinus Torvalds } 181*1da177e4SLinus Torvalds 182*1da177e4SLinus Torvalds static void __exit 183*1da177e4SLinus Torvalds lasi700_exit(void) 184*1da177e4SLinus Torvalds { 185*1da177e4SLinus Torvalds unregister_parisc_driver(&lasi700_driver); 186*1da177e4SLinus Torvalds } 187*1da177e4SLinus Torvalds 188*1da177e4SLinus Torvalds module_init(lasi700_init); 189*1da177e4SLinus Torvalds module_exit(lasi700_exit); 190