Merge commit 'upstream/master'
[pandora-kernel.git] / drivers / ide / pci / generic.c
1 /*
2  *  Copyright (C) 2001-2002     Andre Hedrick <andre@linux-ide.org>
3  *  Portions (C) Copyright 2002  Red Hat Inc <alan@redhat.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2, or (at your option) any
8  * later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * For the avoidance of doubt the "preferred form" of this code is one which
16  * is in an open non patent encumbered format. Where cryptographic key signing
17  * forms part of the process of creating an executable the information
18  * including keys needed to generate an equivalently functional executable
19  * are deemed to be part of the source code.
20  */
21
22 #include <linux/types.h>
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/hdreg.h>
26 #include <linux/pci.h>
27 #include <linux/ide.h>
28 #include <linux/init.h>
29
30 #define DRV_NAME "ide_pci_generic"
31
32 static int ide_generic_all;             /* Set to claim all devices */
33
34 module_param_named(all_generic_ide, ide_generic_all, bool, 0444);
35 MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE storage controllers.");
36
37 #define IDE_HFLAGS_UMC (IDE_HFLAG_NO_DMA | IDE_HFLAG_FORCE_LEGACY_IRQS)
38
39 #define DECLARE_GENERIC_PCI_DEV(extra_flags) \
40         { \
41                 .name           = DRV_NAME, \
42                 .host_flags     = IDE_HFLAG_TRUST_BIOS_FOR_DMA | \
43                                   extra_flags, \
44                 .swdma_mask     = ATA_SWDMA2, \
45                 .mwdma_mask     = ATA_MWDMA2, \
46                 .udma_mask      = ATA_UDMA6, \
47         }
48
49 static const struct ide_port_info generic_chipsets[] __devinitdata = {
50         /*  0: Unknown */
51         DECLARE_GENERIC_PCI_DEV(0),
52
53         {       /* 1: NS87410 */
54                 .name           = DRV_NAME,
55                 .enablebits     = { {0x43, 0x08, 0x08}, {0x47, 0x08, 0x08} },
56                 .host_flags     = IDE_HFLAG_TRUST_BIOS_FOR_DMA,
57                 .swdma_mask     = ATA_SWDMA2,
58                 .mwdma_mask     = ATA_MWDMA2,
59                 .udma_mask      = ATA_UDMA6,
60         },
61
62         /*  2: SAMURAI / HT6565 / HINT_IDE */
63         DECLARE_GENERIC_PCI_DEV(0),
64         /*  3: UM8673F / UM8886A / UM8886BF */
65         DECLARE_GENERIC_PCI_DEV(IDE_HFLAGS_UMC),
66         /*  4: VIA_IDE / OPTI621V / Piccolo010{2,3,5} */
67         DECLARE_GENERIC_PCI_DEV(IDE_HFLAG_NO_AUTODMA),
68
69         {       /* 5: VIA8237SATA */
70                 .name           = DRV_NAME,
71                 .host_flags     = IDE_HFLAG_TRUST_BIOS_FOR_DMA |
72                                   IDE_HFLAG_OFF_BOARD,
73                 .swdma_mask     = ATA_SWDMA2,
74                 .mwdma_mask     = ATA_MWDMA2,
75                 .udma_mask      = ATA_UDMA6,
76         },
77
78         {       /* 6: Revolution */
79                 .name           = DRV_NAME,
80                 .host_flags     = IDE_HFLAG_CLEAR_SIMPLEX |
81                                   IDE_HFLAG_TRUST_BIOS_FOR_DMA |
82                                   IDE_HFLAG_OFF_BOARD,
83                 .swdma_mask     = ATA_SWDMA2,
84                 .mwdma_mask     = ATA_MWDMA2,
85                 .udma_mask      = ATA_UDMA6,
86         }
87 };
88
89 /**
90  *      generic_init_one        -       called when a PIIX is found
91  *      @dev: the generic device
92  *      @id: the matching pci id
93  *
94  *      Called when the PCI registration layer (or the IDE initialization)
95  *      finds a device matching our IDE device tables.
96  */
97
98 static int __devinit generic_init_one(struct pci_dev *dev, const struct pci_device_id *id)
99 {
100         const struct ide_port_info *d = &generic_chipsets[id->driver_data];
101         int ret = -ENODEV;
102
103         /* Don't use the generic entry unless instructed to do so */
104         if (id->driver_data == 0 && ide_generic_all == 0)
105                         goto out;
106
107         switch (dev->vendor) {
108         case PCI_VENDOR_ID_UMC:
109                 if (dev->device == PCI_DEVICE_ID_UMC_UM8886A &&
110                                 !(PCI_FUNC(dev->devfn) & 1))
111                         goto out; /* UM8886A/BF pair */
112                 break;
113         case PCI_VENDOR_ID_OPTI:
114                 if (dev->device == PCI_DEVICE_ID_OPTI_82C558 &&
115                                 !(PCI_FUNC(dev->devfn) & 1))
116                         goto out;
117                 break;
118         case PCI_VENDOR_ID_JMICRON:
119                 if (dev->device != PCI_DEVICE_ID_JMICRON_JMB368 &&
120                                 PCI_FUNC(dev->devfn) != 1)
121                         goto out;
122                 break;
123         case PCI_VENDOR_ID_NS:
124                 if (dev->device == PCI_DEVICE_ID_NS_87410 &&
125                                 (dev->class >> 8) != PCI_CLASS_STORAGE_IDE)
126                         goto out;
127                 break;
128         }
129
130         if (dev->vendor != PCI_VENDOR_ID_JMICRON) {
131                 u16 command;
132                 pci_read_config_word(dev, PCI_COMMAND, &command);
133                 if (!(command & PCI_COMMAND_IO)) {
134                         printk(KERN_INFO "%s %s: skipping disabled "
135                                 "controller\n", d->name, pci_name(dev));
136                         goto out;
137                 }
138         }
139         ret = ide_pci_init_one(dev, d, NULL);
140 out:
141         return ret;
142 }
143
144 static const struct pci_device_id generic_pci_tbl[] = {
145         { PCI_VDEVICE(NS,       PCI_DEVICE_ID_NS_87410),                 1 },
146         { PCI_VDEVICE(PCTECH,   PCI_DEVICE_ID_PCTECH_SAMURAI_IDE),       2 },
147         { PCI_VDEVICE(HOLTEK,   PCI_DEVICE_ID_HOLTEK_6565),              2 },
148         { PCI_VDEVICE(UMC,      PCI_DEVICE_ID_UMC_UM8673F),              3 },
149         { PCI_VDEVICE(UMC,      PCI_DEVICE_ID_UMC_UM8886A),              3 },
150         { PCI_VDEVICE(UMC,      PCI_DEVICE_ID_UMC_UM8886BF),             3 },
151         { PCI_VDEVICE(HINT,     PCI_DEVICE_ID_HINT_VXPROII_IDE),         2 },
152         { PCI_VDEVICE(VIA,      PCI_DEVICE_ID_VIA_82C561),               4 },
153         { PCI_VDEVICE(OPTI,     PCI_DEVICE_ID_OPTI_82C558),              4 },
154 #ifdef CONFIG_BLK_DEV_IDE_SATA
155         { PCI_VDEVICE(VIA,      PCI_DEVICE_ID_VIA_8237_SATA),            5 },
156 #endif
157         { PCI_VDEVICE(TOSHIBA,  PCI_DEVICE_ID_TOSHIBA_PICCOLO),          4 },
158         { PCI_VDEVICE(TOSHIBA,  PCI_DEVICE_ID_TOSHIBA_PICCOLO_1),        4 },
159         { PCI_VDEVICE(TOSHIBA,  PCI_DEVICE_ID_TOSHIBA_PICCOLO_2),        4 },
160         { PCI_VDEVICE(NETCELL,  PCI_DEVICE_ID_REVOLUTION),               6 },
161         /*
162          * Must come last.  If you add entries adjust
163          * this table and generic_chipsets[] appropriately.
164          */
165         { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 0 },
166         { 0, },
167 };
168 MODULE_DEVICE_TABLE(pci, generic_pci_tbl);
169
170 static struct pci_driver driver = {
171         .name           = "PCI_IDE",
172         .id_table       = generic_pci_tbl,
173         .probe          = generic_init_one,
174         .remove         = ide_pci_remove,
175 };
176
177 static int __init generic_ide_init(void)
178 {
179         return ide_pci_register_driver(&driver);
180 }
181
182 static void __exit generic_ide_exit(void)
183 {
184         pci_unregister_driver(&driver);
185 }
186
187 module_init(generic_ide_init);
188 module_exit(generic_ide_exit);
189
190 MODULE_AUTHOR("Andre Hedrick");
191 MODULE_DESCRIPTION("PCI driver module for generic PCI IDE");
192 MODULE_LICENSE("GPL");