pata_via.c 18 KB

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