Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Detection routine for the NCR53c710 based Amiga SCSI Controllers for Linux. |
| 4 | * Amiga Technologies A4000T SCSI controller. |
| 5 | * |
| 6 | * Written 1997 by Alan Hourihane <alanh@fairlite.demon.co.uk> |
| 7 | * plus modifications of the 53c7xx.c driver to support the Amiga. |
| 8 | * |
| 9 | * Rewritten to use 53c700.c by Kars de Jong <jongk@linux-m68k.org> |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.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> |
Geert Uytterhoeven | 96249cf | 2007-06-19 09:47:28 +0200 | [diff] [blame] | 17 | #include <asm/amigahw.h> |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 18 | #include <asm/amigaints.h> |
| 19 | #include <scsi/scsi_host.h> |
| 20 | #include <scsi/scsi_transport_spi.h> |
| 21 | |
| 22 | #include "53c700.h" |
| 23 | |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 24 | |
| 25 | static struct scsi_host_template a4000t_scsi_driver_template = { |
| 26 | .name = "A4000T builtin SCSI", |
| 27 | .proc_name = "A4000t", |
| 28 | .this_id = 7, |
| 29 | .module = THIS_MODULE, |
| 30 | }; |
| 31 | |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 32 | |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 33 | #define A4000T_SCSI_OFFSET 0x40 |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 34 | |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 35 | static int __init amiga_a4000t_scsi_probe(struct platform_device *pdev) |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 36 | { |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 37 | struct resource *res; |
| 38 | phys_addr_t scsi_addr; |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 39 | struct NCR_700_Host_Parameters *hostdata; |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 40 | struct Scsi_Host *host; |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 41 | |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 42 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 43 | if (!res) |
| 44 | return -ENODEV; |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 45 | |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 46 | if (!request_mem_region(res->start, resource_size(res), |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 47 | "A4000T builtin SCSI")) |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 48 | return -EBUSY; |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 49 | |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 50 | hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), |
| 51 | GFP_KERNEL); |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 52 | if (!hostdata) { |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 53 | dev_err(&pdev->dev, "Failed to allocate host data\n"); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 54 | goto out_release; |
| 55 | } |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 56 | |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 57 | scsi_addr = res->start + A4000T_SCSI_OFFSET; |
| 58 | |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 59 | /* Fill in the required pieces of hostdata */ |
Geert Uytterhoeven | 6112ea0 | 2011-01-09 11:03:43 +0100 | [diff] [blame] | 60 | hostdata->base = ZTWO_VADDR(scsi_addr); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 61 | hostdata->clock = 50; |
| 62 | hostdata->chip710 = 1; |
| 63 | hostdata->dmode_extra = DMODE_FC2; |
| 64 | hostdata->dcntl_extra = EA_710; |
| 65 | |
| 66 | /* and register the chip */ |
Geert Uytterhoeven | e5779a5 | 2009-03-11 09:23:52 +0100 | [diff] [blame] | 67 | host = NCR_700_detect(&a4000t_scsi_driver_template, hostdata, |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 68 | &pdev->dev); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 69 | if (!host) { |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 70 | dev_err(&pdev->dev, |
| 71 | "No host detected; board configuration problem?\n"); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 72 | goto out_free; |
| 73 | } |
| 74 | |
| 75 | host->this_id = 7; |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 76 | host->base = scsi_addr; |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 77 | host->irq = IRQ_AMIGA_PORTS; |
| 78 | |
| 79 | if (request_irq(host->irq, NCR_700_intr, IRQF_SHARED, "a4000t-scsi", |
| 80 | host)) { |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 81 | dev_err(&pdev->dev, "request_irq failed\n"); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 82 | goto out_put_host; |
| 83 | } |
| 84 | |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 85 | platform_set_drvdata(pdev, host); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 86 | scsi_scan_host(host); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 87 | return 0; |
| 88 | |
| 89 | out_put_host: |
| 90 | scsi_host_put(host); |
| 91 | out_free: |
| 92 | kfree(hostdata); |
| 93 | out_release: |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 94 | release_mem_region(res->start, resource_size(res)); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 95 | return -ENODEV; |
| 96 | } |
| 97 | |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 98 | static int __exit amiga_a4000t_scsi_remove(struct platform_device *pdev) |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 99 | { |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 100 | struct Scsi_Host *host = platform_get_drvdata(pdev); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 101 | struct NCR_700_Host_Parameters *hostdata = shost_priv(host); |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 102 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 103 | |
| 104 | scsi_remove_host(host); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 105 | NCR_700_release(host); |
| 106 | kfree(hostdata); |
| 107 | free_irq(host->irq, host); |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 108 | release_mem_region(res->start, resource_size(res)); |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 112 | static struct platform_driver amiga_a4000t_scsi_driver = { |
| 113 | .remove = __exit_p(amiga_a4000t_scsi_remove), |
| 114 | .driver = { |
| 115 | .name = "amiga-a4000t-scsi", |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 116 | }, |
Kars de Jong | a16efc1 | 2007-06-17 14:47:08 +0200 | [diff] [blame] | 117 | }; |
| 118 | |
Jingoo Han | 70695ba | 2013-05-02 15:29:53 +0900 | [diff] [blame] | 119 | module_platform_driver_probe(amiga_a4000t_scsi_driver, amiga_a4000t_scsi_probe); |
Geert Uytterhoeven | a24a6b22 | 2009-04-05 13:05:50 +0200 | [diff] [blame] | 120 | |
| 121 | MODULE_AUTHOR("Alan Hourihane <alanh@fairlite.demon.co.uk> / " |
| 122 | "Kars de Jong <jongk@linux-m68k.org>"); |
| 123 | MODULE_DESCRIPTION("Amiga A4000T NCR53C710 driver"); |
| 124 | MODULE_LICENSE("GPL"); |
| 125 | MODULE_ALIAS("platform:amiga-a4000t-scsi"); |