pata_hpt37x.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. /*
  2. * Libata driver for the highpoint 37x and 30x 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. * TODO
  13. * PLL mode
  14. * Look into engine reset on timeout errors. Should not be
  15. * required.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/pci.h>
  20. #include <linux/init.h>
  21. #include <linux/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <scsi/scsi_host.h>
  24. #include <linux/libata.h>
  25. #define DRV_NAME "pata_hpt37x"
  26. #define DRV_VERSION "0.5.2"
  27. struct hpt_clock {
  28. u8 xfer_speed;
  29. u32 timing;
  30. };
  31. struct hpt_chip {
  32. const char *name;
  33. unsigned int base;
  34. struct hpt_clock const *clocks[4];
  35. };
  36. /* key for bus clock timings
  37. * bit
  38. * 0:3 data_high_time. inactive time of DIOW_/DIOR_ for PIO and MW
  39. * DMA. cycles = value + 1
  40. * 4:8 data_low_time. active time of DIOW_/DIOR_ for PIO and MW
  41. * DMA. cycles = value + 1
  42. * 9:12 cmd_high_time. inactive time of DIOW_/DIOR_ during task file
  43. * register access.
  44. * 13:17 cmd_low_time. active time of DIOW_/DIOR_ during task file
  45. * register access.
  46. * 18:21 udma_cycle_time. clock freq and clock cycles for UDMA xfer.
  47. * during task file register access.
  48. * 22:24 pre_high_time. time to initialize 1st cycle for PIO and MW DMA
  49. * xfer.
  50. * 25:27 cmd_pre_high_time. time to initialize 1st PIO cycle for task
  51. * register access.
  52. * 28 UDMA enable
  53. * 29 DMA enable
  54. * 30 PIO_MST enable. if set, the chip is in bus master mode during
  55. * PIO.
  56. * 31 FIFO enable.
  57. */
  58. /* from highpoint documentation. these are old values */
  59. static const struct hpt_clock hpt370_timings_33[] = {
  60. /* { XFER_UDMA_5, 0x1A85F442, 0x16454e31 }, */
  61. { XFER_UDMA_5, 0x16454e31 },
  62. { XFER_UDMA_4, 0x16454e31 },
  63. { XFER_UDMA_3, 0x166d4e31 },
  64. { XFER_UDMA_2, 0x16494e31 },
  65. { XFER_UDMA_1, 0x164d4e31 },
  66. { XFER_UDMA_0, 0x16514e31 },
  67. { XFER_MW_DMA_2, 0x26514e21 },
  68. { XFER_MW_DMA_1, 0x26514e33 },
  69. { XFER_MW_DMA_0, 0x26514e97 },
  70. { XFER_PIO_4, 0x06514e21 },
  71. { XFER_PIO_3, 0x06514e22 },
  72. { XFER_PIO_2, 0x06514e33 },
  73. { XFER_PIO_1, 0x06914e43 },
  74. { XFER_PIO_0, 0x06914e57 },
  75. { 0, 0x06514e57 }
  76. };
  77. static const struct hpt_clock hpt370_timings_66[] = {
  78. { XFER_UDMA_5, 0x14846231 },
  79. { XFER_UDMA_4, 0x14886231 },
  80. { XFER_UDMA_3, 0x148c6231 },
  81. { XFER_UDMA_2, 0x148c6231 },
  82. { XFER_UDMA_1, 0x14906231 },
  83. { XFER_UDMA_0, 0x14986231 },
  84. { XFER_MW_DMA_2, 0x26514e21 },
  85. { XFER_MW_DMA_1, 0x26514e33 },
  86. { XFER_MW_DMA_0, 0x26514e97 },
  87. { XFER_PIO_4, 0x06514e21 },
  88. { XFER_PIO_3, 0x06514e22 },
  89. { XFER_PIO_2, 0x06514e33 },
  90. { XFER_PIO_1, 0x06914e43 },
  91. { XFER_PIO_0, 0x06914e57 },
  92. { 0, 0x06514e57 }
  93. };
  94. /* these are the current (4 sep 2001) timings from highpoint */
  95. static const struct hpt_clock hpt370a_timings_33[] = {
  96. { XFER_UDMA_5, 0x12446231 },
  97. { XFER_UDMA_4, 0x12446231 },
  98. { XFER_UDMA_3, 0x126c6231 },
  99. { XFER_UDMA_2, 0x12486231 },
  100. { XFER_UDMA_1, 0x124c6233 },
  101. { XFER_UDMA_0, 0x12506297 },
  102. { XFER_MW_DMA_2, 0x22406c31 },
  103. { XFER_MW_DMA_1, 0x22406c33 },
  104. { XFER_MW_DMA_0, 0x22406c97 },
  105. { XFER_PIO_4, 0x06414e31 },
  106. { XFER_PIO_3, 0x06414e42 },
  107. { XFER_PIO_2, 0x06414e53 },
  108. { XFER_PIO_1, 0x06814e93 },
  109. { XFER_PIO_0, 0x06814ea7 },
  110. { 0, 0x06814ea7 }
  111. };
  112. /* 2x 33MHz timings */
  113. static const struct hpt_clock hpt370a_timings_66[] = {
  114. { XFER_UDMA_5, 0x1488e673 },
  115. { XFER_UDMA_4, 0x1488e673 },
  116. { XFER_UDMA_3, 0x1498e673 },
  117. { XFER_UDMA_2, 0x1490e673 },
  118. { XFER_UDMA_1, 0x1498e677 },
  119. { XFER_UDMA_0, 0x14a0e73f },
  120. { XFER_MW_DMA_2, 0x2480fa73 },
  121. { XFER_MW_DMA_1, 0x2480fa77 },
  122. { XFER_MW_DMA_0, 0x2480fb3f },
  123. { XFER_PIO_4, 0x0c82be73 },
  124. { XFER_PIO_3, 0x0c82be95 },
  125. { XFER_PIO_2, 0x0c82beb7 },
  126. { XFER_PIO_1, 0x0d02bf37 },
  127. { XFER_PIO_0, 0x0d02bf5f },
  128. { 0, 0x0d02bf5f }
  129. };
  130. static const struct hpt_clock hpt370a_timings_50[] = {
  131. { XFER_UDMA_5, 0x12848242 },
  132. { XFER_UDMA_4, 0x12ac8242 },
  133. { XFER_UDMA_3, 0x128c8242 },
  134. { XFER_UDMA_2, 0x120c8242 },
  135. { XFER_UDMA_1, 0x12148254 },
  136. { XFER_UDMA_0, 0x121882ea },
  137. { XFER_MW_DMA_2, 0x22808242 },
  138. { XFER_MW_DMA_1, 0x22808254 },
  139. { XFER_MW_DMA_0, 0x228082ea },
  140. { XFER_PIO_4, 0x0a81f442 },
  141. { XFER_PIO_3, 0x0a81f443 },
  142. { XFER_PIO_2, 0x0a81f454 },
  143. { XFER_PIO_1, 0x0ac1f465 },
  144. { XFER_PIO_0, 0x0ac1f48a },
  145. { 0, 0x0ac1f48a }
  146. };
  147. static const struct hpt_clock hpt372_timings_33[] = {
  148. { XFER_UDMA_6, 0x1c81dc62 },
  149. { XFER_UDMA_5, 0x1c6ddc62 },
  150. { XFER_UDMA_4, 0x1c8ddc62 },
  151. { XFER_UDMA_3, 0x1c8edc62 }, /* checkme */
  152. { XFER_UDMA_2, 0x1c91dc62 },
  153. { XFER_UDMA_1, 0x1c9adc62 }, /* checkme */
  154. { XFER_UDMA_0, 0x1c82dc62 }, /* checkme */
  155. { XFER_MW_DMA_2, 0x2c829262 },
  156. { XFER_MW_DMA_1, 0x2c829266 }, /* checkme */
  157. { XFER_MW_DMA_0, 0x2c82922e }, /* checkme */
  158. { XFER_PIO_4, 0x0c829c62 },
  159. { XFER_PIO_3, 0x0c829c84 },
  160. { XFER_PIO_2, 0x0c829ca6 },
  161. { XFER_PIO_1, 0x0d029d26 },
  162. { XFER_PIO_0, 0x0d029d5e },
  163. { 0, 0x0d029d5e }
  164. };
  165. static const struct hpt_clock hpt372_timings_50[] = {
  166. { XFER_UDMA_5, 0x12848242 },
  167. { XFER_UDMA_4, 0x12ac8242 },
  168. { XFER_UDMA_3, 0x128c8242 },
  169. { XFER_UDMA_2, 0x120c8242 },
  170. { XFER_UDMA_1, 0x12148254 },
  171. { XFER_UDMA_0, 0x121882ea },
  172. { XFER_MW_DMA_2, 0x22808242 },
  173. { XFER_MW_DMA_1, 0x22808254 },
  174. { XFER_MW_DMA_0, 0x228082ea },
  175. { XFER_PIO_4, 0x0a81f442 },
  176. { XFER_PIO_3, 0x0a81f443 },
  177. { XFER_PIO_2, 0x0a81f454 },
  178. { XFER_PIO_1, 0x0ac1f465 },
  179. { XFER_PIO_0, 0x0ac1f48a },
  180. { 0, 0x0a81f443 }
  181. };
  182. static const struct hpt_clock hpt372_timings_66[] = {
  183. { XFER_UDMA_6, 0x1c869c62 },
  184. { XFER_UDMA_5, 0x1cae9c62 },
  185. { XFER_UDMA_4, 0x1c8a9c62 },
  186. { XFER_UDMA_3, 0x1c8e9c62 },
  187. { XFER_UDMA_2, 0x1c929c62 },
  188. { XFER_UDMA_1, 0x1c9a9c62 },
  189. { XFER_UDMA_0, 0x1c829c62 },
  190. { XFER_MW_DMA_2, 0x2c829c62 },
  191. { XFER_MW_DMA_1, 0x2c829c66 },
  192. { XFER_MW_DMA_0, 0x2c829d2e },
  193. { XFER_PIO_4, 0x0c829c62 },
  194. { XFER_PIO_3, 0x0c829c84 },
  195. { XFER_PIO_2, 0x0c829ca6 },
  196. { XFER_PIO_1, 0x0d029d26 },
  197. { XFER_PIO_0, 0x0d029d5e },
  198. { 0, 0x0d029d26 }
  199. };
  200. static const struct hpt_clock hpt374_timings_33[] = {
  201. { XFER_UDMA_6, 0x12808242 },
  202. { XFER_UDMA_5, 0x12848242 },
  203. { XFER_UDMA_4, 0x12ac8242 },
  204. { XFER_UDMA_3, 0x128c8242 },
  205. { XFER_UDMA_2, 0x120c8242 },
  206. { XFER_UDMA_1, 0x12148254 },
  207. { XFER_UDMA_0, 0x121882ea },
  208. { XFER_MW_DMA_2, 0x22808242 },
  209. { XFER_MW_DMA_1, 0x22808254 },
  210. { XFER_MW_DMA_0, 0x228082ea },
  211. { XFER_PIO_4, 0x0a81f442 },
  212. { XFER_PIO_3, 0x0a81f443 },
  213. { XFER_PIO_2, 0x0a81f454 },
  214. { XFER_PIO_1, 0x0ac1f465 },
  215. { XFER_PIO_0, 0x0ac1f48a },
  216. { 0, 0x06814e93 }
  217. };
  218. static const struct hpt_chip hpt370 = {
  219. "HPT370",
  220. 48,
  221. {
  222. hpt370_timings_33,
  223. NULL,
  224. NULL,
  225. hpt370_timings_66
  226. }
  227. };
  228. static const struct hpt_chip hpt370a = {
  229. "HPT370A",
  230. 48,
  231. {
  232. hpt370a_timings_33,
  233. NULL,
  234. hpt370a_timings_50,
  235. hpt370a_timings_66
  236. }
  237. };
  238. static const struct hpt_chip hpt372 = {
  239. "HPT372",
  240. 55,
  241. {
  242. hpt372_timings_33,
  243. NULL,
  244. hpt372_timings_50,
  245. hpt372_timings_66
  246. }
  247. };
  248. static const struct hpt_chip hpt302 = {
  249. "HPT302",
  250. 66,
  251. {
  252. hpt372_timings_33,
  253. NULL,
  254. hpt372_timings_50,
  255. hpt372_timings_66
  256. }
  257. };
  258. static const struct hpt_chip hpt371 = {
  259. "HPT371",
  260. 66,
  261. {
  262. hpt372_timings_33,
  263. NULL,
  264. hpt372_timings_50,
  265. hpt372_timings_66
  266. }
  267. };
  268. static const struct hpt_chip hpt372a = {
  269. "HPT372A",
  270. 66,
  271. {
  272. hpt372_timings_33,
  273. NULL,
  274. hpt372_timings_50,
  275. hpt372_timings_66
  276. }
  277. };
  278. static const struct hpt_chip hpt374 = {
  279. "HPT374",
  280. 48,
  281. {
  282. hpt374_timings_33,
  283. NULL,
  284. NULL,
  285. NULL
  286. }
  287. };
  288. /**
  289. * hpt37x_find_mode - reset the hpt37x bus
  290. * @ap: ATA port
  291. * @speed: transfer mode
  292. *
  293. * Return the 32bit register programming information for this channel
  294. * that matches the speed provided.
  295. */
  296. static u32 hpt37x_find_mode(struct ata_port *ap, int speed)
  297. {
  298. struct hpt_clock *clocks = ap->host->private_data;
  299. while(clocks->xfer_speed) {
  300. if (clocks->xfer_speed == speed)
  301. return clocks->timing;
  302. clocks++;
  303. }
  304. BUG();
  305. return 0xffffffffU; /* silence compiler warning */
  306. }
  307. static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char *list[])
  308. {
  309. unsigned char model_num[ATA_ID_PROD_LEN + 1];
  310. int i = 0;
  311. ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
  312. while (list[i] != NULL) {
  313. if (!strcmp(list[i], model_num)) {
  314. printk(KERN_WARNING DRV_NAME ": %s is not supported for %s.\n",
  315. modestr, list[i]);
  316. return 1;
  317. }
  318. i++;
  319. }
  320. return 0;
  321. }
  322. static const char *bad_ata33[] = {
  323. "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3", "Maxtor 90845U3", "Maxtor 90650U2",
  324. "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5", "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2",
  325. "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6", "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4",
  326. "Maxtor 90510D4",
  327. "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2",
  328. "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7", "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4",
  329. "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5", "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2",
  330. NULL
  331. };
  332. static const char *bad_ata100_5[] = {
  333. "IBM-DTLA-307075",
  334. "IBM-DTLA-307060",
  335. "IBM-DTLA-307045",
  336. "IBM-DTLA-307030",
  337. "IBM-DTLA-307020",
  338. "IBM-DTLA-307015",
  339. "IBM-DTLA-305040",
  340. "IBM-DTLA-305030",
  341. "IBM-DTLA-305020",
  342. "IC35L010AVER07-0",
  343. "IC35L020AVER07-0",
  344. "IC35L030AVER07-0",
  345. "IC35L040AVER07-0",
  346. "IC35L060AVER07-0",
  347. "WDC AC310200R",
  348. NULL
  349. };
  350. /**
  351. * hpt370_filter - mode selection filter
  352. * @ap: ATA interface
  353. * @adev: ATA device
  354. *
  355. * Block UDMA on devices that cause trouble with this controller.
  356. */
  357. static unsigned long hpt370_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask)
  358. {
  359. if (adev->class == ATA_DEV_ATA) {
  360. if (hpt_dma_blacklisted(adev, "UDMA", bad_ata33))
  361. mask &= ~ATA_MASK_UDMA;
  362. if (hpt_dma_blacklisted(adev, "UDMA100", bad_ata100_5))
  363. mask &= ~(0x1F << ATA_SHIFT_UDMA);
  364. }
  365. return ata_pci_default_filter(ap, adev, mask);
  366. }
  367. /**
  368. * hpt370a_filter - mode selection filter
  369. * @ap: ATA interface
  370. * @adev: ATA device
  371. *
  372. * Block UDMA on devices that cause trouble with this controller.
  373. */
  374. static unsigned long hpt370a_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask)
  375. {
  376. if (adev->class != ATA_DEV_ATA) {
  377. if (hpt_dma_blacklisted(adev, "UDMA100", bad_ata100_5))
  378. mask &= ~ (0x1F << ATA_SHIFT_UDMA);
  379. }
  380. return ata_pci_default_filter(ap, adev, mask);
  381. }
  382. /**
  383. * hpt37x_pre_reset - reset the hpt37x bus
  384. * @ap: ATA port to reset
  385. *
  386. * Perform the initial reset handling for the 370/372 and 374 func 0
  387. */
  388. static int hpt37x_pre_reset(struct ata_port *ap)
  389. {
  390. u8 scr2, ata66;
  391. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  392. static const struct pci_bits hpt37x_enable_bits[] = {
  393. { 0x50, 1, 0x04, 0x04 },
  394. { 0x54, 1, 0x04, 0x04 }
  395. };
  396. if (!pci_test_config_bits(pdev, &hpt37x_enable_bits[ap->port_no]))
  397. return -ENOENT;
  398. pci_read_config_byte(pdev, 0x5B, &scr2);
  399. pci_write_config_byte(pdev, 0x5B, scr2 & ~0x01);
  400. /* Cable register now active */
  401. pci_read_config_byte(pdev, 0x5A, &ata66);
  402. /* Restore state */
  403. pci_write_config_byte(pdev, 0x5B, scr2);
  404. if (ata66 & (1 << ap->port_no))
  405. ap->cbl = ATA_CBL_PATA40;
  406. else
  407. ap->cbl = ATA_CBL_PATA80;
  408. /* Reset the state machine */
  409. pci_write_config_byte(pdev, 0x50, 0x37);
  410. pci_write_config_byte(pdev, 0x54, 0x37);
  411. udelay(100);
  412. return ata_std_prereset(ap);
  413. }
  414. /**
  415. * hpt37x_error_handler - reset the hpt374
  416. * @ap: ATA port to reset
  417. *
  418. * Perform probe for HPT37x, except for HPT374 channel 2
  419. */
  420. static void hpt37x_error_handler(struct ata_port *ap)
  421. {
  422. ata_bmdma_drive_eh(ap, hpt37x_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  423. }
  424. static int hpt374_pre_reset(struct ata_port *ap)
  425. {
  426. static const struct pci_bits hpt37x_enable_bits[] = {
  427. { 0x50, 1, 0x04, 0x04 },
  428. { 0x54, 1, 0x04, 0x04 }
  429. };
  430. u16 mcr3, mcr6;
  431. u8 ata66;
  432. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  433. if (!pci_test_config_bits(pdev, &hpt37x_enable_bits[ap->port_no]))
  434. return -ENOENT;
  435. /* Do the extra channel work */
  436. pci_read_config_word(pdev, 0x52, &mcr3);
  437. pci_read_config_word(pdev, 0x56, &mcr6);
  438. /* Set bit 15 of 0x52 to enable TCBLID as input
  439. Set bit 15 of 0x56 to enable FCBLID as input
  440. */
  441. pci_write_config_word(pdev, 0x52, mcr3 | 0x8000);
  442. pci_write_config_word(pdev, 0x56, mcr6 | 0x8000);
  443. pci_read_config_byte(pdev, 0x5A, &ata66);
  444. /* Reset TCBLID/FCBLID to output */
  445. pci_write_config_word(pdev, 0x52, mcr3);
  446. pci_write_config_word(pdev, 0x56, mcr6);
  447. if (ata66 & (1 << ap->port_no))
  448. ap->cbl = ATA_CBL_PATA40;
  449. else
  450. ap->cbl = ATA_CBL_PATA80;
  451. /* Reset the state machine */
  452. pci_write_config_byte(pdev, 0x50, 0x37);
  453. pci_write_config_byte(pdev, 0x54, 0x37);
  454. udelay(100);
  455. return ata_std_prereset(ap);
  456. }
  457. /**
  458. * hpt374_error_handler - reset the hpt374
  459. * @classes:
  460. *
  461. * The 374 cable detect is a little different due to the extra
  462. * channels. The function 0 channels work like usual but function 1
  463. * is special
  464. */
  465. static void hpt374_error_handler(struct ata_port *ap)
  466. {
  467. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  468. if (!(PCI_FUNC(pdev->devfn) & 1))
  469. hpt37x_error_handler(ap);
  470. else
  471. ata_bmdma_drive_eh(ap, hpt374_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  472. }
  473. /**
  474. * hpt370_set_piomode - PIO setup
  475. * @ap: ATA interface
  476. * @adev: device on the interface
  477. *
  478. * Perform PIO mode setup.
  479. */
  480. static void hpt370_set_piomode(struct ata_port *ap, struct ata_device *adev)
  481. {
  482. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  483. u32 addr1, addr2;
  484. u32 reg;
  485. u32 mode;
  486. u8 fast;
  487. addr1 = 0x40 + 4 * (adev->devno + 2 * ap->port_no);
  488. addr2 = 0x51 + 4 * ap->port_no;
  489. /* Fast interrupt prediction disable, hold off interrupt disable */
  490. pci_read_config_byte(pdev, addr2, &fast);
  491. fast &= ~0x02;
  492. fast |= 0x01;
  493. pci_write_config_byte(pdev, addr2, fast);
  494. pci_read_config_dword(pdev, addr1, &reg);
  495. mode = hpt37x_find_mode(ap, adev->pio_mode);
  496. mode &= ~0x8000000; /* No FIFO in PIO */
  497. mode &= ~0x30070000; /* Leave config bits alone */
  498. reg &= 0x30070000; /* Strip timing bits */
  499. pci_write_config_dword(pdev, addr1, reg | mode);
  500. }
  501. /**
  502. * hpt370_set_dmamode - DMA timing setup
  503. * @ap: ATA interface
  504. * @adev: Device being configured
  505. *
  506. * Set up the channel for MWDMA or UDMA modes. Much the same as with
  507. * PIO, load the mode number and then set MWDMA or UDMA flag.
  508. */
  509. static void hpt370_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  510. {
  511. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  512. u32 addr1, addr2;
  513. u32 reg;
  514. u32 mode;
  515. u8 fast;
  516. addr1 = 0x40 + 4 * (adev->devno + 2 * ap->port_no);
  517. addr2 = 0x51 + 4 * ap->port_no;
  518. /* Fast interrupt prediction disable, hold off interrupt disable */
  519. pci_read_config_byte(pdev, addr2, &fast);
  520. fast &= ~0x02;
  521. fast |= 0x01;
  522. pci_write_config_byte(pdev, addr2, fast);
  523. pci_read_config_dword(pdev, addr1, &reg);
  524. mode = hpt37x_find_mode(ap, adev->dma_mode);
  525. mode |= 0x8000000; /* FIFO in MWDMA or UDMA */
  526. mode &= ~0xC0000000; /* Leave config bits alone */
  527. reg &= 0xC0000000; /* Strip timing bits */
  528. pci_write_config_dword(pdev, addr1, reg | mode);
  529. }
  530. /**
  531. * hpt370_bmdma_start - DMA engine begin
  532. * @qc: ATA command
  533. *
  534. * The 370 and 370A want us to reset the DMA engine each time we
  535. * use it. The 372 and later are fine.
  536. */
  537. static void hpt370_bmdma_start(struct ata_queued_cmd *qc)
  538. {
  539. struct ata_port *ap = qc->ap;
  540. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  541. pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
  542. udelay(10);
  543. ata_bmdma_start(qc);
  544. }
  545. /**
  546. * hpt370_bmdma_end - DMA engine stop
  547. * @qc: ATA command
  548. *
  549. * Work around the HPT370 DMA engine.
  550. */
  551. static void hpt370_bmdma_stop(struct ata_queued_cmd *qc)
  552. {
  553. struct ata_port *ap = qc->ap;
  554. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  555. u8 dma_stat = ioread8(ap->ioaddr.bmdma_addr + 2);
  556. u8 dma_cmd;
  557. void __iomem *bmdma = ap->ioaddr.bmdma_addr;
  558. if (dma_stat & 0x01) {
  559. udelay(20);
  560. dma_stat = ioread8(bmdma + 2);
  561. }
  562. if (dma_stat & 0x01) {
  563. /* Clear the engine */
  564. pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
  565. udelay(10);
  566. /* Stop DMA */
  567. dma_cmd = ioread8(bmdma );
  568. iowrite8(dma_cmd & 0xFE, bmdma);
  569. /* Clear Error */
  570. dma_stat = ioread8(bmdma + 2);
  571. iowrite8(dma_stat | 0x06 , bmdma + 2);
  572. /* Clear the engine */
  573. pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
  574. udelay(10);
  575. }
  576. ata_bmdma_stop(qc);
  577. }
  578. /**
  579. * hpt372_set_piomode - PIO setup
  580. * @ap: ATA interface
  581. * @adev: device on the interface
  582. *
  583. * Perform PIO mode setup.
  584. */
  585. static void hpt372_set_piomode(struct ata_port *ap, struct ata_device *adev)
  586. {
  587. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  588. u32 addr1, addr2;
  589. u32 reg;
  590. u32 mode;
  591. u8 fast;
  592. addr1 = 0x40 + 4 * (adev->devno + 2 * ap->port_no);
  593. addr2 = 0x51 + 4 * ap->port_no;
  594. /* Fast interrupt prediction disable, hold off interrupt disable */
  595. pci_read_config_byte(pdev, addr2, &fast);
  596. fast &= ~0x07;
  597. pci_write_config_byte(pdev, addr2, fast);
  598. pci_read_config_dword(pdev, addr1, &reg);
  599. mode = hpt37x_find_mode(ap, adev->pio_mode);
  600. printk("Find mode for %d reports %X\n", adev->pio_mode, mode);
  601. mode &= ~0x80000000; /* No FIFO in PIO */
  602. mode &= ~0x30070000; /* Leave config bits alone */
  603. reg &= 0x30070000; /* Strip timing bits */
  604. pci_write_config_dword(pdev, addr1, reg | mode);
  605. }
  606. /**
  607. * hpt372_set_dmamode - DMA timing setup
  608. * @ap: ATA interface
  609. * @adev: Device being configured
  610. *
  611. * Set up the channel for MWDMA or UDMA modes. Much the same as with
  612. * PIO, load the mode number and then set MWDMA or UDMA flag.
  613. */
  614. static void hpt372_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  615. {
  616. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  617. u32 addr1, addr2;
  618. u32 reg;
  619. u32 mode;
  620. u8 fast;
  621. addr1 = 0x40 + 4 * (adev->devno + 2 * ap->port_no);
  622. addr2 = 0x51 + 4 * ap->port_no;
  623. /* Fast interrupt prediction disable, hold off interrupt disable */
  624. pci_read_config_byte(pdev, addr2, &fast);
  625. fast &= ~0x07;
  626. pci_write_config_byte(pdev, addr2, fast);
  627. pci_read_config_dword(pdev, addr1, &reg);
  628. mode = hpt37x_find_mode(ap, adev->dma_mode);
  629. printk("Find mode for DMA %d reports %X\n", adev->dma_mode, mode);
  630. mode &= ~0xC0000000; /* Leave config bits alone */
  631. mode |= 0x80000000; /* FIFO in MWDMA or UDMA */
  632. reg &= 0xC0000000; /* Strip timing bits */
  633. pci_write_config_dword(pdev, addr1, reg | mode);
  634. }
  635. /**
  636. * hpt37x_bmdma_end - DMA engine stop
  637. * @qc: ATA command
  638. *
  639. * Clean up after the HPT372 and later DMA engine
  640. */
  641. static void hpt37x_bmdma_stop(struct ata_queued_cmd *qc)
  642. {
  643. struct ata_port *ap = qc->ap;
  644. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  645. int mscreg = 0x50 + 4 * ap->port_no;
  646. u8 bwsr_stat, msc_stat;
  647. pci_read_config_byte(pdev, 0x6A, &bwsr_stat);
  648. pci_read_config_byte(pdev, mscreg, &msc_stat);
  649. if (bwsr_stat & (1 << ap->port_no))
  650. pci_write_config_byte(pdev, mscreg, msc_stat | 0x30);
  651. ata_bmdma_stop(qc);
  652. }
  653. static struct scsi_host_template hpt37x_sht = {
  654. .module = THIS_MODULE,
  655. .name = DRV_NAME,
  656. .ioctl = ata_scsi_ioctl,
  657. .queuecommand = ata_scsi_queuecmd,
  658. .can_queue = ATA_DEF_QUEUE,
  659. .this_id = ATA_SHT_THIS_ID,
  660. .sg_tablesize = LIBATA_MAX_PRD,
  661. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  662. .emulated = ATA_SHT_EMULATED,
  663. .use_clustering = ATA_SHT_USE_CLUSTERING,
  664. .proc_name = DRV_NAME,
  665. .dma_boundary = ATA_DMA_BOUNDARY,
  666. .slave_configure = ata_scsi_slave_config,
  667. .slave_destroy = ata_scsi_slave_destroy,
  668. .bios_param = ata_std_bios_param,
  669. };
  670. /*
  671. * Configuration for HPT370
  672. */
  673. static struct ata_port_operations hpt370_port_ops = {
  674. .port_disable = ata_port_disable,
  675. .set_piomode = hpt370_set_piomode,
  676. .set_dmamode = hpt370_set_dmamode,
  677. .mode_filter = hpt370_filter,
  678. .tf_load = ata_tf_load,
  679. .tf_read = ata_tf_read,
  680. .check_status = ata_check_status,
  681. .exec_command = ata_exec_command,
  682. .dev_select = ata_std_dev_select,
  683. .freeze = ata_bmdma_freeze,
  684. .thaw = ata_bmdma_thaw,
  685. .error_handler = hpt37x_error_handler,
  686. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  687. .bmdma_setup = ata_bmdma_setup,
  688. .bmdma_start = hpt370_bmdma_start,
  689. .bmdma_stop = hpt370_bmdma_stop,
  690. .bmdma_status = ata_bmdma_status,
  691. .qc_prep = ata_qc_prep,
  692. .qc_issue = ata_qc_issue_prot,
  693. .data_xfer = ata_data_xfer,
  694. .irq_handler = ata_interrupt,
  695. .irq_clear = ata_bmdma_irq_clear,
  696. .irq_on = ata_irq_on,
  697. .irq_ack = ata_irq_ack,
  698. .port_start = ata_port_start,
  699. };
  700. /*
  701. * Configuration for HPT370A. Close to 370 but less filters
  702. */
  703. static struct ata_port_operations hpt370a_port_ops = {
  704. .port_disable = ata_port_disable,
  705. .set_piomode = hpt370_set_piomode,
  706. .set_dmamode = hpt370_set_dmamode,
  707. .mode_filter = hpt370a_filter,
  708. .tf_load = ata_tf_load,
  709. .tf_read = ata_tf_read,
  710. .check_status = ata_check_status,
  711. .exec_command = ata_exec_command,
  712. .dev_select = ata_std_dev_select,
  713. .freeze = ata_bmdma_freeze,
  714. .thaw = ata_bmdma_thaw,
  715. .error_handler = hpt37x_error_handler,
  716. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  717. .bmdma_setup = ata_bmdma_setup,
  718. .bmdma_start = hpt370_bmdma_start,
  719. .bmdma_stop = hpt370_bmdma_stop,
  720. .bmdma_status = ata_bmdma_status,
  721. .qc_prep = ata_qc_prep,
  722. .qc_issue = ata_qc_issue_prot,
  723. .data_xfer = ata_data_xfer,
  724. .irq_handler = ata_interrupt,
  725. .irq_clear = ata_bmdma_irq_clear,
  726. .irq_on = ata_irq_on,
  727. .irq_ack = ata_irq_ack,
  728. .port_start = ata_port_start,
  729. };
  730. /*
  731. * Configuration for HPT372, HPT371, HPT302. Slightly different PIO
  732. * and DMA mode setting functionality.
  733. */
  734. static struct ata_port_operations hpt372_port_ops = {
  735. .port_disable = ata_port_disable,
  736. .set_piomode = hpt372_set_piomode,
  737. .set_dmamode = hpt372_set_dmamode,
  738. .mode_filter = ata_pci_default_filter,
  739. .tf_load = ata_tf_load,
  740. .tf_read = ata_tf_read,
  741. .check_status = ata_check_status,
  742. .exec_command = ata_exec_command,
  743. .dev_select = ata_std_dev_select,
  744. .freeze = ata_bmdma_freeze,
  745. .thaw = ata_bmdma_thaw,
  746. .error_handler = hpt37x_error_handler,
  747. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  748. .bmdma_setup = ata_bmdma_setup,
  749. .bmdma_start = ata_bmdma_start,
  750. .bmdma_stop = hpt37x_bmdma_stop,
  751. .bmdma_status = ata_bmdma_status,
  752. .qc_prep = ata_qc_prep,
  753. .qc_issue = ata_qc_issue_prot,
  754. .data_xfer = ata_data_xfer,
  755. .irq_handler = ata_interrupt,
  756. .irq_clear = ata_bmdma_irq_clear,
  757. .irq_on = ata_irq_on,
  758. .irq_ack = ata_irq_ack,
  759. .port_start = ata_port_start,
  760. };
  761. /*
  762. * Configuration for HPT374. Mode setting works like 372 and friends
  763. * but we have a different cable detection procedure.
  764. */
  765. static struct ata_port_operations hpt374_port_ops = {
  766. .port_disable = ata_port_disable,
  767. .set_piomode = hpt372_set_piomode,
  768. .set_dmamode = hpt372_set_dmamode,
  769. .mode_filter = ata_pci_default_filter,
  770. .tf_load = ata_tf_load,
  771. .tf_read = ata_tf_read,
  772. .check_status = ata_check_status,
  773. .exec_command = ata_exec_command,
  774. .dev_select = ata_std_dev_select,
  775. .freeze = ata_bmdma_freeze,
  776. .thaw = ata_bmdma_thaw,
  777. .error_handler = hpt374_error_handler,
  778. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  779. .bmdma_setup = ata_bmdma_setup,
  780. .bmdma_start = ata_bmdma_start,
  781. .bmdma_stop = hpt37x_bmdma_stop,
  782. .bmdma_status = ata_bmdma_status,
  783. .qc_prep = ata_qc_prep,
  784. .qc_issue = ata_qc_issue_prot,
  785. .data_xfer = ata_data_xfer,
  786. .irq_handler = ata_interrupt,
  787. .irq_clear = ata_bmdma_irq_clear,
  788. .irq_on = ata_irq_on,
  789. .irq_ack = ata_irq_ack,
  790. .port_start = ata_port_start,
  791. };
  792. /**
  793. * htp37x_clock_slot - Turn timing to PC clock entry
  794. * @freq: Reported frequency timing
  795. * @base: Base timing
  796. *
  797. * Turn the timing data intoa clock slot (0 for 33, 1 for 40, 2 for 50
  798. * and 3 for 66Mhz)
  799. */
  800. static int hpt37x_clock_slot(unsigned int freq, unsigned int base)
  801. {
  802. unsigned int f = (base * freq) / 192; /* Mhz */
  803. if (f < 40)
  804. return 0; /* 33Mhz slot */
  805. if (f < 45)
  806. return 1; /* 40Mhz slot */
  807. if (f < 55)
  808. return 2; /* 50Mhz slot */
  809. return 3; /* 60Mhz slot */
  810. }
  811. /**
  812. * hpt37x_calibrate_dpll - Calibrate the DPLL loop
  813. * @dev: PCI device
  814. *
  815. * Perform a calibration cycle on the HPT37x DPLL. Returns 1 if this
  816. * succeeds
  817. */
  818. static int hpt37x_calibrate_dpll(struct pci_dev *dev)
  819. {
  820. u8 reg5b;
  821. u32 reg5c;
  822. int tries;
  823. for(tries = 0; tries < 0x5000; tries++) {
  824. udelay(50);
  825. pci_read_config_byte(dev, 0x5b, &reg5b);
  826. if (reg5b & 0x80) {
  827. /* See if it stays set */
  828. for(tries = 0; tries < 0x1000; tries ++) {
  829. pci_read_config_byte(dev, 0x5b, &reg5b);
  830. /* Failed ? */
  831. if ((reg5b & 0x80) == 0)
  832. return 0;
  833. }
  834. /* Turn off tuning, we have the DPLL set */
  835. pci_read_config_dword(dev, 0x5c, &reg5c);
  836. pci_write_config_dword(dev, 0x5c, reg5c & ~ 0x100);
  837. return 1;
  838. }
  839. }
  840. /* Never went stable */
  841. return 0;
  842. }
  843. /**
  844. * hpt37x_init_one - Initialise an HPT37X/302
  845. * @dev: PCI device
  846. * @id: Entry in match table
  847. *
  848. * Initialise an HPT37x device. There are some interesting complications
  849. * here. Firstly the chip may report 366 and be one of several variants.
  850. * Secondly all the timings depend on the clock for the chip which we must
  851. * detect and look up
  852. *
  853. * This is the known chip mappings. It may be missing a couple of later
  854. * releases.
  855. *
  856. * Chip version PCI Rev Notes
  857. * HPT366 4 (HPT366) 0 Other driver
  858. * HPT366 4 (HPT366) 1 Other driver
  859. * HPT368 4 (HPT366) 2 Other driver
  860. * HPT370 4 (HPT366) 3 UDMA100
  861. * HPT370A 4 (HPT366) 4 UDMA100
  862. * HPT372 4 (HPT366) 5 UDMA133 (1)
  863. * HPT372N 4 (HPT366) 6 Other driver
  864. * HPT372A 5 (HPT372) 1 UDMA133 (1)
  865. * HPT372N 5 (HPT372) 2 Other driver
  866. * HPT302 6 (HPT302) 1 UDMA133
  867. * HPT302N 6 (HPT302) 2 Other driver
  868. * HPT371 7 (HPT371) * UDMA133
  869. * HPT374 8 (HPT374) * UDMA133 4 channel
  870. * HPT372N 9 (HPT372N) * Other driver
  871. *
  872. * (1) UDMA133 support depends on the bus clock
  873. */
  874. static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  875. {
  876. /* HPT370 - UDMA100 */
  877. static struct ata_port_info info_hpt370 = {
  878. .sht = &hpt37x_sht,
  879. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  880. .pio_mask = 0x1f,
  881. .mwdma_mask = 0x07,
  882. .udma_mask = 0x3f,
  883. .port_ops = &hpt370_port_ops
  884. };
  885. /* HPT370A - UDMA100 */
  886. static struct ata_port_info info_hpt370a = {
  887. .sht = &hpt37x_sht,
  888. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  889. .pio_mask = 0x1f,
  890. .mwdma_mask = 0x07,
  891. .udma_mask = 0x3f,
  892. .port_ops = &hpt370a_port_ops
  893. };
  894. /* HPT371, 372 and friends - UDMA133 */
  895. static struct ata_port_info info_hpt372 = {
  896. .sht = &hpt37x_sht,
  897. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  898. .pio_mask = 0x1f,
  899. .mwdma_mask = 0x07,
  900. .udma_mask = 0x7f,
  901. .port_ops = &hpt372_port_ops
  902. };
  903. /* HPT371, 372 and friends - UDMA100 at 50MHz clock */
  904. static struct ata_port_info info_hpt372_50 = {
  905. .sht = &hpt37x_sht,
  906. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  907. .pio_mask = 0x1f,
  908. .mwdma_mask = 0x07,
  909. .udma_mask = 0x3f,
  910. .port_ops = &hpt372_port_ops
  911. };
  912. /* HPT374 - UDMA133 */
  913. static struct ata_port_info info_hpt374 = {
  914. .sht = &hpt37x_sht,
  915. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  916. .pio_mask = 0x1f,
  917. .mwdma_mask = 0x07,
  918. .udma_mask = 0x7f,
  919. .port_ops = &hpt374_port_ops
  920. };
  921. static const int MHz[4] = { 33, 40, 50, 66 };
  922. struct ata_port_info *port_info[2];
  923. struct ata_port_info *port;
  924. u8 irqmask;
  925. u32 class_rev;
  926. u32 freq;
  927. const struct hpt_chip *chip_table;
  928. int clock_slot;
  929. pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
  930. class_rev &= 0xFF;
  931. if (dev->device == PCI_DEVICE_ID_TTI_HPT366) {
  932. /* May be a later chip in disguise. Check */
  933. /* Older chips are in the HPT366 driver. Ignore them */
  934. if (class_rev < 3)
  935. return -ENODEV;
  936. /* N series chips have their own driver. Ignore */
  937. if (class_rev == 6)
  938. return -ENODEV;
  939. switch(class_rev) {
  940. case 3:
  941. port = &info_hpt370;
  942. chip_table = &hpt370;
  943. break;
  944. case 4:
  945. port = &info_hpt370a;
  946. chip_table = &hpt370a;
  947. break;
  948. case 5:
  949. port = &info_hpt372;
  950. chip_table = &hpt372;
  951. break;
  952. default:
  953. printk(KERN_ERR "pata_hpt37x: Unknown HPT366 subtype please report (%d).\n", class_rev);
  954. return -ENODEV;
  955. }
  956. } else {
  957. switch(dev->device) {
  958. case PCI_DEVICE_ID_TTI_HPT372:
  959. /* 372N if rev >= 2*/
  960. if (class_rev >= 2)
  961. return -ENODEV;
  962. port = &info_hpt372;
  963. chip_table = &hpt372a;
  964. break;
  965. case PCI_DEVICE_ID_TTI_HPT302:
  966. /* 302N if rev > 1 */
  967. if (class_rev > 1)
  968. return -ENODEV;
  969. port = &info_hpt372;
  970. /* Check this */
  971. chip_table = &hpt302;
  972. break;
  973. case PCI_DEVICE_ID_TTI_HPT371:
  974. port = &info_hpt372;
  975. chip_table = &hpt371;
  976. break;
  977. case PCI_DEVICE_ID_TTI_HPT374:
  978. chip_table = &hpt374;
  979. port = &info_hpt374;
  980. break;
  981. default:
  982. printk(KERN_ERR "pata_hpt37x: PCI table is bogus please report (%d).\n", dev->device);
  983. return -ENODEV;
  984. }
  985. }
  986. /* Ok so this is a chip we support */
  987. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
  988. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
  989. pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  990. pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
  991. pci_read_config_byte(dev, 0x5A, &irqmask);
  992. irqmask &= ~0x10;
  993. pci_write_config_byte(dev, 0x5a, irqmask);
  994. /*
  995. * default to pci clock. make sure MA15/16 are set to output
  996. * to prevent drives having problems with 40-pin cables. Needed
  997. * for some drives such as IBM-DTLA which will not enter ready
  998. * state on reset when PDIAG is a input.
  999. */
  1000. pci_write_config_byte(dev, 0x5b, 0x23);
  1001. pci_read_config_dword(dev, 0x70, &freq);
  1002. if ((freq >> 12) != 0xABCDE) {
  1003. int i;
  1004. u8 sr;
  1005. u32 total = 0;
  1006. printk(KERN_WARNING "pata_hpt37x: BIOS has not set timing clocks.\n");
  1007. /* This is the process the HPT371 BIOS is reported to use */
  1008. for(i = 0; i < 128; i++) {
  1009. pci_read_config_byte(dev, 0x78, &sr);
  1010. total += sr;
  1011. udelay(15);
  1012. }
  1013. freq = total / 128;
  1014. }
  1015. freq &= 0x1FF;
  1016. /*
  1017. * Turn the frequency check into a band and then find a timing
  1018. * table to match it.
  1019. */
  1020. clock_slot = hpt37x_clock_slot(freq, chip_table->base);
  1021. if (chip_table->clocks[clock_slot] == NULL) {
  1022. /*
  1023. * We need to try PLL mode instead
  1024. */
  1025. unsigned int f_low = (MHz[clock_slot] * chip_table->base) / 192;
  1026. unsigned int f_high = f_low + 2;
  1027. int adjust;
  1028. for(adjust = 0; adjust < 8; adjust++) {
  1029. if (hpt37x_calibrate_dpll(dev))
  1030. break;
  1031. /* See if it'll settle at a fractionally different clock */
  1032. if ((adjust & 3) == 3) {
  1033. f_low --;
  1034. f_high ++;
  1035. }
  1036. pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low);
  1037. }
  1038. if (adjust == 8) {
  1039. printk(KERN_WARNING "hpt37x: DPLL did not stabilize.\n");
  1040. return -ENODEV;
  1041. }
  1042. /* Check if this works for all cases */
  1043. port->private_data = (void *)hpt370_timings_66;
  1044. printk(KERN_INFO "hpt37x: Bus clock %dMHz, using DPLL.\n", MHz[clock_slot]);
  1045. } else {
  1046. port->private_data = (void *)chip_table->clocks[clock_slot];
  1047. /*
  1048. * Perform a final fixup. The 371 and 372 clock determines
  1049. * if UDMA133 is available.
  1050. */
  1051. if (clock_slot == 2 && chip_table == &hpt372) { /* 50Mhz */
  1052. printk(KERN_WARNING "pata_hpt37x: No UDMA133 support available with 50MHz bus clock.\n");
  1053. if (port == &info_hpt372)
  1054. port = &info_hpt372_50;
  1055. else BUG();
  1056. }
  1057. printk(KERN_INFO "hpt37x: %s: Bus clock %dMHz.\n", chip_table->name, MHz[clock_slot]);
  1058. }
  1059. port_info[0] = port_info[1] = port;
  1060. /* Now kick off ATA set up */
  1061. return ata_pci_init_one(dev, port_info, 2);
  1062. }
  1063. static const struct pci_device_id hpt37x[] = {
  1064. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT366), },
  1065. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT371), },
  1066. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT372), },
  1067. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT374), },
  1068. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT302), },
  1069. { },
  1070. };
  1071. static struct pci_driver hpt37x_pci_driver = {
  1072. .name = DRV_NAME,
  1073. .id_table = hpt37x,
  1074. .probe = hpt37x_init_one,
  1075. .remove = ata_pci_remove_one
  1076. };
  1077. static int __init hpt37x_init(void)
  1078. {
  1079. return pci_register_driver(&hpt37x_pci_driver);
  1080. }
  1081. static void __exit hpt37x_exit(void)
  1082. {
  1083. pci_unregister_driver(&hpt37x_pci_driver);
  1084. }
  1085. MODULE_AUTHOR("Alan Cox");
  1086. MODULE_DESCRIPTION("low-level driver for the Highpoint HPT37x/30x");
  1087. MODULE_LICENSE("GPL");
  1088. MODULE_DEVICE_TABLE(pci, hpt37x);
  1089. MODULE_VERSION(DRV_VERSION);
  1090. module_init(hpt37x_init);
  1091. module_exit(hpt37x_exit);