hpt366.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  1. /*
  2. * linux/drivers/ide/pci/hpt366.c Version 0.36 April 25, 2003
  3. *
  4. * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org>
  5. * Portions Copyright (C) 2001 Sun Microsystems, Inc.
  6. * Portions Copyright (C) 2003 Red Hat Inc
  7. *
  8. * Thanks to HighPoint Technologies for their assistance, and hardware.
  9. * Special Thanks to Jon Burchmore in SanDiego for the deep pockets, his
  10. * donation of an ABit BP6 mainboard, processor, and memory acellerated
  11. * development and support.
  12. *
  13. *
  14. * Highpoint have their own driver (source except for the raid part)
  15. * available from http://www.highpoint-tech.com/hpt3xx-opensource-v131.tgz
  16. * This may be useful to anyone wanting to work on the mainstream hpt IDE.
  17. *
  18. * Note that final HPT370 support was done by force extraction of GPL.
  19. *
  20. * - add function for getting/setting power status of drive
  21. * - the HPT370's state machine can get confused. reset it before each dma
  22. * xfer to prevent that from happening.
  23. * - reset state engine whenever we get an error.
  24. * - check for busmaster state at end of dma.
  25. * - use new highpoint timings.
  26. * - detect bus speed using highpoint register.
  27. * - use pll if we don't have a clock table. added a 66MHz table that's
  28. * just 2x the 33MHz table.
  29. * - removed turnaround. NOTE: we never want to switch between pll and
  30. * pci clocks as the chip can glitch in those cases. the highpoint
  31. * approved workaround slows everything down too much to be useful. in
  32. * addition, we would have to serialize access to each chip.
  33. * Adrian Sun <a.sun@sun.com>
  34. *
  35. * add drive timings for 66MHz PCI bus,
  36. * fix ATA Cable signal detection, fix incorrect /proc info
  37. * add /proc display for per-drive PIO/DMA/UDMA mode and
  38. * per-channel ATA-33/66 Cable detect.
  39. * Duncan Laurie <void@sun.com>
  40. *
  41. * fixup /proc output for multiple controllers
  42. * Tim Hockin <thockin@sun.com>
  43. *
  44. * On hpt366:
  45. * Reset the hpt366 on error, reset on dma
  46. * Fix disabling Fast Interrupt hpt366.
  47. * Mike Waychison <crlf@sun.com>
  48. *
  49. * Added support for 372N clocking and clock switching. The 372N needs
  50. * different clocks on read/write. This requires overloading rw_disk and
  51. * other deeply crazy things. Thanks to <http://www.hoerstreich.de> for
  52. * keeping me sane.
  53. * Alan Cox <alan@redhat.com>
  54. *
  55. */
  56. #include <linux/config.h>
  57. #include <linux/types.h>
  58. #include <linux/module.h>
  59. #include <linux/kernel.h>
  60. #include <linux/delay.h>
  61. #include <linux/timer.h>
  62. #include <linux/mm.h>
  63. #include <linux/ioport.h>
  64. #include <linux/blkdev.h>
  65. #include <linux/hdreg.h>
  66. #include <linux/interrupt.h>
  67. #include <linux/pci.h>
  68. #include <linux/init.h>
  69. #include <linux/ide.h>
  70. #include <asm/uaccess.h>
  71. #include <asm/io.h>
  72. #include <asm/irq.h>
  73. /* various tuning parameters */
  74. #define HPT_RESET_STATE_ENGINE
  75. #undef HPT_DELAY_INTERRUPT
  76. #undef HPT_SERIALIZE_IO
  77. static const char *quirk_drives[] = {
  78. "QUANTUM FIREBALLlct08 08",
  79. "QUANTUM FIREBALLP KA6.4",
  80. "QUANTUM FIREBALLP LM20.4",
  81. "QUANTUM FIREBALLP LM20.5",
  82. NULL
  83. };
  84. static const char *bad_ata100_5[] = {
  85. "IBM-DTLA-307075",
  86. "IBM-DTLA-307060",
  87. "IBM-DTLA-307045",
  88. "IBM-DTLA-307030",
  89. "IBM-DTLA-307020",
  90. "IBM-DTLA-307015",
  91. "IBM-DTLA-305040",
  92. "IBM-DTLA-305030",
  93. "IBM-DTLA-305020",
  94. "IC35L010AVER07-0",
  95. "IC35L020AVER07-0",
  96. "IC35L030AVER07-0",
  97. "IC35L040AVER07-0",
  98. "IC35L060AVER07-0",
  99. "WDC AC310200R",
  100. NULL
  101. };
  102. static const char *bad_ata66_4[] = {
  103. "IBM-DTLA-307075",
  104. "IBM-DTLA-307060",
  105. "IBM-DTLA-307045",
  106. "IBM-DTLA-307030",
  107. "IBM-DTLA-307020",
  108. "IBM-DTLA-307015",
  109. "IBM-DTLA-305040",
  110. "IBM-DTLA-305030",
  111. "IBM-DTLA-305020",
  112. "IC35L010AVER07-0",
  113. "IC35L020AVER07-0",
  114. "IC35L030AVER07-0",
  115. "IC35L040AVER07-0",
  116. "IC35L060AVER07-0",
  117. "WDC AC310200R",
  118. NULL
  119. };
  120. static const char *bad_ata66_3[] = {
  121. "WDC AC310200R",
  122. NULL
  123. };
  124. static const char *bad_ata33[] = {
  125. "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3", "Maxtor 90845U3", "Maxtor 90650U2",
  126. "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5", "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2",
  127. "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6", "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4",
  128. "Maxtor 90510D4",
  129. "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2",
  130. "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7", "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4",
  131. "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5", "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2",
  132. NULL
  133. };
  134. struct chipset_bus_clock_list_entry {
  135. u8 xfer_speed;
  136. unsigned int chipset_settings;
  137. };
  138. /* key for bus clock timings
  139. * bit
  140. * 0:3 data_high_time. inactive time of DIOW_/DIOR_ for PIO and MW
  141. * DMA. cycles = value + 1
  142. * 4:8 data_low_time. active time of DIOW_/DIOR_ for PIO and MW
  143. * DMA. cycles = value + 1
  144. * 9:12 cmd_high_time. inactive time of DIOW_/DIOR_ during task file
  145. * register access.
  146. * 13:17 cmd_low_time. active time of DIOW_/DIOR_ during task file
  147. * register access.
  148. * 18:21 udma_cycle_time. clock freq and clock cycles for UDMA xfer.
  149. * during task file register access.
  150. * 22:24 pre_high_time. time to initialize 1st cycle for PIO and MW DMA
  151. * xfer.
  152. * 25:27 cmd_pre_high_time. time to initialize 1st PIO cycle for task
  153. * register access.
  154. * 28 UDMA enable
  155. * 29 DMA enable
  156. * 30 PIO_MST enable. if set, the chip is in bus master mode during
  157. * PIO.
  158. * 31 FIFO enable.
  159. */
  160. static struct chipset_bus_clock_list_entry forty_base_hpt366[] = {
  161. { XFER_UDMA_4, 0x900fd943 },
  162. { XFER_UDMA_3, 0x900ad943 },
  163. { XFER_UDMA_2, 0x900bd943 },
  164. { XFER_UDMA_1, 0x9008d943 },
  165. { XFER_UDMA_0, 0x9008d943 },
  166. { XFER_MW_DMA_2, 0xa008d943 },
  167. { XFER_MW_DMA_1, 0xa010d955 },
  168. { XFER_MW_DMA_0, 0xa010d9fc },
  169. { XFER_PIO_4, 0xc008d963 },
  170. { XFER_PIO_3, 0xc010d974 },
  171. { XFER_PIO_2, 0xc010d997 },
  172. { XFER_PIO_1, 0xc010d9c7 },
  173. { XFER_PIO_0, 0xc018d9d9 },
  174. { 0, 0x0120d9d9 }
  175. };
  176. static struct chipset_bus_clock_list_entry thirty_three_base_hpt366[] = {
  177. { XFER_UDMA_4, 0x90c9a731 },
  178. { XFER_UDMA_3, 0x90cfa731 },
  179. { XFER_UDMA_2, 0x90caa731 },
  180. { XFER_UDMA_1, 0x90cba731 },
  181. { XFER_UDMA_0, 0x90c8a731 },
  182. { XFER_MW_DMA_2, 0xa0c8a731 },
  183. { XFER_MW_DMA_1, 0xa0c8a732 }, /* 0xa0c8a733 */
  184. { XFER_MW_DMA_0, 0xa0c8a797 },
  185. { XFER_PIO_4, 0xc0c8a731 },
  186. { XFER_PIO_3, 0xc0c8a742 },
  187. { XFER_PIO_2, 0xc0d0a753 },
  188. { XFER_PIO_1, 0xc0d0a7a3 }, /* 0xc0d0a793 */
  189. { XFER_PIO_0, 0xc0d0a7aa }, /* 0xc0d0a7a7 */
  190. { 0, 0x0120a7a7 }
  191. };
  192. static struct chipset_bus_clock_list_entry twenty_five_base_hpt366[] = {
  193. { XFER_UDMA_4, 0x90c98521 },
  194. { XFER_UDMA_3, 0x90cf8521 },
  195. { XFER_UDMA_2, 0x90cf8521 },
  196. { XFER_UDMA_1, 0x90cb8521 },
  197. { XFER_UDMA_0, 0x90cb8521 },
  198. { XFER_MW_DMA_2, 0xa0ca8521 },
  199. { XFER_MW_DMA_1, 0xa0ca8532 },
  200. { XFER_MW_DMA_0, 0xa0ca8575 },
  201. { XFER_PIO_4, 0xc0ca8521 },
  202. { XFER_PIO_3, 0xc0ca8532 },
  203. { XFER_PIO_2, 0xc0ca8542 },
  204. { XFER_PIO_1, 0xc0d08572 },
  205. { XFER_PIO_0, 0xc0d08585 },
  206. { 0, 0x01208585 }
  207. };
  208. /* from highpoint documentation. these are old values */
  209. static struct chipset_bus_clock_list_entry thirty_three_base_hpt370[] = {
  210. /* { XFER_UDMA_5, 0x1A85F442, 0x16454e31 }, */
  211. { XFER_UDMA_5, 0x16454e31 },
  212. { XFER_UDMA_4, 0x16454e31 },
  213. { XFER_UDMA_3, 0x166d4e31 },
  214. { XFER_UDMA_2, 0x16494e31 },
  215. { XFER_UDMA_1, 0x164d4e31 },
  216. { XFER_UDMA_0, 0x16514e31 },
  217. { XFER_MW_DMA_2, 0x26514e21 },
  218. { XFER_MW_DMA_1, 0x26514e33 },
  219. { XFER_MW_DMA_0, 0x26514e97 },
  220. { XFER_PIO_4, 0x06514e21 },
  221. { XFER_PIO_3, 0x06514e22 },
  222. { XFER_PIO_2, 0x06514e33 },
  223. { XFER_PIO_1, 0x06914e43 },
  224. { XFER_PIO_0, 0x06914e57 },
  225. { 0, 0x06514e57 }
  226. };
  227. static struct chipset_bus_clock_list_entry sixty_six_base_hpt370[] = {
  228. { XFER_UDMA_5, 0x14846231 },
  229. { XFER_UDMA_4, 0x14886231 },
  230. { XFER_UDMA_3, 0x148c6231 },
  231. { XFER_UDMA_2, 0x148c6231 },
  232. { XFER_UDMA_1, 0x14906231 },
  233. { XFER_UDMA_0, 0x14986231 },
  234. { XFER_MW_DMA_2, 0x26514e21 },
  235. { XFER_MW_DMA_1, 0x26514e33 },
  236. { XFER_MW_DMA_0, 0x26514e97 },
  237. { XFER_PIO_4, 0x06514e21 },
  238. { XFER_PIO_3, 0x06514e22 },
  239. { XFER_PIO_2, 0x06514e33 },
  240. { XFER_PIO_1, 0x06914e43 },
  241. { XFER_PIO_0, 0x06914e57 },
  242. { 0, 0x06514e57 }
  243. };
  244. /* these are the current (4 sep 2001) timings from highpoint */
  245. static struct chipset_bus_clock_list_entry thirty_three_base_hpt370a[] = {
  246. { XFER_UDMA_5, 0x12446231 },
  247. { XFER_UDMA_4, 0x12446231 },
  248. { XFER_UDMA_3, 0x126c6231 },
  249. { XFER_UDMA_2, 0x12486231 },
  250. { XFER_UDMA_1, 0x124c6233 },
  251. { XFER_UDMA_0, 0x12506297 },
  252. { XFER_MW_DMA_2, 0x22406c31 },
  253. { XFER_MW_DMA_1, 0x22406c33 },
  254. { XFER_MW_DMA_0, 0x22406c97 },
  255. { XFER_PIO_4, 0x06414e31 },
  256. { XFER_PIO_3, 0x06414e42 },
  257. { XFER_PIO_2, 0x06414e53 },
  258. { XFER_PIO_1, 0x06814e93 },
  259. { XFER_PIO_0, 0x06814ea7 },
  260. { 0, 0x06814ea7 }
  261. };
  262. /* 2x 33MHz timings */
  263. static struct chipset_bus_clock_list_entry sixty_six_base_hpt370a[] = {
  264. { XFER_UDMA_5, 0x1488e673 },
  265. { XFER_UDMA_4, 0x1488e673 },
  266. { XFER_UDMA_3, 0x1498e673 },
  267. { XFER_UDMA_2, 0x1490e673 },
  268. { XFER_UDMA_1, 0x1498e677 },
  269. { XFER_UDMA_0, 0x14a0e73f },
  270. { XFER_MW_DMA_2, 0x2480fa73 },
  271. { XFER_MW_DMA_1, 0x2480fa77 },
  272. { XFER_MW_DMA_0, 0x2480fb3f },
  273. { XFER_PIO_4, 0x0c82be73 },
  274. { XFER_PIO_3, 0x0c82be95 },
  275. { XFER_PIO_2, 0x0c82beb7 },
  276. { XFER_PIO_1, 0x0d02bf37 },
  277. { XFER_PIO_0, 0x0d02bf5f },
  278. { 0, 0x0d02bf5f }
  279. };
  280. static struct chipset_bus_clock_list_entry fifty_base_hpt370a[] = {
  281. { XFER_UDMA_5, 0x12848242 },
  282. { XFER_UDMA_4, 0x12ac8242 },
  283. { XFER_UDMA_3, 0x128c8242 },
  284. { XFER_UDMA_2, 0x120c8242 },
  285. { XFER_UDMA_1, 0x12148254 },
  286. { XFER_UDMA_0, 0x121882ea },
  287. { XFER_MW_DMA_2, 0x22808242 },
  288. { XFER_MW_DMA_1, 0x22808254 },
  289. { XFER_MW_DMA_0, 0x228082ea },
  290. { XFER_PIO_4, 0x0a81f442 },
  291. { XFER_PIO_3, 0x0a81f443 },
  292. { XFER_PIO_2, 0x0a81f454 },
  293. { XFER_PIO_1, 0x0ac1f465 },
  294. { XFER_PIO_0, 0x0ac1f48a },
  295. { 0, 0x0ac1f48a }
  296. };
  297. static struct chipset_bus_clock_list_entry thirty_three_base_hpt372[] = {
  298. { XFER_UDMA_6, 0x1c81dc62 },
  299. { XFER_UDMA_5, 0x1c6ddc62 },
  300. { XFER_UDMA_4, 0x1c8ddc62 },
  301. { XFER_UDMA_3, 0x1c8edc62 }, /* checkme */
  302. { XFER_UDMA_2, 0x1c91dc62 },
  303. { XFER_UDMA_1, 0x1c9adc62 }, /* checkme */
  304. { XFER_UDMA_0, 0x1c82dc62 }, /* checkme */
  305. { XFER_MW_DMA_2, 0x2c829262 },
  306. { XFER_MW_DMA_1, 0x2c829266 }, /* checkme */
  307. { XFER_MW_DMA_0, 0x2c82922e }, /* checkme */
  308. { XFER_PIO_4, 0x0c829c62 },
  309. { XFER_PIO_3, 0x0c829c84 },
  310. { XFER_PIO_2, 0x0c829ca6 },
  311. { XFER_PIO_1, 0x0d029d26 },
  312. { XFER_PIO_0, 0x0d029d5e },
  313. { 0, 0x0d029d5e }
  314. };
  315. static struct chipset_bus_clock_list_entry fifty_base_hpt372[] = {
  316. { XFER_UDMA_5, 0x12848242 },
  317. { XFER_UDMA_4, 0x12ac8242 },
  318. { XFER_UDMA_3, 0x128c8242 },
  319. { XFER_UDMA_2, 0x120c8242 },
  320. { XFER_UDMA_1, 0x12148254 },
  321. { XFER_UDMA_0, 0x121882ea },
  322. { XFER_MW_DMA_2, 0x22808242 },
  323. { XFER_MW_DMA_1, 0x22808254 },
  324. { XFER_MW_DMA_0, 0x228082ea },
  325. { XFER_PIO_4, 0x0a81f442 },
  326. { XFER_PIO_3, 0x0a81f443 },
  327. { XFER_PIO_2, 0x0a81f454 },
  328. { XFER_PIO_1, 0x0ac1f465 },
  329. { XFER_PIO_0, 0x0ac1f48a },
  330. { 0, 0x0a81f443 }
  331. };
  332. static struct chipset_bus_clock_list_entry sixty_six_base_hpt372[] = {
  333. { XFER_UDMA_6, 0x1c869c62 },
  334. { XFER_UDMA_5, 0x1cae9c62 },
  335. { XFER_UDMA_4, 0x1c8a9c62 },
  336. { XFER_UDMA_3, 0x1c8e9c62 },
  337. { XFER_UDMA_2, 0x1c929c62 },
  338. { XFER_UDMA_1, 0x1c9a9c62 },
  339. { XFER_UDMA_0, 0x1c829c62 },
  340. { XFER_MW_DMA_2, 0x2c829c62 },
  341. { XFER_MW_DMA_1, 0x2c829c66 },
  342. { XFER_MW_DMA_0, 0x2c829d2e },
  343. { XFER_PIO_4, 0x0c829c62 },
  344. { XFER_PIO_3, 0x0c829c84 },
  345. { XFER_PIO_2, 0x0c829ca6 },
  346. { XFER_PIO_1, 0x0d029d26 },
  347. { XFER_PIO_0, 0x0d029d5e },
  348. { 0, 0x0d029d26 }
  349. };
  350. static struct chipset_bus_clock_list_entry thirty_three_base_hpt374[] = {
  351. { XFER_UDMA_6, 0x12808242 },
  352. { XFER_UDMA_5, 0x12848242 },
  353. { XFER_UDMA_4, 0x12ac8242 },
  354. { XFER_UDMA_3, 0x128c8242 },
  355. { XFER_UDMA_2, 0x120c8242 },
  356. { XFER_UDMA_1, 0x12148254 },
  357. { XFER_UDMA_0, 0x121882ea },
  358. { XFER_MW_DMA_2, 0x22808242 },
  359. { XFER_MW_DMA_1, 0x22808254 },
  360. { XFER_MW_DMA_0, 0x228082ea },
  361. { XFER_PIO_4, 0x0a81f442 },
  362. { XFER_PIO_3, 0x0a81f443 },
  363. { XFER_PIO_2, 0x0a81f454 },
  364. { XFER_PIO_1, 0x0ac1f465 },
  365. { XFER_PIO_0, 0x0ac1f48a },
  366. { 0, 0x06814e93 }
  367. };
  368. /* FIXME: 50MHz timings for HPT374 */
  369. #if 0
  370. static struct chipset_bus_clock_list_entry sixty_six_base_hpt374[] = {
  371. { XFER_UDMA_6, 0x12406231 }, /* checkme */
  372. { XFER_UDMA_5, 0x12446231 }, /* 0x14846231 */
  373. { XFER_UDMA_4, 0x16814ea7 }, /* 0x14886231 */
  374. { XFER_UDMA_3, 0x16814ea7 }, /* 0x148c6231 */
  375. { XFER_UDMA_2, 0x16814ea7 }, /* 0x148c6231 */
  376. { XFER_UDMA_1, 0x16814ea7 }, /* 0x14906231 */
  377. { XFER_UDMA_0, 0x16814ea7 }, /* 0x14986231 */
  378. { XFER_MW_DMA_2, 0x16814ea7 }, /* 0x26514e21 */
  379. { XFER_MW_DMA_1, 0x16814ea7 }, /* 0x26514e97 */
  380. { XFER_MW_DMA_0, 0x16814ea7 }, /* 0x26514e97 */
  381. { XFER_PIO_4, 0x06814ea7 }, /* 0x06514e21 */
  382. { XFER_PIO_3, 0x06814ea7 }, /* 0x06514e22 */
  383. { XFER_PIO_2, 0x06814ea7 }, /* 0x06514e33 */
  384. { XFER_PIO_1, 0x06814ea7 }, /* 0x06914e43 */
  385. { XFER_PIO_0, 0x06814ea7 }, /* 0x06914e57 */
  386. { 0, 0x06814ea7 }
  387. };
  388. #endif
  389. #define HPT366_DEBUG_DRIVE_INFO 0
  390. #define HPT374_ALLOW_ATA133_6 0
  391. #define HPT371_ALLOW_ATA133_6 0
  392. #define HPT302_ALLOW_ATA133_6 0
  393. #define HPT372_ALLOW_ATA133_6 1
  394. #define HPT370_ALLOW_ATA100_5 1
  395. #define HPT366_ALLOW_ATA66_4 1
  396. #define HPT366_ALLOW_ATA66_3 1
  397. #define HPT366_MAX_DEVS 8
  398. #define F_LOW_PCI_33 0x23
  399. #define F_LOW_PCI_40 0x29
  400. #define F_LOW_PCI_50 0x2d
  401. #define F_LOW_PCI_66 0x42
  402. /*
  403. * Hold all the highpoint quirks and revision information in one
  404. * place.
  405. */
  406. struct hpt_info
  407. {
  408. u8 max_mode; /* Speeds allowed */
  409. int revision; /* Chipset revision */
  410. int flags; /* Chipset properties */
  411. #define PLL_MODE 1
  412. #define IS_372N 2
  413. /* Speed table */
  414. struct chipset_bus_clock_list_entry *speed;
  415. };
  416. /*
  417. * This wants fixing so that we do everything not by classrev
  418. * (which breaks on the newest chips) but by creating an
  419. * enumeration of chip variants and using that
  420. */
  421. static __devinit u32 hpt_revision (struct pci_dev *dev)
  422. {
  423. u32 class_rev;
  424. pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
  425. class_rev &= 0xff;
  426. switch(dev->device) {
  427. /* Remap new 372N onto 372 */
  428. case PCI_DEVICE_ID_TTI_HPT372N:
  429. class_rev = PCI_DEVICE_ID_TTI_HPT372; break;
  430. case PCI_DEVICE_ID_TTI_HPT374:
  431. class_rev = PCI_DEVICE_ID_TTI_HPT374; break;
  432. case PCI_DEVICE_ID_TTI_HPT371:
  433. class_rev = PCI_DEVICE_ID_TTI_HPT371; break;
  434. case PCI_DEVICE_ID_TTI_HPT302:
  435. class_rev = PCI_DEVICE_ID_TTI_HPT302; break;
  436. case PCI_DEVICE_ID_TTI_HPT372:
  437. class_rev = PCI_DEVICE_ID_TTI_HPT372; break;
  438. default:
  439. break;
  440. }
  441. return class_rev;
  442. }
  443. static int check_in_drive_lists(ide_drive_t *drive, const char **list);
  444. static u8 hpt3xx_ratemask (ide_drive_t *drive)
  445. {
  446. ide_hwif_t *hwif = drive->hwif;
  447. struct hpt_info *info = ide_get_hwifdata(hwif);
  448. u8 mode = 0;
  449. /* FIXME: TODO - move this to set info->mode once at boot */
  450. if (info->revision >= 8) { /* HPT374 */
  451. mode = (HPT374_ALLOW_ATA133_6) ? 4 : 3;
  452. } else if (info->revision >= 7) { /* HPT371 */
  453. mode = (HPT371_ALLOW_ATA133_6) ? 4 : 3;
  454. } else if (info->revision >= 6) { /* HPT302 */
  455. mode = (HPT302_ALLOW_ATA133_6) ? 4 : 3;
  456. } else if (info->revision >= 5) { /* HPT372 */
  457. mode = (HPT372_ALLOW_ATA133_6) ? 4 : 3;
  458. } else if (info->revision >= 4) { /* HPT370A */
  459. mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2;
  460. } else if (info->revision >= 3) { /* HPT370 */
  461. mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2;
  462. mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : mode;
  463. } else { /* HPT366 and HPT368 */
  464. mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : 2;
  465. }
  466. if (!eighty_ninty_three(drive) && mode)
  467. mode = min(mode, (u8)1);
  468. return mode;
  469. }
  470. /*
  471. * Note for the future; the SATA hpt37x we must set
  472. * either PIO or UDMA modes 0,4,5
  473. */
  474. static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed)
  475. {
  476. ide_hwif_t *hwif = drive->hwif;
  477. struct hpt_info *info = ide_get_hwifdata(hwif);
  478. u8 mode = hpt3xx_ratemask(drive);
  479. if (drive->media != ide_disk)
  480. return min(speed, (u8)XFER_PIO_4);
  481. switch(mode) {
  482. case 0x04:
  483. speed = min(speed, (u8)XFER_UDMA_6);
  484. break;
  485. case 0x03:
  486. speed = min(speed, (u8)XFER_UDMA_5);
  487. if (info->revision >= 5)
  488. break;
  489. if (check_in_drive_lists(drive, bad_ata100_5))
  490. speed = min(speed, (u8)XFER_UDMA_4);
  491. break;
  492. case 0x02:
  493. speed = min(speed, (u8)XFER_UDMA_4);
  494. /*
  495. * CHECK ME, Does this need to be set to 5 ??
  496. */
  497. if (info->revision >= 3)
  498. break;
  499. if ((check_in_drive_lists(drive, bad_ata66_4)) ||
  500. (!(HPT366_ALLOW_ATA66_4)))
  501. speed = min(speed, (u8)XFER_UDMA_3);
  502. if ((check_in_drive_lists(drive, bad_ata66_3)) ||
  503. (!(HPT366_ALLOW_ATA66_3)))
  504. speed = min(speed, (u8)XFER_UDMA_2);
  505. break;
  506. case 0x01:
  507. speed = min(speed, (u8)XFER_UDMA_2);
  508. /*
  509. * CHECK ME, Does this need to be set to 5 ??
  510. */
  511. if (info->revision >= 3)
  512. break;
  513. if (check_in_drive_lists(drive, bad_ata33))
  514. speed = min(speed, (u8)XFER_MW_DMA_2);
  515. break;
  516. case 0x00:
  517. default:
  518. speed = min(speed, (u8)XFER_MW_DMA_2);
  519. break;
  520. }
  521. return speed;
  522. }
  523. static int check_in_drive_lists (ide_drive_t *drive, const char **list)
  524. {
  525. struct hd_driveid *id = drive->id;
  526. if (quirk_drives == list) {
  527. while (*list)
  528. if (strstr(id->model, *list++))
  529. return 1;
  530. } else {
  531. while (*list)
  532. if (!strcmp(*list++,id->model))
  533. return 1;
  534. }
  535. return 0;
  536. }
  537. static unsigned int pci_bus_clock_list (u8 speed, struct chipset_bus_clock_list_entry * chipset_table)
  538. {
  539. for ( ; chipset_table->xfer_speed ; chipset_table++)
  540. if (chipset_table->xfer_speed == speed)
  541. return chipset_table->chipset_settings;
  542. return chipset_table->chipset_settings;
  543. }
  544. static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
  545. {
  546. ide_hwif_t *hwif = drive->hwif;
  547. struct pci_dev *dev = hwif->pci_dev;
  548. struct hpt_info *info = ide_get_hwifdata(hwif);
  549. u8 speed = hpt3xx_ratefilter(drive, xferspeed);
  550. u8 regtime = (drive->select.b.unit & 0x01) ? 0x44 : 0x40;
  551. u8 regfast = (hwif->channel) ? 0x55 : 0x51;
  552. u8 drive_fast = 0;
  553. u32 reg1 = 0, reg2 = 0;
  554. /*
  555. * Disable the "fast interrupt" prediction.
  556. */
  557. pci_read_config_byte(dev, regfast, &drive_fast);
  558. if (drive_fast & 0x80)
  559. pci_write_config_byte(dev, regfast, drive_fast & ~0x80);
  560. reg2 = pci_bus_clock_list(speed, info->speed);
  561. /*
  562. * Disable on-chip PIO FIFO/buffer
  563. * (to avoid problems handling I/O errors later)
  564. */
  565. pci_read_config_dword(dev, regtime, &reg1);
  566. if (speed >= XFER_MW_DMA_0) {
  567. reg2 = (reg2 & ~0xc0000000) | (reg1 & 0xc0000000);
  568. } else {
  569. reg2 = (reg2 & ~0x30070000) | (reg1 & 0x30070000);
  570. }
  571. reg2 &= ~0x80000000;
  572. pci_write_config_dword(dev, regtime, reg2);
  573. return ide_config_drive_speed(drive, speed);
  574. }
  575. static int hpt370_tune_chipset(ide_drive_t *drive, u8 xferspeed)
  576. {
  577. ide_hwif_t *hwif = drive->hwif;
  578. struct pci_dev *dev = hwif->pci_dev;
  579. struct hpt_info *info = ide_get_hwifdata(hwif);
  580. u8 speed = hpt3xx_ratefilter(drive, xferspeed);
  581. u8 regfast = (drive->hwif->channel) ? 0x55 : 0x51;
  582. u8 drive_pci = 0x40 + (drive->dn * 4);
  583. u8 new_fast = 0, drive_fast = 0;
  584. u32 list_conf = 0, drive_conf = 0;
  585. u32 conf_mask = (speed >= XFER_MW_DMA_0) ? 0xc0000000 : 0x30070000;
  586. /*
  587. * Disable the "fast interrupt" prediction.
  588. * don't holdoff on interrupts. (== 0x01 despite what the docs say)
  589. */
  590. pci_read_config_byte(dev, regfast, &drive_fast);
  591. new_fast = drive_fast;
  592. if (new_fast & 0x02)
  593. new_fast &= ~0x02;
  594. #ifdef HPT_DELAY_INTERRUPT
  595. if (new_fast & 0x01)
  596. new_fast &= ~0x01;
  597. #else
  598. if ((new_fast & 0x01) == 0)
  599. new_fast |= 0x01;
  600. #endif
  601. if (new_fast != drive_fast)
  602. pci_write_config_byte(dev, regfast, new_fast);
  603. list_conf = pci_bus_clock_list(speed, info->speed);
  604. pci_read_config_dword(dev, drive_pci, &drive_conf);
  605. list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask);
  606. if (speed < XFER_MW_DMA_0)
  607. list_conf &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */
  608. pci_write_config_dword(dev, drive_pci, list_conf);
  609. return ide_config_drive_speed(drive, speed);
  610. }
  611. static int hpt372_tune_chipset(ide_drive_t *drive, u8 xferspeed)
  612. {
  613. ide_hwif_t *hwif = drive->hwif;
  614. struct pci_dev *dev = hwif->pci_dev;
  615. struct hpt_info *info = ide_get_hwifdata(hwif);
  616. u8 speed = hpt3xx_ratefilter(drive, xferspeed);
  617. u8 regfast = (drive->hwif->channel) ? 0x55 : 0x51;
  618. u8 drive_fast = 0, drive_pci = 0x40 + (drive->dn * 4);
  619. u32 list_conf = 0, drive_conf = 0;
  620. u32 conf_mask = (speed >= XFER_MW_DMA_0) ? 0xc0000000 : 0x30070000;
  621. /*
  622. * Disable the "fast interrupt" prediction.
  623. * don't holdoff on interrupts. (== 0x01 despite what the docs say)
  624. */
  625. pci_read_config_byte(dev, regfast, &drive_fast);
  626. drive_fast &= ~0x07;
  627. pci_write_config_byte(dev, regfast, drive_fast);
  628. list_conf = pci_bus_clock_list(speed, info->speed);
  629. pci_read_config_dword(dev, drive_pci, &drive_conf);
  630. list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask);
  631. if (speed < XFER_MW_DMA_0)
  632. list_conf &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */
  633. pci_write_config_dword(dev, drive_pci, list_conf);
  634. return ide_config_drive_speed(drive, speed);
  635. }
  636. static int hpt3xx_tune_chipset (ide_drive_t *drive, u8 speed)
  637. {
  638. ide_hwif_t *hwif = drive->hwif;
  639. struct hpt_info *info = ide_get_hwifdata(hwif);
  640. if (info->revision >= 8)
  641. return hpt372_tune_chipset(drive, speed); /* not a typo */
  642. else if (info->revision >= 5)
  643. return hpt372_tune_chipset(drive, speed);
  644. else if (info->revision >= 3)
  645. return hpt370_tune_chipset(drive, speed);
  646. else /* hpt368: hpt_minimum_revision(dev, 2) */
  647. return hpt36x_tune_chipset(drive, speed);
  648. }
  649. static void hpt3xx_tune_drive (ide_drive_t *drive, u8 pio)
  650. {
  651. pio = ide_get_best_pio_mode(drive, 255, pio, NULL);
  652. (void) hpt3xx_tune_chipset(drive, (XFER_PIO_0 + pio));
  653. }
  654. /*
  655. * This allows the configuration of ide_pci chipset registers
  656. * for cards that learn about the drive's UDMA, DMA, PIO capabilities
  657. * after the drive is reported by the OS. Initially for designed for
  658. * HPT366 UDMA chipset by HighPoint|Triones Technologies, Inc.
  659. *
  660. * check_in_drive_lists(drive, bad_ata66_4)
  661. * check_in_drive_lists(drive, bad_ata66_3)
  662. * check_in_drive_lists(drive, bad_ata33)
  663. *
  664. */
  665. static int config_chipset_for_dma (ide_drive_t *drive)
  666. {
  667. u8 speed = ide_dma_speed(drive, hpt3xx_ratemask(drive));
  668. ide_hwif_t *hwif = drive->hwif;
  669. struct hpt_info *info = ide_get_hwifdata(hwif);
  670. if (!speed)
  671. return 0;
  672. /* If we don't have any timings we can't do a lot */
  673. if (info->speed == NULL)
  674. return 0;
  675. (void) hpt3xx_tune_chipset(drive, speed);
  676. return ide_dma_enable(drive);
  677. }
  678. static int hpt3xx_quirkproc (ide_drive_t *drive)
  679. {
  680. return ((int) check_in_drive_lists(drive, quirk_drives));
  681. }
  682. static void hpt3xx_intrproc (ide_drive_t *drive)
  683. {
  684. ide_hwif_t *hwif = drive->hwif;
  685. if (drive->quirk_list)
  686. return;
  687. /* drives in the quirk_list may not like intr setups/cleanups */
  688. hwif->OUTB(drive->ctl|2, IDE_CONTROL_REG);
  689. }
  690. static void hpt3xx_maskproc (ide_drive_t *drive, int mask)
  691. {
  692. ide_hwif_t *hwif = drive->hwif;
  693. struct hpt_info *info = ide_get_hwifdata(hwif);
  694. struct pci_dev *dev = hwif->pci_dev;
  695. if (drive->quirk_list) {
  696. if (info->revision >= 3) {
  697. u8 reg5a = 0;
  698. pci_read_config_byte(dev, 0x5a, &reg5a);
  699. if (((reg5a & 0x10) >> 4) != mask)
  700. pci_write_config_byte(dev, 0x5a, mask ? (reg5a | 0x10) : (reg5a & ~0x10));
  701. } else {
  702. if (mask) {
  703. disable_irq(hwif->irq);
  704. } else {
  705. enable_irq(hwif->irq);
  706. }
  707. }
  708. } else {
  709. if (IDE_CONTROL_REG)
  710. hwif->OUTB(mask ? (drive->ctl | 2) :
  711. (drive->ctl & ~2),
  712. IDE_CONTROL_REG);
  713. }
  714. }
  715. static int hpt366_config_drive_xfer_rate (ide_drive_t *drive)
  716. {
  717. ide_hwif_t *hwif = drive->hwif;
  718. struct hd_driveid *id = drive->id;
  719. drive->init_speed = 0;
  720. if ((id->capability & 1) && drive->autodma) {
  721. if (ide_use_dma(drive)) {
  722. if (config_chipset_for_dma(drive))
  723. return hwif->ide_dma_on(drive);
  724. }
  725. goto fast_ata_pio;
  726. } else if ((id->capability & 8) || (id->field_valid & 2)) {
  727. fast_ata_pio:
  728. hpt3xx_tune_drive(drive, 5);
  729. return hwif->ide_dma_off_quietly(drive);
  730. }
  731. /* IORDY not supported */
  732. return 0;
  733. }
  734. /*
  735. * This is specific to the HPT366 UDMA bios chipset
  736. * by HighPoint|Triones Technologies, Inc.
  737. */
  738. static int hpt366_ide_dma_lostirq (ide_drive_t *drive)
  739. {
  740. struct pci_dev *dev = HWIF(drive)->pci_dev;
  741. u8 reg50h = 0, reg52h = 0, reg5ah = 0;
  742. pci_read_config_byte(dev, 0x50, &reg50h);
  743. pci_read_config_byte(dev, 0x52, &reg52h);
  744. pci_read_config_byte(dev, 0x5a, &reg5ah);
  745. printk("%s: (%s) reg50h=0x%02x, reg52h=0x%02x, reg5ah=0x%02x\n",
  746. drive->name, __FUNCTION__, reg50h, reg52h, reg5ah);
  747. if (reg5ah & 0x10)
  748. pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10);
  749. return __ide_dma_lostirq(drive);
  750. }
  751. static void hpt370_clear_engine (ide_drive_t *drive)
  752. {
  753. u8 regstate = HWIF(drive)->channel ? 0x54 : 0x50;
  754. pci_write_config_byte(HWIF(drive)->pci_dev, regstate, 0x37);
  755. udelay(10);
  756. }
  757. static void hpt370_ide_dma_start(ide_drive_t *drive)
  758. {
  759. #ifdef HPT_RESET_STATE_ENGINE
  760. hpt370_clear_engine(drive);
  761. #endif
  762. ide_dma_start(drive);
  763. }
  764. static int hpt370_ide_dma_end (ide_drive_t *drive)
  765. {
  766. ide_hwif_t *hwif = HWIF(drive);
  767. u8 dma_stat = hwif->INB(hwif->dma_status);
  768. if (dma_stat & 0x01) {
  769. /* wait a little */
  770. udelay(20);
  771. dma_stat = hwif->INB(hwif->dma_status);
  772. }
  773. if ((dma_stat & 0x01) != 0)
  774. /* fallthrough */
  775. (void) HWIF(drive)->ide_dma_timeout(drive);
  776. return __ide_dma_end(drive);
  777. }
  778. static void hpt370_lostirq_timeout (ide_drive_t *drive)
  779. {
  780. ide_hwif_t *hwif = HWIF(drive);
  781. u8 bfifo = 0, reginfo = hwif->channel ? 0x56 : 0x52;
  782. u8 dma_stat = 0, dma_cmd = 0;
  783. pci_read_config_byte(HWIF(drive)->pci_dev, reginfo, &bfifo);
  784. printk(KERN_DEBUG "%s: %d bytes in FIFO\n", drive->name, bfifo);
  785. hpt370_clear_engine(drive);
  786. /* get dma command mode */
  787. dma_cmd = hwif->INB(hwif->dma_command);
  788. /* stop dma */
  789. hwif->OUTB(dma_cmd & ~0x1, hwif->dma_command);
  790. dma_stat = hwif->INB(hwif->dma_status);
  791. /* clear errors */
  792. hwif->OUTB(dma_stat | 0x6, hwif->dma_status);
  793. }
  794. static int hpt370_ide_dma_timeout (ide_drive_t *drive)
  795. {
  796. hpt370_lostirq_timeout(drive);
  797. hpt370_clear_engine(drive);
  798. return __ide_dma_timeout(drive);
  799. }
  800. static int hpt370_ide_dma_lostirq (ide_drive_t *drive)
  801. {
  802. hpt370_lostirq_timeout(drive);
  803. hpt370_clear_engine(drive);
  804. return __ide_dma_lostirq(drive);
  805. }
  806. /* returns 1 if DMA IRQ issued, 0 otherwise */
  807. static int hpt374_ide_dma_test_irq(ide_drive_t *drive)
  808. {
  809. ide_hwif_t *hwif = HWIF(drive);
  810. u16 bfifo = 0;
  811. u8 reginfo = hwif->channel ? 0x56 : 0x52;
  812. u8 dma_stat;
  813. pci_read_config_word(hwif->pci_dev, reginfo, &bfifo);
  814. if (bfifo & 0x1FF) {
  815. // printk("%s: %d bytes in FIFO\n", drive->name, bfifo);
  816. return 0;
  817. }
  818. dma_stat = hwif->INB(hwif->dma_status);
  819. /* return 1 if INTR asserted */
  820. if ((dma_stat & 4) == 4)
  821. return 1;
  822. if (!drive->waiting_for_dma)
  823. printk(KERN_WARNING "%s: (%s) called while not waiting\n",
  824. drive->name, __FUNCTION__);
  825. return 0;
  826. }
  827. static int hpt374_ide_dma_end (ide_drive_t *drive)
  828. {
  829. struct pci_dev *dev = HWIF(drive)->pci_dev;
  830. ide_hwif_t *hwif = HWIF(drive);
  831. u8 msc_stat = 0, mscreg = hwif->channel ? 0x54 : 0x50;
  832. u8 bwsr_stat = 0, bwsr_mask = hwif->channel ? 0x02 : 0x01;
  833. pci_read_config_byte(dev, 0x6a, &bwsr_stat);
  834. pci_read_config_byte(dev, mscreg, &msc_stat);
  835. if ((bwsr_stat & bwsr_mask) == bwsr_mask)
  836. pci_write_config_byte(dev, mscreg, msc_stat|0x30);
  837. return __ide_dma_end(drive);
  838. }
  839. /**
  840. * hpt372n_set_clock - perform clock switching dance
  841. * @drive: Drive to switch
  842. * @mode: Switching mode (0x21 for write, 0x23 otherwise)
  843. *
  844. * Switch the DPLL clock on the HPT372N devices. This is a
  845. * right mess.
  846. */
  847. static void hpt372n_set_clock(ide_drive_t *drive, int mode)
  848. {
  849. ide_hwif_t *hwif = HWIF(drive);
  850. /* FIXME: should we check for DMA active and BUG() */
  851. /* Tristate the bus */
  852. outb(0x80, hwif->dma_base+0x73);
  853. outb(0x80, hwif->dma_base+0x77);
  854. /* Switch clock and reset channels */
  855. outb(mode, hwif->dma_base+0x7B);
  856. outb(0xC0, hwif->dma_base+0x79);
  857. /* Reset state machines */
  858. outb(0x37, hwif->dma_base+0x70);
  859. outb(0x37, hwif->dma_base+0x74);
  860. /* Complete reset */
  861. outb(0x00, hwif->dma_base+0x79);
  862. /* Reconnect channels to bus */
  863. outb(0x00, hwif->dma_base+0x73);
  864. outb(0x00, hwif->dma_base+0x77);
  865. }
  866. /**
  867. * hpt372n_rw_disk - prepare for I/O
  868. * @drive: drive for command
  869. * @rq: block request structure
  870. *
  871. * This is called when a disk I/O is issued to the 372N.
  872. * We need it because of the clock switching.
  873. */
  874. static void hpt372n_rw_disk(ide_drive_t *drive, struct request *rq)
  875. {
  876. ide_hwif_t *hwif = drive->hwif;
  877. int wantclock;
  878. wantclock = rq_data_dir(rq) ? 0x23 : 0x21;
  879. if (hwif->config_data != wantclock) {
  880. hpt372n_set_clock(drive, wantclock);
  881. hwif->config_data = wantclock;
  882. }
  883. }
  884. /*
  885. * Since SUN Cobalt is attempting to do this operation, I should disclose
  886. * this has been a long time ago Thu Jul 27 16:40:57 2000 was the patch date
  887. * HOTSWAP ATA Infrastructure.
  888. */
  889. static void hpt3xx_reset (ide_drive_t *drive)
  890. {
  891. }
  892. static int hpt3xx_tristate (ide_drive_t * drive, int state)
  893. {
  894. ide_hwif_t *hwif = HWIF(drive);
  895. struct pci_dev *dev = hwif->pci_dev;
  896. u8 reg59h = 0, reset = (hwif->channel) ? 0x80 : 0x40;
  897. u8 regXXh = 0, state_reg= (hwif->channel) ? 0x57 : 0x53;
  898. pci_read_config_byte(dev, 0x59, &reg59h);
  899. pci_read_config_byte(dev, state_reg, &regXXh);
  900. if (state) {
  901. (void) ide_do_reset(drive);
  902. pci_write_config_byte(dev, state_reg, regXXh|0x80);
  903. pci_write_config_byte(dev, 0x59, reg59h|reset);
  904. } else {
  905. pci_write_config_byte(dev, 0x59, reg59h & ~(reset));
  906. pci_write_config_byte(dev, state_reg, regXXh & ~(0x80));
  907. (void) ide_do_reset(drive);
  908. }
  909. return 0;
  910. }
  911. /*
  912. * set/get power state for a drive.
  913. * turning the power off does the following things:
  914. * 1) soft-reset the drive
  915. * 2) tri-states the ide bus
  916. *
  917. * when we turn things back on, we need to re-initialize things.
  918. */
  919. #define TRISTATE_BIT 0x8000
  920. static int hpt370_busproc(ide_drive_t * drive, int state)
  921. {
  922. ide_hwif_t *hwif = drive->hwif;
  923. struct pci_dev *dev = hwif->pci_dev;
  924. u8 tristate = 0, resetmask = 0, bus_reg = 0;
  925. u16 tri_reg;
  926. hwif->bus_state = state;
  927. if (hwif->channel) {
  928. /* secondary channel */
  929. tristate = 0x56;
  930. resetmask = 0x80;
  931. } else {
  932. /* primary channel */
  933. tristate = 0x52;
  934. resetmask = 0x40;
  935. }
  936. /* grab status */
  937. pci_read_config_word(dev, tristate, &tri_reg);
  938. pci_read_config_byte(dev, 0x59, &bus_reg);
  939. /* set the state. we don't set it if we don't need to do so.
  940. * make sure that the drive knows that it has failed if it's off */
  941. switch (state) {
  942. case BUSSTATE_ON:
  943. hwif->drives[0].failures = 0;
  944. hwif->drives[1].failures = 0;
  945. if ((bus_reg & resetmask) == 0)
  946. return 0;
  947. tri_reg &= ~TRISTATE_BIT;
  948. bus_reg &= ~resetmask;
  949. break;
  950. case BUSSTATE_OFF:
  951. hwif->drives[0].failures = hwif->drives[0].max_failures + 1;
  952. hwif->drives[1].failures = hwif->drives[1].max_failures + 1;
  953. if ((tri_reg & TRISTATE_BIT) == 0 && (bus_reg & resetmask))
  954. return 0;
  955. tri_reg &= ~TRISTATE_BIT;
  956. bus_reg |= resetmask;
  957. break;
  958. case BUSSTATE_TRISTATE:
  959. hwif->drives[0].failures = hwif->drives[0].max_failures + 1;
  960. hwif->drives[1].failures = hwif->drives[1].max_failures + 1;
  961. if ((tri_reg & TRISTATE_BIT) && (bus_reg & resetmask))
  962. return 0;
  963. tri_reg |= TRISTATE_BIT;
  964. bus_reg |= resetmask;
  965. break;
  966. }
  967. pci_write_config_byte(dev, 0x59, bus_reg);
  968. pci_write_config_word(dev, tristate, tri_reg);
  969. return 0;
  970. }
  971. static void __devinit hpt366_clocking(ide_hwif_t *hwif)
  972. {
  973. u32 reg1 = 0;
  974. struct hpt_info *info = ide_get_hwifdata(hwif);
  975. pci_read_config_dword(hwif->pci_dev, 0x40, &reg1);
  976. /* detect bus speed by looking at control reg timing: */
  977. switch((reg1 >> 8) & 7) {
  978. case 5:
  979. info->speed = forty_base_hpt366;
  980. break;
  981. case 9:
  982. info->speed = twenty_five_base_hpt366;
  983. break;
  984. case 7:
  985. default:
  986. info->speed = thirty_three_base_hpt366;
  987. break;
  988. }
  989. }
  990. static void __devinit hpt37x_clocking(ide_hwif_t *hwif)
  991. {
  992. struct hpt_info *info = ide_get_hwifdata(hwif);
  993. struct pci_dev *dev = hwif->pci_dev;
  994. int adjust, i;
  995. u16 freq;
  996. u32 pll;
  997. u8 reg5bh;
  998. /*
  999. * default to pci clock. make sure MA15/16 are set to output
  1000. * to prevent drives having problems with 40-pin cables. Needed
  1001. * for some drives such as IBM-DTLA which will not enter ready
  1002. * state on reset when PDIAG is a input.
  1003. *
  1004. * ToDo: should we set 0x21 when using PLL mode ?
  1005. */
  1006. pci_write_config_byte(dev, 0x5b, 0x23);
  1007. /*
  1008. * set up the PLL. we need to adjust it so that it's stable.
  1009. * freq = Tpll * 192 / Tpci
  1010. *
  1011. * Todo. For non x86 should probably check the dword is
  1012. * set to 0xABCDExxx indicating the BIOS saved f_CNT
  1013. */
  1014. pci_read_config_word(dev, 0x78, &freq);
  1015. freq &= 0x1FF;
  1016. /*
  1017. * The 372N uses different PCI clock information and has
  1018. * some other complications
  1019. * On PCI33 timing we must clock switch
  1020. * On PCI66 timing we must NOT use the PCI clock
  1021. *
  1022. * Currently we always set up the PLL for the 372N
  1023. */
  1024. if(info->flags & IS_372N)
  1025. {
  1026. printk(KERN_INFO "hpt: HPT372N detected, using 372N timing.\n");
  1027. if(freq < 0x55)
  1028. pll = F_LOW_PCI_33;
  1029. else if(freq < 0x70)
  1030. pll = F_LOW_PCI_40;
  1031. else if(freq < 0x7F)
  1032. pll = F_LOW_PCI_50;
  1033. else
  1034. pll = F_LOW_PCI_66;
  1035. printk(KERN_INFO "FREQ: %d PLL: %d\n", freq, pll);
  1036. /* We always use the pll not the PCI clock on 372N */
  1037. }
  1038. else
  1039. {
  1040. if(freq < 0x9C)
  1041. pll = F_LOW_PCI_33;
  1042. else if(freq < 0xb0)
  1043. pll = F_LOW_PCI_40;
  1044. else if(freq <0xc8)
  1045. pll = F_LOW_PCI_50;
  1046. else
  1047. pll = F_LOW_PCI_66;
  1048. if (pll == F_LOW_PCI_33) {
  1049. if (info->revision >= 8)
  1050. info->speed = thirty_three_base_hpt374;
  1051. else if (info->revision >= 5)
  1052. info->speed = thirty_three_base_hpt372;
  1053. else if (info->revision >= 4)
  1054. info->speed = thirty_three_base_hpt370a;
  1055. else
  1056. info->speed = thirty_three_base_hpt370;
  1057. printk(KERN_DEBUG "HPT37X: using 33MHz PCI clock\n");
  1058. } else if (pll == F_LOW_PCI_40) {
  1059. /* Unsupported */
  1060. } else if (pll == F_LOW_PCI_50) {
  1061. if (info->revision >= 8)
  1062. info->speed = fifty_base_hpt370a;
  1063. else if (info->revision >= 5)
  1064. info->speed = fifty_base_hpt372;
  1065. else if (info->revision >= 4)
  1066. info->speed = fifty_base_hpt370a;
  1067. else
  1068. info->speed = fifty_base_hpt370a;
  1069. printk(KERN_DEBUG "HPT37X: using 50MHz PCI clock\n");
  1070. } else {
  1071. if (info->revision >= 8) {
  1072. printk(KERN_ERR "HPT37x: 66MHz timings are not supported.\n");
  1073. }
  1074. else if (info->revision >= 5)
  1075. info->speed = sixty_six_base_hpt372;
  1076. else if (info->revision >= 4)
  1077. info->speed = sixty_six_base_hpt370a;
  1078. else
  1079. info->speed = sixty_six_base_hpt370;
  1080. printk(KERN_DEBUG "HPT37X: using 66MHz PCI clock\n");
  1081. }
  1082. }
  1083. /*
  1084. * only try the pll if we don't have a table for the clock
  1085. * speed that we're running at. NOTE: the internal PLL will
  1086. * result in slow reads when using a 33MHz PCI clock. we also
  1087. * don't like to use the PLL because it will cause glitches
  1088. * on PRST/SRST when the HPT state engine gets reset.
  1089. *
  1090. * ToDo: Use 66MHz PLL when ATA133 devices are present on a
  1091. * 372 device so we can get ATA133 support
  1092. */
  1093. if (info->speed)
  1094. goto init_hpt37X_done;
  1095. info->flags |= PLL_MODE;
  1096. /*
  1097. * FIXME: make this work correctly, esp with 372N as per
  1098. * reference driver code.
  1099. *
  1100. * adjust PLL based upon PCI clock, enable it, and wait for
  1101. * stabilization.
  1102. */
  1103. adjust = 0;
  1104. freq = (pll < F_LOW_PCI_50) ? 2 : 4;
  1105. while (adjust++ < 6) {
  1106. pci_write_config_dword(dev, 0x5c, (freq + pll) << 16 |
  1107. pll | 0x100);
  1108. /* wait for clock stabilization */
  1109. for (i = 0; i < 0x50000; i++) {
  1110. pci_read_config_byte(dev, 0x5b, &reg5bh);
  1111. if (reg5bh & 0x80) {
  1112. /* spin looking for the clock to destabilize */
  1113. for (i = 0; i < 0x1000; ++i) {
  1114. pci_read_config_byte(dev, 0x5b,
  1115. &reg5bh);
  1116. if ((reg5bh & 0x80) == 0)
  1117. goto pll_recal;
  1118. }
  1119. pci_read_config_dword(dev, 0x5c, &pll);
  1120. pci_write_config_dword(dev, 0x5c,
  1121. pll & ~0x100);
  1122. pci_write_config_byte(dev, 0x5b, 0x21);
  1123. if (info->revision >= 8)
  1124. info->speed = fifty_base_hpt370a;
  1125. else if (info->revision >= 5)
  1126. info->speed = fifty_base_hpt372;
  1127. else if (info->revision >= 4)
  1128. info->speed = fifty_base_hpt370a;
  1129. else
  1130. info->speed = fifty_base_hpt370a;
  1131. printk("HPT37X: using 50MHz internal PLL\n");
  1132. goto init_hpt37X_done;
  1133. }
  1134. }
  1135. pll_recal:
  1136. if (adjust & 1)
  1137. pll -= (adjust >> 1);
  1138. else
  1139. pll += (adjust >> 1);
  1140. }
  1141. init_hpt37X_done:
  1142. if (!info->speed)
  1143. printk(KERN_ERR "HPT37X%s: unknown bus timing [%d %d].\n",
  1144. (info->flags & IS_372N)?"N":"", pll, freq);
  1145. /* reset state engine */
  1146. pci_write_config_byte(dev, 0x50, 0x37);
  1147. pci_write_config_byte(dev, 0x54, 0x37);
  1148. udelay(100);
  1149. }
  1150. static int __devinit init_hpt37x(struct pci_dev *dev)
  1151. {
  1152. u8 reg5ah;
  1153. pci_read_config_byte(dev, 0x5a, &reg5ah);
  1154. /* interrupt force enable */
  1155. pci_write_config_byte(dev, 0x5a, (reg5ah & ~0x10));
  1156. return 0;
  1157. }
  1158. static int __devinit init_hpt366(struct pci_dev *dev)
  1159. {
  1160. u32 reg1 = 0;
  1161. u8 drive_fast = 0;
  1162. /*
  1163. * Disable the "fast interrupt" prediction.
  1164. */
  1165. pci_read_config_byte(dev, 0x51, &drive_fast);
  1166. if (drive_fast & 0x80)
  1167. pci_write_config_byte(dev, 0x51, drive_fast & ~0x80);
  1168. pci_read_config_dword(dev, 0x40, &reg1);
  1169. return 0;
  1170. }
  1171. static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name)
  1172. {
  1173. int ret = 0;
  1174. /*
  1175. * FIXME: Not portable. Also, why do we enable the ROM in the first place?
  1176. * We don't seem to be using it.
  1177. */
  1178. if (dev->resource[PCI_ROM_RESOURCE].start)
  1179. pci_write_config_dword(dev, PCI_ROM_ADDRESS,
  1180. dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
  1181. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
  1182. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
  1183. pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  1184. pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
  1185. if (hpt_revision(dev) >= 3)
  1186. ret = init_hpt37x(dev);
  1187. else
  1188. ret = init_hpt366(dev);
  1189. if (ret)
  1190. return ret;
  1191. return dev->irq;
  1192. }
  1193. static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
  1194. {
  1195. struct pci_dev *dev = hwif->pci_dev;
  1196. struct hpt_info *info = ide_get_hwifdata(hwif);
  1197. u8 ata66 = 0, regmask = (hwif->channel) ? 0x01 : 0x02;
  1198. hwif->tuneproc = &hpt3xx_tune_drive;
  1199. hwif->speedproc = &hpt3xx_tune_chipset;
  1200. hwif->quirkproc = &hpt3xx_quirkproc;
  1201. hwif->intrproc = &hpt3xx_intrproc;
  1202. hwif->maskproc = &hpt3xx_maskproc;
  1203. if(info->flags & IS_372N)
  1204. hwif->rw_disk = &hpt372n_rw_disk;
  1205. /*
  1206. * The HPT37x uses the CBLID pins as outputs for MA15/MA16
  1207. * address lines to access an external eeprom. To read valid
  1208. * cable detect state the pins must be enabled as inputs.
  1209. */
  1210. if (info->revision >= 8 && (PCI_FUNC(dev->devfn) & 1)) {
  1211. /*
  1212. * HPT374 PCI function 1
  1213. * - set bit 15 of reg 0x52 to enable TCBLID as input
  1214. * - set bit 15 of reg 0x56 to enable FCBLID as input
  1215. */
  1216. u16 mcr3, mcr6;
  1217. pci_read_config_word(dev, 0x52, &mcr3);
  1218. pci_read_config_word(dev, 0x56, &mcr6);
  1219. pci_write_config_word(dev, 0x52, mcr3 | 0x8000);
  1220. pci_write_config_word(dev, 0x56, mcr6 | 0x8000);
  1221. /* now read cable id register */
  1222. pci_read_config_byte(dev, 0x5a, &ata66);
  1223. pci_write_config_word(dev, 0x52, mcr3);
  1224. pci_write_config_word(dev, 0x56, mcr6);
  1225. } else if (info->revision >= 3) {
  1226. /*
  1227. * HPT370/372 and 374 pcifn 0
  1228. * - clear bit 0 of 0x5b to enable P/SCBLID as inputs
  1229. */
  1230. u8 scr2;
  1231. pci_read_config_byte(dev, 0x5b, &scr2);
  1232. pci_write_config_byte(dev, 0x5b, scr2 & ~1);
  1233. /* now read cable id register */
  1234. pci_read_config_byte(dev, 0x5a, &ata66);
  1235. pci_write_config_byte(dev, 0x5b, scr2);
  1236. } else {
  1237. pci_read_config_byte(dev, 0x5a, &ata66);
  1238. }
  1239. #ifdef DEBUG
  1240. printk("HPT366: reg5ah=0x%02x ATA-%s Cable Port%d\n",
  1241. ata66, (ata66 & regmask) ? "33" : "66",
  1242. PCI_FUNC(hwif->pci_dev->devfn));
  1243. #endif /* DEBUG */
  1244. #ifdef HPT_SERIALIZE_IO
  1245. /* serialize access to this device */
  1246. if (hwif->mate)
  1247. hwif->serialized = hwif->mate->serialized = 1;
  1248. #endif
  1249. if (info->revision >= 3) {
  1250. u8 reg5ah = 0;
  1251. pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10);
  1252. /*
  1253. * set up ioctl for power status.
  1254. * note: power affects both
  1255. * drives on each channel
  1256. */
  1257. hwif->resetproc = &hpt3xx_reset;
  1258. hwif->busproc = &hpt370_busproc;
  1259. } else if (info->revision >= 2) {
  1260. hwif->resetproc = &hpt3xx_reset;
  1261. hwif->busproc = &hpt3xx_tristate;
  1262. } else {
  1263. hwif->resetproc = &hpt3xx_reset;
  1264. hwif->busproc = &hpt3xx_tristate;
  1265. }
  1266. if (!hwif->dma_base) {
  1267. hwif->drives[0].autotune = 1;
  1268. hwif->drives[1].autotune = 1;
  1269. return;
  1270. }
  1271. hwif->ultra_mask = 0x7f;
  1272. hwif->mwdma_mask = 0x07;
  1273. if (!(hwif->udma_four))
  1274. hwif->udma_four = ((ata66 & regmask) ? 0 : 1);
  1275. hwif->ide_dma_check = &hpt366_config_drive_xfer_rate;
  1276. if (info->revision >= 8) {
  1277. hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;
  1278. hwif->ide_dma_end = &hpt374_ide_dma_end;
  1279. } else if (info->revision >= 5) {
  1280. hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;
  1281. hwif->ide_dma_end = &hpt374_ide_dma_end;
  1282. } else if (info->revision >= 3) {
  1283. hwif->dma_start = &hpt370_ide_dma_start;
  1284. hwif->ide_dma_end = &hpt370_ide_dma_end;
  1285. hwif->ide_dma_timeout = &hpt370_ide_dma_timeout;
  1286. hwif->ide_dma_lostirq = &hpt370_ide_dma_lostirq;
  1287. } else if (info->revision >= 2)
  1288. hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq;
  1289. else
  1290. hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq;
  1291. if (!noautodma)
  1292. hwif->autodma = 1;
  1293. hwif->drives[0].autodma = hwif->autodma;
  1294. hwif->drives[1].autodma = hwif->autodma;
  1295. }
  1296. static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
  1297. {
  1298. struct hpt_info *info = ide_get_hwifdata(hwif);
  1299. u8 masterdma = 0, slavedma = 0;
  1300. u8 dma_new = 0, dma_old = 0;
  1301. u8 primary = hwif->channel ? 0x4b : 0x43;
  1302. u8 secondary = hwif->channel ? 0x4f : 0x47;
  1303. unsigned long flags;
  1304. if (!dmabase)
  1305. return;
  1306. if(info->speed == NULL) {
  1307. printk(KERN_WARNING "hpt: no known IDE timings, disabling DMA.\n");
  1308. return;
  1309. }
  1310. dma_old = hwif->INB(dmabase+2);
  1311. local_irq_save(flags);
  1312. dma_new = dma_old;
  1313. pci_read_config_byte(hwif->pci_dev, primary, &masterdma);
  1314. pci_read_config_byte(hwif->pci_dev, secondary, &slavedma);
  1315. if (masterdma & 0x30) dma_new |= 0x20;
  1316. if (slavedma & 0x30) dma_new |= 0x40;
  1317. if (dma_new != dma_old)
  1318. hwif->OUTB(dma_new, dmabase+2);
  1319. local_irq_restore(flags);
  1320. ide_setup_dma(hwif, dmabase, 8);
  1321. }
  1322. /*
  1323. * We "borrow" this hook in order to set the data structures
  1324. * up early enough before dma or init_hwif calls are made.
  1325. */
  1326. static void __devinit init_iops_hpt366(ide_hwif_t *hwif)
  1327. {
  1328. struct hpt_info *info = kmalloc(sizeof(struct hpt_info), GFP_KERNEL);
  1329. unsigned long dmabase = pci_resource_start(hwif->pci_dev, 4);
  1330. u8 did, rid;
  1331. if(info == NULL) {
  1332. printk(KERN_WARNING "hpt366: out of memory.\n");
  1333. return;
  1334. }
  1335. memset(info, 0, sizeof(struct hpt_info));
  1336. ide_set_hwifdata(hwif, info);
  1337. if(dmabase) {
  1338. did = inb(dmabase + 0x22);
  1339. rid = inb(dmabase + 0x28);
  1340. if((did == 4 && rid == 6) || (did == 5 && rid > 1))
  1341. info->flags |= IS_372N;
  1342. }
  1343. info->revision = hpt_revision(hwif->pci_dev);
  1344. if (info->revision >= 3)
  1345. hpt37x_clocking(hwif);
  1346. else
  1347. hpt366_clocking(hwif);
  1348. }
  1349. static int __devinit init_setup_hpt374(struct pci_dev *dev, ide_pci_device_t *d)
  1350. {
  1351. struct pci_dev *findev = NULL;
  1352. if (PCI_FUNC(dev->devfn) & 1)
  1353. return -ENODEV;
  1354. while ((findev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, findev)) != NULL) {
  1355. if ((findev->vendor == dev->vendor) &&
  1356. (findev->device == dev->device) &&
  1357. ((findev->devfn - dev->devfn) == 1) &&
  1358. (PCI_FUNC(findev->devfn) & 1)) {
  1359. if (findev->irq != dev->irq) {
  1360. /* FIXME: we need a core pci_set_interrupt() */
  1361. findev->irq = dev->irq;
  1362. printk(KERN_WARNING "%s: pci-config space interrupt "
  1363. "fixed.\n", d->name);
  1364. }
  1365. return ide_setup_pci_devices(dev, findev, d);
  1366. }
  1367. }
  1368. return ide_setup_pci_device(dev, d);
  1369. }
  1370. static int __devinit init_setup_hpt37x(struct pci_dev *dev, ide_pci_device_t *d)
  1371. {
  1372. return ide_setup_pci_device(dev, d);
  1373. }
  1374. static int __devinit init_setup_hpt366(struct pci_dev *dev, ide_pci_device_t *d)
  1375. {
  1376. struct pci_dev *findev = NULL;
  1377. u8 pin1 = 0, pin2 = 0;
  1378. unsigned int class_rev;
  1379. char *chipset_names[] = {"HPT366", "HPT366", "HPT368",
  1380. "HPT370", "HPT370A", "HPT372",
  1381. "HPT372N" };
  1382. if (PCI_FUNC(dev->devfn) & 1)
  1383. return -ENODEV;
  1384. pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
  1385. class_rev &= 0xff;
  1386. if(dev->device == PCI_DEVICE_ID_TTI_HPT372N)
  1387. class_rev = 6;
  1388. if(class_rev <= 6)
  1389. d->name = chipset_names[class_rev];
  1390. switch(class_rev) {
  1391. case 6:
  1392. case 5:
  1393. case 4:
  1394. case 3:
  1395. goto init_single;
  1396. default:
  1397. break;
  1398. }
  1399. d->channels = 1;
  1400. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin1);
  1401. while ((findev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, findev)) != NULL) {
  1402. if ((findev->vendor == dev->vendor) &&
  1403. (findev->device == dev->device) &&
  1404. ((findev->devfn - dev->devfn) == 1) &&
  1405. (PCI_FUNC(findev->devfn) & 1)) {
  1406. pci_read_config_byte(findev, PCI_INTERRUPT_PIN, &pin2);
  1407. if ((pin1 != pin2) && (dev->irq == findev->irq)) {
  1408. d->bootable = ON_BOARD;
  1409. printk("%s: onboard version of chipset, "
  1410. "pin1=%d pin2=%d\n", d->name,
  1411. pin1, pin2);
  1412. }
  1413. return ide_setup_pci_devices(dev, findev, d);
  1414. }
  1415. }
  1416. init_single:
  1417. return ide_setup_pci_device(dev, d);
  1418. }
  1419. static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
  1420. { /* 0 */
  1421. .name = "HPT366",
  1422. .init_setup = init_setup_hpt366,
  1423. .init_chipset = init_chipset_hpt366,
  1424. .init_iops = init_iops_hpt366,
  1425. .init_hwif = init_hwif_hpt366,
  1426. .init_dma = init_dma_hpt366,
  1427. .channels = 2,
  1428. .autodma = AUTODMA,
  1429. .bootable = OFF_BOARD,
  1430. .extra = 240
  1431. },{ /* 1 */
  1432. .name = "HPT372A",
  1433. .init_setup = init_setup_hpt37x,
  1434. .init_chipset = init_chipset_hpt366,
  1435. .init_iops = init_iops_hpt366,
  1436. .init_hwif = init_hwif_hpt366,
  1437. .init_dma = init_dma_hpt366,
  1438. .channels = 2,
  1439. .autodma = AUTODMA,
  1440. .bootable = OFF_BOARD,
  1441. },{ /* 2 */
  1442. .name = "HPT302",
  1443. .init_setup = init_setup_hpt37x,
  1444. .init_chipset = init_chipset_hpt366,
  1445. .init_iops = init_iops_hpt366,
  1446. .init_hwif = init_hwif_hpt366,
  1447. .init_dma = init_dma_hpt366,
  1448. .channels = 2,
  1449. .autodma = AUTODMA,
  1450. .bootable = OFF_BOARD,
  1451. },{ /* 3 */
  1452. .name = "HPT371",
  1453. .init_setup = init_setup_hpt37x,
  1454. .init_chipset = init_chipset_hpt366,
  1455. .init_iops = init_iops_hpt366,
  1456. .init_hwif = init_hwif_hpt366,
  1457. .init_dma = init_dma_hpt366,
  1458. .channels = 2,
  1459. .autodma = AUTODMA,
  1460. .bootable = OFF_BOARD,
  1461. },{ /* 4 */
  1462. .name = "HPT374",
  1463. .init_setup = init_setup_hpt374,
  1464. .init_chipset = init_chipset_hpt366,
  1465. .init_iops = init_iops_hpt366,
  1466. .init_hwif = init_hwif_hpt366,
  1467. .init_dma = init_dma_hpt366,
  1468. .channels = 2, /* 4 */
  1469. .autodma = AUTODMA,
  1470. .bootable = OFF_BOARD,
  1471. },{ /* 5 */
  1472. .name = "HPT372N",
  1473. .init_setup = init_setup_hpt37x,
  1474. .init_chipset = init_chipset_hpt366,
  1475. .init_iops = init_iops_hpt366,
  1476. .init_hwif = init_hwif_hpt366,
  1477. .init_dma = init_dma_hpt366,
  1478. .channels = 2, /* 4 */
  1479. .autodma = AUTODMA,
  1480. .bootable = OFF_BOARD,
  1481. }
  1482. };
  1483. /**
  1484. * hpt366_init_one - called when an HPT366 is found
  1485. * @dev: the hpt366 device
  1486. * @id: the matching pci id
  1487. *
  1488. * Called when the PCI registration layer (or the IDE initialization)
  1489. * finds a device matching our IDE device tables.
  1490. */
  1491. static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  1492. {
  1493. ide_pci_device_t *d = &hpt366_chipsets[id->driver_data];
  1494. return d->init_setup(dev, d);
  1495. }
  1496. static struct pci_device_id hpt366_pci_tbl[] = {
  1497. { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT366, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  1498. { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT372, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
  1499. { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT302, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
  1500. { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
  1501. { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT374, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
  1502. { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT372N, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
  1503. { 0, },
  1504. };
  1505. MODULE_DEVICE_TABLE(pci, hpt366_pci_tbl);
  1506. static struct pci_driver driver = {
  1507. .name = "HPT366_IDE",
  1508. .id_table = hpt366_pci_tbl,
  1509. .probe = hpt366_init_one,
  1510. };
  1511. static int hpt366_ide_init(void)
  1512. {
  1513. return ide_pci_register_driver(&driver);
  1514. }
  1515. module_init(hpt366_ide_init);
  1516. MODULE_AUTHOR("Andre Hedrick");
  1517. MODULE_DESCRIPTION("PCI driver module for Highpoint HPT366 IDE");
  1518. MODULE_LICENSE("GPL");