xref: /openbmc/linux/drivers/scsi/bvme6000_scsi.c (revision 58e16d792a6a8c6b750f637a4649967fcac853dc)
1*09c434b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
28276b58aSKars de Jong /*
38276b58aSKars de Jong  * Detection routine for the NCR53c710 based BVME6000 SCSI Controllers for Linux.
48276b58aSKars de Jong  *
58276b58aSKars de Jong  * Based on work by Alan Hourihane and Kars de Jong
68276b58aSKars de Jong  *
78276b58aSKars de Jong  * Rewritten to use 53c700.c by Richard Hirst <richard@sleepie.demon.co.uk>
88276b58aSKars de Jong  */
98276b58aSKars de Jong 
108276b58aSKars de Jong #include <linux/module.h>
118276b58aSKars de Jong #include <linux/blkdev.h>
128276b58aSKars de Jong #include <linux/device.h>
138276b58aSKars de Jong #include <linux/platform_device.h>
148276b58aSKars de Jong #include <linux/init.h>
158276b58aSKars de Jong #include <linux/interrupt.h>
165a0e3ad6STejun Heo #include <linux/slab.h>
178276b58aSKars de Jong #include <asm/bvme6000hw.h>
188276b58aSKars de Jong #include <scsi/scsi_host.h>
198276b58aSKars de Jong #include <scsi/scsi_device.h>
208276b58aSKars de Jong #include <scsi/scsi_transport.h>
218276b58aSKars de Jong #include <scsi/scsi_transport_spi.h>
228276b58aSKars de Jong 
238276b58aSKars de Jong #include "53c700.h"
248276b58aSKars de Jong 
258276b58aSKars de Jong MODULE_AUTHOR("Richard Hirst <richard@sleepie.demon.co.uk>");
268276b58aSKars de Jong MODULE_DESCRIPTION("BVME6000 NCR53C710 driver");
278276b58aSKars de Jong MODULE_LICENSE("GPL");
288276b58aSKars de Jong 
298276b58aSKars de Jong static struct scsi_host_template bvme6000_scsi_driver_template = {
308276b58aSKars de Jong 	.name			= "BVME6000 NCR53c710 SCSI",
318276b58aSKars de Jong 	.proc_name		= "BVME6000",
328276b58aSKars de Jong 	.this_id		= 7,
338276b58aSKars de Jong 	.module			= THIS_MODULE,
348276b58aSKars de Jong };
358276b58aSKars de Jong 
368276b58aSKars de Jong static struct platform_device *bvme6000_scsi_device;
378276b58aSKars de Jong 
386f039790SGreg Kroah-Hartman static int
bvme6000_probe(struct platform_device * dev)397a192ec3SMing Lei bvme6000_probe(struct platform_device *dev)
408276b58aSKars de Jong {
41bbfbbbc1SMariusz Kozlowski 	struct Scsi_Host *host;
428276b58aSKars de Jong 	struct NCR_700_Host_Parameters *hostdata;
438276b58aSKars de Jong 
448276b58aSKars de Jong 	if (!MACH_IS_BVME6000)
458276b58aSKars de Jong 		goto out;
468276b58aSKars de Jong 
47bbfbbbc1SMariusz Kozlowski 	hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL);
48bbfbbbc1SMariusz Kozlowski 	if (!hostdata) {
498276b58aSKars de Jong 		printk(KERN_ERR "bvme6000-scsi: "
508276b58aSKars de Jong 				"Failed to allocate host data\n");
518276b58aSKars de Jong 		goto out;
528276b58aSKars de Jong 	}
538276b58aSKars de Jong 
548276b58aSKars de Jong 	/* Fill in the required pieces of hostdata */
558276b58aSKars de Jong 	hostdata->base = (void __iomem *)BVME_NCR53C710_BASE;
568276b58aSKars de Jong 	hostdata->clock = 40;	/* XXX - depends on the CPU clock! */
578276b58aSKars de Jong 	hostdata->chip710 = 1;
588276b58aSKars de Jong 	hostdata->dmode_extra = DMODE_FC2;
598276b58aSKars de Jong 	hostdata->dcntl_extra = EA_710;
608276b58aSKars de Jong 	hostdata->ctest7_extra = CTEST7_TT1;
618276b58aSKars de Jong 
628276b58aSKars de Jong 	/* and register the chip */
63e5779a58SGeert Uytterhoeven 	host = NCR_700_detect(&bvme6000_scsi_driver_template, hostdata,
64e5779a58SGeert Uytterhoeven 			      &dev->dev);
658276b58aSKars de Jong 	if (!host) {
668276b58aSKars de Jong 		printk(KERN_ERR "bvme6000-scsi: No host detected; "
678276b58aSKars de Jong 				"board configuration problem?\n");
688276b58aSKars de Jong 		goto out_free;
698276b58aSKars de Jong 	}
708276b58aSKars de Jong 	host->base = BVME_NCR53C710_BASE;
718276b58aSKars de Jong 	host->this_id = 7;
728276b58aSKars de Jong 	host->irq = BVME_IRQ_SCSI;
738276b58aSKars de Jong 	if (request_irq(BVME_IRQ_SCSI, NCR_700_intr, 0, "bvme6000-scsi",
748276b58aSKars de Jong 			host)) {
758276b58aSKars de Jong 		printk(KERN_ERR "bvme6000-scsi: request_irq failed\n");
768276b58aSKars de Jong 		goto out_put_host;
778276b58aSKars de Jong 	}
788276b58aSKars de Jong 
797a192ec3SMing Lei 	platform_set_drvdata(dev, host);
808276b58aSKars de Jong 	scsi_scan_host(host);
818276b58aSKars de Jong 
828276b58aSKars de Jong 	return 0;
838276b58aSKars de Jong 
848276b58aSKars de Jong  out_put_host:
858276b58aSKars de Jong 	scsi_host_put(host);
868276b58aSKars de Jong  out_free:
878276b58aSKars de Jong 	kfree(hostdata);
888276b58aSKars de Jong  out:
898276b58aSKars de Jong 	return -ENODEV;
908276b58aSKars de Jong }
918276b58aSKars de Jong 
926f039790SGreg Kroah-Hartman static int
bvme6000_device_remove(struct platform_device * dev)937a192ec3SMing Lei bvme6000_device_remove(struct platform_device *dev)
948276b58aSKars de Jong {
957a192ec3SMing Lei 	struct Scsi_Host *host = platform_get_drvdata(dev);
968276b58aSKars de Jong 	struct NCR_700_Host_Parameters *hostdata = shost_priv(host);
978276b58aSKars de Jong 
988276b58aSKars de Jong 	scsi_remove_host(host);
998276b58aSKars de Jong 	NCR_700_release(host);
1008276b58aSKars de Jong 	kfree(hostdata);
1018276b58aSKars de Jong 	free_irq(host->irq, host);
1028276b58aSKars de Jong 
1038276b58aSKars de Jong 	return 0;
1048276b58aSKars de Jong }
1058276b58aSKars de Jong 
1067a192ec3SMing Lei static struct platform_driver bvme6000_scsi_driver = {
1077a192ec3SMing Lei 	.driver = {
1088276b58aSKars de Jong 		.name		= "bvme6000-scsi",
1097a192ec3SMing Lei 	},
1108276b58aSKars de Jong 	.probe		= bvme6000_probe,
1116f039790SGreg Kroah-Hartman 	.remove		= bvme6000_device_remove,
1128276b58aSKars de Jong };
1138276b58aSKars de Jong 
bvme6000_scsi_init(void)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 
bvme6000_scsi_exit(void)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