hw.c 68 KB

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