diff options
Diffstat (limited to 'drivers/ata/sata_nv.c')
| -rw-r--r-- | drivers/ata/sata_nv.c | 595 |
1 files changed, 595 insertions, 0 deletions
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c new file mode 100644 index 0000000000..be46df75ab --- /dev/null +++ b/drivers/ata/sata_nv.c | |||
| @@ -0,0 +1,595 @@ | |||
| 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/kernel.h> | ||
| 35 | #include <linux/module.h> | ||
| 36 | #include <linux/pci.h> | ||
| 37 | #include <linux/init.h> | ||
| 38 | #include <linux/blkdev.h> | ||
| 39 | #include <linux/delay.h> | ||
| 40 | #include <linux/interrupt.h> | ||
| 41 | #include <linux/device.h> | ||
| 42 | #include <scsi/scsi_host.h> | ||
| 43 | #include <linux/libata.h> | ||
| 44 | |||
| 45 | #define DRV_NAME "sata_nv" | ||
| 46 | #define DRV_VERSION "2.0" | ||
| 47 | |||
| 48 | enum { | ||
| 49 | NV_PORTS = 2, | ||
| 50 | NV_PIO_MASK = 0x1f, | ||
| 51 | NV_MWDMA_MASK = 0x07, | ||
| 52 | NV_UDMA_MASK = 0x7f, | ||
| 53 | NV_PORT0_SCR_REG_OFFSET = 0x00, | ||
| 54 | NV_PORT1_SCR_REG_OFFSET = 0x40, | ||
| 55 | |||
| 56 | /* INT_STATUS/ENABLE */ | ||
| 57 | NV_INT_STATUS = 0x10, | ||
| 58 | NV_INT_ENABLE = 0x11, | ||
| 59 | NV_INT_STATUS_CK804 = 0x440, | ||
| 60 | NV_INT_ENABLE_CK804 = 0x441, | ||
| 61 | |||
| 62 | /* INT_STATUS/ENABLE bits */ | ||
| 63 | NV_INT_DEV = 0x01, | ||
| 64 | NV_INT_PM = 0x02, | ||
| 65 | NV_INT_ADDED = 0x04, | ||
| 66 | NV_INT_REMOVED = 0x08, | ||
| 67 | |||
| 68 | NV_INT_PORT_SHIFT = 4, /* each port occupies 4 bits */ | ||
| 69 | |||
| 70 | NV_INT_ALL = 0x0f, | ||
| 71 | NV_INT_MASK = NV_INT_DEV | | ||
| 72 | NV_INT_ADDED | NV_INT_REMOVED, | ||
| 73 | |||
| 74 | /* INT_CONFIG */ | ||
| 75 | NV_INT_CONFIG = 0x12, | ||
| 76 | NV_INT_CONFIG_METHD = 0x01, // 0 = INT, 1 = SMI | ||
| 77 | |||
| 78 | // For PCI config register 20 | ||
| 79 | NV_MCP_SATA_CFG_20 = 0x50, | ||
| 80 | NV_MCP_SATA_CFG_20_SATA_SPACE_EN = 0x04, | ||
| 81 | }; | ||
| 82 | |||
| 83 | static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); | ||
| 84 | static void nv_ck804_host_stop(struct ata_host_set *host_set); | ||
| 85 | static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance, | ||
| 86 | struct pt_regs *regs); | ||
| 87 | static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance, | ||
| 88 | struct pt_regs *regs); | ||
| 89 | static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance, | ||
| 90 | struct pt_regs *regs); | ||
| 91 | static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg); | ||
| 92 | static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); | ||
| 93 | |||
| 94 | static void nv_nf2_freeze(struct ata_port *ap); | ||
| 95 | static void nv_nf2_thaw(struct ata_port *ap); | ||
| 96 | static void nv_ck804_freeze(struct ata_port *ap); | ||
| 97 | static void nv_ck804_thaw(struct ata_port *ap); | ||
| 98 | static void nv_error_handler(struct ata_port *ap); | ||
| 99 | |||
| 100 | enum nv_host_type | ||
| 101 | { | ||
| 102 | GENERIC, | ||
| 103 | NFORCE2, | ||
| 104 | NFORCE3 = NFORCE2, /* NF2 == NF3 as far as sata_nv is concerned */ | ||
| 105 | CK804 | ||
| 106 | }; | ||
| 107 | |||
| 108 | static const struct pci_device_id nv_pci_tbl[] = { | ||
| 109 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA, | ||
| 110 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE2 }, | ||
| 111 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA, | ||
| 112 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE3 }, | ||
| 113 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2, | ||
| 114 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE3 }, | ||
| 115 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA, | ||
| 116 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 }, | ||
| 117 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA2, | ||
| 118 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 }, | ||
| 119 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA, | ||
| 120 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 }, | ||
| 121 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA2, | ||
| 122 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 }, | ||
| 123 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA, | ||
| 124 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC }, | ||
| 125 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA2, | ||
| 126 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC }, | ||
| 127 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA, | ||
| 128 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC }, | ||
| 129 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA2, | ||
| 130 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC }, | ||
| 131 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA, | ||
| 132 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC }, | ||
| 133 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2, | ||
| 134 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC }, | ||
| 135 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3, | ||
| 136 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC }, | ||
| 137 | { PCI_VENDOR_ID_NVIDIA, 0x045c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC }, | ||
| 138 | { PCI_VENDOR_ID_NVIDIA, 0x045d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC }, | ||
| 139 | { PCI_VENDOR_ID_NVIDIA, 0x045e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC }, | ||
| 140 | { PCI_VENDOR_ID_NVIDIA, 0x045f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC }, | ||
| 141 | { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, | ||
| 142 | PCI_ANY_ID, PCI_ANY_ID, | ||
| 143 | PCI_CLASS_STORAGE_IDE<<8, 0xffff00, GENERIC }, | ||
| 144 | { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, | ||
| 145 | PCI_ANY_ID, PCI_ANY_ID, | ||
| 146 | PCI_CLASS_STORAGE_RAID<<8, 0xffff00, GENERIC }, | ||
| 147 | { 0, } /* terminate list */ | ||
| 148 | }; | ||
| 149 | |||
| 150 | static struct pci_driver nv_pci_driver = { | ||
| 151 | .name = DRV_NAME, | ||
| 152 | .id_table = nv_pci_tbl, | ||
| 153 | .probe = nv_init_one, | ||
| 154 | .remove = ata_pci_remove_one, | ||
| 155 | }; | ||
| 156 | |||
| 157 | static struct scsi_host_template nv_sht = { | ||
| 158 | .module = THIS_MODULE, | ||
| 159 | .name = DRV_NAME, | ||
| 160 | .ioctl = ata_scsi_ioctl, | ||
| 161 | .queuecommand = ata_scsi_queuecmd, | ||
| 162 | .can_queue = ATA_DEF_QUEUE, | ||
| 163 | .this_id = ATA_SHT_THIS_ID, | ||
| 164 | .sg_tablesize = LIBATA_MAX_PRD, | ||
| 165 | .cmd_per_lun = ATA_SHT_CMD_PER_LUN, | ||
| 166 | .emulated = ATA_SHT_EMULATED, | ||
| 167 | .use_clustering = ATA_SHT_USE_CLUSTERING, | ||
| 168 | .proc_name = DRV_NAME, | ||
| 169 | .dma_boundary = ATA_DMA_BOUNDARY, | ||
| 170 | .slave_configure = ata_scsi_slave_config, | ||
| 171 | .slave_destroy = ata_scsi_slave_destroy, | ||
| 172 | .bios_param = ata_std_bios_param, | ||
| 173 | }; | ||
| 174 | |||
| 175 | static const struct ata_port_operations nv_generic_ops = { | ||
| 176 | .port_disable = ata_port_disable, | ||
| 177 | .tf_load = ata_tf_load, | ||
| 178 | .tf_read = ata_tf_read, | ||
| 179 | .exec_command = ata_exec_command, | ||
| 180 | .check_status = ata_check_status, | ||
| 181 | .dev_select = ata_std_dev_select, | ||
| 182 | .bmdma_setup = ata_bmdma_setup, | ||
| 183 | .bmdma_start = ata_bmdma_start, | ||
| 184 | .bmdma_stop = ata_bmdma_stop, | ||
| 185 | .bmdma_status = ata_bmdma_status, | ||
| 186 | .qc_prep = ata_qc_prep, | ||
| 187 | .qc_issue = ata_qc_issue_prot, | ||
| 188 | .freeze = ata_bmdma_freeze, | ||
| 189 | .thaw = ata_bmdma_thaw, | ||
| 190 | .error_handler = nv_error_handler, | ||
| 191 | .post_internal_cmd = ata_bmdma_post_internal_cmd, | ||
| 192 | .data_xfer = ata_pio_data_xfer, | ||
| 193 | .irq_handler = nv_generic_interrupt, | ||
| 194 | .irq_clear = ata_bmdma_irq_clear, | ||
| 195 | .scr_read = nv_scr_read, | ||
| 196 | .scr_write = nv_scr_write, | ||
| 197 | .port_start = ata_port_start, | ||
| 198 | .port_stop = ata_port_stop, | ||
| 199 | .host_stop = ata_pci_host_stop, | ||
| 200 | }; | ||
| 201 | |||
| 202 | static const struct ata_port_operations nv_nf2_ops = { | ||
| 203 | .port_disable = ata_port_disable, | ||
| 204 | .tf_load = ata_tf_load, | ||
| 205 | .tf_read = ata_tf_read, | ||
| 206 | .exec_command = ata_exec_command, | ||
| 207 | .check_status = ata_check_status, | ||
| 208 | .dev_select = ata_std_dev_select, | ||
| 209 | .bmdma_setup = ata_bmdma_setup, | ||
| 210 | .bmdma_start = ata_bmdma_start, | ||
| 211 | .bmdma_stop = ata_bmdma_stop, | ||
| 212 | .bmdma_status = ata_bmdma_status, | ||
| 213 | .qc_prep = ata_qc_prep, | ||
| 214 | .qc_issue = ata_qc_issue_prot, | ||
| 215 | .freeze = nv_nf2_freeze, | ||
| 216 | .thaw = nv_nf2_thaw, | ||
| 217 | .error_handler = nv_error_handler, | ||
| 218 | .post_internal_cmd = ata_bmdma_post_internal_cmd, | ||
| 219 | .data_xfer = ata_pio_data_xfer, | ||
| 220 | .irq_handler = nv_nf2_interrupt, | ||
| 221 | .irq_clear = ata_bmdma_irq_clear, | ||
| 222 | .scr_read = nv_scr_read, | ||
| 223 | .scr_write = nv_scr_write, | ||
| 224 | .port_start = ata_port_start, | ||
| 225 | .port_stop = ata_port_stop, | ||
| 226 | .host_stop = ata_pci_host_stop, | ||
| 227 | }; | ||
| 228 | |||
| 229 | static const struct ata_port_operations nv_ck804_ops = { | ||
| 230 | .port_disable = ata_port_disable, | ||
| 231 | .tf_load = ata_tf_load, | ||
| 232 | .tf_read = ata_tf_read, | ||
| 233 | .exec_command = ata_exec_command, | ||
| 234 | .check_status = ata_check_status, | ||
| 235 | .dev_select = ata_std_dev_select, | ||
| 236 | .bmdma_setup = ata_bmdma_setup, | ||
| 237 | .bmdma_start = ata_bmdma_start, | ||
| 238 | .bmdma_stop = ata_bmdma_stop, | ||
| 239 | .bmdma_status = ata_bmdma_status, | ||
| 240 | .qc_prep = ata_qc_prep, | ||
| 241 | .qc_issue = ata_qc_issue_prot, | ||
| 242 | .freeze = nv_ck804_freeze, | ||
| 243 | .thaw = nv_ck804_thaw, | ||
| 244 | .error_handler = nv_error_handler, | ||
| 245 | .post_internal_cmd = ata_bmdma_post_internal_cmd, | ||
| 246 | .data_xfer = ata_pio_data_xfer, | ||
| 247 | .irq_handler = nv_ck804_interrupt, | ||
| 248 | .irq_clear = ata_bmdma_irq_clear, | ||
| 249 | .scr_read = nv_scr_read, | ||
| 250 | .scr_write = nv_scr_write, | ||
| 251 | .port_start = ata_port_start, | ||
| 252 | .port_stop = ata_port_stop, | ||
| 253 | .host_stop = nv_ck804_host_stop, | ||
| 254 | }; | ||
| 255 | |||
| 256 | static struct ata_port_info nv_port_info[] = { | ||
| 257 | /* generic */ | ||
| 258 | { | ||
| 259 | .sht = &nv_sht, | ||
| 260 | .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, | ||
| 261 | .pio_mask = NV_PIO_MASK, | ||
| 262 | .mwdma_mask = NV_MWDMA_MASK, | ||
| 263 | .udma_mask = NV_UDMA_MASK, | ||
| 264 | .port_ops = &nv_generic_ops, | ||
| 265 | }, | ||
| 266 | /* nforce2/3 */ | ||
| 267 | { | ||
| 268 | .sht = &nv_sht, | ||
| 269 | .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, | ||
| 270 | .pio_mask = NV_PIO_MASK, | ||
| 271 | .mwdma_mask = NV_MWDMA_MASK, | ||
| 272 | .udma_mask = NV_UDMA_MASK, | ||
| 273 | .port_ops = &nv_nf2_ops, | ||
| 274 | }, | ||
| 275 | /* ck804 */ | ||
| 276 | { | ||
| 277 | .sht = &nv_sht, | ||
| 278 | .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, | ||
| 279 | .pio_mask = NV_PIO_MASK, | ||
| 280 | .mwdma_mask = NV_MWDMA_MASK, | ||
| 281 | .udma_mask = NV_UDMA_MASK, | ||
| 282 | .port_ops = &nv_ck804_ops, | ||
| 283 | }, | ||
| 284 | }; | ||
| 285 | |||
| 286 | MODULE_AUTHOR("NVIDIA"); | ||
| 287 | MODULE_DESCRIPTION("low-level driver for NVIDIA nForce SATA controller"); | ||
| 288 | MODULE_LICENSE("GPL"); | ||
| 289 | MODULE_DEVICE_TABLE(pci, nv_pci_tbl); | ||
| 290 | MODULE_VERSION(DRV_VERSION); | ||
| 291 | |||
| 292 | static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance, | ||
| 293 | struct pt_regs *regs) | ||
| 294 | { | ||
| 295 | struct ata_host_set *host_set = dev_instance; | ||
| 296 | unsigned int i; | ||
| 297 | unsigned int handled = 0; | ||
| 298 | unsigned long flags; | ||
| 299 | |||
| 300 | spin_lock_irqsave(&host_set->lock, flags); | ||
| 301 | |||
| 302 | for (i = 0; i < host_set->n_ports; i++) { | ||
| 303 | struct ata_port *ap; | ||
| 304 | |||
| 305 | ap = host_set->ports[i]; | ||
| 306 | if (ap && | ||
| 307 | !(ap->flags & ATA_FLAG_DISABLED)) { | ||
| 308 | struct ata_queued_cmd *qc; | ||
| 309 | |||
| 310 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
| 311 | if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) | ||
| 312 | handled += ata_host_intr(ap, qc); | ||
| 313 | else | ||
| 314 | // No request pending? Clear interrupt status | ||
| 315 | // anyway, in case there's one pending. | ||
| 316 | ap->ops->check_status(ap); | ||
| 317 | } | ||
| 318 | |||
| 319 | } | ||
| 320 | |||
| 321 | spin_unlock_irqrestore(&host_set->lock, flags); | ||
| 322 | |||
| 323 | return IRQ_RETVAL(handled); | ||
| 324 | } | ||
| 325 | |||
| 326 | static int nv_host_intr(struct ata_port *ap, u8 irq_stat) | ||
| 327 | { | ||
| 328 | struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag); | ||
| 329 | int handled; | ||
| 330 | |||
| 331 | /* freeze if hotplugged */ | ||
| 332 | if (unlikely(irq_stat & (NV_INT_ADDED | NV_INT_REMOVED))) { | ||
| 333 | ata_port_freeze(ap); | ||
| 334 | return 1; | ||
| 335 | } | ||
| 336 | |||
| 337 | /* bail out if not our interrupt */ | ||
| 338 | if (!(irq_stat & NV_INT_DEV)) | ||
| 339 | return 0; | ||
| 340 | |||
| 341 | /* DEV interrupt w/ no active qc? */ | ||
| 342 | if (unlikely(!qc || (qc->tf.flags & ATA_TFLAG_POLLING))) { | ||
| 343 | ata_check_status(ap); | ||
| 344 | return 1; | ||
| 345 | } | ||
| 346 | |||
| 347 | /* handle interrupt */ | ||
| 348 | handled = ata_host_intr(ap, qc); | ||
| 349 | if (unlikely(!handled)) { | ||
| 350 | /* spurious, clear it */ | ||
| 351 | ata_check_status(ap); | ||
| 352 | } | ||
| 353 | |||
| 354 | return 1; | ||
| 355 | } | ||
| 356 | |||
| 357 | static irqreturn_t nv_do_interrupt(struct ata_host_set *host_set, u8 irq_stat) | ||
| 358 | { | ||
| 359 | int i, handled = 0; | ||
| 360 | |||
| 361 | for (i = 0; i < host_set->n_ports; i++) { | ||
| 362 | struct ata_port *ap = host_set->ports[i]; | ||
| 363 | |||
| 364 | if (ap && !(ap->flags & ATA_FLAG_DISABLED)) | ||
| 365 | handled += nv_host_intr(ap, irq_stat); | ||
| 366 | |||
| 367 | irq_stat >>= NV_INT_PORT_SHIFT; | ||
| 368 | } | ||
| 369 | |||
| 370 | return IRQ_RETVAL(handled); | ||
| 371 | } | ||
| 372 | |||
| 373 | static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance, | ||
| 374 | struct pt_regs *regs) | ||
| 375 | { | ||
| 376 | struct ata_host_set *host_set = dev_instance; | ||
| 377 | u8 irq_stat; | ||
| 378 | irqreturn_t ret; | ||
| 379 | |||
| 380 | spin_lock(&host_set->lock); | ||
| 381 | irq_stat = inb(host_set->ports[0]->ioaddr.scr_addr + NV_INT_STATUS); | ||
| 382 | ret = nv_do_interrupt(host_set, irq_stat); | ||
| 383 | spin_unlock(&host_set->lock); | ||
| 384 | |||
| 385 | return ret; | ||
| 386 | } | ||
| 387 | |||
| 388 | static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance, | ||
| 389 | struct pt_regs *regs) | ||
| 390 | { | ||
| 391 | struct ata_host_set *host_set = dev_instance; | ||
| 392 | u8 irq_stat; | ||
| 393 | irqreturn_t ret; | ||
| 394 | |||
| 395 | spin_lock(&host_set->lock); | ||
| 396 | irq_stat = readb(host_set->mmio_base + NV_INT_STATUS_CK804); | ||
| 397 | ret = nv_do_interrupt(host_set, irq_stat); | ||
| 398 | spin_unlock(&host_set->lock); | ||
| 399 | |||
| 400 | return ret; | ||
| 401 | } | ||
| 402 | |||
| 403 | static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg) | ||
| 404 | { | ||
| 405 | if (sc_reg > SCR_CONTROL) | ||
| 406 | return 0xffffffffU; | ||
| 407 | |||
| 408 | return ioread32((void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4)); | ||
| 409 | } | ||
| 410 | |||
| 411 | static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) | ||
| 412 | { | ||
| 413 | if (sc_reg > SCR_CONTROL) | ||
| 414 | return; | ||
| 415 | |||
| 416 | iowrite32(val, (void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4)); | ||
| 417 | } | ||
| 418 | |||
| 419 | static void nv_nf2_freeze(struct ata_port *ap) | ||
| 420 | { | ||
| 421 | unsigned long scr_addr = ap->host_set->ports[0]->ioaddr.scr_addr; | ||
| 422 | int shift = ap->port_no * NV_INT_PORT_SHIFT; | ||
| 423 | u8 mask; | ||
| 424 | |||
| 425 | mask = inb(scr_addr + NV_INT_ENABLE); | ||
| 426 | mask &= ~(NV_INT_ALL << shift); | ||
| 427 | outb(mask, scr_addr + NV_INT_ENABLE); | ||
| 428 | } | ||
| 429 | |||
| 430 | static void nv_nf2_thaw(struct ata_port *ap) | ||
| 431 | { | ||
| 432 | unsigned long scr_addr = ap->host_set->ports[0]->ioaddr.scr_addr; | ||
| 433 | int shift = ap->port_no * NV_INT_PORT_SHIFT; | ||
| 434 | u8 mask; | ||
| 435 | |||
| 436 | outb(NV_INT_ALL << shift, scr_addr + NV_INT_STATUS); | ||
| 437 | |||
| 438 | mask = inb(scr_addr + NV_INT_ENABLE); | ||
| 439 | mask |= (NV_INT_MASK << shift); | ||
| 440 | outb(mask, scr_addr + NV_INT_ENABLE); | ||
| 441 | } | ||
| 442 | |||
| 443 | static void nv_ck804_freeze(struct ata_port *ap) | ||
| 444 | { | ||
| 445 | void __iomem *mmio_base = ap->host_set->mmio_base; | ||
| 446 | int shift = ap->port_no * NV_INT_PORT_SHIFT; | ||
| 447 | u8 mask; | ||
| 448 | |||
| 449 | mask = readb(mmio_base + NV_INT_ENABLE_CK804); | ||
| 450 | mask &= ~(NV_INT_ALL << shift); | ||
| 451 | writeb(mask, mmio_base + NV_INT_ENABLE_CK804); | ||
| 452 | } | ||
| 453 | |||
| 454 | static void nv_ck804_thaw(struct ata_port *ap) | ||
| 455 | { | ||
| 456 | void __iomem *mmio_base = ap->host_set->mmio_base; | ||
| 457 | int shift = ap->port_no * NV_INT_PORT_SHIFT; | ||
| 458 | u8 mask; | ||
| 459 | |||
| 460 | writeb(NV_INT_ALL << shift, mmio_base + NV_INT_STATUS_CK804); | ||
| 461 | |||
| 462 | mask = readb(mmio_base + NV_INT_ENABLE_CK804); | ||
| 463 | mask |= (NV_INT_MASK << shift); | ||
| 464 | writeb(mask, mmio_base + NV_INT_ENABLE_CK804); | ||
| 465 | } | ||
| 466 | |||
| 467 | static int nv_hardreset(struct ata_port *ap, unsigned int *class) | ||
| 468 | { | ||
| 469 | unsigned int dummy; | ||
| 470 | |||
| 471 | /* SATA hardreset fails to retrieve proper device signature on | ||
| 472 | * some controllers. Don't classify on hardreset. For more | ||
| 473 | * info, see http://bugme.osdl.org/show_bug.cgi?id=3352 | ||
| 474 | */ | ||
| 475 | return sata_std_hardreset(ap, &dummy); | ||
| 476 | } | ||
| 477 | |||
| 478 | static void nv_error_handler(struct ata_port *ap) | ||
| 479 | { | ||
| 480 | ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset, | ||
| 481 | nv_hardreset, ata_std_postreset); | ||
| 482 | } | ||
| 483 | |||
| 484 | static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) | ||
| 485 | { | ||
| 486 | static int printed_version = 0; | ||
| 487 | struct ata_port_info *ppi; | ||
| 488 | struct ata_probe_ent *probe_ent; | ||
| 489 | int pci_dev_busy = 0; | ||
| 490 | int rc; | ||
| 491 | u32 bar; | ||
| 492 | unsigned long base; | ||
| 493 | |||
| 494 | // Make sure this is a SATA controller by counting the number of bars | ||
| 495 | // (NVIDIA SATA controllers will always have six bars). Otherwise, | ||
| 496 | // it's an IDE controller and we ignore it. | ||
| 497 | for (bar=0; bar<6; bar++) | ||
| 498 | if (pci_resource_start(pdev, bar) == 0) | ||
| 499 | return -ENODEV; | ||
| 500 | |||
| 501 | if (!printed_version++) | ||
| 502 | dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); | ||
| 503 | |||
| 504 | rc = pci_enable_device(pdev); | ||
| 505 | if (rc) | ||
| 506 | goto err_out; | ||
| 507 | |||
| 508 | rc = pci_request_regions(pdev, DRV_NAME); | ||
| 509 | if (rc) { | ||
| 510 | pci_dev_busy = 1; | ||
| 511 | goto err_out_disable; | ||
| 512 | } | ||
| 513 | |||
| 514 | rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); | ||
| 515 | if (rc) | ||
| 516 | goto err_out_regions; | ||
| 517 | rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); | ||
| 518 | if (rc) | ||
| 519 | goto err_out_regions; | ||
| 520 | |||
| 521 | rc = -ENOMEM; | ||
| 522 | |||
| 523 | ppi = &nv_port_info[ent->driver_data]; | ||
| 524 | probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); | ||
| 525 | if (!probe_ent) | ||
| 526 | goto err_out_regions; | ||
| 527 | |||
| 528 | probe_ent->mmio_base = pci_iomap(pdev, 5, 0); | ||
| 529 | if (!probe_ent->mmio_base) { | ||
| 530 | rc = -EIO; | ||
| 531 | goto err_out_free_ent; | ||
| 532 | } | ||
| 533 | |||
| 534 | base = (unsigned long)probe_ent->mmio_base; | ||
| 535 | |||
| 536 | probe_ent->port[0].scr_addr = base + NV_PORT0_SCR_REG_OFFSET; | ||
| 537 | probe_ent->port[1].scr_addr = base + NV_PORT1_SCR_REG_OFFSET; | ||
| 538 | |||
| 539 | /* enable SATA space for CK804 */ | ||
| 540 | if (ent->driver_data == CK804) { | ||
| 541 | u8 regval; | ||
| 542 | |||
| 543 | pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, ®val); | ||
| 544 | regval |= NV_MCP_SATA_CFG_20_SATA_SPACE_EN; | ||
| 545 | pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval); | ||
| 546 | } | ||
| 547 | |||
| 548 | pci_set_master(pdev); | ||
| 549 | |||
| 550 | rc = ata_device_add(probe_ent); | ||
| 551 | if (rc != NV_PORTS) | ||
| 552 | goto err_out_iounmap; | ||
| 553 | |||
| 554 | kfree(probe_ent); | ||
| 555 | |||
| 556 | return 0; | ||
| 557 | |||
| 558 | err_out_iounmap: | ||
| 559 | pci_iounmap(pdev, probe_ent->mmio_base); | ||
| 560 | err_out_free_ent: | ||
| 561 | kfree(probe_ent); | ||
| 562 | err_out_regions: | ||
| 563 | pci_release_regions(pdev); | ||
| 564 | err_out_disable: | ||
| 565 | if (!pci_dev_busy) | ||
| 566 | pci_disable_device(pdev); | ||
| 567 | err_out: | ||
| 568 | return rc; | ||
| 569 | } | ||
| 570 | |||
| 571 | static void nv_ck804_host_stop(struct ata_host_set *host_set) | ||
| 572 | { | ||
| 573 | struct pci_dev *pdev = to_pci_dev(host_set->dev); | ||
| 574 | u8 regval; | ||
| 575 | |||
| 576 | /* disable SATA space for CK804 */ | ||
| 577 | pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, ®val); | ||
| 578 | regval &= ~NV_MCP_SATA_CFG_20_SATA_SPACE_EN; | ||
| 579 | pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval); | ||
| 580 | |||
| 581 | ata_pci_host_stop(host_set); | ||
| 582 | } | ||
| 583 | |||
| 584 | static int __init nv_init(void) | ||
| 585 | { | ||
| 586 | return pci_register_driver(&nv_pci_driver); | ||
| 587 | } | ||
| 588 | |||
| 589 | static void __exit nv_exit(void) | ||
| 590 | { | ||
| 591 | pci_unregister_driver(&nv_pci_driver); | ||
| 592 | } | ||
| 593 | |||
| 594 | module_init(nv_init); | ||
| 595 | module_exit(nv_exit); | ||
