Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Detection routine for the NCR53c710 based Amiga SCSI Controllers for Linux. |
| 3 | * Amiga Technologies A4000T SCSI controller. |
| 4 | * |
| 5 | * Written 1997 by Alan Hourihane <alanh@fairlite.demon.co.uk> |
| 6 | * plus modifications of the 53c7xx.c driver to support the Amiga. |
| 7 | * |
| 8 | * Rewritten to use 53c700.c by Kars de Jong <jongk@linux-m68k.org> |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.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> |
Geert Uytterhoeven | 96249cf | 2007-06-19 09:47:28 +0200 | [diff] [blame] | 16 | #include <asm/amigahw.h> |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 17 | #include <asm/amigaints.h> |
| 18 | #include <scsi/scsi_host.h> |
| 19 | #include <scsi/scsi_transport_spi.h> |
| 20 | |
| 21 | #include "53c700.h" |
| 22 | |
| 23 | MODULE_AUTHOR("Alan Hourihane <alanh@fairlite.demon.co.uk> / Kars de Jong <jongk@linux-m68k.org>"); |
| 24 | MODULE_DESCRIPTION("Amiga A4000T NCR53C710 driver"); |
| 25 | MODULE_LICENSE("GPL"); |
| 26 | |
| 27 | |
| 28 | static struct scsi_host_template a4000t_scsi_driver_template = { |
| 29 | .name = "A4000T builtin SCSI", |
| 30 | .proc_name = "A4000t", |
| 31 | .this_id = 7, |
| 32 | .module = THIS_MODULE, |
| 33 | }; |
| 34 | |
| 35 | static struct platform_device *a4000t_scsi_device; |
| 36 | |
| 37 | #define A4000T_SCSI_ADDR 0xdd0040 |
| 38 | |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 39 | static int __devinit a4000t_probe(struct platform_device *dev) |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 40 | { |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 41 | struct Scsi_Host *host; |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 42 | struct NCR_700_Host_Parameters *hostdata; |
| 43 | |
| 44 | if (!(MACH_IS_AMIGA && AMIGAHW_PRESENT(A4000_SCSI))) |
| 45 | goto out; |
| 46 | |
| 47 | if (!request_mem_region(A4000T_SCSI_ADDR, 0x1000, |
| 48 | "A4000T builtin SCSI")) |
| 49 | goto out; |
| 50 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 51 | hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL); |
| 52 | if (!hostdata) { |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 53 | printk(KERN_ERR "a4000t-scsi: Failed to allocate host data\n"); |
| 54 | goto out_release; |
| 55 | } |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 56 | |
| 57 | /* Fill in the required pieces of hostdata */ |
| 58 | hostdata->base = (void __iomem *)ZTWO_VADDR(A4000T_SCSI_ADDR); |
| 59 | hostdata->clock = 50; |
| 60 | hostdata->chip710 = 1; |
| 61 | hostdata->dmode_extra = DMODE_FC2; |
| 62 | hostdata->dcntl_extra = EA_710; |
| 63 | |
| 64 | /* and register the chip */ |
Geert Uytterhoeven | e5779a5 | 2009-03-11 09:23:52 +0100 | [diff] [blame] | 65 | host = NCR_700_detect(&a4000t_scsi_driver_template, hostdata, |
| 66 | &dev->dev); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 67 | if (!host) { |
| 68 | printk(KERN_ERR "a4000t-scsi: No host detected; " |
| 69 | "board configuration problem?\n"); |
| 70 | goto out_free; |
| 71 | } |
| 72 | |
| 73 | host->this_id = 7; |
| 74 | host->base = A4000T_SCSI_ADDR; |
| 75 | host->irq = IRQ_AMIGA_PORTS; |
| 76 | |
| 77 | if (request_irq(host->irq, NCR_700_intr, IRQF_SHARED, "a4000t-scsi", |
| 78 | host)) { |
| 79 | printk(KERN_ERR "a4000t-scsi: request_irq failed\n"); |
| 80 | goto out_put_host; |
| 81 | } |
| 82 | |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 83 | platform_set_drvdata(dev, host); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 84 | scsi_scan_host(host); |
| 85 | |
| 86 | return 0; |
| 87 | |
| 88 | out_put_host: |
| 89 | scsi_host_put(host); |
| 90 | out_free: |
| 91 | kfree(hostdata); |
| 92 | out_release: |
| 93 | release_mem_region(A4000T_SCSI_ADDR, 0x1000); |
| 94 | out: |
| 95 | return -ENODEV; |
| 96 | } |
| 97 | |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 98 | static __devexit int a4000t_device_remove(struct platform_device *dev) |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 99 | { |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 100 | struct Scsi_Host *host = platform_get_drvdata(dev); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 101 | struct NCR_700_Host_Parameters *hostdata = shost_priv(host); |
| 102 | |
| 103 | scsi_remove_host(host); |
| 104 | |
| 105 | NCR_700_release(host); |
| 106 | kfree(hostdata); |
| 107 | free_irq(host->irq, host); |
| 108 | release_mem_region(A4000T_SCSI_ADDR, 0x1000); |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 113 | static struct platform_driver a4000t_scsi_driver = { |
| 114 | .driver = { |
| 115 | .name = "a4000t-scsi", |
| 116 | .owner = THIS_MODULE, |
| 117 | }, |
| 118 | .probe = a4000t_probe, |
| 119 | .remove = __devexit_p(a4000t_device_remove), |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | static int __init a4000t_scsi_init(void) |
| 123 | { |
| 124 | int err; |
| 125 | |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 126 | err = platform_driver_register(&a4000t_scsi_driver); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 127 | if (err) |
| 128 | return err; |
| 129 | |
| 130 | a4000t_scsi_device = platform_device_register_simple("a4000t-scsi", |
| 131 | -1, NULL, 0); |
| 132 | if (IS_ERR(a4000t_scsi_device)) { |
Geert Uytterhoeven | 2d138ae | 2009-04-09 21:22:42 +0200 | [diff] [blame] | 133 | platform_driver_unregister(&a4000t_scsi_driver); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 134 | return PTR_ERR(a4000t_scsi_device); |
| 135 | } |
| 136 | |
| 137 | return err; |
| 138 | } |
| 139 | |
| 140 | static void __exit a4000t_scsi_exit(void) |
| 141 | { |
| 142 | platform_device_unregister(a4000t_scsi_device); |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 143 | platform_driver_unregister(&a4000t_scsi_driver); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | module_init(a4000t_scsi_init); |
| 147 | module_exit(a4000t_scsi_exit); |