18276b58aSKars de Jong /* 28276b58aSKars de Jong * Detection routine for the NCR53c710 based BVME6000 SCSI Controllers for Linux. 38276b58aSKars de Jong * 48276b58aSKars de Jong * Based on work by Alan Hourihane and Kars de Jong 58276b58aSKars de Jong * 68276b58aSKars de Jong * Rewritten to use 53c700.c by Richard Hirst <richard@sleepie.demon.co.uk> 78276b58aSKars de Jong */ 88276b58aSKars de Jong 98276b58aSKars de Jong #include <linux/module.h> 108276b58aSKars de Jong #include <linux/blkdev.h> 118276b58aSKars de Jong #include <linux/device.h> 128276b58aSKars de Jong #include <linux/platform_device.h> 138276b58aSKars de Jong #include <linux/init.h> 148276b58aSKars de Jong #include <linux/interrupt.h> 155a0e3ad6STejun Heo #include <linux/slab.h> 168276b58aSKars de Jong #include <asm/bvme6000hw.h> 178276b58aSKars de Jong #include <scsi/scsi_host.h> 188276b58aSKars de Jong #include <scsi/scsi_device.h> 198276b58aSKars de Jong #include <scsi/scsi_transport.h> 208276b58aSKars de Jong #include <scsi/scsi_transport_spi.h> 218276b58aSKars de Jong 228276b58aSKars de Jong #include "53c700.h" 238276b58aSKars de Jong 248276b58aSKars de Jong MODULE_AUTHOR("Richard Hirst <richard@sleepie.demon.co.uk>"); 258276b58aSKars de Jong MODULE_DESCRIPTION("BVME6000 NCR53C710 driver"); 268276b58aSKars de Jong MODULE_LICENSE("GPL"); 278276b58aSKars de Jong 288276b58aSKars de Jong static struct scsi_host_template bvme6000_scsi_driver_template = { 298276b58aSKars de Jong .name = "BVME6000 NCR53c710 SCSI", 308276b58aSKars de Jong .proc_name = "BVME6000", 318276b58aSKars de Jong .this_id = 7, 328276b58aSKars de Jong .module = THIS_MODULE, 338276b58aSKars de Jong }; 348276b58aSKars de Jong 358276b58aSKars de Jong static struct platform_device *bvme6000_scsi_device; 368276b58aSKars de Jong 37*6f039790SGreg Kroah-Hartman static int 387a192ec3SMing Lei bvme6000_probe(struct platform_device *dev) 398276b58aSKars de Jong { 40bbfbbbc1SMariusz Kozlowski struct Scsi_Host *host; 418276b58aSKars de Jong struct NCR_700_Host_Parameters *hostdata; 428276b58aSKars de Jong 438276b58aSKars de Jong if (!MACH_IS_BVME6000) 448276b58aSKars de Jong goto out; 458276b58aSKars de Jong 46bbfbbbc1SMariusz Kozlowski hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL); 47bbfbbbc1SMariusz Kozlowski if (!hostdata) { 488276b58aSKars de Jong printk(KERN_ERR "bvme6000-scsi: " 498276b58aSKars de Jong "Failed to allocate host data\n"); 508276b58aSKars de Jong goto out; 518276b58aSKars de Jong } 528276b58aSKars de Jong 538276b58aSKars de Jong /* Fill in the required pieces of hostdata */ 548276b58aSKars de Jong hostdata->base = (void __iomem *)BVME_NCR53C710_BASE; 558276b58aSKars de Jong hostdata->clock = 40; /* XXX - depends on the CPU clock! */ 568276b58aSKars de Jong hostdata->chip710 = 1; 578276b58aSKars de Jong hostdata->dmode_extra = DMODE_FC2; 588276b58aSKars de Jong hostdata->dcntl_extra = EA_710; 598276b58aSKars de Jong hostdata->ctest7_extra = CTEST7_TT1; 608276b58aSKars de Jong 618276b58aSKars de Jong /* and register the chip */ 62e5779a58SGeert Uytterhoeven host = NCR_700_detect(&bvme6000_scsi_driver_template, hostdata, 63e5779a58SGeert Uytterhoeven &dev->dev); 648276b58aSKars de Jong if (!host) { 658276b58aSKars de Jong printk(KERN_ERR "bvme6000-scsi: No host detected; " 668276b58aSKars de Jong "board configuration problem?\n"); 678276b58aSKars de Jong goto out_free; 688276b58aSKars de Jong } 698276b58aSKars de Jong host->base = BVME_NCR53C710_BASE; 708276b58aSKars de Jong host->this_id = 7; 718276b58aSKars de Jong host->irq = BVME_IRQ_SCSI; 728276b58aSKars de Jong if (request_irq(BVME_IRQ_SCSI, NCR_700_intr, 0, "bvme6000-scsi", 738276b58aSKars de Jong host)) { 748276b58aSKars de Jong printk(KERN_ERR "bvme6000-scsi: request_irq failed\n"); 758276b58aSKars de Jong goto out_put_host; 768276b58aSKars de Jong } 778276b58aSKars de Jong 787a192ec3SMing Lei platform_set_drvdata(dev, host); 798276b58aSKars de Jong scsi_scan_host(host); 808276b58aSKars de Jong 818276b58aSKars de Jong return 0; 828276b58aSKars de Jong 838276b58aSKars de Jong out_put_host: 848276b58aSKars de Jong scsi_host_put(host); 858276b58aSKars de Jong out_free: 868276b58aSKars de Jong kfree(hostdata); 878276b58aSKars de Jong out: 888276b58aSKars de Jong return -ENODEV; 898276b58aSKars de Jong } 908276b58aSKars de Jong 91*6f039790SGreg Kroah-Hartman static int 927a192ec3SMing Lei bvme6000_device_remove(struct platform_device *dev) 938276b58aSKars de Jong { 947a192ec3SMing Lei struct Scsi_Host *host = platform_get_drvdata(dev); 958276b58aSKars de Jong struct NCR_700_Host_Parameters *hostdata = shost_priv(host); 968276b58aSKars de Jong 978276b58aSKars de Jong scsi_remove_host(host); 988276b58aSKars de Jong NCR_700_release(host); 998276b58aSKars de Jong kfree(hostdata); 1008276b58aSKars de Jong free_irq(host->irq, host); 1018276b58aSKars de Jong 1028276b58aSKars de Jong return 0; 1038276b58aSKars de Jong } 1048276b58aSKars de Jong 1057a192ec3SMing Lei static struct platform_driver bvme6000_scsi_driver = { 1067a192ec3SMing Lei .driver = { 1078276b58aSKars de Jong .name = "bvme6000-scsi", 1087a192ec3SMing Lei .owner = THIS_MODULE, 1097a192ec3SMing Lei }, 1108276b58aSKars de Jong .probe = bvme6000_probe, 111*6f039790SGreg Kroah-Hartman .remove = bvme6000_device_remove, 1128276b58aSKars de Jong }; 1138276b58aSKars de Jong 1148276b58aSKars de Jong static int __init bvme6000_scsi_init(void) 1158276b58aSKars de Jong { 1168276b58aSKars de Jong int err; 1178276b58aSKars de Jong 1187a192ec3SMing Lei err = platform_driver_register(&bvme6000_scsi_driver); 11996249cf9SGeert Uytterhoeven if (err) 1208276b58aSKars de Jong return err; 1218276b58aSKars de Jong 1228276b58aSKars de Jong bvme6000_scsi_device = platform_device_register_simple("bvme6000-scsi", 1238276b58aSKars de Jong -1, NULL, 0); 1248276b58aSKars de Jong if (IS_ERR(bvme6000_scsi_device)) { 1257a192ec3SMing Lei platform_driver_unregister(&bvme6000_scsi_driver); 1268276b58aSKars de Jong return PTR_ERR(bvme6000_scsi_device); 1278276b58aSKars de Jong } 1288276b58aSKars de Jong 1298276b58aSKars de Jong return 0; 1308276b58aSKars de Jong } 1318276b58aSKars de Jong 1328276b58aSKars de Jong static void __exit bvme6000_scsi_exit(void) 1338276b58aSKars de Jong { 1348276b58aSKars de Jong platform_device_unregister(bvme6000_scsi_device); 1357a192ec3SMing Lei platform_driver_unregister(&bvme6000_scsi_driver); 1368276b58aSKars de Jong } 1378276b58aSKars de Jong 1388276b58aSKars de Jong module_init(bvme6000_scsi_init); 1398276b58aSKars de Jong module_exit(bvme6000_scsi_exit); 140