xref: /openbmc/linux/drivers/scsi/bvme6000_scsi.c (revision e5779a583ddb9916b37cfbb916dc53ec2eaf0b9b)
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>
158276b58aSKars de Jong #include <asm/bvme6000hw.h>
168276b58aSKars de Jong #include <scsi/scsi_host.h>
178276b58aSKars de Jong #include <scsi/scsi_device.h>
188276b58aSKars de Jong #include <scsi/scsi_transport.h>
198276b58aSKars de Jong #include <scsi/scsi_transport_spi.h>
208276b58aSKars de Jong 
218276b58aSKars de Jong #include "53c700.h"
228276b58aSKars de Jong 
238276b58aSKars de Jong MODULE_AUTHOR("Richard Hirst <richard@sleepie.demon.co.uk>");
248276b58aSKars de Jong MODULE_DESCRIPTION("BVME6000 NCR53C710 driver");
258276b58aSKars de Jong MODULE_LICENSE("GPL");
268276b58aSKars de Jong 
278276b58aSKars de Jong static struct scsi_host_template bvme6000_scsi_driver_template = {
288276b58aSKars de Jong 	.name			= "BVME6000 NCR53c710 SCSI",
298276b58aSKars de Jong 	.proc_name		= "BVME6000",
308276b58aSKars de Jong 	.this_id		= 7,
318276b58aSKars de Jong 	.module			= THIS_MODULE,
328276b58aSKars de Jong };
338276b58aSKars de Jong 
348276b58aSKars de Jong static struct platform_device *bvme6000_scsi_device;
358276b58aSKars de Jong 
368276b58aSKars de Jong static __devinit int
377a192ec3SMing Lei bvme6000_probe(struct platform_device *dev)
388276b58aSKars de Jong {
39bbfbbbc1SMariusz Kozlowski 	struct Scsi_Host *host;
408276b58aSKars de Jong 	struct NCR_700_Host_Parameters *hostdata;
418276b58aSKars de Jong 
428276b58aSKars de Jong 	if (!MACH_IS_BVME6000)
438276b58aSKars de Jong 		goto out;
448276b58aSKars de Jong 
45bbfbbbc1SMariusz Kozlowski 	hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL);
46bbfbbbc1SMariusz Kozlowski 	if (!hostdata) {
478276b58aSKars de Jong 		printk(KERN_ERR "bvme6000-scsi: "
488276b58aSKars de Jong 				"Failed to allocate host data\n");
498276b58aSKars de Jong 		goto out;
508276b58aSKars de Jong 	}
518276b58aSKars de Jong 
528276b58aSKars de Jong 	/* Fill in the required pieces of hostdata */
538276b58aSKars de Jong 	hostdata->base = (void __iomem *)BVME_NCR53C710_BASE;
548276b58aSKars de Jong 	hostdata->clock = 40;	/* XXX - depends on the CPU clock! */
558276b58aSKars de Jong 	hostdata->chip710 = 1;
568276b58aSKars de Jong 	hostdata->dmode_extra = DMODE_FC2;
578276b58aSKars de Jong 	hostdata->dcntl_extra = EA_710;
588276b58aSKars de Jong 	hostdata->ctest7_extra = CTEST7_TT1;
598276b58aSKars de Jong 
608276b58aSKars de Jong 	/* and register the chip */
61*e5779a58SGeert Uytterhoeven 	host = NCR_700_detect(&bvme6000_scsi_driver_template, hostdata,
62*e5779a58SGeert Uytterhoeven 			      &dev->dev);
638276b58aSKars de Jong 	if (!host) {
648276b58aSKars de Jong 		printk(KERN_ERR "bvme6000-scsi: No host detected; "
658276b58aSKars de Jong 				"board configuration problem?\n");
668276b58aSKars de Jong 		goto out_free;
678276b58aSKars de Jong 	}
688276b58aSKars de Jong 	host->base = BVME_NCR53C710_BASE;
698276b58aSKars de Jong 	host->this_id = 7;
708276b58aSKars de Jong 	host->irq = BVME_IRQ_SCSI;
718276b58aSKars de Jong 	if (request_irq(BVME_IRQ_SCSI, NCR_700_intr, 0, "bvme6000-scsi",
728276b58aSKars de Jong 			host)) {
738276b58aSKars de Jong 		printk(KERN_ERR "bvme6000-scsi: request_irq failed\n");
748276b58aSKars de Jong 		goto out_put_host;
758276b58aSKars de Jong 	}
768276b58aSKars de Jong 
777a192ec3SMing Lei 	platform_set_drvdata(dev, host);
788276b58aSKars de Jong 	scsi_scan_host(host);
798276b58aSKars de Jong 
808276b58aSKars de Jong 	return 0;
818276b58aSKars de Jong 
828276b58aSKars de Jong  out_put_host:
838276b58aSKars de Jong 	scsi_host_put(host);
848276b58aSKars de Jong  out_free:
858276b58aSKars de Jong 	kfree(hostdata);
868276b58aSKars de Jong  out:
878276b58aSKars de Jong 	return -ENODEV;
888276b58aSKars de Jong }
898276b58aSKars de Jong 
908276b58aSKars de Jong static __devexit int
917a192ec3SMing Lei bvme6000_device_remove(struct platform_device *dev)
928276b58aSKars de Jong {
937a192ec3SMing Lei 	struct Scsi_Host *host = platform_get_drvdata(dev);
948276b58aSKars de Jong 	struct NCR_700_Host_Parameters *hostdata = shost_priv(host);
958276b58aSKars de Jong 
968276b58aSKars de Jong 	scsi_remove_host(host);
978276b58aSKars de Jong 	NCR_700_release(host);
988276b58aSKars de Jong 	kfree(hostdata);
998276b58aSKars de Jong 	free_irq(host->irq, host);
1008276b58aSKars de Jong 
1018276b58aSKars de Jong 	return 0;
1028276b58aSKars de Jong }
1038276b58aSKars de Jong 
1047a192ec3SMing Lei static struct platform_driver bvme6000_scsi_driver = {
1057a192ec3SMing Lei 	.driver = {
1068276b58aSKars de Jong 		.name		= "bvme6000-scsi",
1077a192ec3SMing Lei 		.owner		= THIS_MODULE,
1087a192ec3SMing Lei 	},
1098276b58aSKars de Jong 	.probe		= bvme6000_probe,
1108276b58aSKars de Jong 	.remove		= __devexit_p(bvme6000_device_remove),
1118276b58aSKars de Jong };
1128276b58aSKars de Jong 
1138276b58aSKars de Jong static int __init bvme6000_scsi_init(void)
1148276b58aSKars de Jong {
1158276b58aSKars de Jong 	int err;
1168276b58aSKars de Jong 
1177a192ec3SMing Lei 	err = platform_driver_register(&bvme6000_scsi_driver);
11896249cf9SGeert Uytterhoeven 	if (err)
1198276b58aSKars de Jong 		return err;
1208276b58aSKars de Jong 
1218276b58aSKars de Jong 	bvme6000_scsi_device = platform_device_register_simple("bvme6000-scsi",
1228276b58aSKars de Jong 							       -1, NULL, 0);
1238276b58aSKars de Jong 	if (IS_ERR(bvme6000_scsi_device)) {
1247a192ec3SMing Lei 		platform_driver_unregister(&bvme6000_scsi_driver);
1258276b58aSKars de Jong 		return PTR_ERR(bvme6000_scsi_device);
1268276b58aSKars de Jong 	}
1278276b58aSKars de Jong 
1288276b58aSKars de Jong 	return 0;
1298276b58aSKars de Jong }
1308276b58aSKars de Jong 
1318276b58aSKars de Jong static void __exit bvme6000_scsi_exit(void)
1328276b58aSKars de Jong {
1338276b58aSKars de Jong 	platform_device_unregister(bvme6000_scsi_device);
1347a192ec3SMing Lei 	platform_driver_unregister(&bvme6000_scsi_driver);
1358276b58aSKars de Jong }
1368276b58aSKars de Jong 
1378276b58aSKars de Jong module_init(bvme6000_scsi_init);
1388276b58aSKars de Jong module_exit(bvme6000_scsi_exit);
139