blob: 9e9a82b03f2de3f6b30abc1a043564dd989d7d86 [file] [log] [blame]
Kars de Jong8276b582007-06-17 14:47:06 +02001/*
2 * Detection routine for the NCR53c710 based BVME6000 SCSI Controllers for Linux.
3 *
4 * Based on work by Alan Hourihane and Kars de Jong
5 *
6 * Rewritten to use 53c700.c by Richard Hirst <richard@sleepie.demon.co.uk>
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>
15#include <asm/bvme6000hw.h>
16#include <scsi/scsi_host.h>
17#include <scsi/scsi_device.h>
18#include <scsi/scsi_transport.h>
19#include <scsi/scsi_transport_spi.h>
20
21#include "53c700.h"
22
23MODULE_AUTHOR("Richard Hirst <richard@sleepie.demon.co.uk>");
24MODULE_DESCRIPTION("BVME6000 NCR53C710 driver");
25MODULE_LICENSE("GPL");
26
27static struct scsi_host_template bvme6000_scsi_driver_template = {
28 .name = "BVME6000 NCR53c710 SCSI",
29 .proc_name = "BVME6000",
30 .this_id = 7,
31 .module = THIS_MODULE,
32};
33
34static struct platform_device *bvme6000_scsi_device;
35
36static __devinit int
Ming Lei7a192ec2009-02-06 23:40:12 +080037bvme6000_probe(struct platform_device *dev)
Kars de Jong8276b582007-06-17 14:47:06 +020038{
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +020039 struct Scsi_Host *host;
Kars de Jong8276b582007-06-17 14:47:06 +020040 struct NCR_700_Host_Parameters *hostdata;
41
42 if (!MACH_IS_BVME6000)
43 goto out;
44
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +020045 hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL);
46 if (!hostdata) {
Kars de Jong8276b582007-06-17 14:47:06 +020047 printk(KERN_ERR "bvme6000-scsi: "
48 "Failed to allocate host data\n");
49 goto out;
50 }
Kars de Jong8276b582007-06-17 14:47:06 +020051
52 /* Fill in the required pieces of hostdata */
53 hostdata->base = (void __iomem *)BVME_NCR53C710_BASE;
54 hostdata->clock = 40; /* XXX - depends on the CPU clock! */
55 hostdata->chip710 = 1;
56 hostdata->dmode_extra = DMODE_FC2;
57 hostdata->dcntl_extra = EA_710;
58 hostdata->ctest7_extra = CTEST7_TT1;
59
60 /* and register the chip */
61 host = NCR_700_detect(&bvme6000_scsi_driver_template, hostdata, dev);
62 if (!host) {
63 printk(KERN_ERR "bvme6000-scsi: No host detected; "
64 "board configuration problem?\n");
65 goto out_free;
66 }
67 host->base = BVME_NCR53C710_BASE;
68 host->this_id = 7;
69 host->irq = BVME_IRQ_SCSI;
70 if (request_irq(BVME_IRQ_SCSI, NCR_700_intr, 0, "bvme6000-scsi",
71 host)) {
72 printk(KERN_ERR "bvme6000-scsi: request_irq failed\n");
73 goto out_put_host;
74 }
75
Ming Lei7a192ec2009-02-06 23:40:12 +080076 platform_set_drvdata(dev, host);
Kars de Jong8276b582007-06-17 14:47:06 +020077 scsi_scan_host(host);
78
79 return 0;
80
81 out_put_host:
82 scsi_host_put(host);
83 out_free:
84 kfree(hostdata);
85 out:
86 return -ENODEV;
87}
88
89static __devexit int
Ming Lei7a192ec2009-02-06 23:40:12 +080090bvme6000_device_remove(struct platform_device *dev)
Kars de Jong8276b582007-06-17 14:47:06 +020091{
Ming Lei7a192ec2009-02-06 23:40:12 +080092 struct Scsi_Host *host = platform_get_drvdata(dev);
Kars de Jong8276b582007-06-17 14:47:06 +020093 struct NCR_700_Host_Parameters *hostdata = shost_priv(host);
94
95 scsi_remove_host(host);
96 NCR_700_release(host);
97 kfree(hostdata);
98 free_irq(host->irq, host);
99
100 return 0;
101}
102
Ming Lei7a192ec2009-02-06 23:40:12 +0800103static struct platform_driver bvme6000_scsi_driver = {
104 .driver = {
105 .name = "bvme6000-scsi",
106 .owner = THIS_MODULE,
107 },
108 .probe = bvme6000_probe,
109 .remove = __devexit_p(bvme6000_device_remove),
Kars de Jong8276b582007-06-17 14:47:06 +0200110};
111
112static int __init bvme6000_scsi_init(void)
113{
114 int err;
115
Ming Lei7a192ec2009-02-06 23:40:12 +0800116 err = platform_driver_register(&bvme6000_scsi_driver);
Geert Uytterhoeven96249cf2007-06-19 09:47:28 +0200117 if (err)
Kars de Jong8276b582007-06-17 14:47:06 +0200118 return err;
119
120 bvme6000_scsi_device = platform_device_register_simple("bvme6000-scsi",
121 -1, NULL, 0);
122 if (IS_ERR(bvme6000_scsi_device)) {
Ming Lei7a192ec2009-02-06 23:40:12 +0800123 platform_driver_unregister(&bvme6000_scsi_driver);
Kars de Jong8276b582007-06-17 14:47:06 +0200124 return PTR_ERR(bvme6000_scsi_device);
125 }
126
127 return 0;
128}
129
130static void __exit bvme6000_scsi_exit(void)
131{
132 platform_device_unregister(bvme6000_scsi_device);
Ming Lei7a192ec2009-02-06 23:40:12 +0800133 platform_driver_unregister(&bvme6000_scsi_driver);
Kars de Jong8276b582007-06-17 14:47:06 +0200134}
135
136module_init(bvme6000_scsi_init);
137module_exit(bvme6000_scsi_exit);