viafbdev.c 59 KB

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