hpt366.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676
  1. /*
  2. * linux/drivers/ide/pci/hpt366.c Version 1.22 Dec 4, 2007
  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. * Portions Copyright (C) 2007 Bartlomiej Zolnierkiewicz
  8. * Portions Copyright (C) 2005-2007 MontaVista Software, Inc.
  9. *
  10. * Thanks to HighPoint Technologies for their assistance, and hardware.
  11. * Special Thanks to Jon Burchmore in SanDiego for the deep pockets, his
  12. * donation of an ABit BP6 mainboard, processor, and memory acellerated
  13. * development and support.
  14. *
  15. *
  16. * HighPoint has its own drivers (open source except for the RAID part)
  17. * available from http://www.highpoint-tech.com/BIOS%20+%20Driver/.
  18. * This may be useful to anyone wanting to work on this driver, however do not
  19. * trust them too much since the code tends to become less and less meaningful
  20. * as the time passes... :-/
  21. *
  22. * Note that final HPT370 support was done by force extraction of GPL.
  23. *
  24. * - add function for getting/setting power status of drive
  25. * - the HPT370's state machine can get confused. reset it before each dma
  26. * xfer to prevent that from happening.
  27. * - reset state engine whenever we get an error.
  28. * - check for busmaster state at end of dma.
  29. * - use new highpoint timings.
  30. * - detect bus speed using highpoint register.
  31. * - use pll if we don't have a clock table. added a 66MHz table that's
  32. * just 2x the 33MHz table.
  33. * - removed turnaround. NOTE: we never want to switch between pll and
  34. * pci clocks as the chip can glitch in those cases. the highpoint
  35. * approved workaround slows everything down too much to be useful. in
  36. * addition, we would have to serialize access to each chip.
  37. * Adrian Sun <a.sun@sun.com>
  38. *
  39. * add drive timings for 66MHz PCI bus,
  40. * fix ATA Cable signal detection, fix incorrect /proc info
  41. * add /proc display for per-drive PIO/DMA/UDMA mode and
  42. * per-channel ATA-33/66 Cable detect.
  43. * Duncan Laurie <void@sun.com>
  44. *
  45. * fixup /proc output for multiple controllers
  46. * Tim Hockin <thockin@sun.com>
  47. *
  48. * On hpt366:
  49. * Reset the hpt366 on error, reset on dma
  50. * Fix disabling Fast Interrupt hpt366.
  51. * Mike Waychison <crlf@sun.com>
  52. *
  53. * Added support for 372N clocking and clock switching. The 372N needs
  54. * different clocks on read/write. This requires overloading rw_disk and
  55. * other deeply crazy things. Thanks to <http://www.hoerstreich.de> for
  56. * keeping me sane.
  57. * Alan Cox <alan@redhat.com>
  58. *
  59. * - fix the clock turnaround code: it was writing to the wrong ports when
  60. * called for the secondary channel, caching the current clock mode per-
  61. * channel caused the cached register value to get out of sync with the
  62. * actual one, the channels weren't serialized, the turnaround shouldn't
  63. * be done on 66 MHz PCI bus
  64. * - disable UltraATA/100 for HPT370 by default as the 33 MHz clock being used
  65. * does not allow for this speed anyway
  66. * - avoid touching disabled channels (e.g. HPT371/N are single channel chips,
  67. * their primary channel is kind of virtual, it isn't tied to any pins)
  68. * - fix/remove bad/unused timing tables and use one set of tables for the whole
  69. * HPT37x chip family; save space by introducing the separate transfer mode
  70. * table in which the mode lookup is done
  71. * - use f_CNT value saved by the HighPoint BIOS as reading it directly gives
  72. * the wrong PCI frequency since DPLL has already been calibrated by BIOS;
  73. * read it only from the function 0 of HPT374 chips
  74. * - fix the hotswap code: it caused RESET- to glitch when tristating the bus,
  75. * and for HPT36x the obsolete HDIO_TRISTATE_HWIF handler was called instead
  76. * - pass to init_chipset() handlers a copy of the IDE PCI device structure as
  77. * they tamper with its fields
  78. * - pass to the init_setup handlers a copy of the ide_pci_device_t structure
  79. * since they may tamper with its fields
  80. * - prefix the driver startup messages with the real chip name
  81. * - claim the extra 240 bytes of I/O space for all chips
  82. * - optimize the UltraDMA filtering and the drive list lookup code
  83. * - use pci_get_slot() to get to the function 1 of HPT36x/374
  84. * - cache offset of the channel's misc. control registers (MCRs) being used
  85. * throughout the driver
  86. * - only touch the relevant MCR when detecting the cable type on HPT374's
  87. * function 1
  88. * - rename all the register related variables consistently
  89. * - move all the interrupt twiddling code from the speedproc handlers into
  90. * init_hwif_hpt366(), also grouping all the DMA related code together there
  91. * - merge two HPT37x speedproc handlers, fix the PIO timing register mask and
  92. * separate the UltraDMA and MWDMA masks there to avoid changing PIO timings
  93. * when setting an UltraDMA mode
  94. * - fix hpt3xx_tune_drive() to set the PIO mode requested, not always select
  95. * the best possible one
  96. * - clean up DMA timeout handling for HPT370
  97. * - switch to using the enumeration type to differ between the numerous chip
  98. * variants, matching PCI device/revision ID with the chip type early, at the
  99. * init_setup stage
  100. * - extend the hpt_info structure to hold the DPLL and PCI clock frequencies,
  101. * stop duplicating it for each channel by storing the pointer in the pci_dev
  102. * structure: first, at the init_setup stage, point it to a static "template"
  103. * with only the chip type and its specific base DPLL frequency, the highest
  104. * UltraDMA mode, and the chip settings table pointer filled, then, at the
  105. * init_chipset stage, allocate per-chip instance and fill it with the rest
  106. * of the necessary information
  107. * - get rid of the constant thresholds in the HPT37x PCI clock detection code,
  108. * switch to calculating PCI clock frequency based on the chip's base DPLL
  109. * frequency
  110. * - switch to using the DPLL clock and enable UltraATA/133 mode by default on
  111. * anything newer than HPT370/A (except HPT374 that is not capable of this
  112. * mode according to the manual)
  113. * - fold PCI clock detection and DPLL setup code into init_chipset_hpt366(),
  114. * also fixing the interchanged 25/40 MHz PCI clock cases for HPT36x chips;
  115. * unify HPT36x/37x timing setup code and the speedproc handlers by joining
  116. * the register setting lists into the table indexed by the clock selected
  117. * - set the correct hwif->ultra_mask for each individual chip
  118. * - add Ultra and MW DMA mode filtering for the HPT37[24] based SATA cards
  119. * Sergei Shtylyov, <sshtylyov@ru.mvista.com> or <source@mvista.com>
  120. */
  121. #include <linux/types.h>
  122. #include <linux/module.h>
  123. #include <linux/kernel.h>
  124. #include <linux/delay.h>
  125. #include <linux/timer.h>
  126. #include <linux/mm.h>
  127. #include <linux/ioport.h>
  128. #include <linux/blkdev.h>
  129. #include <linux/hdreg.h>
  130. #include <linux/interrupt.h>
  131. #include <linux/pci.h>
  132. #include <linux/init.h>
  133. #include <linux/ide.h>
  134. #include <asm/uaccess.h>
  135. #include <asm/io.h>
  136. #include <asm/irq.h>
  137. /* various tuning parameters */
  138. #define HPT_RESET_STATE_ENGINE
  139. #undef HPT_DELAY_INTERRUPT
  140. #define HPT_SERIALIZE_IO 0
  141. static const char *quirk_drives[] = {
  142. "QUANTUM FIREBALLlct08 08",
  143. "QUANTUM FIREBALLP KA6.4",
  144. "QUANTUM FIREBALLP LM20.4",
  145. "QUANTUM FIREBALLP LM20.5",
  146. NULL
  147. };
  148. static const char *bad_ata100_5[] = {
  149. "IBM-DTLA-307075",
  150. "IBM-DTLA-307060",
  151. "IBM-DTLA-307045",
  152. "IBM-DTLA-307030",
  153. "IBM-DTLA-307020",
  154. "IBM-DTLA-307015",
  155. "IBM-DTLA-305040",
  156. "IBM-DTLA-305030",
  157. "IBM-DTLA-305020",
  158. "IC35L010AVER07-0",
  159. "IC35L020AVER07-0",
  160. "IC35L030AVER07-0",
  161. "IC35L040AVER07-0",
  162. "IC35L060AVER07-0",
  163. "WDC AC310200R",
  164. NULL
  165. };
  166. static const char *bad_ata66_4[] = {
  167. "IBM-DTLA-307075",
  168. "IBM-DTLA-307060",
  169. "IBM-DTLA-307045",
  170. "IBM-DTLA-307030",
  171. "IBM-DTLA-307020",
  172. "IBM-DTLA-307015",
  173. "IBM-DTLA-305040",
  174. "IBM-DTLA-305030",
  175. "IBM-DTLA-305020",
  176. "IC35L010AVER07-0",
  177. "IC35L020AVER07-0",
  178. "IC35L030AVER07-0",
  179. "IC35L040AVER07-0",
  180. "IC35L060AVER07-0",
  181. "WDC AC310200R",
  182. "MAXTOR STM3320620A",
  183. NULL
  184. };
  185. static const char *bad_ata66_3[] = {
  186. "WDC AC310200R",
  187. NULL
  188. };
  189. static const char *bad_ata33[] = {
  190. "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3", "Maxtor 90845U3", "Maxtor 90650U2",
  191. "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5", "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2",
  192. "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6", "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4",
  193. "Maxtor 90510D4",
  194. "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2",
  195. "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7", "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4",
  196. "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5", "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2",
  197. NULL
  198. };
  199. static u8 xfer_speeds[] = {
  200. XFER_UDMA_6,
  201. XFER_UDMA_5,
  202. XFER_UDMA_4,
  203. XFER_UDMA_3,
  204. XFER_UDMA_2,
  205. XFER_UDMA_1,
  206. XFER_UDMA_0,
  207. XFER_MW_DMA_2,
  208. XFER_MW_DMA_1,
  209. XFER_MW_DMA_0,
  210. XFER_PIO_4,
  211. XFER_PIO_3,
  212. XFER_PIO_2,
  213. XFER_PIO_1,
  214. XFER_PIO_0
  215. };
  216. /* Key for bus clock timings
  217. * 36x 37x
  218. * bits bits
  219. * 0:3 0:3 data_high_time. Inactive time of DIOW_/DIOR_ for PIO and MW DMA.
  220. * cycles = value + 1
  221. * 4:7 4:8 data_low_time. Active time of DIOW_/DIOR_ for PIO and MW DMA.
  222. * cycles = value + 1
  223. * 8:11 9:12 cmd_high_time. Inactive time of DIOW_/DIOR_ during task file
  224. * register access.
  225. * 12:15 13:17 cmd_low_time. Active time of DIOW_/DIOR_ during task file
  226. * register access.
  227. * 16:18 18:20 udma_cycle_time. Clock cycles for UDMA xfer.
  228. * - 21 CLK frequency: 0=ATA clock, 1=dual ATA clock.
  229. * 19:21 22:24 pre_high_time. Time to initialize the 1st cycle for PIO and
  230. * MW DMA xfer.
  231. * 22:24 25:27 cmd_pre_high_time. Time to initialize the 1st PIO cycle for
  232. * task file register access.
  233. * 28 28 UDMA enable.
  234. * 29 29 DMA enable.
  235. * 30 30 PIO MST enable. If set, the chip is in bus master mode during
  236. * PIO xfer.
  237. * 31 31 FIFO enable.
  238. */
  239. static u32 forty_base_hpt36x[] = {
  240. /* XFER_UDMA_6 */ 0x900fd943,
  241. /* XFER_UDMA_5 */ 0x900fd943,
  242. /* XFER_UDMA_4 */ 0x900fd943,
  243. /* XFER_UDMA_3 */ 0x900ad943,
  244. /* XFER_UDMA_2 */ 0x900bd943,
  245. /* XFER_UDMA_1 */ 0x9008d943,
  246. /* XFER_UDMA_0 */ 0x9008d943,
  247. /* XFER_MW_DMA_2 */ 0xa008d943,
  248. /* XFER_MW_DMA_1 */ 0xa010d955,
  249. /* XFER_MW_DMA_0 */ 0xa010d9fc,
  250. /* XFER_PIO_4 */ 0xc008d963,
  251. /* XFER_PIO_3 */ 0xc010d974,
  252. /* XFER_PIO_2 */ 0xc010d997,
  253. /* XFER_PIO_1 */ 0xc010d9c7,
  254. /* XFER_PIO_0 */ 0xc018d9d9
  255. };
  256. static u32 thirty_three_base_hpt36x[] = {
  257. /* XFER_UDMA_6 */ 0x90c9a731,
  258. /* XFER_UDMA_5 */ 0x90c9a731,
  259. /* XFER_UDMA_4 */ 0x90c9a731,
  260. /* XFER_UDMA_3 */ 0x90cfa731,
  261. /* XFER_UDMA_2 */ 0x90caa731,
  262. /* XFER_UDMA_1 */ 0x90cba731,
  263. /* XFER_UDMA_0 */ 0x90c8a731,
  264. /* XFER_MW_DMA_2 */ 0xa0c8a731,
  265. /* XFER_MW_DMA_1 */ 0xa0c8a732, /* 0xa0c8a733 */
  266. /* XFER_MW_DMA_0 */ 0xa0c8a797,
  267. /* XFER_PIO_4 */ 0xc0c8a731,
  268. /* XFER_PIO_3 */ 0xc0c8a742,
  269. /* XFER_PIO_2 */ 0xc0d0a753,
  270. /* XFER_PIO_1 */ 0xc0d0a7a3, /* 0xc0d0a793 */
  271. /* XFER_PIO_0 */ 0xc0d0a7aa /* 0xc0d0a7a7 */
  272. };
  273. static u32 twenty_five_base_hpt36x[] = {
  274. /* XFER_UDMA_6 */ 0x90c98521,
  275. /* XFER_UDMA_5 */ 0x90c98521,
  276. /* XFER_UDMA_4 */ 0x90c98521,
  277. /* XFER_UDMA_3 */ 0x90cf8521,
  278. /* XFER_UDMA_2 */ 0x90cf8521,
  279. /* XFER_UDMA_1 */ 0x90cb8521,
  280. /* XFER_UDMA_0 */ 0x90cb8521,
  281. /* XFER_MW_DMA_2 */ 0xa0ca8521,
  282. /* XFER_MW_DMA_1 */ 0xa0ca8532,
  283. /* XFER_MW_DMA_0 */ 0xa0ca8575,
  284. /* XFER_PIO_4 */ 0xc0ca8521,
  285. /* XFER_PIO_3 */ 0xc0ca8532,
  286. /* XFER_PIO_2 */ 0xc0ca8542,
  287. /* XFER_PIO_1 */ 0xc0d08572,
  288. /* XFER_PIO_0 */ 0xc0d08585
  289. };
  290. #if 0
  291. /* These are the timing tables from the HighPoint open source drivers... */
  292. static u32 thirty_three_base_hpt37x[] = {
  293. /* XFER_UDMA_6 */ 0x12446231, /* 0x12646231 ?? */
  294. /* XFER_UDMA_5 */ 0x12446231,
  295. /* XFER_UDMA_4 */ 0x12446231,
  296. /* XFER_UDMA_3 */ 0x126c6231,
  297. /* XFER_UDMA_2 */ 0x12486231,
  298. /* XFER_UDMA_1 */ 0x124c6233,
  299. /* XFER_UDMA_0 */ 0x12506297,
  300. /* XFER_MW_DMA_2 */ 0x22406c31,
  301. /* XFER_MW_DMA_1 */ 0x22406c33,
  302. /* XFER_MW_DMA_0 */ 0x22406c97,
  303. /* XFER_PIO_4 */ 0x06414e31,
  304. /* XFER_PIO_3 */ 0x06414e42,
  305. /* XFER_PIO_2 */ 0x06414e53,
  306. /* XFER_PIO_1 */ 0x06814e93,
  307. /* XFER_PIO_0 */ 0x06814ea7
  308. };
  309. static u32 fifty_base_hpt37x[] = {
  310. /* XFER_UDMA_6 */ 0x12848242,
  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. };
  326. static u32 sixty_six_base_hpt37x[] = {
  327. /* XFER_UDMA_6 */ 0x1c869c62,
  328. /* XFER_UDMA_5 */ 0x1cae9c62, /* 0x1c8a9c62 */
  329. /* XFER_UDMA_4 */ 0x1c8a9c62,
  330. /* XFER_UDMA_3 */ 0x1c8e9c62,
  331. /* XFER_UDMA_2 */ 0x1c929c62,
  332. /* XFER_UDMA_1 */ 0x1c9a9c62,
  333. /* XFER_UDMA_0 */ 0x1c829c62,
  334. /* XFER_MW_DMA_2 */ 0x2c829c62,
  335. /* XFER_MW_DMA_1 */ 0x2c829c66,
  336. /* XFER_MW_DMA_0 */ 0x2c829d2e,
  337. /* XFER_PIO_4 */ 0x0c829c62,
  338. /* XFER_PIO_3 */ 0x0c829c84,
  339. /* XFER_PIO_2 */ 0x0c829ca6,
  340. /* XFER_PIO_1 */ 0x0d029d26,
  341. /* XFER_PIO_0 */ 0x0d029d5e
  342. };
  343. #else
  344. /*
  345. * The following are the new timing tables with PIO mode data/taskfile transfer
  346. * overclocking fixed...
  347. */
  348. /* This table is taken from the HPT370 data manual rev. 1.02 */
  349. static u32 thirty_three_base_hpt37x[] = {
  350. /* XFER_UDMA_6 */ 0x16455031, /* 0x16655031 ?? */
  351. /* XFER_UDMA_5 */ 0x16455031,
  352. /* XFER_UDMA_4 */ 0x16455031,
  353. /* XFER_UDMA_3 */ 0x166d5031,
  354. /* XFER_UDMA_2 */ 0x16495031,
  355. /* XFER_UDMA_1 */ 0x164d5033,
  356. /* XFER_UDMA_0 */ 0x16515097,
  357. /* XFER_MW_DMA_2 */ 0x26515031,
  358. /* XFER_MW_DMA_1 */ 0x26515033,
  359. /* XFER_MW_DMA_0 */ 0x26515097,
  360. /* XFER_PIO_4 */ 0x06515021,
  361. /* XFER_PIO_3 */ 0x06515022,
  362. /* XFER_PIO_2 */ 0x06515033,
  363. /* XFER_PIO_1 */ 0x06915065,
  364. /* XFER_PIO_0 */ 0x06d1508a
  365. };
  366. static u32 fifty_base_hpt37x[] = {
  367. /* XFER_UDMA_6 */ 0x1a861842,
  368. /* XFER_UDMA_5 */ 0x1a861842,
  369. /* XFER_UDMA_4 */ 0x1aae1842,
  370. /* XFER_UDMA_3 */ 0x1a8e1842,
  371. /* XFER_UDMA_2 */ 0x1a0e1842,
  372. /* XFER_UDMA_1 */ 0x1a161854,
  373. /* XFER_UDMA_0 */ 0x1a1a18ea,
  374. /* XFER_MW_DMA_2 */ 0x2a821842,
  375. /* XFER_MW_DMA_1 */ 0x2a821854,
  376. /* XFER_MW_DMA_0 */ 0x2a8218ea,
  377. /* XFER_PIO_4 */ 0x0a821842,
  378. /* XFER_PIO_3 */ 0x0a821843,
  379. /* XFER_PIO_2 */ 0x0a821855,
  380. /* XFER_PIO_1 */ 0x0ac218a8,
  381. /* XFER_PIO_0 */ 0x0b02190c
  382. };
  383. static u32 sixty_six_base_hpt37x[] = {
  384. /* XFER_UDMA_6 */ 0x1c86fe62,
  385. /* XFER_UDMA_5 */ 0x1caefe62, /* 0x1c8afe62 */
  386. /* XFER_UDMA_4 */ 0x1c8afe62,
  387. /* XFER_UDMA_3 */ 0x1c8efe62,
  388. /* XFER_UDMA_2 */ 0x1c92fe62,
  389. /* XFER_UDMA_1 */ 0x1c9afe62,
  390. /* XFER_UDMA_0 */ 0x1c82fe62,
  391. /* XFER_MW_DMA_2 */ 0x2c82fe62,
  392. /* XFER_MW_DMA_1 */ 0x2c82fe66,
  393. /* XFER_MW_DMA_0 */ 0x2c82ff2e,
  394. /* XFER_PIO_4 */ 0x0c82fe62,
  395. /* XFER_PIO_3 */ 0x0c82fe84,
  396. /* XFER_PIO_2 */ 0x0c82fea6,
  397. /* XFER_PIO_1 */ 0x0d02ff26,
  398. /* XFER_PIO_0 */ 0x0d42ff7f
  399. };
  400. #endif
  401. #define HPT366_DEBUG_DRIVE_INFO 0
  402. #define HPT371_ALLOW_ATA133_6 1
  403. #define HPT302_ALLOW_ATA133_6 1
  404. #define HPT372_ALLOW_ATA133_6 1
  405. #define HPT370_ALLOW_ATA100_5 0
  406. #define HPT366_ALLOW_ATA66_4 1
  407. #define HPT366_ALLOW_ATA66_3 1
  408. #define HPT366_MAX_DEVS 8
  409. /* Supported ATA clock frequencies */
  410. enum ata_clock {
  411. ATA_CLOCK_25MHZ,
  412. ATA_CLOCK_33MHZ,
  413. ATA_CLOCK_40MHZ,
  414. ATA_CLOCK_50MHZ,
  415. ATA_CLOCK_66MHZ,
  416. NUM_ATA_CLOCKS
  417. };
  418. /*
  419. * Hold all the HighPoint chip information in one place.
  420. */
  421. struct hpt_info {
  422. char *chip_name; /* Chip name */
  423. u8 chip_type; /* Chip type */
  424. u8 udma_mask; /* Allowed UltraDMA modes mask. */
  425. u8 dpll_clk; /* DPLL clock in MHz */
  426. u8 pci_clk; /* PCI clock in MHz */
  427. u32 **settings; /* Chipset settings table */
  428. };
  429. /* Supported HighPoint chips */
  430. enum {
  431. HPT36x,
  432. HPT370,
  433. HPT370A,
  434. HPT374,
  435. HPT372,
  436. HPT372A,
  437. HPT302,
  438. HPT371,
  439. HPT372N,
  440. HPT302N,
  441. HPT371N
  442. };
  443. static u32 *hpt36x_settings[NUM_ATA_CLOCKS] = {
  444. twenty_five_base_hpt36x,
  445. thirty_three_base_hpt36x,
  446. forty_base_hpt36x,
  447. NULL,
  448. NULL
  449. };
  450. static u32 *hpt37x_settings[NUM_ATA_CLOCKS] = {
  451. NULL,
  452. thirty_three_base_hpt37x,
  453. NULL,
  454. fifty_base_hpt37x,
  455. sixty_six_base_hpt37x
  456. };
  457. static const struct hpt_info hpt36x __devinitdata = {
  458. .chip_name = "HPT36x",
  459. .chip_type = HPT36x,
  460. .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
  461. .dpll_clk = 0, /* no DPLL */
  462. .settings = hpt36x_settings
  463. };
  464. static const struct hpt_info hpt370 __devinitdata = {
  465. .chip_name = "HPT370",
  466. .chip_type = HPT370,
  467. .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
  468. .dpll_clk = 48,
  469. .settings = hpt37x_settings
  470. };
  471. static const struct hpt_info hpt370a __devinitdata = {
  472. .chip_name = "HPT370A",
  473. .chip_type = HPT370A,
  474. .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
  475. .dpll_clk = 48,
  476. .settings = hpt37x_settings
  477. };
  478. static const struct hpt_info hpt374 __devinitdata = {
  479. .chip_name = "HPT374",
  480. .chip_type = HPT374,
  481. .udma_mask = ATA_UDMA5,
  482. .dpll_clk = 48,
  483. .settings = hpt37x_settings
  484. };
  485. static const struct hpt_info hpt372 __devinitdata = {
  486. .chip_name = "HPT372",
  487. .chip_type = HPT372,
  488. .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
  489. .dpll_clk = 55,
  490. .settings = hpt37x_settings
  491. };
  492. static const struct hpt_info hpt372a __devinitdata = {
  493. .chip_name = "HPT372A",
  494. .chip_type = HPT372A,
  495. .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
  496. .dpll_clk = 66,
  497. .settings = hpt37x_settings
  498. };
  499. static const struct hpt_info hpt302 __devinitdata = {
  500. .chip_name = "HPT302",
  501. .chip_type = HPT302,
  502. .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
  503. .dpll_clk = 66,
  504. .settings = hpt37x_settings
  505. };
  506. static const struct hpt_info hpt371 __devinitdata = {
  507. .chip_name = "HPT371",
  508. .chip_type = HPT371,
  509. .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
  510. .dpll_clk = 66,
  511. .settings = hpt37x_settings
  512. };
  513. static const struct hpt_info hpt372n __devinitdata = {
  514. .chip_name = "HPT372N",
  515. .chip_type = HPT372N,
  516. .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
  517. .dpll_clk = 77,
  518. .settings = hpt37x_settings
  519. };
  520. static const struct hpt_info hpt302n __devinitdata = {
  521. .chip_name = "HPT302N",
  522. .chip_type = HPT302N,
  523. .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
  524. .dpll_clk = 77,
  525. .settings = hpt37x_settings
  526. };
  527. static const struct hpt_info hpt371n __devinitdata = {
  528. .chip_name = "HPT371N",
  529. .chip_type = HPT371N,
  530. .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
  531. .dpll_clk = 77,
  532. .settings = hpt37x_settings
  533. };
  534. static int check_in_drive_list(ide_drive_t *drive, const char **list)
  535. {
  536. struct hd_driveid *id = drive->id;
  537. while (*list)
  538. if (!strcmp(*list++,id->model))
  539. return 1;
  540. return 0;
  541. }
  542. /*
  543. * The Marvell bridge chips used on the HighPoint SATA cards do not seem
  544. * to support the UltraDMA modes 1, 2, and 3 as well as any MWDMA modes...
  545. */
  546. static u8 hpt3xx_udma_filter(ide_drive_t *drive)
  547. {
  548. ide_hwif_t *hwif = HWIF(drive);
  549. struct hpt_info *info = pci_get_drvdata(hwif->pci_dev);
  550. u8 mask = hwif->ultra_mask;
  551. switch (info->chip_type) {
  552. case HPT36x:
  553. if (!HPT366_ALLOW_ATA66_4 ||
  554. check_in_drive_list(drive, bad_ata66_4))
  555. mask = ATA_UDMA3;
  556. if (!HPT366_ALLOW_ATA66_3 ||
  557. check_in_drive_list(drive, bad_ata66_3))
  558. mask = ATA_UDMA2;
  559. break;
  560. case HPT370:
  561. if (!HPT370_ALLOW_ATA100_5 ||
  562. check_in_drive_list(drive, bad_ata100_5))
  563. mask = ATA_UDMA4;
  564. break;
  565. case HPT370A:
  566. if (!HPT370_ALLOW_ATA100_5 ||
  567. check_in_drive_list(drive, bad_ata100_5))
  568. return ATA_UDMA4;
  569. case HPT372 :
  570. case HPT372A:
  571. case HPT372N:
  572. case HPT374 :
  573. if (ide_dev_is_sata(drive->id))
  574. mask &= ~0x0e;
  575. /* Fall thru */
  576. default:
  577. return mask;
  578. }
  579. return check_in_drive_list(drive, bad_ata33) ? 0x00 : mask;
  580. }
  581. static u8 hpt3xx_mdma_filter(ide_drive_t *drive)
  582. {
  583. ide_hwif_t *hwif = HWIF(drive);
  584. struct hpt_info *info = pci_get_drvdata(hwif->pci_dev);
  585. switch (info->chip_type) {
  586. case HPT372 :
  587. case HPT372A:
  588. case HPT372N:
  589. case HPT374 :
  590. if (ide_dev_is_sata(drive->id))
  591. return 0x00;
  592. /* Fall thru */
  593. default:
  594. return 0x07;
  595. }
  596. }
  597. static u32 get_speed_setting(u8 speed, struct hpt_info *info)
  598. {
  599. int i;
  600. /*
  601. * Lookup the transfer mode table to get the index into
  602. * the timing table.
  603. *
  604. * NOTE: For XFER_PIO_SLOW, PIO mode 0 timings will be used.
  605. */
  606. for (i = 0; i < ARRAY_SIZE(xfer_speeds) - 1; i++)
  607. if (xfer_speeds[i] == speed)
  608. break;
  609. /*
  610. * NOTE: info->settings only points to the pointer
  611. * to the list of the actual register values
  612. */
  613. return (*info->settings)[i];
  614. }
  615. static void hpt36x_set_mode(ide_drive_t *drive, const u8 speed)
  616. {
  617. ide_hwif_t *hwif = HWIF(drive);
  618. struct pci_dev *dev = hwif->pci_dev;
  619. struct hpt_info *info = pci_get_drvdata(dev);
  620. u8 itr_addr = drive->dn ? 0x44 : 0x40;
  621. u32 old_itr = 0;
  622. u32 itr_mask, new_itr;
  623. itr_mask = speed < XFER_MW_DMA_0 ? 0x30070000 :
  624. (speed < XFER_UDMA_0 ? 0xc0070000 : 0xc03800ff);
  625. new_itr = get_speed_setting(speed, info);
  626. /*
  627. * Disable on-chip PIO FIFO/buffer (and PIO MST mode as well)
  628. * to avoid problems handling I/O errors later
  629. */
  630. pci_read_config_dword(dev, itr_addr, &old_itr);
  631. new_itr = (new_itr & ~itr_mask) | (old_itr & itr_mask);
  632. new_itr &= ~0xc0000000;
  633. pci_write_config_dword(dev, itr_addr, new_itr);
  634. }
  635. static void hpt37x_set_mode(ide_drive_t *drive, const u8 speed)
  636. {
  637. ide_hwif_t *hwif = HWIF(drive);
  638. struct pci_dev *dev = hwif->pci_dev;
  639. struct hpt_info *info = pci_get_drvdata(dev);
  640. u8 itr_addr = 0x40 + (drive->dn * 4);
  641. u32 old_itr = 0;
  642. u32 itr_mask, new_itr;
  643. itr_mask = speed < XFER_MW_DMA_0 ? 0x303c0000 :
  644. (speed < XFER_UDMA_0 ? 0xc03c0000 : 0xc1c001ff);
  645. new_itr = get_speed_setting(speed, info);
  646. pci_read_config_dword(dev, itr_addr, &old_itr);
  647. new_itr = (new_itr & ~itr_mask) | (old_itr & itr_mask);
  648. if (speed < XFER_MW_DMA_0)
  649. new_itr &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */
  650. pci_write_config_dword(dev, itr_addr, new_itr);
  651. }
  652. static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed)
  653. {
  654. ide_hwif_t *hwif = HWIF(drive);
  655. struct hpt_info *info = pci_get_drvdata(hwif->pci_dev);
  656. if (info->chip_type >= HPT370)
  657. hpt37x_set_mode(drive, speed);
  658. else /* hpt368: hpt_minimum_revision(dev, 2) */
  659. hpt36x_set_mode(drive, speed);
  660. }
  661. static void hpt3xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
  662. {
  663. hpt3xx_set_mode(drive, XFER_PIO_0 + pio);
  664. }
  665. static int hpt3xx_quirkproc(ide_drive_t *drive)
  666. {
  667. struct hd_driveid *id = drive->id;
  668. const char **list = quirk_drives;
  669. while (*list)
  670. if (strstr(id->model, *list++))
  671. return 1;
  672. return 0;
  673. }
  674. static void hpt3xx_intrproc(ide_drive_t *drive)
  675. {
  676. if (drive->quirk_list)
  677. return;
  678. /* drives in the quirk_list may not like intr setups/cleanups */
  679. outb(drive->ctl | 2, IDE_CONTROL_REG);
  680. }
  681. static void hpt3xx_maskproc(ide_drive_t *drive, int mask)
  682. {
  683. ide_hwif_t *hwif = HWIF(drive);
  684. struct pci_dev *dev = hwif->pci_dev;
  685. struct hpt_info *info = pci_get_drvdata(dev);
  686. if (drive->quirk_list) {
  687. if (info->chip_type >= HPT370) {
  688. u8 scr1 = 0;
  689. pci_read_config_byte(dev, 0x5a, &scr1);
  690. if (((scr1 & 0x10) >> 4) != mask) {
  691. if (mask)
  692. scr1 |= 0x10;
  693. else
  694. scr1 &= ~0x10;
  695. pci_write_config_byte(dev, 0x5a, scr1);
  696. }
  697. } else {
  698. if (mask)
  699. disable_irq(hwif->irq);
  700. else
  701. enable_irq (hwif->irq);
  702. }
  703. } else
  704. outb(mask ? (drive->ctl | 2) : (drive->ctl & ~2),
  705. IDE_CONTROL_REG);
  706. }
  707. /*
  708. * This is specific to the HPT366 UDMA chipset
  709. * by HighPoint|Triones Technologies, Inc.
  710. */
  711. static void hpt366_dma_lost_irq(ide_drive_t *drive)
  712. {
  713. struct pci_dev *dev = HWIF(drive)->pci_dev;
  714. u8 mcr1 = 0, mcr3 = 0, scr1 = 0;
  715. pci_read_config_byte(dev, 0x50, &mcr1);
  716. pci_read_config_byte(dev, 0x52, &mcr3);
  717. pci_read_config_byte(dev, 0x5a, &scr1);
  718. printk("%s: (%s) mcr1=0x%02x, mcr3=0x%02x, scr1=0x%02x\n",
  719. drive->name, __FUNCTION__, mcr1, mcr3, scr1);
  720. if (scr1 & 0x10)
  721. pci_write_config_byte(dev, 0x5a, scr1 & ~0x10);
  722. ide_dma_lost_irq(drive);
  723. }
  724. static void hpt370_clear_engine(ide_drive_t *drive)
  725. {
  726. ide_hwif_t *hwif = HWIF(drive);
  727. pci_write_config_byte(hwif->pci_dev, hwif->select_data, 0x37);
  728. udelay(10);
  729. }
  730. static void hpt370_irq_timeout(ide_drive_t *drive)
  731. {
  732. ide_hwif_t *hwif = HWIF(drive);
  733. u16 bfifo = 0;
  734. u8 dma_cmd;
  735. pci_read_config_word(hwif->pci_dev, hwif->select_data + 2, &bfifo);
  736. printk(KERN_DEBUG "%s: %d bytes in FIFO\n", drive->name, bfifo & 0x1ff);
  737. /* get DMA command mode */
  738. dma_cmd = inb(hwif->dma_command);
  739. /* stop DMA */
  740. outb(dma_cmd & ~0x1, hwif->dma_command);
  741. hpt370_clear_engine(drive);
  742. }
  743. static void hpt370_ide_dma_start(ide_drive_t *drive)
  744. {
  745. #ifdef HPT_RESET_STATE_ENGINE
  746. hpt370_clear_engine(drive);
  747. #endif
  748. ide_dma_start(drive);
  749. }
  750. static int hpt370_ide_dma_end(ide_drive_t *drive)
  751. {
  752. ide_hwif_t *hwif = HWIF(drive);
  753. u8 dma_stat = inb(hwif->dma_status);
  754. if (dma_stat & 0x01) {
  755. /* wait a little */
  756. udelay(20);
  757. dma_stat = inb(hwif->dma_status);
  758. if (dma_stat & 0x01)
  759. hpt370_irq_timeout(drive);
  760. }
  761. return __ide_dma_end(drive);
  762. }
  763. static void hpt370_dma_timeout(ide_drive_t *drive)
  764. {
  765. hpt370_irq_timeout(drive);
  766. ide_dma_timeout(drive);
  767. }
  768. /* returns 1 if DMA IRQ issued, 0 otherwise */
  769. static int hpt374_ide_dma_test_irq(ide_drive_t *drive)
  770. {
  771. ide_hwif_t *hwif = HWIF(drive);
  772. u16 bfifo = 0;
  773. u8 dma_stat;
  774. pci_read_config_word(hwif->pci_dev, hwif->select_data + 2, &bfifo);
  775. if (bfifo & 0x1FF) {
  776. // printk("%s: %d bytes in FIFO\n", drive->name, bfifo);
  777. return 0;
  778. }
  779. dma_stat = inb(hwif->dma_status);
  780. /* return 1 if INTR asserted */
  781. if (dma_stat & 4)
  782. return 1;
  783. if (!drive->waiting_for_dma)
  784. printk(KERN_WARNING "%s: (%s) called while not waiting\n",
  785. drive->name, __FUNCTION__);
  786. return 0;
  787. }
  788. static int hpt374_ide_dma_end(ide_drive_t *drive)
  789. {
  790. ide_hwif_t *hwif = HWIF(drive);
  791. struct pci_dev *dev = hwif->pci_dev;
  792. u8 mcr = 0, mcr_addr = hwif->select_data;
  793. u8 bwsr = 0, mask = hwif->channel ? 0x02 : 0x01;
  794. pci_read_config_byte(dev, 0x6a, &bwsr);
  795. pci_read_config_byte(dev, mcr_addr, &mcr);
  796. if (bwsr & mask)
  797. pci_write_config_byte(dev, mcr_addr, mcr | 0x30);
  798. return __ide_dma_end(drive);
  799. }
  800. /**
  801. * hpt3xxn_set_clock - perform clock switching dance
  802. * @hwif: hwif to switch
  803. * @mode: clocking mode (0x21 for write, 0x23 otherwise)
  804. *
  805. * Switch the DPLL clock on the HPT3xxN devices. This is a right mess.
  806. */
  807. static void hpt3xxn_set_clock(ide_hwif_t *hwif, u8 mode)
  808. {
  809. u8 scr2 = inb(hwif->dma_master + 0x7b);
  810. if ((scr2 & 0x7f) == mode)
  811. return;
  812. /* Tristate the bus */
  813. outb(0x80, hwif->dma_master + 0x73);
  814. outb(0x80, hwif->dma_master + 0x77);
  815. /* Switch clock and reset channels */
  816. outb(mode, hwif->dma_master + 0x7b);
  817. outb(0xc0, hwif->dma_master + 0x79);
  818. /*
  819. * Reset the state machines.
  820. * NOTE: avoid accidentally enabling the disabled channels.
  821. */
  822. outb(inb(hwif->dma_master + 0x70) | 0x32, hwif->dma_master + 0x70);
  823. outb(inb(hwif->dma_master + 0x74) | 0x32, hwif->dma_master + 0x74);
  824. /* Complete reset */
  825. outb(0x00, hwif->dma_master + 0x79);
  826. /* Reconnect channels to bus */
  827. outb(0x00, hwif->dma_master + 0x73);
  828. outb(0x00, hwif->dma_master + 0x77);
  829. }
  830. /**
  831. * hpt3xxn_rw_disk - prepare for I/O
  832. * @drive: drive for command
  833. * @rq: block request structure
  834. *
  835. * This is called when a disk I/O is issued to HPT3xxN.
  836. * We need it because of the clock switching.
  837. */
  838. static void hpt3xxn_rw_disk(ide_drive_t *drive, struct request *rq)
  839. {
  840. hpt3xxn_set_clock(HWIF(drive), rq_data_dir(rq) ? 0x23 : 0x21);
  841. }
  842. /*
  843. * Set/get power state for a drive.
  844. * NOTE: affects both drives on each channel.
  845. *
  846. * When we turn the power back on, we need to re-initialize things.
  847. */
  848. #define TRISTATE_BIT 0x8000
  849. static int hpt3xx_busproc(ide_drive_t *drive, int state)
  850. {
  851. ide_hwif_t *hwif = HWIF(drive);
  852. struct pci_dev *dev = hwif->pci_dev;
  853. u8 mcr_addr = hwif->select_data + 2;
  854. u8 resetmask = hwif->channel ? 0x80 : 0x40;
  855. u8 bsr2 = 0;
  856. u16 mcr = 0;
  857. hwif->bus_state = state;
  858. /* Grab the status. */
  859. pci_read_config_word(dev, mcr_addr, &mcr);
  860. pci_read_config_byte(dev, 0x59, &bsr2);
  861. /*
  862. * Set the state. We don't set it if we don't need to do so.
  863. * Make sure that the drive knows that it has failed if it's off.
  864. */
  865. switch (state) {
  866. case BUSSTATE_ON:
  867. if (!(bsr2 & resetmask))
  868. return 0;
  869. hwif->drives[0].failures = hwif->drives[1].failures = 0;
  870. pci_write_config_byte(dev, 0x59, bsr2 & ~resetmask);
  871. pci_write_config_word(dev, mcr_addr, mcr & ~TRISTATE_BIT);
  872. return 0;
  873. case BUSSTATE_OFF:
  874. if ((bsr2 & resetmask) && !(mcr & TRISTATE_BIT))
  875. return 0;
  876. mcr &= ~TRISTATE_BIT;
  877. break;
  878. case BUSSTATE_TRISTATE:
  879. if ((bsr2 & resetmask) && (mcr & TRISTATE_BIT))
  880. return 0;
  881. mcr |= TRISTATE_BIT;
  882. break;
  883. default:
  884. return -EINVAL;
  885. }
  886. hwif->drives[0].failures = hwif->drives[0].max_failures + 1;
  887. hwif->drives[1].failures = hwif->drives[1].max_failures + 1;
  888. pci_write_config_word(dev, mcr_addr, mcr);
  889. pci_write_config_byte(dev, 0x59, bsr2 | resetmask);
  890. return 0;
  891. }
  892. /**
  893. * hpt37x_calibrate_dpll - calibrate the DPLL
  894. * @dev: PCI device
  895. *
  896. * Perform a calibration cycle on the DPLL.
  897. * Returns 1 if this succeeds
  898. */
  899. static int __devinit hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 f_high)
  900. {
  901. u32 dpll = (f_high << 16) | f_low | 0x100;
  902. u8 scr2;
  903. int i;
  904. pci_write_config_dword(dev, 0x5c, dpll);
  905. /* Wait for oscillator ready */
  906. for(i = 0; i < 0x5000; ++i) {
  907. udelay(50);
  908. pci_read_config_byte(dev, 0x5b, &scr2);
  909. if (scr2 & 0x80)
  910. break;
  911. }
  912. /* See if it stays ready (we'll just bail out if it's not yet) */
  913. for(i = 0; i < 0x1000; ++i) {
  914. pci_read_config_byte(dev, 0x5b, &scr2);
  915. /* DPLL destabilized? */
  916. if(!(scr2 & 0x80))
  917. return 0;
  918. }
  919. /* Turn off tuning, we have the DPLL set */
  920. pci_read_config_dword (dev, 0x5c, &dpll);
  921. pci_write_config_dword(dev, 0x5c, (dpll & ~0x100));
  922. return 1;
  923. }
  924. static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name)
  925. {
  926. struct hpt_info *info = kmalloc(sizeof(struct hpt_info), GFP_KERNEL);
  927. unsigned long io_base = pci_resource_start(dev, 4);
  928. u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */
  929. u8 chip_type;
  930. enum ata_clock clock;
  931. if (info == NULL) {
  932. printk(KERN_ERR "%s: out of memory!\n", name);
  933. return -ENOMEM;
  934. }
  935. /*
  936. * Copy everything from a static "template" structure
  937. * to just allocated per-chip hpt_info structure.
  938. */
  939. memcpy(info, pci_get_drvdata(dev), sizeof(struct hpt_info));
  940. chip_type = info->chip_type;
  941. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
  942. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
  943. pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
  944. pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
  945. /*
  946. * First, try to estimate the PCI clock frequency...
  947. */
  948. if (chip_type >= HPT370) {
  949. u8 scr1 = 0;
  950. u16 f_cnt = 0;
  951. u32 temp = 0;
  952. /* Interrupt force enable. */
  953. pci_read_config_byte(dev, 0x5a, &scr1);
  954. if (scr1 & 0x10)
  955. pci_write_config_byte(dev, 0x5a, scr1 & ~0x10);
  956. /*
  957. * HighPoint does this for HPT372A.
  958. * NOTE: This register is only writeable via I/O space.
  959. */
  960. if (chip_type == HPT372A)
  961. outb(0x0e, io_base + 0x9c);
  962. /*
  963. * Default to PCI clock. Make sure MA15/16 are set to output
  964. * to prevent drives having problems with 40-pin cables.
  965. */
  966. pci_write_config_byte(dev, 0x5b, 0x23);
  967. /*
  968. * We'll have to read f_CNT value in order to determine
  969. * the PCI clock frequency according to the following ratio:
  970. *
  971. * f_CNT = Fpci * 192 / Fdpll
  972. *
  973. * First try reading the register in which the HighPoint BIOS
  974. * saves f_CNT value before reprogramming the DPLL from its
  975. * default setting (which differs for the various chips).
  976. *
  977. * NOTE: This register is only accessible via I/O space;
  978. * HPT374 BIOS only saves it for the function 0, so we have to
  979. * always read it from there -- no need to check the result of
  980. * pci_get_slot() for the function 0 as the whole device has
  981. * been already "pinned" (via function 1) in init_setup_hpt374()
  982. */
  983. if (chip_type == HPT374 && (PCI_FUNC(dev->devfn) & 1)) {
  984. struct pci_dev *dev1 = pci_get_slot(dev->bus,
  985. dev->devfn - 1);
  986. unsigned long io_base = pci_resource_start(dev1, 4);
  987. temp = inl(io_base + 0x90);
  988. pci_dev_put(dev1);
  989. } else
  990. temp = inl(io_base + 0x90);
  991. /*
  992. * In case the signature check fails, we'll have to
  993. * resort to reading the f_CNT register itself in hopes
  994. * that nobody has touched the DPLL yet...
  995. */
  996. if ((temp & 0xFFFFF000) != 0xABCDE000) {
  997. int i;
  998. printk(KERN_WARNING "%s: no clock data saved by BIOS\n",
  999. name);
  1000. /* Calculate the average value of f_CNT. */
  1001. for (temp = i = 0; i < 128; i++) {
  1002. pci_read_config_word(dev, 0x78, &f_cnt);
  1003. temp += f_cnt & 0x1ff;
  1004. mdelay(1);
  1005. }
  1006. f_cnt = temp / 128;
  1007. } else
  1008. f_cnt = temp & 0x1ff;
  1009. dpll_clk = info->dpll_clk;
  1010. pci_clk = (f_cnt * dpll_clk) / 192;
  1011. /* Clamp PCI clock to bands. */
  1012. if (pci_clk < 40)
  1013. pci_clk = 33;
  1014. else if(pci_clk < 45)
  1015. pci_clk = 40;
  1016. else if(pci_clk < 55)
  1017. pci_clk = 50;
  1018. else
  1019. pci_clk = 66;
  1020. printk(KERN_INFO "%s: DPLL base: %d MHz, f_CNT: %d, "
  1021. "assuming %d MHz PCI\n", name, dpll_clk, f_cnt, pci_clk);
  1022. } else {
  1023. u32 itr1 = 0;
  1024. pci_read_config_dword(dev, 0x40, &itr1);
  1025. /* Detect PCI clock by looking at cmd_high_time. */
  1026. switch((itr1 >> 8) & 0x07) {
  1027. case 0x09:
  1028. pci_clk = 40;
  1029. break;
  1030. case 0x05:
  1031. pci_clk = 25;
  1032. break;
  1033. case 0x07:
  1034. default:
  1035. pci_clk = 33;
  1036. break;
  1037. }
  1038. }
  1039. /* Let's assume we'll use PCI clock for the ATA clock... */
  1040. switch (pci_clk) {
  1041. case 25:
  1042. clock = ATA_CLOCK_25MHZ;
  1043. break;
  1044. case 33:
  1045. default:
  1046. clock = ATA_CLOCK_33MHZ;
  1047. break;
  1048. case 40:
  1049. clock = ATA_CLOCK_40MHZ;
  1050. break;
  1051. case 50:
  1052. clock = ATA_CLOCK_50MHZ;
  1053. break;
  1054. case 66:
  1055. clock = ATA_CLOCK_66MHZ;
  1056. break;
  1057. }
  1058. /*
  1059. * Only try the DPLL if we don't have a table for the PCI clock that
  1060. * we are running at for HPT370/A, always use it for anything newer...
  1061. *
  1062. * NOTE: Using the internal DPLL results in slow reads on 33 MHz PCI.
  1063. * We also don't like using the DPLL because this causes glitches
  1064. * on PRST-/SRST- when the state engine gets reset...
  1065. */
  1066. if (chip_type >= HPT374 || info->settings[clock] == NULL) {
  1067. u16 f_low, delta = pci_clk < 50 ? 2 : 4;
  1068. int adjust;
  1069. /*
  1070. * Select 66 MHz DPLL clock only if UltraATA/133 mode is
  1071. * supported/enabled, use 50 MHz DPLL clock otherwise...
  1072. */
  1073. if (info->udma_mask == ATA_UDMA6) {
  1074. dpll_clk = 66;
  1075. clock = ATA_CLOCK_66MHZ;
  1076. } else if (dpll_clk) { /* HPT36x chips don't have DPLL */
  1077. dpll_clk = 50;
  1078. clock = ATA_CLOCK_50MHZ;
  1079. }
  1080. if (info->settings[clock] == NULL) {
  1081. printk(KERN_ERR "%s: unknown bus timing!\n", name);
  1082. kfree(info);
  1083. return -EIO;
  1084. }
  1085. /* Select the DPLL clock. */
  1086. pci_write_config_byte(dev, 0x5b, 0x21);
  1087. /*
  1088. * Adjust the DPLL based upon PCI clock, enable it,
  1089. * and wait for stabilization...
  1090. */
  1091. f_low = (pci_clk * 48) / dpll_clk;
  1092. for (adjust = 0; adjust < 8; adjust++) {
  1093. if(hpt37x_calibrate_dpll(dev, f_low, f_low + delta))
  1094. break;
  1095. /*
  1096. * See if it'll settle at a fractionally different clock
  1097. */
  1098. if (adjust & 1)
  1099. f_low -= adjust >> 1;
  1100. else
  1101. f_low += adjust >> 1;
  1102. }
  1103. if (adjust == 8) {
  1104. printk(KERN_ERR "%s: DPLL did not stabilize!\n", name);
  1105. kfree(info);
  1106. return -EIO;
  1107. }
  1108. printk("%s: using %d MHz DPLL clock\n", name, dpll_clk);
  1109. } else {
  1110. /* Mark the fact that we're not using the DPLL. */
  1111. dpll_clk = 0;
  1112. printk("%s: using %d MHz PCI clock\n", name, pci_clk);
  1113. }
  1114. /*
  1115. * Advance the table pointer to a slot which points to the list
  1116. * of the register values settings matching the clock being used.
  1117. */
  1118. info->settings += clock;
  1119. /* Store the clock frequencies. */
  1120. info->dpll_clk = dpll_clk;
  1121. info->pci_clk = pci_clk;
  1122. /* Point to this chip's own instance of the hpt_info structure. */
  1123. pci_set_drvdata(dev, info);
  1124. if (chip_type >= HPT370) {
  1125. u8 mcr1, mcr4;
  1126. /*
  1127. * Reset the state engines.
  1128. * NOTE: Avoid accidentally enabling the disabled channels.
  1129. */
  1130. pci_read_config_byte (dev, 0x50, &mcr1);
  1131. pci_read_config_byte (dev, 0x54, &mcr4);
  1132. pci_write_config_byte(dev, 0x50, (mcr1 | 0x32));
  1133. pci_write_config_byte(dev, 0x54, (mcr4 | 0x32));
  1134. udelay(100);
  1135. }
  1136. /*
  1137. * On HPT371N, if ATA clock is 66 MHz we must set bit 2 in
  1138. * the MISC. register to stretch the UltraDMA Tss timing.
  1139. * NOTE: This register is only writeable via I/O space.
  1140. */
  1141. if (chip_type == HPT371N && clock == ATA_CLOCK_66MHZ)
  1142. outb(inb(io_base + 0x9c) | 0x04, io_base + 0x9c);
  1143. return dev->irq;
  1144. }
  1145. static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
  1146. {
  1147. struct pci_dev *dev = hwif->pci_dev;
  1148. struct hpt_info *info = pci_get_drvdata(dev);
  1149. int serialize = HPT_SERIALIZE_IO;
  1150. u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02;
  1151. u8 chip_type = info->chip_type;
  1152. u8 new_mcr, old_mcr = 0;
  1153. /* Cache the channel's MISC. control registers' offset */
  1154. hwif->select_data = hwif->channel ? 0x54 : 0x50;
  1155. hwif->set_pio_mode = &hpt3xx_set_pio_mode;
  1156. hwif->set_dma_mode = &hpt3xx_set_mode;
  1157. hwif->quirkproc = &hpt3xx_quirkproc;
  1158. hwif->intrproc = &hpt3xx_intrproc;
  1159. hwif->maskproc = &hpt3xx_maskproc;
  1160. hwif->busproc = &hpt3xx_busproc;
  1161. hwif->udma_filter = &hpt3xx_udma_filter;
  1162. hwif->mdma_filter = &hpt3xx_mdma_filter;
  1163. /*
  1164. * HPT3xxN chips have some complications:
  1165. *
  1166. * - on 33 MHz PCI we must clock switch
  1167. * - on 66 MHz PCI we must NOT use the PCI clock
  1168. */
  1169. if (chip_type >= HPT372N && info->dpll_clk && info->pci_clk < 66) {
  1170. /*
  1171. * Clock is shared between the channels,
  1172. * so we'll have to serialize them... :-(
  1173. */
  1174. serialize = 1;
  1175. hwif->rw_disk = &hpt3xxn_rw_disk;
  1176. }
  1177. /* Serialize access to this device if needed */
  1178. if (serialize && hwif->mate)
  1179. hwif->serialized = hwif->mate->serialized = 1;
  1180. /*
  1181. * Disable the "fast interrupt" prediction. Don't hold off
  1182. * on interrupts. (== 0x01 despite what the docs say)
  1183. */
  1184. pci_read_config_byte(dev, hwif->select_data + 1, &old_mcr);
  1185. if (info->chip_type >= HPT374)
  1186. new_mcr = old_mcr & ~0x07;
  1187. else if (info->chip_type >= HPT370) {
  1188. new_mcr = old_mcr;
  1189. new_mcr &= ~0x02;
  1190. #ifdef HPT_DELAY_INTERRUPT
  1191. new_mcr &= ~0x01;
  1192. #else
  1193. new_mcr |= 0x01;
  1194. #endif
  1195. } else /* HPT366 and HPT368 */
  1196. new_mcr = old_mcr & ~0x80;
  1197. if (new_mcr != old_mcr)
  1198. pci_write_config_byte(dev, hwif->select_data + 1, new_mcr);
  1199. if (hwif->dma_base == 0)
  1200. return;
  1201. /*
  1202. * The HPT37x uses the CBLID pins as outputs for MA15/MA16
  1203. * address lines to access an external EEPROM. To read valid
  1204. * cable detect state the pins must be enabled as inputs.
  1205. */
  1206. if (chip_type == HPT374 && (PCI_FUNC(dev->devfn) & 1)) {
  1207. /*
  1208. * HPT374 PCI function 1
  1209. * - set bit 15 of reg 0x52 to enable TCBLID as input
  1210. * - set bit 15 of reg 0x56 to enable FCBLID as input
  1211. */
  1212. u8 mcr_addr = hwif->select_data + 2;
  1213. u16 mcr;
  1214. pci_read_config_word (dev, mcr_addr, &mcr);
  1215. pci_write_config_word(dev, mcr_addr, (mcr | 0x8000));
  1216. /* now read cable id register */
  1217. pci_read_config_byte (dev, 0x5a, &scr1);
  1218. pci_write_config_word(dev, mcr_addr, mcr);
  1219. } else if (chip_type >= HPT370) {
  1220. /*
  1221. * HPT370/372 and 374 pcifn 0
  1222. * - clear bit 0 of reg 0x5b to enable P/SCBLID as inputs
  1223. */
  1224. u8 scr2 = 0;
  1225. pci_read_config_byte (dev, 0x5b, &scr2);
  1226. pci_write_config_byte(dev, 0x5b, (scr2 & ~1));
  1227. /* now read cable id register */
  1228. pci_read_config_byte (dev, 0x5a, &scr1);
  1229. pci_write_config_byte(dev, 0x5b, scr2);
  1230. } else
  1231. pci_read_config_byte (dev, 0x5a, &scr1);
  1232. if (hwif->cbl != ATA_CBL_PATA40_SHORT)
  1233. hwif->cbl = (scr1 & ata66) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
  1234. if (chip_type >= HPT374) {
  1235. hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;
  1236. hwif->ide_dma_end = &hpt374_ide_dma_end;
  1237. } else if (chip_type >= HPT370) {
  1238. hwif->dma_start = &hpt370_ide_dma_start;
  1239. hwif->ide_dma_end = &hpt370_ide_dma_end;
  1240. hwif->dma_timeout = &hpt370_dma_timeout;
  1241. } else
  1242. hwif->dma_lost_irq = &hpt366_dma_lost_irq;
  1243. }
  1244. static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
  1245. {
  1246. struct pci_dev *dev = hwif->pci_dev;
  1247. u8 masterdma = 0, slavedma = 0;
  1248. u8 dma_new = 0, dma_old = 0;
  1249. unsigned long flags;
  1250. dma_old = inb(dmabase + 2);
  1251. local_irq_save(flags);
  1252. dma_new = dma_old;
  1253. pci_read_config_byte(dev, hwif->channel ? 0x4b : 0x43, &masterdma);
  1254. pci_read_config_byte(dev, hwif->channel ? 0x4f : 0x47, &slavedma);
  1255. if (masterdma & 0x30) dma_new |= 0x20;
  1256. if ( slavedma & 0x30) dma_new |= 0x40;
  1257. if (dma_new != dma_old)
  1258. outb(dma_new, dmabase + 2);
  1259. local_irq_restore(flags);
  1260. ide_setup_dma(hwif, dmabase, 8);
  1261. }
  1262. static void __devinit hpt374_init(struct pci_dev *dev, struct pci_dev *dev2)
  1263. {
  1264. if (dev2->irq != dev->irq) {
  1265. /* FIXME: we need a core pci_set_interrupt() */
  1266. dev2->irq = dev->irq;
  1267. printk(KERN_INFO "HPT374: PCI config space interrupt fixed\n");
  1268. }
  1269. }
  1270. static void __devinit hpt371_init(struct pci_dev *dev)
  1271. {
  1272. u8 mcr1 = 0;
  1273. /*
  1274. * HPT371 chips physically have only one channel, the secondary one,
  1275. * but the primary channel registers do exist! Go figure...
  1276. * So, we manually disable the non-existing channel here
  1277. * (if the BIOS hasn't done this already).
  1278. */
  1279. pci_read_config_byte(dev, 0x50, &mcr1);
  1280. if (mcr1 & 0x04)
  1281. pci_write_config_byte(dev, 0x50, mcr1 & ~0x04);
  1282. }
  1283. static int __devinit hpt36x_init(struct pci_dev *dev, struct pci_dev *dev2)
  1284. {
  1285. u8 mcr1 = 0, pin1 = 0, pin2 = 0;
  1286. /*
  1287. * Now we'll have to force both channels enabled if
  1288. * at least one of them has been enabled by BIOS...
  1289. */
  1290. pci_read_config_byte(dev, 0x50, &mcr1);
  1291. if (mcr1 & 0x30)
  1292. pci_write_config_byte(dev, 0x50, mcr1 | 0x30);
  1293. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin1);
  1294. pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &pin2);
  1295. if (pin1 != pin2 && dev->irq == dev2->irq) {
  1296. printk(KERN_INFO "HPT36x: onboard version of chipset, "
  1297. "pin1=%d pin2=%d\n", pin1, pin2);
  1298. return 1;
  1299. }
  1300. return 0;
  1301. }
  1302. static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
  1303. { /* 0 */
  1304. .name = "HPT36x",
  1305. .init_chipset = init_chipset_hpt366,
  1306. .init_hwif = init_hwif_hpt366,
  1307. .init_dma = init_dma_hpt366,
  1308. /*
  1309. * HPT36x chips have one channel per function and have
  1310. * both channel enable bits located differently and visible
  1311. * to both functions -- really stupid design decision... :-(
  1312. * Bit 4 is for the primary channel, bit 5 for the secondary.
  1313. */
  1314. .enablebits = {{0x50,0x10,0x10}, {0x54,0x04,0x04}},
  1315. .extra = 240,
  1316. .host_flags = IDE_HFLAG_SINGLE |
  1317. IDE_HFLAG_NO_ATAPI_DMA |
  1318. IDE_HFLAG_OFF_BOARD,
  1319. .pio_mask = ATA_PIO4,
  1320. .mwdma_mask = ATA_MWDMA2,
  1321. },{ /* 1 */
  1322. .name = "HPT372A",
  1323. .init_chipset = init_chipset_hpt366,
  1324. .init_hwif = init_hwif_hpt366,
  1325. .init_dma = init_dma_hpt366,
  1326. .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
  1327. .extra = 240,
  1328. .host_flags = IDE_HFLAG_NO_ATAPI_DMA | IDE_HFLAG_OFF_BOARD,
  1329. .pio_mask = ATA_PIO4,
  1330. .mwdma_mask = ATA_MWDMA2,
  1331. },{ /* 2 */
  1332. .name = "HPT302",
  1333. .init_chipset = init_chipset_hpt366,
  1334. .init_hwif = init_hwif_hpt366,
  1335. .init_dma = init_dma_hpt366,
  1336. .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
  1337. .extra = 240,
  1338. .host_flags = IDE_HFLAG_NO_ATAPI_DMA | IDE_HFLAG_OFF_BOARD,
  1339. .pio_mask = ATA_PIO4,
  1340. .mwdma_mask = ATA_MWDMA2,
  1341. },{ /* 3 */
  1342. .name = "HPT371",
  1343. .init_chipset = init_chipset_hpt366,
  1344. .init_hwif = init_hwif_hpt366,
  1345. .init_dma = init_dma_hpt366,
  1346. .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
  1347. .extra = 240,
  1348. .host_flags = IDE_HFLAG_NO_ATAPI_DMA | IDE_HFLAG_OFF_BOARD,
  1349. .pio_mask = ATA_PIO4,
  1350. .mwdma_mask = ATA_MWDMA2,
  1351. },{ /* 4 */
  1352. .name = "HPT374",
  1353. .init_chipset = init_chipset_hpt366,
  1354. .init_hwif = init_hwif_hpt366,
  1355. .init_dma = init_dma_hpt366,
  1356. .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
  1357. .udma_mask = ATA_UDMA5,
  1358. .extra = 240,
  1359. .host_flags = IDE_HFLAG_NO_ATAPI_DMA | IDE_HFLAG_OFF_BOARD,
  1360. .pio_mask = ATA_PIO4,
  1361. .mwdma_mask = ATA_MWDMA2,
  1362. },{ /* 5 */
  1363. .name = "HPT372N",
  1364. .init_chipset = init_chipset_hpt366,
  1365. .init_hwif = init_hwif_hpt366,
  1366. .init_dma = init_dma_hpt366,
  1367. .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
  1368. .extra = 240,
  1369. .host_flags = IDE_HFLAG_NO_ATAPI_DMA | IDE_HFLAG_OFF_BOARD,
  1370. .pio_mask = ATA_PIO4,
  1371. .mwdma_mask = ATA_MWDMA2,
  1372. }
  1373. };
  1374. /**
  1375. * hpt366_init_one - called when an HPT366 is found
  1376. * @dev: the hpt366 device
  1377. * @id: the matching pci id
  1378. *
  1379. * Called when the PCI registration layer (or the IDE initialization)
  1380. * finds a device matching our IDE device tables.
  1381. */
  1382. static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  1383. {
  1384. const struct hpt_info *info = NULL;
  1385. struct pci_dev *dev2 = NULL;
  1386. struct ide_port_info d;
  1387. u8 idx = id->driver_data;
  1388. u8 rev = dev->revision;
  1389. if ((idx == 0 || idx == 4) && (PCI_FUNC(dev->devfn) & 1))
  1390. return -ENODEV;
  1391. switch (idx) {
  1392. case 0:
  1393. if (rev < 3)
  1394. info = &hpt36x;
  1395. else {
  1396. static const struct hpt_info *hpt37x_info[] =
  1397. { &hpt370, &hpt370a, &hpt372, &hpt372n };
  1398. info = hpt37x_info[min_t(u8, rev, 6) - 3];
  1399. idx++;
  1400. }
  1401. break;
  1402. case 1:
  1403. info = (rev > 1) ? &hpt372n : &hpt372a;
  1404. break;
  1405. case 2:
  1406. info = (rev > 1) ? &hpt302n : &hpt302;
  1407. break;
  1408. case 3:
  1409. hpt371_init(dev);
  1410. info = (rev > 1) ? &hpt371n : &hpt371;
  1411. break;
  1412. case 4:
  1413. info = &hpt374;
  1414. break;
  1415. case 5:
  1416. info = &hpt372n;
  1417. break;
  1418. }
  1419. d = hpt366_chipsets[idx];
  1420. d.name = info->chip_name;
  1421. d.udma_mask = info->udma_mask;
  1422. pci_set_drvdata(dev, (void *)info);
  1423. if (info == &hpt36x || info == &hpt374)
  1424. dev2 = pci_get_slot(dev->bus, dev->devfn + 1);
  1425. if (dev2) {
  1426. int ret;
  1427. pci_set_drvdata(dev2, (void *)info);
  1428. if (info == &hpt374)
  1429. hpt374_init(dev, dev2);
  1430. else {
  1431. if (hpt36x_init(dev, dev2))
  1432. d.host_flags |= IDE_HFLAG_BOOTABLE;
  1433. }
  1434. ret = ide_setup_pci_devices(dev, dev2, &d);
  1435. if (ret < 0)
  1436. pci_dev_put(dev2);
  1437. return ret;
  1438. }
  1439. return ide_setup_pci_device(dev, &d);
  1440. }
  1441. static const struct pci_device_id hpt366_pci_tbl[] = {
  1442. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT366), 0 },
  1443. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT372), 1 },
  1444. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT302), 2 },
  1445. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT371), 3 },
  1446. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT374), 4 },
  1447. { PCI_VDEVICE(TTI, PCI_DEVICE_ID_TTI_HPT372N), 5 },
  1448. { 0, },
  1449. };
  1450. MODULE_DEVICE_TABLE(pci, hpt366_pci_tbl);
  1451. static struct pci_driver driver = {
  1452. .name = "HPT366_IDE",
  1453. .id_table = hpt366_pci_tbl,
  1454. .probe = hpt366_init_one,
  1455. };
  1456. static int __init hpt366_ide_init(void)
  1457. {
  1458. return ide_pci_register_driver(&driver);
  1459. }
  1460. module_init(hpt366_ide_init);
  1461. MODULE_AUTHOR("Andre Hedrick");
  1462. MODULE_DESCRIPTION("PCI driver module for Highpoint HPT366 IDE");
  1463. MODULE_LICENSE("GPL");