PageRenderTime 423ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/ata/sata_via.c

https://bitbucket.org/cresqo/cm7-p500-kernel
C | 674 lines | 457 code | 101 blank | 116 comment | 49 complexity | 3d1938bce1f8d5a26910a520ff7b73bc MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1. /*
  2. * sata_via.c - VIA Serial ATA controllers
  3. *
  4. * Maintained by: Jeff Garzik <jgarzik@pobox.com>
  5. * Please ALWAYS copy linux-ide@vger.kernel.org
  6. * on emails.
  7. *
  8. * Copyright 2003-2004 Red Hat, Inc. All rights reserved.
  9. * Copyright 2003-2004 Jeff Garzik
  10. *
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2, or (at your option)
  15. * any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; see the file COPYING. If not, write to
  24. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  25. *
  26. *
  27. * libata documentation is available via 'make {ps|pdf}docs',
  28. * as Documentation/DocBook/libata.*
  29. *
  30. * Hardware documentation available under NDA.
  31. *
  32. *
  33. *
  34. */
  35. #include <linux/kernel.h>
  36. #include <linux/module.h>
  37. #include <linux/pci.h>
  38. #include <linux/init.h>
  39. #include <linux/blkdev.h>
  40. #include <linux/delay.h>
  41. #include <linux/device.h>
  42. #include <scsi/scsi.h>
  43. #include <scsi/scsi_cmnd.h>
  44. #include <scsi/scsi_host.h>
  45. #include <linux/libata.h>
  46. #define DRV_NAME "sata_via"
  47. #define DRV_VERSION "2.6"
  48. /*
  49. * vt8251 is different from other sata controllers of VIA. It has two
  50. * channels, each channel has both Master and Slave slot.
  51. */
  52. enum board_ids_enum {
  53. vt6420,
  54. vt6421,
  55. vt8251,
  56. };
  57. enum {
  58. SATA_CHAN_ENAB = 0x40, /* SATA channel enable */
  59. SATA_INT_GATE = 0x41, /* SATA interrupt gating */
  60. SATA_NATIVE_MODE = 0x42, /* Native mode enable */
  61. PATA_UDMA_TIMING = 0xB3, /* PATA timing for DMA/ cable detect */
  62. PATA_PIO_TIMING = 0xAB, /* PATA timing register */
  63. PORT0 = (1 << 1),
  64. PORT1 = (1 << 0),
  65. ALL_PORTS = PORT0 | PORT1,
  66. NATIVE_MODE_ALL = (1 << 7) | (1 << 6) | (1 << 5) | (1 << 4),
  67. SATA_EXT_PHY = (1 << 6), /* 0==use PATA, 1==ext phy */
  68. };
  69. static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
  70. static int svia_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
  71. static int svia_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
  72. static int vt8251_scr_read(struct ata_link *link, unsigned int scr, u32 *val);
  73. static int vt8251_scr_write(struct ata_link *link, unsigned int scr, u32 val);
  74. static void svia_tf_load(struct ata_port *ap, const struct ata_taskfile *tf);
  75. static void svia_noop_freeze(struct ata_port *ap);
  76. static int vt6420_prereset(struct ata_link *link, unsigned long deadline);
  77. static void vt6420_bmdma_start(struct ata_queued_cmd *qc);
  78. static int vt6421_pata_cable_detect(struct ata_port *ap);
  79. static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev);
  80. static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev);
  81. static const struct pci_device_id svia_pci_tbl[] = {
  82. { PCI_VDEVICE(VIA, 0x5337), vt6420 },
  83. { PCI_VDEVICE(VIA, 0x0591), vt6420 }, /* 2 sata chnls (Master) */
  84. { PCI_VDEVICE(VIA, 0x3149), vt6420 }, /* 2 sata chnls (Master) */
  85. { PCI_VDEVICE(VIA, 0x3249), vt6421 }, /* 2 sata chnls, 1 pata chnl */
  86. { PCI_VDEVICE(VIA, 0x5372), vt6420 },
  87. { PCI_VDEVICE(VIA, 0x7372), vt6420 },
  88. { PCI_VDEVICE(VIA, 0x5287), vt8251 }, /* 2 sata chnls (Master/Slave) */
  89. { PCI_VDEVICE(VIA, 0x9000), vt8251 },
  90. { } /* terminate list */
  91. };
  92. static struct pci_driver svia_pci_driver = {
  93. .name = DRV_NAME,
  94. .id_table = svia_pci_tbl,
  95. .probe = svia_init_one,
  96. #ifdef CONFIG_PM
  97. .suspend = ata_pci_device_suspend,
  98. .resume = ata_pci_device_resume,
  99. #endif
  100. .remove = ata_pci_remove_one,
  101. };
  102. static struct scsi_host_template svia_sht = {
  103. ATA_BMDMA_SHT(DRV_NAME),
  104. };
  105. static struct ata_port_operations svia_base_ops = {
  106. .inherits = &ata_bmdma_port_ops,
  107. .sff_tf_load = svia_tf_load,
  108. };
  109. static struct ata_port_operations vt6420_sata_ops = {
  110. .inherits = &svia_base_ops,
  111. .freeze = svia_noop_freeze,
  112. .prereset = vt6420_prereset,
  113. .bmdma_start = vt6420_bmdma_start,
  114. };
  115. static struct ata_port_operations vt6421_pata_ops = {
  116. .inherits = &svia_base_ops,
  117. .cable_detect = vt6421_pata_cable_detect,
  118. .set_piomode = vt6421_set_pio_mode,
  119. .set_dmamode = vt6421_set_dma_mode,
  120. };
  121. static struct ata_port_operations vt6421_sata_ops = {
  122. .inherits = &svia_base_ops,
  123. .scr_read = svia_scr_read,
  124. .scr_write = svia_scr_write,
  125. };
  126. static struct ata_port_operations vt8251_ops = {
  127. .inherits = &svia_base_ops,
  128. .hardreset = sata_std_hardreset,
  129. .scr_read = vt8251_scr_read,
  130. .scr_write = vt8251_scr_write,
  131. };
  132. static const struct ata_port_info vt6420_port_info = {
  133. .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
  134. .pio_mask = ATA_PIO4,
  135. .mwdma_mask = ATA_MWDMA2,
  136. .udma_mask = ATA_UDMA6,
  137. .port_ops = &vt6420_sata_ops,
  138. };
  139. static struct ata_port_info vt6421_sport_info = {
  140. .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
  141. .pio_mask = ATA_PIO4,
  142. .mwdma_mask = ATA_MWDMA2,
  143. .udma_mask = ATA_UDMA6,
  144. .port_ops = &vt6421_sata_ops,
  145. };
  146. static struct ata_port_info vt6421_pport_info = {
  147. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_LEGACY,
  148. .pio_mask = ATA_PIO4,
  149. /* No MWDMA */
  150. .udma_mask = ATA_UDMA6,
  151. .port_ops = &vt6421_pata_ops,
  152. };
  153. static struct ata_port_info vt8251_port_info = {
  154. .flags = ATA_FLAG_SATA | ATA_FLAG_SLAVE_POSS |
  155. ATA_FLAG_NO_LEGACY,
  156. .pio_mask = ATA_PIO4,
  157. .mwdma_mask = ATA_MWDMA2,
  158. .udma_mask = ATA_UDMA6,
  159. .port_ops = &vt8251_ops,
  160. };
  161. MODULE_AUTHOR("Jeff Garzik");
  162. MODULE_DESCRIPTION("SCSI low-level driver for VIA SATA controllers");
  163. MODULE_LICENSE("GPL");
  164. MODULE_DEVICE_TABLE(pci, svia_pci_tbl);
  165. MODULE_VERSION(DRV_VERSION);
  166. static int svia_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
  167. {
  168. if (sc_reg > SCR_CONTROL)
  169. return -EINVAL;
  170. *val = ioread32(link->ap->ioaddr.scr_addr + (4 * sc_reg));
  171. return 0;
  172. }
  173. static int svia_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
  174. {
  175. if (sc_reg > SCR_CONTROL)
  176. return -EINVAL;
  177. iowrite32(val, link->ap->ioaddr.scr_addr + (4 * sc_reg));
  178. return 0;
  179. }
  180. static int vt8251_scr_read(struct ata_link *link, unsigned int scr, u32 *val)
  181. {
  182. static const u8 ipm_tbl[] = { 1, 2, 6, 0 };
  183. struct pci_dev *pdev = to_pci_dev(link->ap->host->dev);
  184. int slot = 2 * link->ap->port_no + link->pmp;
  185. u32 v = 0;
  186. u8 raw;
  187. switch (scr) {
  188. case SCR_STATUS:
  189. pci_read_config_byte(pdev, 0xA0 + slot, &raw);
  190. /* read the DET field, bit0 and 1 of the config byte */
  191. v |= raw & 0x03;
  192. /* read the SPD field, bit4 of the configure byte */
  193. if (raw & (1 << 4))
  194. v |= 0x02 << 4;
  195. else
  196. v |= 0x01 << 4;
  197. /* read the IPM field, bit2 and 3 of the config byte */
  198. v |= ipm_tbl[(raw >> 2) & 0x3];
  199. break;
  200. case SCR_ERROR:
  201. /* devices other than 5287 uses 0xA8 as base */
  202. WARN_ON(pdev->device != 0x5287);
  203. pci_read_config_dword(pdev, 0xB0 + slot * 4, &v);
  204. break;
  205. case SCR_CONTROL:
  206. pci_read_config_byte(pdev, 0xA4 + slot, &raw);
  207. /* read the DET field, bit0 and bit1 */
  208. v |= ((raw & 0x02) << 1) | (raw & 0x01);
  209. /* read the IPM field, bit2 and bit3 */
  210. v |= ((raw >> 2) & 0x03) << 8;
  211. break;
  212. default:
  213. return -EINVAL;
  214. }
  215. *val = v;
  216. return 0;
  217. }
  218. static int vt8251_scr_write(struct ata_link *link, unsigned int scr, u32 val)
  219. {
  220. struct pci_dev *pdev = to_pci_dev(link->ap->host->dev);
  221. int slot = 2 * link->ap->port_no + link->pmp;
  222. u32 v = 0;
  223. switch (scr) {
  224. case SCR_ERROR:
  225. /* devices other than 5287 uses 0xA8 as base */
  226. WARN_ON(pdev->device != 0x5287);
  227. pci_write_config_dword(pdev, 0xB0 + slot * 4, val);
  228. return 0;
  229. case SCR_CONTROL:
  230. /* set the DET field */
  231. v |= ((val & 0x4) >> 1) | (val & 0x1);
  232. /* set the IPM field */
  233. v |= ((val >> 8) & 0x3) << 2;
  234. pci_write_config_byte(pdev, 0xA4 + slot, v);
  235. return 0;
  236. default:
  237. return -EINVAL;
  238. }
  239. }
  240. /**
  241. * svia_tf_load - send taskfile registers to host controller
  242. * @ap: Port to which output is sent
  243. * @tf: ATA taskfile register set
  244. *
  245. * Outputs ATA taskfile to standard ATA host controller.
  246. *
  247. * This is to fix the internal bug of via chipsets, which will
  248. * reset the device register after changing the IEN bit on ctl
  249. * register.
  250. */
  251. static void svia_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
  252. {
  253. struct ata_taskfile ttf;
  254. if (tf->ctl != ap->last_ctl) {
  255. ttf = *tf;
  256. ttf.flags |= ATA_TFLAG_DEVICE;
  257. tf = &ttf;
  258. }
  259. ata_sff_tf_load(ap, tf);
  260. }
  261. static void svia_noop_freeze(struct ata_port *ap)
  262. {
  263. /* Some VIA controllers choke if ATA_NIEN is manipulated in
  264. * certain way. Leave it alone and just clear pending IRQ.
  265. */
  266. ap->ops->sff_check_status(ap);
  267. ata_bmdma_irq_clear(ap);
  268. }
  269. /**
  270. * vt6420_prereset - prereset for vt6420
  271. * @link: target ATA link
  272. * @deadline: deadline jiffies for the operation
  273. *
  274. * SCR registers on vt6420 are pieces of shit and may hang the
  275. * whole machine completely if accessed with the wrong timing.
  276. * To avoid such catastrophe, vt6420 doesn't provide generic SCR
  277. * access operations, but uses SStatus and SControl only during
  278. * boot probing in controlled way.
  279. *
  280. * As the old (pre EH update) probing code is proven to work, we
  281. * strictly follow the access pattern.
  282. *
  283. * LOCKING:
  284. * Kernel thread context (may sleep)
  285. *
  286. * RETURNS:
  287. * 0 on success, -errno otherwise.
  288. */
  289. static int vt6420_prereset(struct ata_link *link, unsigned long deadline)
  290. {
  291. struct ata_port *ap = link->ap;
  292. struct ata_eh_context *ehc = &ap->link.eh_context;
  293. unsigned long timeout = jiffies + (HZ * 5);
  294. u32 sstatus, scontrol;
  295. int online;
  296. /* don't do any SCR stuff if we're not loading */
  297. if (!(ap->pflags & ATA_PFLAG_LOADING))
  298. goto skip_scr;
  299. /* Resume phy. This is the old SATA resume sequence */
  300. svia_scr_write(link, SCR_CONTROL, 0x300);
  301. svia_scr_read(link, SCR_CONTROL, &scontrol); /* flush */
  302. /* wait for phy to become ready, if necessary */
  303. do {
  304. msleep(200);
  305. svia_scr_read(link, SCR_STATUS, &sstatus);
  306. if ((sstatus & 0xf) != 1)
  307. break;
  308. } while (time_before(jiffies, timeout));
  309. /* open code sata_print_link_status() */
  310. svia_scr_read(link, SCR_STATUS, &sstatus);
  311. svia_scr_read(link, SCR_CONTROL, &scontrol);
  312. online = (sstatus & 0xf) == 0x3;
  313. ata_port_printk(ap, KERN_INFO,
  314. "SATA link %s 1.5 Gbps (SStatus %X SControl %X)\n",
  315. online ? "up" : "down", sstatus, scontrol);
  316. /* SStatus is read one more time */
  317. svia_scr_read(link, SCR_STATUS, &sstatus);
  318. if (!online) {
  319. /* tell EH to bail */
  320. ehc->i.action &= ~ATA_EH_RESET;
  321. return 0;
  322. }
  323. skip_scr:
  324. /* wait for !BSY */
  325. ata_sff_wait_ready(link, deadline);
  326. return 0;
  327. }
  328. static void vt6420_bmdma_start(struct ata_queued_cmd *qc)
  329. {
  330. struct ata_port *ap = qc->ap;
  331. if ((qc->tf.command == ATA_CMD_PACKET) &&
  332. (qc->scsicmd->sc_data_direction == DMA_TO_DEVICE)) {
  333. /* Prevents corruption on some ATAPI burners */
  334. ata_sff_pause(ap);
  335. }
  336. ata_bmdma_start(qc);
  337. }
  338. static int vt6421_pata_cable_detect(struct ata_port *ap)
  339. {
  340. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  341. u8 tmp;
  342. pci_read_config_byte(pdev, PATA_UDMA_TIMING, &tmp);
  343. if (tmp & 0x10)
  344. return ATA_CBL_PATA40;
  345. return ATA_CBL_PATA80;
  346. }
  347. static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev)
  348. {
  349. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  350. static const u8 pio_bits[] = { 0xA8, 0x65, 0x65, 0x31, 0x20 };
  351. pci_write_config_byte(pdev, PATA_PIO_TIMING - adev->devno,
  352. pio_bits[adev->pio_mode - XFER_PIO_0]);
  353. }
  354. static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev)
  355. {
  356. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  357. static const u8 udma_bits[] = { 0xEE, 0xE8, 0xE6, 0xE4, 0xE2, 0xE1, 0xE0, 0xE0 };
  358. pci_write_config_byte(pdev, PATA_UDMA_TIMING - adev->devno,
  359. udma_bits[adev->dma_mode - XFER_UDMA_0]);
  360. }
  361. static const unsigned int svia_bar_sizes[] = {
  362. 8, 4, 8, 4, 16, 256
  363. };
  364. static const unsigned int vt6421_bar_sizes[] = {
  365. 16, 16, 16, 16, 32, 128
  366. };
  367. static void __iomem *svia_scr_addr(void __iomem *addr, unsigned int port)
  368. {
  369. return addr + (port * 128);
  370. }
  371. static void __iomem *vt6421_scr_addr(void __iomem *addr, unsigned int port)
  372. {
  373. return addr + (port * 64);
  374. }
  375. static void vt6421_init_addrs(struct ata_port *ap)
  376. {
  377. void __iomem * const * iomap = ap->host->iomap;
  378. void __iomem *reg_addr = iomap[ap->port_no];
  379. void __iomem *bmdma_addr = iomap[4] + (ap->port_no * 8);
  380. struct ata_ioports *ioaddr = &ap->ioaddr;
  381. ioaddr->cmd_addr = reg_addr;
  382. ioaddr->altstatus_addr =
  383. ioaddr->ctl_addr = (void __iomem *)
  384. ((unsigned long)(reg_addr + 8) | ATA_PCI_CTL_OFS);
  385. ioaddr->bmdma_addr = bmdma_addr;
  386. ioaddr->scr_addr = vt6421_scr_addr(iomap[5], ap->port_no);
  387. ata_sff_std_ports(ioaddr);
  388. ata_port_pbar_desc(ap, ap->port_no, -1, "port");
  389. ata_port_pbar_desc(ap, 4, ap->port_no * 8, "bmdma");
  390. }
  391. static int vt6420_prepare_host(struct pci_dev *pdev, struct ata_host **r_host)
  392. {
  393. const struct ata_port_info *ppi[] = { &vt6420_port_info, NULL };
  394. struct ata_host *host;
  395. int rc;
  396. rc = ata_pci_bmdma_prepare_host(pdev, ppi, &host);
  397. if (rc)
  398. return rc;
  399. *r_host = host;
  400. rc = pcim_iomap_regions(pdev, 1 << 5, DRV_NAME);
  401. if (rc) {
  402. dev_printk(KERN_ERR, &pdev->dev, "failed to iomap PCI BAR 5\n");
  403. return rc;
  404. }
  405. host->ports[0]->ioaddr.scr_addr = svia_scr_addr(host->iomap[5], 0);
  406. host->ports[1]->ioaddr.scr_addr = svia_scr_addr(host->iomap[5], 1);
  407. return 0;
  408. }
  409. static int vt6421_prepare_host(struct pci_dev *pdev, struct ata_host **r_host)
  410. {
  411. const struct ata_port_info *ppi[] =
  412. { &vt6421_sport_info, &vt6421_sport_info, &vt6421_pport_info };
  413. struct ata_host *host;
  414. int i, rc;
  415. *r_host = host = ata_host_alloc_pinfo(&pdev->dev, ppi, ARRAY_SIZE(ppi));
  416. if (!host) {
  417. dev_printk(KERN_ERR, &pdev->dev, "failed to allocate host\n");
  418. return -ENOMEM;
  419. }
  420. rc = pcim_iomap_regions(pdev, 0x3f, DRV_NAME);
  421. if (rc) {
  422. dev_printk(KERN_ERR, &pdev->dev, "failed to request/iomap "
  423. "PCI BARs (errno=%d)\n", rc);
  424. return rc;
  425. }
  426. host->iomap = pcim_iomap_table(pdev);
  427. for (i = 0; i < host->n_ports; i++)
  428. vt6421_init_addrs(host->ports[i]);
  429. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  430. if (rc)
  431. return rc;
  432. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  433. if (rc)
  434. return rc;
  435. return 0;
  436. }
  437. static int vt8251_prepare_host(struct pci_dev *pdev, struct ata_host **r_host)
  438. {
  439. const struct ata_port_info *ppi[] = { &vt8251_port_info, NULL };
  440. struct ata_host *host;
  441. int i, rc;
  442. rc = ata_pci_bmdma_prepare_host(pdev, ppi, &host);
  443. if (rc)
  444. return rc;
  445. *r_host = host;
  446. rc = pcim_iomap_regions(pdev, 1 << 5, DRV_NAME);
  447. if (rc) {
  448. dev_printk(KERN_ERR, &pdev->dev, "failed to iomap PCI BAR 5\n");
  449. return rc;
  450. }
  451. /* 8251 hosts four sata ports as M/S of the two channels */
  452. for (i = 0; i < host->n_ports; i++)
  453. ata_slave_link_init(host->ports[i]);
  454. return 0;
  455. }
  456. static void svia_configure(struct pci_dev *pdev, int board_id)
  457. {
  458. u8 tmp8;
  459. pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &tmp8);
  460. dev_printk(KERN_INFO, &pdev->dev, "routed to hard irq line %d\n",
  461. (int) (tmp8 & 0xf0) == 0xf0 ? 0 : tmp8 & 0x0f);
  462. /* make sure SATA channels are enabled */
  463. pci_read_config_byte(pdev, SATA_CHAN_ENAB, &tmp8);
  464. if ((tmp8 & ALL_PORTS) != ALL_PORTS) {
  465. dev_printk(KERN_DEBUG, &pdev->dev,
  466. "enabling SATA channels (0x%x)\n",
  467. (int) tmp8);
  468. tmp8 |= ALL_PORTS;
  469. pci_write_config_byte(pdev, SATA_CHAN_ENAB, tmp8);
  470. }
  471. /* make sure interrupts for each channel sent to us */
  472. pci_read_config_byte(pdev, SATA_INT_GATE, &tmp8);
  473. if ((tmp8 & ALL_PORTS) != ALL_PORTS) {
  474. dev_printk(KERN_DEBUG, &pdev->dev,
  475. "enabling SATA channel interrupts (0x%x)\n",
  476. (int) tmp8);
  477. tmp8 |= ALL_PORTS;
  478. pci_write_config_byte(pdev, SATA_INT_GATE, tmp8);
  479. }
  480. /* make sure native mode is enabled */
  481. pci_read_config_byte(pdev, SATA_NATIVE_MODE, &tmp8);
  482. if ((tmp8 & NATIVE_MODE_ALL) != NATIVE_MODE_ALL) {
  483. dev_printk(KERN_DEBUG, &pdev->dev,
  484. "enabling SATA channel native mode (0x%x)\n",
  485. (int) tmp8);
  486. tmp8 |= NATIVE_MODE_ALL;
  487. pci_write_config_byte(pdev, SATA_NATIVE_MODE, tmp8);
  488. }
  489. /*
  490. * vt6420/1 has problems talking to some drives. The following
  491. * is the fix from Joseph Chan <JosephChan@via.com.tw>.
  492. *
  493. * When host issues HOLD, device may send up to 20DW of data
  494. * before acknowledging it with HOLDA and the host should be
  495. * able to buffer them in FIFO. Unfortunately, some WD drives
  496. * send upto 40DW before acknowledging HOLD and, in the
  497. * default configuration, this ends up overflowing vt6421's
  498. * FIFO, making the controller abort the transaction with
  499. * R_ERR.
  500. *
  501. * Rx52[2] is the internal 128DW FIFO Flow control watermark
  502. * adjusting mechanism enable bit and the default value 0
  503. * means host will issue HOLD to device when the left FIFO
  504. * size goes below 32DW. Setting it to 1 makes the watermark
  505. * 64DW.
  506. *
  507. * https://bugzilla.kernel.org/show_bug.cgi?id=15173
  508. * http://article.gmane.org/gmane.linux.ide/46352
  509. * http://thread.gmane.org/gmane.linux.kernel/1062139
  510. */
  511. if (board_id == vt6420 || board_id == vt6421) {
  512. pci_read_config_byte(pdev, 0x52, &tmp8);
  513. tmp8 |= 1 << 2;
  514. pci_write_config_byte(pdev, 0x52, tmp8);
  515. }
  516. }
  517. static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  518. {
  519. static int printed_version;
  520. unsigned int i;
  521. int rc;
  522. struct ata_host *host = NULL;
  523. int board_id = (int) ent->driver_data;
  524. const unsigned *bar_sizes;
  525. if (!printed_version++)
  526. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  527. rc = pcim_enable_device(pdev);
  528. if (rc)
  529. return rc;
  530. if (board_id == vt6421)
  531. bar_sizes = &vt6421_bar_sizes[0];
  532. else
  533. bar_sizes = &svia_bar_sizes[0];
  534. for (i = 0; i < ARRAY_SIZE(svia_bar_sizes); i++)
  535. if ((pci_resource_start(pdev, i) == 0) ||
  536. (pci_resource_len(pdev, i) < bar_sizes[i])) {
  537. dev_printk(KERN_ERR, &pdev->dev,
  538. "invalid PCI BAR %u (sz 0x%llx, val 0x%llx)\n",
  539. i,
  540. (unsigned long long)pci_resource_start(pdev, i),
  541. (unsigned long long)pci_resource_len(pdev, i));
  542. return -ENODEV;
  543. }
  544. switch (board_id) {
  545. case vt6420:
  546. rc = vt6420_prepare_host(pdev, &host);
  547. break;
  548. case vt6421:
  549. rc = vt6421_prepare_host(pdev, &host);
  550. break;
  551. case vt8251:
  552. rc = vt8251_prepare_host(pdev, &host);
  553. break;
  554. default:
  555. rc = -EINVAL;
  556. }
  557. if (rc)
  558. return rc;
  559. svia_configure(pdev, board_id);
  560. pci_set_master(pdev);
  561. return ata_host_activate(host, pdev->irq, ata_bmdma_interrupt,
  562. IRQF_SHARED, &svia_sht);
  563. }
  564. static int __init svia_init(void)
  565. {
  566. return pci_register_driver(&svia_pci_driver);
  567. }
  568. static void __exit svia_exit(void)
  569. {
  570. pci_unregister_driver(&svia_pci_driver);
  571. }
  572. module_init(svia_init);
  573. module_exit(svia_exit);