hw.c 58 KB

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