Thomas Gleixner | 74ba920 | 2019-05-20 09:19:02 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Thomas Bogendoerfer | c27d85f | 2006-12-25 21:32:04 +0100 | [diff] [blame] | 2 | /* -*- mode: c; c-basic-offset: 8 -*- */ |
| 3 | |
| 4 | /* SNI RM driver |
| 5 | * |
| 6 | * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com |
| 7 | **----------------------------------------------------------------------------- |
| 8 | ** |
Thomas Bogendoerfer | c27d85f | 2006-12-25 21:32:04 +0100 | [diff] [blame] | 9 | ** |
| 10 | **----------------------------------------------------------------------------- |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * Based on lasi700.c |
| 15 | */ |
| 16 | |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/types.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Thomas Bogendoerfer | c27d85f | 2006-12-25 21:32:04 +0100 | [diff] [blame] | 22 | #include <linux/stat.h> |
| 23 | #include <linux/mm.h> |
| 24 | #include <linux/blkdev.h> |
| 25 | #include <linux/sched.h> |
| 26 | #include <linux/ioport.h> |
| 27 | #include <linux/dma-mapping.h> |
| 28 | #include <linux/platform_device.h> |
| 29 | |
| 30 | #include <asm/page.h> |
Thomas Bogendoerfer | c27d85f | 2006-12-25 21:32:04 +0100 | [diff] [blame] | 31 | #include <asm/irq.h> |
| 32 | #include <asm/delay.h> |
| 33 | |
| 34 | #include <scsi/scsi_host.h> |
| 35 | #include <scsi/scsi_device.h> |
| 36 | #include <scsi/scsi_transport.h> |
| 37 | #include <scsi/scsi_transport_spi.h> |
| 38 | |
| 39 | #include "53c700.h" |
| 40 | |
Al Viro | d36b691 | 2011-12-29 17:09:01 -0500 | [diff] [blame] | 41 | MODULE_AUTHOR("Thomas Bogendörfer"); |
Thomas Bogendoerfer | c27d85f | 2006-12-25 21:32:04 +0100 | [diff] [blame] | 42 | MODULE_DESCRIPTION("SNI RM 53c710 SCSI Driver"); |
| 43 | MODULE_LICENSE("GPL"); |
Kay Sievers | ecc1241e | 2008-04-18 13:57:19 -0700 | [diff] [blame] | 44 | MODULE_ALIAS("platform:snirm_53c710"); |
Thomas Bogendoerfer | c27d85f | 2006-12-25 21:32:04 +0100 | [diff] [blame] | 45 | |
| 46 | #define SNIRM710_CLOCK 32 |
| 47 | |
| 48 | static struct scsi_host_template snirm710_template = { |
| 49 | .name = "SNI RM SCSI 53c710", |
| 50 | .proc_name = "snirm_53c710", |
| 51 | .this_id = 7, |
| 52 | .module = THIS_MODULE, |
| 53 | }; |
| 54 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 55 | static int snirm710_probe(struct platform_device *dev) |
Thomas Bogendoerfer | c27d85f | 2006-12-25 21:32:04 +0100 | [diff] [blame] | 56 | { |
| 57 | unsigned long base; |
| 58 | struct NCR_700_Host_Parameters *hostdata; |
| 59 | struct Scsi_Host *host; |
| 60 | struct resource *res; |
| 61 | |
| 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 Bogendoerfer | 0ee6211 | 2019-10-09 17:11:18 +0200 | [diff] [blame] | 68 | if (!hostdata) |
Thomas Bogendoerfer | c27d85f | 2006-12-25 21:32:04 +0100 | [diff] [blame] | 69 | return -ENOMEM; |
Thomas Bogendoerfer | c27d85f | 2006-12-25 21:32:04 +0100 | [diff] [blame] | 70 | |
| 71 | hostdata->dev = &dev->dev; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 72 | dma_set_mask(&dev->dev, DMA_BIT_MASK(32)); |
Christoph Hellwig | 4bdc0d6 | 2020-01-06 09:43:50 +0100 | [diff] [blame] | 73 | hostdata->base = ioremap(base, 0x100); |
Thomas Bogendoerfer | c27d85f | 2006-12-25 21:32:04 +0100 | [diff] [blame] | 74 | 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; |
| 86 | host->irq = platform_get_irq(dev, 0); |
Thomas Gleixner | 2833bf6 | 2007-05-08 00:28:52 -0700 | [diff] [blame] | 87 | if(request_irq(host->irq, NCR_700_intr, IRQF_SHARED, "snirm710", host)) { |
Thomas Bogendoerfer | c27d85f | 2006-12-25 21:32:04 +0100 | [diff] [blame] | 88 | printk(KERN_ERR "snirm710: request_irq failed!\n"); |
| 89 | goto out_put_host; |
| 90 | } |
| 91 | |
| 92 | dev_set_drvdata(&dev->dev, host); |
| 93 | scsi_scan_host(host); |
| 94 | |
| 95 | return 0; |
| 96 | |
| 97 | out_put_host: |
| 98 | scsi_host_put(host); |
| 99 | out_kfree: |
| 100 | iounmap(hostdata->base); |
| 101 | kfree(hostdata); |
| 102 | return -ENODEV; |
| 103 | } |
| 104 | |
Dmitry Torokhov | ba21222 | 2017-03-01 17:38:38 -0800 | [diff] [blame] | 105 | static int snirm710_driver_remove(struct platform_device *dev) |
Thomas Bogendoerfer | c27d85f | 2006-12-25 21:32:04 +0100 | [diff] [blame] | 106 | { |
| 107 | struct Scsi_Host *host = dev_get_drvdata(&dev->dev); |
| 108 | struct NCR_700_Host_Parameters *hostdata = |
| 109 | (struct NCR_700_Host_Parameters *)host->hostdata[0]; |
| 110 | |
| 111 | scsi_remove_host(host); |
| 112 | NCR_700_release(host); |
| 113 | free_irq(host->irq, host); |
| 114 | iounmap(hostdata->base); |
| 115 | kfree(hostdata); |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static struct platform_driver snirm710_driver = { |
| 121 | .probe = snirm710_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 122 | .remove = snirm710_driver_remove, |
Thomas Bogendoerfer | c27d85f | 2006-12-25 21:32:04 +0100 | [diff] [blame] | 123 | .driver = { |
| 124 | .name = "snirm_53c710", |
| 125 | }, |
| 126 | }; |
Liu Shixin | a3b73c9 | 2020-09-14 14:54:03 +0800 | [diff] [blame] | 127 | module_platform_driver(snirm710_driver); |