blob: 678651b9b4dda405af403e84f57d5ff76b951ac6 [file] [log] [blame]
Thomas Gleixner74ba9202019-05-20 09:19:02 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +01002
3/* SNI RM driver
4 *
5 * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
6**-----------------------------------------------------------------------------
7**
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +01008**
9**-----------------------------------------------------------------------------
10 */
11
12/*
13 * Based on lasi700.c
14 */
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/types.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090020#include <linux/slab.h>
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +010021#include <linux/stat.h>
22#include <linux/mm.h>
23#include <linux/blkdev.h>
24#include <linux/sched.h>
25#include <linux/ioport.h>
26#include <linux/dma-mapping.h>
27#include <linux/platform_device.h>
28
29#include <asm/page.h>
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +010030#include <asm/irq.h>
31#include <asm/delay.h>
32
33#include <scsi/scsi_host.h>
34#include <scsi/scsi_device.h>
35#include <scsi/scsi_transport.h>
36#include <scsi/scsi_transport_spi.h>
37
38#include "53c700.h"
39
Al Virod36b6912011-12-29 17:09:01 -050040MODULE_AUTHOR("Thomas Bogendörfer");
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +010041MODULE_DESCRIPTION("SNI RM 53c710 SCSI Driver");
42MODULE_LICENSE("GPL");
Kay Sieversecc1241e2008-04-18 13:57:19 -070043MODULE_ALIAS("platform:snirm_53c710");
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +010044
45#define SNIRM710_CLOCK 32
46
47static struct scsi_host_template snirm710_template = {
48 .name = "SNI RM SCSI 53c710",
49 .proc_name = "snirm_53c710",
50 .this_id = 7,
51 .module = THIS_MODULE,
52};
53
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080054static int snirm710_probe(struct platform_device *dev)
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +010055{
56 unsigned long base;
57 struct NCR_700_Host_Parameters *hostdata;
58 struct Scsi_Host *host;
59 struct resource *res;
Sergey Shtylyov1160d61b2021-03-30 20:45:12 +030060 int rc;
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +010061
62 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
63 if (!res)
64 return -ENODEV;
65
66 base = res->start;
67 hostdata = kzalloc(sizeof(*hostdata), GFP_KERNEL);
Thomas Bogendoerfer0ee62112019-10-09 17:11:18 +020068 if (!hostdata)
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +010069 return -ENOMEM;
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +010070
71 hostdata->dev = &dev->dev;
Yang Hongyang284901a2009-04-06 19:01:15 -070072 dma_set_mask(&dev->dev, DMA_BIT_MASK(32));
Christoph Hellwig4bdc0d62020-01-06 09:43:50 +010073 hostdata->base = ioremap(base, 0x100);
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +010074 hostdata->differential = 0;
75
76 hostdata->clock = SNIRM710_CLOCK;
77 hostdata->force_le_on_be = 1;
78 hostdata->chip710 = 1;
79 hostdata->burst_length = 4;
80
81 host = NCR_700_detect(&snirm710_template, hostdata, &dev->dev);
82 if (!host)
83 goto out_kfree;
84 host->this_id = 7;
85 host->base = base;
Sergey Shtylyov1160d61b2021-03-30 20:45:12 +030086 host->irq = rc = platform_get_irq(dev, 0);
87 if (rc < 0)
88 goto out_put_host;
Thomas Gleixner2833bf62007-05-08 00:28:52 -070089 if(request_irq(host->irq, NCR_700_intr, IRQF_SHARED, "snirm710", host)) {
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +010090 printk(KERN_ERR "snirm710: request_irq failed!\n");
91 goto out_put_host;
92 }
93
94 dev_set_drvdata(&dev->dev, host);
95 scsi_scan_host(host);
96
97 return 0;
98
99 out_put_host:
100 scsi_host_put(host);
101 out_kfree:
102 iounmap(hostdata->base);
103 kfree(hostdata);
104 return -ENODEV;
105}
106
Dmitry Torokhovba212222017-03-01 17:38:38 -0800107static int snirm710_driver_remove(struct platform_device *dev)
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +0100108{
109 struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
110 struct NCR_700_Host_Parameters *hostdata =
111 (struct NCR_700_Host_Parameters *)host->hostdata[0];
112
113 scsi_remove_host(host);
114 NCR_700_release(host);
115 free_irq(host->irq, host);
116 iounmap(hostdata->base);
117 kfree(hostdata);
118
119 return 0;
120}
121
122static struct platform_driver snirm710_driver = {
123 .probe = snirm710_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800124 .remove = snirm710_driver_remove,
Thomas Bogendoerferc27d85f2006-12-25 21:32:04 +0100125 .driver = {
126 .name = "snirm_53c710",
127 },
128};
Liu Shixina3b73c92020-09-14 14:54:03 +0800129module_platform_driver(snirm710_driver);