blob: f5a2ab41543bd0bd9006a3af5687085343a25220 [file] [log] [blame]
Kars de Jonga16efc12007-06-17 14:47:08 +02001/*
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 Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Geert Uytterhoeven96249cf2007-06-19 09:47:28 +020016#include <asm/amigahw.h>
Kars de Jonga16efc12007-06-17 14:47:08 +020017#include <asm/amigaints.h>
18#include <scsi/scsi_host.h>
19#include <scsi/scsi_transport_spi.h>
20
21#include "53c700.h"
22
Kars de Jonga16efc12007-06-17 14:47:08 +020023
24static struct scsi_host_template a4000t_scsi_driver_template = {
25 .name = "A4000T builtin SCSI",
26 .proc_name = "A4000t",
27 .this_id = 7,
28 .module = THIS_MODULE,
29};
30
Kars de Jonga16efc12007-06-17 14:47:08 +020031
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020032#define A4000T_SCSI_OFFSET 0x40
Kars de Jonga16efc12007-06-17 14:47:08 +020033
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020034static int __init amiga_a4000t_scsi_probe(struct platform_device *pdev)
Kars de Jonga16efc12007-06-17 14:47:08 +020035{
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020036 struct resource *res;
37 phys_addr_t scsi_addr;
Kars de Jonga16efc12007-06-17 14:47:08 +020038 struct NCR_700_Host_Parameters *hostdata;
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020039 struct Scsi_Host *host;
Kars de Jonga16efc12007-06-17 14:47:08 +020040
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020041 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
42 if (!res)
43 return -ENODEV;
Kars de Jonga16efc12007-06-17 14:47:08 +020044
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020045 if (!request_mem_region(res->start, resource_size(res),
Kars de Jonga16efc12007-06-17 14:47:08 +020046 "A4000T builtin SCSI"))
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020047 return -EBUSY;
Kars de Jonga16efc12007-06-17 14:47:08 +020048
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020049 hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters),
50 GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +020051 if (!hostdata) {
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020052 dev_err(&pdev->dev, "Failed to allocate host data\n");
Kars de Jonga16efc12007-06-17 14:47:08 +020053 goto out_release;
54 }
Kars de Jonga16efc12007-06-17 14:47:08 +020055
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020056 scsi_addr = res->start + A4000T_SCSI_OFFSET;
57
Kars de Jonga16efc12007-06-17 14:47:08 +020058 /* Fill in the required pieces of hostdata */
Geert Uytterhoeven6112ea02011-01-09 11:03:43 +010059 hostdata->base = ZTWO_VADDR(scsi_addr);
Kars de Jonga16efc12007-06-17 14:47:08 +020060 hostdata->clock = 50;
61 hostdata->chip710 = 1;
62 hostdata->dmode_extra = DMODE_FC2;
63 hostdata->dcntl_extra = EA_710;
64
65 /* and register the chip */
Geert Uytterhoevene5779a52009-03-11 09:23:52 +010066 host = NCR_700_detect(&a4000t_scsi_driver_template, hostdata,
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020067 &pdev->dev);
Kars de Jonga16efc12007-06-17 14:47:08 +020068 if (!host) {
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020069 dev_err(&pdev->dev,
70 "No host detected; board configuration problem?\n");
Kars de Jonga16efc12007-06-17 14:47:08 +020071 goto out_free;
72 }
73
74 host->this_id = 7;
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020075 host->base = scsi_addr;
Kars de Jonga16efc12007-06-17 14:47:08 +020076 host->irq = IRQ_AMIGA_PORTS;
77
78 if (request_irq(host->irq, NCR_700_intr, IRQF_SHARED, "a4000t-scsi",
79 host)) {
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020080 dev_err(&pdev->dev, "request_irq failed\n");
Kars de Jonga16efc12007-06-17 14:47:08 +020081 goto out_put_host;
82 }
83
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020084 platform_set_drvdata(pdev, host);
Kars de Jonga16efc12007-06-17 14:47:08 +020085 scsi_scan_host(host);
Kars de Jonga16efc12007-06-17 14:47:08 +020086 return 0;
87
88 out_put_host:
89 scsi_host_put(host);
90 out_free:
91 kfree(hostdata);
92 out_release:
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020093 release_mem_region(res->start, resource_size(res));
Kars de Jonga16efc12007-06-17 14:47:08 +020094 return -ENODEV;
95}
96
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020097static int __exit amiga_a4000t_scsi_remove(struct platform_device *pdev)
Kars de Jonga16efc12007-06-17 14:47:08 +020098{
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +020099 struct Scsi_Host *host = platform_get_drvdata(pdev);
Kars de Jonga16efc12007-06-17 14:47:08 +0200100 struct NCR_700_Host_Parameters *hostdata = shost_priv(host);
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +0200101 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Kars de Jonga16efc12007-06-17 14:47:08 +0200102
103 scsi_remove_host(host);
Kars de Jonga16efc12007-06-17 14:47:08 +0200104 NCR_700_release(host);
105 kfree(hostdata);
106 free_irq(host->irq, host);
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +0200107 release_mem_region(res->start, resource_size(res));
Kars de Jonga16efc12007-06-17 14:47:08 +0200108 return 0;
109}
110
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +0200111static struct platform_driver amiga_a4000t_scsi_driver = {
112 .remove = __exit_p(amiga_a4000t_scsi_remove),
113 .driver = {
114 .name = "amiga-a4000t-scsi",
115 .owner = THIS_MODULE,
Ming Lei7a192ec2009-02-06 23:40:12 +0800116 },
Kars de Jonga16efc12007-06-17 14:47:08 +0200117};
118
Jingoo Han70695ba2013-05-02 15:29:53 +0900119module_platform_driver_probe(amiga_a4000t_scsi_driver, amiga_a4000t_scsi_probe);
Geert Uytterhoevena24a6b222009-04-05 13:05:50 +0200120
121MODULE_AUTHOR("Alan Hourihane <alanh@fairlite.demon.co.uk> / "
122 "Kars de Jong <jongk@linux-m68k.org>");
123MODULE_DESCRIPTION("Amiga A4000T NCR53C710 driver");
124MODULE_LICENSE("GPL");
125MODULE_ALIAS("platform:amiga-a4000t-scsi");