PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/ata/pata_hpt366.c

https://bitbucket.org/Lloir/lge-kernel-jb
C | 422 lines | 265 code | 56 blank | 101 comment | 24 complexity | 09f6b6361e011448b278820609ab88f8 MD5 | raw file
  1. /*
  2. * Libata driver for the highpoint 366 and 368 UDMA66 ATA controllers.
  3. *
  4. * This driver is heavily based upon:
  5. *
  6. * linux/drivers/ide/pci/hpt366.c Version 0.36 April 25, 2003
  7. *
  8. * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org>
  9. * Portions Copyright (C) 2001 Sun Microsystems, Inc.
  10. * Portions Copyright (C) 2003 Red Hat Inc
  11. *
  12. *
  13. * TODO
  14. * Look into engine reset on timeout errors. Should not be required.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/pci.h>
  19. #include <linux/init.h>
  20. #include <linux/blkdev.h>
  21. #include <linux/delay.h>
  22. #include <scsi/scsi_host.h>
  23. #include <linux/libata.h>
  24. #define DRV_NAME "pata_hpt366"
  25. #define DRV_VERSION "0.6.10"
  26. struct hpt_clock {
  27. u8 xfer_mode;
  28. u32 timing;
  29. };
  30. /* key for bus clock timings
  31. * bit
  32. * 0:3 data_high_time. Inactive time of DIOW_/DIOR_ for PIO and MW DMA.
  33. * cycles = value + 1
  34. * 4:7 data_low_time. Active time of DIOW_/DIOR_ for PIO and MW DMA.
  35. * cycles = value + 1
  36. * 8:11 cmd_high_time. Inactive time of DIOW_/DIOR_ during task file
  37. * register access.
  38. * 12:15 cmd_low_time. Active time of DIOW_/DIOR_ during task file
  39. * register access.
  40. * 16:18 udma_cycle_time. Clock cycles for UDMA xfer?
  41. * 19:21 pre_high_time. Time to initialize 1st cycle for PIO and MW DMA xfer.
  42. * 22:24 cmd_pre_high_time. Time to initialize 1st PIO cycle for task file
  43. * register access.
  44. * 28 UDMA enable.
  45. * 29 DMA enable.
  46. * 30 PIO_MST enable. If set, the chip is in bus master mode during
  47. * PIO xfer.
  48. * 31 FIFO enable.
  49. */
  50. static const struct hpt_clock hpt366_40[] = {
  51. { XFER_UDMA_4, 0x900fd943 },
  52. { XFER_UDMA_3, 0x900ad943 },
  53. { XFER_UDMA_2, 0x900bd943 },
  54. { XFER_UDMA_1, 0x9008d943 },
  55. { XFER_UDMA_0, 0x9008d943 },
  56. { XFER_MW_DMA_2, 0xa008d943 },
  57. { XFER_MW_DMA_1, 0xa010d955 },
  58. { XFER_MW_DMA_0, 0xa010d9fc },
  59. { XFER_PIO_4, 0xc008d963 },
  60. { XFER_PIO_3, 0xc010d974 },
  61. { XFER_PIO_2, 0xc010d997 },
  62. { XFER_PIO_1, 0xc010d9c7 },
  63. { XFER_PIO_0, 0xc018d9d9 },
  64. { 0, 0x0120d9d9 }
  65. };
  66. static const struct hpt_clock hpt366_33[] = {
  67. { XFER_UDMA_4, 0x90c9a731 },
  68. { XFER_UDMA_3, 0x90cfa731 },
  69. { XFER_UDMA_2, 0x90caa731 },
  70. { XFER_UDMA_1, 0x90cba731 },
  71. { XFER_UDMA_0, 0x90c8a731 },
  72. { XFER_MW_DMA_2, 0xa0c8a731 },
  73. { XFER_MW_DMA_1, 0xa0c8a732 }, /* 0xa0c8a733 */
  74. { XFER_MW_DMA_0, 0xa0c8a797 },
  75. { XFER_PIO_4, 0xc0c8a731 },
  76. { XFER_PIO_3, 0xc0c8a742 },
  77. { XFER_PIO_2, 0xc0d0a753 },
  78. { XFER_PIO_1, 0xc0d0a7a3 }, /* 0xc0d0a793 */
  79. { XFER_PIO_0, 0xc0d0a7aa }, /* 0xc0d0a7a7 */
  80. { 0, 0x0120a7a7 }
  81. };
  82. static const struct hpt_clock hpt366_25[] = {
  83. { XFER_UDMA_4, 0x90c98521 },
  84. { XFER_UDMA_3, 0x90cf8521 },
  85. { XFER_UDMA_2, 0x90cf8521 },
  86. { XFER_UDMA_1, 0x90cb8521 },
  87. { XFER_UDMA_0, 0x90cb8521 },
  88. { XFER_MW_DMA_2, 0xa0ca8521 },
  89. { XFER_MW_DMA_1, 0xa0ca8532 },
  90. { XFER_MW_DMA_0, 0xa0ca8575 },
  91. { XFER_PIO_4, 0xc0ca8521 },
  92. { XFER_PIO_3, 0xc0ca8532 },
  93. { XFER_PIO_2, 0xc0ca8542 },
  94. { XFER_PIO_1, 0xc0d08572 },
  95. { XFER_PIO_0, 0xc0d08585 },
  96. { 0, 0x01208585 }
  97. };
  98. static const char * const bad_ata33[] = {
  99. "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3",
  100. "Maxtor 90845U3", "Maxtor 90650U2",
  101. "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5",
  102. "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2",
  103. "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6",
  104. "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4",
  105. "Maxtor 90510D4",
  106. "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2",
  107. "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7",
  108. "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4",
  109. "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5",
  110. "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2",
  111. NULL
  112. };
  113. static const char * const bad_ata66_4[] = {
  114. "IBM-DTLA-307075",
  115. "IBM-DTLA-307060",
  116. "IBM-DTLA-307045",
  117. "IBM-DTLA-307030",
  118. "IBM-DTLA-307020",
  119. "IBM-DTLA-307015",
  120. "IBM-DTLA-305040",
  121. "IBM-DTLA-305030",
  122. "IBM-DTLA-305020",
  123. "IC35L010AVER07-0",
  124. "IC35L020AVER07-0",
  125. "IC35L030AVER07-0",
  126. "IC35L040AVER07-0",
  127. "IC35L060AVER07-0",
  128. "WDC AC310200R",
  129. NULL
  130. };
  131. static const char * const bad_ata66_3[] = {
  132. "WDC AC310200R",
  133. NULL
  134. };
  135. static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr,
  136. const char * const list[])
  137. {
  138. unsigned char model_num[ATA_ID_PROD_LEN + 1];
  139. int i = 0;
  140. ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
  141. while (list[i] != NULL) {
  142. if (!strcmp(list[i], model_num)) {
  143. pr_warning(DRV_NAME ": %s is not supported for %s.\n",
  144. modestr, list[i]);
  145. return 1;
  146. }
  147. i++;
  148. }
  149. return 0;
  150. }
  151. /**
  152. * hpt366_filter - mode selection filter
  153. * @adev: ATA device
  154. *
  155. * Block UDMA on devices that cause trouble with this controller.
  156. */
  157. static unsigned long hpt366_filter(struct ata_device *adev, unsigned long mask)
  158. {
  159. if (adev->class == ATA_DEV_ATA) {
  160. if (hpt_dma_blacklisted(adev, "UDMA", bad_ata33))
  161. mask &= ~ATA_MASK_UDMA;
  162. if (hpt_dma_blacklisted(adev, "UDMA3", bad_ata66_3))
  163. mask &= ~(0xF8 << ATA_SHIFT_UDMA);
  164. if (hpt_dma_blacklisted(adev, "UDMA4", bad_ata66_4))
  165. mask &= ~(0xF0 << ATA_SHIFT_UDMA);
  166. } else if (adev->class == ATA_DEV_ATAPI)
  167. mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
  168. return mask;
  169. }
  170. static int hpt36x_cable_detect(struct ata_port *ap)
  171. {
  172. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  173. u8 ata66;
  174. /*
  175. * Each channel of pata_hpt366 occupies separate PCI function
  176. * as the primary channel and bit1 indicates the cable type.
  177. */
  178. pci_read_config_byte(pdev, 0x5A, &ata66);
  179. if (ata66 & 2)
  180. return ATA_CBL_PATA40;
  181. return ATA_CBL_PATA80;
  182. }
  183. static void hpt366_set_mode(struct ata_port *ap, struct ata_device *adev,
  184. u8 mode)
  185. {
  186. struct hpt_clock *clocks = ap->host->private_data;
  187. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  188. u32 addr = 0x40 + 4 * adev->devno;
  189. u32 mask, reg;
  190. /* determine timing mask and find matching clock entry */
  191. if (mode < XFER_MW_DMA_0)
  192. mask = 0xc1f8ffff;
  193. else if (mode < XFER_UDMA_0)
  194. mask = 0x303800ff;
  195. else
  196. mask = 0x30070000;
  197. while (clocks->xfer_mode) {
  198. if (clocks->xfer_mode == mode)
  199. break;
  200. clocks++;
  201. }
  202. if (!clocks->xfer_mode)
  203. BUG();
  204. /*
  205. * Combine new mode bits with old config bits and disable
  206. * on-chip PIO FIFO/buffer (and PIO MST mode as well) to avoid
  207. * problems handling I/O errors later.
  208. */
  209. pci_read_config_dword(pdev, addr, &reg);
  210. reg = ((reg & ~mask) | (clocks->timing & mask)) & ~0xc0000000;
  211. pci_write_config_dword(pdev, addr, reg);
  212. }
  213. /**
  214. * hpt366_set_piomode - PIO setup
  215. * @ap: ATA interface
  216. * @adev: device on the interface
  217. *
  218. * Perform PIO mode setup.
  219. */
  220. static void hpt366_set_piomode(struct ata_port *ap, struct ata_device *adev)
  221. {
  222. hpt366_set_mode(ap, adev, adev->pio_mode);
  223. }
  224. /**
  225. * hpt366_set_dmamode - DMA timing setup
  226. * @ap: ATA interface
  227. * @adev: Device being configured
  228. *
  229. * Set up the channel for MWDMA or UDMA modes. Much the same as with
  230. * PIO, load the mode number and then set MWDMA or UDMA flag.
  231. */
  232. static void hpt366_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  233. {
  234. hpt366_set_mode(ap, adev, adev->dma_mode);
  235. }
  236. static struct scsi_host_template hpt36x_sht = {
  237. ATA_BMDMA_SHT(DRV_NAME),
  238. };
  239. /*
  240. * Configuration for HPT366/68
  241. */
  242. static struct ata_port_operations hpt366_port_ops = {
  243. .inherits = &ata_bmdma_port_ops,
  244. .cable_detect = hpt36x_cable_detect,
  245. .mode_filter = hpt366_filter,
  246. .set_piomode = hpt366_set_piomode,
  247. .set_dmamode = hpt366_set_dmamode,
  248. };
  249. /**
  250. * hpt36x_init_chipset - common chip setup
  251. * @dev: PCI device
  252. *
  253. * Perform the chip setup work that must be done at both init and
  254. * resume time
  255. */
  256. static void hpt36x_init_chipset(struct pci_dev *dev)
  257. {
  258. u8 drive_fast;
  259. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
  260. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
  261. pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  262. pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
  263. pci_read_config_byte(dev, 0x51, &drive_fast);
  264. if (drive_fast & 0x80)
  265. pci_write_config_byte(dev, 0x51, drive_fast & ~0x80);
  266. }
  267. /**
  268. * hpt36x_init_one - Initialise an HPT366/368
  269. * @dev: PCI device
  270. * @id: Entry in match table
  271. *
  272. * Initialise an HPT36x device. There are some interesting complications
  273. * here. Firstly the chip may report 366 and be one of several variants.
  274. * Secondly all the timings depend on the clock for the chip which we must
  275. * detect and look up
  276. *
  277. * This is the known chip mappings. It may be missing a couple of later
  278. * releases.
  279. *
  280. * Chip version PCI Rev Notes
  281. * HPT366 4 (HPT366) 0 UDMA66
  282. * HPT366 4 (HPT366) 1 UDMA66
  283. * HPT368 4 (HPT366) 2 UDMA66
  284. * HPT37x/30x 4 (HPT366) 3+ Other driver
  285. *
  286. */
  287. static int hpt36x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  288. {
  289. static const struct ata_port_info info_hpt366 = {
  290. .flags = ATA_FLAG_SLAVE_POSS,
  291. .pio_mask = ATA_PIO4,
  292. .mwdma_mask = ATA_MWDMA2,
  293. .udma_mask = ATA_UDMA4,
  294. .port_ops = &hpt366_port_ops
  295. };
  296. const struct ata_port_info *ppi[] = { &info_hpt366, NULL };
  297. void *hpriv = NULL;
  298. u32 reg1;
  299. int rc;
  300. rc = pcim_enable_device(dev);
  301. if (rc)
  302. return rc;
  303. /* May be a later chip in disguise. Check */
  304. /* Newer chips are not in the HPT36x driver. Ignore them */
  305. if (dev->revision > 2)
  306. return -ENODEV;
  307. hpt36x_init_chipset(dev);
  308. pci_read_config_dword(dev, 0x40, &reg1);
  309. /* PCI clocking determines the ATA timing values to use */
  310. /* info_hpt366 is safe against re-entry so we can scribble on it */
  311. switch ((reg1 & 0x700) >> 8) {
  312. case 9:
  313. hpriv = &hpt366_40;
  314. break;
  315. case 5:
  316. hpriv = &hpt366_25;
  317. break;
  318. default:
  319. hpriv = &hpt366_33;
  320. break;
  321. }
  322. /* Now kick off ATA set up */
  323. return ata_pci_bmdma_init_one(dev, ppi, &hpt36x_sht, hpriv, 0);
  324. }
  325. #ifdef CONFIG_PM
  326. static int hpt36x_reinit_one(struct pci_dev *dev)
  327. {
  328. struct ata_host *host = dev_get_drvdata(&dev->dev);
  329. int rc;
  330. rc = ata_pci_device_do_resume(dev);
  331. if (rc)
  332. return rc;
  333. hpt36x_init_chipset(dev);
  334. ata_host_resume(host);
  335. return 0;
  336. }
  337. #endif
  338. static const struct pci_device_id hpt36x[] = {
  339. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT366), },
  340. { },
  341. };
  342. static struct pci_driver hpt36x_pci_driver = {
  343. .name = DRV_NAME,
  344. .id_table = hpt36x,
  345. .probe = hpt36x_init_one,
  346. .remove = ata_pci_remove_one,
  347. #ifdef CONFIG_PM
  348. .suspend = ata_pci_device_suspend,
  349. .resume = hpt36x_reinit_one,
  350. #endif
  351. };
  352. static int __init hpt36x_init(void)
  353. {
  354. return pci_register_driver(&hpt36x_pci_driver);
  355. }
  356. static void __exit hpt36x_exit(void)
  357. {
  358. pci_unregister_driver(&hpt36x_pci_driver);
  359. }
  360. MODULE_AUTHOR("Alan Cox");
  361. MODULE_DESCRIPTION("low-level driver for the Highpoint HPT366/368");
  362. MODULE_LICENSE("GPL");
  363. MODULE_DEVICE_TABLE(pci, hpt36x);
  364. MODULE_VERSION(DRV_VERSION);
  365. module_init(hpt36x_init);
  366. module_exit(hpt36x_exit);