hw.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135
  1. /*
  2. * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
  3. * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License as published by the Free Software Foundation;
  7. * either version 2, or (at your option) any later version.
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
  10. * the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. * A PARTICULAR PURPOSE.See the GNU General Public License
  12. * for more details.
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <linux/via-core.h>
  19. #include <asm/olpc.h>
  20. #include "global.h"
  21. #include "via_clock.h"
  22. static struct pll_limit cle266_pll_limits[] = {
  23. {19, 19, 4, 0},
  24. {26, 102, 5, 0},
  25. {53, 112, 6, 0},
  26. {41, 100, 7, 0},
  27. {83, 108, 8, 0},
  28. {87, 118, 9, 0},
  29. {95, 115, 12, 0},
  30. {108, 108, 13, 0},
  31. {83, 83, 17, 0},
  32. {67, 98, 20, 0},
  33. {121, 121, 24, 0},
  34. {99, 99, 29, 0},
  35. {33, 33, 3, 1},
  36. {15, 23, 4, 1},
  37. {37, 121, 5, 1},
  38. {82, 82, 6, 1},
  39. {31, 84, 7, 1},
  40. {83, 83, 8, 1},
  41. {76, 127, 9, 1},
  42. {33, 121, 4, 2},
  43. {91, 118, 5, 2},
  44. {83, 109, 6, 2},
  45. {90, 90, 7, 2},
  46. {93, 93, 2, 3},
  47. {53, 53, 3, 3},
  48. {73, 117, 4, 3},
  49. {101, 127, 5, 3},
  50. {99, 99, 7, 3}
  51. };
  52. static struct pll_limit k800_pll_limits[] = {
  53. {22, 22, 2, 0},
  54. {28, 28, 3, 0},
  55. {81, 112, 3, 1},
  56. {86, 166, 4, 1},
  57. {109, 153, 5, 1},
  58. {66, 116, 3, 2},
  59. {93, 137, 4, 2},
  60. {117, 208, 5, 2},
  61. {30, 30, 2, 3},
  62. {69, 125, 3, 3},
  63. {89, 161, 4, 3},
  64. {121, 208, 5, 3},
  65. {66, 66, 2, 4},
  66. {85, 85, 3, 4},
  67. {141, 161, 4, 4},
  68. {177, 177, 5, 4}
  69. };
  70. static struct pll_limit cx700_pll_limits[] = {
  71. {98, 98, 3, 1},
  72. {86, 86, 4, 1},
  73. {109, 208, 5, 1},
  74. {68, 68, 2, 2},
  75. {95, 116, 3, 2},
  76. {93, 166, 4, 2},
  77. {110, 206, 5, 2},
  78. {174, 174, 7, 2},
  79. {82, 109, 3, 3},
  80. {117, 161, 4, 3},
  81. {112, 208, 5, 3},
  82. {141, 202, 5, 4}
  83. };
  84. static struct pll_limit vx855_pll_limits[] = {
  85. {86, 86, 4, 1},
  86. {108, 208, 5, 1},
  87. {110, 208, 5, 2},
  88. {83, 112, 3, 3},
  89. {103, 161, 4, 3},
  90. {112, 209, 5, 3},
  91. {142, 161, 4, 4},
  92. {141, 176, 5, 4}
  93. };
  94. /* according to VIA Technologies these values are based on experiment */
  95. static struct io_reg scaling_parameters[] = {
  96. {VIACR, CR7A, 0xFF, 0x01}, /* LCD Scaling Parameter 1 */
  97. {VIACR, CR7B, 0xFF, 0x02}, /* LCD Scaling Parameter 2 */
  98. {VIACR, CR7C, 0xFF, 0x03}, /* LCD Scaling Parameter 3 */
  99. {VIACR, CR7D, 0xFF, 0x04}, /* LCD Scaling Parameter 4 */
  100. {VIACR, CR7E, 0xFF, 0x07}, /* LCD Scaling Parameter 5 */
  101. {VIACR, CR7F, 0xFF, 0x0A}, /* LCD Scaling Parameter 6 */
  102. {VIACR, CR80, 0xFF, 0x0D}, /* LCD Scaling Parameter 7 */
  103. {VIACR, CR81, 0xFF, 0x13}, /* LCD Scaling Parameter 8 */
  104. {VIACR, CR82, 0xFF, 0x16}, /* LCD Scaling Parameter 9 */
  105. {VIACR, CR83, 0xFF, 0x19}, /* LCD Scaling Parameter 10 */
  106. {VIACR, CR84, 0xFF, 0x1C}, /* LCD Scaling Parameter 11 */
  107. {VIACR, CR85, 0xFF, 0x1D}, /* LCD Scaling Parameter 12 */
  108. {VIACR, CR86, 0xFF, 0x1E}, /* LCD Scaling Parameter 13 */
  109. {VIACR, CR87, 0xFF, 0x1F}, /* LCD Scaling Parameter 14 */
  110. };
  111. static struct io_reg common_vga[] = {
  112. {VIACR, CR07, 0x10, 0x10}, /* [0] vertical total (bit 8)
  113. [1] vertical display end (bit 8)
  114. [2] vertical retrace start (bit 8)
  115. [3] start vertical blanking (bit 8)
  116. [4] line compare (bit 8)
  117. [5] vertical total (bit 9)
  118. [6] vertical display end (bit 9)
  119. [7] vertical retrace start (bit 9) */
  120. {VIACR, CR08, 0xFF, 0x00}, /* [0-4] preset row scan
  121. [5-6] byte panning */
  122. {VIACR, CR09, 0xDF, 0x40}, /* [0-4] max scan line
  123. [5] start vertical blanking (bit 9)
  124. [6] line compare (bit 9)
  125. [7] scan doubling */
  126. {VIACR, CR0A, 0xFF, 0x1E}, /* [0-4] cursor start
  127. [5] cursor disable */
  128. {VIACR, CR0B, 0xFF, 0x00}, /* [0-4] cursor end
  129. [5-6] cursor skew */
  130. {VIACR, CR0E, 0xFF, 0x00}, /* [0-7] cursor location (high) */
  131. {VIACR, CR0F, 0xFF, 0x00}, /* [0-7] cursor location (low) */
  132. {VIACR, CR11, 0xF0, 0x80}, /* [0-3] vertical retrace end
  133. [6] memory refresh bandwidth
  134. [7] CRTC register protect enable */
  135. {VIACR, CR14, 0xFF, 0x00}, /* [0-4] underline location
  136. [5] divide memory address clock by 4
  137. [6] double word addressing */
  138. {VIACR, CR17, 0xFF, 0x63}, /* [0-1] mapping of display address 13-14
  139. [2] divide scan line clock by 2
  140. [3] divide memory address clock by 2
  141. [5] address wrap
  142. [6] byte mode select
  143. [7] sync enable */
  144. {VIACR, CR18, 0xFF, 0xFF}, /* [0-7] line compare */
  145. };
  146. static struct fifo_depth_select display_fifo_depth_reg = {
  147. /* IGA1 FIFO Depth_Select */
  148. {IGA1_FIFO_DEPTH_SELECT_REG_NUM, {{SR17, 0, 7} } },
  149. /* IGA2 FIFO Depth_Select */
  150. {IGA2_FIFO_DEPTH_SELECT_REG_NUM,
  151. {{CR68, 4, 7}, {CR94, 7, 7}, {CR95, 7, 7} } }
  152. };
  153. static struct fifo_threshold_select fifo_threshold_select_reg = {
  154. /* IGA1 FIFO Threshold Select */
  155. {IGA1_FIFO_THRESHOLD_REG_NUM, {{SR16, 0, 5}, {SR16, 7, 7} } },
  156. /* IGA2 FIFO Threshold Select */
  157. {IGA2_FIFO_THRESHOLD_REG_NUM, {{CR68, 0, 3}, {CR95, 4, 6} } }
  158. };
  159. static struct fifo_high_threshold_select fifo_high_threshold_select_reg = {
  160. /* IGA1 FIFO High Threshold Select */
  161. {IGA1_FIFO_HIGH_THRESHOLD_REG_NUM, {{SR18, 0, 5}, {SR18, 7, 7} } },
  162. /* IGA2 FIFO High Threshold Select */
  163. {IGA2_FIFO_HIGH_THRESHOLD_REG_NUM, {{CR92, 0, 3}, {CR95, 0, 2} } }
  164. };
  165. static struct display_queue_expire_num display_queue_expire_num_reg = {
  166. /* IGA1 Display Queue Expire Num */
  167. {IGA1_DISPLAY_QUEUE_EXPIRE_NUM_REG_NUM, {{SR22, 0, 4} } },
  168. /* IGA2 Display Queue Expire Num */
  169. {IGA2_DISPLAY_QUEUE_EXPIRE_NUM_REG_NUM, {{CR94, 0, 6} } }
  170. };
  171. /* Definition Fetch Count Registers*/
  172. static struct fetch_count fetch_count_reg = {
  173. /* IGA1 Fetch Count Register */
  174. {IGA1_FETCH_COUNT_REG_NUM, {{SR1C, 0, 7}, {SR1D, 0, 1} } },
  175. /* IGA2 Fetch Count Register */
  176. {IGA2_FETCH_COUNT_REG_NUM, {{CR65, 0, 7}, {CR67, 2, 3} } }
  177. };
  178. static struct rgbLUT palLUT_table[] = {
  179. /* {R,G,B} */
  180. /* Index 0x00~0x03 */
  181. {0x00, 0x00, 0x00}, {0x00, 0x00, 0x2A}, {0x00, 0x2A, 0x00}, {0x00,
  182. 0x2A,
  183. 0x2A},
  184. /* Index 0x04~0x07 */
  185. {0x2A, 0x00, 0x00}, {0x2A, 0x00, 0x2A}, {0x2A, 0x15, 0x00}, {0x2A,
  186. 0x2A,
  187. 0x2A},
  188. /* Index 0x08~0x0B */
  189. {0x15, 0x15, 0x15}, {0x15, 0x15, 0x3F}, {0x15, 0x3F, 0x15}, {0x15,
  190. 0x3F,
  191. 0x3F},
  192. /* Index 0x0C~0x0F */
  193. {0x3F, 0x15, 0x15}, {0x3F, 0x15, 0x3F}, {0x3F, 0x3F, 0x15}, {0x3F,
  194. 0x3F,
  195. 0x3F},
  196. /* Index 0x10~0x13 */
  197. {0x00, 0x00, 0x00}, {0x05, 0x05, 0x05}, {0x08, 0x08, 0x08}, {0x0B,
  198. 0x0B,
  199. 0x0B},
  200. /* Index 0x14~0x17 */
  201. {0x0E, 0x0E, 0x0E}, {0x11, 0x11, 0x11}, {0x14, 0x14, 0x14}, {0x18,
  202. 0x18,
  203. 0x18},
  204. /* Index 0x18~0x1B */
  205. {0x1C, 0x1C, 0x1C}, {0x20, 0x20, 0x20}, {0x24, 0x24, 0x24}, {0x28,
  206. 0x28,
  207. 0x28},
  208. /* Index 0x1C~0x1F */
  209. {0x2D, 0x2D, 0x2D}, {0x32, 0x32, 0x32}, {0x38, 0x38, 0x38}, {0x3F,
  210. 0x3F,
  211. 0x3F},
  212. /* Index 0x20~0x23 */
  213. {0x00, 0x00, 0x3F}, {0x10, 0x00, 0x3F}, {0x1F, 0x00, 0x3F}, {0x2F,
  214. 0x00,
  215. 0x3F},
  216. /* Index 0x24~0x27 */
  217. {0x3F, 0x00, 0x3F}, {0x3F, 0x00, 0x2F}, {0x3F, 0x00, 0x1F}, {0x3F,
  218. 0x00,
  219. 0x10},
  220. /* Index 0x28~0x2B */
  221. {0x3F, 0x00, 0x00}, {0x3F, 0x10, 0x00}, {0x3F, 0x1F, 0x00}, {0x3F,
  222. 0x2F,
  223. 0x00},
  224. /* Index 0x2C~0x2F */
  225. {0x3F, 0x3F, 0x00}, {0x2F, 0x3F, 0x00}, {0x1F, 0x3F, 0x00}, {0x10,
  226. 0x3F,
  227. 0x00},
  228. /* Index 0x30~0x33 */
  229. {0x00, 0x3F, 0x00}, {0x00, 0x3F, 0x10}, {0x00, 0x3F, 0x1F}, {0x00,
  230. 0x3F,
  231. 0x2F},
  232. /* Index 0x34~0x37 */
  233. {0x00, 0x3F, 0x3F}, {0x00, 0x2F, 0x3F}, {0x00, 0x1F, 0x3F}, {0x00,
  234. 0x10,
  235. 0x3F},
  236. /* Index 0x38~0x3B */
  237. {0x1F, 0x1F, 0x3F}, {0x27, 0x1F, 0x3F}, {0x2F, 0x1F, 0x3F}, {0x37,
  238. 0x1F,
  239. 0x3F},
  240. /* Index 0x3C~0x3F */
  241. {0x3F, 0x1F, 0x3F}, {0x3F, 0x1F, 0x37}, {0x3F, 0x1F, 0x2F}, {0x3F,
  242. 0x1F,
  243. 0x27},
  244. /* Index 0x40~0x43 */
  245. {0x3F, 0x1F, 0x1F}, {0x3F, 0x27, 0x1F}, {0x3F, 0x2F, 0x1F}, {0x3F,
  246. 0x3F,
  247. 0x1F},
  248. /* Index 0x44~0x47 */
  249. {0x3F, 0x3F, 0x1F}, {0x37, 0x3F, 0x1F}, {0x2F, 0x3F, 0x1F}, {0x27,
  250. 0x3F,
  251. 0x1F},
  252. /* Index 0x48~0x4B */
  253. {0x1F, 0x3F, 0x1F}, {0x1F, 0x3F, 0x27}, {0x1F, 0x3F, 0x2F}, {0x1F,
  254. 0x3F,
  255. 0x37},
  256. /* Index 0x4C~0x4F */
  257. {0x1F, 0x3F, 0x3F}, {0x1F, 0x37, 0x3F}, {0x1F, 0x2F, 0x3F}, {0x1F,
  258. 0x27,
  259. 0x3F},
  260. /* Index 0x50~0x53 */
  261. {0x2D, 0x2D, 0x3F}, {0x31, 0x2D, 0x3F}, {0x36, 0x2D, 0x3F}, {0x3A,
  262. 0x2D,
  263. 0x3F},
  264. /* Index 0x54~0x57 */
  265. {0x3F, 0x2D, 0x3F}, {0x3F, 0x2D, 0x3A}, {0x3F, 0x2D, 0x36}, {0x3F,
  266. 0x2D,
  267. 0x31},
  268. /* Index 0x58~0x5B */
  269. {0x3F, 0x2D, 0x2D}, {0x3F, 0x31, 0x2D}, {0x3F, 0x36, 0x2D}, {0x3F,
  270. 0x3A,
  271. 0x2D},
  272. /* Index 0x5C~0x5F */
  273. {0x3F, 0x3F, 0x2D}, {0x3A, 0x3F, 0x2D}, {0x36, 0x3F, 0x2D}, {0x31,
  274. 0x3F,
  275. 0x2D},
  276. /* Index 0x60~0x63 */
  277. {0x2D, 0x3F, 0x2D}, {0x2D, 0x3F, 0x31}, {0x2D, 0x3F, 0x36}, {0x2D,
  278. 0x3F,
  279. 0x3A},
  280. /* Index 0x64~0x67 */
  281. {0x2D, 0x3F, 0x3F}, {0x2D, 0x3A, 0x3F}, {0x2D, 0x36, 0x3F}, {0x2D,
  282. 0x31,
  283. 0x3F},
  284. /* Index 0x68~0x6B */
  285. {0x00, 0x00, 0x1C}, {0x07, 0x00, 0x1C}, {0x0E, 0x00, 0x1C}, {0x15,
  286. 0x00,
  287. 0x1C},
  288. /* Index 0x6C~0x6F */
  289. {0x1C, 0x00, 0x1C}, {0x1C, 0x00, 0x15}, {0x1C, 0x00, 0x0E}, {0x1C,
  290. 0x00,
  291. 0x07},
  292. /* Index 0x70~0x73 */
  293. {0x1C, 0x00, 0x00}, {0x1C, 0x07, 0x00}, {0x1C, 0x0E, 0x00}, {0x1C,
  294. 0x15,
  295. 0x00},
  296. /* Index 0x74~0x77 */
  297. {0x1C, 0x1C, 0x00}, {0x15, 0x1C, 0x00}, {0x0E, 0x1C, 0x00}, {0x07,
  298. 0x1C,
  299. 0x00},
  300. /* Index 0x78~0x7B */
  301. {0x00, 0x1C, 0x00}, {0x00, 0x1C, 0x07}, {0x00, 0x1C, 0x0E}, {0x00,
  302. 0x1C,
  303. 0x15},
  304. /* Index 0x7C~0x7F */
  305. {0x00, 0x1C, 0x1C}, {0x00, 0x15, 0x1C}, {0x00, 0x0E, 0x1C}, {0x00,
  306. 0x07,
  307. 0x1C},
  308. /* Index 0x80~0x83 */
  309. {0x0E, 0x0E, 0x1C}, {0x11, 0x0E, 0x1C}, {0x15, 0x0E, 0x1C}, {0x18,
  310. 0x0E,
  311. 0x1C},
  312. /* Index 0x84~0x87 */
  313. {0x1C, 0x0E, 0x1C}, {0x1C, 0x0E, 0x18}, {0x1C, 0x0E, 0x15}, {0x1C,
  314. 0x0E,
  315. 0x11},
  316. /* Index 0x88~0x8B */
  317. {0x1C, 0x0E, 0x0E}, {0x1C, 0x11, 0x0E}, {0x1C, 0x15, 0x0E}, {0x1C,
  318. 0x18,
  319. 0x0E},
  320. /* Index 0x8C~0x8F */
  321. {0x1C, 0x1C, 0x0E}, {0x18, 0x1C, 0x0E}, {0x15, 0x1C, 0x0E}, {0x11,
  322. 0x1C,
  323. 0x0E},
  324. /* Index 0x90~0x93 */
  325. {0x0E, 0x1C, 0x0E}, {0x0E, 0x1C, 0x11}, {0x0E, 0x1C, 0x15}, {0x0E,
  326. 0x1C,
  327. 0x18},
  328. /* Index 0x94~0x97 */
  329. {0x0E, 0x1C, 0x1C}, {0x0E, 0x18, 0x1C}, {0x0E, 0x15, 0x1C}, {0x0E,
  330. 0x11,
  331. 0x1C},
  332. /* Index 0x98~0x9B */
  333. {0x14, 0x14, 0x1C}, {0x16, 0x14, 0x1C}, {0x18, 0x14, 0x1C}, {0x1A,
  334. 0x14,
  335. 0x1C},
  336. /* Index 0x9C~0x9F */
  337. {0x1C, 0x14, 0x1C}, {0x1C, 0x14, 0x1A}, {0x1C, 0x14, 0x18}, {0x1C,
  338. 0x14,
  339. 0x16},
  340. /* Index 0xA0~0xA3 */
  341. {0x1C, 0x14, 0x14}, {0x1C, 0x16, 0x14}, {0x1C, 0x18, 0x14}, {0x1C,
  342. 0x1A,
  343. 0x14},
  344. /* Index 0xA4~0xA7 */
  345. {0x1C, 0x1C, 0x14}, {0x1A, 0x1C, 0x14}, {0x18, 0x1C, 0x14}, {0x16,
  346. 0x1C,
  347. 0x14},
  348. /* Index 0xA8~0xAB */
  349. {0x14, 0x1C, 0x14}, {0x14, 0x1C, 0x16}, {0x14, 0x1C, 0x18}, {0x14,
  350. 0x1C,
  351. 0x1A},
  352. /* Index 0xAC~0xAF */
  353. {0x14, 0x1C, 0x1C}, {0x14, 0x1A, 0x1C}, {0x14, 0x18, 0x1C}, {0x14,
  354. 0x16,
  355. 0x1C},
  356. /* Index 0xB0~0xB3 */
  357. {0x00, 0x00, 0x10}, {0x04, 0x00, 0x10}, {0x08, 0x00, 0x10}, {0x0C,
  358. 0x00,
  359. 0x10},
  360. /* Index 0xB4~0xB7 */
  361. {0x10, 0x00, 0x10}, {0x10, 0x00, 0x0C}, {0x10, 0x00, 0x08}, {0x10,
  362. 0x00,
  363. 0x04},
  364. /* Index 0xB8~0xBB */
  365. {0x10, 0x00, 0x00}, {0x10, 0x04, 0x00}, {0x10, 0x08, 0x00}, {0x10,
  366. 0x0C,
  367. 0x00},
  368. /* Index 0xBC~0xBF */
  369. {0x10, 0x10, 0x00}, {0x0C, 0x10, 0x00}, {0x08, 0x10, 0x00}, {0x04,
  370. 0x10,
  371. 0x00},
  372. /* Index 0xC0~0xC3 */
  373. {0x00, 0x10, 0x00}, {0x00, 0x10, 0x04}, {0x00, 0x10, 0x08}, {0x00,
  374. 0x10,
  375. 0x0C},
  376. /* Index 0xC4~0xC7 */
  377. {0x00, 0x10, 0x10}, {0x00, 0x0C, 0x10}, {0x00, 0x08, 0x10}, {0x00,
  378. 0x04,
  379. 0x10},
  380. /* Index 0xC8~0xCB */
  381. {0x08, 0x08, 0x10}, {0x0A, 0x08, 0x10}, {0x0C, 0x08, 0x10}, {0x0E,
  382. 0x08,
  383. 0x10},
  384. /* Index 0xCC~0xCF */
  385. {0x10, 0x08, 0x10}, {0x10, 0x08, 0x0E}, {0x10, 0x08, 0x0C}, {0x10,
  386. 0x08,
  387. 0x0A},
  388. /* Index 0xD0~0xD3 */
  389. {0x10, 0x08, 0x08}, {0x10, 0x0A, 0x08}, {0x10, 0x0C, 0x08}, {0x10,
  390. 0x0E,
  391. 0x08},
  392. /* Index 0xD4~0xD7 */
  393. {0x10, 0x10, 0x08}, {0x0E, 0x10, 0x08}, {0x0C, 0x10, 0x08}, {0x0A,
  394. 0x10,
  395. 0x08},
  396. /* Index 0xD8~0xDB */
  397. {0x08, 0x10, 0x08}, {0x08, 0x10, 0x0A}, {0x08, 0x10, 0x0C}, {0x08,
  398. 0x10,
  399. 0x0E},
  400. /* Index 0xDC~0xDF */
  401. {0x08, 0x10, 0x10}, {0x08, 0x0E, 0x10}, {0x08, 0x0C, 0x10}, {0x08,
  402. 0x0A,
  403. 0x10},
  404. /* Index 0xE0~0xE3 */
  405. {0x0B, 0x0B, 0x10}, {0x0C, 0x0B, 0x10}, {0x0D, 0x0B, 0x10}, {0x0F,
  406. 0x0B,
  407. 0x10},
  408. /* Index 0xE4~0xE7 */
  409. {0x10, 0x0B, 0x10}, {0x10, 0x0B, 0x0F}, {0x10, 0x0B, 0x0D}, {0x10,
  410. 0x0B,
  411. 0x0C},
  412. /* Index 0xE8~0xEB */
  413. {0x10, 0x0B, 0x0B}, {0x10, 0x0C, 0x0B}, {0x10, 0x0D, 0x0B}, {0x10,
  414. 0x0F,
  415. 0x0B},
  416. /* Index 0xEC~0xEF */
  417. {0x10, 0x10, 0x0B}, {0x0F, 0x10, 0x0B}, {0x0D, 0x10, 0x0B}, {0x0C,
  418. 0x10,
  419. 0x0B},
  420. /* Index 0xF0~0xF3 */
  421. {0x0B, 0x10, 0x0B}, {0x0B, 0x10, 0x0C}, {0x0B, 0x10, 0x0D}, {0x0B,
  422. 0x10,
  423. 0x0F},
  424. /* Index 0xF4~0xF7 */
  425. {0x0B, 0x10, 0x10}, {0x0B, 0x0F, 0x10}, {0x0B, 0x0D, 0x10}, {0x0B,
  426. 0x0C,
  427. 0x10},
  428. /* Index 0xF8~0xFB */
  429. {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00,
  430. 0x00,
  431. 0x00},
  432. /* Index 0xFC~0xFF */
  433. {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00,
  434. 0x00,
  435. 0x00}
  436. };
  437. static struct via_device_mapping device_mapping[] = {
  438. {VIA_LDVP0, "LDVP0"},
  439. {VIA_LDVP1, "LDVP1"},
  440. {VIA_DVP0, "DVP0"},
  441. {VIA_CRT, "CRT"},
  442. {VIA_DVP1, "DVP1"},
  443. {VIA_LVDS1, "LVDS1"},
  444. {VIA_LVDS2, "LVDS2"}
  445. };
  446. /* structure with function pointers to support clock control */
  447. static struct via_clock clock;
  448. static void load_fix_bit_crtc_reg(void);
  449. static void __devinit init_gfx_chip_info(int chip_type);
  450. static void __devinit init_tmds_chip_info(void);
  451. static void __devinit init_lvds_chip_info(void);
  452. static void device_screen_off(void);
  453. static void device_screen_on(void);
  454. static void set_display_channel(void);
  455. static void device_off(void);
  456. static void device_on(void);
  457. static void enable_second_display_channel(void);
  458. static void disable_second_display_channel(void);
  459. void viafb_lock_crt(void)
  460. {
  461. viafb_write_reg_mask(CR11, VIACR, BIT7, BIT7);
  462. }
  463. void viafb_unlock_crt(void)
  464. {
  465. viafb_write_reg_mask(CR11, VIACR, 0, BIT7);
  466. viafb_write_reg_mask(CR47, VIACR, 0, BIT0);
  467. }
  468. static void write_dac_reg(u8 index, u8 r, u8 g, u8 b)
  469. {
  470. outb(index, LUT_INDEX_WRITE);
  471. outb(r, LUT_DATA);
  472. outb(g, LUT_DATA);
  473. outb(b, LUT_DATA);
  474. }
  475. static u32 get_dvi_devices(int output_interface)
  476. {
  477. switch (output_interface) {
  478. case INTERFACE_DVP0:
  479. return VIA_DVP0 | VIA_LDVP0;
  480. case INTERFACE_DVP1:
  481. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
  482. return VIA_LDVP1;
  483. else
  484. return VIA_DVP1;
  485. case INTERFACE_DFP_HIGH:
  486. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
  487. return 0;
  488. else
  489. return VIA_LVDS2 | VIA_DVP0;
  490. case INTERFACE_DFP_LOW:
  491. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
  492. return 0;
  493. else
  494. return VIA_DVP1 | VIA_LVDS1;
  495. case INTERFACE_TMDS:
  496. return VIA_LVDS1;
  497. }
  498. return 0;
  499. }
  500. static u32 get_lcd_devices(int output_interface)
  501. {
  502. switch (output_interface) {
  503. case INTERFACE_DVP0:
  504. return VIA_DVP0;
  505. case INTERFACE_DVP1:
  506. return VIA_DVP1;
  507. case INTERFACE_DFP_HIGH:
  508. return VIA_LVDS2 | VIA_DVP0;
  509. case INTERFACE_DFP_LOW:
  510. return VIA_LVDS1 | VIA_DVP1;
  511. case INTERFACE_DFP:
  512. return VIA_LVDS1 | VIA_LVDS2;
  513. case INTERFACE_LVDS0:
  514. case INTERFACE_LVDS0LVDS1:
  515. return VIA_LVDS1;
  516. case INTERFACE_LVDS1:
  517. return VIA_LVDS2;
  518. }
  519. return 0;
  520. }
  521. /*Set IGA path for each device*/
  522. void viafb_set_iga_path(void)
  523. {
  524. int crt_iga_path = 0;
  525. if (viafb_SAMM_ON == 1) {
  526. if (viafb_CRT_ON) {
  527. if (viafb_primary_dev == CRT_Device)
  528. crt_iga_path = IGA1;
  529. else
  530. crt_iga_path = IGA2;
  531. }
  532. if (viafb_DVI_ON) {
  533. if (viafb_primary_dev == DVI_Device)
  534. viaparinfo->tmds_setting_info->iga_path = IGA1;
  535. else
  536. viaparinfo->tmds_setting_info->iga_path = IGA2;
  537. }
  538. if (viafb_LCD_ON) {
  539. if (viafb_primary_dev == LCD_Device) {
  540. if (viafb_dual_fb &&
  541. (viaparinfo->chip_info->gfx_chip_name ==
  542. UNICHROME_CLE266)) {
  543. viaparinfo->
  544. lvds_setting_info->iga_path = IGA2;
  545. crt_iga_path = IGA1;
  546. viaparinfo->
  547. tmds_setting_info->iga_path = IGA1;
  548. } else
  549. viaparinfo->
  550. lvds_setting_info->iga_path = IGA1;
  551. } else {
  552. viaparinfo->lvds_setting_info->iga_path = IGA2;
  553. }
  554. }
  555. if (viafb_LCD2_ON) {
  556. if (LCD2_Device == viafb_primary_dev)
  557. viaparinfo->lvds_setting_info2->iga_path = IGA1;
  558. else
  559. viaparinfo->lvds_setting_info2->iga_path = IGA2;
  560. }
  561. } else {
  562. viafb_SAMM_ON = 0;
  563. if (viafb_CRT_ON && viafb_LCD_ON) {
  564. crt_iga_path = IGA1;
  565. viaparinfo->lvds_setting_info->iga_path = IGA2;
  566. } else if (viafb_CRT_ON && viafb_DVI_ON) {
  567. crt_iga_path = IGA1;
  568. viaparinfo->tmds_setting_info->iga_path = IGA2;
  569. } else if (viafb_LCD_ON && viafb_DVI_ON) {
  570. viaparinfo->tmds_setting_info->iga_path = IGA1;
  571. viaparinfo->lvds_setting_info->iga_path = IGA2;
  572. } else if (viafb_LCD_ON && viafb_LCD2_ON) {
  573. viaparinfo->lvds_setting_info->iga_path = IGA2;
  574. viaparinfo->lvds_setting_info2->iga_path = IGA2;
  575. } else if (viafb_CRT_ON) {
  576. crt_iga_path = IGA1;
  577. } else if (viafb_LCD_ON) {
  578. viaparinfo->lvds_setting_info->iga_path = IGA2;
  579. } else if (viafb_DVI_ON) {
  580. viaparinfo->tmds_setting_info->iga_path = IGA1;
  581. }
  582. }
  583. viaparinfo->shared->iga1_devices = 0;
  584. viaparinfo->shared->iga2_devices = 0;
  585. if (viafb_CRT_ON) {
  586. if (crt_iga_path == IGA1)
  587. viaparinfo->shared->iga1_devices |= VIA_CRT;
  588. else
  589. viaparinfo->shared->iga2_devices |= VIA_CRT;
  590. }
  591. if (viafb_DVI_ON) {
  592. if (viaparinfo->tmds_setting_info->iga_path == IGA1)
  593. viaparinfo->shared->iga1_devices |= get_dvi_devices(
  594. viaparinfo->chip_info->
  595. tmds_chip_info.output_interface);
  596. else
  597. viaparinfo->shared->iga2_devices |= get_dvi_devices(
  598. viaparinfo->chip_info->
  599. tmds_chip_info.output_interface);
  600. }
  601. if (viafb_LCD_ON) {
  602. if (viaparinfo->lvds_setting_info->iga_path == IGA1)
  603. viaparinfo->shared->iga1_devices |= get_lcd_devices(
  604. viaparinfo->chip_info->
  605. lvds_chip_info.output_interface);
  606. else
  607. viaparinfo->shared->iga2_devices |= get_lcd_devices(
  608. viaparinfo->chip_info->
  609. lvds_chip_info.output_interface);
  610. }
  611. if (viafb_LCD2_ON) {
  612. if (viaparinfo->lvds_setting_info2->iga_path == IGA1)
  613. viaparinfo->shared->iga1_devices |= get_lcd_devices(
  614. viaparinfo->chip_info->
  615. lvds_chip_info2.output_interface);
  616. else
  617. viaparinfo->shared->iga2_devices |= get_lcd_devices(
  618. viaparinfo->chip_info->
  619. lvds_chip_info2.output_interface);
  620. }
  621. /* looks like the OLPC has its display wired to DVP1 and LVDS2 */
  622. if (machine_is_olpc())
  623. viaparinfo->shared->iga2_devices = VIA_DVP1 | VIA_LVDS2;
  624. }
  625. static void set_color_register(u8 index, u8 red, u8 green, u8 blue)
  626. {
  627. outb(0xFF, 0x3C6); /* bit mask of palette */
  628. outb(index, 0x3C8);
  629. outb(red, 0x3C9);
  630. outb(green, 0x3C9);
  631. outb(blue, 0x3C9);
  632. }
  633. void viafb_set_primary_color_register(u8 index, u8 red, u8 green, u8 blue)
  634. {
  635. viafb_write_reg_mask(0x1A, VIASR, 0x00, 0x01);
  636. set_color_register(index, red, green, blue);
  637. }
  638. void viafb_set_secondary_color_register(u8 index, u8 red, u8 green, u8 blue)
  639. {
  640. viafb_write_reg_mask(0x1A, VIASR, 0x01, 0x01);
  641. set_color_register(index, red, green, blue);
  642. }
  643. static void set_source_common(u8 index, u8 offset, u8 iga)
  644. {
  645. u8 value, mask = 1 << offset;
  646. switch (iga) {
  647. case IGA1:
  648. value = 0x00;
  649. break;
  650. case IGA2:
  651. value = mask;
  652. break;
  653. default:
  654. printk(KERN_WARNING "viafb: Unsupported source: %d\n", iga);
  655. return;
  656. }
  657. via_write_reg_mask(VIACR, index, value, mask);
  658. }
  659. static void set_crt_source(u8 iga)
  660. {
  661. u8 value;
  662. switch (iga) {
  663. case IGA1:
  664. value = 0x00;
  665. break;
  666. case IGA2:
  667. value = 0x40;
  668. break;
  669. default:
  670. printk(KERN_WARNING "viafb: Unsupported source: %d\n", iga);
  671. return;
  672. }
  673. via_write_reg_mask(VIASR, 0x16, value, 0x40);
  674. }
  675. static inline void set_ldvp0_source(u8 iga)
  676. {
  677. set_source_common(0x6C, 7, iga);
  678. }
  679. static inline void set_ldvp1_source(u8 iga)
  680. {
  681. set_source_common(0x93, 7, iga);
  682. }
  683. static inline void set_dvp0_source(u8 iga)
  684. {
  685. set_source_common(0x96, 4, iga);
  686. }
  687. static inline void set_dvp1_source(u8 iga)
  688. {
  689. set_source_common(0x9B, 4, iga);
  690. }
  691. static inline void set_lvds1_source(u8 iga)
  692. {
  693. set_source_common(0x99, 4, iga);
  694. }
  695. static inline void set_lvds2_source(u8 iga)
  696. {
  697. set_source_common(0x97, 4, iga);
  698. }
  699. void via_set_source(u32 devices, u8 iga)
  700. {
  701. if (devices & VIA_LDVP0)
  702. set_ldvp0_source(iga);
  703. if (devices & VIA_LDVP1)
  704. set_ldvp1_source(iga);
  705. if (devices & VIA_DVP0)
  706. set_dvp0_source(iga);
  707. if (devices & VIA_CRT)
  708. set_crt_source(iga);
  709. if (devices & VIA_DVP1)
  710. set_dvp1_source(iga);
  711. if (devices & VIA_LVDS1)
  712. set_lvds1_source(iga);
  713. if (devices & VIA_LVDS2)
  714. set_lvds2_source(iga);
  715. }
  716. static void set_crt_state(u8 state)
  717. {
  718. u8 value;
  719. switch (state) {
  720. case VIA_STATE_ON:
  721. value = 0x00;
  722. break;
  723. case VIA_STATE_STANDBY:
  724. value = 0x10;
  725. break;
  726. case VIA_STATE_SUSPEND:
  727. value = 0x20;
  728. break;
  729. case VIA_STATE_OFF:
  730. value = 0x30;
  731. break;
  732. default:
  733. return;
  734. }
  735. via_write_reg_mask(VIACR, 0x36, value, 0x30);
  736. }
  737. static void set_dvp0_state(u8 state)
  738. {
  739. u8 value;
  740. switch (state) {
  741. case VIA_STATE_ON:
  742. value = 0xC0;
  743. break;
  744. case VIA_STATE_OFF:
  745. value = 0x00;
  746. break;
  747. default:
  748. return;
  749. }
  750. via_write_reg_mask(VIASR, 0x1E, value, 0xC0);
  751. }
  752. static void set_dvp1_state(u8 state)
  753. {
  754. u8 value;
  755. switch (state) {
  756. case VIA_STATE_ON:
  757. value = 0x30;
  758. break;
  759. case VIA_STATE_OFF:
  760. value = 0x00;
  761. break;
  762. default:
  763. return;
  764. }
  765. via_write_reg_mask(VIASR, 0x1E, value, 0x30);
  766. }
  767. static void set_lvds1_state(u8 state)
  768. {
  769. u8 value;
  770. switch (state) {
  771. case VIA_STATE_ON:
  772. value = 0x03;
  773. break;
  774. case VIA_STATE_OFF:
  775. value = 0x00;
  776. break;
  777. default:
  778. return;
  779. }
  780. via_write_reg_mask(VIASR, 0x2A, value, 0x03);
  781. }
  782. static void set_lvds2_state(u8 state)
  783. {
  784. u8 value;
  785. switch (state) {
  786. case VIA_STATE_ON:
  787. value = 0x0C;
  788. break;
  789. case VIA_STATE_OFF:
  790. value = 0x00;
  791. break;
  792. default:
  793. return;
  794. }
  795. via_write_reg_mask(VIASR, 0x2A, value, 0x0C);
  796. }
  797. void via_set_state(u32 devices, u8 state)
  798. {
  799. /*
  800. TODO: Can we enable/disable these devices? How?
  801. if (devices & VIA_LDVP0)
  802. if (devices & VIA_LDVP1)
  803. */
  804. if (devices & VIA_DVP0)
  805. set_dvp0_state(state);
  806. if (devices & VIA_CRT)
  807. set_crt_state(state);
  808. if (devices & VIA_DVP1)
  809. set_dvp1_state(state);
  810. if (devices & VIA_LVDS1)
  811. set_lvds1_state(state);
  812. if (devices & VIA_LVDS2)
  813. set_lvds2_state(state);
  814. }
  815. void via_set_sync_polarity(u32 devices, u8 polarity)
  816. {
  817. if (polarity & ~(VIA_HSYNC_NEGATIVE | VIA_VSYNC_NEGATIVE)) {
  818. printk(KERN_WARNING "viafb: Unsupported polarity: %d\n",
  819. polarity);
  820. return;
  821. }
  822. if (devices & VIA_CRT)
  823. via_write_misc_reg_mask(polarity << 6, 0xC0);
  824. if (devices & VIA_DVP1)
  825. via_write_reg_mask(VIACR, 0x9B, polarity << 5, 0x60);
  826. if (devices & VIA_LVDS1)
  827. via_write_reg_mask(VIACR, 0x99, polarity << 5, 0x60);
  828. if (devices & VIA_LVDS2)
  829. via_write_reg_mask(VIACR, 0x97, polarity << 5, 0x60);
  830. }
  831. u32 via_parse_odev(char *input, char **end)
  832. {
  833. char *ptr = input;
  834. u32 odev = 0;
  835. bool next = true;
  836. int i, len;
  837. while (next) {
  838. next = false;
  839. for (i = 0; i < ARRAY_SIZE(device_mapping); i++) {
  840. len = strlen(device_mapping[i].name);
  841. if (!strncmp(ptr, device_mapping[i].name, len)) {
  842. odev |= device_mapping[i].device;
  843. ptr += len;
  844. if (*ptr == ',') {
  845. ptr++;
  846. next = true;
  847. }
  848. }
  849. }
  850. }
  851. *end = ptr;
  852. return odev;
  853. }
  854. void via_odev_to_seq(struct seq_file *m, u32 odev)
  855. {
  856. int i, count = 0;
  857. for (i = 0; i < ARRAY_SIZE(device_mapping); i++) {
  858. if (odev & device_mapping[i].device) {
  859. if (count > 0)
  860. seq_putc(m, ',');
  861. seq_puts(m, device_mapping[i].name);
  862. count++;
  863. }
  864. }
  865. seq_putc(m, '\n');
  866. }
  867. static void load_fix_bit_crtc_reg(void)
  868. {
  869. viafb_unlock_crt();
  870. /* always set to 1 */
  871. viafb_write_reg_mask(CR03, VIACR, 0x80, BIT7);
  872. /* line compare should set all bits = 1 (extend modes) */
  873. viafb_write_reg_mask(CR35, VIACR, 0x10, BIT4);
  874. /* line compare should set all bits = 1 (extend modes) */
  875. viafb_write_reg_mask(CR33, VIACR, 0x06, BIT0 + BIT1 + BIT2);
  876. /*viafb_write_reg_mask(CR32, VIACR, 0x01, BIT0); */
  877. viafb_lock_crt();
  878. /* If K8M800, enable Prefetch Mode. */
  879. if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800)
  880. || (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K8M890))
  881. viafb_write_reg_mask(CR33, VIACR, 0x08, BIT3);
  882. if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
  883. && (viaparinfo->chip_info->gfx_chip_revision == CLE266_REVISION_AX))
  884. viafb_write_reg_mask(SR1A, VIASR, 0x02, BIT1);
  885. }
  886. void viafb_load_reg(int timing_value, int viafb_load_reg_num,
  887. struct io_register *reg,
  888. int io_type)
  889. {
  890. int reg_mask;
  891. int bit_num = 0;
  892. int data;
  893. int i, j;
  894. int shift_next_reg;
  895. int start_index, end_index, cr_index;
  896. u16 get_bit;
  897. for (i = 0; i < viafb_load_reg_num; i++) {
  898. reg_mask = 0;
  899. data = 0;
  900. start_index = reg[i].start_bit;
  901. end_index = reg[i].end_bit;
  902. cr_index = reg[i].io_addr;
  903. shift_next_reg = bit_num;
  904. for (j = start_index; j <= end_index; j++) {
  905. /*if (bit_num==8) timing_value = timing_value >>8; */
  906. reg_mask = reg_mask | (BIT0 << j);
  907. get_bit = (timing_value & (BIT0 << bit_num));
  908. data =
  909. data | ((get_bit >> shift_next_reg) << start_index);
  910. bit_num++;
  911. }
  912. if (io_type == VIACR)
  913. viafb_write_reg_mask(cr_index, VIACR, data, reg_mask);
  914. else
  915. viafb_write_reg_mask(cr_index, VIASR, data, reg_mask);
  916. }
  917. }
  918. /* Write Registers */
  919. void viafb_write_regx(struct io_reg RegTable[], int ItemNum)
  920. {
  921. int i;
  922. /*DEBUG_MSG(KERN_INFO "Table Size : %x!!\n",ItemNum ); */
  923. for (i = 0; i < ItemNum; i++)
  924. via_write_reg_mask(RegTable[i].port, RegTable[i].index,
  925. RegTable[i].value, RegTable[i].mask);
  926. }
  927. void viafb_load_fetch_count_reg(int h_addr, int bpp_byte, int set_iga)
  928. {
  929. int reg_value;
  930. int viafb_load_reg_num;
  931. struct io_register *reg = NULL;
  932. switch (set_iga) {
  933. case IGA1:
  934. reg_value = IGA1_FETCH_COUNT_FORMULA(h_addr, bpp_byte);
  935. viafb_load_reg_num = fetch_count_reg.
  936. iga1_fetch_count_reg.reg_num;
  937. reg = fetch_count_reg.iga1_fetch_count_reg.reg;
  938. viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
  939. break;
  940. case IGA2:
  941. reg_value = IGA2_FETCH_COUNT_FORMULA(h_addr, bpp_byte);
  942. viafb_load_reg_num = fetch_count_reg.
  943. iga2_fetch_count_reg.reg_num;
  944. reg = fetch_count_reg.iga2_fetch_count_reg.reg;
  945. viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
  946. break;
  947. }
  948. }
  949. void viafb_load_FIFO_reg(int set_iga, int hor_active, int ver_active)
  950. {
  951. int reg_value;
  952. int viafb_load_reg_num;
  953. struct io_register *reg = NULL;
  954. int iga1_fifo_max_depth = 0, iga1_fifo_threshold =
  955. 0, iga1_fifo_high_threshold = 0, iga1_display_queue_expire_num = 0;
  956. int iga2_fifo_max_depth = 0, iga2_fifo_threshold =
  957. 0, iga2_fifo_high_threshold = 0, iga2_display_queue_expire_num = 0;
  958. if (set_iga == IGA1) {
  959. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800) {
  960. iga1_fifo_max_depth = K800_IGA1_FIFO_MAX_DEPTH;
  961. iga1_fifo_threshold = K800_IGA1_FIFO_THRESHOLD;
  962. iga1_fifo_high_threshold =
  963. K800_IGA1_FIFO_HIGH_THRESHOLD;
  964. /* If resolution > 1280x1024, expire length = 64, else
  965. expire length = 128 */
  966. if ((hor_active > 1280) && (ver_active > 1024))
  967. iga1_display_queue_expire_num = 16;
  968. else
  969. iga1_display_queue_expire_num =
  970. K800_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
  971. }
  972. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_PM800) {
  973. iga1_fifo_max_depth = P880_IGA1_FIFO_MAX_DEPTH;
  974. iga1_fifo_threshold = P880_IGA1_FIFO_THRESHOLD;
  975. iga1_fifo_high_threshold =
  976. P880_IGA1_FIFO_HIGH_THRESHOLD;
  977. iga1_display_queue_expire_num =
  978. P880_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
  979. /* If resolution > 1280x1024, expire length = 64, else
  980. expire length = 128 */
  981. if ((hor_active > 1280) && (ver_active > 1024))
  982. iga1_display_queue_expire_num = 16;
  983. else
  984. iga1_display_queue_expire_num =
  985. P880_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
  986. }
  987. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CN700) {
  988. iga1_fifo_max_depth = CN700_IGA1_FIFO_MAX_DEPTH;
  989. iga1_fifo_threshold = CN700_IGA1_FIFO_THRESHOLD;
  990. iga1_fifo_high_threshold =
  991. CN700_IGA1_FIFO_HIGH_THRESHOLD;
  992. /* If resolution > 1280x1024, expire length = 64,
  993. else expire length = 128 */
  994. if ((hor_active > 1280) && (ver_active > 1024))
  995. iga1_display_queue_expire_num = 16;
  996. else
  997. iga1_display_queue_expire_num =
  998. CN700_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
  999. }
  1000. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) {
  1001. iga1_fifo_max_depth = CX700_IGA1_FIFO_MAX_DEPTH;
  1002. iga1_fifo_threshold = CX700_IGA1_FIFO_THRESHOLD;
  1003. iga1_fifo_high_threshold =
  1004. CX700_IGA1_FIFO_HIGH_THRESHOLD;
  1005. iga1_display_queue_expire_num =
  1006. CX700_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
  1007. }
  1008. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K8M890) {
  1009. iga1_fifo_max_depth = K8M890_IGA1_FIFO_MAX_DEPTH;
  1010. iga1_fifo_threshold = K8M890_IGA1_FIFO_THRESHOLD;
  1011. iga1_fifo_high_threshold =
  1012. K8M890_IGA1_FIFO_HIGH_THRESHOLD;
  1013. iga1_display_queue_expire_num =
  1014. K8M890_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
  1015. }
  1016. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_P4M890) {
  1017. iga1_fifo_max_depth = P4M890_IGA1_FIFO_MAX_DEPTH;
  1018. iga1_fifo_threshold = P4M890_IGA1_FIFO_THRESHOLD;
  1019. iga1_fifo_high_threshold =
  1020. P4M890_IGA1_FIFO_HIGH_THRESHOLD;
  1021. iga1_display_queue_expire_num =
  1022. P4M890_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
  1023. }
  1024. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_P4M900) {
  1025. iga1_fifo_max_depth = P4M900_IGA1_FIFO_MAX_DEPTH;
  1026. iga1_fifo_threshold = P4M900_IGA1_FIFO_THRESHOLD;
  1027. iga1_fifo_high_threshold =
  1028. P4M900_IGA1_FIFO_HIGH_THRESHOLD;
  1029. iga1_display_queue_expire_num =
  1030. P4M900_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
  1031. }
  1032. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX800) {
  1033. iga1_fifo_max_depth = VX800_IGA1_FIFO_MAX_DEPTH;
  1034. iga1_fifo_threshold = VX800_IGA1_FIFO_THRESHOLD;
  1035. iga1_fifo_high_threshold =
  1036. VX800_IGA1_FIFO_HIGH_THRESHOLD;
  1037. iga1_display_queue_expire_num =
  1038. VX800_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
  1039. }
  1040. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX855) {
  1041. iga1_fifo_max_depth = VX855_IGA1_FIFO_MAX_DEPTH;
  1042. iga1_fifo_threshold = VX855_IGA1_FIFO_THRESHOLD;
  1043. iga1_fifo_high_threshold =
  1044. VX855_IGA1_FIFO_HIGH_THRESHOLD;
  1045. iga1_display_queue_expire_num =
  1046. VX855_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
  1047. }
  1048. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX900) {
  1049. iga1_fifo_max_depth = VX900_IGA1_FIFO_MAX_DEPTH;
  1050. iga1_fifo_threshold = VX900_IGA1_FIFO_THRESHOLD;
  1051. iga1_fifo_high_threshold =
  1052. VX900_IGA1_FIFO_HIGH_THRESHOLD;
  1053. iga1_display_queue_expire_num =
  1054. VX900_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
  1055. }
  1056. /* Set Display FIFO Depath Select */
  1057. reg_value = IGA1_FIFO_DEPTH_SELECT_FORMULA(iga1_fifo_max_depth);
  1058. viafb_load_reg_num =
  1059. display_fifo_depth_reg.iga1_fifo_depth_select_reg.reg_num;
  1060. reg = display_fifo_depth_reg.iga1_fifo_depth_select_reg.reg;
  1061. viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
  1062. /* Set Display FIFO Threshold Select */
  1063. reg_value = IGA1_FIFO_THRESHOLD_FORMULA(iga1_fifo_threshold);
  1064. viafb_load_reg_num =
  1065. fifo_threshold_select_reg.
  1066. iga1_fifo_threshold_select_reg.reg_num;
  1067. reg =
  1068. fifo_threshold_select_reg.
  1069. iga1_fifo_threshold_select_reg.reg;
  1070. viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
  1071. /* Set FIFO High Threshold Select */
  1072. reg_value =
  1073. IGA1_FIFO_HIGH_THRESHOLD_FORMULA(iga1_fifo_high_threshold);
  1074. viafb_load_reg_num =
  1075. fifo_high_threshold_select_reg.
  1076. iga1_fifo_high_threshold_select_reg.reg_num;
  1077. reg =
  1078. fifo_high_threshold_select_reg.
  1079. iga1_fifo_high_threshold_select_reg.reg;
  1080. viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
  1081. /* Set Display Queue Expire Num */
  1082. reg_value =
  1083. IGA1_DISPLAY_QUEUE_EXPIRE_NUM_FORMULA
  1084. (iga1_display_queue_expire_num);
  1085. viafb_load_reg_num =
  1086. display_queue_expire_num_reg.
  1087. iga1_display_queue_expire_num_reg.reg_num;
  1088. reg =
  1089. display_queue_expire_num_reg.
  1090. iga1_display_queue_expire_num_reg.reg;
  1091. viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
  1092. } else {
  1093. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800) {
  1094. iga2_fifo_max_depth = K800_IGA2_FIFO_MAX_DEPTH;
  1095. iga2_fifo_threshold = K800_IGA2_FIFO_THRESHOLD;
  1096. iga2_fifo_high_threshold =
  1097. K800_IGA2_FIFO_HIGH_THRESHOLD;
  1098. /* If resolution > 1280x1024, expire length = 64,
  1099. else expire length = 128 */
  1100. if ((hor_active > 1280) && (ver_active > 1024))
  1101. iga2_display_queue_expire_num = 16;
  1102. else
  1103. iga2_display_queue_expire_num =
  1104. K800_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
  1105. }
  1106. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_PM800) {
  1107. iga2_fifo_max_depth = P880_IGA2_FIFO_MAX_DEPTH;
  1108. iga2_fifo_threshold = P880_IGA2_FIFO_THRESHOLD;
  1109. iga2_fifo_high_threshold =
  1110. P880_IGA2_FIFO_HIGH_THRESHOLD;
  1111. /* If resolution > 1280x1024, expire length = 64,
  1112. else expire length = 128 */
  1113. if ((hor_active > 1280) && (ver_active > 1024))
  1114. iga2_display_queue_expire_num = 16;
  1115. else
  1116. iga2_display_queue_expire_num =
  1117. P880_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
  1118. }
  1119. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CN700) {
  1120. iga2_fifo_max_depth = CN700_IGA2_FIFO_MAX_DEPTH;
  1121. iga2_fifo_threshold = CN700_IGA2_FIFO_THRESHOLD;
  1122. iga2_fifo_high_threshold =
  1123. CN700_IGA2_FIFO_HIGH_THRESHOLD;
  1124. /* If resolution > 1280x1024, expire length = 64,
  1125. else expire length = 128 */
  1126. if ((hor_active > 1280) && (ver_active > 1024))
  1127. iga2_display_queue_expire_num = 16;
  1128. else
  1129. iga2_display_queue_expire_num =
  1130. CN700_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
  1131. }
  1132. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) {
  1133. iga2_fifo_max_depth = CX700_IGA2_FIFO_MAX_DEPTH;
  1134. iga2_fifo_threshold = CX700_IGA2_FIFO_THRESHOLD;
  1135. iga2_fifo_high_threshold =
  1136. CX700_IGA2_FIFO_HIGH_THRESHOLD;
  1137. iga2_display_queue_expire_num =
  1138. CX700_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
  1139. }
  1140. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K8M890) {
  1141. iga2_fifo_max_depth = K8M890_IGA2_FIFO_MAX_DEPTH;
  1142. iga2_fifo_threshold = K8M890_IGA2_FIFO_THRESHOLD;
  1143. iga2_fifo_high_threshold =
  1144. K8M890_IGA2_FIFO_HIGH_THRESHOLD;
  1145. iga2_display_queue_expire_num =
  1146. K8M890_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
  1147. }
  1148. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_P4M890) {
  1149. iga2_fifo_max_depth = P4M890_IGA2_FIFO_MAX_DEPTH;
  1150. iga2_fifo_threshold = P4M890_IGA2_FIFO_THRESHOLD;
  1151. iga2_fifo_high_threshold =
  1152. P4M890_IGA2_FIFO_HIGH_THRESHOLD;
  1153. iga2_display_queue_expire_num =
  1154. P4M890_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
  1155. }
  1156. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_P4M900) {
  1157. iga2_fifo_max_depth = P4M900_IGA2_FIFO_MAX_DEPTH;
  1158. iga2_fifo_threshold = P4M900_IGA2_FIFO_THRESHOLD;
  1159. iga2_fifo_high_threshold =
  1160. P4M900_IGA2_FIFO_HIGH_THRESHOLD;
  1161. iga2_display_queue_expire_num =
  1162. P4M900_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
  1163. }
  1164. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX800) {
  1165. iga2_fifo_max_depth = VX800_IGA2_FIFO_MAX_DEPTH;
  1166. iga2_fifo_threshold = VX800_IGA2_FIFO_THRESHOLD;
  1167. iga2_fifo_high_threshold =
  1168. VX800_IGA2_FIFO_HIGH_THRESHOLD;
  1169. iga2_display_queue_expire_num =
  1170. VX800_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
  1171. }
  1172. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX855) {
  1173. iga2_fifo_max_depth = VX855_IGA2_FIFO_MAX_DEPTH;
  1174. iga2_fifo_threshold = VX855_IGA2_FIFO_THRESHOLD;
  1175. iga2_fifo_high_threshold =
  1176. VX855_IGA2_FIFO_HIGH_THRESHOLD;
  1177. iga2_display_queue_expire_num =
  1178. VX855_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
  1179. }
  1180. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX900) {
  1181. iga2_fifo_max_depth = VX900_IGA2_FIFO_MAX_DEPTH;
  1182. iga2_fifo_threshold = VX900_IGA2_FIFO_THRESHOLD;
  1183. iga2_fifo_high_threshold =
  1184. VX900_IGA2_FIFO_HIGH_THRESHOLD;
  1185. iga2_display_queue_expire_num =
  1186. VX900_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
  1187. }
  1188. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800) {
  1189. /* Set Display FIFO Depath Select */
  1190. reg_value =
  1191. IGA2_FIFO_DEPTH_SELECT_FORMULA(iga2_fifo_max_depth)
  1192. - 1;
  1193. /* Patch LCD in IGA2 case */
  1194. viafb_load_reg_num =
  1195. display_fifo_depth_reg.
  1196. iga2_fifo_depth_select_reg.reg_num;
  1197. reg =
  1198. display_fifo_depth_reg.
  1199. iga2_fifo_depth_select_reg.reg;
  1200. viafb_load_reg(reg_value,
  1201. viafb_load_reg_num, reg, VIACR);
  1202. } else {
  1203. /* Set Display FIFO Depath Select */
  1204. reg_value =
  1205. IGA2_FIFO_DEPTH_SELECT_FORMULA(iga2_fifo_max_depth);
  1206. viafb_load_reg_num =
  1207. display_fifo_depth_reg.
  1208. iga2_fifo_depth_select_reg.reg_num;
  1209. reg =
  1210. display_fifo_depth_reg.
  1211. iga2_fifo_depth_select_reg.reg;
  1212. viafb_load_reg(reg_value,
  1213. viafb_load_reg_num, reg, VIACR);
  1214. }
  1215. /* Set Display FIFO Threshold Select */
  1216. reg_value = IGA2_FIFO_THRESHOLD_FORMULA(iga2_fifo_threshold);
  1217. viafb_load_reg_num =
  1218. fifo_threshold_select_reg.
  1219. iga2_fifo_threshold_select_reg.reg_num;
  1220. reg =
  1221. fifo_threshold_select_reg.
  1222. iga2_fifo_threshold_select_reg.reg;
  1223. viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
  1224. /* Set FIFO High Threshold Select */
  1225. reg_value =
  1226. IGA2_FIFO_HIGH_THRESHOLD_FORMULA(iga2_fifo_high_threshold);
  1227. viafb_load_reg_num =
  1228. fifo_high_threshold_select_reg.
  1229. iga2_fifo_high_threshold_select_reg.reg_num;
  1230. reg =
  1231. fifo_high_threshold_select_reg.
  1232. iga2_fifo_high_threshold_select_reg.reg;
  1233. viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
  1234. /* Set Display Queue Expire Num */
  1235. reg_value =
  1236. IGA2_DISPLAY_QUEUE_EXPIRE_NUM_FORMULA
  1237. (iga2_display_queue_expire_num);
  1238. viafb_load_reg_num =
  1239. display_queue_expire_num_reg.
  1240. iga2_display_queue_expire_num_reg.reg_num;
  1241. reg =
  1242. display_queue_expire_num_reg.
  1243. iga2_display_queue_expire_num_reg.reg;
  1244. viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
  1245. }
  1246. }
  1247. static struct via_pll_config get_pll_config(struct pll_limit *limits, int size,
  1248. int clk)
  1249. {
  1250. struct via_pll_config cur, up, down, best = {0, 1, 0};
  1251. const u32 f0 = 14318180; /* X1 frequency */
  1252. int i, f;
  1253. for (i = 0; i < size; i++) {
  1254. cur.rshift = limits[i].rshift;
  1255. cur.divisor = limits[i].divisor;
  1256. cur.multiplier = clk / ((f0 / cur.divisor)>>cur.rshift);
  1257. f = abs(get_pll_output_frequency(f0, cur) - clk);
  1258. up = down = cur;
  1259. up.multiplier++;
  1260. down.multiplier--;
  1261. if (abs(get_pll_output_frequency(f0, up) - clk) < f)
  1262. cur = up;
  1263. else if (abs(get_pll_output_frequency(f0, down) - clk) < f)
  1264. cur = down;
  1265. if (cur.multiplier < limits[i].multiplier_min)
  1266. cur.multiplier = limits[i].multiplier_min;
  1267. else if (cur.multiplier > limits[i].multiplier_max)
  1268. cur.multiplier = limits[i].multiplier_max;
  1269. f = abs(get_pll_output_frequency(f0, cur) - clk);
  1270. if (f < abs(get_pll_output_frequency(f0, best) - clk))
  1271. best = cur;
  1272. }
  1273. return best;
  1274. }
  1275. static struct via_pll_config get_best_pll_config(int clk)
  1276. {
  1277. struct via_pll_config config;
  1278. switch (viaparinfo->chip_info->gfx_chip_name) {
  1279. case UNICHROME_CLE266:
  1280. case UNICHROME_K400:
  1281. config = get_pll_config(cle266_pll_limits,
  1282. ARRAY_SIZE(cle266_pll_limits), clk);
  1283. break;
  1284. case UNICHROME_K800:
  1285. case UNICHROME_PM800:
  1286. case UNICHROME_CN700:
  1287. config = get_pll_config(k800_pll_limits,
  1288. ARRAY_SIZE(k800_pll_limits), clk);
  1289. break;
  1290. case UNICHROME_CX700:
  1291. case UNICHROME_CN750:
  1292. case UNICHROME_K8M890:
  1293. case UNICHROME_P4M890:
  1294. case UNICHROME_P4M900:
  1295. case UNICHROME_VX800:
  1296. config = get_pll_config(cx700_pll_limits,
  1297. ARRAY_SIZE(cx700_pll_limits), clk);
  1298. break;
  1299. case UNICHROME_VX855:
  1300. case UNICHROME_VX900:
  1301. config = get_pll_config(vx855_pll_limits,
  1302. ARRAY_SIZE(vx855_pll_limits), clk);
  1303. break;
  1304. }
  1305. return config;
  1306. }
  1307. /* Set VCLK*/
  1308. void viafb_set_vclock(u32 clk, int set_iga)
  1309. {
  1310. struct via_pll_config config = get_best_pll_config(clk);
  1311. if (set_iga == IGA1)
  1312. clock.set_primary_pll(config);
  1313. if (set_iga == IGA2)
  1314. clock.set_secondary_pll(config);
  1315. /* Fire! */
  1316. via_write_misc_reg_mask(0x0C, 0x0C); /* select external clock */
  1317. }
  1318. struct display_timing var_to_timing(const struct fb_var_screeninfo *var,
  1319. u16 cxres, u16 cyres)
  1320. {
  1321. struct display_timing timing;
  1322. u16 dx = (var->xres - cxres) / 2, dy = (var->yres - cyres) / 2;
  1323. timing.hor_addr = cxres;
  1324. timing.hor_sync_start = timing.hor_addr + var->right_margin + dx;
  1325. timing.hor_sync_end = timing.hor_sync_start + var->hsync_len;
  1326. timing.hor_total = timing.hor_sync_end + var->left_margin + dx;
  1327. timing.hor_blank_start = timing.hor_addr + dx;
  1328. timing.hor_blank_end = timing.hor_total - dx;
  1329. timing.ver_addr = cyres;
  1330. timing.ver_sync_start = timing.ver_addr + var->lower_margin + dy;
  1331. timing.ver_sync_end = timing.ver_sync_start + var->vsync_len;
  1332. timing.ver_total = timing.ver_sync_end + var->upper_margin + dy;
  1333. timing.ver_blank_start = timing.ver_addr + dy;
  1334. timing.ver_blank_end = timing.ver_total - dy;
  1335. return timing;
  1336. }
  1337. void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var,
  1338. u16 cxres, u16 cyres, int iga)
  1339. {
  1340. struct display_timing crt_reg = var_to_timing(var,
  1341. cxres ? cxres : var->xres, cyres ? cyres : var->yres);
  1342. if (iga == IGA1)
  1343. via_set_primary_timing(&crt_reg);
  1344. else if (iga == IGA2)
  1345. via_set_secondary_timing(&crt_reg);
  1346. viafb_load_fetch_count_reg(var->xres, var->bits_per_pixel / 8, iga);
  1347. if (viaparinfo->chip_info->gfx_chip_name != UNICHROME_CLE266
  1348. && viaparinfo->chip_info->gfx_chip_name != UNICHROME_K400)
  1349. viafb_load_FIFO_reg(iga, var->xres, var->yres);
  1350. viafb_set_vclock(PICOS2KHZ(var->pixclock) * 1000, iga);
  1351. }
  1352. void __devinit viafb_init_chip_info(int chip_type)
  1353. {
  1354. via_clock_init(&clock, chip_type);
  1355. init_gfx_chip_info(chip_type);
  1356. init_tmds_chip_info();
  1357. init_lvds_chip_info();
  1358. /*Set IGA path for each device */
  1359. viafb_set_iga_path();
  1360. viaparinfo->lvds_setting_info->display_method = viafb_lcd_dsp_method;
  1361. viaparinfo->lvds_setting_info->lcd_mode = viafb_lcd_mode;
  1362. viaparinfo->lvds_setting_info2->display_method =
  1363. viaparinfo->lvds_setting_info->display_method;
  1364. viaparinfo->lvds_setting_info2->lcd_mode =
  1365. viaparinfo->lvds_setting_info->lcd_mode;
  1366. }
  1367. void viafb_update_device_setting(int hres, int vres, int bpp, int flag)
  1368. {
  1369. if (flag == 0) {
  1370. viaparinfo->tmds_setting_info->h_active = hres;
  1371. viaparinfo->tmds_setting_info->v_active = vres;
  1372. } else {
  1373. if (viaparinfo->tmds_setting_info->iga_path == IGA2) {
  1374. viaparinfo->tmds_setting_info->h_active = hres;
  1375. viaparinfo->tmds_setting_info->v_active = vres;
  1376. }
  1377. }
  1378. }
  1379. static void __devinit init_gfx_chip_info(int chip_type)
  1380. {
  1381. u8 tmp;
  1382. viaparinfo->chip_info->gfx_chip_name = chip_type;
  1383. /* Check revision of CLE266 Chip */
  1384. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
  1385. /* CR4F only define in CLE266.CX chip */
  1386. tmp = viafb_read_reg(VIACR, CR4F);
  1387. viafb_write_reg(CR4F, VIACR, 0x55);
  1388. if (viafb_read_reg(VIACR, CR4F) != 0x55)
  1389. viaparinfo->chip_info->gfx_chip_revision =
  1390. CLE266_REVISION_AX;
  1391. else
  1392. viaparinfo->chip_info->gfx_chip_revision =
  1393. CLE266_REVISION_CX;
  1394. /* restore orignal CR4F value */
  1395. viafb_write_reg(CR4F, VIACR, tmp);
  1396. }
  1397. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) {
  1398. tmp = viafb_read_reg(VIASR, SR43);
  1399. DEBUG_MSG(KERN_INFO "SR43:%X\n", tmp);
  1400. if (tmp & 0x02) {
  1401. viaparinfo->chip_info->gfx_chip_revision =
  1402. CX700_REVISION_700M2;
  1403. } else if (tmp & 0x40) {
  1404. viaparinfo->chip_info->gfx_chip_revision =
  1405. CX700_REVISION_700M;
  1406. } else {
  1407. viaparinfo->chip_info->gfx_chip_revision =
  1408. CX700_REVISION_700;
  1409. }
  1410. }
  1411. /* Determine which 2D engine we have */
  1412. switch (viaparinfo->chip_info->gfx_chip_name) {
  1413. case UNICHROME_VX800:
  1414. case UNICHROME_VX855:
  1415. case UNICHROME_VX900:
  1416. viaparinfo->chip_info->twod_engine = VIA_2D_ENG_M1;
  1417. break;
  1418. case UNICHROME_K8M890:
  1419. case UNICHROME_P4M900:
  1420. viaparinfo->chip_info->twod_engine = VIA_2D_ENG_H5;
  1421. break;
  1422. default:
  1423. viaparinfo->chip_info->twod_engine = VIA_2D_ENG_H2;
  1424. break;
  1425. }
  1426. }
  1427. static void __devinit init_tmds_chip_info(void)
  1428. {
  1429. viafb_tmds_trasmitter_identify();
  1430. if (INTERFACE_NONE == viaparinfo->chip_info->tmds_chip_info.
  1431. output_interface) {
  1432. switch (viaparinfo->chip_info->gfx_chip_name) {
  1433. case UNICHROME_CX700:
  1434. {
  1435. /* we should check support by hardware layout.*/
  1436. if ((viafb_display_hardware_layout ==
  1437. HW_LAYOUT_DVI_ONLY)
  1438. || (viafb_display_hardware_layout ==
  1439. HW_LAYOUT_LCD_DVI)) {
  1440. viaparinfo->chip_info->tmds_chip_info.
  1441. output_interface = INTERFACE_TMDS;
  1442. } else {
  1443. viaparinfo->chip_info->tmds_chip_info.
  1444. output_interface =
  1445. INTERFACE_NONE;
  1446. }
  1447. break;
  1448. }
  1449. case UNICHROME_K8M890:
  1450. case UNICHROME_P4M900:
  1451. case UNICHROME_P4M890:
  1452. /* TMDS on PCIE, we set DFPLOW as default. */
  1453. viaparinfo->chip_info->tmds_chip_info.output_interface =
  1454. INTERFACE_DFP_LOW;
  1455. break;
  1456. default:
  1457. {
  1458. /* set DVP1 default for DVI */
  1459. viaparinfo->chip_info->tmds_chip_info
  1460. .output_interface = INTERFACE_DVP1;
  1461. }
  1462. }
  1463. }
  1464. DEBUG_MSG(KERN_INFO "TMDS Chip = %d\n",
  1465. viaparinfo->chip_info->tmds_chip_info.tmds_chip_name);
  1466. viafb_init_dvi_size(&viaparinfo->shared->chip_info.tmds_chip_info,
  1467. &viaparinfo->shared->tmds_setting_info);
  1468. }
  1469. static void __devinit init_lvds_chip_info(void)
  1470. {
  1471. viafb_lvds_trasmitter_identify();
  1472. viafb_init_lcd_size();
  1473. viafb_init_lvds_output_interface(&viaparinfo->chip_info->lvds_chip_info,
  1474. viaparinfo->lvds_setting_info);
  1475. if (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
  1476. viafb_init_lvds_output_interface(&viaparinfo->chip_info->
  1477. lvds_chip_info2, viaparinfo->lvds_setting_info2);
  1478. }
  1479. /*If CX700,two singel LCD, we need to reassign
  1480. LCD interface to different LVDS port */
  1481. if ((UNICHROME_CX700 == viaparinfo->chip_info->gfx_chip_name)
  1482. && (HW_LAYOUT_LCD1_LCD2 == viafb_display_hardware_layout)) {
  1483. if ((INTEGRATED_LVDS == viaparinfo->chip_info->lvds_chip_info.
  1484. lvds_chip_name) && (INTEGRATED_LVDS ==
  1485. viaparinfo->chip_info->
  1486. lvds_chip_info2.lvds_chip_name)) {
  1487. viaparinfo->chip_info->lvds_chip_info.output_interface =
  1488. INTERFACE_LVDS0;
  1489. viaparinfo->chip_info->lvds_chip_info2.
  1490. output_interface =
  1491. INTERFACE_LVDS1;
  1492. }
  1493. }
  1494. DEBUG_MSG(KERN_INFO "LVDS Chip = %d\n",
  1495. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name);
  1496. DEBUG_MSG(KERN_INFO "LVDS1 output_interface = %d\n",
  1497. viaparinfo->chip_info->lvds_chip_info.output_interface);
  1498. DEBUG_MSG(KERN_INFO "LVDS2 output_interface = %d\n",
  1499. viaparinfo->chip_info->lvds_chip_info.output_interface);
  1500. }
  1501. void __devinit viafb_init_dac(int set_iga)
  1502. {
  1503. int i;
  1504. u8 tmp;
  1505. if (set_iga == IGA1) {
  1506. /* access Primary Display's LUT */
  1507. viafb_write_reg_mask(SR1A, VIASR, 0x00, BIT0);
  1508. /* turn off LCK */
  1509. viafb_write_reg_mask(SR1B, VIASR, 0x00, BIT7 + BIT6);
  1510. for (i = 0; i < 256; i++) {
  1511. write_dac_reg(i, palLUT_table[i].red,
  1512. palLUT_table[i].green,
  1513. palLUT_table[i].blue);
  1514. }
  1515. /* turn on LCK */
  1516. viafb_write_reg_mask(SR1B, VIASR, 0xC0, BIT7 + BIT6);
  1517. } else {
  1518. tmp = viafb_read_reg(VIACR, CR6A);
  1519. /* access Secondary Display's LUT */
  1520. viafb_write_reg_mask(CR6A, VIACR, 0x40, BIT6);
  1521. viafb_write_reg_mask(SR1A, VIASR, 0x01, BIT0);
  1522. for (i = 0; i < 256; i++) {
  1523. write_dac_reg(i, palLUT_table[i].red,
  1524. palLUT_table[i].green,
  1525. palLUT_table[i].blue);
  1526. }
  1527. /* set IGA1 DAC for default */
  1528. viafb_write_reg_mask(SR1A, VIASR, 0x00, BIT0);
  1529. viafb_write_reg(CR6A, VIACR, tmp);
  1530. }
  1531. }
  1532. static void device_screen_off(void)
  1533. {
  1534. /* turn off CRT screen (IGA1) */
  1535. viafb_write_reg_mask(SR01, VIASR, 0x20, BIT5);
  1536. }
  1537. static void device_screen_on(void)
  1538. {
  1539. /* turn on CRT screen (IGA1) */
  1540. viafb_write_reg_mask(SR01, VIASR, 0x00, BIT5);
  1541. }
  1542. static void set_display_channel(void)
  1543. {
  1544. /*If viafb_LCD2_ON, on cx700, internal lvds's information
  1545. is keeped on lvds_setting_info2 */
  1546. if (viafb_LCD2_ON &&
  1547. viaparinfo->lvds_setting_info2->device_lcd_dualedge) {
  1548. /* For dual channel LCD: */
  1549. /* Set to Dual LVDS channel. */
  1550. viafb_write_reg_mask(CRD2, VIACR, 0x20, BIT4 + BIT5);
  1551. } else if (viafb_LCD_ON && viafb_DVI_ON) {
  1552. /* For LCD+DFP: */
  1553. /* Set to LVDS1 + TMDS channel. */
  1554. viafb_write_reg_mask(CRD2, VIACR, 0x10, BIT4 + BIT5);
  1555. } else if (viafb_DVI_ON) {
  1556. /* Set to single TMDS channel. */
  1557. viafb_write_reg_mask(CRD2, VIACR, 0x30, BIT4 + BIT5);
  1558. } else if (viafb_LCD_ON) {
  1559. if (viaparinfo->lvds_setting_info->device_lcd_dualedge) {
  1560. /* For dual channel LCD: */
  1561. /* Set to Dual LVDS channel. */
  1562. viafb_write_reg_mask(CRD2, VIACR, 0x20, BIT4 + BIT5);
  1563. } else {
  1564. /* Set to LVDS0 + LVDS1 channel. */
  1565. viafb_write_reg_mask(CRD2, VIACR, 0x00, BIT4 + BIT5);
  1566. }
  1567. }
  1568. }
  1569. static u8 get_sync(struct fb_var_screeninfo *var)
  1570. {
  1571. u8 polarity = 0;
  1572. if (!(var->sync & FB_SYNC_HOR_HIGH_ACT))
  1573. polarity |= VIA_HSYNC_NEGATIVE;
  1574. if (!(var->sync & FB_SYNC_VERT_HIGH_ACT))
  1575. polarity |= VIA_VSYNC_NEGATIVE;
  1576. return polarity;
  1577. }
  1578. static void hw_init(void)
  1579. {
  1580. int i;
  1581. inb(VIAStatus);
  1582. outb(0x00, VIAAR);
  1583. /* Write Common Setting for Video Mode */
  1584. viafb_write_regx(common_vga, ARRAY_SIZE(common_vga));
  1585. switch (viaparinfo->chip_info->gfx_chip_name) {
  1586. case UNICHROME_CLE266:
  1587. viafb_write_regx(CLE266_ModeXregs, NUM_TOTAL_CLE266_ModeXregs);
  1588. break;
  1589. case UNICHROME_K400:
  1590. viafb_write_regx(KM400_ModeXregs, NUM_TOTAL_KM400_ModeXregs);
  1591. break;
  1592. case UNICHROME_K800:
  1593. case UNICHROME_PM800:
  1594. viafb_write_regx(CN400_ModeXregs, NUM_TOTAL_CN400_ModeXregs);
  1595. break;
  1596. case UNICHROME_CN700:
  1597. case UNICHROME_K8M890:
  1598. case UNICHROME_P4M890:
  1599. case UNICHROME_P4M900:
  1600. viafb_write_regx(CN700_ModeXregs, NUM_TOTAL_CN700_ModeXregs);
  1601. break;
  1602. case UNICHROME_CX700:
  1603. case UNICHROME_VX800:
  1604. viafb_write_regx(CX700_ModeXregs, NUM_TOTAL_CX700_ModeXregs);
  1605. break;
  1606. case UNICHROME_VX855:
  1607. case UNICHROME_VX900:
  1608. viafb_write_regx(VX855_ModeXregs, NUM_TOTAL_VX855_ModeXregs);
  1609. break;
  1610. }
  1611. /* magic required on VX900 for correct modesetting on IGA1 */
  1612. via_write_reg_mask(VIACR, 0x45, 0x00, 0x01);
  1613. /* probably this should go to the scaling code one day */
  1614. via_write_reg_mask(VIACR, 0xFD, 0, 0x80); /* VX900 hw scale on IGA2 */
  1615. viafb_write_regx(scaling_parameters, ARRAY_SIZE(scaling_parameters));
  1616. /* Fill VPIT Parameters */
  1617. /* Write Misc Register */
  1618. outb(VPIT.Misc, VIA_MISC_REG_WRITE);
  1619. /* Write Sequencer */
  1620. for (i = 1; i <= StdSR; i++)
  1621. via_write_reg(VIASR, i, VPIT.SR[i - 1]);
  1622. viafb_write_reg_mask(0x15, VIASR, 0xA2, 0xA2);
  1623. /* Write Graphic Controller */
  1624. for (i = 0; i < StdGR; i++)
  1625. via_write_reg(VIAGR, i, VPIT.GR[i]);
  1626. /* Write Attribute Controller */
  1627. for (i = 0; i < StdAR; i++) {
  1628. inb(VIAStatus);
  1629. outb(i, VIAAR);
  1630. outb(VPIT.AR[i], VIAAR);
  1631. }
  1632. inb(VIAStatus);
  1633. outb(0x20, VIAAR);
  1634. load_fix_bit_crtc_reg();
  1635. }
  1636. int viafb_setmode(void)
  1637. {
  1638. int j, cxres = 0, cyres = 0;
  1639. int port;
  1640. u32 devices = viaparinfo->shared->iga1_devices
  1641. | viaparinfo->shared->iga2_devices;
  1642. u8 value, index, mask;
  1643. struct fb_var_screeninfo var2;
  1644. device_screen_off();
  1645. device_off();
  1646. via_set_state(devices, VIA_STATE_OFF);
  1647. hw_init();
  1648. /* Update Patch Register */
  1649. if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266
  1650. || viaparinfo->chip_info->gfx_chip_name == UNICHROME_K400)
  1651. && viafbinfo->var.xres == 1024 && viafbinfo->var.yres == 768) {
  1652. for (j = 0; j < res_patch_table[0].table_length; j++) {
  1653. index = res_patch_table[0].io_reg_table[j].index;
  1654. port = res_patch_table[0].io_reg_table[j].port;
  1655. value = res_patch_table[0].io_reg_table[j].value;
  1656. mask = res_patch_table[0].io_reg_table[j].mask;
  1657. viafb_write_reg_mask(index, port, value, mask);
  1658. }
  1659. }
  1660. via_set_primary_pitch(viafbinfo->fix.line_length);
  1661. via_set_secondary_pitch(viafb_dual_fb ? viafbinfo1->fix.line_length
  1662. : viafbinfo->fix.line_length);
  1663. via_set_primary_color_depth(viaparinfo->depth);
  1664. via_set_secondary_color_depth(viafb_dual_fb ? viaparinfo1->depth
  1665. : viaparinfo->depth);
  1666. via_set_source(viaparinfo->shared->iga1_devices, IGA1);
  1667. via_set_source(viaparinfo->shared->iga2_devices, IGA2);
  1668. if (viaparinfo->shared->iga2_devices)
  1669. enable_second_display_channel();
  1670. else
  1671. disable_second_display_channel();
  1672. /* Update Refresh Rate Setting */
  1673. /* Clear On Screen */
  1674. if (viafb_dual_fb) {
  1675. var2 = viafbinfo1->var;
  1676. } else if (viafb_SAMM_ON) {
  1677. viafb_fill_var_timing_info(&var2, viafb_get_best_mode(
  1678. viafb_second_xres, viafb_second_yres, viafb_refresh1));
  1679. cxres = viafbinfo->var.xres;
  1680. cyres = viafbinfo->var.yres;
  1681. var2.bits_per_pixel = viafbinfo->var.bits_per_pixel;
  1682. }
  1683. /* CRT set mode */
  1684. if (viafb_CRT_ON) {
  1685. if (viaparinfo->shared->iga2_devices & VIA_CRT
  1686. && viafb_SAMM_ON)
  1687. viafb_fill_crtc_timing(&var2, cxres, cyres, IGA2);
  1688. else
  1689. viafb_fill_crtc_timing(&viafbinfo->var, 0, 0,
  1690. (viaparinfo->shared->iga1_devices & VIA_CRT)
  1691. ? IGA1 : IGA2);
  1692. /* Patch if set_hres is not 8 alignment (1366) to viafb_setmode
  1693. to 8 alignment (1368),there is several pixels (2 pixels)
  1694. on right side of screen. */
  1695. if (viafbinfo->var.xres % 8) {
  1696. viafb_unlock_crt();
  1697. viafb_write_reg(CR02, VIACR,
  1698. viafb_read_reg(VIACR, CR02) - 1);
  1699. viafb_lock_crt();
  1700. }
  1701. }
  1702. if (viafb_DVI_ON) {
  1703. if (viaparinfo->shared->tmds_setting_info.iga_path == IGA2
  1704. && viafb_SAMM_ON)
  1705. viafb_dvi_set_mode(&var2, cxres, cyres, IGA2);
  1706. else
  1707. viafb_dvi_set_mode(&viafbinfo->var, 0, 0,
  1708. viaparinfo->tmds_setting_info->iga_path);
  1709. }
  1710. if (viafb_LCD_ON) {
  1711. if (viafb_SAMM_ON &&
  1712. (viaparinfo->lvds_setting_info->iga_path == IGA2)) {
  1713. viafb_lcd_set_mode(&var2, cxres, cyres,
  1714. viaparinfo->lvds_setting_info,
  1715. &viaparinfo->chip_info->lvds_chip_info);
  1716. } else {
  1717. /* IGA1 doesn't have LCD scaling, so set it center. */
  1718. if (viaparinfo->lvds_setting_info->iga_path == IGA1) {
  1719. viaparinfo->lvds_setting_info->display_method =
  1720. LCD_CENTERING;
  1721. }
  1722. viafb_lcd_set_mode(&viafbinfo->var, 0, 0,
  1723. viaparinfo->lvds_setting_info,
  1724. &viaparinfo->chip_info->lvds_chip_info);
  1725. }
  1726. }
  1727. if (viafb_LCD2_ON) {
  1728. if (viafb_SAMM_ON &&
  1729. (viaparinfo->lvds_setting_info2->iga_path == IGA2)) {
  1730. viafb_lcd_set_mode(&var2, cxres, cyres,
  1731. viaparinfo->lvds_setting_info2,
  1732. &viaparinfo->chip_info->lvds_chip_info2);
  1733. } else {
  1734. /* IGA1 doesn't have LCD scaling, so set it center. */
  1735. if (viaparinfo->lvds_setting_info2->iga_path == IGA1) {
  1736. viaparinfo->lvds_setting_info2->display_method =
  1737. LCD_CENTERING;
  1738. }
  1739. viafb_lcd_set_mode(&viafbinfo->var, 0, 0,
  1740. viaparinfo->lvds_setting_info2,
  1741. &viaparinfo->chip_info->lvds_chip_info2);
  1742. }
  1743. }
  1744. if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700)
  1745. && (viafb_LCD_ON || viafb_DVI_ON))
  1746. set_display_channel();
  1747. /* If set mode normally, save resolution information for hot-plug . */
  1748. if (!viafb_hotplug) {
  1749. viafb_hotplug_Xres = viafbinfo->var.xres;
  1750. viafb_hotplug_Yres = viafbinfo->var.yres;
  1751. viafb_hotplug_bpp = viafbinfo->var.bits_per_pixel;
  1752. viafb_hotplug_refresh = viafb_refresh;
  1753. if (viafb_DVI_ON)
  1754. viafb_DeviceStatus = DVI_Device;
  1755. else
  1756. viafb_DeviceStatus = CRT_Device;
  1757. }
  1758. device_on();
  1759. if (!viafb_SAMM_ON)
  1760. via_set_sync_polarity(devices, get_sync(&viafbinfo->var));
  1761. else {
  1762. via_set_sync_polarity(viaparinfo->shared->iga1_devices,
  1763. get_sync(&viafbinfo->var));
  1764. via_set_sync_polarity(viaparinfo->shared->iga2_devices,
  1765. get_sync(&var2));
  1766. }
  1767. clock.set_engine_pll_state(VIA_STATE_ON);
  1768. clock.set_primary_clock_source(VIA_CLKSRC_X1, true);
  1769. clock.set_secondary_clock_source(VIA_CLKSRC_X1, true);
  1770. #ifdef CONFIG_FB_VIA_X_COMPATIBILITY
  1771. clock.set_primary_pll_state(VIA_STATE_ON);
  1772. clock.set_primary_clock_state(VIA_STATE_ON);
  1773. clock.set_secondary_pll_state(VIA_STATE_ON);
  1774. clock.set_secondary_clock_state(VIA_STATE_ON);
  1775. #else
  1776. if (viaparinfo->shared->iga1_devices) {
  1777. clock.set_primary_pll_state(VIA_STATE_ON);
  1778. clock.set_primary_clock_state(VIA_STATE_ON);
  1779. } else {
  1780. clock.set_primary_pll_state(VIA_STATE_OFF);
  1781. clock.set_primary_clock_state(VIA_STATE_OFF);
  1782. }
  1783. if (viaparinfo->shared->iga2_devices) {
  1784. clock.set_secondary_pll_state(VIA_STATE_ON);
  1785. clock.set_secondary_clock_state(VIA_STATE_ON);
  1786. } else {
  1787. clock.set_secondary_pll_state(VIA_STATE_OFF);
  1788. clock.set_secondary_clock_state(VIA_STATE_OFF);
  1789. }
  1790. #endif /*CONFIG_FB_VIA_X_COMPATIBILITY*/
  1791. via_set_state(devices, VIA_STATE_ON);
  1792. device_screen_on();
  1793. return 1;
  1794. }
  1795. int viafb_get_refresh(int hres, int vres, u32 long_refresh)
  1796. {
  1797. const struct fb_videomode *best;
  1798. best = viafb_get_best_mode(hres, vres, long_refresh);
  1799. if (!best)
  1800. return 60;
  1801. if (abs(best->refresh - long_refresh) > 3) {
  1802. if (hres == 1200 && vres == 900)
  1803. return 49; /* OLPC DCON only supports 50 Hz */
  1804. else
  1805. return 60;
  1806. }
  1807. return best->refresh;
  1808. }
  1809. static void device_off(void)
  1810. {
  1811. viafb_dvi_disable();
  1812. viafb_lcd_disable();
  1813. }
  1814. static void device_on(void)
  1815. {
  1816. if (viafb_DVI_ON == 1)
  1817. viafb_dvi_enable();
  1818. if (viafb_LCD_ON == 1)
  1819. viafb_lcd_enable();
  1820. }
  1821. static void enable_second_display_channel(void)
  1822. {
  1823. /* to enable second display channel. */
  1824. viafb_write_reg_mask(CR6A, VIACR, 0x00, BIT6);
  1825. viafb_write_reg_mask(CR6A, VIACR, BIT7, BIT7);
  1826. viafb_write_reg_mask(CR6A, VIACR, BIT6, BIT6);
  1827. }
  1828. static void disable_second_display_channel(void)
  1829. {
  1830. /* to disable second display channel. */
  1831. viafb_write_reg_mask(CR6A, VIACR, 0x00, BIT6);
  1832. viafb_write_reg_mask(CR6A, VIACR, 0x00, BIT7);
  1833. viafb_write_reg_mask(CR6A, VIACR, BIT6, BIT6);
  1834. }
  1835. void viafb_set_dpa_gfx(int output_interface, struct GFX_DPA_SETTING\
  1836. *p_gfx_dpa_setting)
  1837. {
  1838. switch (output_interface) {
  1839. case INTERFACE_DVP0:
  1840. {
  1841. /* DVP0 Clock Polarity and Adjust: */
  1842. viafb_write_reg_mask(CR96, VIACR,
  1843. p_gfx_dpa_setting->DVP0, 0x0F);
  1844. /* DVP0 Clock and Data Pads Driving: */
  1845. viafb_write_reg_mask(SR1E, VIASR,
  1846. p_gfx_dpa_setting->DVP0ClockDri_S, BIT2);
  1847. viafb_write_reg_mask(SR2A, VIASR,
  1848. p_gfx_dpa_setting->DVP0ClockDri_S1,
  1849. BIT4);
  1850. viafb_write_reg_mask(SR1B, VIASR,
  1851. p_gfx_dpa_setting->DVP0DataDri_S, BIT1);
  1852. viafb_write_reg_mask(SR2A, VIASR,
  1853. p_gfx_dpa_setting->DVP0DataDri_S1, BIT5);
  1854. break;
  1855. }
  1856. case INTERFACE_DVP1:
  1857. {
  1858. /* DVP1 Clock Polarity and Adjust: */
  1859. viafb_write_reg_mask(CR9B, VIACR,
  1860. p_gfx_dpa_setting->DVP1, 0x0F);
  1861. /* DVP1 Clock and Data Pads Driving: */
  1862. viafb_write_reg_mask(SR65, VIASR,
  1863. p_gfx_dpa_setting->DVP1Driving, 0x0F);
  1864. break;
  1865. }
  1866. case INTERFACE_DFP_HIGH:
  1867. {
  1868. viafb_write_reg_mask(CR97, VIACR,
  1869. p_gfx_dpa_setting->DFPHigh, 0x0F);
  1870. break;
  1871. }
  1872. case INTERFACE_DFP_LOW:
  1873. {
  1874. viafb_write_reg_mask(CR99, VIACR,
  1875. p_gfx_dpa_setting->DFPLow, 0x0F);
  1876. break;
  1877. }
  1878. case INTERFACE_DFP:
  1879. {
  1880. viafb_write_reg_mask(CR97, VIACR,
  1881. p_gfx_dpa_setting->DFPHigh, 0x0F);
  1882. viafb_write_reg_mask(CR99, VIACR,
  1883. p_gfx_dpa_setting->DFPLow, 0x0F);
  1884. break;
  1885. }
  1886. }
  1887. }
  1888. void viafb_fill_var_timing_info(struct fb_var_screeninfo *var,
  1889. const struct fb_videomode *mode)
  1890. {
  1891. var->pixclock = mode->pixclock;
  1892. var->xres = mode->xres;
  1893. var->yres = mode->yres;
  1894. var->left_margin = mode->left_margin;
  1895. var->right_margin = mode->right_margin;
  1896. var->hsync_len = mode->hsync_len;
  1897. var->upper_margin = mode->upper_margin;
  1898. var->lower_margin = mode->lower_margin;
  1899. var->vsync_len = mode->vsync_len;
  1900. var->sync = mode->sync;
  1901. }