pata_via.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. * pata_via.c - VIA PATA for new ATA layer
  3. * (C) 2005-2006 Red Hat Inc
  4. *
  5. * Documentation
  6. * Most chipset documentation available under NDA only
  7. *
  8. * VIA version guide
  9. * VIA VT82C561 - early design, uses ata_generic currently
  10. * VIA VT82C576 - MWDMA, 33Mhz
  11. * VIA VT82C586 - MWDMA, 33Mhz
  12. * VIA VT82C586a - Added UDMA to 33Mhz
  13. * VIA VT82C586b - UDMA33
  14. * VIA VT82C596a - Nonfunctional UDMA66
  15. * VIA VT82C596b - Working UDMA66
  16. * VIA VT82C686 - Nonfunctional UDMA66
  17. * VIA VT82C686a - Working UDMA66
  18. * VIA VT82C686b - Updated to UDMA100
  19. * VIA VT8231 - UDMA100
  20. * VIA VT8233 - UDMA100
  21. * VIA VT8233a - UDMA133
  22. * VIA VT8233c - UDMA100
  23. * VIA VT8235 - UDMA133
  24. * VIA VT8237 - UDMA133
  25. * VIA VT8237A - 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.4"
  64. enum {
  65. VIA_BAD_PREQ = 0x01, /* Crashes if PREQ# till DDACK# set */
  66. VIA_BAD_CLK66 = 0x02, /* 66 MHz clock doesn't work correctly */
  67. VIA_SET_FIFO = 0x04, /* Needs to have FIFO split set */
  68. VIA_NO_UNMASK = 0x08, /* Doesn't work with IRQ unmasking on */
  69. VIA_BAD_ID = 0x10, /* Has wrong vendor ID (0x1107) */
  70. VIA_BAD_AST = 0x20, /* Don't touch Address Setup Timing */
  71. VIA_NO_ENABLES = 0x40, /* Has no enablebits */
  72. VIA_SATA_PATA = 0x80, /* SATA/PATA combined configuration */
  73. };
  74. enum {
  75. VIA_IDFLAG_SINGLE = (1 << 0), /* single channel controller) */
  76. };
  77. /*
  78. * VIA SouthBridge chips.
  79. */
  80. static const struct via_isa_bridge {
  81. const char *name;
  82. u16 id;
  83. u8 rev_min;
  84. u8 rev_max;
  85. u8 udma_mask;
  86. u8 flags;
  87. } via_isa_bridges[] = {
  88. { "vx855", PCI_DEVICE_ID_VIA_VX855, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST | VIA_SATA_PATA },
  89. { "vx800", PCI_DEVICE_ID_VIA_VX800, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST | VIA_SATA_PATA },
  90. { "vt8261", PCI_DEVICE_ID_VIA_8261, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
  91. { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
  92. { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
  93. { "cx700", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST | VIA_SATA_PATA },
  94. { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST | VIA_NO_ENABLES },
  95. { "vt6415", PCI_DEVICE_ID_VIA_6415, 0x00, 0xff, ATA_UDMA6, VIA_BAD_AST | VIA_NO_ENABLES },
  96. { "vt8237a", PCI_DEVICE_ID_VIA_8237A, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
  97. { "vt8237", PCI_DEVICE_ID_VIA_8237, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
  98. { "vt8235", PCI_DEVICE_ID_VIA_8235, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
  99. { "vt8233a", PCI_DEVICE_ID_VIA_8233A, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
  100. { "vt8233c", PCI_DEVICE_ID_VIA_8233C_0, 0x00, 0x2f, ATA_UDMA5, },
  101. { "vt8233", PCI_DEVICE_ID_VIA_8233_0, 0x00, 0x2f, ATA_UDMA5, },
  102. { "vt8231", PCI_DEVICE_ID_VIA_8231, 0x00, 0x2f, ATA_UDMA5, },
  103. { "vt82c686b", PCI_DEVICE_ID_VIA_82C686, 0x40, 0x4f, ATA_UDMA5, },
  104. { "vt82c686a", PCI_DEVICE_ID_VIA_82C686, 0x10, 0x2f, ATA_UDMA4, },
  105. { "vt82c686", PCI_DEVICE_ID_VIA_82C686, 0x00, 0x0f, ATA_UDMA2, VIA_BAD_CLK66 },
  106. { "vt82c596b", PCI_DEVICE_ID_VIA_82C596, 0x10, 0x2f, ATA_UDMA4, },
  107. { "vt82c596a", PCI_DEVICE_ID_VIA_82C596, 0x00, 0x0f, ATA_UDMA2, VIA_BAD_CLK66 },
  108. { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x47, 0x4f, ATA_UDMA2, VIA_SET_FIFO },
  109. { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x40, 0x46, ATA_UDMA2, VIA_SET_FIFO | VIA_BAD_PREQ },
  110. { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x30, 0x3f, ATA_UDMA2, VIA_SET_FIFO },
  111. { "vt82c586a", PCI_DEVICE_ID_VIA_82C586_0, 0x20, 0x2f, ATA_UDMA2, VIA_SET_FIFO },
  112. { "vt82c586", PCI_DEVICE_ID_VIA_82C586_0, 0x00, 0x0f, 0x00, VIA_SET_FIFO },
  113. { "vt82c576", PCI_DEVICE_ID_VIA_82C576, 0x00, 0x2f, 0x00, VIA_SET_FIFO | VIA_NO_UNMASK },
  114. { "vt82c576", PCI_DEVICE_ID_VIA_82C576, 0x00, 0x2f, 0x00, VIA_SET_FIFO | VIA_NO_UNMASK | VIA_BAD_ID },
  115. { "vtxxxx", PCI_DEVICE_ID_VIA_ANON, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
  116. { NULL }
  117. };
  118. struct via_port {
  119. u8 cached_device;
  120. };
  121. /*
  122. * Cable special cases
  123. */
  124. static const struct dmi_system_id cable_dmi_table[] = {
  125. {
  126. .ident = "Acer Ferrari 3400",
  127. .matches = {
  128. DMI_MATCH(DMI_BOARD_VENDOR, "Acer,Inc."),
  129. DMI_MATCH(DMI_BOARD_NAME, "Ferrari 3400"),
  130. },
  131. },
  132. { }
  133. };
  134. static int via_cable_override(struct pci_dev *pdev)
  135. {
  136. /* Systems by DMI */
  137. if (dmi_check_system(cable_dmi_table))
  138. return 1;
  139. /* Arima W730-K8/Targa Visionary 811/... */
  140. if (pdev->subsystem_vendor == 0x161F && pdev->subsystem_device == 0x2032)
  141. return 1;
  142. return 0;
  143. }
  144. /**
  145. * via_cable_detect - cable detection
  146. * @ap: ATA port
  147. *
  148. * Perform cable detection. Actually for the VIA case the BIOS
  149. * already did this for us. We read the values provided by the
  150. * BIOS. If you are using an 8235 in a non-PC configuration you
  151. * may need to update this code.
  152. *
  153. * Hotplug also impacts on this.
  154. */
  155. static int via_cable_detect(struct ata_port *ap) {
  156. const struct via_isa_bridge *config = ap->host->private_data;
  157. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  158. u32 ata66;
  159. if (via_cable_override(pdev))
  160. return ATA_CBL_PATA40_SHORT;
  161. if ((config->flags & VIA_SATA_PATA) && ap->port_no == 0)
  162. return ATA_CBL_SATA;
  163. /* Early chips are 40 wire */
  164. if (config->udma_mask < ATA_UDMA4)
  165. return ATA_CBL_PATA40;
  166. /* UDMA 66 chips have only drive side logic */
  167. else if (config->udma_mask < ATA_UDMA5)
  168. return ATA_CBL_PATA_UNK;
  169. /* UDMA 100 or later */
  170. pci_read_config_dword(pdev, 0x50, &ata66);
  171. /* Check both the drive cable reporting bits, we might not have
  172. two drives */
  173. if (ata66 & (0x10100000 >> (16 * ap->port_no)))
  174. return ATA_CBL_PATA80;
  175. /* Check with ACPI so we can spot BIOS reported SATA bridges */
  176. if (ata_acpi_init_gtm(ap) &&
  177. ata_acpi_cbl_80wire(ap, ata_acpi_init_gtm(ap)))
  178. return ATA_CBL_PATA80;
  179. return ATA_CBL_PATA40;
  180. }
  181. static int via_pre_reset(struct ata_link *link, unsigned long deadline)
  182. {
  183. struct ata_port *ap = link->ap;
  184. const struct via_isa_bridge *config = ap->host->private_data;
  185. if (!(config->flags & VIA_NO_ENABLES)) {
  186. static const struct pci_bits via_enable_bits[] = {
  187. { 0x40, 1, 0x02, 0x02 },
  188. { 0x40, 1, 0x01, 0x01 }
  189. };
  190. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  191. if (!pci_test_config_bits(pdev, &via_enable_bits[ap->port_no]))
  192. return -ENOENT;
  193. }
  194. return ata_sff_prereset(link, deadline);
  195. }
  196. /**
  197. * via_do_set_mode - set transfer mode data
  198. * @ap: ATA interface
  199. * @adev: ATA device
  200. * @mode: ATA mode being programmed
  201. * @set_ast: Set to program address setup
  202. * @udma_type: UDMA mode/format of registers
  203. *
  204. * Program the VIA registers for DMA and PIO modes. Uses the ata timing
  205. * support in order to compute modes.
  206. *
  207. * FIXME: Hotplug will require we serialize multiple mode changes
  208. * on the two channels.
  209. */
  210. static void via_do_set_mode(struct ata_port *ap, struct ata_device *adev,
  211. int mode, int set_ast, int udma_type)
  212. {
  213. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  214. struct ata_device *peer = ata_dev_pair(adev);
  215. struct ata_timing t, p;
  216. static int via_clock = 33333; /* Bus clock in kHZ */
  217. unsigned long T = 1000000000 / via_clock;
  218. unsigned long UT = T;
  219. int ut;
  220. int offset = 3 - (2*ap->port_no) - adev->devno;
  221. switch (udma_type) {
  222. case ATA_UDMA4:
  223. UT = T / 2; break;
  224. case ATA_UDMA5:
  225. UT = T / 3; break;
  226. case ATA_UDMA6:
  227. UT = T / 4; break;
  228. }
  229. /* Calculate the timing values we require */
  230. ata_timing_compute(adev, mode, &t, T, UT);
  231. /* We share 8bit timing so we must merge the constraints */
  232. if (peer) {
  233. if (peer->pio_mode) {
  234. ata_timing_compute(peer, peer->pio_mode, &p, T, UT);
  235. ata_timing_merge(&p, &t, &t, ATA_TIMING_8BIT);
  236. }
  237. }
  238. /* Address setup is programmable but breaks on UDMA133 setups */
  239. if (set_ast) {
  240. u8 setup; /* 2 bits per drive */
  241. int shift = 2 * offset;
  242. pci_read_config_byte(pdev, 0x4C, &setup);
  243. setup &= ~(3 << shift);
  244. setup |= (clamp_val(t.setup, 1, 4) - 1) << shift;
  245. pci_write_config_byte(pdev, 0x4C, setup);
  246. }
  247. /* Load the PIO mode bits */
  248. pci_write_config_byte(pdev, 0x4F - ap->port_no,
  249. ((clamp_val(t.act8b, 1, 16) - 1) << 4) | (clamp_val(t.rec8b, 1, 16) - 1));
  250. pci_write_config_byte(pdev, 0x48 + offset,
  251. ((clamp_val(t.active, 1, 16) - 1) << 4) | (clamp_val(t.recover, 1, 16) - 1));
  252. /* Load the UDMA bits according to type */
  253. switch (udma_type) {
  254. case ATA_UDMA2:
  255. default:
  256. ut = t.udma ? (0xe0 | (clamp_val(t.udma, 2, 5) - 2)) : 0x03;
  257. break;
  258. case ATA_UDMA4:
  259. ut = t.udma ? (0xe8 | (clamp_val(t.udma, 2, 9) - 2)) : 0x0f;
  260. break;
  261. case ATA_UDMA5:
  262. ut = t.udma ? (0xe0 | (clamp_val(t.udma, 2, 9) - 2)) : 0x07;
  263. break;
  264. case ATA_UDMA6:
  265. ut = t.udma ? (0xe0 | (clamp_val(t.udma, 2, 9) - 2)) : 0x07;
  266. break;
  267. }
  268. /* Set UDMA unless device is not UDMA capable */
  269. if (udma_type) {
  270. u8 udma_etc;
  271. pci_read_config_byte(pdev, 0x50 + offset, &udma_etc);
  272. /* clear transfer mode bit */
  273. udma_etc &= ~0x20;
  274. if (t.udma) {
  275. /* preserve 80-wire cable detection bit */
  276. udma_etc &= 0x10;
  277. udma_etc |= ut;
  278. }
  279. pci_write_config_byte(pdev, 0x50 + offset, udma_etc);
  280. }
  281. }
  282. static void via_set_piomode(struct ata_port *ap, struct ata_device *adev)
  283. {
  284. const struct via_isa_bridge *config = ap->host->private_data;
  285. int set_ast = (config->flags & VIA_BAD_AST) ? 0 : 1;
  286. via_do_set_mode(ap, adev, adev->pio_mode, set_ast, config->udma_mask);
  287. }
  288. static void via_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  289. {
  290. const struct via_isa_bridge *config = ap->host->private_data;
  291. int set_ast = (config->flags & VIA_BAD_AST) ? 0 : 1;
  292. via_do_set_mode(ap, adev, adev->dma_mode, set_ast, config->udma_mask);
  293. }
  294. /**
  295. * via_mode_filter - filter buggy device/mode pairs
  296. * @dev: ATA device
  297. * @mask: Mode bitmask
  298. *
  299. * We need to apply some minimal filtering for old controllers and at least
  300. * one breed of Transcend SSD. Return the updated mask.
  301. */
  302. static unsigned long via_mode_filter(struct ata_device *dev, unsigned long mask)
  303. {
  304. struct ata_host *host = dev->link->ap->host;
  305. const struct via_isa_bridge *config = host->private_data;
  306. unsigned char model_num[ATA_ID_PROD_LEN + 1];
  307. if (config->id == PCI_DEVICE_ID_VIA_82C586_0) {
  308. ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
  309. if (strcmp(model_num, "TS64GSSD25-M") == 0) {
  310. ata_dev_printk(dev, KERN_WARNING,
  311. "disabling UDMA mode due to reported lockups with this device.\n");
  312. mask &= ~ ATA_MASK_UDMA;
  313. }
  314. }
  315. return ata_bmdma_mode_filter(dev, mask);
  316. }
  317. /**
  318. * via_tf_load - send taskfile registers to host controller
  319. * @ap: Port to which output is sent
  320. * @tf: ATA taskfile register set
  321. *
  322. * Outputs ATA taskfile to standard ATA host controller.
  323. *
  324. * Note: This is to fix the internal bug of via chipsets, which
  325. * will reset the device register after changing the IEN bit on
  326. * ctl register
  327. */
  328. static void via_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
  329. {
  330. struct ata_ioports *ioaddr = &ap->ioaddr;
  331. struct via_port *vp = ap->private_data;
  332. unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
  333. int newctl = 0;
  334. if (tf->ctl != ap->last_ctl) {
  335. iowrite8(tf->ctl, ioaddr->ctl_addr);
  336. ap->last_ctl = tf->ctl;
  337. ata_wait_idle(ap);
  338. newctl = 1;
  339. }
  340. if (tf->flags & ATA_TFLAG_DEVICE) {
  341. iowrite8(tf->device, ioaddr->device_addr);
  342. vp->cached_device = tf->device;
  343. } else if (newctl)
  344. iowrite8(vp->cached_device, ioaddr->device_addr);
  345. if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
  346. WARN_ON_ONCE(!ioaddr->ctl_addr);
  347. iowrite8(tf->hob_feature, ioaddr->feature_addr);
  348. iowrite8(tf->hob_nsect, ioaddr->nsect_addr);
  349. iowrite8(tf->hob_lbal, ioaddr->lbal_addr);
  350. iowrite8(tf->hob_lbam, ioaddr->lbam_addr);
  351. iowrite8(tf->hob_lbah, ioaddr->lbah_addr);
  352. VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
  353. tf->hob_feature,
  354. tf->hob_nsect,
  355. tf->hob_lbal,
  356. tf->hob_lbam,
  357. tf->hob_lbah);
  358. }
  359. if (is_addr) {
  360. iowrite8(tf->feature, ioaddr->feature_addr);
  361. iowrite8(tf->nsect, ioaddr->nsect_addr);
  362. iowrite8(tf->lbal, ioaddr->lbal_addr);
  363. iowrite8(tf->lbam, ioaddr->lbam_addr);
  364. iowrite8(tf->lbah, ioaddr->lbah_addr);
  365. VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
  366. tf->feature,
  367. tf->nsect,
  368. tf->lbal,
  369. tf->lbam,
  370. tf->lbah);
  371. }
  372. ata_wait_idle(ap);
  373. }
  374. static int via_port_start(struct ata_port *ap)
  375. {
  376. struct via_port *vp;
  377. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  378. int ret = ata_sff_port_start(ap);
  379. if (ret < 0)
  380. return ret;
  381. vp = devm_kzalloc(&pdev->dev, sizeof(struct via_port), GFP_KERNEL);
  382. if (vp == NULL)
  383. return -ENOMEM;
  384. ap->private_data = vp;
  385. return 0;
  386. }
  387. static struct scsi_host_template via_sht = {
  388. ATA_BMDMA_SHT(DRV_NAME),
  389. };
  390. static struct ata_port_operations via_port_ops = {
  391. .inherits = &ata_bmdma_port_ops,
  392. .cable_detect = via_cable_detect,
  393. .set_piomode = via_set_piomode,
  394. .set_dmamode = via_set_dmamode,
  395. .prereset = via_pre_reset,
  396. .sff_tf_load = via_tf_load,
  397. .port_start = via_port_start,
  398. .mode_filter = via_mode_filter,
  399. };
  400. static struct ata_port_operations via_port_ops_noirq = {
  401. .inherits = &via_port_ops,
  402. .sff_data_xfer = ata_sff_data_xfer_noirq,
  403. };
  404. /**
  405. * via_config_fifo - set up the FIFO
  406. * @pdev: PCI device
  407. * @flags: configuration flags
  408. *
  409. * Set the FIFO properties for this device if necessary. Used both on
  410. * set up and on and the resume path
  411. */
  412. static void via_config_fifo(struct pci_dev *pdev, unsigned int flags)
  413. {
  414. u8 enable;
  415. /* 0x40 low bits indicate enabled channels */
  416. pci_read_config_byte(pdev, 0x40 , &enable);
  417. enable &= 3;
  418. if (flags & VIA_SET_FIFO) {
  419. static const u8 fifo_setting[4] = {0x00, 0x60, 0x00, 0x20};
  420. u8 fifo;
  421. pci_read_config_byte(pdev, 0x43, &fifo);
  422. /* Clear PREQ# until DDACK# for errata */
  423. if (flags & VIA_BAD_PREQ)
  424. fifo &= 0x7F;
  425. else
  426. fifo &= 0x9f;
  427. /* Turn on FIFO for enabled channels */
  428. fifo |= fifo_setting[enable];
  429. pci_write_config_byte(pdev, 0x43, fifo);
  430. }
  431. }
  432. /**
  433. * via_init_one - discovery callback
  434. * @pdev: PCI device
  435. * @id: PCI table info
  436. *
  437. * A VIA IDE interface has been discovered. Figure out what revision
  438. * and perform configuration work before handing it to the ATA layer
  439. */
  440. static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  441. {
  442. /* Early VIA without UDMA support */
  443. static const struct ata_port_info via_mwdma_info = {
  444. .flags = ATA_FLAG_SLAVE_POSS,
  445. .pio_mask = ATA_PIO4,
  446. .mwdma_mask = ATA_MWDMA2,
  447. .port_ops = &via_port_ops
  448. };
  449. /* Ditto with IRQ masking required */
  450. static const struct ata_port_info via_mwdma_info_borked = {
  451. .flags = ATA_FLAG_SLAVE_POSS,
  452. .pio_mask = ATA_PIO4,
  453. .mwdma_mask = ATA_MWDMA2,
  454. .port_ops = &via_port_ops_noirq,
  455. };
  456. /* VIA UDMA 33 devices (and borked 66) */
  457. static const struct ata_port_info via_udma33_info = {
  458. .flags = ATA_FLAG_SLAVE_POSS,
  459. .pio_mask = ATA_PIO4,
  460. .mwdma_mask = ATA_MWDMA2,
  461. .udma_mask = ATA_UDMA2,
  462. .port_ops = &via_port_ops
  463. };
  464. /* VIA UDMA 66 devices */
  465. static const struct ata_port_info via_udma66_info = {
  466. .flags = ATA_FLAG_SLAVE_POSS,
  467. .pio_mask = ATA_PIO4,
  468. .mwdma_mask = ATA_MWDMA2,
  469. .udma_mask = ATA_UDMA4,
  470. .port_ops = &via_port_ops
  471. };
  472. /* VIA UDMA 100 devices */
  473. static const struct ata_port_info via_udma100_info = {
  474. .flags = ATA_FLAG_SLAVE_POSS,
  475. .pio_mask = ATA_PIO4,
  476. .mwdma_mask = ATA_MWDMA2,
  477. .udma_mask = ATA_UDMA5,
  478. .port_ops = &via_port_ops
  479. };
  480. /* UDMA133 with bad AST (All current 133) */
  481. static const struct ata_port_info via_udma133_info = {
  482. .flags = ATA_FLAG_SLAVE_POSS,
  483. .pio_mask = ATA_PIO4,
  484. .mwdma_mask = ATA_MWDMA2,
  485. .udma_mask = ATA_UDMA6, /* FIXME: should check north bridge */
  486. .port_ops = &via_port_ops
  487. };
  488. const struct ata_port_info *ppi[] = { NULL, NULL };
  489. struct pci_dev *isa;
  490. const struct via_isa_bridge *config;
  491. static int printed_version;
  492. u8 enable;
  493. u32 timing;
  494. unsigned long flags = id->driver_data;
  495. int rc;
  496. if (!printed_version++)
  497. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  498. rc = pcim_enable_device(pdev);
  499. if (rc)
  500. return rc;
  501. if (flags & VIA_IDFLAG_SINGLE)
  502. ppi[1] = &ata_dummy_port_info;
  503. /* To find out how the IDE will behave and what features we
  504. actually have to look at the bridge not the IDE controller */
  505. for (config = via_isa_bridges; config->id != PCI_DEVICE_ID_VIA_ANON;
  506. config++)
  507. if ((isa = pci_get_device(PCI_VENDOR_ID_VIA +
  508. !!(config->flags & VIA_BAD_ID),
  509. config->id, NULL))) {
  510. u8 rev = isa->revision;
  511. pci_dev_put(isa);
  512. if (rev >= config->rev_min && rev <= config->rev_max)
  513. break;
  514. }
  515. if (!(config->flags & VIA_NO_ENABLES)) {
  516. /* 0x40 low bits indicate enabled channels */
  517. pci_read_config_byte(pdev, 0x40 , &enable);
  518. enable &= 3;
  519. if (enable == 0)
  520. return -ENODEV;
  521. }
  522. /* Initialise the FIFO for the enabled channels. */
  523. via_config_fifo(pdev, config->flags);
  524. /* Clock set up */
  525. switch (config->udma_mask) {
  526. case 0x00:
  527. if (config->flags & VIA_NO_UNMASK)
  528. ppi[0] = &via_mwdma_info_borked;
  529. else
  530. ppi[0] = &via_mwdma_info;
  531. break;
  532. case ATA_UDMA2:
  533. ppi[0] = &via_udma33_info;
  534. break;
  535. case ATA_UDMA4:
  536. ppi[0] = &via_udma66_info;
  537. break;
  538. case ATA_UDMA5:
  539. ppi[0] = &via_udma100_info;
  540. break;
  541. case ATA_UDMA6:
  542. ppi[0] = &via_udma133_info;
  543. break;
  544. default:
  545. WARN_ON(1);
  546. return -ENODEV;
  547. }
  548. if (config->flags & VIA_BAD_CLK66) {
  549. /* Disable the 66MHz clock on problem devices */
  550. pci_read_config_dword(pdev, 0x50, &timing);
  551. timing &= ~0x80008;
  552. pci_write_config_dword(pdev, 0x50, timing);
  553. }
  554. /* We have established the device type, now fire it up */
  555. return ata_pci_sff_init_one(pdev, ppi, &via_sht, (void *)config, 0);
  556. }
  557. #ifdef CONFIG_PM
  558. /**
  559. * via_reinit_one - reinit after resume
  560. * @pdev; PCI device
  561. *
  562. * Called when the VIA PATA device is resumed. We must then
  563. * reconfigure the fifo and other setup we may have altered. In
  564. * addition the kernel needs to have the resume methods on PCI
  565. * quirk supported.
  566. */
  567. static int via_reinit_one(struct pci_dev *pdev)
  568. {
  569. u32 timing;
  570. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  571. const struct via_isa_bridge *config = host->private_data;
  572. int rc;
  573. rc = ata_pci_device_do_resume(pdev);
  574. if (rc)
  575. return rc;
  576. via_config_fifo(pdev, config->flags);
  577. if (config->udma_mask == ATA_UDMA4) {
  578. /* The 66 MHz devices require we enable the clock */
  579. pci_read_config_dword(pdev, 0x50, &timing);
  580. timing |= 0x80008;
  581. pci_write_config_dword(pdev, 0x50, timing);
  582. }
  583. if (config->flags & VIA_BAD_CLK66) {
  584. /* Disable the 66MHz clock on problem devices */
  585. pci_read_config_dword(pdev, 0x50, &timing);
  586. timing &= ~0x80008;
  587. pci_write_config_dword(pdev, 0x50, timing);
  588. }
  589. ata_host_resume(host);
  590. return 0;
  591. }
  592. #endif
  593. static const struct pci_device_id via[] = {
  594. { PCI_VDEVICE(VIA, 0x0415), },
  595. { PCI_VDEVICE(VIA, 0x0571), },
  596. { PCI_VDEVICE(VIA, 0x0581), },
  597. { PCI_VDEVICE(VIA, 0x1571), },
  598. { PCI_VDEVICE(VIA, 0x3164), },
  599. { PCI_VDEVICE(VIA, 0x5324), },
  600. { PCI_VDEVICE(VIA, 0xC409), VIA_IDFLAG_SINGLE },
  601. { },
  602. };
  603. static struct pci_driver via_pci_driver = {
  604. .name = DRV_NAME,
  605. .id_table = via,
  606. .probe = via_init_one,
  607. .remove = ata_pci_remove_one,
  608. #ifdef CONFIG_PM
  609. .suspend = ata_pci_device_suspend,
  610. .resume = via_reinit_one,
  611. #endif
  612. };
  613. static int __init via_init(void)
  614. {
  615. return pci_register_driver(&via_pci_driver);
  616. }
  617. static void __exit via_exit(void)
  618. {
  619. pci_unregister_driver(&via_pci_driver);
  620. }
  621. MODULE_AUTHOR("Alan Cox");
  622. MODULE_DESCRIPTION("low-level driver for VIA PATA");
  623. MODULE_LICENSE("GPL");
  624. MODULE_DEVICE_TABLE(pci, via);
  625. MODULE_VERSION(DRV_VERSION);
  626. module_init(via_init);
  627. module_exit(via_exit);