viafbdev.c 59 KB

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