Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Detection routine for the NCR53c710 based BVME6000 SCSI Controllers for Linux. |
| 4 | * |
| 5 | * Based on work by Alan Hourihane and Kars de Jong |
| 6 | * |
| 7 | * Rewritten to use 53c700.c by Richard Hirst <richard@sleepie.demon.co.uk> |
| 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 17 | #include <asm/bvme6000hw.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 | |
| 25 | MODULE_AUTHOR("Richard Hirst <richard@sleepie.demon.co.uk>"); |
| 26 | MODULE_DESCRIPTION("BVME6000 NCR53C710 driver"); |
| 27 | MODULE_LICENSE("GPL"); |
| 28 | |
| 29 | static struct scsi_host_template bvme6000_scsi_driver_template = { |
| 30 | .name = "BVME6000 NCR53c710 SCSI", |
| 31 | .proc_name = "BVME6000", |
| 32 | .this_id = 7, |
| 33 | .module = THIS_MODULE, |
| 34 | }; |
| 35 | |
| 36 | static struct platform_device *bvme6000_scsi_device; |
| 37 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 38 | static int |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 39 | bvme6000_probe(struct platform_device *dev) |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 40 | { |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 41 | struct Scsi_Host *host; |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 42 | struct NCR_700_Host_Parameters *hostdata; |
| 43 | |
| 44 | if (!MACH_IS_BVME6000) |
| 45 | goto out; |
| 46 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 47 | hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL); |
| 48 | if (!hostdata) { |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 49 | printk(KERN_ERR "bvme6000-scsi: " |
| 50 | "Failed to allocate host data\n"); |
| 51 | goto out; |
| 52 | } |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 53 | |
| 54 | /* Fill in the required pieces of hostdata */ |
| 55 | hostdata->base = (void __iomem *)BVME_NCR53C710_BASE; |
| 56 | hostdata->clock = 40; /* XXX - depends on the CPU clock! */ |
| 57 | hostdata->chip710 = 1; |
| 58 | hostdata->dmode_extra = DMODE_FC2; |
| 59 | hostdata->dcntl_extra = EA_710; |
| 60 | hostdata->ctest7_extra = CTEST7_TT1; |
| 61 | |
| 62 | /* and register the chip */ |
Geert Uytterhoeven | e5779a5 | 2009-03-11 09:23:52 +0100 | [diff] [blame] | 63 | host = NCR_700_detect(&bvme6000_scsi_driver_template, hostdata, |
| 64 | &dev->dev); |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 65 | if (!host) { |
| 66 | printk(KERN_ERR "bvme6000-scsi: No host detected; " |
| 67 | "board configuration problem?\n"); |
| 68 | goto out_free; |
| 69 | } |
| 70 | host->base = BVME_NCR53C710_BASE; |
| 71 | host->this_id = 7; |
| 72 | host->irq = BVME_IRQ_SCSI; |
| 73 | if (request_irq(BVME_IRQ_SCSI, NCR_700_intr, 0, "bvme6000-scsi", |
| 74 | host)) { |
| 75 | printk(KERN_ERR "bvme6000-scsi: request_irq failed\n"); |
| 76 | goto out_put_host; |
| 77 | } |
| 78 | |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 79 | platform_set_drvdata(dev, host); |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 80 | scsi_scan_host(host); |
| 81 | |
| 82 | return 0; |
| 83 | |
| 84 | out_put_host: |
| 85 | scsi_host_put(host); |
| 86 | out_free: |
| 87 | kfree(hostdata); |
| 88 | out: |
| 89 | return -ENODEV; |
| 90 | } |
| 91 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 92 | static int |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 93 | bvme6000_device_remove(struct platform_device *dev) |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 94 | { |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 95 | struct Scsi_Host *host = platform_get_drvdata(dev); |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 96 | struct NCR_700_Host_Parameters *hostdata = shost_priv(host); |
| 97 | |
| 98 | scsi_remove_host(host); |
| 99 | NCR_700_release(host); |
| 100 | kfree(hostdata); |
| 101 | free_irq(host->irq, host); |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 106 | static struct platform_driver bvme6000_scsi_driver = { |
| 107 | .driver = { |
| 108 | .name = "bvme6000-scsi", |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 109 | }, |
| 110 | .probe = bvme6000_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 111 | .remove = bvme6000_device_remove, |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | static int __init bvme6000_scsi_init(void) |
| 115 | { |
| 116 | int err; |
| 117 | |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 118 | err = platform_driver_register(&bvme6000_scsi_driver); |
Geert Uytterhoeven | 96249cf | 2007-06-19 09:47:28 +0200 | [diff] [blame] | 119 | if (err) |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 120 | return err; |
| 121 | |
| 122 | bvme6000_scsi_device = platform_device_register_simple("bvme6000-scsi", |
| 123 | -1, NULL, 0); |
| 124 | if (IS_ERR(bvme6000_scsi_device)) { |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 125 | platform_driver_unregister(&bvme6000_scsi_driver); |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 126 | return PTR_ERR(bvme6000_scsi_device); |
| 127 | } |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | static void __exit bvme6000_scsi_exit(void) |
| 133 | { |
| 134 | platform_device_unregister(bvme6000_scsi_device); |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 135 | platform_driver_unregister(&bvme6000_scsi_driver); |
Kars de Jong | 8276b58 | 2007-06-17 14:47:06 +0200 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | module_init(bvme6000_scsi_init); |
| 139 | module_exit(bvme6000_scsi_exit); |