blob: 21d638299ab8e56df786dc9b82b960d0a7a8b3b5 [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Kars de Jong506c7bb2007-06-17 14:47:07 +02002/*
3 * Detection routine for the NCR53c710 based MVME16x SCSI Controllers for Linux.
4 *
5 * Based on work by Alan Hourihane
6 *
7 * Rewritten to use 53c700.c by Kars de Jong <jongk@linux-m68k.org>
8 */
9
10#include <linux/module.h>
11#include <linux/blkdev.h>
12#include <linux/device.h>
13#include <linux/platform_device.h>
14#include <linux/init.h>
15#include <linux/interrupt.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Kars de Jong506c7bb2007-06-17 14:47:07 +020017#include <asm/mvme16xhw.h>
18#include <scsi/scsi_host.h>
19#include <scsi/scsi_device.h>
20#include <scsi/scsi_transport.h>
21#include <scsi/scsi_transport_spi.h>
22
23#include "53c700.h"
24
25MODULE_AUTHOR("Kars de Jong <jongk@linux-m68k.org>");
26MODULE_DESCRIPTION("MVME16x NCR53C710 driver");
27MODULE_LICENSE("GPL");
28
29static struct scsi_host_template mvme16x_scsi_driver_template = {
30 .name = "MVME16x NCR53c710 SCSI",
31 .proc_name = "MVME16x",
32 .this_id = 7,
33 .module = THIS_MODULE,
34};
35
36static struct platform_device *mvme16x_scsi_device;
37
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080038static int mvme16x_probe(struct platform_device *dev)
Kars de Jong506c7bb2007-06-17 14:47:07 +020039{
40 struct Scsi_Host * host = NULL;
41 struct NCR_700_Host_Parameters *hostdata;
42
43 if (!MACH_IS_MVME16x)
44 goto out;
45
46 if (mvme16x_config & MVME16x_CONFIG_NO_SCSICHIP) {
47 printk(KERN_INFO "mvme16x-scsi: detection disabled, "
48 "SCSI chip not present\n");
49 goto out;
50 }
51
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +020052 hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL);
Kars de Jong506c7bb2007-06-17 14:47:07 +020053 if (hostdata == NULL) {
54 printk(KERN_ERR "mvme16x-scsi: "
55 "Failed to allocate host data\n");
56 goto out;
57 }
Kars de Jong506c7bb2007-06-17 14:47:07 +020058
59 /* Fill in the required pieces of hostdata */
60 hostdata->base = (void __iomem *)0xfff47000UL;
61 hostdata->clock = 50; /* XXX - depends on the CPU clock! */
62 hostdata->chip710 = 1;
63 hostdata->dmode_extra = DMODE_FC2;
64 hostdata->dcntl_extra = EA_710;
65 hostdata->ctest7_extra = CTEST7_TT1;
66
67 /* and register the chip */
Geert Uytterhoevene5779a52009-03-11 09:23:52 +010068 host = NCR_700_detect(&mvme16x_scsi_driver_template, hostdata,
69 &dev->dev);
Kars de Jong506c7bb2007-06-17 14:47:07 +020070 if (!host) {
71 printk(KERN_ERR "mvme16x-scsi: No host detected; "
72 "board configuration problem?\n");
73 goto out_free;
74 }
75 host->this_id = 7;
76 host->base = 0xfff47000UL;
77 host->irq = MVME16x_IRQ_SCSI;
78 if (request_irq(host->irq, NCR_700_intr, 0, "mvme16x-scsi", host)) {
79 printk(KERN_ERR "mvme16x-scsi: request_irq failed\n");
80 goto out_put_host;
81 }
82
83 /* Enable scsi chip ints */
84 {
85 volatile unsigned long v;
86
87 /* Enable scsi interrupts at level 4 in PCCchip2 */
88 v = in_be32(0xfff4202c);
89 v = (v & ~0xff) | 0x10 | 4;
90 out_be32(0xfff4202c, v);
91 }
92
Ming Lei7a192ec2009-02-06 23:40:12 +080093 platform_set_drvdata(dev, host);
Kars de Jong506c7bb2007-06-17 14:47:07 +020094 scsi_scan_host(host);
95
96 return 0;
97
98 out_put_host:
99 scsi_host_put(host);
100 out_free:
101 kfree(hostdata);
102 out:
103 return -ENODEV;
104}
105
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800106static int mvme16x_device_remove(struct platform_device *dev)
Kars de Jong506c7bb2007-06-17 14:47:07 +0200107{
Ming Lei7a192ec2009-02-06 23:40:12 +0800108 struct Scsi_Host *host = platform_get_drvdata(dev);
Kars de Jong506c7bb2007-06-17 14:47:07 +0200109 struct NCR_700_Host_Parameters *hostdata = shost_priv(host);
110
111 /* Disable scsi chip ints */
112 {
113 volatile unsigned long v;
114
115 v = in_be32(0xfff4202c);
116 v &= ~0x10;
117 out_be32(0xfff4202c, v);
118 }
119 scsi_remove_host(host);
120 NCR_700_release(host);
121 kfree(hostdata);
122 free_irq(host->irq, host);
123
124 return 0;
125}
126
Ming Lei7a192ec2009-02-06 23:40:12 +0800127static struct platform_driver mvme16x_scsi_driver = {
128 .driver = {
129 .name = "mvme16x-scsi",
Ming Lei7a192ec2009-02-06 23:40:12 +0800130 },
131 .probe = mvme16x_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800132 .remove = mvme16x_device_remove,
Kars de Jong506c7bb2007-06-17 14:47:07 +0200133};
134
135static int __init mvme16x_scsi_init(void)
136{
137 int err;
138
Ming Lei7a192ec2009-02-06 23:40:12 +0800139 err = platform_driver_register(&mvme16x_scsi_driver);
Kars de Jong506c7bb2007-06-17 14:47:07 +0200140 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 Lei7a192ec2009-02-06 23:40:12 +0800146 platform_driver_unregister(&mvme16x_scsi_driver);
Kars de Jong506c7bb2007-06-17 14:47:07 +0200147 return PTR_ERR(mvme16x_scsi_device);
148 }
149
150 return 0;
151}
152
153static void __exit mvme16x_scsi_exit(void)
154{
155 platform_device_unregister(mvme16x_scsi_device);
Ming Lei7a192ec2009-02-06 23:40:12 +0800156 platform_driver_unregister(&mvme16x_scsi_driver);
Kars de Jong506c7bb2007-06-17 14:47:07 +0200157}
158
159module_init(mvme16x_scsi_init);
160module_exit(mvme16x_scsi_exit);