sata_via.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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_host.h>
  43. #include <linux/libata.h>
  44. #define DRV_NAME "sata_via"
  45. #define DRV_VERSION "2.4"
  46. /*
  47. * vt8251 is different from other sata controllers of VIA. It has two
  48. * channels, each channel has both Master and Slave slot.
  49. */
  50. enum board_ids_enum {
  51. vt6420,
  52. vt6421,
  53. vt8251,
  54. };
  55. enum {
  56. SATA_CHAN_ENAB = 0x40, /* SATA channel enable */
  57. SATA_INT_GATE = 0x41, /* SATA interrupt gating */
  58. SATA_NATIVE_MODE = 0x42, /* Native mode enable */
  59. PATA_UDMA_TIMING = 0xB3, /* PATA timing for DMA/ cable detect */
  60. PATA_PIO_TIMING = 0xAB, /* PATA timing register */
  61. PORT0 = (1 << 1),
  62. PORT1 = (1 << 0),
  63. ALL_PORTS = PORT0 | PORT1,
  64. NATIVE_MODE_ALL = (1 << 7) | (1 << 6) | (1 << 5) | (1 << 4),
  65. SATA_EXT_PHY = (1 << 6), /* 0==use PATA, 1==ext phy */
  66. };
  67. static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
  68. static int svia_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
  69. static int svia_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
  70. static int vt8251_scr_read(struct ata_link *link, unsigned int scr, u32 *val);
  71. static int vt8251_scr_write(struct ata_link *link, unsigned int scr, u32 val);
  72. static void svia_tf_load(struct ata_port *ap, const struct ata_taskfile *tf);
  73. static void svia_noop_freeze(struct ata_port *ap);
  74. static int vt6420_prereset(struct ata_link *link, unsigned long deadline);
  75. static int vt6421_pata_cable_detect(struct ata_port *ap);
  76. static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev);
  77. static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev);
  78. static const struct pci_device_id svia_pci_tbl[] = {
  79. { PCI_VDEVICE(VIA, 0x5337), vt6420 },
  80. { PCI_VDEVICE(VIA, 0x0591), vt6420 }, /* 2 sata chnls (Master) */
  81. { PCI_VDEVICE(VIA, 0x3149), vt6420 }, /* 2 sata chnls (Master) */
  82. { PCI_VDEVICE(VIA, 0x3249), vt6421 }, /* 2 sata chnls, 1 pata chnl */
  83. { PCI_VDEVICE(VIA, 0x5372), vt6420 },
  84. { PCI_VDEVICE(VIA, 0x7372), vt6420 },
  85. { PCI_VDEVICE(VIA, 0x5287), vt8251 }, /* 2 sata chnls (Master/Slave) */
  86. { } /* terminate list */
  87. };
  88. static struct pci_driver svia_pci_driver = {
  89. .name = DRV_NAME,
  90. .id_table = svia_pci_tbl,
  91. .probe = svia_init_one,
  92. #ifdef CONFIG_PM
  93. .suspend = ata_pci_device_suspend,
  94. .resume = ata_pci_device_resume,
  95. #endif
  96. .remove = ata_pci_remove_one,
  97. };
  98. static struct scsi_host_template svia_sht = {
  99. ATA_BMDMA_SHT(DRV_NAME),
  100. };
  101. static struct ata_port_operations svia_base_ops = {
  102. .inherits = &ata_bmdma_port_ops,
  103. .sff_tf_load = svia_tf_load,
  104. };
  105. static struct ata_port_operations vt6420_sata_ops = {
  106. .inherits = &svia_base_ops,
  107. .freeze = svia_noop_freeze,
  108. .prereset = vt6420_prereset,
  109. };
  110. static struct ata_port_operations vt6421_pata_ops = {
  111. .inherits = &svia_base_ops,
  112. .cable_detect = vt6421_pata_cable_detect,
  113. .set_piomode = vt6421_set_pio_mode,
  114. .set_dmamode = vt6421_set_dma_mode,
  115. };
  116. static struct ata_port_operations vt6421_sata_ops = {
  117. .inherits = &svia_base_ops,
  118. .scr_read = svia_scr_read,
  119. .scr_write = svia_scr_write,
  120. };
  121. static struct ata_port_operations vt8251_ops = {
  122. .inherits = &svia_base_ops,
  123. .hardreset = sata_std_hardreset,
  124. .scr_read = vt8251_scr_read,
  125. .scr_write = vt8251_scr_write,
  126. };
  127. static const struct ata_port_info vt6420_port_info = {
  128. .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
  129. .pio_mask = 0x1f,
  130. .mwdma_mask = 0x07,
  131. .udma_mask = ATA_UDMA6,
  132. .port_ops = &vt6420_sata_ops,
  133. };
  134. static struct ata_port_info vt6421_sport_info = {
  135. .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
  136. .pio_mask = 0x1f,
  137. .mwdma_mask = 0x07,
  138. .udma_mask = ATA_UDMA6,
  139. .port_ops = &vt6421_sata_ops,
  140. };
  141. static struct ata_port_info vt6421_pport_info = {
  142. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_LEGACY,
  143. .pio_mask = 0x1f,
  144. .mwdma_mask = 0,
  145. .udma_mask = ATA_UDMA6,
  146. .port_ops = &vt6421_pata_ops,
  147. };
  148. static struct ata_port_info vt8251_port_info = {
  149. .flags = ATA_FLAG_SATA | ATA_FLAG_SLAVE_POSS |
  150. ATA_FLAG_NO_LEGACY,
  151. .pio_mask = 0x1f,
  152. .mwdma_mask = 0x07,
  153. .udma_mask = ATA_UDMA6,
  154. .port_ops = &vt8251_ops,
  155. };
  156. MODULE_AUTHOR("Jeff Garzik");
  157. MODULE_DESCRIPTION("SCSI low-level driver for VIA SATA controllers");
  158. MODULE_LICENSE("GPL");
  159. MODULE_DEVICE_TABLE(pci, svia_pci_tbl);
  160. MODULE_VERSION(DRV_VERSION);
  161. static int svia_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
  162. {
  163. if (sc_reg > SCR_CONTROL)
  164. return -EINVAL;
  165. *val = ioread32(link->ap->ioaddr.scr_addr + (4 * sc_reg));
  166. return 0;
  167. }
  168. static int svia_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
  169. {
  170. if (sc_reg > SCR_CONTROL)
  171. return -EINVAL;
  172. iowrite32(val, link->ap->ioaddr.scr_addr + (4 * sc_reg));
  173. return 0;
  174. }
  175. static int vt8251_scr_read(struct ata_link *link, unsigned int scr, u32 *val)
  176. {
  177. static const u8 ipm_tbl[] = { 1, 2, 6, 0 };
  178. struct pci_dev *pdev = to_pci_dev(link->ap->host->dev);
  179. int slot = 2 * link->ap->port_no + link->pmp;
  180. u32 v = 0;
  181. u8 raw;
  182. switch (scr) {
  183. case SCR_STATUS:
  184. pci_read_config_byte(pdev, 0xA0 + slot, &raw);
  185. /* read the DET field, bit0 and 1 of the config byte */
  186. v |= raw & 0x03;
  187. /* read the SPD field, bit4 of the configure byte */
  188. if (raw & (1 << 4))
  189. v |= 0x02 << 4;
  190. else
  191. v |= 0x01 << 4;
  192. /* read the IPM field, bit2 and 3 of the config byte */
  193. v |= ipm_tbl[(raw >> 2) & 0x3];
  194. break;
  195. case SCR_ERROR:
  196. /* devices other than 5287 uses 0xA8 as base */
  197. WARN_ON(pdev->device != 0x5287);
  198. pci_read_config_dword(pdev, 0xB0 + slot * 4, &v);
  199. break;
  200. case SCR_CONTROL:
  201. pci_read_config_byte(pdev, 0xA4 + slot, &raw);
  202. /* read the DET field, bit0 and bit1 */
  203. v |= ((raw & 0x02) << 1) | (raw & 0x01);
  204. /* read the IPM field, bit2 and bit3 */
  205. v |= ((raw >> 2) & 0x03) << 8;
  206. break;
  207. default:
  208. return -EINVAL;
  209. }
  210. *val = v;
  211. return 0;
  212. }
  213. static int vt8251_scr_write(struct ata_link *link, unsigned int scr, u32 val)
  214. {
  215. struct pci_dev *pdev = to_pci_dev(link->ap->host->dev);
  216. int slot = 2 * link->ap->port_no + link->pmp;
  217. u32 v = 0;
  218. switch (scr) {
  219. case SCR_ERROR:
  220. /* devices other than 5287 uses 0xA8 as base */
  221. WARN_ON(pdev->device != 0x5287);
  222. pci_write_config_dword(pdev, 0xB0 + slot * 4, val);
  223. return 0;
  224. case SCR_CONTROL:
  225. /* set the DET field */
  226. v |= ((val & 0x4) >> 1) | (val & 0x1);
  227. /* set the IPM field */
  228. v |= ((val >> 8) & 0x3) << 2;
  229. pci_write_config_byte(pdev, 0xA4 + slot, v);
  230. return 0;
  231. default:
  232. return -EINVAL;
  233. }
  234. }
  235. /**
  236. * svia_tf_load - send taskfile registers to host controller
  237. * @ap: Port to which output is sent
  238. * @tf: ATA taskfile register set
  239. *
  240. * Outputs ATA taskfile to standard ATA host controller.
  241. *
  242. * This is to fix the internal bug of via chipsets, which will
  243. * reset the device register after changing the IEN bit on ctl
  244. * register.
  245. */
  246. static void svia_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
  247. {
  248. struct ata_taskfile ttf;
  249. if (tf->ctl != ap->last_ctl) {
  250. ttf = *tf;
  251. ttf.flags |= ATA_TFLAG_DEVICE;
  252. tf = &ttf;
  253. }
  254. ata_sff_tf_load(ap, tf);
  255. }
  256. static void svia_noop_freeze(struct ata_port *ap)
  257. {
  258. /* Some VIA controllers choke if ATA_NIEN is manipulated in
  259. * certain way. Leave it alone and just clear pending IRQ.
  260. */
  261. ap->ops->sff_check_status(ap);
  262. ata_sff_irq_clear(ap);
  263. }
  264. /**
  265. * vt6420_prereset - prereset for vt6420
  266. * @link: target ATA link
  267. * @deadline: deadline jiffies for the operation
  268. *
  269. * SCR registers on vt6420 are pieces of shit and may hang the
  270. * whole machine completely if accessed with the wrong timing.
  271. * To avoid such catastrophe, vt6420 doesn't provide generic SCR
  272. * access operations, but uses SStatus and SControl only during
  273. * boot probing in controlled way.
  274. *
  275. * As the old (pre EH update) probing code is proven to work, we
  276. * strictly follow the access pattern.
  277. *
  278. * LOCKING:
  279. * Kernel thread context (may sleep)
  280. *
  281. * RETURNS:
  282. * 0 on success, -errno otherwise.
  283. */
  284. static int vt6420_prereset(struct ata_link *link, unsigned long deadline)
  285. {
  286. struct ata_port *ap = link->ap;
  287. struct ata_eh_context *ehc = &ap->link.eh_context;
  288. unsigned long timeout = jiffies + (HZ * 5);
  289. u32 sstatus, scontrol;
  290. int online;
  291. /* don't do any SCR stuff if we're not loading */
  292. if (!(ap->pflags & ATA_PFLAG_LOADING))
  293. goto skip_scr;
  294. /* Resume phy. This is the old SATA resume sequence */
  295. svia_scr_write(link, SCR_CONTROL, 0x300);
  296. svia_scr_read(link, SCR_CONTROL, &scontrol); /* flush */
  297. /* wait for phy to become ready, if necessary */
  298. do {
  299. msleep(200);
  300. svia_scr_read(link, SCR_STATUS, &sstatus);
  301. if ((sstatus & 0xf) != 1)
  302. break;
  303. } while (time_before(jiffies, timeout));
  304. /* open code sata_print_link_status() */
  305. svia_scr_read(link, SCR_STATUS, &sstatus);
  306. svia_scr_read(link, SCR_CONTROL, &scontrol);
  307. online = (sstatus & 0xf) == 0x3;
  308. ata_port_printk(ap, KERN_INFO,
  309. "SATA link %s 1.5 Gbps (SStatus %X SControl %X)\n",
  310. online ? "up" : "down", sstatus, scontrol);
  311. /* SStatus is read one more time */
  312. svia_scr_read(link, SCR_STATUS, &sstatus);
  313. if (!online) {
  314. /* tell EH to bail */
  315. ehc->i.action &= ~ATA_EH_RESET;
  316. return 0;
  317. }
  318. skip_scr:
  319. /* wait for !BSY */
  320. ata_sff_wait_ready(link, deadline);
  321. return 0;
  322. }
  323. static int vt6421_pata_cable_detect(struct ata_port *ap)
  324. {
  325. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  326. u8 tmp;
  327. pci_read_config_byte(pdev, PATA_UDMA_TIMING, &tmp);
  328. if (tmp & 0x10)
  329. return ATA_CBL_PATA40;
  330. return ATA_CBL_PATA80;
  331. }
  332. static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev)
  333. {
  334. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  335. static const u8 pio_bits[] = { 0xA8, 0x65, 0x65, 0x31, 0x20 };
  336. pci_write_config_byte(pdev, PATA_PIO_TIMING, pio_bits[adev->pio_mode - XFER_PIO_0]);
  337. }
  338. static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev)
  339. {
  340. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  341. static const u8 udma_bits[] = { 0xEE, 0xE8, 0xE6, 0xE4, 0xE2, 0xE1, 0xE0, 0xE0 };
  342. pci_write_config_byte(pdev, PATA_UDMA_TIMING, udma_bits[adev->dma_mode - XFER_UDMA_0]);
  343. }
  344. static const unsigned int svia_bar_sizes[] = {
  345. 8, 4, 8, 4, 16, 256
  346. };
  347. static const unsigned int vt6421_bar_sizes[] = {
  348. 16, 16, 16, 16, 32, 128
  349. };
  350. static void __iomem *svia_scr_addr(void __iomem *addr, unsigned int port)
  351. {
  352. return addr + (port * 128);
  353. }
  354. static void __iomem *vt6421_scr_addr(void __iomem *addr, unsigned int port)
  355. {
  356. return addr + (port * 64);
  357. }
  358. static void vt6421_init_addrs(struct ata_port *ap)
  359. {
  360. void __iomem * const * iomap = ap->host->iomap;
  361. void __iomem *reg_addr = iomap[ap->port_no];
  362. void __iomem *bmdma_addr = iomap[4] + (ap->port_no * 8);
  363. struct ata_ioports *ioaddr = &ap->ioaddr;
  364. ioaddr->cmd_addr = reg_addr;
  365. ioaddr->altstatus_addr =
  366. ioaddr->ctl_addr = (void __iomem *)
  367. ((unsigned long)(reg_addr + 8) | ATA_PCI_CTL_OFS);
  368. ioaddr->bmdma_addr = bmdma_addr;
  369. ioaddr->scr_addr = vt6421_scr_addr(iomap[5], ap->port_no);
  370. ata_sff_std_ports(ioaddr);
  371. ata_port_pbar_desc(ap, ap->port_no, -1, "port");
  372. ata_port_pbar_desc(ap, 4, ap->port_no * 8, "bmdma");
  373. }
  374. static int vt6420_prepare_host(struct pci_dev *pdev, struct ata_host **r_host)
  375. {
  376. const struct ata_port_info *ppi[] = { &vt6420_port_info, NULL };
  377. struct ata_host *host;
  378. int rc;
  379. rc = ata_pci_sff_prepare_host(pdev, ppi, &host);
  380. if (rc)
  381. return rc;
  382. *r_host = host;
  383. rc = pcim_iomap_regions(pdev, 1 << 5, DRV_NAME);
  384. if (rc) {
  385. dev_printk(KERN_ERR, &pdev->dev, "failed to iomap PCI BAR 5\n");
  386. return rc;
  387. }
  388. host->ports[0]->ioaddr.scr_addr = svia_scr_addr(host->iomap[5], 0);
  389. host->ports[1]->ioaddr.scr_addr = svia_scr_addr(host->iomap[5], 1);
  390. return 0;
  391. }
  392. static int vt6421_prepare_host(struct pci_dev *pdev, struct ata_host **r_host)
  393. {
  394. const struct ata_port_info *ppi[] =
  395. { &vt6421_sport_info, &vt6421_sport_info, &vt6421_pport_info };
  396. struct ata_host *host;
  397. int i, rc;
  398. *r_host = host = ata_host_alloc_pinfo(&pdev->dev, ppi, ARRAY_SIZE(ppi));
  399. if (!host) {
  400. dev_printk(KERN_ERR, &pdev->dev, "failed to allocate host\n");
  401. return -ENOMEM;
  402. }
  403. rc = pcim_iomap_regions(pdev, 0x3f, DRV_NAME);
  404. if (rc) {
  405. dev_printk(KERN_ERR, &pdev->dev, "failed to request/iomap "
  406. "PCI BARs (errno=%d)\n", rc);
  407. return rc;
  408. }
  409. host->iomap = pcim_iomap_table(pdev);
  410. for (i = 0; i < host->n_ports; i++)
  411. vt6421_init_addrs(host->ports[i]);
  412. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  413. if (rc)
  414. return rc;
  415. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  416. if (rc)
  417. return rc;
  418. return 0;
  419. }
  420. static int vt8251_prepare_host(struct pci_dev *pdev, struct ata_host **r_host)
  421. {
  422. const struct ata_port_info *ppi[] = { &vt8251_port_info, NULL };
  423. struct ata_host *host;
  424. int i, rc;
  425. rc = ata_pci_sff_prepare_host(pdev, ppi, &host);
  426. if (rc)
  427. return rc;
  428. *r_host = host;
  429. rc = pcim_iomap_regions(pdev, 1 << 5, DRV_NAME);
  430. if (rc) {
  431. dev_printk(KERN_ERR, &pdev->dev, "failed to iomap PCI BAR 5\n");
  432. return rc;
  433. }
  434. /* 8251 hosts four sata ports as M/S of the two channels */
  435. for (i = 0; i < host->n_ports; i++)
  436. ata_slave_link_init(host->ports[i]);
  437. return 0;
  438. }
  439. static void svia_configure(struct pci_dev *pdev)
  440. {
  441. u8 tmp8;
  442. pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &tmp8);
  443. dev_printk(KERN_INFO, &pdev->dev, "routed to hard irq line %d\n",
  444. (int) (tmp8 & 0xf0) == 0xf0 ? 0 : tmp8 & 0x0f);
  445. /* make sure SATA channels are enabled */
  446. pci_read_config_byte(pdev, SATA_CHAN_ENAB, &tmp8);
  447. if ((tmp8 & ALL_PORTS) != ALL_PORTS) {
  448. dev_printk(KERN_DEBUG, &pdev->dev,
  449. "enabling SATA channels (0x%x)\n",
  450. (int) tmp8);
  451. tmp8 |= ALL_PORTS;
  452. pci_write_config_byte(pdev, SATA_CHAN_ENAB, tmp8);
  453. }
  454. /* make sure interrupts for each channel sent to us */
  455. pci_read_config_byte(pdev, SATA_INT_GATE, &tmp8);
  456. if ((tmp8 & ALL_PORTS) != ALL_PORTS) {
  457. dev_printk(KERN_DEBUG, &pdev->dev,
  458. "enabling SATA channel interrupts (0x%x)\n",
  459. (int) tmp8);
  460. tmp8 |= ALL_PORTS;
  461. pci_write_config_byte(pdev, SATA_INT_GATE, tmp8);
  462. }
  463. /* make sure native mode is enabled */
  464. pci_read_config_byte(pdev, SATA_NATIVE_MODE, &tmp8);
  465. if ((tmp8 & NATIVE_MODE_ALL) != NATIVE_MODE_ALL) {
  466. dev_printk(KERN_DEBUG, &pdev->dev,
  467. "enabling SATA channel native mode (0x%x)\n",
  468. (int) tmp8);
  469. tmp8 |= NATIVE_MODE_ALL;
  470. pci_write_config_byte(pdev, SATA_NATIVE_MODE, tmp8);
  471. }
  472. }
  473. static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  474. {
  475. static int printed_version;
  476. unsigned int i;
  477. int rc;
  478. struct ata_host *host;
  479. int board_id = (int) ent->driver_data;
  480. const unsigned *bar_sizes;
  481. if (!printed_version++)
  482. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  483. rc = pcim_enable_device(pdev);
  484. if (rc)
  485. return rc;
  486. if (board_id == vt6421)
  487. bar_sizes = &vt6421_bar_sizes[0];
  488. else
  489. bar_sizes = &svia_bar_sizes[0];
  490. for (i = 0; i < ARRAY_SIZE(svia_bar_sizes); i++)
  491. if ((pci_resource_start(pdev, i) == 0) ||
  492. (pci_resource_len(pdev, i) < bar_sizes[i])) {
  493. dev_printk(KERN_ERR, &pdev->dev,
  494. "invalid PCI BAR %u (sz 0x%llx, val 0x%llx)\n",
  495. i,
  496. (unsigned long long)pci_resource_start(pdev, i),
  497. (unsigned long long)pci_resource_len(pdev, i));
  498. return -ENODEV;
  499. }
  500. switch (board_id) {
  501. case vt6420:
  502. rc = vt6420_prepare_host(pdev, &host);
  503. break;
  504. case vt6421:
  505. rc = vt6421_prepare_host(pdev, &host);
  506. break;
  507. case vt8251:
  508. rc = vt8251_prepare_host(pdev, &host);
  509. break;
  510. default:
  511. rc = -EINVAL;
  512. }
  513. if (rc)
  514. return rc;
  515. svia_configure(pdev);
  516. pci_set_master(pdev);
  517. return ata_host_activate(host, pdev->irq, ata_sff_interrupt,
  518. IRQF_SHARED, &svia_sht);
  519. }
  520. static int __init svia_init(void)
  521. {
  522. return pci_register_driver(&svia_pci_driver);
  523. }
  524. static void __exit svia_exit(void)
  525. {
  526. pci_unregister_driver(&svia_pci_driver);
  527. }
  528. module_init(svia_init);
  529. module_exit(svia_exit);