pata_hpt37x.c 31 KB

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