viafbdev.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132
  1. /*
  2. * Copyright 1998-2009 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/module.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/slab.h>
  21. #include <linux/stat.h>
  22. #include <linux/via-core.h>
  23. #define _MASTER_FILE
  24. #include "global.h"
  25. static char *viafb_name = "Via";
  26. static u32 pseudo_pal[17];
  27. /* video mode */
  28. static char *viafb_mode;
  29. static char *viafb_mode1;
  30. static int viafb_bpp = 32;
  31. static int viafb_bpp1 = 32;
  32. static unsigned int viafb_second_offset;
  33. static int viafb_second_size;
  34. static int viafb_accel = 1;
  35. /* Added for specifying active devices.*/
  36. char *viafb_active_dev;
  37. /*Added for specify lcd output port*/
  38. char *viafb_lcd_port = "";
  39. char *viafb_dvi_port = "";
  40. static void retrieve_device_setting(struct viafb_ioctl_setting
  41. *setting_info);
  42. static int viafb_pan_display(struct fb_var_screeninfo *var,
  43. struct fb_info *info);
  44. static struct fb_ops viafb_ops;
  45. /* supported output devices on each IGP
  46. * only CX700, VX800, VX855 were documented
  47. * VIA_CRT should be everywhere
  48. * VIA_6C can be onle pre-CX700 (probably only on CLE266) as 6C is used for PLL
  49. * source selection on CX700 and later
  50. * K400 seems to support VIA_96, VIA_DVP1, VIA_LVDS{1,2} as in viamode.c
  51. */
  52. static const u32 supported_odev_map[] = {
  53. [UNICHROME_CLE266] = VIA_CRT | VIA_LDVP0 | VIA_LDVP1,
  54. [UNICHROME_K400] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
  55. | VIA_LVDS2,
  56. [UNICHROME_K800] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
  57. | VIA_LVDS2,
  58. [UNICHROME_PM800] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
  59. | VIA_LVDS2,
  60. [UNICHROME_CN700] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
  61. | VIA_LVDS2,
  62. [UNICHROME_CX700] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  63. [UNICHROME_CN750] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  64. [UNICHROME_K8M890] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  65. [UNICHROME_P4M890] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  66. [UNICHROME_P4M900] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  67. [UNICHROME_VX800] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  68. [UNICHROME_VX855] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  69. };
  70. static void viafb_fill_var_color_info(struct fb_var_screeninfo *var, u8 depth)
  71. {
  72. var->grayscale = 0;
  73. var->red.msb_right = 0;
  74. var->green.msb_right = 0;
  75. var->blue.msb_right = 0;
  76. var->transp.offset = 0;
  77. var->transp.length = 0;
  78. var->transp.msb_right = 0;
  79. var->nonstd = 0;
  80. switch (depth) {
  81. case 8:
  82. var->bits_per_pixel = 8;
  83. var->red.offset = 0;
  84. var->green.offset = 0;
  85. var->blue.offset = 0;
  86. var->red.length = 8;
  87. var->green.length = 8;
  88. var->blue.length = 8;
  89. break;
  90. case 15:
  91. var->bits_per_pixel = 16;
  92. var->red.offset = 10;
  93. var->green.offset = 5;
  94. var->blue.offset = 0;
  95. var->red.length = 5;
  96. var->green.length = 5;
  97. var->blue.length = 5;
  98. break;
  99. case 16:
  100. var->bits_per_pixel = 16;
  101. var->red.offset = 11;
  102. var->green.offset = 5;
  103. var->blue.offset = 0;
  104. var->red.length = 5;
  105. var->green.length = 6;
  106. var->blue.length = 5;
  107. break;
  108. case 24:
  109. var->bits_per_pixel = 32;
  110. var->red.offset = 16;
  111. var->green.offset = 8;
  112. var->blue.offset = 0;
  113. var->red.length = 8;
  114. var->green.length = 8;
  115. var->blue.length = 8;
  116. break;
  117. case 30:
  118. var->bits_per_pixel = 32;
  119. var->red.offset = 20;
  120. var->green.offset = 10;
  121. var->blue.offset = 0;
  122. var->red.length = 10;
  123. var->green.length = 10;
  124. var->blue.length = 10;
  125. break;
  126. }
  127. }
  128. static void viafb_update_fix(struct fb_info *info)
  129. {
  130. u32 bpp = info->var.bits_per_pixel;
  131. info->fix.visual =
  132. bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
  133. info->fix.line_length = (info->var.xres_virtual * bpp / 8 + 7) & ~7;
  134. }
  135. static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix,
  136. struct viafb_par *viaparinfo)
  137. {
  138. memset(fix, 0, sizeof(struct fb_fix_screeninfo));
  139. strcpy(fix->id, viafb_name);
  140. fix->smem_start = viaparinfo->fbmem;
  141. fix->smem_len = viaparinfo->fbmem_free;
  142. fix->type = FB_TYPE_PACKED_PIXELS;
  143. fix->type_aux = 0;
  144. fix->visual = FB_VISUAL_TRUECOLOR;
  145. fix->xpanstep = fix->ywrapstep = 0;
  146. fix->ypanstep = 1;
  147. /* Just tell the accel name */
  148. viafbinfo->fix.accel = FB_ACCEL_VIA_UNICHROME;
  149. }
  150. static int viafb_open(struct fb_info *info, int user)
  151. {
  152. DEBUG_MSG(KERN_INFO "viafb_open!\n");
  153. return 0;
  154. }
  155. static int viafb_release(struct fb_info *info, int user)
  156. {
  157. DEBUG_MSG(KERN_INFO "viafb_release!\n");
  158. return 0;
  159. }
  160. static int viafb_check_var(struct fb_var_screeninfo *var,
  161. struct fb_info *info)
  162. {
  163. int htotal, vtotal, depth;
  164. struct VideoModeTable *vmode_entry;
  165. struct viafb_par *ppar = info->par;
  166. u32 long_refresh, line;
  167. DEBUG_MSG(KERN_INFO "viafb_check_var!\n");
  168. /* Sanity check */
  169. /* HW neither support interlacte nor double-scaned mode */
  170. if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE)
  171. return -EINVAL;
  172. vmode_entry = viafb_get_mode(var->xres, var->yres);
  173. if (!vmode_entry) {
  174. DEBUG_MSG(KERN_INFO
  175. "viafb: Mode %dx%dx%d not supported!!\n",
  176. var->xres, var->yres, var->bits_per_pixel);
  177. return -EINVAL;
  178. }
  179. depth = fb_get_color_depth(var, &info->fix);
  180. if (!depth)
  181. depth = var->bits_per_pixel;
  182. if (depth < 0 || depth > 32)
  183. return -EINVAL;
  184. else if (!depth)
  185. depth = 24;
  186. else if (depth == 15 && viafb_dual_fb && ppar->iga_path == IGA1)
  187. depth = 15;
  188. else if (depth == 30)
  189. depth = 30;
  190. else if (depth <= 8)
  191. depth = 8;
  192. else if (depth <= 16)
  193. depth = 16;
  194. else
  195. depth = 24;
  196. viafb_fill_var_color_info(var, depth);
  197. line = (var->xres_virtual * var->bits_per_pixel / 8 + 7) & ~7;
  198. if (line * var->yres_virtual > ppar->memsize)
  199. return -EINVAL;
  200. /* Based on var passed in to calculate the refresh,
  201. * because our driver use some modes special.
  202. */
  203. htotal = var->xres + var->left_margin +
  204. var->right_margin + var->hsync_len;
  205. vtotal = var->yres + var->upper_margin +
  206. var->lower_margin + var->vsync_len;
  207. long_refresh = 1000000000UL / var->pixclock * 1000;
  208. long_refresh /= (htotal * vtotal);
  209. viafb_refresh = viafb_get_refresh(var->xres, var->yres, long_refresh);
  210. /* Adjust var according to our driver's own table */
  211. viafb_fill_var_timing_info(var, viafb_refresh, vmode_entry);
  212. if (var->accel_flags & FB_ACCELF_TEXT &&
  213. !ppar->shared->vdev->engine_mmio)
  214. var->accel_flags = 0;
  215. return 0;
  216. }
  217. static int viafb_set_par(struct fb_info *info)
  218. {
  219. struct viafb_par *viapar = info->par;
  220. struct VideoModeTable *vmode_entry, *vmode_entry1 = NULL;
  221. DEBUG_MSG(KERN_INFO "viafb_set_par!\n");
  222. viafb_update_fix(info);
  223. viapar->depth = fb_get_color_depth(&info->var, &info->fix);
  224. viafb_update_device_setting(viafbinfo->var.xres, viafbinfo->var.yres,
  225. viafbinfo->var.bits_per_pixel, viafb_refresh, 0);
  226. vmode_entry = viafb_get_mode(viafbinfo->var.xres, viafbinfo->var.yres);
  227. if (viafb_dual_fb) {
  228. vmode_entry1 = viafb_get_mode(viafbinfo1->var.xres,
  229. viafbinfo1->var.yres);
  230. viafb_update_device_setting(viafbinfo1->var.xres,
  231. viafbinfo1->var.yres, viafbinfo1->var.bits_per_pixel,
  232. viafb_refresh1, 1);
  233. } else if (viafb_SAMM_ON == 1) {
  234. DEBUG_MSG(KERN_INFO
  235. "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
  236. viafb_second_xres, viafb_second_yres, viafb_bpp1);
  237. vmode_entry1 = viafb_get_mode(viafb_second_xres,
  238. viafb_second_yres);
  239. viafb_update_device_setting(viafb_second_xres,
  240. viafb_second_yres, viafb_bpp1, viafb_refresh1, 1);
  241. }
  242. if (vmode_entry) {
  243. if (viafb_dual_fb && viapar->iga_path == IGA2)
  244. viafb_bpp1 = info->var.bits_per_pixel;
  245. else
  246. viafb_bpp = info->var.bits_per_pixel;
  247. if (info->var.accel_flags & FB_ACCELF_TEXT)
  248. info->flags &= ~FBINFO_HWACCEL_DISABLED;
  249. else
  250. info->flags |= FBINFO_HWACCEL_DISABLED;
  251. viafb_setmode(vmode_entry, info->var.bits_per_pixel,
  252. vmode_entry1, viafb_bpp1);
  253. viafb_pan_display(&info->var, info);
  254. }
  255. return 0;
  256. }
  257. /* Set one color register */
  258. static int viafb_setcolreg(unsigned regno, unsigned red, unsigned green,
  259. unsigned blue, unsigned transp, struct fb_info *info)
  260. {
  261. struct viafb_par *viapar = info->par;
  262. u32 r, g, b;
  263. if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
  264. if (regno > 255)
  265. return -EINVAL;
  266. if (!viafb_dual_fb || viapar->iga_path == IGA1)
  267. viafb_set_primary_color_register(regno, red >> 8,
  268. green >> 8, blue >> 8);
  269. if (!viafb_dual_fb || viapar->iga_path == IGA2)
  270. viafb_set_secondary_color_register(regno, red >> 8,
  271. green >> 8, blue >> 8);
  272. } else {
  273. if (regno > 15)
  274. return -EINVAL;
  275. r = (red >> (16 - info->var.red.length))
  276. << info->var.red.offset;
  277. b = (blue >> (16 - info->var.blue.length))
  278. << info->var.blue.offset;
  279. g = (green >> (16 - info->var.green.length))
  280. << info->var.green.offset;
  281. ((u32 *) info->pseudo_palette)[regno] = r | g | b;
  282. }
  283. return 0;
  284. }
  285. static int viafb_pan_display(struct fb_var_screeninfo *var,
  286. struct fb_info *info)
  287. {
  288. struct viafb_par *viapar = info->par;
  289. u32 vram_addr = (var->yoffset * var->xres_virtual + var->xoffset)
  290. * (var->bits_per_pixel / 8) + viapar->vram_addr;
  291. DEBUG_MSG(KERN_DEBUG "viafb_pan_display, address = %d\n", vram_addr);
  292. if (!viafb_dual_fb) {
  293. via_set_primary_address(vram_addr);
  294. via_set_secondary_address(vram_addr);
  295. } else if (viapar->iga_path == IGA1)
  296. via_set_primary_address(vram_addr);
  297. else
  298. via_set_secondary_address(vram_addr);
  299. return 0;
  300. }
  301. static int viafb_blank(int blank_mode, struct fb_info *info)
  302. {
  303. DEBUG_MSG(KERN_INFO "viafb_blank!\n");
  304. /* clear DPMS setting */
  305. switch (blank_mode) {
  306. case FB_BLANK_UNBLANK:
  307. /* Screen: On, HSync: On, VSync: On */
  308. /* control CRT monitor power management */
  309. via_set_state(VIA_CRT, VIA_STATE_ON);
  310. break;
  311. case FB_BLANK_HSYNC_SUSPEND:
  312. /* Screen: Off, HSync: Off, VSync: On */
  313. /* control CRT monitor power management */
  314. via_set_state(VIA_CRT, VIA_STATE_STANDBY);
  315. break;
  316. case FB_BLANK_VSYNC_SUSPEND:
  317. /* Screen: Off, HSync: On, VSync: Off */
  318. /* control CRT monitor power management */
  319. via_set_state(VIA_CRT, VIA_STATE_SUSPEND);
  320. break;
  321. case FB_BLANK_POWERDOWN:
  322. /* Screen: Off, HSync: Off, VSync: Off */
  323. /* control CRT monitor power management */
  324. via_set_state(VIA_CRT, VIA_STATE_OFF);
  325. break;
  326. }
  327. return 0;
  328. }
  329. static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
  330. {
  331. union {
  332. struct viafb_ioctl_mode viamode;
  333. struct viafb_ioctl_samm viasamm;
  334. struct viafb_driver_version driver_version;
  335. struct fb_var_screeninfo sec_var;
  336. struct _panel_size_pos_info panel_pos_size_para;
  337. struct viafb_ioctl_setting viafb_setting;
  338. struct device_t active_dev;
  339. } u;
  340. u32 state_info = 0;
  341. u32 *viafb_gamma_table;
  342. char driver_name[] = "viafb";
  343. u32 __user *argp = (u32 __user *) arg;
  344. u32 gpu32;
  345. DEBUG_MSG(KERN_INFO "viafb_ioctl: 0x%X !!\n", cmd);
  346. printk(KERN_WARNING "viafb_ioctl: Please avoid this interface as it is unstable and might change or vanish at any time!\n");
  347. memset(&u, 0, sizeof(u));
  348. switch (cmd) {
  349. case VIAFB_GET_CHIP_INFO:
  350. if (copy_to_user(argp, viaparinfo->chip_info,
  351. sizeof(struct chip_information)))
  352. return -EFAULT;
  353. break;
  354. case VIAFB_GET_INFO_SIZE:
  355. return put_user((u32)sizeof(struct viafb_ioctl_info), argp);
  356. case VIAFB_GET_INFO:
  357. return viafb_ioctl_get_viafb_info(arg);
  358. case VIAFB_HOTPLUG:
  359. return put_user(viafb_ioctl_hotplug(info->var.xres,
  360. info->var.yres,
  361. info->var.bits_per_pixel), argp);
  362. case VIAFB_SET_HOTPLUG_FLAG:
  363. if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
  364. return -EFAULT;
  365. viafb_hotplug = (gpu32) ? 1 : 0;
  366. break;
  367. case VIAFB_GET_RESOLUTION:
  368. u.viamode.xres = (u32) viafb_hotplug_Xres;
  369. u.viamode.yres = (u32) viafb_hotplug_Yres;
  370. u.viamode.refresh = (u32) viafb_hotplug_refresh;
  371. u.viamode.bpp = (u32) viafb_hotplug_bpp;
  372. if (viafb_SAMM_ON == 1) {
  373. u.viamode.xres_sec = viafb_second_xres;
  374. u.viamode.yres_sec = viafb_second_yres;
  375. u.viamode.virtual_xres_sec = viafb_second_virtual_xres;
  376. u.viamode.virtual_yres_sec = viafb_second_virtual_yres;
  377. u.viamode.refresh_sec = viafb_refresh1;
  378. u.viamode.bpp_sec = viafb_bpp1;
  379. } else {
  380. u.viamode.xres_sec = 0;
  381. u.viamode.yres_sec = 0;
  382. u.viamode.virtual_xres_sec = 0;
  383. u.viamode.virtual_yres_sec = 0;
  384. u.viamode.refresh_sec = 0;
  385. u.viamode.bpp_sec = 0;
  386. }
  387. if (copy_to_user(argp, &u.viamode, sizeof(u.viamode)))
  388. return -EFAULT;
  389. break;
  390. case VIAFB_GET_SAMM_INFO:
  391. u.viasamm.samm_status = viafb_SAMM_ON;
  392. if (viafb_SAMM_ON == 1) {
  393. if (viafb_dual_fb) {
  394. u.viasamm.size_prim = viaparinfo->fbmem_free;
  395. u.viasamm.size_sec = viaparinfo1->fbmem_free;
  396. } else {
  397. if (viafb_second_size) {
  398. u.viasamm.size_prim =
  399. viaparinfo->fbmem_free -
  400. viafb_second_size * 1024 * 1024;
  401. u.viasamm.size_sec =
  402. viafb_second_size * 1024 * 1024;
  403. } else {
  404. u.viasamm.size_prim =
  405. viaparinfo->fbmem_free >> 1;
  406. u.viasamm.size_sec =
  407. (viaparinfo->fbmem_free >> 1);
  408. }
  409. }
  410. u.viasamm.mem_base = viaparinfo->fbmem;
  411. u.viasamm.offset_sec = viafb_second_offset;
  412. } else {
  413. u.viasamm.size_prim =
  414. viaparinfo->memsize - viaparinfo->fbmem_used;
  415. u.viasamm.size_sec = 0;
  416. u.viasamm.mem_base = viaparinfo->fbmem;
  417. u.viasamm.offset_sec = 0;
  418. }
  419. if (copy_to_user(argp, &u.viasamm, sizeof(u.viasamm)))
  420. return -EFAULT;
  421. break;
  422. case VIAFB_TURN_ON_OUTPUT_DEVICE:
  423. if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
  424. return -EFAULT;
  425. if (gpu32 & CRT_Device)
  426. via_set_state(VIA_CRT, VIA_STATE_ON);
  427. if (gpu32 & DVI_Device)
  428. viafb_dvi_enable();
  429. if (gpu32 & LCD_Device)
  430. viafb_lcd_enable();
  431. break;
  432. case VIAFB_TURN_OFF_OUTPUT_DEVICE:
  433. if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
  434. return -EFAULT;
  435. if (gpu32 & CRT_Device)
  436. via_set_state(VIA_CRT, VIA_STATE_OFF);
  437. if (gpu32 & DVI_Device)
  438. viafb_dvi_disable();
  439. if (gpu32 & LCD_Device)
  440. viafb_lcd_disable();
  441. break;
  442. case VIAFB_GET_DEVICE:
  443. u.active_dev.crt = viafb_CRT_ON;
  444. u.active_dev.dvi = viafb_DVI_ON;
  445. u.active_dev.lcd = viafb_LCD_ON;
  446. u.active_dev.samm = viafb_SAMM_ON;
  447. u.active_dev.primary_dev = viafb_primary_dev;
  448. u.active_dev.lcd_dsp_cent = viafb_lcd_dsp_method;
  449. u.active_dev.lcd_panel_id = viafb_lcd_panel_id;
  450. u.active_dev.lcd_mode = viafb_lcd_mode;
  451. u.active_dev.xres = viafb_hotplug_Xres;
  452. u.active_dev.yres = viafb_hotplug_Yres;
  453. u.active_dev.xres1 = viafb_second_xres;
  454. u.active_dev.yres1 = viafb_second_yres;
  455. u.active_dev.bpp = viafb_bpp;
  456. u.active_dev.bpp1 = viafb_bpp1;
  457. u.active_dev.refresh = viafb_refresh;
  458. u.active_dev.refresh1 = viafb_refresh1;
  459. u.active_dev.epia_dvi = viafb_platform_epia_dvi;
  460. u.active_dev.lcd_dual_edge = viafb_device_lcd_dualedge;
  461. u.active_dev.bus_width = viafb_bus_width;
  462. if (copy_to_user(argp, &u.active_dev, sizeof(u.active_dev)))
  463. return -EFAULT;
  464. break;
  465. case VIAFB_GET_DRIVER_VERSION:
  466. u.driver_version.iMajorNum = VERSION_MAJOR;
  467. u.driver_version.iKernelNum = VERSION_KERNEL;
  468. u.driver_version.iOSNum = VERSION_OS;
  469. u.driver_version.iMinorNum = VERSION_MINOR;
  470. if (copy_to_user(argp, &u.driver_version,
  471. sizeof(u.driver_version)))
  472. return -EFAULT;
  473. break;
  474. case VIAFB_GET_DEVICE_INFO:
  475. retrieve_device_setting(&u.viafb_setting);
  476. if (copy_to_user(argp, &u.viafb_setting,
  477. sizeof(u.viafb_setting)))
  478. return -EFAULT;
  479. break;
  480. case VIAFB_GET_DEVICE_SUPPORT:
  481. viafb_get_device_support_state(&state_info);
  482. if (put_user(state_info, argp))
  483. return -EFAULT;
  484. break;
  485. case VIAFB_GET_DEVICE_CONNECT:
  486. viafb_get_device_connect_state(&state_info);
  487. if (put_user(state_info, argp))
  488. return -EFAULT;
  489. break;
  490. case VIAFB_GET_PANEL_SUPPORT_EXPAND:
  491. state_info =
  492. viafb_lcd_get_support_expand_state(info->var.xres,
  493. info->var.yres);
  494. if (put_user(state_info, argp))
  495. return -EFAULT;
  496. break;
  497. case VIAFB_GET_DRIVER_NAME:
  498. if (copy_to_user(argp, driver_name, sizeof(driver_name)))
  499. return -EFAULT;
  500. break;
  501. case VIAFB_SET_GAMMA_LUT:
  502. viafb_gamma_table = memdup_user(argp, 256 * sizeof(u32));
  503. if (IS_ERR(viafb_gamma_table))
  504. return PTR_ERR(viafb_gamma_table);
  505. viafb_set_gamma_table(viafb_bpp, viafb_gamma_table);
  506. kfree(viafb_gamma_table);
  507. break;
  508. case VIAFB_GET_GAMMA_LUT:
  509. viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);
  510. if (!viafb_gamma_table)
  511. return -ENOMEM;
  512. viafb_get_gamma_table(viafb_gamma_table);
  513. if (copy_to_user(argp, viafb_gamma_table,
  514. 256 * sizeof(u32))) {
  515. kfree(viafb_gamma_table);
  516. return -EFAULT;
  517. }
  518. kfree(viafb_gamma_table);
  519. break;
  520. case VIAFB_GET_GAMMA_SUPPORT_STATE:
  521. viafb_get_gamma_support_state(viafb_bpp, &state_info);
  522. if (put_user(state_info, argp))
  523. return -EFAULT;
  524. break;
  525. case VIAFB_SYNC_SURFACE:
  526. DEBUG_MSG(KERN_INFO "lobo VIAFB_SYNC_SURFACE\n");
  527. break;
  528. case VIAFB_GET_DRIVER_CAPS:
  529. break;
  530. case VIAFB_GET_PANEL_MAX_SIZE:
  531. if (copy_from_user(&u.panel_pos_size_para, argp,
  532. sizeof(u.panel_pos_size_para)))
  533. return -EFAULT;
  534. u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
  535. if (copy_to_user(argp, &u.panel_pos_size_para,
  536. sizeof(u.panel_pos_size_para)))
  537. return -EFAULT;
  538. break;
  539. case VIAFB_GET_PANEL_MAX_POSITION:
  540. if (copy_from_user(&u.panel_pos_size_para, argp,
  541. sizeof(u.panel_pos_size_para)))
  542. return -EFAULT;
  543. u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
  544. if (copy_to_user(argp, &u.panel_pos_size_para,
  545. sizeof(u.panel_pos_size_para)))
  546. return -EFAULT;
  547. break;
  548. case VIAFB_GET_PANEL_POSITION:
  549. if (copy_from_user(&u.panel_pos_size_para, argp,
  550. sizeof(u.panel_pos_size_para)))
  551. return -EFAULT;
  552. u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
  553. if (copy_to_user(argp, &u.panel_pos_size_para,
  554. sizeof(u.panel_pos_size_para)))
  555. return -EFAULT;
  556. break;
  557. case VIAFB_GET_PANEL_SIZE:
  558. if (copy_from_user(&u.panel_pos_size_para, argp,
  559. sizeof(u.panel_pos_size_para)))
  560. return -EFAULT;
  561. u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
  562. if (copy_to_user(argp, &u.panel_pos_size_para,
  563. sizeof(u.panel_pos_size_para)))
  564. return -EFAULT;
  565. break;
  566. case VIAFB_SET_PANEL_POSITION:
  567. if (copy_from_user(&u.panel_pos_size_para, argp,
  568. sizeof(u.panel_pos_size_para)))
  569. return -EFAULT;
  570. break;
  571. case VIAFB_SET_PANEL_SIZE:
  572. if (copy_from_user(&u.panel_pos_size_para, argp,
  573. sizeof(u.panel_pos_size_para)))
  574. return -EFAULT;
  575. break;
  576. default:
  577. return -EINVAL;
  578. }
  579. return 0;
  580. }
  581. static void viafb_fillrect(struct fb_info *info,
  582. const struct fb_fillrect *rect)
  583. {
  584. struct viafb_par *viapar = info->par;
  585. struct viafb_shared *shared = viapar->shared;
  586. u32 fg_color;
  587. u8 rop;
  588. if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt) {
  589. cfb_fillrect(info, rect);
  590. return;
  591. }
  592. if (!rect->width || !rect->height)
  593. return;
  594. if (info->fix.visual == FB_VISUAL_TRUECOLOR)
  595. fg_color = ((u32 *)info->pseudo_palette)[rect->color];
  596. else
  597. fg_color = rect->color;
  598. if (rect->rop == ROP_XOR)
  599. rop = 0x5A;
  600. else
  601. rop = 0xF0;
  602. DEBUG_MSG(KERN_DEBUG "viafb 2D engine: fillrect\n");
  603. if (shared->hw_bitblt(shared->vdev->engine_mmio, VIA_BITBLT_FILL,
  604. rect->width, rect->height, info->var.bits_per_pixel,
  605. viapar->vram_addr, info->fix.line_length, rect->dx, rect->dy,
  606. NULL, 0, 0, 0, 0, fg_color, 0, rop))
  607. cfb_fillrect(info, rect);
  608. }
  609. static void viafb_copyarea(struct fb_info *info,
  610. const struct fb_copyarea *area)
  611. {
  612. struct viafb_par *viapar = info->par;
  613. struct viafb_shared *shared = viapar->shared;
  614. if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt) {
  615. cfb_copyarea(info, area);
  616. return;
  617. }
  618. if (!area->width || !area->height)
  619. return;
  620. DEBUG_MSG(KERN_DEBUG "viafb 2D engine: copyarea\n");
  621. if (shared->hw_bitblt(shared->vdev->engine_mmio, VIA_BITBLT_COLOR,
  622. area->width, area->height, info->var.bits_per_pixel,
  623. viapar->vram_addr, info->fix.line_length, area->dx, area->dy,
  624. NULL, viapar->vram_addr, info->fix.line_length,
  625. area->sx, area->sy, 0, 0, 0))
  626. cfb_copyarea(info, area);
  627. }
  628. static void viafb_imageblit(struct fb_info *info,
  629. const struct fb_image *image)
  630. {
  631. struct viafb_par *viapar = info->par;
  632. struct viafb_shared *shared = viapar->shared;
  633. u32 fg_color = 0, bg_color = 0;
  634. u8 op;
  635. if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt ||
  636. (image->depth != 1 && image->depth != viapar->depth)) {
  637. cfb_imageblit(info, image);
  638. return;
  639. }
  640. if (image->depth == 1) {
  641. op = VIA_BITBLT_MONO;
  642. if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
  643. fg_color =
  644. ((u32 *)info->pseudo_palette)[image->fg_color];
  645. bg_color =
  646. ((u32 *)info->pseudo_palette)[image->bg_color];
  647. } else {
  648. fg_color = image->fg_color;
  649. bg_color = image->bg_color;
  650. }
  651. } else
  652. op = VIA_BITBLT_COLOR;
  653. DEBUG_MSG(KERN_DEBUG "viafb 2D engine: imageblit\n");
  654. if (shared->hw_bitblt(shared->vdev->engine_mmio, op,
  655. image->width, image->height, info->var.bits_per_pixel,
  656. viapar->vram_addr, info->fix.line_length, image->dx, image->dy,
  657. (u32 *)image->data, 0, 0, 0, 0, fg_color, bg_color, 0))
  658. cfb_imageblit(info, image);
  659. }
  660. static int viafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  661. {
  662. struct viafb_par *viapar = info->par;
  663. void __iomem *engine = viapar->shared->vdev->engine_mmio;
  664. u32 temp, xx, yy, bg_color = 0, fg_color = 0,
  665. chip_name = viapar->shared->chip_info.gfx_chip_name;
  666. int i, j = 0, cur_size = 64;
  667. if (info->flags & FBINFO_HWACCEL_DISABLED || info != viafbinfo)
  668. return -ENODEV;
  669. /* LCD ouput does not support hw cursors (at least on VN896) */
  670. if ((chip_name == UNICHROME_CLE266 && viapar->iga_path == IGA2) ||
  671. viafb_LCD_ON)
  672. return -ENODEV;
  673. viafb_show_hw_cursor(info, HW_Cursor_OFF);
  674. if (cursor->set & FB_CUR_SETHOT) {
  675. temp = (cursor->hot.x << 16) + cursor->hot.y;
  676. writel(temp, engine + VIA_REG_CURSOR_ORG);
  677. }
  678. if (cursor->set & FB_CUR_SETPOS) {
  679. yy = cursor->image.dy - info->var.yoffset;
  680. xx = cursor->image.dx - info->var.xoffset;
  681. temp = yy & 0xFFFF;
  682. temp |= (xx << 16);
  683. writel(temp, engine + VIA_REG_CURSOR_POS);
  684. }
  685. if (cursor->image.width <= 32 && cursor->image.height <= 32)
  686. cur_size = 32;
  687. else if (cursor->image.width <= 64 && cursor->image.height <= 64)
  688. cur_size = 64;
  689. else {
  690. printk(KERN_WARNING "viafb_cursor: The cursor is too large "
  691. "%dx%d", cursor->image.width, cursor->image.height);
  692. return -ENXIO;
  693. }
  694. if (cursor->set & FB_CUR_SETSIZE) {
  695. temp = readl(engine + VIA_REG_CURSOR_MODE);
  696. if (cur_size == 32)
  697. temp |= 0x2;
  698. else
  699. temp &= ~0x2;
  700. writel(temp, engine + VIA_REG_CURSOR_MODE);
  701. }
  702. if (cursor->set & FB_CUR_SETCMAP) {
  703. fg_color = cursor->image.fg_color;
  704. bg_color = cursor->image.bg_color;
  705. if (chip_name == UNICHROME_CX700 ||
  706. chip_name == UNICHROME_VX800 ||
  707. chip_name == UNICHROME_VX855) {
  708. fg_color =
  709. ((info->cmap.red[fg_color] & 0xFFC0) << 14) |
  710. ((info->cmap.green[fg_color] & 0xFFC0) << 4) |
  711. ((info->cmap.blue[fg_color] & 0xFFC0) >> 6);
  712. bg_color =
  713. ((info->cmap.red[bg_color] & 0xFFC0) << 14) |
  714. ((info->cmap.green[bg_color] & 0xFFC0) << 4) |
  715. ((info->cmap.blue[bg_color] & 0xFFC0) >> 6);
  716. } else {
  717. fg_color =
  718. ((info->cmap.red[fg_color] & 0xFF00) << 8) |
  719. (info->cmap.green[fg_color] & 0xFF00) |
  720. ((info->cmap.blue[fg_color] & 0xFF00) >> 8);
  721. bg_color =
  722. ((info->cmap.red[bg_color] & 0xFF00) << 8) |
  723. (info->cmap.green[bg_color] & 0xFF00) |
  724. ((info->cmap.blue[bg_color] & 0xFF00) >> 8);
  725. }
  726. writel(bg_color, engine + VIA_REG_CURSOR_BG);
  727. writel(fg_color, engine + VIA_REG_CURSOR_FG);
  728. }
  729. if (cursor->set & FB_CUR_SETSHAPE) {
  730. struct {
  731. u8 data[CURSOR_SIZE];
  732. u32 bak[CURSOR_SIZE / 4];
  733. } *cr_data = kzalloc(sizeof(*cr_data), GFP_ATOMIC);
  734. int size = ((cursor->image.width + 7) >> 3) *
  735. cursor->image.height;
  736. if (!cr_data)
  737. return -ENOMEM;
  738. if (cur_size == 32) {
  739. for (i = 0; i < (CURSOR_SIZE / 4); i++) {
  740. cr_data->bak[i] = 0x0;
  741. cr_data->bak[i + 1] = 0xFFFFFFFF;
  742. i += 1;
  743. }
  744. } else {
  745. for (i = 0; i < (CURSOR_SIZE / 4); i++) {
  746. cr_data->bak[i] = 0x0;
  747. cr_data->bak[i + 1] = 0x0;
  748. cr_data->bak[i + 2] = 0xFFFFFFFF;
  749. cr_data->bak[i + 3] = 0xFFFFFFFF;
  750. i += 3;
  751. }
  752. }
  753. switch (cursor->rop) {
  754. case ROP_XOR:
  755. for (i = 0; i < size; i++)
  756. cr_data->data[i] = cursor->mask[i];
  757. break;
  758. case ROP_COPY:
  759. for (i = 0; i < size; i++)
  760. cr_data->data[i] = cursor->mask[i];
  761. break;
  762. default:
  763. break;
  764. }
  765. if (cur_size == 32) {
  766. for (i = 0; i < size; i++) {
  767. cr_data->bak[j] = (u32) cr_data->data[i];
  768. cr_data->bak[j + 1] = ~cr_data->bak[j];
  769. j += 2;
  770. }
  771. } else {
  772. for (i = 0; i < size; i++) {
  773. cr_data->bak[j] = (u32) cr_data->data[i];
  774. cr_data->bak[j + 1] = 0x0;
  775. cr_data->bak[j + 2] = ~cr_data->bak[j];
  776. cr_data->bak[j + 3] = ~cr_data->bak[j + 1];
  777. j += 4;
  778. }
  779. }
  780. memcpy_toio(viafbinfo->screen_base + viapar->shared->
  781. cursor_vram_addr, cr_data->bak, CURSOR_SIZE);
  782. kfree(cr_data);
  783. }
  784. if (cursor->enable)
  785. viafb_show_hw_cursor(info, HW_Cursor_ON);
  786. return 0;
  787. }
  788. static int viafb_sync(struct fb_info *info)
  789. {
  790. if (!(info->flags & FBINFO_HWACCEL_DISABLED))
  791. viafb_wait_engine_idle(info);
  792. return 0;
  793. }
  794. static int get_primary_device(void)
  795. {
  796. int primary_device = 0;
  797. /* Rule: device on iga1 path are the primary device. */
  798. if (viafb_SAMM_ON) {
  799. if (viafb_CRT_ON) {
  800. if (viaparinfo->crt_setting_info->iga_path == IGA1) {
  801. DEBUG_MSG(KERN_INFO "CRT IGA Path:%d\n",
  802. viaparinfo->
  803. crt_setting_info->iga_path);
  804. primary_device = CRT_Device;
  805. }
  806. }
  807. if (viafb_DVI_ON) {
  808. if (viaparinfo->tmds_setting_info->iga_path == IGA1) {
  809. DEBUG_MSG(KERN_INFO "DVI IGA Path:%d\n",
  810. viaparinfo->
  811. tmds_setting_info->iga_path);
  812. primary_device = DVI_Device;
  813. }
  814. }
  815. if (viafb_LCD_ON) {
  816. if (viaparinfo->lvds_setting_info->iga_path == IGA1) {
  817. DEBUG_MSG(KERN_INFO "LCD IGA Path:%d\n",
  818. viaparinfo->
  819. lvds_setting_info->iga_path);
  820. primary_device = LCD_Device;
  821. }
  822. }
  823. if (viafb_LCD2_ON) {
  824. if (viaparinfo->lvds_setting_info2->iga_path == IGA1) {
  825. DEBUG_MSG(KERN_INFO "LCD2 IGA Path:%d\n",
  826. viaparinfo->
  827. lvds_setting_info2->iga_path);
  828. primary_device = LCD2_Device;
  829. }
  830. }
  831. }
  832. return primary_device;
  833. }
  834. static void retrieve_device_setting(struct viafb_ioctl_setting
  835. *setting_info)
  836. {
  837. /* get device status */
  838. if (viafb_CRT_ON == 1)
  839. setting_info->device_status = CRT_Device;
  840. if (viafb_DVI_ON == 1)
  841. setting_info->device_status |= DVI_Device;
  842. if (viafb_LCD_ON == 1)
  843. setting_info->device_status |= LCD_Device;
  844. if (viafb_LCD2_ON == 1)
  845. setting_info->device_status |= LCD2_Device;
  846. setting_info->samm_status = viafb_SAMM_ON;
  847. setting_info->primary_device = get_primary_device();
  848. setting_info->first_dev_bpp = viafb_bpp;
  849. setting_info->second_dev_bpp = viafb_bpp1;
  850. setting_info->first_dev_refresh = viafb_refresh;
  851. setting_info->second_dev_refresh = viafb_refresh1;
  852. setting_info->first_dev_hor_res = viafb_hotplug_Xres;
  853. setting_info->first_dev_ver_res = viafb_hotplug_Yres;
  854. setting_info->second_dev_hor_res = viafb_second_xres;
  855. setting_info->second_dev_ver_res = viafb_second_yres;
  856. /* Get lcd attributes */
  857. setting_info->lcd_attributes.display_center = viafb_lcd_dsp_method;
  858. setting_info->lcd_attributes.panel_id = viafb_lcd_panel_id;
  859. setting_info->lcd_attributes.lcd_mode = viafb_lcd_mode;
  860. }
  861. static int __init parse_active_dev(void)
  862. {
  863. viafb_CRT_ON = STATE_OFF;
  864. viafb_DVI_ON = STATE_OFF;
  865. viafb_LCD_ON = STATE_OFF;
  866. viafb_LCD2_ON = STATE_OFF;
  867. /* 1. Modify the active status of devices. */
  868. /* 2. Keep the order of devices, so we can set corresponding
  869. IGA path to devices in SAMM case. */
  870. /* Note: The previous of active_dev is primary device,
  871. and the following is secondary device. */
  872. if (!viafb_active_dev) {
  873. viafb_CRT_ON = STATE_ON;
  874. viafb_SAMM_ON = STATE_OFF;
  875. } else if (!strcmp(viafb_active_dev, "CRT+DVI")) {
  876. /* CRT+DVI */
  877. viafb_CRT_ON = STATE_ON;
  878. viafb_DVI_ON = STATE_ON;
  879. viafb_primary_dev = CRT_Device;
  880. } else if (!strcmp(viafb_active_dev, "DVI+CRT")) {
  881. /* DVI+CRT */
  882. viafb_CRT_ON = STATE_ON;
  883. viafb_DVI_ON = STATE_ON;
  884. viafb_primary_dev = DVI_Device;
  885. } else if (!strcmp(viafb_active_dev, "CRT+LCD")) {
  886. /* CRT+LCD */
  887. viafb_CRT_ON = STATE_ON;
  888. viafb_LCD_ON = STATE_ON;
  889. viafb_primary_dev = CRT_Device;
  890. } else if (!strcmp(viafb_active_dev, "LCD+CRT")) {
  891. /* LCD+CRT */
  892. viafb_CRT_ON = STATE_ON;
  893. viafb_LCD_ON = STATE_ON;
  894. viafb_primary_dev = LCD_Device;
  895. } else if (!strcmp(viafb_active_dev, "DVI+LCD")) {
  896. /* DVI+LCD */
  897. viafb_DVI_ON = STATE_ON;
  898. viafb_LCD_ON = STATE_ON;
  899. viafb_primary_dev = DVI_Device;
  900. } else if (!strcmp(viafb_active_dev, "LCD+DVI")) {
  901. /* LCD+DVI */
  902. viafb_DVI_ON = STATE_ON;
  903. viafb_LCD_ON = STATE_ON;
  904. viafb_primary_dev = LCD_Device;
  905. } else if (!strcmp(viafb_active_dev, "LCD+LCD2")) {
  906. viafb_LCD_ON = STATE_ON;
  907. viafb_LCD2_ON = STATE_ON;
  908. viafb_primary_dev = LCD_Device;
  909. } else if (!strcmp(viafb_active_dev, "LCD2+LCD")) {
  910. viafb_LCD_ON = STATE_ON;
  911. viafb_LCD2_ON = STATE_ON;
  912. viafb_primary_dev = LCD2_Device;
  913. } else if (!strcmp(viafb_active_dev, "CRT")) {
  914. /* CRT only */
  915. viafb_CRT_ON = STATE_ON;
  916. viafb_SAMM_ON = STATE_OFF;
  917. } else if (!strcmp(viafb_active_dev, "DVI")) {
  918. /* DVI only */
  919. viafb_DVI_ON = STATE_ON;
  920. viafb_SAMM_ON = STATE_OFF;
  921. } else if (!strcmp(viafb_active_dev, "LCD")) {
  922. /* LCD only */
  923. viafb_LCD_ON = STATE_ON;
  924. viafb_SAMM_ON = STATE_OFF;
  925. } else
  926. return -EINVAL;
  927. return 0;
  928. }
  929. static int __devinit parse_port(char *opt_str, int *output_interface)
  930. {
  931. if (!strncmp(opt_str, "DVP0", 4))
  932. *output_interface = INTERFACE_DVP0;
  933. else if (!strncmp(opt_str, "DVP1", 4))
  934. *output_interface = INTERFACE_DVP1;
  935. else if (!strncmp(opt_str, "DFP_HIGHLOW", 11))
  936. *output_interface = INTERFACE_DFP;
  937. else if (!strncmp(opt_str, "DFP_HIGH", 8))
  938. *output_interface = INTERFACE_DFP_HIGH;
  939. else if (!strncmp(opt_str, "DFP_LOW", 7))
  940. *output_interface = INTERFACE_DFP_LOW;
  941. else
  942. *output_interface = INTERFACE_NONE;
  943. return 0;
  944. }
  945. static void __devinit parse_lcd_port(void)
  946. {
  947. parse_port(viafb_lcd_port, &viaparinfo->chip_info->lvds_chip_info.
  948. output_interface);
  949. /*Initialize to avoid unexpected behavior */
  950. viaparinfo->chip_info->lvds_chip_info2.output_interface =
  951. INTERFACE_NONE;
  952. DEBUG_MSG(KERN_INFO "parse_lcd_port: viafb_lcd_port:%s,interface:%d\n",
  953. viafb_lcd_port, viaparinfo->chip_info->lvds_chip_info.
  954. output_interface);
  955. }
  956. static void __devinit parse_dvi_port(void)
  957. {
  958. parse_port(viafb_dvi_port, &viaparinfo->chip_info->tmds_chip_info.
  959. output_interface);
  960. DEBUG_MSG(KERN_INFO "parse_dvi_port: viafb_dvi_port:%s,interface:%d\n",
  961. viafb_dvi_port, viaparinfo->chip_info->tmds_chip_info.
  962. output_interface);
  963. }
  964. #ifdef CONFIG_FB_VIA_DIRECT_PROCFS
  965. /*
  966. * The proc filesystem read/write function, a simple proc implement to
  967. * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
  968. * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2],
  969. * CR9B, SR65, CR97, CR99
  970. */
  971. static int viafb_dvp0_proc_show(struct seq_file *m, void *v)
  972. {
  973. u8 dvp0_data_dri = 0, dvp0_clk_dri = 0, dvp0 = 0;
  974. dvp0_data_dri =
  975. (viafb_read_reg(VIASR, SR2A) & BIT5) >> 4 |
  976. (viafb_read_reg(VIASR, SR1B) & BIT1) >> 1;
  977. dvp0_clk_dri =
  978. (viafb_read_reg(VIASR, SR2A) & BIT4) >> 3 |
  979. (viafb_read_reg(VIASR, SR1E) & BIT2) >> 2;
  980. dvp0 = viafb_read_reg(VIACR, CR96) & 0x0f;
  981. seq_printf(m, "%x %x %x\n", dvp0, dvp0_data_dri, dvp0_clk_dri);
  982. return 0;
  983. }
  984. static int viafb_dvp0_proc_open(struct inode *inode, struct file *file)
  985. {
  986. return single_open(file, viafb_dvp0_proc_show, NULL);
  987. }
  988. static ssize_t viafb_dvp0_proc_write(struct file *file,
  989. const char __user *buffer, size_t count, loff_t *pos)
  990. {
  991. char buf[20], *value, *pbuf;
  992. u8 reg_val = 0;
  993. unsigned long length, i;
  994. if (count < 1)
  995. return -EINVAL;
  996. length = count > 20 ? 20 : count;
  997. if (copy_from_user(&buf[0], buffer, length))
  998. return -EFAULT;
  999. buf[length - 1] = '\0'; /*Ensure end string */
  1000. pbuf = &buf[0];
  1001. for (i = 0; i < 3; i++) {
  1002. value = strsep(&pbuf, " ");
  1003. if (value != NULL) {
  1004. strict_strtoul(value, 0, (unsigned long *)&reg_val);
  1005. DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
  1006. reg_val);
  1007. switch (i) {
  1008. case 0:
  1009. viafb_write_reg_mask(CR96, VIACR,
  1010. reg_val, 0x0f);
  1011. break;
  1012. case 1:
  1013. viafb_write_reg_mask(SR2A, VIASR,
  1014. reg_val << 4, BIT5);
  1015. viafb_write_reg_mask(SR1B, VIASR,
  1016. reg_val << 1, BIT1);
  1017. break;
  1018. case 2:
  1019. viafb_write_reg_mask(SR2A, VIASR,
  1020. reg_val << 3, BIT4);
  1021. viafb_write_reg_mask(SR1E, VIASR,
  1022. reg_val << 2, BIT2);
  1023. break;
  1024. default:
  1025. break;
  1026. }
  1027. } else {
  1028. break;
  1029. }
  1030. }
  1031. return count;
  1032. }
  1033. static const struct file_operations viafb_dvp0_proc_fops = {
  1034. .owner = THIS_MODULE,
  1035. .open = viafb_dvp0_proc_open,
  1036. .read = seq_read,
  1037. .llseek = seq_lseek,
  1038. .release = single_release,
  1039. .write = viafb_dvp0_proc_write,
  1040. };
  1041. static int viafb_dvp1_proc_show(struct seq_file *m, void *v)
  1042. {
  1043. u8 dvp1 = 0, dvp1_data_dri = 0, dvp1_clk_dri = 0;
  1044. dvp1 = viafb_read_reg(VIACR, CR9B) & 0x0f;
  1045. dvp1_data_dri = (viafb_read_reg(VIASR, SR65) & 0x0c) >> 2;
  1046. dvp1_clk_dri = viafb_read_reg(VIASR, SR65) & 0x03;
  1047. seq_printf(m, "%x %x %x\n", dvp1, dvp1_data_dri, dvp1_clk_dri);
  1048. return 0;
  1049. }
  1050. static int viafb_dvp1_proc_open(struct inode *inode, struct file *file)
  1051. {
  1052. return single_open(file, viafb_dvp1_proc_show, NULL);
  1053. }
  1054. static ssize_t viafb_dvp1_proc_write(struct file *file,
  1055. const char __user *buffer, size_t count, loff_t *pos)
  1056. {
  1057. char buf[20], *value, *pbuf;
  1058. u8 reg_val = 0;
  1059. unsigned long length, i;
  1060. if (count < 1)
  1061. return -EINVAL;
  1062. length = count > 20 ? 20 : count;
  1063. if (copy_from_user(&buf[0], buffer, length))
  1064. return -EFAULT;
  1065. buf[length - 1] = '\0'; /*Ensure end string */
  1066. pbuf = &buf[0];
  1067. for (i = 0; i < 3; i++) {
  1068. value = strsep(&pbuf, " ");
  1069. if (value != NULL) {
  1070. strict_strtoul(value, 0, (unsigned long *)&reg_val);
  1071. switch (i) {
  1072. case 0:
  1073. viafb_write_reg_mask(CR9B, VIACR,
  1074. reg_val, 0x0f);
  1075. break;
  1076. case 1:
  1077. viafb_write_reg_mask(SR65, VIASR,
  1078. reg_val << 2, 0x0c);
  1079. break;
  1080. case 2:
  1081. viafb_write_reg_mask(SR65, VIASR,
  1082. reg_val, 0x03);
  1083. break;
  1084. default:
  1085. break;
  1086. }
  1087. } else {
  1088. break;
  1089. }
  1090. }
  1091. return count;
  1092. }
  1093. static const struct file_operations viafb_dvp1_proc_fops = {
  1094. .owner = THIS_MODULE,
  1095. .open = viafb_dvp1_proc_open,
  1096. .read = seq_read,
  1097. .llseek = seq_lseek,
  1098. .release = single_release,
  1099. .write = viafb_dvp1_proc_write,
  1100. };
  1101. static int viafb_dfph_proc_show(struct seq_file *m, void *v)
  1102. {
  1103. u8 dfp_high = 0;
  1104. dfp_high = viafb_read_reg(VIACR, CR97) & 0x0f;
  1105. seq_printf(m, "%x\n", dfp_high);
  1106. return 0;
  1107. }
  1108. static int viafb_dfph_proc_open(struct inode *inode, struct file *file)
  1109. {
  1110. return single_open(file, viafb_dfph_proc_show, NULL);
  1111. }
  1112. static ssize_t viafb_dfph_proc_write(struct file *file,
  1113. const char __user *buffer, size_t count, loff_t *pos)
  1114. {
  1115. char buf[20];
  1116. u8 reg_val = 0;
  1117. unsigned long length;
  1118. if (count < 1)
  1119. return -EINVAL;
  1120. length = count > 20 ? 20 : count;
  1121. if (copy_from_user(&buf[0], buffer, length))
  1122. return -EFAULT;
  1123. buf[length - 1] = '\0'; /*Ensure end string */
  1124. strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
  1125. viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
  1126. return count;
  1127. }
  1128. static const struct file_operations viafb_dfph_proc_fops = {
  1129. .owner = THIS_MODULE,
  1130. .open = viafb_dfph_proc_open,
  1131. .read = seq_read,
  1132. .llseek = seq_lseek,
  1133. .release = single_release,
  1134. .write = viafb_dfph_proc_write,
  1135. };
  1136. static int viafb_dfpl_proc_show(struct seq_file *m, void *v)
  1137. {
  1138. u8 dfp_low = 0;
  1139. dfp_low = viafb_read_reg(VIACR, CR99) & 0x0f;
  1140. seq_printf(m, "%x\n", dfp_low);
  1141. return 0;
  1142. }
  1143. static int viafb_dfpl_proc_open(struct inode *inode, struct file *file)
  1144. {
  1145. return single_open(file, viafb_dfpl_proc_show, NULL);
  1146. }
  1147. static ssize_t viafb_dfpl_proc_write(struct file *file,
  1148. const char __user *buffer, size_t count, loff_t *pos)
  1149. {
  1150. char buf[20];
  1151. u8 reg_val = 0;
  1152. unsigned long length;
  1153. if (count < 1)
  1154. return -EINVAL;
  1155. length = count > 20 ? 20 : count;
  1156. if (copy_from_user(&buf[0], buffer, length))
  1157. return -EFAULT;
  1158. buf[length - 1] = '\0'; /*Ensure end string */
  1159. strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
  1160. viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
  1161. return count;
  1162. }
  1163. static const struct file_operations viafb_dfpl_proc_fops = {
  1164. .owner = THIS_MODULE,
  1165. .open = viafb_dfpl_proc_open,
  1166. .read = seq_read,
  1167. .llseek = seq_lseek,
  1168. .release = single_release,
  1169. .write = viafb_dfpl_proc_write,
  1170. };
  1171. static int viafb_vt1636_proc_show(struct seq_file *m, void *v)
  1172. {
  1173. u8 vt1636_08 = 0, vt1636_09 = 0;
  1174. switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
  1175. case VT1636_LVDS:
  1176. vt1636_08 =
  1177. viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
  1178. &viaparinfo->chip_info->lvds_chip_info, 0x08) & 0x0f;
  1179. vt1636_09 =
  1180. viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
  1181. &viaparinfo->chip_info->lvds_chip_info, 0x09) & 0x1f;
  1182. seq_printf(m, "%x %x\n", vt1636_08, vt1636_09);
  1183. break;
  1184. default:
  1185. break;
  1186. }
  1187. switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
  1188. case VT1636_LVDS:
  1189. vt1636_08 =
  1190. viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
  1191. &viaparinfo->chip_info->lvds_chip_info2, 0x08) & 0x0f;
  1192. vt1636_09 =
  1193. viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
  1194. &viaparinfo->chip_info->lvds_chip_info2, 0x09) & 0x1f;
  1195. seq_printf(m, " %x %x\n", vt1636_08, vt1636_09);
  1196. break;
  1197. default:
  1198. break;
  1199. }
  1200. return 0;
  1201. }
  1202. static int viafb_vt1636_proc_open(struct inode *inode, struct file *file)
  1203. {
  1204. return single_open(file, viafb_vt1636_proc_show, NULL);
  1205. }
  1206. static ssize_t viafb_vt1636_proc_write(struct file *file,
  1207. const char __user *buffer, size_t count, loff_t *pos)
  1208. {
  1209. char buf[30], *value, *pbuf;
  1210. struct IODATA reg_val;
  1211. unsigned long length, i;
  1212. if (count < 1)
  1213. return -EINVAL;
  1214. length = count > 30 ? 30 : count;
  1215. if (copy_from_user(&buf[0], buffer, length))
  1216. return -EFAULT;
  1217. buf[length - 1] = '\0'; /*Ensure end string */
  1218. pbuf = &buf[0];
  1219. switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
  1220. case VT1636_LVDS:
  1221. for (i = 0; i < 2; i++) {
  1222. value = strsep(&pbuf, " ");
  1223. if (value != NULL) {
  1224. strict_strtoul(value, 0,
  1225. (unsigned long *)&reg_val.Data);
  1226. switch (i) {
  1227. case 0:
  1228. reg_val.Index = 0x08;
  1229. reg_val.Mask = 0x0f;
  1230. viafb_gpio_i2c_write_mask_lvds
  1231. (viaparinfo->lvds_setting_info,
  1232. &viaparinfo->
  1233. chip_info->lvds_chip_info,
  1234. reg_val);
  1235. break;
  1236. case 1:
  1237. reg_val.Index = 0x09;
  1238. reg_val.Mask = 0x1f;
  1239. viafb_gpio_i2c_write_mask_lvds
  1240. (viaparinfo->lvds_setting_info,
  1241. &viaparinfo->
  1242. chip_info->lvds_chip_info,
  1243. reg_val);
  1244. break;
  1245. default:
  1246. break;
  1247. }
  1248. } else {
  1249. break;
  1250. }
  1251. }
  1252. break;
  1253. default:
  1254. break;
  1255. }
  1256. switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
  1257. case VT1636_LVDS:
  1258. for (i = 0; i < 2; i++) {
  1259. value = strsep(&pbuf, " ");
  1260. if (value != NULL) {
  1261. strict_strtoul(value, 0,
  1262. (unsigned long *)&reg_val.Data);
  1263. switch (i) {
  1264. case 0:
  1265. reg_val.Index = 0x08;
  1266. reg_val.Mask = 0x0f;
  1267. viafb_gpio_i2c_write_mask_lvds
  1268. (viaparinfo->lvds_setting_info2,
  1269. &viaparinfo->
  1270. chip_info->lvds_chip_info2,
  1271. reg_val);
  1272. break;
  1273. case 1:
  1274. reg_val.Index = 0x09;
  1275. reg_val.Mask = 0x1f;
  1276. viafb_gpio_i2c_write_mask_lvds
  1277. (viaparinfo->lvds_setting_info2,
  1278. &viaparinfo->
  1279. chip_info->lvds_chip_info2,
  1280. reg_val);
  1281. break;
  1282. default:
  1283. break;
  1284. }
  1285. } else {
  1286. break;
  1287. }
  1288. }
  1289. break;
  1290. default:
  1291. break;
  1292. }
  1293. return count;
  1294. }
  1295. static const struct file_operations viafb_vt1636_proc_fops = {
  1296. .owner = THIS_MODULE,
  1297. .open = viafb_vt1636_proc_open,
  1298. .read = seq_read,
  1299. .llseek = seq_lseek,
  1300. .release = single_release,
  1301. .write = viafb_vt1636_proc_write,
  1302. };
  1303. #endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
  1304. static int viafb_sup_odev_proc_show(struct seq_file *m, void *v)
  1305. {
  1306. via_odev_to_seq(m, supported_odev_map[
  1307. viaparinfo->shared->chip_info.gfx_chip_name]);
  1308. return 0;
  1309. }
  1310. static int viafb_sup_odev_proc_open(struct inode *inode, struct file *file)
  1311. {
  1312. return single_open(file, viafb_sup_odev_proc_show, NULL);
  1313. }
  1314. static const struct file_operations viafb_sup_odev_proc_fops = {
  1315. .owner = THIS_MODULE,
  1316. .open = viafb_sup_odev_proc_open,
  1317. .read = seq_read,
  1318. .llseek = seq_lseek,
  1319. .release = single_release,
  1320. };
  1321. static ssize_t odev_update(const char __user *buffer, size_t count, u32 *odev)
  1322. {
  1323. char buf[64], *ptr = buf;
  1324. u32 devices;
  1325. bool add, sub;
  1326. if (count < 1 || count > 63)
  1327. return -EINVAL;
  1328. if (copy_from_user(&buf[0], buffer, count))
  1329. return -EFAULT;
  1330. buf[count] = '\0';
  1331. add = buf[0] == '+';
  1332. sub = buf[0] == '-';
  1333. if (add || sub)
  1334. ptr++;
  1335. devices = via_parse_odev(ptr, &ptr);
  1336. if (*ptr == '\n')
  1337. ptr++;
  1338. if (*ptr != 0)
  1339. return -EINVAL;
  1340. if (add)
  1341. *odev |= devices;
  1342. else if (sub)
  1343. *odev &= ~devices;
  1344. else
  1345. *odev = devices;
  1346. return count;
  1347. }
  1348. static int viafb_iga1_odev_proc_show(struct seq_file *m, void *v)
  1349. {
  1350. via_odev_to_seq(m, viaparinfo->shared->iga1_devices);
  1351. return 0;
  1352. }
  1353. static int viafb_iga1_odev_proc_open(struct inode *inode, struct file *file)
  1354. {
  1355. return single_open(file, viafb_iga1_odev_proc_show, NULL);
  1356. }
  1357. static ssize_t viafb_iga1_odev_proc_write(struct file *file,
  1358. const char __user *buffer, size_t count, loff_t *pos)
  1359. {
  1360. u32 dev_on, dev_off, dev_old, dev_new;
  1361. ssize_t res;
  1362. dev_old = dev_new = viaparinfo->shared->iga1_devices;
  1363. res = odev_update(buffer, count, &dev_new);
  1364. if (res != count)
  1365. return res;
  1366. dev_off = dev_old & ~dev_new;
  1367. dev_on = dev_new & ~dev_old;
  1368. viaparinfo->shared->iga1_devices = dev_new;
  1369. viaparinfo->shared->iga2_devices &= ~dev_new;
  1370. via_set_state(dev_off, VIA_STATE_OFF);
  1371. via_set_source(dev_new, IGA1);
  1372. via_set_state(dev_on, VIA_STATE_ON);
  1373. return res;
  1374. }
  1375. static const struct file_operations viafb_iga1_odev_proc_fops = {
  1376. .owner = THIS_MODULE,
  1377. .open = viafb_iga1_odev_proc_open,
  1378. .read = seq_read,
  1379. .llseek = seq_lseek,
  1380. .release = single_release,
  1381. .write = viafb_iga1_odev_proc_write,
  1382. };
  1383. static int viafb_iga2_odev_proc_show(struct seq_file *m, void *v)
  1384. {
  1385. via_odev_to_seq(m, viaparinfo->shared->iga2_devices);
  1386. return 0;
  1387. }
  1388. static int viafb_iga2_odev_proc_open(struct inode *inode, struct file *file)
  1389. {
  1390. return single_open(file, viafb_iga2_odev_proc_show, NULL);
  1391. }
  1392. static ssize_t viafb_iga2_odev_proc_write(struct file *file,
  1393. const char __user *buffer, size_t count, loff_t *pos)
  1394. {
  1395. u32 dev_on, dev_off, dev_old, dev_new;
  1396. ssize_t res;
  1397. dev_old = dev_new = viaparinfo->shared->iga2_devices;
  1398. res = odev_update(buffer, count, &dev_new);
  1399. if (res != count)
  1400. return res;
  1401. dev_off = dev_old & ~dev_new;
  1402. dev_on = dev_new & ~dev_old;
  1403. viaparinfo->shared->iga2_devices = dev_new;
  1404. viaparinfo->shared->iga1_devices &= ~dev_new;
  1405. via_set_state(dev_off, VIA_STATE_OFF);
  1406. via_set_source(dev_new, IGA2);
  1407. via_set_state(dev_on, VIA_STATE_ON);
  1408. return res;
  1409. }
  1410. static const struct file_operations viafb_iga2_odev_proc_fops = {
  1411. .owner = THIS_MODULE,
  1412. .open = viafb_iga2_odev_proc_open,
  1413. .read = seq_read,
  1414. .llseek = seq_lseek,
  1415. .release = single_release,
  1416. .write = viafb_iga2_odev_proc_write,
  1417. };
  1418. #define IS_VT1636(lvds_chip) ((lvds_chip).lvds_chip_name == VT1636_LVDS)
  1419. static void viafb_init_proc(struct viafb_shared *shared)
  1420. {
  1421. struct proc_dir_entry *iga1_entry, *iga2_entry,
  1422. *viafb_entry = proc_mkdir("viafb", NULL);
  1423. shared->proc_entry = viafb_entry;
  1424. if (viafb_entry) {
  1425. #ifdef CONFIG_FB_VIA_DIRECT_PROCFS
  1426. proc_create("dvp0", 0, viafb_entry, &viafb_dvp0_proc_fops);
  1427. proc_create("dvp1", 0, viafb_entry, &viafb_dvp1_proc_fops);
  1428. proc_create("dfph", 0, viafb_entry, &viafb_dfph_proc_fops);
  1429. proc_create("dfpl", 0, viafb_entry, &viafb_dfpl_proc_fops);
  1430. if (IS_VT1636(shared->chip_info.lvds_chip_info)
  1431. || IS_VT1636(shared->chip_info.lvds_chip_info2))
  1432. proc_create("vt1636", 0, viafb_entry,
  1433. &viafb_vt1636_proc_fops);
  1434. #endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
  1435. proc_create("supported_output_devices", 0, viafb_entry,
  1436. &viafb_sup_odev_proc_fops);
  1437. iga1_entry = proc_mkdir("iga1", viafb_entry);
  1438. shared->iga1_proc_entry = iga1_entry;
  1439. proc_create("output_devices", 0, iga1_entry,
  1440. &viafb_iga1_odev_proc_fops);
  1441. iga2_entry = proc_mkdir("iga2", viafb_entry);
  1442. shared->iga2_proc_entry = iga2_entry;
  1443. proc_create("output_devices", 0, iga2_entry,
  1444. &viafb_iga2_odev_proc_fops);
  1445. }
  1446. }
  1447. static void viafb_remove_proc(struct viafb_shared *shared)
  1448. {
  1449. struct proc_dir_entry *viafb_entry = shared->proc_entry,
  1450. *iga1_entry = shared->iga1_proc_entry,
  1451. *iga2_entry = shared->iga2_proc_entry;
  1452. if (!viafb_entry)
  1453. return;
  1454. remove_proc_entry("output_devices", iga2_entry);
  1455. remove_proc_entry("iga2", viafb_entry);
  1456. remove_proc_entry("output_devices", iga1_entry);
  1457. remove_proc_entry("iga1", viafb_entry);
  1458. remove_proc_entry("supported_output_devices", viafb_entry);
  1459. #ifdef CONFIG_FB_VIA_DIRECT_PROCFS
  1460. remove_proc_entry("dvp0", viafb_entry);/* parent dir */
  1461. remove_proc_entry("dvp1", viafb_entry);
  1462. remove_proc_entry("dfph", viafb_entry);
  1463. remove_proc_entry("dfpl", viafb_entry);
  1464. if (IS_VT1636(shared->chip_info.lvds_chip_info)
  1465. || IS_VT1636(shared->chip_info.lvds_chip_info2))
  1466. remove_proc_entry("vt1636", viafb_entry);
  1467. #endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
  1468. remove_proc_entry("viafb", NULL);
  1469. }
  1470. #undef IS_VT1636
  1471. static int parse_mode(const char *str, u32 *xres, u32 *yres)
  1472. {
  1473. char *ptr;
  1474. if (!str) {
  1475. *xres = 640;
  1476. *yres = 480;
  1477. return 0;
  1478. }
  1479. *xres = simple_strtoul(str, &ptr, 10);
  1480. if (ptr[0] != 'x')
  1481. return -EINVAL;
  1482. *yres = simple_strtoul(&ptr[1], &ptr, 10);
  1483. if (ptr[0])
  1484. return -EINVAL;
  1485. return 0;
  1486. }
  1487. #ifdef CONFIG_PM
  1488. int viafb_suspend(struct pci_dev *pdev, pm_message_t state)
  1489. {
  1490. if (state.event == PM_EVENT_SUSPEND) {
  1491. acquire_console_sem();
  1492. memcpy_fromio(viaparinfo->shared->saved_regs,
  1493. viaparinfo->shared->vdev->engine_mmio + 0x100,
  1494. 0xff * sizeof(u32));
  1495. fb_set_suspend(viafbinfo, 1);
  1496. viafb_sync(viafbinfo);
  1497. pci_save_state(pdev);
  1498. pci_disable_device(pdev);
  1499. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  1500. release_console_sem();
  1501. }
  1502. return 0;
  1503. }
  1504. int viafb_resume(struct pci_dev *pdev)
  1505. {
  1506. acquire_console_sem();
  1507. pci_set_power_state(pdev, PCI_D0);
  1508. pci_restore_state(pdev);
  1509. if (pci_enable_device(pdev))
  1510. goto fail;
  1511. pci_set_master(pdev);
  1512. memcpy_toio(viaparinfo->shared->vdev->engine_mmio + 0x100,
  1513. viaparinfo->shared->saved_regs,
  1514. 0x100 * sizeof(u32));
  1515. fb_set_suspend(viafbinfo, 0);
  1516. fail:
  1517. release_console_sem();
  1518. return 0;
  1519. }
  1520. #endif
  1521. int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
  1522. {
  1523. u32 default_xres, default_yres;
  1524. struct VideoModeTable *vmode_entry;
  1525. struct fb_var_screeninfo default_var;
  1526. int rc;
  1527. u32 viafb_par_length;
  1528. DEBUG_MSG(KERN_INFO "VIAFB PCI Probe!!\n");
  1529. memset(&default_var, 0, sizeof(default_var));
  1530. viafb_par_length = ALIGN(sizeof(struct viafb_par), BITS_PER_LONG/8);
  1531. /* Allocate fb_info and ***_par here, also including some other needed
  1532. * variables
  1533. */
  1534. viafbinfo = framebuffer_alloc(viafb_par_length +
  1535. ALIGN(sizeof(struct viafb_shared), BITS_PER_LONG/8),
  1536. &vdev->pdev->dev);
  1537. if (!viafbinfo) {
  1538. printk(KERN_ERR"Could not allocate memory for viafb_info.\n");
  1539. return -ENOMEM;
  1540. }
  1541. viaparinfo = (struct viafb_par *)viafbinfo->par;
  1542. viaparinfo->shared = viafbinfo->par + viafb_par_length;
  1543. viaparinfo->shared->vdev = vdev;
  1544. viaparinfo->vram_addr = 0;
  1545. viaparinfo->tmds_setting_info = &viaparinfo->shared->tmds_setting_info;
  1546. viaparinfo->lvds_setting_info = &viaparinfo->shared->lvds_setting_info;
  1547. viaparinfo->lvds_setting_info2 =
  1548. &viaparinfo->shared->lvds_setting_info2;
  1549. viaparinfo->crt_setting_info = &viaparinfo->shared->crt_setting_info;
  1550. viaparinfo->chip_info = &viaparinfo->shared->chip_info;
  1551. if (viafb_dual_fb)
  1552. viafb_SAMM_ON = 1;
  1553. parse_lcd_port();
  1554. parse_dvi_port();
  1555. viafb_init_chip_info(vdev->chip_type);
  1556. /*
  1557. * The framebuffer will have been successfully mapped by
  1558. * the core (or we'd not be here), but we still need to
  1559. * set up our own accounting.
  1560. */
  1561. viaparinfo->fbmem = vdev->fbmem_start;
  1562. viaparinfo->memsize = vdev->fbmem_len;
  1563. viaparinfo->fbmem_free = viaparinfo->memsize;
  1564. viaparinfo->fbmem_used = 0;
  1565. viafbinfo->screen_base = vdev->fbmem;
  1566. viafbinfo->fix.mmio_start = vdev->engine_start;
  1567. viafbinfo->fix.mmio_len = vdev->engine_len;
  1568. viafbinfo->node = 0;
  1569. viafbinfo->fbops = &viafb_ops;
  1570. viafbinfo->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  1571. viafbinfo->pseudo_palette = pseudo_pal;
  1572. if (viafb_accel && !viafb_init_engine(viafbinfo)) {
  1573. viafbinfo->flags |= FBINFO_HWACCEL_COPYAREA |
  1574. FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_IMAGEBLIT;
  1575. default_var.accel_flags = FB_ACCELF_TEXT;
  1576. } else {
  1577. viafbinfo->flags |= FBINFO_HWACCEL_DISABLED;
  1578. default_var.accel_flags = 0;
  1579. }
  1580. if (viafb_second_size && (viafb_second_size < 8)) {
  1581. viafb_second_offset = viaparinfo->fbmem_free -
  1582. viafb_second_size * 1024 * 1024;
  1583. } else {
  1584. viafb_second_size = 8;
  1585. viafb_second_offset = viaparinfo->fbmem_free -
  1586. viafb_second_size * 1024 * 1024;
  1587. }
  1588. parse_mode(viafb_mode, &default_xres, &default_yres);
  1589. vmode_entry = viafb_get_mode(default_xres, default_yres);
  1590. if (viafb_SAMM_ON == 1) {
  1591. parse_mode(viafb_mode1, &viafb_second_xres,
  1592. &viafb_second_yres);
  1593. viafb_second_virtual_xres = viafb_second_xres;
  1594. viafb_second_virtual_yres = viafb_second_yres;
  1595. }
  1596. default_var.xres = default_xres;
  1597. default_var.yres = default_yres;
  1598. default_var.xres_virtual = default_xres;
  1599. default_var.yres_virtual = default_yres;
  1600. default_var.bits_per_pixel = viafb_bpp;
  1601. default_var.pixclock =
  1602. viafb_get_pixclock(default_xres, default_yres, viafb_refresh);
  1603. default_var.left_margin = (default_xres >> 3) & 0xf8;
  1604. default_var.right_margin = 32;
  1605. default_var.upper_margin = 16;
  1606. default_var.lower_margin = 4;
  1607. default_var.hsync_len = default_var.left_margin;
  1608. default_var.vsync_len = 4;
  1609. viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo);
  1610. viafbinfo->var = default_var;
  1611. if (viafb_dual_fb) {
  1612. viafbinfo1 = framebuffer_alloc(viafb_par_length,
  1613. &vdev->pdev->dev);
  1614. if (!viafbinfo1) {
  1615. printk(KERN_ERR
  1616. "allocate the second framebuffer struct error\n");
  1617. rc = -ENOMEM;
  1618. goto out_fb_release;
  1619. }
  1620. viaparinfo1 = viafbinfo1->par;
  1621. memcpy(viaparinfo1, viaparinfo, viafb_par_length);
  1622. viaparinfo1->vram_addr = viafb_second_offset;
  1623. viaparinfo1->memsize = viaparinfo->memsize -
  1624. viafb_second_offset;
  1625. viaparinfo->memsize = viafb_second_offset;
  1626. viaparinfo1->fbmem = viaparinfo->fbmem + viafb_second_offset;
  1627. viaparinfo1->fbmem_used = viaparinfo->fbmem_used;
  1628. viaparinfo1->fbmem_free = viaparinfo1->memsize -
  1629. viaparinfo1->fbmem_used;
  1630. viaparinfo->fbmem_free = viaparinfo->memsize;
  1631. viaparinfo->fbmem_used = 0;
  1632. viaparinfo->iga_path = IGA1;
  1633. viaparinfo1->iga_path = IGA2;
  1634. memcpy(viafbinfo1, viafbinfo, sizeof(struct fb_info));
  1635. viafbinfo1->par = viaparinfo1;
  1636. viafbinfo1->screen_base = viafbinfo->screen_base +
  1637. viafb_second_offset;
  1638. default_var.xres = viafb_second_xres;
  1639. default_var.yres = viafb_second_yres;
  1640. default_var.xres_virtual = viafb_second_virtual_xres;
  1641. default_var.yres_virtual = viafb_second_virtual_yres;
  1642. default_var.bits_per_pixel = viafb_bpp1;
  1643. default_var.pixclock =
  1644. viafb_get_pixclock(viafb_second_xres, viafb_second_yres,
  1645. viafb_refresh);
  1646. default_var.left_margin = (viafb_second_xres >> 3) & 0xf8;
  1647. default_var.right_margin = 32;
  1648. default_var.upper_margin = 16;
  1649. default_var.lower_margin = 4;
  1650. default_var.hsync_len = default_var.left_margin;
  1651. default_var.vsync_len = 4;
  1652. viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1);
  1653. viafb_check_var(&default_var, viafbinfo1);
  1654. viafbinfo1->var = default_var;
  1655. viafb_update_fix(viafbinfo1);
  1656. viaparinfo1->depth = fb_get_color_depth(&viafbinfo1->var,
  1657. &viafbinfo1->fix);
  1658. }
  1659. viafb_check_var(&viafbinfo->var, viafbinfo);
  1660. viafb_update_fix(viafbinfo);
  1661. viaparinfo->depth = fb_get_color_depth(&viafbinfo->var,
  1662. &viafbinfo->fix);
  1663. default_var.activate = FB_ACTIVATE_NOW;
  1664. rc = fb_alloc_cmap(&viafbinfo->cmap, 256, 0);
  1665. if (rc)
  1666. goto out_fb1_release;
  1667. if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
  1668. && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)) {
  1669. rc = register_framebuffer(viafbinfo1);
  1670. if (rc)
  1671. goto out_dealloc_cmap;
  1672. }
  1673. rc = register_framebuffer(viafbinfo);
  1674. if (rc)
  1675. goto out_fb1_unreg_lcd_cle266;
  1676. if (viafb_dual_fb && ((viafb_primary_dev != LCD_Device)
  1677. || (viaparinfo->chip_info->gfx_chip_name !=
  1678. UNICHROME_CLE266))) {
  1679. rc = register_framebuffer(viafbinfo1);
  1680. if (rc)
  1681. goto out_fb_unreg;
  1682. }
  1683. DEBUG_MSG(KERN_INFO "fb%d: %s frame buffer device %dx%d-%dbpp\n",
  1684. viafbinfo->node, viafbinfo->fix.id, default_var.xres,
  1685. default_var.yres, default_var.bits_per_pixel);
  1686. viafb_init_proc(viaparinfo->shared);
  1687. viafb_init_dac(IGA2);
  1688. return 0;
  1689. out_fb_unreg:
  1690. unregister_framebuffer(viafbinfo);
  1691. out_fb1_unreg_lcd_cle266:
  1692. if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
  1693. && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266))
  1694. unregister_framebuffer(viafbinfo1);
  1695. out_dealloc_cmap:
  1696. fb_dealloc_cmap(&viafbinfo->cmap);
  1697. out_fb1_release:
  1698. if (viafbinfo1)
  1699. framebuffer_release(viafbinfo1);
  1700. out_fb_release:
  1701. framebuffer_release(viafbinfo);
  1702. return rc;
  1703. }
  1704. void __devexit via_fb_pci_remove(struct pci_dev *pdev)
  1705. {
  1706. DEBUG_MSG(KERN_INFO "via_pci_remove!\n");
  1707. fb_dealloc_cmap(&viafbinfo->cmap);
  1708. unregister_framebuffer(viafbinfo);
  1709. if (viafb_dual_fb)
  1710. unregister_framebuffer(viafbinfo1);
  1711. viafb_remove_proc(viaparinfo->shared);
  1712. framebuffer_release(viafbinfo);
  1713. if (viafb_dual_fb)
  1714. framebuffer_release(viafbinfo1);
  1715. }
  1716. #ifndef MODULE
  1717. static int __init viafb_setup(char *options)
  1718. {
  1719. char *this_opt;
  1720. DEBUG_MSG(KERN_INFO "viafb_setup!\n");
  1721. if (!options || !*options)
  1722. return 0;
  1723. while ((this_opt = strsep(&options, ",")) != NULL) {
  1724. if (!*this_opt)
  1725. continue;
  1726. if (!strncmp(this_opt, "viafb_mode1=", 12))
  1727. viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
  1728. else if (!strncmp(this_opt, "viafb_mode=", 11))
  1729. viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
  1730. else if (!strncmp(this_opt, "viafb_bpp1=", 11))
  1731. strict_strtoul(this_opt + 11, 0,
  1732. (unsigned long *)&viafb_bpp1);
  1733. else if (!strncmp(this_opt, "viafb_bpp=", 10))
  1734. strict_strtoul(this_opt + 10, 0,
  1735. (unsigned long *)&viafb_bpp);
  1736. else if (!strncmp(this_opt, "viafb_refresh1=", 15))
  1737. strict_strtoul(this_opt + 15, 0,
  1738. (unsigned long *)&viafb_refresh1);
  1739. else if (!strncmp(this_opt, "viafb_refresh=", 14))
  1740. strict_strtoul(this_opt + 14, 0,
  1741. (unsigned long *)&viafb_refresh);
  1742. else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21))
  1743. strict_strtoul(this_opt + 21, 0,
  1744. (unsigned long *)&viafb_lcd_dsp_method);
  1745. else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19))
  1746. strict_strtoul(this_opt + 19, 0,
  1747. (unsigned long *)&viafb_lcd_panel_id);
  1748. else if (!strncmp(this_opt, "viafb_accel=", 12))
  1749. strict_strtoul(this_opt + 12, 0,
  1750. (unsigned long *)&viafb_accel);
  1751. else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14))
  1752. strict_strtoul(this_opt + 14, 0,
  1753. (unsigned long *)&viafb_SAMM_ON);
  1754. else if (!strncmp(this_opt, "viafb_active_dev=", 17))
  1755. viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
  1756. else if (!strncmp(this_opt,
  1757. "viafb_display_hardware_layout=", 30))
  1758. strict_strtoul(this_opt + 30, 0,
  1759. (unsigned long *)&viafb_display_hardware_layout);
  1760. else if (!strncmp(this_opt, "viafb_second_size=", 18))
  1761. strict_strtoul(this_opt + 18, 0,
  1762. (unsigned long *)&viafb_second_size);
  1763. else if (!strncmp(this_opt,
  1764. "viafb_platform_epia_dvi=", 24))
  1765. strict_strtoul(this_opt + 24, 0,
  1766. (unsigned long *)&viafb_platform_epia_dvi);
  1767. else if (!strncmp(this_opt,
  1768. "viafb_device_lcd_dualedge=", 26))
  1769. strict_strtoul(this_opt + 26, 0,
  1770. (unsigned long *)&viafb_device_lcd_dualedge);
  1771. else if (!strncmp(this_opt, "viafb_bus_width=", 16))
  1772. strict_strtoul(this_opt + 16, 0,
  1773. (unsigned long *)&viafb_bus_width);
  1774. else if (!strncmp(this_opt, "viafb_lcd_mode=", 15))
  1775. strict_strtoul(this_opt + 15, 0,
  1776. (unsigned long *)&viafb_lcd_mode);
  1777. else if (!strncmp(this_opt, "viafb_lcd_port=", 15))
  1778. viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
  1779. else if (!strncmp(this_opt, "viafb_dvi_port=", 15))
  1780. viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
  1781. }
  1782. return 0;
  1783. }
  1784. #endif
  1785. /*
  1786. * These are called out of via-core for now.
  1787. */
  1788. int __init viafb_init(void)
  1789. {
  1790. u32 dummy;
  1791. #ifndef MODULE
  1792. char *option = NULL;
  1793. if (fb_get_options("viafb", &option))
  1794. return -ENODEV;
  1795. viafb_setup(option);
  1796. #endif
  1797. if (parse_mode(viafb_mode, &dummy, &dummy)
  1798. || parse_mode(viafb_mode1, &dummy, &dummy)
  1799. || viafb_bpp < 0 || viafb_bpp > 32
  1800. || viafb_bpp1 < 0 || viafb_bpp1 > 32
  1801. || parse_active_dev())
  1802. return -EINVAL;
  1803. printk(KERN_INFO
  1804. "VIA Graphics Intergration Chipset framebuffer %d.%d initializing\n",
  1805. VERSION_MAJOR, VERSION_MINOR);
  1806. return 0;
  1807. }
  1808. void __exit viafb_exit(void)
  1809. {
  1810. DEBUG_MSG(KERN_INFO "viafb_exit!\n");
  1811. }
  1812. static struct fb_ops viafb_ops = {
  1813. .owner = THIS_MODULE,
  1814. .fb_open = viafb_open,
  1815. .fb_release = viafb_release,
  1816. .fb_check_var = viafb_check_var,
  1817. .fb_set_par = viafb_set_par,
  1818. .fb_setcolreg = viafb_setcolreg,
  1819. .fb_pan_display = viafb_pan_display,
  1820. .fb_blank = viafb_blank,
  1821. .fb_fillrect = viafb_fillrect,
  1822. .fb_copyarea = viafb_copyarea,
  1823. .fb_imageblit = viafb_imageblit,
  1824. .fb_cursor = viafb_cursor,
  1825. .fb_ioctl = viafb_ioctl,
  1826. .fb_sync = viafb_sync,
  1827. };
  1828. #ifdef MODULE
  1829. module_param(viafb_mode, charp, S_IRUSR);
  1830. MODULE_PARM_DESC(viafb_mode, "Set resolution (default=640x480)");
  1831. module_param(viafb_mode1, charp, S_IRUSR);
  1832. MODULE_PARM_DESC(viafb_mode1, "Set resolution (default=640x480)");
  1833. module_param(viafb_bpp, int, S_IRUSR);
  1834. MODULE_PARM_DESC(viafb_bpp, "Set color depth (default=32bpp)");
  1835. module_param(viafb_bpp1, int, S_IRUSR);
  1836. MODULE_PARM_DESC(viafb_bpp1, "Set color depth (default=32bpp)");
  1837. module_param(viafb_refresh, int, S_IRUSR);
  1838. MODULE_PARM_DESC(viafb_refresh,
  1839. "Set CRT viafb_refresh rate (default = 60)");
  1840. module_param(viafb_refresh1, int, S_IRUSR);
  1841. MODULE_PARM_DESC(viafb_refresh1,
  1842. "Set CRT refresh rate (default = 60)");
  1843. module_param(viafb_lcd_panel_id, int, S_IRUSR);
  1844. MODULE_PARM_DESC(viafb_lcd_panel_id,
  1845. "Set Flat Panel type(Default=1024x768)");
  1846. module_param(viafb_lcd_dsp_method, int, S_IRUSR);
  1847. MODULE_PARM_DESC(viafb_lcd_dsp_method,
  1848. "Set Flat Panel display scaling method.(Default=Expandsion)");
  1849. module_param(viafb_SAMM_ON, int, S_IRUSR);
  1850. MODULE_PARM_DESC(viafb_SAMM_ON,
  1851. "Turn on/off flag of SAMM(Default=OFF)");
  1852. module_param(viafb_accel, int, S_IRUSR);
  1853. MODULE_PARM_DESC(viafb_accel,
  1854. "Set 2D Hardware Acceleration: 0 = OFF, 1 = ON (default)");
  1855. module_param(viafb_active_dev, charp, S_IRUSR);
  1856. MODULE_PARM_DESC(viafb_active_dev, "Specify active devices.");
  1857. module_param(viafb_display_hardware_layout, int, S_IRUSR);
  1858. MODULE_PARM_DESC(viafb_display_hardware_layout,
  1859. "Display Hardware Layout (LCD Only, DVI Only...,etc)");
  1860. module_param(viafb_second_size, int, S_IRUSR);
  1861. MODULE_PARM_DESC(viafb_second_size,
  1862. "Set secondary device memory size");
  1863. module_param(viafb_dual_fb, int, S_IRUSR);
  1864. MODULE_PARM_DESC(viafb_dual_fb,
  1865. "Turn on/off flag of dual framebuffer devices.(Default = OFF)");
  1866. module_param(viafb_platform_epia_dvi, int, S_IRUSR);
  1867. MODULE_PARM_DESC(viafb_platform_epia_dvi,
  1868. "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)");
  1869. module_param(viafb_device_lcd_dualedge, int, S_IRUSR);
  1870. MODULE_PARM_DESC(viafb_device_lcd_dualedge,
  1871. "Turn on/off flag of dual edge panel.(Default = OFF)");
  1872. module_param(viafb_bus_width, int, S_IRUSR);
  1873. MODULE_PARM_DESC(viafb_bus_width,
  1874. "Set bus width of panel.(Default = 12)");
  1875. module_param(viafb_lcd_mode, int, S_IRUSR);
  1876. MODULE_PARM_DESC(viafb_lcd_mode,
  1877. "Set Flat Panel mode(Default=OPENLDI)");
  1878. module_param(viafb_lcd_port, charp, S_IRUSR);
  1879. MODULE_PARM_DESC(viafb_lcd_port, "Specify LCD output port.");
  1880. module_param(viafb_dvi_port, charp, S_IRUSR);
  1881. MODULE_PARM_DESC(viafb_dvi_port, "Specify DVI output port.");
  1882. MODULE_LICENSE("GPL");
  1883. #endif