Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * sim710.c - Copyright (C) 1999 Richard Hirst <richard@sleepie.demon.co.uk> |
| 3 | * |
| 4 | *---------------------------------------------------------------------------- |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | *---------------------------------------------------------------------------- |
| 19 | * |
Paul Gortmaker | a88dc06 | 2012-05-16 20:33:52 -0400 | [diff] [blame] | 20 | * MCA card detection code by Trent McNair. (now deleted) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | * Fixes to not explicitly nul bss data from Xavier Bestel. |
| 22 | * Some multiboard fixes from Rolf Eike Beer. |
| 23 | * Auto probing of EISA config space from Trevor Hemsley. |
| 24 | * |
| 25 | * Rewritten to use 53c700.c by James.Bottomley@SteelEye.com |
| 26 | * |
| 27 | */ |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | #include <linux/blkdev.h> |
| 33 | #include <linux/device.h> |
| 34 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/eisa.h> |
| 36 | #include <linux/interrupt.h> |
| 37 | #include <scsi/scsi_host.h> |
| 38 | #include <scsi/scsi_device.h> |
| 39 | #include <scsi/scsi_transport.h> |
| 40 | #include <scsi/scsi_transport_spi.h> |
| 41 | |
| 42 | #include "53c700.h" |
| 43 | |
| 44 | |
Paul Gortmaker | a88dc06 | 2012-05-16 20:33:52 -0400 | [diff] [blame] | 45 | /* Must be enough for EISA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #define MAX_SLOTS 8 |
| 47 | static __u8 __initdata id_array[MAX_SLOTS] = { [0 ... MAX_SLOTS-1] = 7 }; |
| 48 | |
| 49 | static char *sim710; /* command line passed by insmod */ |
| 50 | |
| 51 | MODULE_AUTHOR("Richard Hirst"); |
| 52 | MODULE_DESCRIPTION("Simple NCR53C710 driver"); |
| 53 | MODULE_LICENSE("GPL"); |
| 54 | |
| 55 | module_param(sim710, charp, 0); |
| 56 | |
| 57 | #ifdef MODULE |
| 58 | #define ARG_SEP ' ' |
| 59 | #else |
| 60 | #define ARG_SEP ',' |
| 61 | #endif |
| 62 | |
| 63 | static __init int |
| 64 | param_setup(char *str) |
| 65 | { |
| 66 | char *pos = str, *next; |
| 67 | int slot = -1; |
| 68 | |
| 69 | while(pos != NULL && (next = strchr(pos, ':')) != NULL) { |
| 70 | int val = (int)simple_strtoul(++next, NULL, 0); |
| 71 | |
| 72 | if(!strncmp(pos, "slot:", 5)) |
| 73 | slot = val; |
| 74 | else if(!strncmp(pos, "id:", 3)) { |
| 75 | if(slot == -1) { |
| 76 | printk(KERN_WARNING "sim710: Must specify slot for id parameter\n"); |
Eric Sesterhenn | 1a34456 | 2006-04-18 21:09:20 -0700 | [diff] [blame] | 77 | } else if(slot >= MAX_SLOTS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | printk(KERN_WARNING "sim710: Illegal slot %d for id %d\n", slot, val); |
| 79 | } else { |
| 80 | id_array[slot] = val; |
| 81 | } |
| 82 | } |
| 83 | if((pos = strchr(pos, ARG_SEP)) != NULL) |
| 84 | pos++; |
| 85 | } |
| 86 | return 1; |
| 87 | } |
| 88 | __setup("sim710=", param_setup); |
| 89 | |
| 90 | static struct scsi_host_template sim710_driver_template = { |
Paul Gortmaker | a88dc06 | 2012-05-16 20:33:52 -0400 | [diff] [blame] | 91 | .name = "LSI (Symbios) 710 EISA", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | .proc_name = "sim710", |
| 93 | .this_id = 7, |
| 94 | .module = THIS_MODULE, |
| 95 | }; |
| 96 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 97 | static int sim710_probe_common(struct device *dev, unsigned long base_addr, |
| 98 | int irq, int clock, int differential, |
| 99 | int scsi_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
| 101 | struct Scsi_Host * host = NULL; |
| 102 | struct NCR_700_Host_Parameters *hostdata = |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 103 | kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 105 | printk(KERN_NOTICE "sim710: %s\n", dev_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | printk(KERN_NOTICE "sim710: irq = %d, clock = %d, base = 0x%lx, scsi_id = %d\n", |
| 107 | irq, clock, base_addr, scsi_id); |
| 108 | |
| 109 | if(hostdata == NULL) { |
| 110 | printk(KERN_ERR "sim710: Failed to allocate host data\n"); |
| 111 | goto out; |
| 112 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | if(request_region(base_addr, 64, "sim710") == NULL) { |
| 115 | printk(KERN_ERR "sim710: Failed to reserve IO region 0x%lx\n", |
| 116 | base_addr); |
| 117 | goto out_free; |
| 118 | } |
| 119 | |
| 120 | /* Fill in the three required pieces of hostdata */ |
| 56fece2 | 2005-04-03 03:57:48 -0600 | [diff] [blame] | 121 | hostdata->base = ioport_map(base_addr, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | hostdata->differential = differential; |
| 123 | hostdata->clock = clock; |
| 124 | hostdata->chip710 = 1; |
Thomas Bogendoerfer | f67a9c1 | 2006-12-25 21:30:08 +0100 | [diff] [blame] | 125 | hostdata->burst_length = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
| 127 | /* and register the chip */ |
| 128 | if((host = NCR_700_detect(&sim710_driver_template, hostdata, dev)) |
| 129 | == NULL) { |
| 130 | printk(KERN_ERR "sim710: No host detected; card configuration problem?\n"); |
| 131 | goto out_release; |
| 132 | } |
| 133 | host->this_id = scsi_id; |
| 56fece2 | 2005-04-03 03:57:48 -0600 | [diff] [blame] | 134 | host->base = base_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | host->irq = irq; |
Thomas Gleixner | 1d6f359 | 2006-07-01 19:29:42 -0700 | [diff] [blame] | 136 | if (request_irq(irq, NCR_700_intr, IRQF_SHARED, "sim710", host)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | printk(KERN_ERR "sim710: request_irq failed\n"); |
| 138 | goto out_put_host; |
| 139 | } |
| 140 | |
Matthew Wilcox | 3ac709c | 2007-07-17 13:38:03 -0600 | [diff] [blame] | 141 | dev_set_drvdata(dev, host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | scsi_scan_host(host); |
| 143 | |
| 144 | return 0; |
| 145 | |
| 146 | out_put_host: |
| 147 | scsi_host_put(host); |
| 148 | out_release: |
Adrian Bunk | a1d4f73 | 2006-03-10 23:25:00 +0100 | [diff] [blame] | 149 | release_region(base_addr, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | out_free: |
| 151 | kfree(hostdata); |
| 152 | out: |
| 153 | return -ENODEV; |
| 154 | } |
| 155 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 156 | static int sim710_device_remove(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
Matthew Wilcox | 3ac709c | 2007-07-17 13:38:03 -0600 | [diff] [blame] | 158 | struct Scsi_Host *host = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | struct NCR_700_Host_Parameters *hostdata = |
| 160 | (struct NCR_700_Host_Parameters *)host->hostdata[0]; |
| 161 | |
| 162 | scsi_remove_host(host); |
| 163 | NCR_700_release(host); |
| 164 | kfree(hostdata); |
| 165 | free_irq(host->irq, host); |
| 56fece2 | 2005-04-03 03:57:48 -0600 | [diff] [blame] | 166 | release_region(host->base, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | return 0; |
| 168 | } |
| 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | #ifdef CONFIG_EISA |
| 171 | static struct eisa_device_id sim710_eisa_ids[] = { |
| 172 | { "CPQ4410" }, |
| 173 | { "CPQ4411" }, |
| 174 | { "HWP0C80" }, |
| 175 | { "" } |
| 176 | }; |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 177 | MODULE_DEVICE_TABLE(eisa, sim710_eisa_ids); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Sudip Mukherjee | 648a0a7 | 2016-02-11 10:29:03 +0530 | [diff] [blame] | 179 | static int sim710_eisa_probe(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | { |
| 181 | struct eisa_device *edev = to_eisa_device(dev); |
| 182 | unsigned long io_addr = edev->base_addr; |
| 183 | char eisa_cpq_irqs[] = { 11, 14, 15, 10, 9, 0 }; |
| 184 | char eisa_hwp_irqs[] = { 3, 4, 5, 7, 12, 10, 11, 0}; |
| 185 | char *eisa_irqs; |
| 186 | unsigned char irq_index; |
| 187 | unsigned char irq, differential = 0, scsi_id = 7; |
| 188 | |
| 189 | if(strcmp(edev->id.sig, "HWP0C80") == 0) { |
| 190 | __u8 val; |
| 191 | eisa_irqs = eisa_hwp_irqs; |
| 192 | irq_index = (inb(io_addr + 0xc85) & 0x7) - 1; |
| 193 | |
| 194 | val = inb(io_addr + 0x4); |
| 195 | scsi_id = ffs(val) - 1; |
| 196 | |
| 197 | if(scsi_id > 7 || (val & ~(1<<scsi_id)) != 0) { |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 198 | printk(KERN_ERR "sim710.c, EISA card %s has incorrect scsi_id, setting to 7\n", dev_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | scsi_id = 7; |
| 200 | } |
| 201 | } else { |
| 202 | eisa_irqs = eisa_cpq_irqs; |
| 203 | irq_index = inb(io_addr + 0xc88) & 0x07; |
| 204 | } |
| 205 | |
| 206 | if(irq_index >= strlen(eisa_irqs)) { |
| 207 | printk("sim710.c: irq nasty\n"); |
| 208 | return -ENODEV; |
| 209 | } |
| 210 | |
| 211 | irq = eisa_irqs[irq_index]; |
| 212 | |
| 213 | return sim710_probe_common(dev, io_addr, irq, 50, |
| 214 | differential, scsi_id); |
| 215 | } |
| 216 | |
| 217 | static struct eisa_driver sim710_eisa_driver = { |
| 218 | .id_table = sim710_eisa_ids, |
| 219 | .driver = { |
| 220 | .name = "sim710", |
| 221 | .probe = sim710_eisa_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 222 | .remove = sim710_device_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | }, |
| 224 | }; |
| 225 | #endif /* CONFIG_EISA */ |
| 226 | |
| 227 | static int __init sim710_init(void) |
| 228 | { |
| 229 | int err = -ENODEV; |
| 230 | |
| 231 | #ifdef MODULE |
| 232 | if (sim710) |
| 233 | param_setup(sim710); |
| 234 | #endif |
| 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | #ifdef CONFIG_EISA |
| 237 | err = eisa_driver_register(&sim710_eisa_driver); |
| 238 | #endif |
| 239 | /* FIXME: what we'd really like to return here is -ENODEV if |
| 240 | * no devices have actually been found. Instead, the err |
| 241 | * above actually only reports problems with kobject_register, |
| 242 | * so for the moment return success */ |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | static void __exit sim710_exit(void) |
| 248 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | #ifdef CONFIG_EISA |
| 250 | eisa_driver_unregister(&sim710_eisa_driver); |
| 251 | #endif |
| 252 | } |
| 253 | |
| 254 | module_init(sim710_init); |
| 255 | module_exit(sim710_exit); |