sata_nv.c 16 KB

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