pata_via.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /*
  2. * pata_via.c - VIA PATA for new ATA layer
  3. * (C) 2005-2006 Red Hat Inc
  4. * Alan Cox <alan@redhat.com>
  5. *
  6. * Documentation
  7. * Most chipset documentation available under NDA only
  8. *
  9. * VIA version guide
  10. * VIA VT82C561 - early design, uses ata_generic currently
  11. * VIA VT82C576 - MWDMA, 33Mhz
  12. * VIA VT82C586 - MWDMA, 33Mhz
  13. * VIA VT82C586a - Added UDMA to 33Mhz
  14. * VIA VT82C586b - UDMA33
  15. * VIA VT82C596a - Nonfunctional UDMA66
  16. * VIA VT82C596b - Working UDMA66
  17. * VIA VT82C686 - Nonfunctional UDMA66
  18. * VIA VT82C686a - Working UDMA66
  19. * VIA VT82C686b - Updated to UDMA100
  20. * VIA VT8231 - UDMA100
  21. * VIA VT8233 - UDMA100
  22. * VIA VT8233a - UDMA133
  23. * VIA VT8233c - UDMA100
  24. * VIA VT8235 - UDMA133
  25. * VIA VT8237 - UDMA133
  26. * VIA VT8237S - UDMA133
  27. * VIA VT8251 - UDMA133
  28. *
  29. * Most registers remain compatible across chips. Others start reserved
  30. * and acquire sensible semantics if set to 1 (eg cable detect). A few
  31. * exceptions exist, notably around the FIFO settings.
  32. *
  33. * One additional quirk of the VIA design is that like ALi they use few
  34. * PCI IDs for a lot of chips.
  35. *
  36. * Based heavily on:
  37. *
  38. * Version 3.38
  39. *
  40. * VIA IDE driver for Linux. Supported southbridges:
  41. *
  42. * vt82c576, vt82c586, vt82c586a, vt82c586b, vt82c596a, vt82c596b,
  43. * vt82c686, vt82c686a, vt82c686b, vt8231, vt8233, vt8233c, vt8233a,
  44. * vt8235, vt8237
  45. *
  46. * Copyright (c) 2000-2002 Vojtech Pavlik
  47. *
  48. * Based on the work of:
  49. * Michel Aubry
  50. * Jeff Garzik
  51. * Andre Hedrick
  52. */
  53. #include <linux/kernel.h>
  54. #include <linux/module.h>
  55. #include <linux/pci.h>
  56. #include <linux/init.h>
  57. #include <linux/blkdev.h>
  58. #include <linux/delay.h>
  59. #include <scsi/scsi_host.h>
  60. #include <linux/libata.h>
  61. #include <linux/dmi.h>
  62. #define DRV_NAME "pata_via"
  63. #define DRV_VERSION "0.3.3"
  64. /*
  65. * The following comes directly from Vojtech Pavlik's ide/pci/via82cxxx
  66. * driver.
  67. */
  68. enum {
  69. VIA_UDMA = 0x007,
  70. VIA_UDMA_NONE = 0x000,
  71. VIA_UDMA_33 = 0x001,
  72. VIA_UDMA_66 = 0x002,
  73. VIA_UDMA_100 = 0x003,
  74. VIA_UDMA_133 = 0x004,
  75. VIA_BAD_PREQ = 0x010, /* Crashes if PREQ# till DDACK# set */
  76. VIA_BAD_CLK66 = 0x020, /* 66 MHz clock doesn't work correctly */
  77. VIA_SET_FIFO = 0x040, /* Needs to have FIFO split set */
  78. VIA_NO_UNMASK = 0x080, /* Doesn't work with IRQ unmasking on */
  79. VIA_BAD_ID = 0x100, /* Has wrong vendor ID (0x1107) */
  80. VIA_BAD_AST = 0x200, /* Don't touch Address Setup Timing */
  81. VIA_NO_ENABLES = 0x400, /* Has no enablebits */
  82. VIA_SATA_PATA = 0x800, /* SATA/PATA combined configuration */
  83. };
  84. /*
  85. * VIA SouthBridge chips.
  86. */
  87. static const struct via_isa_bridge {
  88. const char *name;
  89. u16 id;
  90. u8 rev_min;
  91. u8 rev_max;
  92. u16 flags;
  93. } via_isa_bridges[] = {
  94. { "vx800", PCI_DEVICE_ID_VIA_VX800, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  95. { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  96. { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  97. { "cx700", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST | VIA_SATA_PATA },
  98. { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST | VIA_NO_ENABLES},
  99. { "vt8237a", PCI_DEVICE_ID_VIA_8237A, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  100. { "vt8237", PCI_DEVICE_ID_VIA_8237, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  101. { "vt8235", PCI_DEVICE_ID_VIA_8235, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  102. { "vt8233a", PCI_DEVICE_ID_VIA_8233A, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  103. { "vt8233c", PCI_DEVICE_ID_VIA_8233C_0, 0x00, 0x2f, VIA_UDMA_100 },
  104. { "vt8233", PCI_DEVICE_ID_VIA_8233_0, 0x00, 0x2f, VIA_UDMA_100 },
  105. { "vt8231", PCI_DEVICE_ID_VIA_8231, 0x00, 0x2f, VIA_UDMA_100 },
  106. { "vt82c686b", PCI_DEVICE_ID_VIA_82C686, 0x40, 0x4f, VIA_UDMA_100 },
  107. { "vt82c686a", PCI_DEVICE_ID_VIA_82C686, 0x10, 0x2f, VIA_UDMA_66 },
  108. { "vt82c686", PCI_DEVICE_ID_VIA_82C686, 0x00, 0x0f, VIA_UDMA_33 | VIA_BAD_CLK66 },
  109. { "vt82c596b", PCI_DEVICE_ID_VIA_82C596, 0x10, 0x2f, VIA_UDMA_66 },
  110. { "vt82c596a", PCI_DEVICE_ID_VIA_82C596, 0x00, 0x0f, VIA_UDMA_33 | VIA_BAD_CLK66 },
  111. { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x47, 0x4f, VIA_UDMA_33 | VIA_SET_FIFO },
  112. { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x40, 0x46, VIA_UDMA_33 | VIA_SET_FIFO | VIA_BAD_PREQ },
  113. { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x30, 0x3f, VIA_UDMA_33 | VIA_SET_FIFO },
  114. { "vt82c586a", PCI_DEVICE_ID_VIA_82C586_0, 0x20, 0x2f, VIA_UDMA_33 | VIA_SET_FIFO },
  115. { "vt82c586", PCI_DEVICE_ID_VIA_82C586_0, 0x00, 0x0f, VIA_UDMA_NONE | VIA_SET_FIFO },
  116. { "vt82c576", PCI_DEVICE_ID_VIA_82C576, 0x00, 0x2f, VIA_UDMA_NONE | VIA_SET_FIFO | VIA_NO_UNMASK },
  117. { "vt82c576", PCI_DEVICE_ID_VIA_82C576, 0x00, 0x2f, VIA_UDMA_NONE | VIA_SET_FIFO | VIA_NO_UNMASK | VIA_BAD_ID },
  118. { NULL }
  119. };
  120. /*
  121. * Cable special cases
  122. */
  123. static const struct dmi_system_id cable_dmi_table[] = {
  124. {
  125. .ident = "Acer Ferrari 3400",
  126. .matches = {
  127. DMI_MATCH(DMI_BOARD_VENDOR, "Acer,Inc."),
  128. DMI_MATCH(DMI_BOARD_NAME, "Ferrari 3400"),
  129. },
  130. },
  131. { }
  132. };
  133. static int via_cable_override(struct pci_dev *pdev)
  134. {
  135. /* Systems by DMI */
  136. if (dmi_check_system(cable_dmi_table))
  137. return 1;
  138. /* Arima W730-K8/Targa Visionary 811/... */
  139. if (pdev->subsystem_vendor == 0x161F && pdev->subsystem_device == 0x2032)
  140. return 1;
  141. return 0;
  142. }
  143. /**
  144. * via_cable_detect - cable detection
  145. * @ap: ATA port
  146. *
  147. * Perform cable detection. Actually for the VIA case the BIOS
  148. * already did this for us. We read the values provided by the
  149. * BIOS. If you are using an 8235 in a non-PC configuration you
  150. * may need to update this code.
  151. *
  152. * Hotplug also impacts on this.
  153. */
  154. static int via_cable_detect(struct ata_port *ap) {
  155. const struct via_isa_bridge *config = ap->host->private_data;
  156. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  157. u32 ata66;
  158. if (via_cable_override(pdev))
  159. return ATA_CBL_PATA40_SHORT;
  160. if ((config->flags & VIA_SATA_PATA) && ap->port_no == 0)
  161. return ATA_CBL_SATA;
  162. /* Early chips are 40 wire */
  163. if ((config->flags & VIA_UDMA) < VIA_UDMA_66)
  164. return ATA_CBL_PATA40;
  165. /* UDMA 66 chips have only drive side logic */
  166. else if ((config->flags & VIA_UDMA) < VIA_UDMA_100)
  167. return ATA_CBL_PATA_UNK;
  168. /* UDMA 100 or later */
  169. pci_read_config_dword(pdev, 0x50, &ata66);
  170. /* Check both the drive cable reporting bits, we might not have
  171. two drives */
  172. if (ata66 & (0x10100000 >> (16 * ap->port_no)))
  173. return ATA_CBL_PATA80;
  174. /* Check with ACPI so we can spot BIOS reported SATA bridges */
  175. if (ata_acpi_init_gtm(ap) &&
  176. ata_acpi_cbl_80wire(ap, ata_acpi_init_gtm(ap)))
  177. return ATA_CBL_PATA80;
  178. return ATA_CBL_PATA40;
  179. }
  180. static int via_pre_reset(struct ata_link *link, unsigned long deadline)
  181. {
  182. struct ata_port *ap = link->ap;
  183. const struct via_isa_bridge *config = ap->host->private_data;
  184. if (!(config->flags & VIA_NO_ENABLES)) {
  185. static const struct pci_bits via_enable_bits[] = {
  186. { 0x40, 1, 0x02, 0x02 },
  187. { 0x40, 1, 0x01, 0x01 }
  188. };
  189. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  190. if (!pci_test_config_bits(pdev, &via_enable_bits[ap->port_no]))
  191. return -ENOENT;
  192. }
  193. return ata_std_prereset(link, deadline);
  194. }
  195. /**
  196. * via_error_handler - reset for VIA chips
  197. * @ap: ATA port
  198. *
  199. * Handle the reset callback for the later chips with cable detect
  200. */
  201. static void via_error_handler(struct ata_port *ap)
  202. {
  203. ata_bmdma_drive_eh(ap, via_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  204. }
  205. /**
  206. * via_do_set_mode - set initial PIO mode data
  207. * @ap: ATA interface
  208. * @adev: ATA device
  209. * @mode: ATA mode being programmed
  210. * @tdiv: Clocks per PCI clock
  211. * @set_ast: Set to program address setup
  212. * @udma_type: UDMA mode/format of registers
  213. *
  214. * Program the VIA registers for DMA and PIO modes. Uses the ata timing
  215. * support in order to compute modes.
  216. *
  217. * FIXME: Hotplug will require we serialize multiple mode changes
  218. * on the two channels.
  219. */
  220. static void via_do_set_mode(struct ata_port *ap, struct ata_device *adev, int mode, int tdiv, int set_ast, int udma_type)
  221. {
  222. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  223. struct ata_device *peer = ata_dev_pair(adev);
  224. struct ata_timing t, p;
  225. static int via_clock = 33333; /* Bus clock in kHZ - ought to be tunable one day */
  226. unsigned long T = 1000000000 / via_clock;
  227. unsigned long UT = T/tdiv;
  228. int ut;
  229. int offset = 3 - (2*ap->port_no) - adev->devno;
  230. /* Calculate the timing values we require */
  231. ata_timing_compute(adev, mode, &t, T, UT);
  232. /* We share 8bit timing so we must merge the constraints */
  233. if (peer) {
  234. if (peer->pio_mode) {
  235. ata_timing_compute(peer, peer->pio_mode, &p, T, UT);
  236. ata_timing_merge(&p, &t, &t, ATA_TIMING_8BIT);
  237. }
  238. }
  239. /* Address setup is programmable but breaks on UDMA133 setups */
  240. if (set_ast) {
  241. u8 setup; /* 2 bits per drive */
  242. int shift = 2 * offset;
  243. pci_read_config_byte(pdev, 0x4C, &setup);
  244. setup &= ~(3 << shift);
  245. setup |= FIT(t.setup, 1, 4) << shift; /* 1,4 or 1,4 - 1 FIXME */
  246. pci_write_config_byte(pdev, 0x4C, setup);
  247. }
  248. /* Load the PIO mode bits */
  249. pci_write_config_byte(pdev, 0x4F - ap->port_no,
  250. ((FIT(t.act8b, 1, 16) - 1) << 4) | (FIT(t.rec8b, 1, 16) - 1));
  251. pci_write_config_byte(pdev, 0x48 + offset,
  252. ((FIT(t.active, 1, 16) - 1) << 4) | (FIT(t.recover, 1, 16) - 1));
  253. /* Load the UDMA bits according to type */
  254. switch(udma_type) {
  255. default:
  256. /* BUG() ? */
  257. /* fall through */
  258. case 33:
  259. ut = t.udma ? (0xe0 | (FIT(t.udma, 2, 5) - 2)) : 0x03;
  260. break;
  261. case 66:
  262. ut = t.udma ? (0xe8 | (FIT(t.udma, 2, 9) - 2)) : 0x0f;
  263. break;
  264. case 100:
  265. ut = t.udma ? (0xe0 | (FIT(t.udma, 2, 9) - 2)) : 0x07;
  266. break;
  267. case 133:
  268. ut = t.udma ? (0xe0 | (FIT(t.udma, 2, 9) - 2)) : 0x07;
  269. break;
  270. }
  271. /* Set UDMA unless device is not UDMA capable */
  272. if (udma_type && t.udma) {
  273. u8 cable80_status;
  274. /* Get 80-wire cable detection bit */
  275. pci_read_config_byte(pdev, 0x50 + offset, &cable80_status);
  276. cable80_status &= 0x10;
  277. pci_write_config_byte(pdev, 0x50 + offset, ut | cable80_status);
  278. }
  279. }
  280. static void via_set_piomode(struct ata_port *ap, struct ata_device *adev)
  281. {
  282. const struct via_isa_bridge *config = ap->host->private_data;
  283. int set_ast = (config->flags & VIA_BAD_AST) ? 0 : 1;
  284. int mode = config->flags & VIA_UDMA;
  285. static u8 tclock[5] = { 1, 1, 2, 3, 4 };
  286. static u8 udma[5] = { 0, 33, 66, 100, 133 };
  287. via_do_set_mode(ap, adev, adev->pio_mode, tclock[mode], set_ast, udma[mode]);
  288. }
  289. static void via_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  290. {
  291. const struct via_isa_bridge *config = ap->host->private_data;
  292. int set_ast = (config->flags & VIA_BAD_AST) ? 0 : 1;
  293. int mode = config->flags & VIA_UDMA;
  294. static u8 tclock[5] = { 1, 1, 2, 3, 4 };
  295. static u8 udma[5] = { 0, 33, 66, 100, 133 };
  296. via_do_set_mode(ap, adev, adev->dma_mode, tclock[mode], set_ast, udma[mode]);
  297. }
  298. static struct scsi_host_template via_sht = {
  299. ATA_BMDMA_SHT(DRV_NAME),
  300. };
  301. static struct ata_port_operations via_port_ops = {
  302. .inherits = &ata_bmdma_port_ops,
  303. .cable_detect = via_cable_detect,
  304. .set_piomode = via_set_piomode,
  305. .set_dmamode = via_set_dmamode,
  306. .error_handler = via_error_handler,
  307. };
  308. static struct ata_port_operations via_port_ops_noirq = {
  309. .inherits = &via_port_ops,
  310. .data_xfer = ata_data_xfer_noirq,
  311. };
  312. /**
  313. * via_config_fifo - set up the FIFO
  314. * @pdev: PCI device
  315. * @flags: configuration flags
  316. *
  317. * Set the FIFO properties for this device if necessary. Used both on
  318. * set up and on and the resume path
  319. */
  320. static void via_config_fifo(struct pci_dev *pdev, unsigned int flags)
  321. {
  322. u8 enable;
  323. /* 0x40 low bits indicate enabled channels */
  324. pci_read_config_byte(pdev, 0x40 , &enable);
  325. enable &= 3;
  326. if (flags & VIA_SET_FIFO) {
  327. static const u8 fifo_setting[4] = {0x00, 0x60, 0x00, 0x20};
  328. u8 fifo;
  329. pci_read_config_byte(pdev, 0x43, &fifo);
  330. /* Clear PREQ# until DDACK# for errata */
  331. if (flags & VIA_BAD_PREQ)
  332. fifo &= 0x7F;
  333. else
  334. fifo &= 0x9f;
  335. /* Turn on FIFO for enabled channels */
  336. fifo |= fifo_setting[enable];
  337. pci_write_config_byte(pdev, 0x43, fifo);
  338. }
  339. }
  340. /**
  341. * via_init_one - discovery callback
  342. * @pdev: PCI device
  343. * @id: PCI table info
  344. *
  345. * A VIA IDE interface has been discovered. Figure out what revision
  346. * and perform configuration work before handing it to the ATA layer
  347. */
  348. static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  349. {
  350. /* Early VIA without UDMA support */
  351. static const struct ata_port_info via_mwdma_info = {
  352. .flags = ATA_FLAG_SLAVE_POSS,
  353. .pio_mask = 0x1f,
  354. .mwdma_mask = 0x07,
  355. .port_ops = &via_port_ops
  356. };
  357. /* Ditto with IRQ masking required */
  358. static const struct ata_port_info via_mwdma_info_borked = {
  359. .flags = ATA_FLAG_SLAVE_POSS,
  360. .pio_mask = 0x1f,
  361. .mwdma_mask = 0x07,
  362. .port_ops = &via_port_ops_noirq,
  363. };
  364. /* VIA UDMA 33 devices (and borked 66) */
  365. static const struct ata_port_info via_udma33_info = {
  366. .flags = ATA_FLAG_SLAVE_POSS,
  367. .pio_mask = 0x1f,
  368. .mwdma_mask = 0x07,
  369. .udma_mask = ATA_UDMA2,
  370. .port_ops = &via_port_ops
  371. };
  372. /* VIA UDMA 66 devices */
  373. static const struct ata_port_info via_udma66_info = {
  374. .flags = ATA_FLAG_SLAVE_POSS,
  375. .pio_mask = 0x1f,
  376. .mwdma_mask = 0x07,
  377. .udma_mask = ATA_UDMA4,
  378. .port_ops = &via_port_ops
  379. };
  380. /* VIA UDMA 100 devices */
  381. static const struct ata_port_info via_udma100_info = {
  382. .flags = ATA_FLAG_SLAVE_POSS,
  383. .pio_mask = 0x1f,
  384. .mwdma_mask = 0x07,
  385. .udma_mask = ATA_UDMA5,
  386. .port_ops = &via_port_ops
  387. };
  388. /* UDMA133 with bad AST (All current 133) */
  389. static const struct ata_port_info via_udma133_info = {
  390. .flags = ATA_FLAG_SLAVE_POSS,
  391. .pio_mask = 0x1f,
  392. .mwdma_mask = 0x07,
  393. .udma_mask = ATA_UDMA6, /* FIXME: should check north bridge */
  394. .port_ops = &via_port_ops
  395. };
  396. struct ata_port_info type;
  397. const struct ata_port_info *ppi[] = { &type, NULL };
  398. struct pci_dev *isa = NULL;
  399. const struct via_isa_bridge *config;
  400. static int printed_version;
  401. u8 enable;
  402. u32 timing;
  403. int rc;
  404. if (!printed_version++)
  405. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  406. rc = pcim_enable_device(pdev);
  407. if (rc)
  408. return rc;
  409. /* To find out how the IDE will behave and what features we
  410. actually have to look at the bridge not the IDE controller */
  411. for (config = via_isa_bridges; config->id; config++)
  412. if ((isa = pci_get_device(PCI_VENDOR_ID_VIA +
  413. !!(config->flags & VIA_BAD_ID),
  414. config->id, NULL))) {
  415. if (isa->revision >= config->rev_min &&
  416. isa->revision <= config->rev_max)
  417. break;
  418. pci_dev_put(isa);
  419. }
  420. if (!config->id) {
  421. printk(KERN_WARNING "via: Unknown VIA SouthBridge, disabling.\n");
  422. return -ENODEV;
  423. }
  424. pci_dev_put(isa);
  425. /* 0x40 low bits indicate enabled channels */
  426. pci_read_config_byte(pdev, 0x40 , &enable);
  427. enable &= 3;
  428. if (enable == 0) {
  429. return -ENODEV;
  430. }
  431. /* Initialise the FIFO for the enabled channels. */
  432. via_config_fifo(pdev, config->flags);
  433. /* Clock set up */
  434. switch(config->flags & VIA_UDMA) {
  435. case VIA_UDMA_NONE:
  436. if (config->flags & VIA_NO_UNMASK)
  437. type = via_mwdma_info_borked;
  438. else
  439. type = via_mwdma_info;
  440. break;
  441. case VIA_UDMA_33:
  442. type = via_udma33_info;
  443. break;
  444. case VIA_UDMA_66:
  445. type = via_udma66_info;
  446. /* The 66 MHz devices require we enable the clock */
  447. pci_read_config_dword(pdev, 0x50, &timing);
  448. timing |= 0x80008;
  449. pci_write_config_dword(pdev, 0x50, timing);
  450. break;
  451. case VIA_UDMA_100:
  452. type = via_udma100_info;
  453. break;
  454. case VIA_UDMA_133:
  455. type = via_udma133_info;
  456. break;
  457. default:
  458. WARN_ON(1);
  459. return -ENODEV;
  460. }
  461. if (config->flags & VIA_BAD_CLK66) {
  462. /* Disable the 66MHz clock on problem devices */
  463. pci_read_config_dword(pdev, 0x50, &timing);
  464. timing &= ~0x80008;
  465. pci_write_config_dword(pdev, 0x50, timing);
  466. }
  467. /* We have established the device type, now fire it up */
  468. type.private_data = (void *)config;
  469. return ata_pci_init_one(pdev, ppi, &via_sht);
  470. }
  471. #ifdef CONFIG_PM
  472. /**
  473. * via_reinit_one - reinit after resume
  474. * @pdev; PCI device
  475. *
  476. * Called when the VIA PATA device is resumed. We must then
  477. * reconfigure the fifo and other setup we may have altered. In
  478. * addition the kernel needs to have the resume methods on PCI
  479. * quirk supported.
  480. */
  481. static int via_reinit_one(struct pci_dev *pdev)
  482. {
  483. u32 timing;
  484. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  485. const struct via_isa_bridge *config = host->private_data;
  486. int rc;
  487. rc = ata_pci_device_do_resume(pdev);
  488. if (rc)
  489. return rc;
  490. via_config_fifo(pdev, config->flags);
  491. if ((config->flags & VIA_UDMA) == VIA_UDMA_66) {
  492. /* The 66 MHz devices require we enable the clock */
  493. pci_read_config_dword(pdev, 0x50, &timing);
  494. timing |= 0x80008;
  495. pci_write_config_dword(pdev, 0x50, timing);
  496. }
  497. if (config->flags & VIA_BAD_CLK66) {
  498. /* Disable the 66MHz clock on problem devices */
  499. pci_read_config_dword(pdev, 0x50, &timing);
  500. timing &= ~0x80008;
  501. pci_write_config_dword(pdev, 0x50, timing);
  502. }
  503. ata_host_resume(host);
  504. return 0;
  505. }
  506. #endif
  507. static const struct pci_device_id via[] = {
  508. { PCI_VDEVICE(VIA, 0x0571), },
  509. { PCI_VDEVICE(VIA, 0x0581), },
  510. { PCI_VDEVICE(VIA, 0x1571), },
  511. { PCI_VDEVICE(VIA, 0x3164), },
  512. { PCI_VDEVICE(VIA, 0x5324), },
  513. { },
  514. };
  515. static struct pci_driver via_pci_driver = {
  516. .name = DRV_NAME,
  517. .id_table = via,
  518. .probe = via_init_one,
  519. .remove = ata_pci_remove_one,
  520. #ifdef CONFIG_PM
  521. .suspend = ata_pci_device_suspend,
  522. .resume = via_reinit_one,
  523. #endif
  524. };
  525. static int __init via_init(void)
  526. {
  527. return pci_register_driver(&via_pci_driver);
  528. }
  529. static void __exit via_exit(void)
  530. {
  531. pci_unregister_driver(&via_pci_driver);
  532. }
  533. MODULE_AUTHOR("Alan Cox");
  534. MODULE_DESCRIPTION("low-level driver for VIA PATA");
  535. MODULE_LICENSE("GPL");
  536. MODULE_DEVICE_TABLE(pci, via);
  537. MODULE_VERSION(DRV_VERSION);
  538. module_init(via_init);
  539. module_exit(via_exit);