Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Linux driver attachment glue for aic7770 based controllers. |
| 3 | * |
| 4 | * Copyright (c) 2000-2003 Adaptec Inc. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions, and the following disclaimer, |
| 12 | * without modification. |
| 13 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 14 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 15 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 16 | * including a substantially similar Disclaimer requirement for further |
| 17 | * binary redistribution. |
| 18 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 19 | * of any contributors may be used to endorse or promote products derived |
| 20 | * from this software without specific prior written permission. |
| 21 | * |
| 22 | * Alternatively, this software may be distributed under the terms of the |
| 23 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 24 | * Software Foundation. |
| 25 | * |
| 26 | * NO WARRANTY |
| 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 31 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 35 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 36 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 37 | * POSSIBILITY OF SUCH DAMAGES. |
| 38 | * |
| 39 | * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7770_osm.c#14 $ |
| 40 | */ |
| 41 | |
| 42 | #include "aic7xxx_osm.h" |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <linux/device.h> |
| 45 | #include <linux/eisa.h> |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | int |
| 48 | aic7770_map_registers(struct ahc_softc *ahc, u_int port) |
| 49 | { |
| 50 | /* |
| 51 | * Lock out other contenders for our i/o space. |
| 52 | */ |
Harvey Harrison | 172c122 | 2008-04-28 16:50:03 -0700 | [diff] [blame] | 53 | if (!request_region(port, AHC_EISA_IOSIZE, "aic7xxx")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | return (ENOMEM); |
| 55 | ahc->tag = BUS_SPACE_PIO; |
| 56 | ahc->bsh.ioport = port; |
| 57 | return (0); |
| 58 | } |
| 59 | |
| 60 | int |
| 61 | aic7770_map_int(struct ahc_softc *ahc, u_int irq) |
| 62 | { |
| 63 | int error; |
| 64 | int shared; |
| 65 | |
| 66 | shared = 0; |
| 67 | if ((ahc->flags & AHC_EDGE_INTERRUPT) == 0) |
Thomas Gleixner | 1d6f359 | 2006-07-01 19:29:42 -0700 | [diff] [blame] | 68 | shared = IRQF_SHARED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | error = request_irq(irq, ahc_linux_isr, shared, "aic7xxx", ahc); |
| 71 | if (error == 0) |
| 72 | ahc->platform_data->irq = irq; |
| 73 | |
| 74 | return (-error); |
| 75 | } |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | static int |
Christoph Hellwig | d6cbbad | 2005-06-11 00:17:03 +0200 | [diff] [blame] | 78 | aic7770_probe(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
Christoph Hellwig | d6cbbad | 2005-06-11 00:17:03 +0200 | [diff] [blame] | 80 | struct eisa_device *edev = to_eisa_device(dev); |
| 81 | u_int eisaBase = edev->base_addr+AHC_EISA_SLOT_OFFSET; |
| 82 | struct ahc_softc *ahc; |
| 83 | char buf[80]; |
| 84 | char *name; |
| 85 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Christoph Hellwig | d6cbbad | 2005-06-11 00:17:03 +0200 | [diff] [blame] | 87 | sprintf(buf, "ahc_eisa:%d", eisaBase >> 12); |
Pekka Enberg | 48813cf | 2010-07-14 13:12:57 +0300 | [diff] [blame^] | 88 | name = kmalloc(strlen(buf) + 1, GFP_ATOMIC); |
Christoph Hellwig | d6cbbad | 2005-06-11 00:17:03 +0200 | [diff] [blame] | 89 | if (name == NULL) |
| 90 | return (ENOMEM); |
| 91 | strcpy(name, buf); |
| 92 | ahc = ahc_alloc(&aic7xxx_driver_template, name); |
| 93 | if (ahc == NULL) |
| 94 | return (ENOMEM); |
| 95 | error = aic7770_config(ahc, aic7770_ident_table + edev->id.driver_data, |
| 96 | eisaBase); |
| 97 | if (error != 0) { |
| 98 | ahc->bsh.ioport = 0; |
| 99 | ahc_free(ahc); |
| 100 | return (error); |
| 101 | } |
| 102 | |
| 103 | dev_set_drvdata(dev, ahc); |
| 104 | |
Christoph Hellwig | dfd287f | 2005-06-28 16:49:44 +0200 | [diff] [blame] | 105 | error = ahc_linux_register_host(ahc, &aic7xxx_driver_template); |
Christoph Hellwig | d6cbbad | 2005-06-11 00:17:03 +0200 | [diff] [blame] | 106 | return (error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static int |
Christoph Hellwig | d6cbbad | 2005-06-11 00:17:03 +0200 | [diff] [blame] | 110 | aic7770_remove(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | { |
Christoph Hellwig | d6cbbad | 2005-06-11 00:17:03 +0200 | [diff] [blame] | 112 | struct ahc_softc *ahc = dev_get_drvdata(dev); |
Christoph Hellwig | 3d65692 | 2005-06-11 00:14:30 +0200 | [diff] [blame] | 113 | u_long s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
James Bottomley | 97af50f | 2005-10-02 15:22:35 -0500 | [diff] [blame] | 115 | if (ahc->platform_data && ahc->platform_data->host) |
| 116 | scsi_remove_host(ahc->platform_data->host); |
| 117 | |
Christoph Hellwig | 3d65692 | 2005-06-11 00:14:30 +0200 | [diff] [blame] | 118 | ahc_lock(ahc, &s); |
| 119 | ahc_intr_enable(ahc, FALSE); |
| 120 | ahc_unlock(ahc, &s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Christoph Hellwig | d6cbbad | 2005-06-11 00:17:03 +0200 | [diff] [blame] | 122 | ahc_free(ahc); |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static struct eisa_device_id aic7770_ids[] = { |
| 127 | { "ADP7771", 0 }, /* AHA 274x */ |
| 128 | { "ADP7756", 1 }, /* AHA 284x BIOS enabled */ |
| 129 | { "ADP7757", 2 }, /* AHA 284x BIOS disabled */ |
| 130 | { "ADP7782", 3 }, /* AHA 274x Olivetti OEM */ |
| 131 | { "ADP7783", 4 }, /* AHA 274x Olivetti OEM (Differential) */ |
| 132 | { "ADP7770", 5 }, /* AIC7770 generic */ |
| 133 | { "" } |
| 134 | }; |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 135 | MODULE_DEVICE_TABLE(eisa, aic7770_ids); |
| 136 | |
Christoph Hellwig | d6cbbad | 2005-06-11 00:17:03 +0200 | [diff] [blame] | 137 | static struct eisa_driver aic7770_driver = { |
| 138 | .id_table = aic7770_ids, |
| 139 | .driver = { |
| 140 | .name = "aic7xxx", |
| 141 | .probe = aic7770_probe, |
| 142 | .remove = aic7770_remove, |
| 143 | } |
| 144 | }; |
| 145 | |
| 146 | int |
| 147 | ahc_linux_eisa_init(void) |
| 148 | { |
| 149 | return eisa_driver_register(&aic7770_driver); |
| 150 | } |
| 151 | |
| 152 | void |
| 153 | ahc_linux_eisa_exit(void) |
| 154 | { |
| 155 | eisa_driver_unregister(&aic7770_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |