sata_nv.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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. NV_INT_STATUS = 0x10,
  54. NV_INT_STATUS_CK804 = 0x440,
  55. NV_INT_STATUS_PDEV_INT = 0x01,
  56. NV_INT_STATUS_PDEV_PM = 0x02,
  57. NV_INT_STATUS_PDEV_ADDED = 0x04,
  58. NV_INT_STATUS_PDEV_REMOVED = 0x08,
  59. NV_INT_STATUS_SDEV_INT = 0x10,
  60. NV_INT_STATUS_SDEV_PM = 0x20,
  61. NV_INT_STATUS_SDEV_ADDED = 0x40,
  62. NV_INT_STATUS_SDEV_REMOVED = 0x80,
  63. NV_INT_STATUS_PDEV_HOTPLUG = (NV_INT_STATUS_PDEV_ADDED |
  64. NV_INT_STATUS_PDEV_REMOVED),
  65. NV_INT_STATUS_SDEV_HOTPLUG = (NV_INT_STATUS_SDEV_ADDED |
  66. NV_INT_STATUS_SDEV_REMOVED),
  67. NV_INT_STATUS_HOTPLUG = (NV_INT_STATUS_PDEV_HOTPLUG |
  68. NV_INT_STATUS_SDEV_HOTPLUG),
  69. NV_INT_ENABLE = 0x11,
  70. NV_INT_ENABLE_CK804 = 0x441,
  71. NV_INT_ENABLE_PDEV_MASK = 0x01,
  72. NV_INT_ENABLE_PDEV_PM = 0x02,
  73. NV_INT_ENABLE_PDEV_ADDED = 0x04,
  74. NV_INT_ENABLE_PDEV_REMOVED = 0x08,
  75. NV_INT_ENABLE_SDEV_MASK = 0x10,
  76. NV_INT_ENABLE_SDEV_PM = 0x20,
  77. NV_INT_ENABLE_SDEV_ADDED = 0x40,
  78. NV_INT_ENABLE_SDEV_REMOVED = 0x80,
  79. NV_INT_ENABLE_PDEV_HOTPLUG = (NV_INT_ENABLE_PDEV_ADDED |
  80. NV_INT_ENABLE_PDEV_REMOVED),
  81. NV_INT_ENABLE_SDEV_HOTPLUG = (NV_INT_ENABLE_SDEV_ADDED |
  82. NV_INT_ENABLE_SDEV_REMOVED),
  83. NV_INT_ENABLE_HOTPLUG = (NV_INT_ENABLE_PDEV_HOTPLUG |
  84. NV_INT_ENABLE_SDEV_HOTPLUG),
  85. NV_INT_CONFIG = 0x12,
  86. NV_INT_CONFIG_METHD = 0x01, // 0 = INT, 1 = SMI
  87. // For PCI config register 20
  88. NV_MCP_SATA_CFG_20 = 0x50,
  89. NV_MCP_SATA_CFG_20_SATA_SPACE_EN = 0x04,
  90. };
  91. static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
  92. static irqreturn_t nv_interrupt (int irq, void *dev_instance,
  93. struct pt_regs *regs);
  94. static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg);
  95. static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
  96. static void nv_host_stop (struct ata_host_set *host_set);
  97. static void nv_enable_hotplug(struct ata_probe_ent *probe_ent);
  98. static void nv_disable_hotplug(struct ata_host_set *host_set);
  99. static int nv_check_hotplug(struct ata_host_set *host_set);
  100. static void nv_enable_hotplug_ck804(struct ata_probe_ent *probe_ent);
  101. static void nv_disable_hotplug_ck804(struct ata_host_set *host_set);
  102. static int nv_check_hotplug_ck804(struct ata_host_set *host_set);
  103. enum nv_host_type
  104. {
  105. GENERIC,
  106. NFORCE2,
  107. NFORCE3,
  108. CK804
  109. };
  110. static const struct pci_device_id nv_pci_tbl[] = {
  111. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA,
  112. PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE2 },
  113. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA,
  114. PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE3 },
  115. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2,
  116. PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE3 },
  117. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA,
  118. PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
  119. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA2,
  120. PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
  121. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA,
  122. PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
  123. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA2,
  124. PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
  125. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA,
  126. PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
  127. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA2,
  128. PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
  129. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA,
  130. PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
  131. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA2,
  132. PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
  133. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA,
  134. PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
  135. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2,
  136. PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
  137. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3,
  138. PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
  139. { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  140. PCI_ANY_ID, PCI_ANY_ID,
  141. PCI_CLASS_STORAGE_IDE<<8, 0xffff00, GENERIC },
  142. { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  143. PCI_ANY_ID, PCI_ANY_ID,
  144. PCI_CLASS_STORAGE_RAID<<8, 0xffff00, GENERIC },
  145. { 0, } /* terminate list */
  146. };
  147. struct nv_host_desc
  148. {
  149. enum nv_host_type host_type;
  150. void (*enable_hotplug)(struct ata_probe_ent *probe_ent);
  151. void (*disable_hotplug)(struct ata_host_set *host_set);
  152. int (*check_hotplug)(struct ata_host_set *host_set);
  153. };
  154. static struct nv_host_desc nv_device_tbl[] = {
  155. {
  156. .host_type = GENERIC,
  157. .enable_hotplug = NULL,
  158. .disable_hotplug= NULL,
  159. .check_hotplug = NULL,
  160. },
  161. {
  162. .host_type = NFORCE2,
  163. .enable_hotplug = nv_enable_hotplug,
  164. .disable_hotplug= nv_disable_hotplug,
  165. .check_hotplug = nv_check_hotplug,
  166. },
  167. {
  168. .host_type = NFORCE3,
  169. .enable_hotplug = nv_enable_hotplug,
  170. .disable_hotplug= nv_disable_hotplug,
  171. .check_hotplug = nv_check_hotplug,
  172. },
  173. { .host_type = CK804,
  174. .enable_hotplug = nv_enable_hotplug_ck804,
  175. .disable_hotplug= nv_disable_hotplug_ck804,
  176. .check_hotplug = nv_check_hotplug_ck804,
  177. },
  178. };
  179. struct nv_host
  180. {
  181. struct nv_host_desc *host_desc;
  182. unsigned long host_flags;
  183. };
  184. static struct pci_driver nv_pci_driver = {
  185. .name = DRV_NAME,
  186. .id_table = nv_pci_tbl,
  187. .probe = nv_init_one,
  188. .remove = ata_pci_remove_one,
  189. };
  190. static struct scsi_host_template nv_sht = {
  191. .module = THIS_MODULE,
  192. .name = DRV_NAME,
  193. .ioctl = ata_scsi_ioctl,
  194. .queuecommand = ata_scsi_queuecmd,
  195. .can_queue = ATA_DEF_QUEUE,
  196. .this_id = ATA_SHT_THIS_ID,
  197. .sg_tablesize = LIBATA_MAX_PRD,
  198. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  199. .emulated = ATA_SHT_EMULATED,
  200. .use_clustering = ATA_SHT_USE_CLUSTERING,
  201. .proc_name = DRV_NAME,
  202. .dma_boundary = ATA_DMA_BOUNDARY,
  203. .slave_configure = ata_scsi_slave_config,
  204. .slave_destroy = ata_scsi_slave_destroy,
  205. .bios_param = ata_std_bios_param,
  206. };
  207. static const struct ata_port_operations nv_ops = {
  208. .port_disable = ata_port_disable,
  209. .tf_load = ata_tf_load,
  210. .tf_read = ata_tf_read,
  211. .exec_command = ata_exec_command,
  212. .check_status = ata_check_status,
  213. .dev_select = ata_std_dev_select,
  214. .phy_reset = sata_phy_reset,
  215. .bmdma_setup = ata_bmdma_setup,
  216. .bmdma_start = ata_bmdma_start,
  217. .bmdma_stop = ata_bmdma_stop,
  218. .bmdma_status = ata_bmdma_status,
  219. .qc_prep = ata_qc_prep,
  220. .qc_issue = ata_qc_issue_prot,
  221. .eng_timeout = ata_eng_timeout,
  222. .data_xfer = ata_pio_data_xfer,
  223. .irq_handler = nv_interrupt,
  224. .irq_clear = ata_bmdma_irq_clear,
  225. .scr_read = nv_scr_read,
  226. .scr_write = nv_scr_write,
  227. .port_start = ata_port_start,
  228. .port_stop = ata_port_stop,
  229. .host_stop = nv_host_stop,
  230. };
  231. /* FIXME: The hardware provides the necessary SATA PHY controls
  232. * to support ATA_FLAG_SATA_RESET. However, it is currently
  233. * necessary to disable that flag, to solve misdetection problems.
  234. * See http://bugme.osdl.org/show_bug.cgi?id=3352 for more info.
  235. *
  236. * This problem really needs to be investigated further. But in the
  237. * meantime, we avoid ATA_FLAG_SATA_RESET to get people working.
  238. */
  239. static struct ata_port_info nv_port_info = {
  240. .sht = &nv_sht,
  241. .host_flags = ATA_FLAG_SATA |
  242. /* ATA_FLAG_SATA_RESET | */
  243. ATA_FLAG_SRST |
  244. ATA_FLAG_NO_LEGACY,
  245. .pio_mask = NV_PIO_MASK,
  246. .mwdma_mask = NV_MWDMA_MASK,
  247. .udma_mask = NV_UDMA_MASK,
  248. .port_ops = &nv_ops,
  249. };
  250. MODULE_AUTHOR("NVIDIA");
  251. MODULE_DESCRIPTION("low-level driver for NVIDIA nForce SATA controller");
  252. MODULE_LICENSE("GPL");
  253. MODULE_DEVICE_TABLE(pci, nv_pci_tbl);
  254. MODULE_VERSION(DRV_VERSION);
  255. static irqreturn_t nv_interrupt (int irq, void *dev_instance,
  256. struct pt_regs *regs)
  257. {
  258. struct ata_host_set *host_set = dev_instance;
  259. struct nv_host *host = host_set->private_data;
  260. unsigned int i;
  261. unsigned int handled = 0;
  262. unsigned long flags;
  263. spin_lock_irqsave(&host_set->lock, flags);
  264. for (i = 0; i < host_set->n_ports; i++) {
  265. struct ata_port *ap;
  266. ap = host_set->ports[i];
  267. if (ap &&
  268. !(ap->flags & ATA_FLAG_DISABLED)) {
  269. struct ata_queued_cmd *qc;
  270. qc = ata_qc_from_tag(ap, ap->active_tag);
  271. if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
  272. handled += ata_host_intr(ap, qc);
  273. else
  274. // No request pending? Clear interrupt status
  275. // anyway, in case there's one pending.
  276. ap->ops->check_status(ap);
  277. }
  278. }
  279. if (host->host_desc->check_hotplug)
  280. handled += host->host_desc->check_hotplug(host_set);
  281. spin_unlock_irqrestore(&host_set->lock, flags);
  282. return IRQ_RETVAL(handled);
  283. }
  284. static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg)
  285. {
  286. if (sc_reg > SCR_CONTROL)
  287. return 0xffffffffU;
  288. return ioread32((void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
  289. }
  290. static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
  291. {
  292. if (sc_reg > SCR_CONTROL)
  293. return;
  294. iowrite32(val, (void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
  295. }
  296. static void nv_host_stop (struct ata_host_set *host_set)
  297. {
  298. struct nv_host *host = host_set->private_data;
  299. // Disable hotplug event interrupts.
  300. if (host->host_desc->disable_hotplug)
  301. host->host_desc->disable_hotplug(host_set);
  302. kfree(host);
  303. ata_pci_host_stop(host_set);
  304. }
  305. static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  306. {
  307. static int printed_version = 0;
  308. struct nv_host *host;
  309. struct ata_port_info *ppi;
  310. struct ata_probe_ent *probe_ent;
  311. int pci_dev_busy = 0;
  312. int rc;
  313. u32 bar;
  314. unsigned long base;
  315. // Make sure this is a SATA controller by counting the number of bars
  316. // (NVIDIA SATA controllers will always have six bars). Otherwise,
  317. // it's an IDE controller and we ignore it.
  318. for (bar=0; bar<6; bar++)
  319. if (pci_resource_start(pdev, bar) == 0)
  320. return -ENODEV;
  321. if (!printed_version++)
  322. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  323. rc = pci_enable_device(pdev);
  324. if (rc)
  325. goto err_out;
  326. rc = pci_request_regions(pdev, DRV_NAME);
  327. if (rc) {
  328. pci_dev_busy = 1;
  329. goto err_out_disable;
  330. }
  331. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  332. if (rc)
  333. goto err_out_regions;
  334. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  335. if (rc)
  336. goto err_out_regions;
  337. rc = -ENOMEM;
  338. ppi = &nv_port_info;
  339. probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
  340. if (!probe_ent)
  341. goto err_out_regions;
  342. host = kmalloc(sizeof(struct nv_host), GFP_KERNEL);
  343. if (!host)
  344. goto err_out_free_ent;
  345. memset(host, 0, sizeof(struct nv_host));
  346. host->host_desc = &nv_device_tbl[ent->driver_data];
  347. probe_ent->private_data = host;
  348. probe_ent->mmio_base = pci_iomap(pdev, 5, 0);
  349. if (!probe_ent->mmio_base) {
  350. rc = -EIO;
  351. goto err_out_free_host;
  352. }
  353. base = (unsigned long)probe_ent->mmio_base;
  354. probe_ent->port[0].scr_addr = base + NV_PORT0_SCR_REG_OFFSET;
  355. probe_ent->port[1].scr_addr = base + NV_PORT1_SCR_REG_OFFSET;
  356. pci_set_master(pdev);
  357. rc = ata_device_add(probe_ent);
  358. if (rc != NV_PORTS)
  359. goto err_out_iounmap;
  360. // Enable hotplug event interrupts.
  361. if (host->host_desc->enable_hotplug)
  362. host->host_desc->enable_hotplug(probe_ent);
  363. kfree(probe_ent);
  364. return 0;
  365. err_out_iounmap:
  366. pci_iounmap(pdev, probe_ent->mmio_base);
  367. err_out_free_host:
  368. kfree(host);
  369. err_out_free_ent:
  370. kfree(probe_ent);
  371. err_out_regions:
  372. pci_release_regions(pdev);
  373. err_out_disable:
  374. if (!pci_dev_busy)
  375. pci_disable_device(pdev);
  376. err_out:
  377. return rc;
  378. }
  379. static void nv_enable_hotplug(struct ata_probe_ent *probe_ent)
  380. {
  381. u8 intr_mask;
  382. outb(NV_INT_STATUS_HOTPLUG,
  383. probe_ent->port[0].scr_addr + NV_INT_STATUS);
  384. intr_mask = inb(probe_ent->port[0].scr_addr + NV_INT_ENABLE);
  385. intr_mask |= NV_INT_ENABLE_HOTPLUG;
  386. outb(intr_mask, probe_ent->port[0].scr_addr + NV_INT_ENABLE);
  387. }
  388. static void nv_disable_hotplug(struct ata_host_set *host_set)
  389. {
  390. u8 intr_mask;
  391. intr_mask = inb(host_set->ports[0]->ioaddr.scr_addr + NV_INT_ENABLE);
  392. intr_mask &= ~(NV_INT_ENABLE_HOTPLUG);
  393. outb(intr_mask, host_set->ports[0]->ioaddr.scr_addr + NV_INT_ENABLE);
  394. }
  395. static int nv_check_hotplug(struct ata_host_set *host_set)
  396. {
  397. u8 intr_status;
  398. intr_status = inb(host_set->ports[0]->ioaddr.scr_addr + NV_INT_STATUS);
  399. // Clear interrupt status.
  400. outb(0xff, host_set->ports[0]->ioaddr.scr_addr + NV_INT_STATUS);
  401. if (intr_status & NV_INT_STATUS_HOTPLUG) {
  402. if (intr_status & NV_INT_STATUS_PDEV_ADDED)
  403. printk(KERN_WARNING "nv_sata: "
  404. "Primary device added\n");
  405. if (intr_status & NV_INT_STATUS_PDEV_REMOVED)
  406. printk(KERN_WARNING "nv_sata: "
  407. "Primary device removed\n");
  408. if (intr_status & NV_INT_STATUS_SDEV_ADDED)
  409. printk(KERN_WARNING "nv_sata: "
  410. "Secondary device added\n");
  411. if (intr_status & NV_INT_STATUS_SDEV_REMOVED)
  412. printk(KERN_WARNING "nv_sata: "
  413. "Secondary device removed\n");
  414. return 1;
  415. }
  416. return 0;
  417. }
  418. static void nv_enable_hotplug_ck804(struct ata_probe_ent *probe_ent)
  419. {
  420. struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
  421. u8 intr_mask;
  422. u8 regval;
  423. pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, &regval);
  424. regval |= NV_MCP_SATA_CFG_20_SATA_SPACE_EN;
  425. pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval);
  426. writeb(NV_INT_STATUS_HOTPLUG, probe_ent->mmio_base + NV_INT_STATUS_CK804);
  427. intr_mask = readb(probe_ent->mmio_base + NV_INT_ENABLE_CK804);
  428. intr_mask |= NV_INT_ENABLE_HOTPLUG;
  429. writeb(intr_mask, probe_ent->mmio_base + NV_INT_ENABLE_CK804);
  430. }
  431. static void nv_disable_hotplug_ck804(struct ata_host_set *host_set)
  432. {
  433. struct pci_dev *pdev = to_pci_dev(host_set->dev);
  434. u8 intr_mask;
  435. u8 regval;
  436. intr_mask = readb(host_set->mmio_base + NV_INT_ENABLE_CK804);
  437. intr_mask &= ~(NV_INT_ENABLE_HOTPLUG);
  438. writeb(intr_mask, host_set->mmio_base + NV_INT_ENABLE_CK804);
  439. pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, &regval);
  440. regval &= ~NV_MCP_SATA_CFG_20_SATA_SPACE_EN;
  441. pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval);
  442. }
  443. static int nv_check_hotplug_ck804(struct ata_host_set *host_set)
  444. {
  445. u8 intr_status;
  446. intr_status = readb(host_set->mmio_base + NV_INT_STATUS_CK804);
  447. // Clear interrupt status.
  448. writeb(0xff, host_set->mmio_base + NV_INT_STATUS_CK804);
  449. if (intr_status & NV_INT_STATUS_HOTPLUG) {
  450. if (intr_status & NV_INT_STATUS_PDEV_ADDED)
  451. printk(KERN_WARNING "nv_sata: "
  452. "Primary device added\n");
  453. if (intr_status & NV_INT_STATUS_PDEV_REMOVED)
  454. printk(KERN_WARNING "nv_sata: "
  455. "Primary device removed\n");
  456. if (intr_status & NV_INT_STATUS_SDEV_ADDED)
  457. printk(KERN_WARNING "nv_sata: "
  458. "Secondary device added\n");
  459. if (intr_status & NV_INT_STATUS_SDEV_REMOVED)
  460. printk(KERN_WARNING "nv_sata: "
  461. "Secondary device removed\n");
  462. return 1;
  463. }
  464. return 0;
  465. }
  466. static int __init nv_init(void)
  467. {
  468. return pci_module_init(&nv_pci_driver);
  469. }
  470. static void __exit nv_exit(void)
  471. {
  472. pci_unregister_driver(&nv_pci_driver);
  473. }
  474. module_init(nv_init);
  475. module_exit(nv_exit);