sata_nv.c 16 KB

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