2 * sim710.c - Copyright (C) 1999 Richard Hirst <richard@sleepie.demon.co.uk>
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.
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.
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 *----------------------------------------------------------------------------
20 * MCA card detection code by Trent McNair. (now deleted)
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.
25 * Rewritten to use 53c700.c by James.Bottomley@SteelEye.com
29 #include <linux/module.h>
30 #include <linux/slab.h>
32 #include <linux/blkdev.h>
33 #include <linux/device.h>
34 #include <linux/init.h>
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>
45 /* Must be enough for EISA */
47 static __u8 __initdata id_array[MAX_SLOTS] = { [0 ... MAX_SLOTS-1] = 7 };
49 static char *sim710; /* command line passed by insmod */
51 MODULE_AUTHOR("Richard Hirst");
52 MODULE_DESCRIPTION("Simple NCR53C710 driver");
53 MODULE_LICENSE("GPL");
55 module_param(sim710, charp, 0);
64 param_setup(char *str)
66 char *pos = str, *next;
69 while(pos != NULL && (next = strchr(pos, ':')) != NULL) {
70 int val = (int)simple_strtoul(++next, NULL, 0);
72 if(!strncmp(pos, "slot:", 5))
74 else if(!strncmp(pos, "id:", 3)) {
76 printk(KERN_WARNING "sim710: Must specify slot for id parameter\n");
77 } else if(slot >= MAX_SLOTS) {
78 printk(KERN_WARNING "sim710: Illegal slot %d for id %d\n", slot, val);
83 if((pos = strchr(pos, ARG_SEP)) != NULL)
88 __setup("sim710=", param_setup);
90 static struct scsi_host_template sim710_driver_template = {
91 .name = "LSI (Symbios) 710 EISA",
92 .proc_name = "sim710",
94 .module = THIS_MODULE,
98 sim710_probe_common(struct device *dev, unsigned long base_addr,
99 int irq, int clock, int differential, int scsi_id)
101 struct Scsi_Host * host = NULL;
102 struct NCR_700_Host_Parameters *hostdata =
103 kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL);
105 printk(KERN_NOTICE "sim710: %s\n", dev_name(dev));
106 printk(KERN_NOTICE "sim710: irq = %d, clock = %d, base = 0x%lx, scsi_id = %d\n",
107 irq, clock, base_addr, scsi_id);
109 if(hostdata == NULL) {
110 printk(KERN_ERR "sim710: Failed to allocate host data\n");
114 if(request_region(base_addr, 64, "sim710") == NULL) {
115 printk(KERN_ERR "sim710: Failed to reserve IO region 0x%lx\n",
120 /* Fill in the three required pieces of hostdata */
121 hostdata->base = ioport_map(base_addr, 64);
122 hostdata->differential = differential;
123 hostdata->clock = clock;
124 hostdata->chip710 = 1;
125 hostdata->burst_length = 8;
127 /* and register the chip */
128 if((host = NCR_700_detect(&sim710_driver_template, hostdata, dev))
130 printk(KERN_ERR "sim710: No host detected; card configuration problem?\n");
133 host->this_id = scsi_id;
134 host->base = base_addr;
136 if (request_irq(irq, NCR_700_intr, IRQF_SHARED, "sim710", host)) {
137 printk(KERN_ERR "sim710: request_irq failed\n");
141 dev_set_drvdata(dev, host);
142 scsi_scan_host(host);
149 release_region(base_addr, 64);
157 sim710_device_remove(struct device *dev)
159 struct Scsi_Host *host = dev_get_drvdata(dev);
160 struct NCR_700_Host_Parameters *hostdata =
161 (struct NCR_700_Host_Parameters *)host->hostdata[0];
163 scsi_remove_host(host);
164 NCR_700_release(host);
166 free_irq(host->irq, host);
167 release_region(host->base, 64);
172 static struct eisa_device_id sim710_eisa_ids[] = {
178 MODULE_DEVICE_TABLE(eisa, sim710_eisa_ids);
181 sim710_eisa_probe(struct device *dev)
183 struct eisa_device *edev = to_eisa_device(dev);
184 unsigned long io_addr = edev->base_addr;
185 char eisa_cpq_irqs[] = { 11, 14, 15, 10, 9, 0 };
186 char eisa_hwp_irqs[] = { 3, 4, 5, 7, 12, 10, 11, 0};
188 unsigned char irq_index;
189 unsigned char irq, differential = 0, scsi_id = 7;
191 if(strcmp(edev->id.sig, "HWP0C80") == 0) {
193 eisa_irqs = eisa_hwp_irqs;
194 irq_index = (inb(io_addr + 0xc85) & 0x7) - 1;
196 val = inb(io_addr + 0x4);
197 scsi_id = ffs(val) - 1;
199 if(scsi_id > 7 || (val & ~(1<<scsi_id)) != 0) {
200 printk(KERN_ERR "sim710.c, EISA card %s has incorrect scsi_id, setting to 7\n", dev_name(dev));
204 eisa_irqs = eisa_cpq_irqs;
205 irq_index = inb(io_addr + 0xc88) & 0x07;
208 if(irq_index >= strlen(eisa_irqs)) {
209 printk("sim710.c: irq nasty\n");
213 irq = eisa_irqs[irq_index];
215 return sim710_probe_common(dev, io_addr, irq, 50,
216 differential, scsi_id);
219 static struct eisa_driver sim710_eisa_driver = {
220 .id_table = sim710_eisa_ids,
223 .probe = sim710_eisa_probe,
224 .remove = __devexit_p(sim710_device_remove),
227 #endif /* CONFIG_EISA */
229 static int __init sim710_init(void)
239 err = eisa_driver_register(&sim710_eisa_driver);
241 /* FIXME: what we'd really like to return here is -ENODEV if
242 * no devices have actually been found. Instead, the err
243 * above actually only reports problems with kobject_register,
244 * so for the moment return success */
249 static void __exit sim710_exit(void)
252 eisa_driver_unregister(&sim710_eisa_driver);
256 module_init(sim710_init);
257 module_exit(sim710_exit);