pata_via.c 17 KB

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