hpt366.c 48 KB

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