[libata sata_nv] cleanups: convert #defines to enums; remove in-file history
[sfrench/cifs-2.6.git] / drivers / scsi / sata_nv.c
1 /*
2  *  sata_nv.c - NVIDIA nForce SATA
3  *
4  *  Copyright 2004 NVIDIA Corp.  All rights reserved.
5  *  Copyright 2004 Andrew Chew
6  *
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2, or (at your option)
11  *  any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; see the file COPYING.  If not, write to
20  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  *
23  *  libata documentation is available via 'make {ps|pdf}docs',
24  *  as Documentation/DocBook/libata.*
25  *
26  *  No hardware documentation available outside of NVIDIA.
27  *  This driver programs the NVIDIA SATA controller in a similar
28  *  fashion as with other PCI IDE BMDMA controllers, with a few
29  *  NV-specific details such as register offsets, SATA phy location,
30  *  hotplug info, etc.
31  *
32  */
33
34 #include <linux/config.h>
35 #include <linux/kernel.h>
36 #include <linux/module.h>
37 #include <linux/pci.h>
38 #include <linux/init.h>
39 #include <linux/blkdev.h>
40 #include <linux/delay.h>
41 #include <linux/interrupt.h>
42 #include <linux/device.h>
43 #include <scsi/scsi_host.h>
44 #include <linux/libata.h>
45
46 #define DRV_NAME                        "sata_nv"
47 #define DRV_VERSION                     "0.8"
48
49 enum {
50         NV_PORTS                        = 2,
51         NV_PIO_MASK                     = 0x1f,
52         NV_MWDMA_MASK                   = 0x07,
53         NV_UDMA_MASK                    = 0x7f,
54         NV_PORT0_SCR_REG_OFFSET         = 0x00,
55         NV_PORT1_SCR_REG_OFFSET         = 0x40,
56
57         NV_INT_STATUS                   = 0x10,
58         NV_INT_STATUS_CK804             = 0x440,
59         NV_INT_STATUS_PDEV_INT          = 0x01,
60         NV_INT_STATUS_PDEV_PM           = 0x02,
61         NV_INT_STATUS_PDEV_ADDED        = 0x04,
62         NV_INT_STATUS_PDEV_REMOVED      = 0x08,
63         NV_INT_STATUS_SDEV_INT          = 0x10,
64         NV_INT_STATUS_SDEV_PM           = 0x20,
65         NV_INT_STATUS_SDEV_ADDED        = 0x40,
66         NV_INT_STATUS_SDEV_REMOVED      = 0x80,
67         NV_INT_STATUS_PDEV_HOTPLUG      = (NV_INT_STATUS_PDEV_ADDED |
68                                            NV_INT_STATUS_PDEV_REMOVED),
69         NV_INT_STATUS_SDEV_HOTPLUG      = (NV_INT_STATUS_SDEV_ADDED |
70                                            NV_INT_STATUS_SDEV_REMOVED),
71         NV_INT_STATUS_HOTPLUG           = (NV_INT_STATUS_PDEV_HOTPLUG |
72                                            NV_INT_STATUS_SDEV_HOTPLUG),
73
74         NV_INT_ENABLE                   = 0x11,
75         NV_INT_ENABLE_CK804             = 0x441,
76         NV_INT_ENABLE_PDEV_MASK         = 0x01,
77         NV_INT_ENABLE_PDEV_PM           = 0x02,
78         NV_INT_ENABLE_PDEV_ADDED        = 0x04,
79         NV_INT_ENABLE_PDEV_REMOVED      = 0x08,
80         NV_INT_ENABLE_SDEV_MASK         = 0x10,
81         NV_INT_ENABLE_SDEV_PM           = 0x20,
82         NV_INT_ENABLE_SDEV_ADDED        = 0x40,
83         NV_INT_ENABLE_SDEV_REMOVED      = 0x80,
84         NV_INT_ENABLE_PDEV_HOTPLUG      = (NV_INT_ENABLE_PDEV_ADDED |
85                                            NV_INT_ENABLE_PDEV_REMOVED),
86         NV_INT_ENABLE_SDEV_HOTPLUG      = (NV_INT_ENABLE_SDEV_ADDED |
87                                            NV_INT_ENABLE_SDEV_REMOVED),
88         NV_INT_ENABLE_HOTPLUG           = (NV_INT_ENABLE_PDEV_HOTPLUG |
89                                            NV_INT_ENABLE_SDEV_HOTPLUG),
90
91         NV_INT_CONFIG                   = 0x12,
92         NV_INT_CONFIG_METHD             = 0x01, // 0 = INT, 1 = SMI
93
94         // For PCI config register 20
95         NV_MCP_SATA_CFG_20              = 0x50,
96         NV_MCP_SATA_CFG_20_SATA_SPACE_EN = 0x04,
97 };
98
99 static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
100 static irqreturn_t nv_interrupt (int irq, void *dev_instance,
101                                  struct pt_regs *regs);
102 static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg);
103 static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
104 static void nv_host_stop (struct ata_host_set *host_set);
105 static void nv_enable_hotplug(struct ata_probe_ent *probe_ent);
106 static void nv_disable_hotplug(struct ata_host_set *host_set);
107 static int nv_check_hotplug(struct ata_host_set *host_set);
108 static void nv_enable_hotplug_ck804(struct ata_probe_ent *probe_ent);
109 static void nv_disable_hotplug_ck804(struct ata_host_set *host_set);
110 static int nv_check_hotplug_ck804(struct ata_host_set *host_set);
111
112 enum nv_host_type
113 {
114         GENERIC,
115         NFORCE2,
116         NFORCE3,
117         CK804
118 };
119
120 static const struct pci_device_id nv_pci_tbl[] = {
121         { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA,
122                 PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE2 },
123         { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA,
124                 PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE3 },
125         { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2,
126                 PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE3 },
127         { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA,
128                 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
129         { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA2,
130                 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
131         { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA,
132                 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
133         { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA2,
134                 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
135         { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA,
136                 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
137         { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA2,
138                 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
139         { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA,
140                 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
141         { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA2,
142                 PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
143         { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
144                 PCI_ANY_ID, PCI_ANY_ID,
145                 PCI_CLASS_STORAGE_IDE<<8, 0xffff00, GENERIC },
146         { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
147                 PCI_ANY_ID, PCI_ANY_ID,
148                 PCI_CLASS_STORAGE_RAID<<8, 0xffff00, GENERIC },
149         { 0, } /* terminate list */
150 };
151
152 #define NV_HOST_FLAGS_SCR_MMIO  0x00000001
153
154 struct nv_host_desc
155 {
156         enum nv_host_type       host_type;
157         void                    (*enable_hotplug)(struct ata_probe_ent *probe_ent);
158         void                    (*disable_hotplug)(struct ata_host_set *host_set);
159         int                     (*check_hotplug)(struct ata_host_set *host_set);
160
161 };
162 static struct nv_host_desc nv_device_tbl[] = {
163         {
164                 .host_type      = GENERIC,
165                 .enable_hotplug = NULL,
166                 .disable_hotplug= NULL,
167                 .check_hotplug  = NULL,
168         },
169         {
170                 .host_type      = NFORCE2,
171                 .enable_hotplug = nv_enable_hotplug,
172                 .disable_hotplug= nv_disable_hotplug,
173                 .check_hotplug  = nv_check_hotplug,
174         },
175         {
176                 .host_type      = NFORCE3,
177                 .enable_hotplug = nv_enable_hotplug,
178                 .disable_hotplug= nv_disable_hotplug,
179                 .check_hotplug  = nv_check_hotplug,
180         },
181         {       .host_type      = CK804,
182                 .enable_hotplug = nv_enable_hotplug_ck804,
183                 .disable_hotplug= nv_disable_hotplug_ck804,
184                 .check_hotplug  = nv_check_hotplug_ck804,
185         },
186 };
187
188 struct nv_host
189 {
190         struct nv_host_desc     *host_desc;
191         unsigned long           host_flags;
192 };
193
194 static struct pci_driver nv_pci_driver = {
195         .name                   = DRV_NAME,
196         .id_table               = nv_pci_tbl,
197         .probe                  = nv_init_one,
198         .remove                 = ata_pci_remove_one,
199 };
200
201 static struct scsi_host_template nv_sht = {
202         .module                 = THIS_MODULE,
203         .name                   = DRV_NAME,
204         .ioctl                  = ata_scsi_ioctl,
205         .queuecommand           = ata_scsi_queuecmd,
206         .eh_strategy_handler    = ata_scsi_error,
207         .can_queue              = ATA_DEF_QUEUE,
208         .this_id                = ATA_SHT_THIS_ID,
209         .sg_tablesize           = LIBATA_MAX_PRD,
210         .cmd_per_lun            = ATA_SHT_CMD_PER_LUN,
211         .emulated               = ATA_SHT_EMULATED,
212         .use_clustering         = ATA_SHT_USE_CLUSTERING,
213         .proc_name              = DRV_NAME,
214         .dma_boundary           = ATA_DMA_BOUNDARY,
215         .slave_configure        = ata_scsi_slave_config,
216         .bios_param             = ata_std_bios_param,
217 };
218
219 static const struct ata_port_operations nv_ops = {
220         .port_disable           = ata_port_disable,
221         .tf_load                = ata_tf_load,
222         .tf_read                = ata_tf_read,
223         .exec_command           = ata_exec_command,
224         .check_status           = ata_check_status,
225         .dev_select             = ata_std_dev_select,
226         .phy_reset              = sata_phy_reset,
227         .bmdma_setup            = ata_bmdma_setup,
228         .bmdma_start            = ata_bmdma_start,
229         .bmdma_stop             = ata_bmdma_stop,
230         .bmdma_status           = ata_bmdma_status,
231         .qc_prep                = ata_qc_prep,
232         .qc_issue               = ata_qc_issue_prot,
233         .eng_timeout            = ata_eng_timeout,
234         .irq_handler            = nv_interrupt,
235         .irq_clear              = ata_bmdma_irq_clear,
236         .scr_read               = nv_scr_read,
237         .scr_write              = nv_scr_write,
238         .port_start             = ata_port_start,
239         .port_stop              = ata_port_stop,
240         .host_stop              = nv_host_stop,
241 };
242
243 /* FIXME: The hardware provides the necessary SATA PHY controls
244  * to support ATA_FLAG_SATA_RESET.  However, it is currently
245  * necessary to disable that flag, to solve misdetection problems.
246  * See http://bugme.osdl.org/show_bug.cgi?id=3352 for more info.
247  *
248  * This problem really needs to be investigated further.  But in the
249  * meantime, we avoid ATA_FLAG_SATA_RESET to get people working.
250  */
251 static struct ata_port_info nv_port_info = {
252         .sht            = &nv_sht,
253         .host_flags     = ATA_FLAG_SATA |
254                           /* ATA_FLAG_SATA_RESET | */
255                           ATA_FLAG_SRST |
256                           ATA_FLAG_NO_LEGACY,
257         .pio_mask       = NV_PIO_MASK,
258         .mwdma_mask     = NV_MWDMA_MASK,
259         .udma_mask      = NV_UDMA_MASK,
260         .port_ops       = &nv_ops,
261 };
262
263 MODULE_AUTHOR("NVIDIA");
264 MODULE_DESCRIPTION("low-level driver for NVIDIA nForce SATA controller");
265 MODULE_LICENSE("GPL");
266 MODULE_DEVICE_TABLE(pci, nv_pci_tbl);
267 MODULE_VERSION(DRV_VERSION);
268
269 static irqreturn_t nv_interrupt (int irq, void *dev_instance,
270                                  struct pt_regs *regs)
271 {
272         struct ata_host_set *host_set = dev_instance;
273         struct nv_host *host = host_set->private_data;
274         unsigned int i;
275         unsigned int handled = 0;
276         unsigned long flags;
277
278         spin_lock_irqsave(&host_set->lock, flags);
279
280         for (i = 0; i < host_set->n_ports; i++) {
281                 struct ata_port *ap;
282
283                 ap = host_set->ports[i];
284                 if (ap &&
285                     !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) {
286                         struct ata_queued_cmd *qc;
287
288                         qc = ata_qc_from_tag(ap, ap->active_tag);
289                         if (qc && (!(qc->tf.ctl & ATA_NIEN)))
290                                 handled += ata_host_intr(ap, qc);
291                         else
292                                 // No request pending?  Clear interrupt status
293                                 // anyway, in case there's one pending.
294                                 ap->ops->check_status(ap);
295                 }
296
297         }
298
299         if (host->host_desc->check_hotplug)
300                 handled += host->host_desc->check_hotplug(host_set);
301
302         spin_unlock_irqrestore(&host_set->lock, flags);
303
304         return IRQ_RETVAL(handled);
305 }
306
307 static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg)
308 {
309         struct ata_host_set *host_set = ap->host_set;
310         struct nv_host *host = host_set->private_data;
311
312         if (sc_reg > SCR_CONTROL)
313                 return 0xffffffffU;
314
315         if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO)
316                 return readl((void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
317         else
318                 return inl(ap->ioaddr.scr_addr + (sc_reg * 4));
319 }
320
321 static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
322 {
323         struct ata_host_set *host_set = ap->host_set;
324         struct nv_host *host = host_set->private_data;
325
326         if (sc_reg > SCR_CONTROL)
327                 return;
328
329         if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO)
330                 writel(val, (void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
331         else
332                 outl(val, ap->ioaddr.scr_addr + (sc_reg * 4));
333 }
334
335 static void nv_host_stop (struct ata_host_set *host_set)
336 {
337         struct nv_host *host = host_set->private_data;
338         struct pci_dev *pdev = to_pci_dev(host_set->dev);
339
340         // Disable hotplug event interrupts.
341         if (host->host_desc->disable_hotplug)
342                 host->host_desc->disable_hotplug(host_set);
343
344         kfree(host);
345
346         if (host_set->mmio_base)
347                 pci_iounmap(pdev, host_set->mmio_base);
348 }
349
350 static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
351 {
352         static int printed_version = 0;
353         struct nv_host *host;
354         struct ata_port_info *ppi;
355         struct ata_probe_ent *probe_ent;
356         int pci_dev_busy = 0;
357         int rc;
358         u32 bar;
359
360         // Make sure this is a SATA controller by counting the number of bars
361         // (NVIDIA SATA controllers will always have six bars).  Otherwise,
362         // it's an IDE controller and we ignore it.
363         for (bar=0; bar<6; bar++)
364                 if (pci_resource_start(pdev, bar) == 0)
365                         return -ENODEV;
366
367         if (!printed_version++)
368                 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
369
370         rc = pci_enable_device(pdev);
371         if (rc)
372                 goto err_out;
373
374         rc = pci_request_regions(pdev, DRV_NAME);
375         if (rc) {
376                 pci_dev_busy = 1;
377                 goto err_out_disable;
378         }
379
380         rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
381         if (rc)
382                 goto err_out_regions;
383         rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
384         if (rc)
385                 goto err_out_regions;
386
387         rc = -ENOMEM;
388
389         ppi = &nv_port_info;
390         probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
391         if (!probe_ent)
392                 goto err_out_regions;
393
394         host = kmalloc(sizeof(struct nv_host), GFP_KERNEL);
395         if (!host)
396                 goto err_out_free_ent;
397
398         memset(host, 0, sizeof(struct nv_host));
399         host->host_desc = &nv_device_tbl[ent->driver_data];
400
401         probe_ent->private_data = host;
402
403         if (pci_resource_flags(pdev, 5) & IORESOURCE_MEM)
404                 host->host_flags |= NV_HOST_FLAGS_SCR_MMIO;
405
406         if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO) {
407                 unsigned long base;
408
409                 probe_ent->mmio_base = pci_iomap(pdev, 5, 0);
410                 if (probe_ent->mmio_base == NULL) {
411                         rc = -EIO;
412                         goto err_out_free_host;
413                 }
414
415                 base = (unsigned long)probe_ent->mmio_base;
416
417                 probe_ent->port[0].scr_addr =
418                         base + NV_PORT0_SCR_REG_OFFSET;
419                 probe_ent->port[1].scr_addr =
420                         base + NV_PORT1_SCR_REG_OFFSET;
421         } else {
422
423                 probe_ent->port[0].scr_addr =
424                         pci_resource_start(pdev, 5) | NV_PORT0_SCR_REG_OFFSET;
425                 probe_ent->port[1].scr_addr =
426                         pci_resource_start(pdev, 5) | NV_PORT1_SCR_REG_OFFSET;
427         }
428
429         pci_set_master(pdev);
430
431         rc = ata_device_add(probe_ent);
432         if (rc != NV_PORTS)
433                 goto err_out_iounmap;
434
435         // Enable hotplug event interrupts.
436         if (host->host_desc->enable_hotplug)
437                 host->host_desc->enable_hotplug(probe_ent);
438
439         kfree(probe_ent);
440
441         return 0;
442
443 err_out_iounmap:
444         if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO)
445                 pci_iounmap(pdev, probe_ent->mmio_base);
446 err_out_free_host:
447         kfree(host);
448 err_out_free_ent:
449         kfree(probe_ent);
450 err_out_regions:
451         pci_release_regions(pdev);
452 err_out_disable:
453         if (!pci_dev_busy)
454                 pci_disable_device(pdev);
455 err_out:
456         return rc;
457 }
458
459 static void nv_enable_hotplug(struct ata_probe_ent *probe_ent)
460 {
461         u8 intr_mask;
462
463         outb(NV_INT_STATUS_HOTPLUG,
464                 probe_ent->port[0].scr_addr + NV_INT_STATUS);
465
466         intr_mask = inb(probe_ent->port[0].scr_addr + NV_INT_ENABLE);
467         intr_mask |= NV_INT_ENABLE_HOTPLUG;
468
469         outb(intr_mask, probe_ent->port[0].scr_addr + NV_INT_ENABLE);
470 }
471
472 static void nv_disable_hotplug(struct ata_host_set *host_set)
473 {
474         u8 intr_mask;
475
476         intr_mask = inb(host_set->ports[0]->ioaddr.scr_addr + NV_INT_ENABLE);
477
478         intr_mask &= ~(NV_INT_ENABLE_HOTPLUG);
479
480         outb(intr_mask, host_set->ports[0]->ioaddr.scr_addr + NV_INT_ENABLE);
481 }
482
483 static int nv_check_hotplug(struct ata_host_set *host_set)
484 {
485         u8 intr_status;
486
487         intr_status = inb(host_set->ports[0]->ioaddr.scr_addr + NV_INT_STATUS);
488
489         // Clear interrupt status.
490         outb(0xff, host_set->ports[0]->ioaddr.scr_addr + NV_INT_STATUS);
491
492         if (intr_status & NV_INT_STATUS_HOTPLUG) {
493                 if (intr_status & NV_INT_STATUS_PDEV_ADDED)
494                         printk(KERN_WARNING "nv_sata: "
495                                 "Primary device added\n");
496
497                 if (intr_status & NV_INT_STATUS_PDEV_REMOVED)
498                         printk(KERN_WARNING "nv_sata: "
499                                 "Primary device removed\n");
500
501                 if (intr_status & NV_INT_STATUS_SDEV_ADDED)
502                         printk(KERN_WARNING "nv_sata: "
503                                 "Secondary device added\n");
504
505                 if (intr_status & NV_INT_STATUS_SDEV_REMOVED)
506                         printk(KERN_WARNING "nv_sata: "
507                                 "Secondary device removed\n");
508
509                 return 1;
510         }
511
512         return 0;
513 }
514
515 static void nv_enable_hotplug_ck804(struct ata_probe_ent *probe_ent)
516 {
517         struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
518         u8 intr_mask;
519         u8 regval;
520
521         pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, &regval);
522         regval |= NV_MCP_SATA_CFG_20_SATA_SPACE_EN;
523         pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval);
524
525         writeb(NV_INT_STATUS_HOTPLUG, probe_ent->mmio_base + NV_INT_STATUS_CK804);
526
527         intr_mask = readb(probe_ent->mmio_base + NV_INT_ENABLE_CK804);
528         intr_mask |= NV_INT_ENABLE_HOTPLUG;
529
530         writeb(intr_mask, probe_ent->mmio_base + NV_INT_ENABLE_CK804);
531 }
532
533 static void nv_disable_hotplug_ck804(struct ata_host_set *host_set)
534 {
535         struct pci_dev *pdev = to_pci_dev(host_set->dev);
536         u8 intr_mask;
537         u8 regval;
538
539         intr_mask = readb(host_set->mmio_base + NV_INT_ENABLE_CK804);
540
541         intr_mask &= ~(NV_INT_ENABLE_HOTPLUG);
542
543         writeb(intr_mask, host_set->mmio_base + NV_INT_ENABLE_CK804);
544
545         pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, &regval);
546         regval &= ~NV_MCP_SATA_CFG_20_SATA_SPACE_EN;
547         pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval);
548 }
549
550 static int nv_check_hotplug_ck804(struct ata_host_set *host_set)
551 {
552         u8 intr_status;
553
554         intr_status = readb(host_set->mmio_base + NV_INT_STATUS_CK804);
555
556         // Clear interrupt status.
557         writeb(0xff, host_set->mmio_base + NV_INT_STATUS_CK804);
558
559         if (intr_status & NV_INT_STATUS_HOTPLUG) {
560                 if (intr_status & NV_INT_STATUS_PDEV_ADDED)
561                         printk(KERN_WARNING "nv_sata: "
562                                 "Primary device added\n");
563
564                 if (intr_status & NV_INT_STATUS_PDEV_REMOVED)
565                         printk(KERN_WARNING "nv_sata: "
566                                 "Primary device removed\n");
567
568                 if (intr_status & NV_INT_STATUS_SDEV_ADDED)
569                         printk(KERN_WARNING "nv_sata: "
570                                 "Secondary device added\n");
571
572                 if (intr_status & NV_INT_STATUS_SDEV_REMOVED)
573                         printk(KERN_WARNING "nv_sata: "
574                                 "Secondary device removed\n");
575
576                 return 1;
577         }
578
579         return 0;
580 }
581
582 static int __init nv_init(void)
583 {
584         return pci_module_init(&nv_pci_driver);
585 }
586
587 static void __exit nv_exit(void)
588 {
589         pci_unregister_driver(&nv_pci_driver);
590 }
591
592 module_init(nv_init);
593 module_exit(nv_exit);