| Kars de Jong | 506c7bb | 2007-06-17 14:47:07 +0200 | [diff] [blame] | 1 | /* | 
 | 2 |  * Detection routine for the NCR53c710 based MVME16x SCSI Controllers for Linux. | 
 | 3 |  * | 
 | 4 |  * Based on work by Alan Hourihane | 
 | 5 |  * | 
 | 6 |  * Rewritten to use 53c700.c by Kars de Jong <jongk@linux-m68k.org> | 
 | 7 |  */ | 
 | 8 |  | 
 | 9 | #include <linux/module.h> | 
 | 10 | #include <linux/blkdev.h> | 
 | 11 | #include <linux/device.h> | 
 | 12 | #include <linux/platform_device.h> | 
 | 13 | #include <linux/init.h> | 
 | 14 | #include <linux/interrupt.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> | 
| Kars de Jong | 506c7bb | 2007-06-17 14:47:07 +0200 | [diff] [blame] | 16 | #include <asm/mvme16xhw.h> | 
 | 17 | #include <scsi/scsi_host.h> | 
 | 18 | #include <scsi/scsi_device.h> | 
 | 19 | #include <scsi/scsi_transport.h> | 
 | 20 | #include <scsi/scsi_transport_spi.h> | 
 | 21 |  | 
 | 22 | #include "53c700.h" | 
 | 23 |  | 
 | 24 | MODULE_AUTHOR("Kars de Jong <jongk@linux-m68k.org>"); | 
 | 25 | MODULE_DESCRIPTION("MVME16x NCR53C710 driver"); | 
 | 26 | MODULE_LICENSE("GPL"); | 
 | 27 |  | 
 | 28 | static struct scsi_host_template mvme16x_scsi_driver_template = { | 
 | 29 | 	.name			= "MVME16x NCR53c710 SCSI", | 
 | 30 | 	.proc_name		= "MVME16x", | 
 | 31 | 	.this_id		= 7, | 
 | 32 | 	.module			= THIS_MODULE, | 
 | 33 | }; | 
 | 34 |  | 
 | 35 | static struct platform_device *mvme16x_scsi_device; | 
 | 36 |  | 
| Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 37 | static int mvme16x_probe(struct platform_device *dev) | 
| Kars de Jong | 506c7bb | 2007-06-17 14:47:07 +0200 | [diff] [blame] | 38 | { | 
 | 39 | 	struct Scsi_Host * host = NULL; | 
 | 40 | 	struct NCR_700_Host_Parameters *hostdata; | 
 | 41 |  | 
 | 42 | 	if (!MACH_IS_MVME16x) | 
 | 43 | 		goto out; | 
 | 44 |  | 
 | 45 | 	if (mvme16x_config & MVME16x_CONFIG_NO_SCSICHIP) { | 
 | 46 | 		printk(KERN_INFO "mvme16x-scsi: detection disabled, " | 
 | 47 | 				 "SCSI chip not present\n"); | 
 | 48 | 		goto out; | 
 | 49 | 	} | 
 | 50 |  | 
| Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 51 | 	hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL); | 
| Kars de Jong | 506c7bb | 2007-06-17 14:47:07 +0200 | [diff] [blame] | 52 | 	if (hostdata == NULL) { | 
 | 53 | 		printk(KERN_ERR "mvme16x-scsi: " | 
 | 54 | 				"Failed to allocate host data\n"); | 
 | 55 | 		goto out; | 
 | 56 | 	} | 
| Kars de Jong | 506c7bb | 2007-06-17 14:47:07 +0200 | [diff] [blame] | 57 |  | 
 | 58 | 	/* Fill in the required pieces of hostdata */ | 
 | 59 | 	hostdata->base = (void __iomem *)0xfff47000UL; | 
 | 60 | 	hostdata->clock = 50;	/* XXX - depends on the CPU clock! */ | 
 | 61 | 	hostdata->chip710 = 1; | 
 | 62 | 	hostdata->dmode_extra = DMODE_FC2; | 
 | 63 | 	hostdata->dcntl_extra = EA_710; | 
 | 64 | 	hostdata->ctest7_extra = CTEST7_TT1; | 
 | 65 |  | 
 | 66 | 	/* and register the chip */ | 
| Geert Uytterhoeven | e5779a5 | 2009-03-11 09:23:52 +0100 | [diff] [blame] | 67 | 	host = NCR_700_detect(&mvme16x_scsi_driver_template, hostdata, | 
 | 68 | 			      &dev->dev); | 
| Kars de Jong | 506c7bb | 2007-06-17 14:47:07 +0200 | [diff] [blame] | 69 | 	if (!host) { | 
 | 70 | 		printk(KERN_ERR "mvme16x-scsi: No host detected; " | 
 | 71 | 				"board configuration problem?\n"); | 
 | 72 | 		goto out_free; | 
 | 73 | 	} | 
 | 74 | 	host->this_id = 7; | 
 | 75 | 	host->base = 0xfff47000UL; | 
 | 76 | 	host->irq = MVME16x_IRQ_SCSI; | 
 | 77 | 	if (request_irq(host->irq, NCR_700_intr, 0, "mvme16x-scsi", host)) { | 
 | 78 | 		printk(KERN_ERR "mvme16x-scsi: request_irq failed\n"); | 
 | 79 | 		goto out_put_host; | 
 | 80 | 	} | 
 | 81 |  | 
 | 82 | 	/* Enable scsi chip ints */ | 
 | 83 | 	{ | 
 | 84 | 		volatile unsigned long v; | 
 | 85 |  | 
 | 86 | 		/* Enable scsi interrupts at level 4 in PCCchip2 */ | 
 | 87 | 		v = in_be32(0xfff4202c); | 
 | 88 | 		v = (v & ~0xff) | 0x10 | 4; | 
 | 89 | 		out_be32(0xfff4202c, v); | 
 | 90 | 	} | 
 | 91 |  | 
| Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 92 | 	platform_set_drvdata(dev, host); | 
| Kars de Jong | 506c7bb | 2007-06-17 14:47:07 +0200 | [diff] [blame] | 93 | 	scsi_scan_host(host); | 
 | 94 |  | 
 | 95 | 	return 0; | 
 | 96 |  | 
 | 97 |  out_put_host: | 
 | 98 | 	scsi_host_put(host); | 
 | 99 |  out_free: | 
 | 100 | 	kfree(hostdata); | 
 | 101 |  out: | 
 | 102 | 	return -ENODEV; | 
 | 103 | } | 
 | 104 |  | 
| Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 105 | static int mvme16x_device_remove(struct platform_device *dev) | 
| Kars de Jong | 506c7bb | 2007-06-17 14:47:07 +0200 | [diff] [blame] | 106 | { | 
| Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 107 | 	struct Scsi_Host *host = platform_get_drvdata(dev); | 
| Kars de Jong | 506c7bb | 2007-06-17 14:47:07 +0200 | [diff] [blame] | 108 | 	struct NCR_700_Host_Parameters *hostdata = shost_priv(host); | 
 | 109 |  | 
 | 110 | 	/* Disable scsi chip ints */ | 
 | 111 | 	{ | 
 | 112 | 		volatile unsigned long v; | 
 | 113 |  | 
 | 114 | 		v = in_be32(0xfff4202c); | 
 | 115 | 		v &= ~0x10; | 
 | 116 | 		out_be32(0xfff4202c, v); | 
 | 117 | 	} | 
 | 118 | 	scsi_remove_host(host); | 
 | 119 | 	NCR_700_release(host); | 
 | 120 | 	kfree(hostdata); | 
 | 121 | 	free_irq(host->irq, host); | 
 | 122 |  | 
 | 123 | 	return 0; | 
 | 124 | } | 
 | 125 |  | 
| Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 126 | static struct platform_driver mvme16x_scsi_driver = { | 
 | 127 | 	.driver = { | 
 | 128 | 		.name           = "mvme16x-scsi", | 
 | 129 | 		.owner          = THIS_MODULE, | 
 | 130 | 	}, | 
 | 131 | 	.probe          = mvme16x_probe, | 
| Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 132 | 	.remove         = mvme16x_device_remove, | 
| Kars de Jong | 506c7bb | 2007-06-17 14:47:07 +0200 | [diff] [blame] | 133 | }; | 
 | 134 |  | 
 | 135 | static int __init mvme16x_scsi_init(void) | 
 | 136 | { | 
 | 137 | 	int err; | 
 | 138 |  | 
| Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 139 | 	err = platform_driver_register(&mvme16x_scsi_driver); | 
| Kars de Jong | 506c7bb | 2007-06-17 14:47:07 +0200 | [diff] [blame] | 140 | 	if (err) | 
 | 141 | 		return err; | 
 | 142 |  | 
 | 143 | 	mvme16x_scsi_device = platform_device_register_simple("mvme16x-scsi", | 
 | 144 | 							      -1, NULL, 0); | 
 | 145 | 	if (IS_ERR(mvme16x_scsi_device)) { | 
| Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 146 | 		platform_driver_unregister(&mvme16x_scsi_driver); | 
| Kars de Jong | 506c7bb | 2007-06-17 14:47:07 +0200 | [diff] [blame] | 147 | 		return PTR_ERR(mvme16x_scsi_device); | 
 | 148 | 	} | 
 | 149 |  | 
 | 150 | 	return 0; | 
 | 151 | } | 
 | 152 |  | 
 | 153 | static void __exit mvme16x_scsi_exit(void) | 
 | 154 | { | 
 | 155 | 	platform_device_unregister(mvme16x_scsi_device); | 
| Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 156 | 	platform_driver_unregister(&mvme16x_scsi_driver); | 
| Kars de Jong | 506c7bb | 2007-06-17 14:47:07 +0200 | [diff] [blame] | 157 | } | 
 | 158 |  | 
 | 159 | module_init(mvme16x_scsi_init); | 
 | 160 | module_exit(mvme16x_scsi_exit); |