sata_nv.c 16 KB

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