pata_hpt37x.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  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. .eng_timeout = ata_eng_timeout,
  692. .data_xfer = ata_pio_data_xfer,
  693. .irq_handler = ata_interrupt,
  694. .irq_clear = ata_bmdma_irq_clear,
  695. .port_start = ata_port_start,
  696. .port_stop = ata_port_stop,
  697. .host_stop = ata_host_stop
  698. };
  699. /*
  700. * Configuration for HPT370A. Close to 370 but less filters
  701. */
  702. static struct ata_port_operations hpt370a_port_ops = {
  703. .port_disable = ata_port_disable,
  704. .set_piomode = hpt370_set_piomode,
  705. .set_dmamode = hpt370_set_dmamode,
  706. .mode_filter = hpt370a_filter,
  707. .tf_load = ata_tf_load,
  708. .tf_read = ata_tf_read,
  709. .check_status = ata_check_status,
  710. .exec_command = ata_exec_command,
  711. .dev_select = ata_std_dev_select,
  712. .freeze = ata_bmdma_freeze,
  713. .thaw = ata_bmdma_thaw,
  714. .error_handler = hpt37x_error_handler,
  715. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  716. .bmdma_setup = ata_bmdma_setup,
  717. .bmdma_start = hpt370_bmdma_start,
  718. .bmdma_stop = hpt370_bmdma_stop,
  719. .bmdma_status = ata_bmdma_status,
  720. .qc_prep = ata_qc_prep,
  721. .qc_issue = ata_qc_issue_prot,
  722. .eng_timeout = ata_eng_timeout,
  723. .data_xfer = ata_pio_data_xfer,
  724. .irq_handler = ata_interrupt,
  725. .irq_clear = ata_bmdma_irq_clear,
  726. .port_start = ata_port_start,
  727. .port_stop = ata_port_stop,
  728. .host_stop = ata_host_stop
  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. .eng_timeout = ata_eng_timeout,
  755. .data_xfer = ata_pio_data_xfer,
  756. .irq_handler = ata_interrupt,
  757. .irq_clear = ata_bmdma_irq_clear,
  758. .port_start = ata_port_start,
  759. .port_stop = ata_port_stop,
  760. .host_stop = ata_host_stop
  761. };
  762. /*
  763. * Configuration for HPT374. Mode setting works like 372 and friends
  764. * but we have a different cable detection procedure.
  765. */
  766. static struct ata_port_operations hpt374_port_ops = {
  767. .port_disable = ata_port_disable,
  768. .set_piomode = hpt372_set_piomode,
  769. .set_dmamode = hpt372_set_dmamode,
  770. .mode_filter = ata_pci_default_filter,
  771. .tf_load = ata_tf_load,
  772. .tf_read = ata_tf_read,
  773. .check_status = ata_check_status,
  774. .exec_command = ata_exec_command,
  775. .dev_select = ata_std_dev_select,
  776. .freeze = ata_bmdma_freeze,
  777. .thaw = ata_bmdma_thaw,
  778. .error_handler = hpt374_error_handler,
  779. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  780. .bmdma_setup = ata_bmdma_setup,
  781. .bmdma_start = ata_bmdma_start,
  782. .bmdma_stop = hpt37x_bmdma_stop,
  783. .bmdma_status = ata_bmdma_status,
  784. .qc_prep = ata_qc_prep,
  785. .qc_issue = ata_qc_issue_prot,
  786. .eng_timeout = ata_eng_timeout,
  787. .data_xfer = ata_pio_data_xfer,
  788. .irq_handler = ata_interrupt,
  789. .irq_clear = ata_bmdma_irq_clear,
  790. .port_start = ata_port_start,
  791. .port_stop = ata_port_stop,
  792. .host_stop = ata_host_stop
  793. };
  794. /**
  795. * htp37x_clock_slot - Turn timing to PC clock entry
  796. * @freq: Reported frequency timing
  797. * @base: Base timing
  798. *
  799. * Turn the timing data intoa clock slot (0 for 33, 1 for 40, 2 for 50
  800. * and 3 for 66Mhz)
  801. */
  802. static int hpt37x_clock_slot(unsigned int freq, unsigned int base)
  803. {
  804. unsigned int f = (base * freq) / 192; /* Mhz */
  805. if (f < 40)
  806. return 0; /* 33Mhz slot */
  807. if (f < 45)
  808. return 1; /* 40Mhz slot */
  809. if (f < 55)
  810. return 2; /* 50Mhz slot */
  811. return 3; /* 60Mhz slot */
  812. }
  813. /**
  814. * hpt37x_calibrate_dpll - Calibrate the DPLL loop
  815. * @dev: PCI device
  816. *
  817. * Perform a calibration cycle on the HPT37x DPLL. Returns 1 if this
  818. * succeeds
  819. */
  820. static int hpt37x_calibrate_dpll(struct pci_dev *dev)
  821. {
  822. u8 reg5b;
  823. u32 reg5c;
  824. int tries;
  825. for(tries = 0; tries < 0x5000; tries++) {
  826. udelay(50);
  827. pci_read_config_byte(dev, 0x5b, &reg5b);
  828. if (reg5b & 0x80) {
  829. /* See if it stays set */
  830. for(tries = 0; tries < 0x1000; tries ++) {
  831. pci_read_config_byte(dev, 0x5b, &reg5b);
  832. /* Failed ? */
  833. if ((reg5b & 0x80) == 0)
  834. return 0;
  835. }
  836. /* Turn off tuning, we have the DPLL set */
  837. pci_read_config_dword(dev, 0x5c, &reg5c);
  838. pci_write_config_dword(dev, 0x5c, reg5c & ~ 0x100);
  839. return 1;
  840. }
  841. }
  842. /* Never went stable */
  843. return 0;
  844. }
  845. /**
  846. * hpt37x_init_one - Initialise an HPT37X/302
  847. * @dev: PCI device
  848. * @id: Entry in match table
  849. *
  850. * Initialise an HPT37x device. There are some interesting complications
  851. * here. Firstly the chip may report 366 and be one of several variants.
  852. * Secondly all the timings depend on the clock for the chip which we must
  853. * detect and look up
  854. *
  855. * This is the known chip mappings. It may be missing a couple of later
  856. * releases.
  857. *
  858. * Chip version PCI Rev Notes
  859. * HPT366 4 (HPT366) 0 Other driver
  860. * HPT366 4 (HPT366) 1 Other driver
  861. * HPT368 4 (HPT366) 2 Other driver
  862. * HPT370 4 (HPT366) 3 UDMA100
  863. * HPT370A 4 (HPT366) 4 UDMA100
  864. * HPT372 4 (HPT366) 5 UDMA133 (1)
  865. * HPT372N 4 (HPT366) 6 Other driver
  866. * HPT372A 5 (HPT372) 1 UDMA133 (1)
  867. * HPT372N 5 (HPT372) 2 Other driver
  868. * HPT302 6 (HPT302) 1 UDMA133
  869. * HPT302N 6 (HPT302) 2 Other driver
  870. * HPT371 7 (HPT371) * UDMA133
  871. * HPT374 8 (HPT374) * UDMA133 4 channel
  872. * HPT372N 9 (HPT372N) * Other driver
  873. *
  874. * (1) UDMA133 support depends on the bus clock
  875. */
  876. static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  877. {
  878. /* HPT370 - UDMA100 */
  879. static struct ata_port_info info_hpt370 = {
  880. .sht = &hpt37x_sht,
  881. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  882. .pio_mask = 0x1f,
  883. .mwdma_mask = 0x07,
  884. .udma_mask = 0x3f,
  885. .port_ops = &hpt370_port_ops
  886. };
  887. /* HPT370A - UDMA100 */
  888. static struct ata_port_info info_hpt370a = {
  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 = &hpt370a_port_ops
  895. };
  896. /* HPT371, 372 and friends - UDMA133 */
  897. static struct ata_port_info info_hpt372 = {
  898. .sht = &hpt37x_sht,
  899. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  900. .pio_mask = 0x1f,
  901. .mwdma_mask = 0x07,
  902. .udma_mask = 0x7f,
  903. .port_ops = &hpt372_port_ops
  904. };
  905. /* HPT371, 372 and friends - UDMA100 at 50MHz clock */
  906. static struct ata_port_info info_hpt372_50 = {
  907. .sht = &hpt37x_sht,
  908. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  909. .pio_mask = 0x1f,
  910. .mwdma_mask = 0x07,
  911. .udma_mask = 0x3f,
  912. .port_ops = &hpt372_port_ops
  913. };
  914. /* HPT374 - UDMA133 */
  915. static struct ata_port_info info_hpt374 = {
  916. .sht = &hpt37x_sht,
  917. .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
  918. .pio_mask = 0x1f,
  919. .mwdma_mask = 0x07,
  920. .udma_mask = 0x7f,
  921. .port_ops = &hpt374_port_ops
  922. };
  923. static const int MHz[4] = { 33, 40, 50, 66 };
  924. struct ata_port_info *port_info[2];
  925. struct ata_port_info *port;
  926. u8 irqmask;
  927. u32 class_rev;
  928. u32 freq;
  929. const struct hpt_chip *chip_table;
  930. int clock_slot;
  931. pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
  932. class_rev &= 0xFF;
  933. if (dev->device == PCI_DEVICE_ID_TTI_HPT366) {
  934. /* May be a later chip in disguise. Check */
  935. /* Older chips are in the HPT366 driver. Ignore them */
  936. if (class_rev < 3)
  937. return -ENODEV;
  938. /* N series chips have their own driver. Ignore */
  939. if (class_rev == 6)
  940. return -ENODEV;
  941. switch(class_rev) {
  942. case 3:
  943. port = &info_hpt370;
  944. chip_table = &hpt370;
  945. break;
  946. case 4:
  947. port = &info_hpt370a;
  948. chip_table = &hpt370a;
  949. break;
  950. case 5:
  951. port = &info_hpt372;
  952. chip_table = &hpt372;
  953. break;
  954. default:
  955. printk(KERN_ERR "pata_hpt37x: Unknown HPT366 subtype please report (%d).\n", class_rev);
  956. return -ENODEV;
  957. }
  958. } else {
  959. switch(dev->device) {
  960. case PCI_DEVICE_ID_TTI_HPT372:
  961. /* 372N if rev >= 2*/
  962. if (class_rev >= 2)
  963. return -ENODEV;
  964. port = &info_hpt372;
  965. chip_table = &hpt372a;
  966. break;
  967. case PCI_DEVICE_ID_TTI_HPT302:
  968. /* 302N if rev > 1 */
  969. if (class_rev > 1)
  970. return -ENODEV;
  971. port = &info_hpt372;
  972. /* Check this */
  973. chip_table = &hpt302;
  974. break;
  975. case PCI_DEVICE_ID_TTI_HPT371:
  976. port = &info_hpt372;
  977. chip_table = &hpt371;
  978. break;
  979. case PCI_DEVICE_ID_TTI_HPT374:
  980. chip_table = &hpt374;
  981. port = &info_hpt374;
  982. break;
  983. default:
  984. printk(KERN_ERR "pata_hpt37x: PCI table is bogus please report (%d).\n", dev->device);
  985. return -ENODEV;
  986. }
  987. }
  988. /* Ok so this is a chip we support */
  989. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
  990. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
  991. pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  992. pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
  993. pci_read_config_byte(dev, 0x5A, &irqmask);
  994. irqmask &= ~0x10;
  995. pci_write_config_byte(dev, 0x5a, irqmask);
  996. /*
  997. * default to pci clock. make sure MA15/16 are set to output
  998. * to prevent drives having problems with 40-pin cables. Needed
  999. * for some drives such as IBM-DTLA which will not enter ready
  1000. * state on reset when PDIAG is a input.
  1001. */
  1002. pci_write_config_byte(dev, 0x5b, 0x23);
  1003. pci_read_config_dword(dev, 0x70, &freq);
  1004. if ((freq >> 12) != 0xABCDE) {
  1005. int i;
  1006. u8 sr;
  1007. u32 total = 0;
  1008. printk(KERN_WARNING "pata_hpt37x: BIOS has not set timing clocks.\n");
  1009. /* This is the process the HPT371 BIOS is reported to use */
  1010. for(i = 0; i < 128; i++) {
  1011. pci_read_config_byte(dev, 0x78, &sr);
  1012. total += sr;
  1013. udelay(15);
  1014. }
  1015. freq = total / 128;
  1016. }
  1017. freq &= 0x1FF;
  1018. /*
  1019. * Turn the frequency check into a band and then find a timing
  1020. * table to match it.
  1021. */
  1022. clock_slot = hpt37x_clock_slot(freq, chip_table->base);
  1023. if (chip_table->clocks[clock_slot] == NULL) {
  1024. /*
  1025. * We need to try PLL mode instead
  1026. */
  1027. unsigned int f_low = (MHz[clock_slot] * chip_table->base) / 192;
  1028. unsigned int f_high = f_low + 2;
  1029. int adjust;
  1030. for(adjust = 0; adjust < 8; adjust++) {
  1031. if (hpt37x_calibrate_dpll(dev))
  1032. break;
  1033. /* See if it'll settle at a fractionally different clock */
  1034. if ((adjust & 3) == 3) {
  1035. f_low --;
  1036. f_high ++;
  1037. }
  1038. pci_write_config_dword(dev, 0x5C, (f_high << 16) | f_low);
  1039. }
  1040. if (adjust == 8) {
  1041. printk(KERN_WARNING "hpt37x: DPLL did not stabilize.\n");
  1042. return -ENODEV;
  1043. }
  1044. /* Check if this works for all cases */
  1045. port->private_data = (void *)hpt370_timings_66;
  1046. printk(KERN_INFO "hpt37x: Bus clock %dMHz, using DPLL.\n", MHz[clock_slot]);
  1047. } else {
  1048. port->private_data = (void *)chip_table->clocks[clock_slot];
  1049. /*
  1050. * Perform a final fixup. The 371 and 372 clock determines
  1051. * if UDMA133 is available.
  1052. */
  1053. if (clock_slot == 2 && chip_table == &hpt372) { /* 50Mhz */
  1054. printk(KERN_WARNING "pata_hpt37x: No UDMA133 support available with 50MHz bus clock.\n");
  1055. if (port == &info_hpt372)
  1056. port = &info_hpt372_50;
  1057. else BUG();
  1058. }
  1059. printk(KERN_INFO "hpt37x: %s: Bus clock %dMHz.\n", chip_table->name, MHz[clock_slot]);
  1060. }
  1061. port_info[0] = port_info[1] = port;
  1062. /* Now kick off ATA set up */
  1063. return ata_pci_init_one(dev, port_info, 2);
  1064. }
  1065. static struct pci_device_id hpt37x[] = {
  1066. { PCI_DEVICE(PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT366), },
  1067. { PCI_DEVICE(PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT371), },
  1068. { PCI_DEVICE(PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT372), },
  1069. { PCI_DEVICE(PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT374), },
  1070. { PCI_DEVICE(PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT302), },
  1071. { 0, },
  1072. };
  1073. static struct pci_driver hpt37x_pci_driver = {
  1074. .name = DRV_NAME,
  1075. .id_table = hpt37x,
  1076. .probe = hpt37x_init_one,
  1077. .remove = ata_pci_remove_one
  1078. };
  1079. static int __init hpt37x_init(void)
  1080. {
  1081. return pci_register_driver(&hpt37x_pci_driver);
  1082. }
  1083. static void __exit hpt37x_exit(void)
  1084. {
  1085. pci_unregister_driver(&hpt37x_pci_driver);
  1086. }
  1087. MODULE_AUTHOR("Alan Cox");
  1088. MODULE_DESCRIPTION("low-level driver for the Highpoint HPT37x/30x");
  1089. MODULE_LICENSE("GPL");
  1090. MODULE_DEVICE_TABLE(pci, hpt37x);
  1091. MODULE_VERSION(DRV_VERSION);
  1092. module_init(hpt37x_init);
  1093. module_exit(hpt37x_exit);