pata_hpt37x.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  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.1"
  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[40];
  310. char *s;
  311. unsigned int len;
  312. int i = 0;
  313. ata_id_string(dev->id, model_num, ATA_ID_PROD_OFS,
  314. sizeof(model_num));
  315. s = &model_num[0];
  316. len = strnlen(s, sizeof(model_num));
  317. /* ATAPI specifies that empty space is blank-filled; remove blanks */
  318. while ((len > 0) && (s[len - 1] == ' ')) {
  319. len--;
  320. s[len] = 0;
  321. }
  322. while(list[i] != NULL) {
  323. if (!strncmp(list[i], s, len)) {
  324. printk(KERN_WARNING DRV_NAME ": %s is not supported for %s.\n",
  325. modestr, list[i]);
  326. return 1;
  327. }
  328. i++;
  329. }
  330. return 0;
  331. }
  332. static const char *bad_ata33[] = {
  333. "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3", "Maxtor 90845U3", "Maxtor 90650U2",
  334. "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5", "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2",
  335. "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6", "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4",
  336. "Maxtor 90510D4",
  337. "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2",
  338. "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7", "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4",
  339. "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5", "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2",
  340. NULL
  341. };
  342. static const char *bad_ata100_5[] = {
  343. "IBM-DTLA-307075",
  344. "IBM-DTLA-307060",
  345. "IBM-DTLA-307045",
  346. "IBM-DTLA-307030",
  347. "IBM-DTLA-307020",
  348. "IBM-DTLA-307015",
  349. "IBM-DTLA-305040",
  350. "IBM-DTLA-305030",
  351. "IBM-DTLA-305020",
  352. "IC35L010AVER07-0",
  353. "IC35L020AVER07-0",
  354. "IC35L030AVER07-0",
  355. "IC35L040AVER07-0",
  356. "IC35L060AVER07-0",
  357. "WDC AC310200R",
  358. NULL
  359. };
  360. /**
  361. * hpt370_filter - mode selection filter
  362. * @ap: ATA interface
  363. * @adev: ATA device
  364. *
  365. * Block UDMA on devices that cause trouble with this controller.
  366. */
  367. static unsigned long hpt370_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask)
  368. {
  369. if (adev->class != ATA_DEV_ATA) {
  370. if (hpt_dma_blacklisted(adev, "UDMA", bad_ata33))
  371. mask &= ~ATA_MASK_UDMA;
  372. if (hpt_dma_blacklisted(adev, "UDMA100", bad_ata100_5))
  373. mask &= ~(0x1F << ATA_SHIFT_UDMA);
  374. }
  375. return ata_pci_default_filter(ap, adev, mask);
  376. }
  377. /**
  378. * hpt370a_filter - mode selection filter
  379. * @ap: ATA interface
  380. * @adev: ATA device
  381. *
  382. * Block UDMA on devices that cause trouble with this controller.
  383. */
  384. static unsigned long hpt370a_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask)
  385. {
  386. if (adev->class != ATA_DEV_ATA) {
  387. if (hpt_dma_blacklisted(adev, "UDMA100", bad_ata100_5))
  388. mask &= ~ (0x1F << ATA_SHIFT_UDMA);
  389. }
  390. return ata_pci_default_filter(ap, adev, mask);
  391. }
  392. /**
  393. * hpt37x_pre_reset - reset the hpt37x bus
  394. * @ap: ATA port to reset
  395. *
  396. * Perform the initial reset handling for the 370/372 and 374 func 0
  397. */
  398. static int hpt37x_pre_reset(struct ata_port *ap)
  399. {
  400. u8 scr2, ata66;
  401. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  402. static const struct pci_bits hpt37x_enable_bits[] = {
  403. { 0x50, 1, 0x04, 0x04 },
  404. { 0x54, 1, 0x04, 0x04 }
  405. };
  406. if (!pci_test_config_bits(pdev, &hpt37x_enable_bits[ap->port_no]))
  407. return -ENOENT;
  408. pci_read_config_byte(pdev, 0x5B, &scr2);
  409. pci_write_config_byte(pdev, 0x5B, scr2 & ~0x01);
  410. /* Cable register now active */
  411. pci_read_config_byte(pdev, 0x5A, &ata66);
  412. /* Restore state */
  413. pci_write_config_byte(pdev, 0x5B, scr2);
  414. if (ata66 & (1 << ap->port_no))
  415. ap->cbl = ATA_CBL_PATA40;
  416. else
  417. ap->cbl = ATA_CBL_PATA80;
  418. /* Reset the state machine */
  419. pci_write_config_byte(pdev, 0x50, 0x37);
  420. pci_write_config_byte(pdev, 0x54, 0x37);
  421. udelay(100);
  422. return ata_std_prereset(ap);
  423. }
  424. /**
  425. * hpt37x_error_handler - reset the hpt374
  426. * @ap: ATA port to reset
  427. *
  428. * Perform probe for HPT37x, except for HPT374 channel 2
  429. */
  430. static void hpt37x_error_handler(struct ata_port *ap)
  431. {
  432. ata_bmdma_drive_eh(ap, hpt37x_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  433. }
  434. static int hpt374_pre_reset(struct ata_port *ap)
  435. {
  436. static const struct pci_bits hpt37x_enable_bits[] = {
  437. { 0x50, 1, 0x04, 0x04 },
  438. { 0x54, 1, 0x04, 0x04 }
  439. };
  440. u16 mcr3, mcr6;
  441. u8 ata66;
  442. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  443. if (!pci_test_config_bits(pdev, &hpt37x_enable_bits[ap->port_no]))
  444. return -ENOENT;
  445. /* Do the extra channel work */
  446. pci_read_config_word(pdev, 0x52, &mcr3);
  447. pci_read_config_word(pdev, 0x56, &mcr6);
  448. /* Set bit 15 of 0x52 to enable TCBLID as input
  449. Set bit 15 of 0x56 to enable FCBLID as input
  450. */
  451. pci_write_config_word(pdev, 0x52, mcr3 | 0x8000);
  452. pci_write_config_word(pdev, 0x56, mcr6 | 0x8000);
  453. pci_read_config_byte(pdev, 0x5A, &ata66);
  454. /* Reset TCBLID/FCBLID to output */
  455. pci_write_config_word(pdev, 0x52, mcr3);
  456. pci_write_config_word(pdev, 0x56, mcr6);
  457. if (ata66 & (1 << ap->port_no))
  458. ap->cbl = ATA_CBL_PATA40;
  459. else
  460. ap->cbl = ATA_CBL_PATA80;
  461. /* Reset the state machine */
  462. pci_write_config_byte(pdev, 0x50, 0x37);
  463. pci_write_config_byte(pdev, 0x54, 0x37);
  464. udelay(100);
  465. return ata_std_prereset(ap);
  466. }
  467. /**
  468. * hpt374_error_handler - reset the hpt374
  469. * @classes:
  470. *
  471. * The 374 cable detect is a little different due to the extra
  472. * channels. The function 0 channels work like usual but function 1
  473. * is special
  474. */
  475. static void hpt374_error_handler(struct ata_port *ap)
  476. {
  477. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  478. if (!(PCI_FUNC(pdev->devfn) & 1))
  479. hpt37x_error_handler(ap);
  480. else
  481. ata_bmdma_drive_eh(ap, hpt374_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  482. }
  483. /**
  484. * hpt370_set_piomode - PIO setup
  485. * @ap: ATA interface
  486. * @adev: device on the interface
  487. *
  488. * Perform PIO mode setup.
  489. */
  490. static void hpt370_set_piomode(struct ata_port *ap, struct ata_device *adev)
  491. {
  492. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  493. u32 addr1, addr2;
  494. u32 reg;
  495. u32 mode;
  496. u8 fast;
  497. addr1 = 0x40 + 4 * (adev->devno + 2 * ap->port_no);
  498. addr2 = 0x51 + 4 * ap->port_no;
  499. /* Fast interrupt prediction disable, hold off interrupt disable */
  500. pci_read_config_byte(pdev, addr2, &fast);
  501. fast &= ~0x02;
  502. fast |= 0x01;
  503. pci_write_config_byte(pdev, addr2, fast);
  504. pci_read_config_dword(pdev, addr1, &reg);
  505. mode = hpt37x_find_mode(ap, adev->pio_mode);
  506. mode &= ~0x8000000; /* No FIFO in PIO */
  507. mode &= ~0x30070000; /* Leave config bits alone */
  508. reg &= 0x30070000; /* Strip timing bits */
  509. pci_write_config_dword(pdev, addr1, reg | mode);
  510. }
  511. /**
  512. * hpt370_set_dmamode - DMA timing setup
  513. * @ap: ATA interface
  514. * @adev: Device being configured
  515. *
  516. * Set up the channel for MWDMA or UDMA modes. Much the same as with
  517. * PIO, load the mode number and then set MWDMA or UDMA flag.
  518. */
  519. static void hpt370_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  520. {
  521. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  522. u32 addr1, addr2;
  523. u32 reg;
  524. u32 mode;
  525. u8 fast;
  526. addr1 = 0x40 + 4 * (adev->devno + 2 * ap->port_no);
  527. addr2 = 0x51 + 4 * ap->port_no;
  528. /* Fast interrupt prediction disable, hold off interrupt disable */
  529. pci_read_config_byte(pdev, addr2, &fast);
  530. fast &= ~0x02;
  531. fast |= 0x01;
  532. pci_write_config_byte(pdev, addr2, fast);
  533. pci_read_config_dword(pdev, addr1, &reg);
  534. mode = hpt37x_find_mode(ap, adev->dma_mode);
  535. mode |= 0x8000000; /* FIFO in MWDMA or UDMA */
  536. mode &= ~0xC0000000; /* Leave config bits alone */
  537. reg &= 0xC0000000; /* Strip timing bits */
  538. pci_write_config_dword(pdev, addr1, reg | mode);
  539. }
  540. /**
  541. * hpt370_bmdma_start - DMA engine begin
  542. * @qc: ATA command
  543. *
  544. * The 370 and 370A want us to reset the DMA engine each time we
  545. * use it. The 372 and later are fine.
  546. */
  547. static void hpt370_bmdma_start(struct ata_queued_cmd *qc)
  548. {
  549. struct ata_port *ap = qc->ap;
  550. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  551. pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
  552. udelay(10);
  553. ata_bmdma_start(qc);
  554. }
  555. /**
  556. * hpt370_bmdma_end - DMA engine stop
  557. * @qc: ATA command
  558. *
  559. * Work around the HPT370 DMA engine.
  560. */
  561. static void hpt370_bmdma_stop(struct ata_queued_cmd *qc)
  562. {
  563. struct ata_port *ap = qc->ap;
  564. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  565. u8 dma_stat = inb(ap->ioaddr.bmdma_addr + 2);
  566. u8 dma_cmd;
  567. unsigned long bmdma = ap->ioaddr.bmdma_addr;
  568. if (dma_stat & 0x01) {
  569. udelay(20);
  570. dma_stat = inb(bmdma + 2);
  571. }
  572. if (dma_stat & 0x01) {
  573. /* Clear the engine */
  574. pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
  575. udelay(10);
  576. /* Stop DMA */
  577. dma_cmd = inb(bmdma );
  578. outb(dma_cmd & 0xFE, bmdma);
  579. /* Clear Error */
  580. dma_stat = inb(bmdma + 2);
  581. outb(dma_stat | 0x06 , bmdma + 2);
  582. /* Clear the engine */
  583. pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
  584. udelay(10);
  585. }
  586. ata_bmdma_stop(qc);
  587. }
  588. /**
  589. * hpt372_set_piomode - PIO setup
  590. * @ap: ATA interface
  591. * @adev: device on the interface
  592. *
  593. * Perform PIO mode setup.
  594. */
  595. static void hpt372_set_piomode(struct ata_port *ap, struct ata_device *adev)
  596. {
  597. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  598. u32 addr1, addr2;
  599. u32 reg;
  600. u32 mode;
  601. u8 fast;
  602. addr1 = 0x40 + 4 * (adev->devno + 2 * ap->port_no);
  603. addr2 = 0x51 + 4 * ap->port_no;
  604. /* Fast interrupt prediction disable, hold off interrupt disable */
  605. pci_read_config_byte(pdev, addr2, &fast);
  606. fast &= ~0x07;
  607. pci_write_config_byte(pdev, addr2, fast);
  608. pci_read_config_dword(pdev, addr1, &reg);
  609. mode = hpt37x_find_mode(ap, adev->pio_mode);
  610. printk("Find mode for %d reports %X\n", adev->pio_mode, mode);
  611. mode &= ~0x80000000; /* No FIFO in PIO */
  612. mode &= ~0x30070000; /* Leave config bits alone */
  613. reg &= 0x30070000; /* Strip timing bits */
  614. pci_write_config_dword(pdev, addr1, reg | mode);
  615. }
  616. /**
  617. * hpt372_set_dmamode - DMA timing setup
  618. * @ap: ATA interface
  619. * @adev: Device being configured
  620. *
  621. * Set up the channel for MWDMA or UDMA modes. Much the same as with
  622. * PIO, load the mode number and then set MWDMA or UDMA flag.
  623. */
  624. static void hpt372_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  625. {
  626. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  627. u32 addr1, addr2;
  628. u32 reg;
  629. u32 mode;
  630. u8 fast;
  631. addr1 = 0x40 + 4 * (adev->devno + 2 * ap->port_no);
  632. addr2 = 0x51 + 4 * ap->port_no;
  633. /* Fast interrupt prediction disable, hold off interrupt disable */
  634. pci_read_config_byte(pdev, addr2, &fast);
  635. fast &= ~0x07;
  636. pci_write_config_byte(pdev, addr2, fast);
  637. pci_read_config_dword(pdev, addr1, &reg);
  638. mode = hpt37x_find_mode(ap, adev->dma_mode);
  639. printk("Find mode for DMA %d reports %X\n", adev->dma_mode, mode);
  640. mode &= ~0xC0000000; /* Leave config bits alone */
  641. mode |= 0x80000000; /* FIFO in MWDMA or UDMA */
  642. reg &= 0xC0000000; /* Strip timing bits */
  643. pci_write_config_dword(pdev, addr1, reg | mode);
  644. }
  645. /**
  646. * hpt37x_bmdma_end - DMA engine stop
  647. * @qc: ATA command
  648. *
  649. * Clean up after the HPT372 and later DMA engine
  650. */
  651. static void hpt37x_bmdma_stop(struct ata_queued_cmd *qc)
  652. {
  653. struct ata_port *ap = qc->ap;
  654. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  655. int mscreg = 0x50 + 2 * ap->port_no;
  656. u8 bwsr_stat, msc_stat;
  657. pci_read_config_byte(pdev, 0x6A, &bwsr_stat);
  658. pci_read_config_byte(pdev, mscreg, &msc_stat);
  659. if (bwsr_stat & (1 << ap->port_no))
  660. pci_write_config_byte(pdev, mscreg, msc_stat | 0x30);
  661. ata_bmdma_stop(qc);
  662. }
  663. static struct scsi_host_template hpt37x_sht = {
  664. .module = THIS_MODULE,
  665. .name = DRV_NAME,
  666. .ioctl = ata_scsi_ioctl,
  667. .queuecommand = ata_scsi_queuecmd,
  668. .can_queue = ATA_DEF_QUEUE,
  669. .this_id = ATA_SHT_THIS_ID,
  670. .sg_tablesize = LIBATA_MAX_PRD,
  671. .max_sectors = ATA_MAX_SECTORS,
  672. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  673. .emulated = ATA_SHT_EMULATED,
  674. .use_clustering = ATA_SHT_USE_CLUSTERING,
  675. .proc_name = DRV_NAME,
  676. .dma_boundary = ATA_DMA_BOUNDARY,
  677. .slave_configure = ata_scsi_slave_config,
  678. .slave_destroy = ata_scsi_slave_destroy,
  679. .bios_param = ata_std_bios_param,
  680. };
  681. /*
  682. * Configuration for HPT370
  683. */
  684. static struct ata_port_operations hpt370_port_ops = {
  685. .port_disable = ata_port_disable,
  686. .set_piomode = hpt370_set_piomode,
  687. .set_dmamode = hpt370_set_dmamode,
  688. .mode_filter = hpt370_filter,
  689. .tf_load = ata_tf_load,
  690. .tf_read = ata_tf_read,
  691. .check_status = ata_check_status,
  692. .exec_command = ata_exec_command,
  693. .dev_select = ata_std_dev_select,
  694. .freeze = ata_bmdma_freeze,
  695. .thaw = ata_bmdma_thaw,
  696. .error_handler = hpt37x_error_handler,
  697. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  698. .bmdma_setup = ata_bmdma_setup,
  699. .bmdma_start = hpt370_bmdma_start,
  700. .bmdma_stop = hpt370_bmdma_stop,
  701. .bmdma_status = ata_bmdma_status,
  702. .qc_prep = ata_qc_prep,
  703. .qc_issue = ata_qc_issue_prot,
  704. .data_xfer = ata_pio_data_xfer,
  705. .irq_handler = ata_interrupt,
  706. .irq_clear = ata_bmdma_irq_clear,
  707. .port_start = ata_port_start,
  708. .port_stop = ata_port_stop,
  709. .host_stop = ata_host_stop
  710. };
  711. /*
  712. * Configuration for HPT370A. Close to 370 but less filters
  713. */
  714. static struct ata_port_operations hpt370a_port_ops = {
  715. .port_disable = ata_port_disable,
  716. .set_piomode = hpt370_set_piomode,
  717. .set_dmamode = hpt370_set_dmamode,
  718. .mode_filter = hpt370a_filter,
  719. .tf_load = ata_tf_load,
  720. .tf_read = ata_tf_read,
  721. .check_status = ata_check_status,
  722. .exec_command = ata_exec_command,
  723. .dev_select = ata_std_dev_select,
  724. .freeze = ata_bmdma_freeze,
  725. .thaw = ata_bmdma_thaw,
  726. .error_handler = hpt37x_error_handler,
  727. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  728. .bmdma_setup = ata_bmdma_setup,
  729. .bmdma_start = hpt370_bmdma_start,
  730. .bmdma_stop = hpt370_bmdma_stop,
  731. .bmdma_status = ata_bmdma_status,
  732. .qc_prep = ata_qc_prep,
  733. .qc_issue = ata_qc_issue_prot,
  734. .data_xfer = ata_pio_data_xfer,
  735. .irq_handler = ata_interrupt,
  736. .irq_clear = ata_bmdma_irq_clear,
  737. .port_start = ata_port_start,
  738. .port_stop = ata_port_stop,
  739. .host_stop = ata_host_stop
  740. };
  741. /*
  742. * Configuration for HPT372, HPT371, HPT302. Slightly different PIO
  743. * and DMA mode setting functionality.
  744. */
  745. static struct ata_port_operations hpt372_port_ops = {
  746. .port_disable = ata_port_disable,
  747. .set_piomode = hpt372_set_piomode,
  748. .set_dmamode = hpt372_set_dmamode,
  749. .mode_filter = ata_pci_default_filter,
  750. .tf_load = ata_tf_load,
  751. .tf_read = ata_tf_read,
  752. .check_status = ata_check_status,
  753. .exec_command = ata_exec_command,
  754. .dev_select = ata_std_dev_select,
  755. .freeze = ata_bmdma_freeze,
  756. .thaw = ata_bmdma_thaw,
  757. .error_handler = hpt37x_error_handler,
  758. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  759. .bmdma_setup = ata_bmdma_setup,
  760. .bmdma_start = ata_bmdma_start,
  761. .bmdma_stop = hpt37x_bmdma_stop,
  762. .bmdma_status = ata_bmdma_status,
  763. .qc_prep = ata_qc_prep,
  764. .qc_issue = ata_qc_issue_prot,
  765. .data_xfer = ata_pio_data_xfer,
  766. .irq_handler = ata_interrupt,
  767. .irq_clear = ata_bmdma_irq_clear,
  768. .port_start = ata_port_start,
  769. .port_stop = ata_port_stop,
  770. .host_stop = ata_host_stop
  771. };
  772. /*
  773. * Configuration for HPT374. Mode setting works like 372 and friends
  774. * but we have a different cable detection procedure.
  775. */
  776. static struct ata_port_operations hpt374_port_ops = {
  777. .port_disable = ata_port_disable,
  778. .set_piomode = hpt372_set_piomode,
  779. .set_dmamode = hpt372_set_dmamode,
  780. .mode_filter = ata_pci_default_filter,
  781. .tf_load = ata_tf_load,
  782. .tf_read = ata_tf_read,
  783. .check_status = ata_check_status,
  784. .exec_command = ata_exec_command,
  785. .dev_select = ata_std_dev_select,
  786. .freeze = ata_bmdma_freeze,
  787. .thaw = ata_bmdma_thaw,
  788. .error_handler = hpt374_error_handler,
  789. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  790. .bmdma_setup = ata_bmdma_setup,
  791. .bmdma_start = ata_bmdma_start,
  792. .bmdma_stop = hpt37x_bmdma_stop,
  793. .bmdma_status = ata_bmdma_status,
  794. .qc_prep = ata_qc_prep,
  795. .qc_issue = ata_qc_issue_prot,
  796. .data_xfer = ata_pio_data_xfer,
  797. .irq_handler = ata_interrupt,
  798. .irq_clear = ata_bmdma_irq_clear,
  799. .port_start = ata_port_start,
  800. .port_stop = ata_port_stop,
  801. .host_stop = ata_host_stop
  802. };
  803. /**
  804. * htp37x_clock_slot - Turn timing to PC clock entry
  805. * @freq: Reported frequency timing
  806. * @base: Base timing
  807. *
  808. * Turn the timing data intoa clock slot (0 for 33, 1 for 40, 2 for 50
  809. * and 3 for 66Mhz)
  810. */
  811. static int hpt37x_clock_slot(unsigned int freq, unsigned int base)
  812. {
  813. unsigned int f = (base * freq) / 192; /* Mhz */
  814. if (f < 40)
  815. return 0; /* 33Mhz slot */
  816. if (f < 45)
  817. return 1; /* 40Mhz slot */
  818. if (f < 55)
  819. return 2; /* 50Mhz slot */
  820. return 3; /* 60Mhz slot */
  821. }
  822. /**
  823. * hpt37x_calibrate_dpll - Calibrate the DPLL loop
  824. * @dev: PCI device
  825. *
  826. * Perform a calibration cycle on the HPT37x DPLL. Returns 1 if this
  827. * succeeds
  828. */
  829. static int hpt37x_calibrate_dpll(struct pci_dev *dev)
  830. {
  831. u8 reg5b;
  832. u32 reg5c;
  833. int tries;
  834. for(tries = 0; tries < 0x5000; tries++) {
  835. udelay(50);
  836. pci_read_config_byte(dev, 0x5b, &reg5b);
  837. if (reg5b & 0x80) {
  838. /* See if it stays set */
  839. for(tries = 0; tries < 0x1000; tries ++) {
  840. pci_read_config_byte(dev, 0x5b, &reg5b);
  841. /* Failed ? */
  842. if ((reg5b & 0x80) == 0)
  843. return 0;
  844. }
  845. /* Turn off tuning, we have the DPLL set */
  846. pci_read_config_dword(dev, 0x5c, &reg5c);
  847. pci_write_config_dword(dev, 0x5c, reg5c & ~ 0x100);
  848. return 1;
  849. }
  850. }
  851. /* Never went stable */
  852. return 0;
  853. }
  854. /**
  855. * hpt37x_init_one - Initialise an HPT37X/302
  856. * @dev: PCI device
  857. * @id: Entry in match table
  858. *
  859. * Initialise an HPT37x device. There are some interesting complications
  860. * here. Firstly the chip may report 366 and be one of several variants.
  861. * Secondly all the timings depend on the clock for the chip which we must
  862. * detect and look up
  863. *
  864. * This is the known chip mappings. It may be missing a couple of later
  865. * releases.
  866. *
  867. * Chip version PCI Rev Notes
  868. * HPT366 4 (HPT366) 0 Other driver
  869. * HPT366 4 (HPT366) 1 Other driver
  870. * HPT368 4 (HPT366) 2 Other driver
  871. * HPT370 4 (HPT366) 3 UDMA100
  872. * HPT370A 4 (HPT366) 4 UDMA100
  873. * HPT372 4 (HPT366) 5 UDMA133 (1)
  874. * HPT372N 4 (HPT366) 6 Other driver
  875. * HPT372A 5 (HPT372) 1 UDMA133 (1)
  876. * HPT372N 5 (HPT372) 2 Other driver
  877. * HPT302 6 (HPT302) 1 UDMA133
  878. * HPT302N 6 (HPT302) 2 Other driver
  879. * HPT371 7 (HPT371) * UDMA133
  880. * HPT374 8 (HPT374) * UDMA133 4 channel
  881. * HPT372N 9 (HPT372N) * Other driver
  882. *
  883. * (1) UDMA133 support depends on the bus clock
  884. */
  885. static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  886. {
  887. /* HPT370 - UDMA100 */
  888. static struct ata_port_info info_hpt370 = {
  889. .sht = &hpt37x_sht,
  890. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  891. .pio_mask = 0x1f,
  892. .mwdma_mask = 0x07,
  893. .udma_mask = 0x3f,
  894. .port_ops = &hpt370_port_ops
  895. };
  896. /* HPT370A - UDMA100 */
  897. static struct ata_port_info info_hpt370a = {
  898. .sht = &hpt37x_sht,
  899. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  900. .pio_mask = 0x1f,
  901. .mwdma_mask = 0x07,
  902. .udma_mask = 0x3f,
  903. .port_ops = &hpt370a_port_ops
  904. };
  905. /* HPT371, 372 and friends - UDMA133 */
  906. static struct ata_port_info info_hpt372 = {
  907. .sht = &hpt37x_sht,
  908. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  909. .pio_mask = 0x1f,
  910. .mwdma_mask = 0x07,
  911. .udma_mask = 0x7f,
  912. .port_ops = &hpt372_port_ops
  913. };
  914. /* HPT371, 372 and friends - UDMA100 at 50MHz clock */
  915. static struct ata_port_info info_hpt372_50 = {
  916. .sht = &hpt37x_sht,
  917. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  918. .pio_mask = 0x1f,
  919. .mwdma_mask = 0x07,
  920. .udma_mask = 0x3f,
  921. .port_ops = &hpt372_port_ops
  922. };
  923. /* HPT374 - UDMA133 */
  924. static struct ata_port_info info_hpt374 = {
  925. .sht = &hpt37x_sht,
  926. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  927. .pio_mask = 0x1f,
  928. .mwdma_mask = 0x07,
  929. .udma_mask = 0x7f,
  930. .port_ops = &hpt374_port_ops
  931. };
  932. static const int MHz[4] = { 33, 40, 50, 66 };
  933. struct ata_port_info *port_info[2];
  934. struct ata_port_info *port;
  935. u8 irqmask;
  936. u32 class_rev;
  937. u32 freq;
  938. const struct hpt_chip *chip_table;
  939. int clock_slot;
  940. pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
  941. class_rev &= 0xFF;
  942. if (dev->device == PCI_DEVICE_ID_TTI_HPT366) {
  943. /* May be a later chip in disguise. Check */
  944. /* Older chips are in the HPT366 driver. Ignore them */
  945. if (class_rev < 3)
  946. return -ENODEV;
  947. /* N series chips have their own driver. Ignore */
  948. if (class_rev == 6)
  949. return -ENODEV;
  950. switch(class_rev) {
  951. case 3:
  952. port = &info_hpt370;
  953. chip_table = &hpt370;
  954. break;
  955. case 4:
  956. port = &info_hpt370a;
  957. chip_table = &hpt370a;
  958. break;
  959. case 5:
  960. port = &info_hpt372;
  961. chip_table = &hpt372;
  962. break;
  963. default:
  964. printk(KERN_ERR "pata_hpt37x: Unknown HPT366 subtype please report (%d).\n", class_rev);
  965. return -ENODEV;
  966. }
  967. } else {
  968. switch(dev->device) {
  969. case PCI_DEVICE_ID_TTI_HPT372:
  970. /* 372N if rev >= 2*/
  971. if (class_rev >= 2)
  972. return -ENODEV;
  973. port = &info_hpt372;
  974. chip_table = &hpt372a;
  975. break;
  976. case PCI_DEVICE_ID_TTI_HPT302:
  977. /* 302N if rev > 1 */
  978. if (class_rev > 1)
  979. return -ENODEV;
  980. port = &info_hpt372;
  981. /* Check this */
  982. chip_table = &hpt302;
  983. break;
  984. case PCI_DEVICE_ID_TTI_HPT371:
  985. port = &info_hpt372;
  986. chip_table = &hpt371;
  987. break;
  988. case PCI_DEVICE_ID_TTI_HPT374:
  989. chip_table = &hpt374;
  990. port = &info_hpt374;
  991. break;
  992. default:
  993. printk(KERN_ERR "pata_hpt37x: PCI table is bogus please report (%d).\n", dev->device);
  994. return -ENODEV;
  995. }
  996. }
  997. /* Ok so this is a chip we support */
  998. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
  999. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
  1000. pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  1001. pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
  1002. pci_read_config_byte(dev, 0x5A, &irqmask);
  1003. irqmask &= ~0x10;
  1004. pci_write_config_byte(dev, 0x5a, irqmask);
  1005. /*
  1006. * default to pci clock. make sure MA15/16 are set to output
  1007. * to prevent drives having problems with 40-pin cables. Needed
  1008. * for some drives such as IBM-DTLA which will not enter ready
  1009. * state on reset when PDIAG is a input.
  1010. */
  1011. pci_write_config_byte(dev, 0x5b, 0x23);
  1012. pci_read_config_dword(dev, 0x70, &freq);
  1013. if ((freq >> 12) != 0xABCDE) {
  1014. int i;
  1015. u8 sr;
  1016. u32 total = 0;
  1017. printk(KERN_WARNING "pata_hpt37x: BIOS has not set timing clocks.\n");
  1018. /* This is the process the HPT371 BIOS is reported to use */
  1019. for(i = 0; i < 128; i++) {
  1020. pci_read_config_byte(dev, 0x78, &sr);
  1021. total += sr;
  1022. udelay(15);
  1023. }
  1024. freq = total / 128;
  1025. }
  1026. freq &= 0x1FF;
  1027. /*
  1028. * Turn the frequency check into a band and then find a timing
  1029. * table to match it.
  1030. */
  1031. clock_slot = hpt37x_clock_slot(freq, chip_table->base);
  1032. if (chip_table->clocks[clock_slot] == NULL) {
  1033. /*
  1034. * We need to try PLL mode instead
  1035. */
  1036. unsigned int f_low = (MHz[clock_slot] * chip_table->base) / 192;
  1037. unsigned int f_high = f_low + 2;
  1038. int adjust;
  1039. for(adjust = 0; adjust < 8; adjust++) {
  1040. if (hpt37x_calibrate_dpll(dev))
  1041. break;
  1042. /* See if it'll settle at a fractionally different clock */
  1043. if ((adjust & 3) == 3) {
  1044. f_low --;
  1045. f_high ++;
  1046. }
  1047. pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low);
  1048. }
  1049. if (adjust == 8) {
  1050. printk(KERN_WARNING "hpt37x: DPLL did not stabilize.\n");
  1051. return -ENODEV;
  1052. }
  1053. /* Check if this works for all cases */
  1054. port->private_data = (void *)hpt370_timings_66;
  1055. printk(KERN_INFO "hpt37x: Bus clock %dMHz, using DPLL.\n", MHz[clock_slot]);
  1056. } else {
  1057. port->private_data = (void *)chip_table->clocks[clock_slot];
  1058. /*
  1059. * Perform a final fixup. The 371 and 372 clock determines
  1060. * if UDMA133 is available.
  1061. */
  1062. if (clock_slot == 2 && chip_table == &hpt372) { /* 50Mhz */
  1063. printk(KERN_WARNING "pata_hpt37x: No UDMA133 support available with 50MHz bus clock.\n");
  1064. if (port == &info_hpt372)
  1065. port = &info_hpt372_50;
  1066. else BUG();
  1067. }
  1068. printk(KERN_INFO "hpt37x: %s: Bus clock %dMHz.\n", chip_table->name, MHz[clock_slot]);
  1069. }
  1070. port_info[0] = port_info[1] = port;
  1071. /* Now kick off ATA set up */
  1072. return ata_pci_init_one(dev, port_info, 2);
  1073. }
  1074. static const struct pci_device_id hpt37x[] = {
  1075. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT366), },
  1076. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT371), },
  1077. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT372), },
  1078. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT374), },
  1079. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT302), },
  1080. { },
  1081. };
  1082. static struct pci_driver hpt37x_pci_driver = {
  1083. .name = DRV_NAME,
  1084. .id_table = hpt37x,
  1085. .probe = hpt37x_init_one,
  1086. .remove = ata_pci_remove_one
  1087. };
  1088. static int __init hpt37x_init(void)
  1089. {
  1090. return pci_register_driver(&hpt37x_pci_driver);
  1091. }
  1092. static void __exit hpt37x_exit(void)
  1093. {
  1094. pci_unregister_driver(&hpt37x_pci_driver);
  1095. }
  1096. MODULE_AUTHOR("Alan Cox");
  1097. MODULE_DESCRIPTION("low-level driver for the Highpoint HPT37x/30x");
  1098. MODULE_LICENSE("GPL");
  1099. MODULE_DEVICE_TABLE(pci, hpt37x);
  1100. MODULE_VERSION(DRV_VERSION);
  1101. module_init(hpt37x_init);
  1102. module_exit(hpt37x_exit);