hpt366.c 44 KB

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