upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / drivers / scsi / ata_piix.c
1 /*
2
3     ata_piix.c - Intel PATA/SATA controllers
4
5     Maintained by:  Jeff Garzik <jgarzik@pobox.com>
6                     Please ALWAYS copy linux-ide@vger.kernel.org
7                     on emails.
8
9
10         Copyright 2003-2004 Red Hat Inc
11         Copyright 2003-2004 Jeff Garzik
12
13
14         Copyright header from piix.c:
15
16     Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer
17     Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
18     Copyright (C) 2003 Red Hat Inc <alan@redhat.com>
19
20     May be copied or modified under the terms of the GNU General Public License
21
22  */
23
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/pci.h>
27 #include <linux/init.h>
28 #include <linux/blkdev.h>
29 #include <linux/delay.h>
30 #include "scsi.h"
31 #include <scsi/scsi_host.h>
32 #include <linux/libata.h>
33
34 #define DRV_NAME        "ata_piix"
35 #define DRV_VERSION     "1.03"
36
37 enum {
38         PIIX_IOCFG              = 0x54, /* IDE I/O configuration register */
39         ICH5_PMR                = 0x90, /* port mapping register */
40         ICH5_PCS                = 0x92, /* port control and status */
41
42         PIIX_FLAG_AHCI          = (1 << 28), /* AHCI possible */
43         PIIX_FLAG_CHECKINTR     = (1 << 29), /* make sure PCI INTx enabled */
44         PIIX_FLAG_COMBINED      = (1 << 30), /* combined mode possible */
45
46         /* combined mode.  if set, PATA is channel 0.
47          * if clear, PATA is channel 1.
48          */
49         PIIX_COMB_PATA_P0       = (1 << 1),
50         PIIX_COMB               = (1 << 2), /* combined mode enabled? */
51
52         PIIX_PORT_PRESENT       = (1 << 0),
53         PIIX_PORT_ENABLED       = (1 << 4),
54
55         PIIX_80C_PRI            = (1 << 5) | (1 << 4),
56         PIIX_80C_SEC            = (1 << 7) | (1 << 6),
57
58         ich5_pata               = 0,
59         ich5_sata               = 1,
60         piix4_pata              = 2,
61         ich6_sata               = 3,
62         ich6_sata_rm            = 4,
63         ich7_sata               = 5,
64 };
65
66 static int piix_init_one (struct pci_dev *pdev,
67                                     const struct pci_device_id *ent);
68
69 static void piix_pata_phy_reset(struct ata_port *ap);
70 static void piix_sata_phy_reset(struct ata_port *ap);
71 static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev);
72 static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev);
73
74 static unsigned int in_module_init = 1;
75
76 static struct pci_device_id piix_pci_tbl[] = {
77 #ifdef ATA_ENABLE_PATA
78         { 0x8086, 0x7111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix4_pata },
79         { 0x8086, 0x24db, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_pata },
80         { 0x8086, 0x25a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_pata },
81 #endif
82
83         /* NOTE: The following PCI ids must be kept in sync with the
84          * list in drivers/pci/quirks.c.
85          */
86
87         { 0x8086, 0x24d1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
88         { 0x8086, 0x24df, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
89         { 0x8086, 0x25a3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
90         { 0x8086, 0x25b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
91         { 0x8086, 0x2651, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata },
92         { 0x8086, 0x2652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_rm },
93         { 0x8086, 0x2653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_rm },
94         { 0x8086, 0x27c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich7_sata },
95         { 0x8086, 0x27c4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich7_sata },
96
97         { }     /* terminate list */
98 };
99
100 static struct pci_driver piix_pci_driver = {
101         .name                   = DRV_NAME,
102         .id_table               = piix_pci_tbl,
103         .probe                  = piix_init_one,
104         .remove                 = ata_pci_remove_one,
105 };
106
107 static Scsi_Host_Template piix_sht = {
108         .module                 = THIS_MODULE,
109         .name                   = DRV_NAME,
110         .ioctl                  = ata_scsi_ioctl,
111         .queuecommand           = ata_scsi_queuecmd,
112         .eh_strategy_handler    = ata_scsi_error,
113         .can_queue              = ATA_DEF_QUEUE,
114         .this_id                = ATA_SHT_THIS_ID,
115         .sg_tablesize           = LIBATA_MAX_PRD,
116         .max_sectors            = ATA_MAX_SECTORS,
117         .cmd_per_lun            = ATA_SHT_CMD_PER_LUN,
118         .emulated               = ATA_SHT_EMULATED,
119         .use_clustering         = ATA_SHT_USE_CLUSTERING,
120         .proc_name              = DRV_NAME,
121         .dma_boundary           = ATA_DMA_BOUNDARY,
122         .slave_configure        = ata_scsi_slave_config,
123         .bios_param             = ata_std_bios_param,
124 };
125
126 static struct ata_port_operations piix_pata_ops = {
127         .port_disable           = ata_port_disable,
128         .set_piomode            = piix_set_piomode,
129         .set_dmamode            = piix_set_dmamode,
130
131         .tf_load                = ata_tf_load,
132         .tf_read                = ata_tf_read,
133         .check_status           = ata_check_status,
134         .exec_command           = ata_exec_command,
135         .dev_select             = ata_std_dev_select,
136
137         .phy_reset              = piix_pata_phy_reset,
138
139         .bmdma_setup            = ata_bmdma_setup,
140         .bmdma_start            = ata_bmdma_start,
141         .qc_prep                = ata_qc_prep,
142         .qc_issue               = ata_qc_issue_prot,
143
144         .eng_timeout            = ata_eng_timeout,
145
146         .irq_handler            = ata_interrupt,
147         .irq_clear              = ata_bmdma_irq_clear,
148
149         .port_start             = ata_port_start,
150         .port_stop              = ata_port_stop,
151 };
152
153 static struct ata_port_operations piix_sata_ops = {
154         .port_disable           = ata_port_disable,
155
156         .tf_load                = ata_tf_load,
157         .tf_read                = ata_tf_read,
158         .check_status           = ata_check_status,
159         .exec_command           = ata_exec_command,
160         .dev_select             = ata_std_dev_select,
161
162         .phy_reset              = piix_sata_phy_reset,
163
164         .bmdma_setup            = ata_bmdma_setup,
165         .bmdma_start            = ata_bmdma_start,
166         .qc_prep                = ata_qc_prep,
167         .qc_issue               = ata_qc_issue_prot,
168
169         .eng_timeout            = ata_eng_timeout,
170
171         .irq_handler            = ata_interrupt,
172         .irq_clear              = ata_bmdma_irq_clear,
173
174         .port_start             = ata_port_start,
175         .port_stop              = ata_port_stop,
176 };
177
178 static struct ata_port_info piix_port_info[] = {
179         /* ich5_pata */
180         {
181                 .sht            = &piix_sht,
182                 .host_flags     = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST |
183                                   PIIX_FLAG_CHECKINTR,
184                 .pio_mask       = 0x1f, /* pio0-4 */
185 #if 0
186                 .mwdma_mask     = 0x06, /* mwdma1-2 */
187 #else
188                 .mwdma_mask     = 0x00, /* mwdma broken */
189 #endif
190                 .udma_mask      = 0x3f, /* udma0-5 */
191                 .port_ops       = &piix_pata_ops,
192         },
193
194         /* ich5_sata */
195         {
196                 .sht            = &piix_sht,
197                 .host_flags     = ATA_FLAG_SATA | ATA_FLAG_SRST |
198                                   PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR,
199                 .pio_mask       = 0x1f, /* pio0-4 */
200                 .mwdma_mask     = 0x07, /* mwdma0-2 */
201                 .udma_mask      = 0x7f, /* udma0-6 */
202                 .port_ops       = &piix_sata_ops,
203         },
204
205         /* piix4_pata */
206         {
207                 .sht            = &piix_sht,
208                 .host_flags     = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
209                 .pio_mask       = 0x1f, /* pio0-4 */
210 #if 0
211                 .mwdma_mask     = 0x06, /* mwdma1-2 */
212 #else
213                 .mwdma_mask     = 0x00, /* mwdma broken */
214 #endif
215                 .udma_mask      = ATA_UDMA_MASK_40C,
216                 .port_ops       = &piix_pata_ops,
217         },
218
219         /* ich6_sata */
220         {
221                 .sht            = &piix_sht,
222                 .host_flags     = ATA_FLAG_SATA | ATA_FLAG_SRST |
223                                   PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR |
224                                   ATA_FLAG_SLAVE_POSS,
225                 .pio_mask       = 0x1f, /* pio0-4 */
226                 .mwdma_mask     = 0x07, /* mwdma0-2 */
227                 .udma_mask      = 0x7f, /* udma0-6 */
228                 .port_ops       = &piix_sata_ops,
229         },
230
231         /* ich6_sata_rm */
232         {
233                 .sht            = &piix_sht,
234                 .host_flags     = ATA_FLAG_SATA | ATA_FLAG_SRST |
235                                   PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR |
236                                   ATA_FLAG_SLAVE_POSS | PIIX_FLAG_AHCI,
237                 .pio_mask       = 0x1f, /* pio0-4 */
238                 .mwdma_mask     = 0x07, /* mwdma0-2 */
239                 .udma_mask      = 0x7f, /* udma0-6 */
240                 .port_ops       = &piix_sata_ops,
241         },
242
243         /* ich7_sata */
244         {
245                 .sht            = &piix_sht,
246                 .host_flags     = ATA_FLAG_SATA | ATA_FLAG_SRST |
247                                   PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR |
248                                   ATA_FLAG_SLAVE_POSS | PIIX_FLAG_AHCI,
249                 .pio_mask       = 0x1f, /* pio0-4 */
250                 .mwdma_mask     = 0x07, /* mwdma0-2 */
251                 .udma_mask      = 0x7f, /* udma0-6 */
252                 .port_ops       = &piix_sata_ops,
253         },
254 };
255
256 static struct pci_bits piix_enable_bits[] = {
257         { 0x41U, 1U, 0x80UL, 0x80UL },  /* port 0 */
258         { 0x43U, 1U, 0x80UL, 0x80UL },  /* port 1 */
259 };
260
261 MODULE_AUTHOR("Andre Hedrick, Alan Cox, Andrzej Krzysztofowicz, Jeff Garzik");
262 MODULE_DESCRIPTION("SCSI low-level driver for Intel PIIX/ICH ATA controllers");
263 MODULE_LICENSE("GPL");
264 MODULE_DEVICE_TABLE(pci, piix_pci_tbl);
265 MODULE_VERSION(DRV_VERSION);
266
267 /**
268  *      piix_pata_cbl_detect - Probe host controller cable detect info
269  *      @ap: Port for which cable detect info is desired
270  *
271  *      Read 80c cable indicator from ATA PCI device's PCI config
272  *      register.  This register is normally set by firmware (BIOS).
273  *
274  *      LOCKING:
275  *      None (inherited from caller).
276  */
277 static void piix_pata_cbl_detect(struct ata_port *ap)
278 {
279         struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
280         u8 tmp, mask;
281
282         /* no 80c support in host controller? */
283         if ((ap->udma_mask & ~ATA_UDMA_MASK_40C) == 0)
284                 goto cbl40;
285
286         /* check BIOS cable detect results */
287         mask = ap->hard_port_no == 0 ? PIIX_80C_PRI : PIIX_80C_SEC;
288         pci_read_config_byte(pdev, PIIX_IOCFG, &tmp);
289         if ((tmp & mask) == 0)
290                 goto cbl40;
291
292         ap->cbl = ATA_CBL_PATA80;
293         return;
294
295 cbl40:
296         ap->cbl = ATA_CBL_PATA40;
297         ap->udma_mask &= ATA_UDMA_MASK_40C;
298 }
299
300 /**
301  *      piix_pata_phy_reset - Probe specified port on PATA host controller
302  *      @ap: Port to probe
303  *
304  *      Probe PATA phy.
305  *
306  *      LOCKING:
307  *      None (inherited from caller).
308  */
309
310 static void piix_pata_phy_reset(struct ata_port *ap)
311 {
312         struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
313
314         if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->hard_port_no])) {
315                 ata_port_disable(ap);
316                 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
317                 return;
318         }
319
320         piix_pata_cbl_detect(ap);
321
322         ata_port_probe(ap);
323
324         ata_bus_reset(ap);
325 }
326
327 /**
328  *      piix_sata_probe - Probe PCI device for present SATA devices
329  *      @ap: Port associated with the PCI device we wish to probe
330  *
331  *      Reads SATA PCI device's PCI config register Port Configuration
332  *      and Status (PCS) to determine port and device availability.
333  *
334  *      LOCKING:
335  *      None (inherited from caller).
336  *
337  *      RETURNS:
338  *      Non-zero if device detected, zero otherwise.
339  */
340 static int piix_sata_probe (struct ata_port *ap)
341 {
342         struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
343         int combined = (ap->flags & ATA_FLAG_SLAVE_POSS);
344         int orig_mask, mask, i;
345         u8 pcs;
346
347         mask = (PIIX_PORT_PRESENT << ap->hard_port_no) |
348                (PIIX_PORT_ENABLED << ap->hard_port_no);
349
350         pci_read_config_byte(pdev, ICH5_PCS, &pcs);
351         orig_mask = (int) pcs & 0xff;
352
353         /* TODO: this is vaguely wrong for ICH6 combined mode,
354          * where only two of the four SATA ports are mapped
355          * onto a single ATA channel.  It is also vaguely inaccurate
356          * for ICH5, which has only two ports.  However, this is ok,
357          * as further device presence detection code will handle
358          * any false positives produced here.
359          */
360
361         for (i = 0; i < 4; i++) {
362                 mask = (PIIX_PORT_PRESENT << i) | (PIIX_PORT_ENABLED << i);
363
364                 if ((orig_mask & mask) == mask)
365                         if (combined || (i == ap->hard_port_no))
366                                 return 1;
367         }
368
369         return 0;
370 }
371
372 /**
373  *      piix_sata_phy_reset - Probe specified port on SATA host controller
374  *      @ap: Port to probe
375  *
376  *      Probe SATA phy.
377  *
378  *      LOCKING:
379  *      None (inherited from caller).
380  */
381
382 static void piix_sata_phy_reset(struct ata_port *ap)
383 {
384         if (!piix_sata_probe(ap)) {
385                 ata_port_disable(ap);
386                 printk(KERN_INFO "ata%u: SATA port has no device.\n", ap->id);
387                 return;
388         }
389
390         ap->cbl = ATA_CBL_SATA;
391
392         ata_port_probe(ap);
393
394         ata_bus_reset(ap);
395 }
396
397 /**
398  *      piix_set_piomode - Initialize host controller PATA PIO timings
399  *      @ap: Port whose timings we are configuring
400  *      @adev: um
401  *      @pio: PIO mode, 0 - 4
402  *
403  *      Set PIO mode for device, in host controller PCI config space.
404  *
405  *      LOCKING:
406  *      None (inherited from caller).
407  */
408
409 static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev)
410 {
411         unsigned int pio        = adev->pio_mode - XFER_PIO_0;
412         struct pci_dev *dev     = to_pci_dev(ap->host_set->dev);
413         unsigned int is_slave   = (adev->devno != 0);
414         unsigned int master_port= ap->hard_port_no ? 0x42 : 0x40;
415         unsigned int slave_port = 0x44;
416         u16 master_data;
417         u8 slave_data;
418
419         static const     /* ISP  RTC */
420         u8 timings[][2] = { { 0, 0 },
421                             { 0, 0 },
422                             { 1, 0 },
423                             { 2, 1 },
424                             { 2, 3 }, };
425
426         pci_read_config_word(dev, master_port, &master_data);
427         if (is_slave) {
428                 master_data |= 0x4000;
429                 /* enable PPE, IE and TIME */
430                 master_data |= 0x0070;
431                 pci_read_config_byte(dev, slave_port, &slave_data);
432                 slave_data &= (ap->hard_port_no ? 0x0f : 0xf0);
433                 slave_data |=
434                         (timings[pio][0] << 2) |
435                         (timings[pio][1] << (ap->hard_port_no ? 4 : 0));
436         } else {
437                 master_data &= 0xccf8;
438                 /* enable PPE, IE and TIME */
439                 master_data |= 0x0007;
440                 master_data |=
441                         (timings[pio][0] << 12) |
442                         (timings[pio][1] << 8);
443         }
444         pci_write_config_word(dev, master_port, master_data);
445         if (is_slave)
446                 pci_write_config_byte(dev, slave_port, slave_data);
447 }
448
449 /**
450  *      piix_set_dmamode - Initialize host controller PATA PIO timings
451  *      @ap: Port whose timings we are configuring
452  *      @adev: um
453  *      @udma: udma mode, 0 - 6
454  *
455  *      Set UDMA mode for device, in host controller PCI config space.
456  *
457  *      LOCKING:
458  *      None (inherited from caller).
459  */
460
461 static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev)
462 {
463         unsigned int udma       = adev->dma_mode; /* FIXME: MWDMA too */
464         struct pci_dev *dev     = to_pci_dev(ap->host_set->dev);
465         u8 maslave              = ap->hard_port_no ? 0x42 : 0x40;
466         u8 speed                = udma;
467         unsigned int drive_dn   = (ap->hard_port_no ? 2 : 0) + adev->devno;
468         int a_speed             = 3 << (drive_dn * 4);
469         int u_flag              = 1 << drive_dn;
470         int v_flag              = 0x01 << drive_dn;
471         int w_flag              = 0x10 << drive_dn;
472         int u_speed             = 0;
473         int                     sitre;
474         u16                     reg4042, reg4a;
475         u8                      reg48, reg54, reg55;
476
477         pci_read_config_word(dev, maslave, &reg4042);
478         DPRINTK("reg4042 = 0x%04x\n", reg4042);
479         sitre = (reg4042 & 0x4000) ? 1 : 0;
480         pci_read_config_byte(dev, 0x48, &reg48);
481         pci_read_config_word(dev, 0x4a, &reg4a);
482         pci_read_config_byte(dev, 0x54, &reg54);
483         pci_read_config_byte(dev, 0x55, &reg55);
484
485         switch(speed) {
486                 case XFER_UDMA_4:
487                 case XFER_UDMA_2:       u_speed = 2 << (drive_dn * 4); break;
488                 case XFER_UDMA_6:
489                 case XFER_UDMA_5:
490                 case XFER_UDMA_3:
491                 case XFER_UDMA_1:       u_speed = 1 << (drive_dn * 4); break;
492                 case XFER_UDMA_0:       u_speed = 0 << (drive_dn * 4); break;
493                 case XFER_MW_DMA_2:
494                 case XFER_MW_DMA_1:     break;
495                 default:
496                         BUG();
497                         return;
498         }
499
500         if (speed >= XFER_UDMA_0) {
501                 if (!(reg48 & u_flag))
502                         pci_write_config_byte(dev, 0x48, reg48 | u_flag);
503                 if (speed == XFER_UDMA_5) {
504                         pci_write_config_byte(dev, 0x55, (u8) reg55|w_flag);
505                 } else {
506                         pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag);
507                 }
508                 if ((reg4a & a_speed) != u_speed)
509                         pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed);
510                 if (speed > XFER_UDMA_2) {
511                         if (!(reg54 & v_flag))
512                                 pci_write_config_byte(dev, 0x54, reg54 | v_flag);
513                 } else
514                         pci_write_config_byte(dev, 0x54, reg54 & ~v_flag);
515         } else {
516                 if (reg48 & u_flag)
517                         pci_write_config_byte(dev, 0x48, reg48 & ~u_flag);
518                 if (reg4a & a_speed)
519                         pci_write_config_word(dev, 0x4a, reg4a & ~a_speed);
520                 if (reg54 & v_flag)
521                         pci_write_config_byte(dev, 0x54, reg54 & ~v_flag);
522                 if (reg55 & w_flag)
523                         pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag);
524         }
525 }
526
527 /* move to PCI layer, integrate w/ MSI stuff */
528 static void pci_enable_intx(struct pci_dev *pdev)
529 {
530         u16 pci_command;
531
532         pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
533         if (pci_command & PCI_COMMAND_INTX_DISABLE) {
534                 pci_command &= ~PCI_COMMAND_INTX_DISABLE;
535                 pci_write_config_word(pdev, PCI_COMMAND, pci_command);
536         }
537 }
538
539 #define AHCI_PCI_BAR 5
540 #define AHCI_GLOBAL_CTL 0x04
541 #define AHCI_ENABLE (1 << 31)
542 static int piix_disable_ahci(struct pci_dev *pdev)
543 {
544         void *mmio;
545         unsigned long addr;
546         u32 tmp;
547         int rc = 0;
548
549         /* BUG: pci_enable_device has not yet been called.  This
550          * works because this device is usually set up by BIOS.
551          */
552
553         addr = pci_resource_start(pdev, AHCI_PCI_BAR);
554         if (!addr || !pci_resource_len(pdev, AHCI_PCI_BAR))
555                 return 0;
556         
557         mmio = ioremap(addr, 64);
558         if (!mmio)
559                 return -ENOMEM;
560         
561         tmp = readl(mmio + AHCI_GLOBAL_CTL);
562         if (tmp & AHCI_ENABLE) {
563                 tmp &= ~AHCI_ENABLE;
564                 writel(tmp, mmio + AHCI_GLOBAL_CTL);
565
566                 tmp = readl(mmio + AHCI_GLOBAL_CTL);
567                 if (tmp & AHCI_ENABLE)
568                         rc = -EIO;
569         }
570         
571         iounmap(mmio);
572         return rc;
573 }
574
575 /**
576  *      piix_init_one - Register PIIX ATA PCI device with kernel services
577  *      @pdev: PCI device to register
578  *      @ent: Entry in piix_pci_tbl matching with @pdev
579  *
580  *      Called from kernel PCI layer.  We probe for combined mode (sigh),
581  *      and then hand over control to libata, for it to do the rest.
582  *
583  *      LOCKING:
584  *      Inherited from PCI layer (may sleep).
585  *
586  *      RETURNS:
587  *      Zero on success, or -ERRNO value.
588  */
589
590 static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
591 {
592         static int printed_version;
593         struct ata_port_info *port_info[2];
594         unsigned int combined = 0, n_ports = 1;
595         unsigned int pata_chan = 0, sata_chan = 0;
596
597         if (!printed_version++)
598                 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
599
600         /* no hotplugging support (FIXME) */
601         if (!in_module_init)
602                 return -ENODEV;
603
604         port_info[0] = &piix_port_info[ent->driver_data];
605         port_info[1] = NULL;
606
607         if (port_info[0]->host_flags & PIIX_FLAG_AHCI) {
608                 int rc = piix_disable_ahci(pdev);
609                 if (rc)
610                         return rc;
611         }
612
613         if (port_info[0]->host_flags & PIIX_FLAG_COMBINED) {
614                 u8 tmp;
615                 pci_read_config_byte(pdev, ICH5_PMR, &tmp);
616
617                 if (tmp & PIIX_COMB) {
618                         combined = 1;
619                         if (tmp & PIIX_COMB_PATA_P0)
620                                 sata_chan = 1;
621                         else
622                                 pata_chan = 1;
623                 }
624         }
625
626         /* On ICH5, some BIOSen disable the interrupt using the
627          * PCI_COMMAND_INTX_DISABLE bit added in PCI 2.3.
628          * On ICH6, this bit has the same effect, but only when
629          * MSI is disabled (and it is disabled, as we don't use
630          * message-signalled interrupts currently).
631          */
632         if (port_info[0]->host_flags & PIIX_FLAG_CHECKINTR)
633                 pci_enable_intx(pdev);
634
635         if (combined) {
636                 port_info[sata_chan] = &piix_port_info[ent->driver_data];
637                 port_info[sata_chan]->host_flags |= ATA_FLAG_SLAVE_POSS;
638                 port_info[pata_chan] = &piix_port_info[ich5_pata];
639                 n_ports++;
640
641                 printk(KERN_WARNING DRV_NAME ": combined mode detected\n");
642         }
643
644         return ata_pci_init_one(pdev, port_info, n_ports);
645 }
646
647 /**
648  *      piix_init -
649  *
650  *      LOCKING:
651  *
652  *      RETURNS:
653  *
654  */
655
656 static int __init piix_init(void)
657 {
658         int rc;
659
660         DPRINTK("pci_module_init\n");
661         rc = pci_module_init(&piix_pci_driver);
662         if (rc)
663                 return rc;
664
665         in_module_init = 0;
666
667         DPRINTK("done\n");
668         return 0;
669 }
670
671 /**
672  *      piix_exit -
673  *
674  *      LOCKING:
675  *
676  */
677
678 static void __exit piix_exit(void)
679 {
680         pci_unregister_driver(&piix_pci_driver);
681 }
682
683 module_init(piix_init);
684 module_exit(piix_exit);
685