Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v2.6.19 373 lines 10 kB view raw
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 * 20 * MCA card detection code by Trent McNair. 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 29#include <linux/module.h> 30 31#include <linux/blkdev.h> 32#include <linux/device.h> 33#include <linux/init.h> 34#include <linux/mca.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> 41 42#include "53c700.h" 43 44 45/* Must be enough for both EISA and MCA */ 46#define MAX_SLOTS 8 47static __u8 __initdata id_array[MAX_SLOTS] = { [0 ... MAX_SLOTS-1] = 7 }; 48 49static char *sim710; /* command line passed by insmod */ 50 51MODULE_AUTHOR("Richard Hirst"); 52MODULE_DESCRIPTION("Simple NCR53C710 driver"); 53MODULE_LICENSE("GPL"); 54 55module_param(sim710, charp, 0); 56 57#ifdef MODULE 58#define ARG_SEP ' ' 59#else 60#define ARG_SEP ',' 61#endif 62 63static __init int 64param_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"); 77 } else if(slot >= MAX_SLOTS) { 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 90static struct scsi_host_template sim710_driver_template = { 91 .name = "LSI (Symbios) 710 MCA/EISA", 92 .proc_name = "sim710", 93 .this_id = 7, 94 .module = THIS_MODULE, 95}; 96 97static __devinit int 98sim710_probe_common(struct device *dev, unsigned long base_addr, 99 int irq, int clock, int differential, int scsi_id) 100{ 101 struct Scsi_Host * host = NULL; 102 struct NCR_700_Host_Parameters *hostdata = 103 kmalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL); 104 105 printk(KERN_NOTICE "sim710: %s\n", dev->bus_id); 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 } 113 memset(hostdata, 0, sizeof(struct NCR_700_Host_Parameters)); 114 115 if(request_region(base_addr, 64, "sim710") == NULL) { 116 printk(KERN_ERR "sim710: Failed to reserve IO region 0x%lx\n", 117 base_addr); 118 goto out_free; 119 } 120 121 /* Fill in the three required pieces of hostdata */ 122 hostdata->base = ioport_map(base_addr, 64); 123 hostdata->differential = differential; 124 hostdata->clock = clock; 125 hostdata->chip710 = 1; 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; 134 host->base = base_addr; 135 host->irq = irq; 136 if (request_irq(irq, NCR_700_intr, IRQF_SHARED, "sim710", host)) { 137 printk(KERN_ERR "sim710: request_irq failed\n"); 138 goto out_put_host; 139 } 140 141 scsi_scan_host(host); 142 143 return 0; 144 145 out_put_host: 146 scsi_host_put(host); 147 out_release: 148 release_region(base_addr, 64); 149 out_free: 150 kfree(hostdata); 151 out: 152 return -ENODEV; 153} 154 155static __devexit int 156sim710_device_remove(struct device *dev) 157{ 158 struct Scsi_Host *host = dev_to_shost(dev); 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); 166 release_region(host->base, 64); 167 return 0; 168} 169 170#ifdef CONFIG_MCA 171 172/* CARD ID 01BB and 01BA use the same pos values */ 173#define MCA_01BB_IO_PORTS { 0x0000, 0x0000, 0x0800, 0x0C00, 0x1000, 0x1400, \ 174 0x1800, 0x1C00, 0x2000, 0x2400, 0x2800, \ 175 0x2C00, 0x3000, 0x3400, 0x3800, 0x3C00, \ 176 0x4000, 0x4400, 0x4800, 0x4C00, 0x5000 } 177 178#define MCA_01BB_IRQS { 3, 5, 11, 14 } 179 180/* CARD ID 004f */ 181#define MCA_004F_IO_PORTS { 0x0000, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600 } 182#define MCA_004F_IRQS { 5, 9, 14 } 183 184static short sim710_mca_id_table[] = { 0x01bb, 0x01ba, 0x004f, 0}; 185 186static __init int 187sim710_mca_probe(struct device *dev) 188{ 189 struct mca_device *mca_dev = to_mca_device(dev); 190 int slot = mca_dev->slot; 191 int pos[3]; 192 unsigned int base; 193 int irq_vector; 194 short id = sim710_mca_id_table[mca_dev->index]; 195 static int io_004f_by_pos[] = MCA_004F_IO_PORTS; 196 static int irq_004f_by_pos[] = MCA_004F_IRQS; 197 static int io_01bb_by_pos[] = MCA_01BB_IO_PORTS; 198 static int irq_01bb_by_pos[] = MCA_01BB_IRQS; 199 char *name; 200 int clock; 201 202 pos[0] = mca_device_read_stored_pos(mca_dev, 2); 203 pos[1] = mca_device_read_stored_pos(mca_dev, 3); 204 pos[2] = mca_device_read_stored_pos(mca_dev, 4); 205 206 /* 207 * 01BB & 01BA port base by bits 7,6,5,4,3,2 in pos[2] 208 * 209 * 000000 <disabled> 001010 0x2800 210 * 000001 <invalid> 001011 0x2C00 211 * 000010 0x0800 001100 0x3000 212 * 000011 0x0C00 001101 0x3400 213 * 000100 0x1000 001110 0x3800 214 * 000101 0x1400 001111 0x3C00 215 * 000110 0x1800 010000 0x4000 216 * 000111 0x1C00 010001 0x4400 217 * 001000 0x2000 010010 0x4800 218 * 001001 0x2400 010011 0x4C00 219 * 010100 0x5000 220 * 221 * 00F4 port base by bits 3,2,1 in pos[0] 222 * 223 * 000 <disabled> 001 0x200 224 * 010 0x300 011 0x400 225 * 100 0x500 101 0x600 226 * 227 * 01BB & 01BA IRQ is specified in pos[0] bits 7 and 6: 228 * 229 * 00 3 10 11 230 * 01 5 11 14 231 * 232 * 00F4 IRQ specified by bits 6,5,4 in pos[0] 233 * 234 * 100 5 101 9 235 * 110 14 236 */ 237 238 if (id == 0x01bb || id == 0x01ba) { 239 base = io_01bb_by_pos[(pos[2] & 0xFC) >> 2]; 240 irq_vector = 241 irq_01bb_by_pos[((pos[0] & 0xC0) >> 6)]; 242 243 clock = 50; 244 if (id == 0x01bb) 245 name = "NCR 3360/3430 SCSI SubSystem"; 246 else 247 name = "NCR Dual SIOP SCSI Host Adapter Board"; 248 } else if ( id == 0x004f ) { 249 base = io_004f_by_pos[((pos[0] & 0x0E) >> 1)]; 250 irq_vector = 251 irq_004f_by_pos[((pos[0] & 0x70) >> 4) - 4]; 252 clock = 50; 253 name = "NCR 53c710 SCSI Host Adapter Board"; 254 } else { 255 return -ENODEV; 256 } 257 mca_device_set_name(mca_dev, name); 258 mca_device_set_claim(mca_dev, 1); 259 base = mca_device_transform_ioport(mca_dev, base); 260 irq_vector = mca_device_transform_irq(mca_dev, irq_vector); 261 262 return sim710_probe_common(dev, base, irq_vector, clock, 263 0, id_array[slot]); 264} 265 266static struct mca_driver sim710_mca_driver = { 267 .id_table = sim710_mca_id_table, 268 .driver = { 269 .name = "sim710", 270 .bus = &mca_bus_type, 271 .probe = sim710_mca_probe, 272 .remove = __devexit_p(sim710_device_remove), 273 }, 274}; 275 276#endif /* CONFIG_MCA */ 277 278#ifdef CONFIG_EISA 279static struct eisa_device_id sim710_eisa_ids[] = { 280 { "CPQ4410" }, 281 { "CPQ4411" }, 282 { "HWP0C80" }, 283 { "" } 284}; 285MODULE_DEVICE_TABLE(eisa, sim710_eisa_ids); 286 287static __init int 288sim710_eisa_probe(struct device *dev) 289{ 290 struct eisa_device *edev = to_eisa_device(dev); 291 unsigned long io_addr = edev->base_addr; 292 char eisa_cpq_irqs[] = { 11, 14, 15, 10, 9, 0 }; 293 char eisa_hwp_irqs[] = { 3, 4, 5, 7, 12, 10, 11, 0}; 294 char *eisa_irqs; 295 unsigned char irq_index; 296 unsigned char irq, differential = 0, scsi_id = 7; 297 298 if(strcmp(edev->id.sig, "HWP0C80") == 0) { 299 __u8 val; 300 eisa_irqs = eisa_hwp_irqs; 301 irq_index = (inb(io_addr + 0xc85) & 0x7) - 1; 302 303 val = inb(io_addr + 0x4); 304 scsi_id = ffs(val) - 1; 305 306 if(scsi_id > 7 || (val & ~(1<<scsi_id)) != 0) { 307 printk(KERN_ERR "sim710.c, EISA card %s has incorrect scsi_id, setting to 7\n", dev->bus_id); 308 scsi_id = 7; 309 } 310 } else { 311 eisa_irqs = eisa_cpq_irqs; 312 irq_index = inb(io_addr + 0xc88) & 0x07; 313 } 314 315 if(irq_index >= strlen(eisa_irqs)) { 316 printk("sim710.c: irq nasty\n"); 317 return -ENODEV; 318 } 319 320 irq = eisa_irqs[irq_index]; 321 322 return sim710_probe_common(dev, io_addr, irq, 50, 323 differential, scsi_id); 324} 325 326static struct eisa_driver sim710_eisa_driver = { 327 .id_table = sim710_eisa_ids, 328 .driver = { 329 .name = "sim710", 330 .probe = sim710_eisa_probe, 331 .remove = __devexit_p(sim710_device_remove), 332 }, 333}; 334#endif /* CONFIG_EISA */ 335 336static int __init sim710_init(void) 337{ 338 int err = -ENODEV; 339 340#ifdef MODULE 341 if (sim710) 342 param_setup(sim710); 343#endif 344 345#ifdef CONFIG_MCA 346 err = mca_register_driver(&sim710_mca_driver); 347#endif 348 349#ifdef CONFIG_EISA 350 err = eisa_driver_register(&sim710_eisa_driver); 351#endif 352 /* FIXME: what we'd really like to return here is -ENODEV if 353 * no devices have actually been found. Instead, the err 354 * above actually only reports problems with kobject_register, 355 * so for the moment return success */ 356 357 return 0; 358} 359 360static void __exit sim710_exit(void) 361{ 362#ifdef CONFIG_MCA 363 if (MCA_bus) 364 mca_unregister_driver(&sim710_mca_driver); 365#endif 366 367#ifdef CONFIG_EISA 368 eisa_driver_unregister(&sim710_eisa_driver); 369#endif 370} 371 372module_init(sim710_init); 373module_exit(sim710_exit);