pata_via.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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. };
  83. /*
  84. * VIA SouthBridge chips.
  85. */
  86. static const struct via_isa_bridge {
  87. const char *name;
  88. u16 id;
  89. u8 rev_min;
  90. u8 rev_max;
  91. u16 flags;
  92. } via_isa_bridges[] = {
  93. { "vx800", PCI_DEVICE_ID_VIA_VX800, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  94. { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  95. { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  96. { "cx700", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  97. { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST | VIA_NO_ENABLES},
  98. { "vt8237a", PCI_DEVICE_ID_VIA_8237A, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  99. { "vt8237", PCI_DEVICE_ID_VIA_8237, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  100. { "vt8235", PCI_DEVICE_ID_VIA_8235, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  101. { "vt8233a", PCI_DEVICE_ID_VIA_8233A, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
  102. { "vt8233c", PCI_DEVICE_ID_VIA_8233C_0, 0x00, 0x2f, VIA_UDMA_100 },
  103. { "vt8233", PCI_DEVICE_ID_VIA_8233_0, 0x00, 0x2f, VIA_UDMA_100 },
  104. { "vt8231", PCI_DEVICE_ID_VIA_8231, 0x00, 0x2f, VIA_UDMA_100 },
  105. { "vt82c686b", PCI_DEVICE_ID_VIA_82C686, 0x40, 0x4f, VIA_UDMA_100 },
  106. { "vt82c686a", PCI_DEVICE_ID_VIA_82C686, 0x10, 0x2f, VIA_UDMA_66 },
  107. { "vt82c686", PCI_DEVICE_ID_VIA_82C686, 0x00, 0x0f, VIA_UDMA_33 | VIA_BAD_CLK66 },
  108. { "vt82c596b", PCI_DEVICE_ID_VIA_82C596, 0x10, 0x2f, VIA_UDMA_66 },
  109. { "vt82c596a", PCI_DEVICE_ID_VIA_82C596, 0x00, 0x0f, VIA_UDMA_33 | VIA_BAD_CLK66 },
  110. { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x47, 0x4f, VIA_UDMA_33 | VIA_SET_FIFO },
  111. { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x40, 0x46, VIA_UDMA_33 | VIA_SET_FIFO | VIA_BAD_PREQ },
  112. { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x30, 0x3f, VIA_UDMA_33 | VIA_SET_FIFO },
  113. { "vt82c586a", PCI_DEVICE_ID_VIA_82C586_0, 0x20, 0x2f, VIA_UDMA_33 | VIA_SET_FIFO },
  114. { "vt82c586", PCI_DEVICE_ID_VIA_82C586_0, 0x00, 0x0f, VIA_UDMA_NONE | VIA_SET_FIFO },
  115. { "vt82c576", PCI_DEVICE_ID_VIA_82C576, 0x00, 0x2f, VIA_UDMA_NONE | VIA_SET_FIFO | VIA_NO_UNMASK },
  116. { "vt82c576", PCI_DEVICE_ID_VIA_82C576, 0x00, 0x2f, VIA_UDMA_NONE | VIA_SET_FIFO | VIA_NO_UNMASK | VIA_BAD_ID },
  117. { NULL }
  118. };
  119. /*
  120. * Cable special cases
  121. */
  122. static const struct dmi_system_id cable_dmi_table[] = {
  123. {
  124. .ident = "Acer Ferrari 3400",
  125. .matches = {
  126. DMI_MATCH(DMI_BOARD_VENDOR, "Acer,Inc."),
  127. DMI_MATCH(DMI_BOARD_NAME, "Ferrari 3400"),
  128. },
  129. },
  130. { }
  131. };
  132. static int via_cable_override(struct pci_dev *pdev)
  133. {
  134. /* Systems by DMI */
  135. if (dmi_check_system(cable_dmi_table))
  136. return 1;
  137. /* Arima W730-K8/Targa Visionary 811/... */
  138. if (pdev->subsystem_vendor == 0x161F && pdev->subsystem_device == 0x2032)
  139. return 1;
  140. return 0;
  141. }
  142. /**
  143. * via_cable_detect - cable detection
  144. * @ap: ATA port
  145. *
  146. * Perform cable detection. Actually for the VIA case the BIOS
  147. * already did this for us. We read the values provided by the
  148. * BIOS. If you are using an 8235 in a non-PC configuration you
  149. * may need to update this code.
  150. *
  151. * Hotplug also impacts on this.
  152. */
  153. static int via_cable_detect(struct ata_port *ap) {
  154. const struct via_isa_bridge *config = ap->host->private_data;
  155. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  156. u32 ata66;
  157. if (via_cable_override(pdev))
  158. return ATA_CBL_PATA40_SHORT;
  159. /* Early chips are 40 wire */
  160. if ((config->flags & VIA_UDMA) < VIA_UDMA_66)
  161. return ATA_CBL_PATA40;
  162. /* UDMA 66 chips have only drive side logic */
  163. else if ((config->flags & VIA_UDMA) < VIA_UDMA_100)
  164. return ATA_CBL_PATA_UNK;
  165. /* UDMA 100 or later */
  166. pci_read_config_dword(pdev, 0x50, &ata66);
  167. /* Check both the drive cable reporting bits, we might not have
  168. two drives */
  169. if (ata66 & (0x10100000 >> (16 * ap->port_no)))
  170. return ATA_CBL_PATA80;
  171. /* Check with ACPI so we can spot BIOS reported SATA bridges */
  172. if (ata_acpi_init_gtm(ap) &&
  173. ata_acpi_cbl_80wire(ap, ata_acpi_init_gtm(ap)))
  174. return ATA_CBL_PATA80;
  175. return ATA_CBL_PATA40;
  176. }
  177. static int via_pre_reset(struct ata_link *link, unsigned long deadline)
  178. {
  179. struct ata_port *ap = link->ap;
  180. const struct via_isa_bridge *config = ap->host->private_data;
  181. if (!(config->flags & VIA_NO_ENABLES)) {
  182. static const struct pci_bits via_enable_bits[] = {
  183. { 0x40, 1, 0x02, 0x02 },
  184. { 0x40, 1, 0x01, 0x01 }
  185. };
  186. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  187. if (!pci_test_config_bits(pdev, &via_enable_bits[ap->port_no]))
  188. return -ENOENT;
  189. }
  190. return ata_std_prereset(link, deadline);
  191. }
  192. /**
  193. * via_error_handler - reset for VIA chips
  194. * @ap: ATA port
  195. *
  196. * Handle the reset callback for the later chips with cable detect
  197. */
  198. static void via_error_handler(struct ata_port *ap)
  199. {
  200. ata_bmdma_drive_eh(ap, via_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  201. }
  202. /**
  203. * via_do_set_mode - set initial PIO mode data
  204. * @ap: ATA interface
  205. * @adev: ATA device
  206. * @mode: ATA mode being programmed
  207. * @tdiv: Clocks per PCI clock
  208. * @set_ast: Set to program address setup
  209. * @udma_type: UDMA mode/format of registers
  210. *
  211. * Program the VIA registers for DMA and PIO modes. Uses the ata timing
  212. * support in order to compute modes.
  213. *
  214. * FIXME: Hotplug will require we serialize multiple mode changes
  215. * on the two channels.
  216. */
  217. static void via_do_set_mode(struct ata_port *ap, struct ata_device *adev, int mode, int tdiv, int set_ast, int udma_type)
  218. {
  219. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  220. struct ata_device *peer = ata_dev_pair(adev);
  221. struct ata_timing t, p;
  222. static int via_clock = 33333; /* Bus clock in kHZ - ought to be tunable one day */
  223. unsigned long T = 1000000000 / via_clock;
  224. unsigned long UT = T/tdiv;
  225. int ut;
  226. int offset = 3 - (2*ap->port_no) - adev->devno;
  227. /* Calculate the timing values we require */
  228. ata_timing_compute(adev, mode, &t, T, UT);
  229. /* We share 8bit timing so we must merge the constraints */
  230. if (peer) {
  231. if (peer->pio_mode) {
  232. ata_timing_compute(peer, peer->pio_mode, &p, T, UT);
  233. ata_timing_merge(&p, &t, &t, ATA_TIMING_8BIT);
  234. }
  235. }
  236. /* Address setup is programmable but breaks on UDMA133 setups */
  237. if (set_ast) {
  238. u8 setup; /* 2 bits per drive */
  239. int shift = 2 * offset;
  240. pci_read_config_byte(pdev, 0x4C, &setup);
  241. setup &= ~(3 << shift);
  242. setup |= FIT(t.setup, 1, 4) << shift; /* 1,4 or 1,4 - 1 FIXME */
  243. pci_write_config_byte(pdev, 0x4C, setup);
  244. }
  245. /* Load the PIO mode bits */
  246. pci_write_config_byte(pdev, 0x4F - ap->port_no,
  247. ((FIT(t.act8b, 1, 16) - 1) << 4) | (FIT(t.rec8b, 1, 16) - 1));
  248. pci_write_config_byte(pdev, 0x48 + offset,
  249. ((FIT(t.active, 1, 16) - 1) << 4) | (FIT(t.recover, 1, 16) - 1));
  250. /* Load the UDMA bits according to type */
  251. switch(udma_type) {
  252. default:
  253. /* BUG() ? */
  254. /* fall through */
  255. case 33:
  256. ut = t.udma ? (0xe0 | (FIT(t.udma, 2, 5) - 2)) : 0x03;
  257. break;
  258. case 66:
  259. ut = t.udma ? (0xe8 | (FIT(t.udma, 2, 9) - 2)) : 0x0f;
  260. break;
  261. case 100:
  262. ut = t.udma ? (0xe0 | (FIT(t.udma, 2, 9) - 2)) : 0x07;
  263. break;
  264. case 133:
  265. ut = t.udma ? (0xe0 | (FIT(t.udma, 2, 9) - 2)) : 0x07;
  266. break;
  267. }
  268. /* Set UDMA unless device is not UDMA capable */
  269. if (udma_type && t.udma) {
  270. u8 cable80_status;
  271. /* Get 80-wire cable detection bit */
  272. pci_read_config_byte(pdev, 0x50 + offset, &cable80_status);
  273. cable80_status &= 0x10;
  274. pci_write_config_byte(pdev, 0x50 + offset, ut | cable80_status);
  275. }
  276. }
  277. static void via_set_piomode(struct ata_port *ap, struct ata_device *adev)
  278. {
  279. const struct via_isa_bridge *config = ap->host->private_data;
  280. int set_ast = (config->flags & VIA_BAD_AST) ? 0 : 1;
  281. int mode = config->flags & VIA_UDMA;
  282. static u8 tclock[5] = { 1, 1, 2, 3, 4 };
  283. static u8 udma[5] = { 0, 33, 66, 100, 133 };
  284. via_do_set_mode(ap, adev, adev->pio_mode, tclock[mode], set_ast, udma[mode]);
  285. }
  286. static void via_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  287. {
  288. const struct via_isa_bridge *config = ap->host->private_data;
  289. int set_ast = (config->flags & VIA_BAD_AST) ? 0 : 1;
  290. int mode = config->flags & VIA_UDMA;
  291. static u8 tclock[5] = { 1, 1, 2, 3, 4 };
  292. static u8 udma[5] = { 0, 33, 66, 100, 133 };
  293. via_do_set_mode(ap, adev, adev->dma_mode, tclock[mode], set_ast, udma[mode]);
  294. }
  295. static struct scsi_host_template via_sht = {
  296. .module = THIS_MODULE,
  297. .name = DRV_NAME,
  298. .ioctl = ata_scsi_ioctl,
  299. .queuecommand = ata_scsi_queuecmd,
  300. .can_queue = ATA_DEF_QUEUE,
  301. .this_id = ATA_SHT_THIS_ID,
  302. .sg_tablesize = LIBATA_MAX_PRD,
  303. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  304. .emulated = ATA_SHT_EMULATED,
  305. .use_clustering = ATA_SHT_USE_CLUSTERING,
  306. .proc_name = DRV_NAME,
  307. .dma_boundary = ATA_DMA_BOUNDARY,
  308. .slave_configure = ata_scsi_slave_config,
  309. .slave_destroy = ata_scsi_slave_destroy,
  310. .bios_param = ata_std_bios_param,
  311. };
  312. static struct ata_port_operations via_port_ops = {
  313. .set_piomode = via_set_piomode,
  314. .set_dmamode = via_set_dmamode,
  315. .mode_filter = ata_pci_default_filter,
  316. .tf_load = ata_tf_load,
  317. .tf_read = ata_tf_read,
  318. .check_status = ata_check_status,
  319. .exec_command = ata_exec_command,
  320. .dev_select = ata_std_dev_select,
  321. .freeze = ata_bmdma_freeze,
  322. .thaw = ata_bmdma_thaw,
  323. .error_handler = via_error_handler,
  324. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  325. .cable_detect = via_cable_detect,
  326. .bmdma_setup = ata_bmdma_setup,
  327. .bmdma_start = ata_bmdma_start,
  328. .bmdma_stop = ata_bmdma_stop,
  329. .bmdma_status = ata_bmdma_status,
  330. .qc_prep = ata_qc_prep,
  331. .qc_issue = ata_qc_issue_prot,
  332. .data_xfer = ata_data_xfer,
  333. .irq_handler = ata_interrupt,
  334. .irq_clear = ata_bmdma_irq_clear,
  335. .irq_on = ata_irq_on,
  336. .port_start = ata_sff_port_start,
  337. };
  338. static struct ata_port_operations via_port_ops_noirq = {
  339. .set_piomode = via_set_piomode,
  340. .set_dmamode = via_set_dmamode,
  341. .mode_filter = ata_pci_default_filter,
  342. .tf_load = ata_tf_load,
  343. .tf_read = ata_tf_read,
  344. .check_status = ata_check_status,
  345. .exec_command = ata_exec_command,
  346. .dev_select = ata_std_dev_select,
  347. .freeze = ata_bmdma_freeze,
  348. .thaw = ata_bmdma_thaw,
  349. .error_handler = via_error_handler,
  350. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  351. .cable_detect = via_cable_detect,
  352. .bmdma_setup = ata_bmdma_setup,
  353. .bmdma_start = ata_bmdma_start,
  354. .bmdma_stop = ata_bmdma_stop,
  355. .bmdma_status = ata_bmdma_status,
  356. .qc_prep = ata_qc_prep,
  357. .qc_issue = ata_qc_issue_prot,
  358. .data_xfer = ata_data_xfer_noirq,
  359. .irq_handler = ata_interrupt,
  360. .irq_clear = ata_bmdma_irq_clear,
  361. .irq_on = ata_irq_on,
  362. .port_start = ata_sff_port_start,
  363. };
  364. /**
  365. * via_config_fifo - set up the FIFO
  366. * @pdev: PCI device
  367. * @flags: configuration flags
  368. *
  369. * Set the FIFO properties for this device if necessary. Used both on
  370. * set up and on and the resume path
  371. */
  372. static void via_config_fifo(struct pci_dev *pdev, unsigned int flags)
  373. {
  374. u8 enable;
  375. /* 0x40 low bits indicate enabled channels */
  376. pci_read_config_byte(pdev, 0x40 , &enable);
  377. enable &= 3;
  378. if (flags & VIA_SET_FIFO) {
  379. static const u8 fifo_setting[4] = {0x00, 0x60, 0x00, 0x20};
  380. u8 fifo;
  381. pci_read_config_byte(pdev, 0x43, &fifo);
  382. /* Clear PREQ# until DDACK# for errata */
  383. if (flags & VIA_BAD_PREQ)
  384. fifo &= 0x7F;
  385. else
  386. fifo &= 0x9f;
  387. /* Turn on FIFO for enabled channels */
  388. fifo |= fifo_setting[enable];
  389. pci_write_config_byte(pdev, 0x43, fifo);
  390. }
  391. }
  392. /**
  393. * via_init_one - discovery callback
  394. * @pdev: PCI device
  395. * @id: PCI table info
  396. *
  397. * A VIA IDE interface has been discovered. Figure out what revision
  398. * and perform configuration work before handing it to the ATA layer
  399. */
  400. static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  401. {
  402. /* Early VIA without UDMA support */
  403. static const struct ata_port_info via_mwdma_info = {
  404. .sht = &via_sht,
  405. .flags = ATA_FLAG_SLAVE_POSS,
  406. .pio_mask = 0x1f,
  407. .mwdma_mask = 0x07,
  408. .port_ops = &via_port_ops
  409. };
  410. /* Ditto with IRQ masking required */
  411. static const struct ata_port_info via_mwdma_info_borked = {
  412. .sht = &via_sht,
  413. .flags = ATA_FLAG_SLAVE_POSS,
  414. .pio_mask = 0x1f,
  415. .mwdma_mask = 0x07,
  416. .port_ops = &via_port_ops_noirq,
  417. };
  418. /* VIA UDMA 33 devices (and borked 66) */
  419. static const struct ata_port_info via_udma33_info = {
  420. .sht = &via_sht,
  421. .flags = ATA_FLAG_SLAVE_POSS,
  422. .pio_mask = 0x1f,
  423. .mwdma_mask = 0x07,
  424. .udma_mask = ATA_UDMA2,
  425. .port_ops = &via_port_ops
  426. };
  427. /* VIA UDMA 66 devices */
  428. static const struct ata_port_info via_udma66_info = {
  429. .sht = &via_sht,
  430. .flags = ATA_FLAG_SLAVE_POSS,
  431. .pio_mask = 0x1f,
  432. .mwdma_mask = 0x07,
  433. .udma_mask = ATA_UDMA4,
  434. .port_ops = &via_port_ops
  435. };
  436. /* VIA UDMA 100 devices */
  437. static const struct ata_port_info via_udma100_info = {
  438. .sht = &via_sht,
  439. .flags = ATA_FLAG_SLAVE_POSS,
  440. .pio_mask = 0x1f,
  441. .mwdma_mask = 0x07,
  442. .udma_mask = ATA_UDMA5,
  443. .port_ops = &via_port_ops
  444. };
  445. /* UDMA133 with bad AST (All current 133) */
  446. static const struct ata_port_info via_udma133_info = {
  447. .sht = &via_sht,
  448. .flags = ATA_FLAG_SLAVE_POSS,
  449. .pio_mask = 0x1f,
  450. .mwdma_mask = 0x07,
  451. .udma_mask = ATA_UDMA6, /* FIXME: should check north bridge */
  452. .port_ops = &via_port_ops
  453. };
  454. struct ata_port_info type;
  455. const struct ata_port_info *ppi[] = { &type, NULL };
  456. struct pci_dev *isa = NULL;
  457. const struct via_isa_bridge *config;
  458. static int printed_version;
  459. u8 enable;
  460. u32 timing;
  461. if (!printed_version++)
  462. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  463. /* To find out how the IDE will behave and what features we
  464. actually have to look at the bridge not the IDE controller */
  465. for (config = via_isa_bridges; config->id; config++)
  466. if ((isa = pci_get_device(PCI_VENDOR_ID_VIA +
  467. !!(config->flags & VIA_BAD_ID),
  468. config->id, NULL))) {
  469. if (isa->revision >= config->rev_min &&
  470. isa->revision <= config->rev_max)
  471. break;
  472. pci_dev_put(isa);
  473. }
  474. if (!config->id) {
  475. printk(KERN_WARNING "via: Unknown VIA SouthBridge, disabling.\n");
  476. return -ENODEV;
  477. }
  478. pci_dev_put(isa);
  479. /* 0x40 low bits indicate enabled channels */
  480. pci_read_config_byte(pdev, 0x40 , &enable);
  481. enable &= 3;
  482. if (enable == 0) {
  483. return -ENODEV;
  484. }
  485. /* Initialise the FIFO for the enabled channels. */
  486. via_config_fifo(pdev, config->flags);
  487. /* Clock set up */
  488. switch(config->flags & VIA_UDMA) {
  489. case VIA_UDMA_NONE:
  490. if (config->flags & VIA_NO_UNMASK)
  491. type = via_mwdma_info_borked;
  492. else
  493. type = via_mwdma_info;
  494. break;
  495. case VIA_UDMA_33:
  496. type = via_udma33_info;
  497. break;
  498. case VIA_UDMA_66:
  499. type = via_udma66_info;
  500. /* The 66 MHz devices require we enable the clock */
  501. pci_read_config_dword(pdev, 0x50, &timing);
  502. timing |= 0x80008;
  503. pci_write_config_dword(pdev, 0x50, timing);
  504. break;
  505. case VIA_UDMA_100:
  506. type = via_udma100_info;
  507. break;
  508. case VIA_UDMA_133:
  509. type = via_udma133_info;
  510. break;
  511. default:
  512. WARN_ON(1);
  513. return -ENODEV;
  514. }
  515. if (config->flags & VIA_BAD_CLK66) {
  516. /* Disable the 66MHz clock on problem devices */
  517. pci_read_config_dword(pdev, 0x50, &timing);
  518. timing &= ~0x80008;
  519. pci_write_config_dword(pdev, 0x50, timing);
  520. }
  521. /* We have established the device type, now fire it up */
  522. type.private_data = (void *)config;
  523. return ata_pci_init_one(pdev, ppi);
  524. }
  525. #ifdef CONFIG_PM
  526. /**
  527. * via_reinit_one - reinit after resume
  528. * @pdev; PCI device
  529. *
  530. * Called when the VIA PATA device is resumed. We must then
  531. * reconfigure the fifo and other setup we may have altered. In
  532. * addition the kernel needs to have the resume methods on PCI
  533. * quirk supported.
  534. */
  535. static int via_reinit_one(struct pci_dev *pdev)
  536. {
  537. u32 timing;
  538. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  539. const struct via_isa_bridge *config = host->private_data;
  540. via_config_fifo(pdev, config->flags);
  541. if ((config->flags & VIA_UDMA) == VIA_UDMA_66) {
  542. /* The 66 MHz devices require we enable the clock */
  543. pci_read_config_dword(pdev, 0x50, &timing);
  544. timing |= 0x80008;
  545. pci_write_config_dword(pdev, 0x50, timing);
  546. }
  547. if (config->flags & VIA_BAD_CLK66) {
  548. /* Disable the 66MHz clock on problem devices */
  549. pci_read_config_dword(pdev, 0x50, &timing);
  550. timing &= ~0x80008;
  551. pci_write_config_dword(pdev, 0x50, timing);
  552. }
  553. return ata_pci_device_resume(pdev);
  554. }
  555. #endif
  556. static const struct pci_device_id via[] = {
  557. { PCI_VDEVICE(VIA, 0x0571), },
  558. { PCI_VDEVICE(VIA, 0x0581), },
  559. { PCI_VDEVICE(VIA, 0x1571), },
  560. { PCI_VDEVICE(VIA, 0x3164), },
  561. { PCI_VDEVICE(VIA, 0x5324), },
  562. { },
  563. };
  564. static struct pci_driver via_pci_driver = {
  565. .name = DRV_NAME,
  566. .id_table = via,
  567. .probe = via_init_one,
  568. .remove = ata_pci_remove_one,
  569. #ifdef CONFIG_PM
  570. .suspend = ata_pci_device_suspend,
  571. .resume = via_reinit_one,
  572. #endif
  573. };
  574. static int __init via_init(void)
  575. {
  576. return pci_register_driver(&via_pci_driver);
  577. }
  578. static void __exit via_exit(void)
  579. {
  580. pci_unregister_driver(&via_pci_driver);
  581. }
  582. MODULE_AUTHOR("Alan Cox");
  583. MODULE_DESCRIPTION("low-level driver for VIA PATA");
  584. MODULE_LICENSE("GPL");
  585. MODULE_DEVICE_TABLE(pci, via);
  586. MODULE_VERSION(DRV_VERSION);
  587. module_init(via_init);
  588. module_exit(via_exit);