pata_via.c 18 KB

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