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