pata_via.c 18 KB

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