xref: /linux/drivers/scsi/sni_53c710.c (revision 06d07429858317ded2db7986113a9e0129cd599b)
174ba9207SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2c27d85f3SThomas Bogendoerfer 
3c27d85f3SThomas Bogendoerfer /* SNI RM driver
4c27d85f3SThomas Bogendoerfer  *
5c27d85f3SThomas Bogendoerfer  * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
6c27d85f3SThomas Bogendoerfer **-----------------------------------------------------------------------------
7c27d85f3SThomas Bogendoerfer **
8c27d85f3SThomas Bogendoerfer **
9c27d85f3SThomas Bogendoerfer **-----------------------------------------------------------------------------
10c27d85f3SThomas Bogendoerfer  */
11c27d85f3SThomas Bogendoerfer 
12c27d85f3SThomas Bogendoerfer /*
13c27d85f3SThomas Bogendoerfer  * Based on lasi700.c
14c27d85f3SThomas Bogendoerfer  */
15c27d85f3SThomas Bogendoerfer 
16c27d85f3SThomas Bogendoerfer #include <linux/kernel.h>
17c27d85f3SThomas Bogendoerfer #include <linux/module.h>
18c27d85f3SThomas Bogendoerfer #include <linux/init.h>
19c27d85f3SThomas Bogendoerfer #include <linux/types.h>
205a0e3ad6STejun Heo #include <linux/slab.h>
21c27d85f3SThomas Bogendoerfer #include <linux/stat.h>
22c27d85f3SThomas Bogendoerfer #include <linux/mm.h>
23c27d85f3SThomas Bogendoerfer #include <linux/blkdev.h>
24c27d85f3SThomas Bogendoerfer #include <linux/sched.h>
25c27d85f3SThomas Bogendoerfer #include <linux/ioport.h>
26c27d85f3SThomas Bogendoerfer #include <linux/dma-mapping.h>
27c27d85f3SThomas Bogendoerfer #include <linux/platform_device.h>
28c27d85f3SThomas Bogendoerfer 
29c27d85f3SThomas Bogendoerfer #include <asm/page.h>
30c27d85f3SThomas Bogendoerfer #include <asm/irq.h>
31c27d85f3SThomas Bogendoerfer #include <asm/delay.h>
32c27d85f3SThomas Bogendoerfer 
33c27d85f3SThomas Bogendoerfer #include <scsi/scsi_host.h>
34c27d85f3SThomas Bogendoerfer #include <scsi/scsi_device.h>
35c27d85f3SThomas Bogendoerfer #include <scsi/scsi_transport.h>
36c27d85f3SThomas Bogendoerfer #include <scsi/scsi_transport_spi.h>
37c27d85f3SThomas Bogendoerfer 
38c27d85f3SThomas Bogendoerfer #include "53c700.h"
39c27d85f3SThomas Bogendoerfer 
40d36b6910SAl Viro MODULE_AUTHOR("Thomas Bogendörfer");
41c27d85f3SThomas Bogendoerfer MODULE_DESCRIPTION("SNI RM 53c710 SCSI Driver");
42c27d85f3SThomas Bogendoerfer MODULE_LICENSE("GPL");
43ecc1241eSKay Sievers MODULE_ALIAS("platform:snirm_53c710");
44c27d85f3SThomas Bogendoerfer 
45c27d85f3SThomas Bogendoerfer #define SNIRM710_CLOCK	32
46c27d85f3SThomas Bogendoerfer 
47c27d85f3SThomas Bogendoerfer static struct scsi_host_template snirm710_template = {
48c27d85f3SThomas Bogendoerfer 	.name		= "SNI RM SCSI 53c710",
49c27d85f3SThomas Bogendoerfer 	.proc_name	= "snirm_53c710",
50c27d85f3SThomas Bogendoerfer 	.this_id	= 7,
51c27d85f3SThomas Bogendoerfer 	.module		= THIS_MODULE,
52c27d85f3SThomas Bogendoerfer };
53c27d85f3SThomas Bogendoerfer 
snirm710_probe(struct platform_device * dev)546f039790SGreg Kroah-Hartman static int snirm710_probe(struct platform_device *dev)
55c27d85f3SThomas Bogendoerfer {
56c27d85f3SThomas Bogendoerfer 	unsigned long base;
57c27d85f3SThomas Bogendoerfer 	struct NCR_700_Host_Parameters *hostdata;
58c27d85f3SThomas Bogendoerfer 	struct Scsi_Host *host;
59c27d85f3SThomas Bogendoerfer 	struct  resource *res;
601160d61bSSergey Shtylyov 	int rc;
61c27d85f3SThomas Bogendoerfer 
62c27d85f3SThomas Bogendoerfer 	res = platform_get_resource(dev, IORESOURCE_MEM, 0);
63c27d85f3SThomas Bogendoerfer 	if (!res)
64c27d85f3SThomas Bogendoerfer 		return -ENODEV;
65c27d85f3SThomas Bogendoerfer 
66c27d85f3SThomas Bogendoerfer 	base = res->start;
67c27d85f3SThomas Bogendoerfer 	hostdata = kzalloc(sizeof(*hostdata), GFP_KERNEL);
680ee62114SThomas Bogendoerfer 	if (!hostdata)
69c27d85f3SThomas Bogendoerfer 		return -ENOMEM;
70c27d85f3SThomas Bogendoerfer 
71c27d85f3SThomas Bogendoerfer 	hostdata->dev = &dev->dev;
72284901a9SYang Hongyang 	dma_set_mask(&dev->dev, DMA_BIT_MASK(32));
734bdc0d67SChristoph Hellwig 	hostdata->base = ioremap(base, 0x100);
74c27d85f3SThomas Bogendoerfer 	hostdata->differential = 0;
75c27d85f3SThomas Bogendoerfer 
76c27d85f3SThomas Bogendoerfer 	hostdata->clock = SNIRM710_CLOCK;
77c27d85f3SThomas Bogendoerfer 	hostdata->force_le_on_be = 1;
78c27d85f3SThomas Bogendoerfer 	hostdata->chip710 = 1;
79c27d85f3SThomas Bogendoerfer 	hostdata->burst_length = 4;
80c27d85f3SThomas Bogendoerfer 
81c27d85f3SThomas Bogendoerfer 	host = NCR_700_detect(&snirm710_template, hostdata, &dev->dev);
82c27d85f3SThomas Bogendoerfer 	if (!host)
83c27d85f3SThomas Bogendoerfer 		goto out_kfree;
84c27d85f3SThomas Bogendoerfer 	host->this_id = 7;
85c27d85f3SThomas Bogendoerfer 	host->base = base;
861160d61bSSergey Shtylyov 	host->irq = rc = platform_get_irq(dev, 0);
871160d61bSSergey Shtylyov 	if (rc < 0)
881160d61bSSergey Shtylyov 		goto out_put_host;
892833bf68SThomas Gleixner 	if(request_irq(host->irq, NCR_700_intr, IRQF_SHARED, "snirm710", host)) {
90c27d85f3SThomas Bogendoerfer 		printk(KERN_ERR "snirm710: request_irq failed!\n");
91c27d85f3SThomas Bogendoerfer 		goto out_put_host;
92c27d85f3SThomas Bogendoerfer 	}
93c27d85f3SThomas Bogendoerfer 
94c27d85f3SThomas Bogendoerfer 	dev_set_drvdata(&dev->dev, host);
95c27d85f3SThomas Bogendoerfer 	scsi_scan_host(host);
96c27d85f3SThomas Bogendoerfer 
97c27d85f3SThomas Bogendoerfer 	return 0;
98c27d85f3SThomas Bogendoerfer 
99c27d85f3SThomas Bogendoerfer  out_put_host:
100c27d85f3SThomas Bogendoerfer 	scsi_host_put(host);
101c27d85f3SThomas Bogendoerfer  out_kfree:
102c27d85f3SThomas Bogendoerfer 	iounmap(hostdata->base);
103c27d85f3SThomas Bogendoerfer 	kfree(hostdata);
104c27d85f3SThomas Bogendoerfer 	return -ENODEV;
105c27d85f3SThomas Bogendoerfer }
106c27d85f3SThomas Bogendoerfer 
snirm710_driver_remove(struct platform_device * dev)107*357a7fd2SUwe Kleine-König static void snirm710_driver_remove(struct platform_device *dev)
108c27d85f3SThomas Bogendoerfer {
109c27d85f3SThomas Bogendoerfer 	struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
110c27d85f3SThomas Bogendoerfer 	struct NCR_700_Host_Parameters *hostdata =
111c27d85f3SThomas Bogendoerfer 		(struct NCR_700_Host_Parameters *)host->hostdata[0];
112c27d85f3SThomas Bogendoerfer 
113c27d85f3SThomas Bogendoerfer 	scsi_remove_host(host);
114c27d85f3SThomas Bogendoerfer 	NCR_700_release(host);
115c27d85f3SThomas Bogendoerfer 	free_irq(host->irq, host);
116c27d85f3SThomas Bogendoerfer 	iounmap(hostdata->base);
117c27d85f3SThomas Bogendoerfer 	kfree(hostdata);
118c27d85f3SThomas Bogendoerfer }
119c27d85f3SThomas Bogendoerfer 
120c27d85f3SThomas Bogendoerfer static struct platform_driver snirm710_driver = {
121c27d85f3SThomas Bogendoerfer 	.probe	= snirm710_probe,
122*357a7fd2SUwe Kleine-König 	.remove_new = snirm710_driver_remove,
123c27d85f3SThomas Bogendoerfer 	.driver	= {
124c27d85f3SThomas Bogendoerfer 		.name	= "snirm_53c710",
125c27d85f3SThomas Bogendoerfer 	},
126c27d85f3SThomas Bogendoerfer };
127a3b73c96SLiu Shixin module_platform_driver(snirm710_driver);
128