sata_nv.c 16 KB

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