viafbdev.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122
  1. /*
  2. * Copyright 1998-2009 VIA Technologies, Inc. All Rights Reserved.
  3. * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License as published by the Free Software Foundation;
  7. * either version 2, or (at your option) any later version.
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
  10. * the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. * A PARTICULAR PURPOSE.See the GNU General Public License
  12. * for more details.
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/slab.h>
  21. #include <linux/stat.h>
  22. #include <linux/via-core.h>
  23. #define _MASTER_FILE
  24. #include "global.h"
  25. static char *viafb_name = "Via";
  26. static u32 pseudo_pal[17];
  27. /* video mode */
  28. static char *viafb_mode;
  29. static char *viafb_mode1;
  30. static int viafb_bpp = 32;
  31. static int viafb_bpp1 = 32;
  32. static unsigned int viafb_second_xres = 640;
  33. static unsigned int viafb_second_yres = 480;
  34. static unsigned int viafb_second_offset;
  35. static int viafb_second_size;
  36. static int viafb_accel = 1;
  37. /* Added for specifying active devices.*/
  38. static char *viafb_active_dev;
  39. /*Added for specify lcd output port*/
  40. static char *viafb_lcd_port = "";
  41. static char *viafb_dvi_port = "";
  42. static void retrieve_device_setting(struct viafb_ioctl_setting
  43. *setting_info);
  44. static int viafb_pan_display(struct fb_var_screeninfo *var,
  45. struct fb_info *info);
  46. static struct fb_ops viafb_ops;
  47. /* supported output devices on each IGP
  48. * only CX700, VX800, VX855, VX900 were documented
  49. * VIA_CRT should be everywhere
  50. * VIA_6C can be onle pre-CX700 (probably only on CLE266) as 6C is used for PLL
  51. * source selection on CX700 and later
  52. * K400 seems to support VIA_96, VIA_DVP1, VIA_LVDS{1,2} as in viamode.c
  53. */
  54. static const u32 supported_odev_map[] = {
  55. [UNICHROME_CLE266] = VIA_CRT | VIA_LDVP0 | VIA_LDVP1,
  56. [UNICHROME_K400] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
  57. | VIA_LVDS2,
  58. [UNICHROME_K800] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
  59. | VIA_LVDS2,
  60. [UNICHROME_PM800] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
  61. | VIA_LVDS2,
  62. [UNICHROME_CN700] = VIA_CRT | VIA_DVP0 | VIA_DVP1 | VIA_LVDS1
  63. | VIA_LVDS2,
  64. [UNICHROME_CX700] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  65. [UNICHROME_CN750] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  66. [UNICHROME_K8M890] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  67. [UNICHROME_P4M890] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  68. [UNICHROME_P4M900] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  69. [UNICHROME_VX800] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  70. [UNICHROME_VX855] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  71. [UNICHROME_VX900] = VIA_CRT | VIA_DVP1 | VIA_LVDS1 | VIA_LVDS2,
  72. };
  73. static void viafb_fill_var_color_info(struct fb_var_screeninfo *var, u8 depth)
  74. {
  75. var->grayscale = 0;
  76. var->red.msb_right = 0;
  77. var->green.msb_right = 0;
  78. var->blue.msb_right = 0;
  79. var->transp.offset = 0;
  80. var->transp.length = 0;
  81. var->transp.msb_right = 0;
  82. var->nonstd = 0;
  83. switch (depth) {
  84. case 8:
  85. var->bits_per_pixel = 8;
  86. var->red.offset = 0;
  87. var->green.offset = 0;
  88. var->blue.offset = 0;
  89. var->red.length = 8;
  90. var->green.length = 8;
  91. var->blue.length = 8;
  92. break;
  93. case 15:
  94. var->bits_per_pixel = 16;
  95. var->red.offset = 10;
  96. var->green.offset = 5;
  97. var->blue.offset = 0;
  98. var->red.length = 5;
  99. var->green.length = 5;
  100. var->blue.length = 5;
  101. break;
  102. case 16:
  103. var->bits_per_pixel = 16;
  104. var->red.offset = 11;
  105. var->green.offset = 5;
  106. var->blue.offset = 0;
  107. var->red.length = 5;
  108. var->green.length = 6;
  109. var->blue.length = 5;
  110. break;
  111. case 24:
  112. var->bits_per_pixel = 32;
  113. var->red.offset = 16;
  114. var->green.offset = 8;
  115. var->blue.offset = 0;
  116. var->red.length = 8;
  117. var->green.length = 8;
  118. var->blue.length = 8;
  119. break;
  120. case 30:
  121. var->bits_per_pixel = 32;
  122. var->red.offset = 20;
  123. var->green.offset = 10;
  124. var->blue.offset = 0;
  125. var->red.length = 10;
  126. var->green.length = 10;
  127. var->blue.length = 10;
  128. break;
  129. }
  130. }
  131. static void viafb_update_fix(struct fb_info *info)
  132. {
  133. u32 bpp = info->var.bits_per_pixel;
  134. info->fix.visual =
  135. bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
  136. info->fix.line_length = (info->var.xres_virtual * bpp / 8 + 7) & ~7;
  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 VideoModeTable *vmode_entry;
  177. struct viafb_par *ppar = info->par;
  178. u32 line;
  179. DEBUG_MSG(KERN_INFO "viafb_check_var!\n");
  180. /* Sanity check */
  181. /* HW neither support interlacte nor double-scaned mode */
  182. if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE)
  183. return -EINVAL;
  184. vmode_entry = viafb_get_mode(var->xres, var->yres);
  185. if (!vmode_entry) {
  186. DEBUG_MSG(KERN_INFO
  187. "viafb: Mode %dx%dx%d not supported!!\n",
  188. var->xres, var->yres, var->bits_per_pixel);
  189. return -EINVAL;
  190. }
  191. depth = fb_get_color_depth(var, &info->fix);
  192. if (!depth)
  193. depth = var->bits_per_pixel;
  194. if (depth < 0 || depth > 32)
  195. return -EINVAL;
  196. else if (!depth)
  197. depth = 24;
  198. else if (depth == 15 && viafb_dual_fb && ppar->iga_path == IGA1)
  199. depth = 15;
  200. else if (depth == 30)
  201. depth = 30;
  202. else if (depth <= 8)
  203. depth = 8;
  204. else if (depth <= 16)
  205. depth = 16;
  206. else
  207. depth = 24;
  208. viafb_fill_var_color_info(var, depth);
  209. line = (var->xres_virtual * var->bits_per_pixel / 8 + 7) & ~7;
  210. if (line * var->yres_virtual > ppar->memsize)
  211. return -EINVAL;
  212. /* Based on var passed in to calculate the refresh,
  213. * because our driver use some modes special.
  214. */
  215. refresh = viafb_get_refresh(var->xres, var->yres,
  216. get_var_refresh(var));
  217. /* Adjust var according to our driver's own table */
  218. viafb_fill_var_timing_info(var, refresh, vmode_entry);
  219. if (var->accel_flags & FB_ACCELF_TEXT &&
  220. !ppar->shared->vdev->engine_mmio)
  221. var->accel_flags = 0;
  222. return 0;
  223. }
  224. static int viafb_set_par(struct fb_info *info)
  225. {
  226. struct viafb_par *viapar = info->par;
  227. struct VideoModeTable *vmode_entry, *vmode_entry1 = NULL;
  228. int refresh;
  229. DEBUG_MSG(KERN_INFO "viafb_set_par!\n");
  230. viafb_update_fix(info);
  231. viapar->depth = fb_get_color_depth(&info->var, &info->fix);
  232. viafb_update_device_setting(viafbinfo->var.xres, viafbinfo->var.yres,
  233. viafbinfo->var.bits_per_pixel, 0);
  234. vmode_entry = viafb_get_mode(viafbinfo->var.xres, viafbinfo->var.yres);
  235. if (viafb_dual_fb) {
  236. vmode_entry1 = viafb_get_mode(viafbinfo1->var.xres,
  237. viafbinfo1->var.yres);
  238. viafb_update_device_setting(viafbinfo1->var.xres,
  239. viafbinfo1->var.yres, viafbinfo1->var.bits_per_pixel,
  240. 1);
  241. } else if (viafb_SAMM_ON == 1) {
  242. DEBUG_MSG(KERN_INFO
  243. "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
  244. viafb_second_xres, viafb_second_yres, viafb_bpp1);
  245. vmode_entry1 = viafb_get_mode(viafb_second_xres,
  246. viafb_second_yres);
  247. viafb_update_device_setting(viafb_second_xres,
  248. viafb_second_yres, viafb_bpp1, 1);
  249. }
  250. refresh = viafb_get_refresh(info->var.xres, info->var.yres,
  251. get_var_refresh(&info->var));
  252. if (vmode_entry) {
  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(vmode_entry, info->var.bits_per_pixel,
  265. vmode_entry1, viafb_bpp1);
  266. viafb_pan_display(&info->var, info);
  267. }
  268. return 0;
  269. }
  270. /* Set one color register */
  271. static int viafb_setcolreg(unsigned regno, unsigned red, unsigned green,
  272. unsigned blue, unsigned transp, struct fb_info *info)
  273. {
  274. struct viafb_par *viapar = info->par;
  275. u32 r, g, b;
  276. if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
  277. if (regno > 255)
  278. return -EINVAL;
  279. if (!viafb_dual_fb || viapar->iga_path == IGA1)
  280. viafb_set_primary_color_register(regno, red >> 8,
  281. green >> 8, blue >> 8);
  282. if (!viafb_dual_fb || viapar->iga_path == IGA2)
  283. viafb_set_secondary_color_register(regno, red >> 8,
  284. green >> 8, blue >> 8);
  285. } else {
  286. if (regno > 15)
  287. return -EINVAL;
  288. r = (red >> (16 - info->var.red.length))
  289. << info->var.red.offset;
  290. b = (blue >> (16 - info->var.blue.length))
  291. << info->var.blue.offset;
  292. g = (green >> (16 - info->var.green.length))
  293. << info->var.green.offset;
  294. ((u32 *) info->pseudo_palette)[regno] = r | g | b;
  295. }
  296. return 0;
  297. }
  298. static int viafb_pan_display(struct fb_var_screeninfo *var,
  299. struct fb_info *info)
  300. {
  301. struct viafb_par *viapar = info->par;
  302. u32 vram_addr = (var->yoffset * var->xres_virtual + var->xoffset)
  303. * (var->bits_per_pixel / 8) + viapar->vram_addr;
  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. viafb_CRT_ON = STATE_ON;
  886. viafb_SAMM_ON = STATE_OFF;
  887. } else if (!strcmp(viafb_active_dev, "CRT+DVI")) {
  888. /* CRT+DVI */
  889. viafb_CRT_ON = STATE_ON;
  890. viafb_DVI_ON = STATE_ON;
  891. viafb_primary_dev = CRT_Device;
  892. } else if (!strcmp(viafb_active_dev, "DVI+CRT")) {
  893. /* DVI+CRT */
  894. viafb_CRT_ON = STATE_ON;
  895. viafb_DVI_ON = STATE_ON;
  896. viafb_primary_dev = DVI_Device;
  897. } else if (!strcmp(viafb_active_dev, "CRT+LCD")) {
  898. /* CRT+LCD */
  899. viafb_CRT_ON = STATE_ON;
  900. viafb_LCD_ON = STATE_ON;
  901. viafb_primary_dev = CRT_Device;
  902. } else if (!strcmp(viafb_active_dev, "LCD+CRT")) {
  903. /* LCD+CRT */
  904. viafb_CRT_ON = STATE_ON;
  905. viafb_LCD_ON = STATE_ON;
  906. viafb_primary_dev = LCD_Device;
  907. } else if (!strcmp(viafb_active_dev, "DVI+LCD")) {
  908. /* DVI+LCD */
  909. viafb_DVI_ON = STATE_ON;
  910. viafb_LCD_ON = STATE_ON;
  911. viafb_primary_dev = DVI_Device;
  912. } else if (!strcmp(viafb_active_dev, "LCD+DVI")) {
  913. /* LCD+DVI */
  914. viafb_DVI_ON = STATE_ON;
  915. viafb_LCD_ON = STATE_ON;
  916. viafb_primary_dev = LCD_Device;
  917. } else if (!strcmp(viafb_active_dev, "LCD+LCD2")) {
  918. viafb_LCD_ON = STATE_ON;
  919. viafb_LCD2_ON = STATE_ON;
  920. viafb_primary_dev = LCD_Device;
  921. } else if (!strcmp(viafb_active_dev, "LCD2+LCD")) {
  922. viafb_LCD_ON = STATE_ON;
  923. viafb_LCD2_ON = STATE_ON;
  924. viafb_primary_dev = LCD2_Device;
  925. } else if (!strcmp(viafb_active_dev, "CRT")) {
  926. /* CRT only */
  927. viafb_CRT_ON = STATE_ON;
  928. viafb_SAMM_ON = STATE_OFF;
  929. } else if (!strcmp(viafb_active_dev, "DVI")) {
  930. /* DVI only */
  931. viafb_DVI_ON = STATE_ON;
  932. viafb_SAMM_ON = STATE_OFF;
  933. } else if (!strcmp(viafb_active_dev, "LCD")) {
  934. /* LCD only */
  935. viafb_LCD_ON = STATE_ON;
  936. viafb_SAMM_ON = STATE_OFF;
  937. } else
  938. return -EINVAL;
  939. return 0;
  940. }
  941. static int __devinit parse_port(char *opt_str, int *output_interface)
  942. {
  943. if (!strncmp(opt_str, "DVP0", 4))
  944. *output_interface = INTERFACE_DVP0;
  945. else if (!strncmp(opt_str, "DVP1", 4))
  946. *output_interface = INTERFACE_DVP1;
  947. else if (!strncmp(opt_str, "DFP_HIGHLOW", 11))
  948. *output_interface = INTERFACE_DFP;
  949. else if (!strncmp(opt_str, "DFP_HIGH", 8))
  950. *output_interface = INTERFACE_DFP_HIGH;
  951. else if (!strncmp(opt_str, "DFP_LOW", 7))
  952. *output_interface = INTERFACE_DFP_LOW;
  953. else
  954. *output_interface = INTERFACE_NONE;
  955. return 0;
  956. }
  957. static void __devinit parse_lcd_port(void)
  958. {
  959. parse_port(viafb_lcd_port, &viaparinfo->chip_info->lvds_chip_info.
  960. output_interface);
  961. /*Initialize to avoid unexpected behavior */
  962. viaparinfo->chip_info->lvds_chip_info2.output_interface =
  963. INTERFACE_NONE;
  964. DEBUG_MSG(KERN_INFO "parse_lcd_port: viafb_lcd_port:%s,interface:%d\n",
  965. viafb_lcd_port, viaparinfo->chip_info->lvds_chip_info.
  966. output_interface);
  967. }
  968. static void __devinit parse_dvi_port(void)
  969. {
  970. parse_port(viafb_dvi_port, &viaparinfo->chip_info->tmds_chip_info.
  971. output_interface);
  972. DEBUG_MSG(KERN_INFO "parse_dvi_port: viafb_dvi_port:%s,interface:%d\n",
  973. viafb_dvi_port, viaparinfo->chip_info->tmds_chip_info.
  974. output_interface);
  975. }
  976. #ifdef CONFIG_FB_VIA_DIRECT_PROCFS
  977. /*
  978. * The proc filesystem read/write function, a simple proc implement to
  979. * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
  980. * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2],
  981. * CR9B, SR65, CR97, CR99
  982. */
  983. static int viafb_dvp0_proc_show(struct seq_file *m, void *v)
  984. {
  985. u8 dvp0_data_dri = 0, dvp0_clk_dri = 0, dvp0 = 0;
  986. dvp0_data_dri =
  987. (viafb_read_reg(VIASR, SR2A) & BIT5) >> 4 |
  988. (viafb_read_reg(VIASR, SR1B) & BIT1) >> 1;
  989. dvp0_clk_dri =
  990. (viafb_read_reg(VIASR, SR2A) & BIT4) >> 3 |
  991. (viafb_read_reg(VIASR, SR1E) & BIT2) >> 2;
  992. dvp0 = viafb_read_reg(VIACR, CR96) & 0x0f;
  993. seq_printf(m, "%x %x %x\n", dvp0, dvp0_data_dri, dvp0_clk_dri);
  994. return 0;
  995. }
  996. static int viafb_dvp0_proc_open(struct inode *inode, struct file *file)
  997. {
  998. return single_open(file, viafb_dvp0_proc_show, NULL);
  999. }
  1000. static ssize_t viafb_dvp0_proc_write(struct file *file,
  1001. const char __user *buffer, size_t count, loff_t *pos)
  1002. {
  1003. char buf[20], *value, *pbuf;
  1004. u8 reg_val = 0;
  1005. unsigned long length, i;
  1006. if (count < 1)
  1007. return -EINVAL;
  1008. length = count > 20 ? 20 : count;
  1009. if (copy_from_user(&buf[0], buffer, length))
  1010. return -EFAULT;
  1011. buf[length - 1] = '\0'; /*Ensure end string */
  1012. pbuf = &buf[0];
  1013. for (i = 0; i < 3; i++) {
  1014. value = strsep(&pbuf, " ");
  1015. if (value != NULL) {
  1016. strict_strtoul(value, 0, (unsigned long *)&reg_val);
  1017. DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
  1018. reg_val);
  1019. switch (i) {
  1020. case 0:
  1021. viafb_write_reg_mask(CR96, VIACR,
  1022. reg_val, 0x0f);
  1023. break;
  1024. case 1:
  1025. viafb_write_reg_mask(SR2A, VIASR,
  1026. reg_val << 4, BIT5);
  1027. viafb_write_reg_mask(SR1B, VIASR,
  1028. reg_val << 1, BIT1);
  1029. break;
  1030. case 2:
  1031. viafb_write_reg_mask(SR2A, VIASR,
  1032. reg_val << 3, BIT4);
  1033. viafb_write_reg_mask(SR1E, VIASR,
  1034. reg_val << 2, BIT2);
  1035. break;
  1036. default:
  1037. break;
  1038. }
  1039. } else {
  1040. break;
  1041. }
  1042. }
  1043. return count;
  1044. }
  1045. static const struct file_operations viafb_dvp0_proc_fops = {
  1046. .owner = THIS_MODULE,
  1047. .open = viafb_dvp0_proc_open,
  1048. .read = seq_read,
  1049. .llseek = seq_lseek,
  1050. .release = single_release,
  1051. .write = viafb_dvp0_proc_write,
  1052. };
  1053. static int viafb_dvp1_proc_show(struct seq_file *m, void *v)
  1054. {
  1055. u8 dvp1 = 0, dvp1_data_dri = 0, dvp1_clk_dri = 0;
  1056. dvp1 = viafb_read_reg(VIACR, CR9B) & 0x0f;
  1057. dvp1_data_dri = (viafb_read_reg(VIASR, SR65) & 0x0c) >> 2;
  1058. dvp1_clk_dri = viafb_read_reg(VIASR, SR65) & 0x03;
  1059. seq_printf(m, "%x %x %x\n", dvp1, dvp1_data_dri, dvp1_clk_dri);
  1060. return 0;
  1061. }
  1062. static int viafb_dvp1_proc_open(struct inode *inode, struct file *file)
  1063. {
  1064. return single_open(file, viafb_dvp1_proc_show, NULL);
  1065. }
  1066. static ssize_t viafb_dvp1_proc_write(struct file *file,
  1067. const char __user *buffer, size_t count, loff_t *pos)
  1068. {
  1069. char buf[20], *value, *pbuf;
  1070. u8 reg_val = 0;
  1071. unsigned long length, i;
  1072. if (count < 1)
  1073. return -EINVAL;
  1074. length = count > 20 ? 20 : count;
  1075. if (copy_from_user(&buf[0], buffer, length))
  1076. return -EFAULT;
  1077. buf[length - 1] = '\0'; /*Ensure end string */
  1078. pbuf = &buf[0];
  1079. for (i = 0; i < 3; i++) {
  1080. value = strsep(&pbuf, " ");
  1081. if (value != NULL) {
  1082. strict_strtoul(value, 0, (unsigned long *)&reg_val);
  1083. switch (i) {
  1084. case 0:
  1085. viafb_write_reg_mask(CR9B, VIACR,
  1086. reg_val, 0x0f);
  1087. break;
  1088. case 1:
  1089. viafb_write_reg_mask(SR65, VIASR,
  1090. reg_val << 2, 0x0c);
  1091. break;
  1092. case 2:
  1093. viafb_write_reg_mask(SR65, VIASR,
  1094. reg_val, 0x03);
  1095. break;
  1096. default:
  1097. break;
  1098. }
  1099. } else {
  1100. break;
  1101. }
  1102. }
  1103. return count;
  1104. }
  1105. static const struct file_operations viafb_dvp1_proc_fops = {
  1106. .owner = THIS_MODULE,
  1107. .open = viafb_dvp1_proc_open,
  1108. .read = seq_read,
  1109. .llseek = seq_lseek,
  1110. .release = single_release,
  1111. .write = viafb_dvp1_proc_write,
  1112. };
  1113. static int viafb_dfph_proc_show(struct seq_file *m, void *v)
  1114. {
  1115. u8 dfp_high = 0;
  1116. dfp_high = viafb_read_reg(VIACR, CR97) & 0x0f;
  1117. seq_printf(m, "%x\n", dfp_high);
  1118. return 0;
  1119. }
  1120. static int viafb_dfph_proc_open(struct inode *inode, struct file *file)
  1121. {
  1122. return single_open(file, viafb_dfph_proc_show, NULL);
  1123. }
  1124. static ssize_t viafb_dfph_proc_write(struct file *file,
  1125. const char __user *buffer, size_t count, loff_t *pos)
  1126. {
  1127. char buf[20];
  1128. u8 reg_val = 0;
  1129. unsigned long length;
  1130. if (count < 1)
  1131. return -EINVAL;
  1132. length = count > 20 ? 20 : count;
  1133. if (copy_from_user(&buf[0], buffer, length))
  1134. return -EFAULT;
  1135. buf[length - 1] = '\0'; /*Ensure end string */
  1136. strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
  1137. viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
  1138. return count;
  1139. }
  1140. static const struct file_operations viafb_dfph_proc_fops = {
  1141. .owner = THIS_MODULE,
  1142. .open = viafb_dfph_proc_open,
  1143. .read = seq_read,
  1144. .llseek = seq_lseek,
  1145. .release = single_release,
  1146. .write = viafb_dfph_proc_write,
  1147. };
  1148. static int viafb_dfpl_proc_show(struct seq_file *m, void *v)
  1149. {
  1150. u8 dfp_low = 0;
  1151. dfp_low = viafb_read_reg(VIACR, CR99) & 0x0f;
  1152. seq_printf(m, "%x\n", dfp_low);
  1153. return 0;
  1154. }
  1155. static int viafb_dfpl_proc_open(struct inode *inode, struct file *file)
  1156. {
  1157. return single_open(file, viafb_dfpl_proc_show, NULL);
  1158. }
  1159. static ssize_t viafb_dfpl_proc_write(struct file *file,
  1160. const char __user *buffer, size_t count, loff_t *pos)
  1161. {
  1162. char buf[20];
  1163. u8 reg_val = 0;
  1164. unsigned long length;
  1165. if (count < 1)
  1166. return -EINVAL;
  1167. length = count > 20 ? 20 : count;
  1168. if (copy_from_user(&buf[0], buffer, length))
  1169. return -EFAULT;
  1170. buf[length - 1] = '\0'; /*Ensure end string */
  1171. strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
  1172. viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
  1173. return count;
  1174. }
  1175. static const struct file_operations viafb_dfpl_proc_fops = {
  1176. .owner = THIS_MODULE,
  1177. .open = viafb_dfpl_proc_open,
  1178. .read = seq_read,
  1179. .llseek = seq_lseek,
  1180. .release = single_release,
  1181. .write = viafb_dfpl_proc_write,
  1182. };
  1183. static int viafb_vt1636_proc_show(struct seq_file *m, void *v)
  1184. {
  1185. u8 vt1636_08 = 0, vt1636_09 = 0;
  1186. switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
  1187. case VT1636_LVDS:
  1188. vt1636_08 =
  1189. viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
  1190. &viaparinfo->chip_info->lvds_chip_info, 0x08) & 0x0f;
  1191. vt1636_09 =
  1192. viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
  1193. &viaparinfo->chip_info->lvds_chip_info, 0x09) & 0x1f;
  1194. seq_printf(m, "%x %x\n", vt1636_08, vt1636_09);
  1195. break;
  1196. default:
  1197. break;
  1198. }
  1199. switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
  1200. case VT1636_LVDS:
  1201. vt1636_08 =
  1202. viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
  1203. &viaparinfo->chip_info->lvds_chip_info2, 0x08) & 0x0f;
  1204. vt1636_09 =
  1205. viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
  1206. &viaparinfo->chip_info->lvds_chip_info2, 0x09) & 0x1f;
  1207. seq_printf(m, " %x %x\n", vt1636_08, vt1636_09);
  1208. break;
  1209. default:
  1210. break;
  1211. }
  1212. return 0;
  1213. }
  1214. static int viafb_vt1636_proc_open(struct inode *inode, struct file *file)
  1215. {
  1216. return single_open(file, viafb_vt1636_proc_show, NULL);
  1217. }
  1218. static ssize_t viafb_vt1636_proc_write(struct file *file,
  1219. const char __user *buffer, size_t count, loff_t *pos)
  1220. {
  1221. char buf[30], *value, *pbuf;
  1222. struct IODATA reg_val;
  1223. unsigned long length, i;
  1224. if (count < 1)
  1225. return -EINVAL;
  1226. length = count > 30 ? 30 : count;
  1227. if (copy_from_user(&buf[0], buffer, length))
  1228. return -EFAULT;
  1229. buf[length - 1] = '\0'; /*Ensure end string */
  1230. pbuf = &buf[0];
  1231. switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
  1232. case VT1636_LVDS:
  1233. for (i = 0; i < 2; i++) {
  1234. value = strsep(&pbuf, " ");
  1235. if (value != NULL) {
  1236. strict_strtoul(value, 0,
  1237. (unsigned long *)&reg_val.Data);
  1238. switch (i) {
  1239. case 0:
  1240. reg_val.Index = 0x08;
  1241. reg_val.Mask = 0x0f;
  1242. viafb_gpio_i2c_write_mask_lvds
  1243. (viaparinfo->lvds_setting_info,
  1244. &viaparinfo->
  1245. chip_info->lvds_chip_info,
  1246. reg_val);
  1247. break;
  1248. case 1:
  1249. reg_val.Index = 0x09;
  1250. reg_val.Mask = 0x1f;
  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. default:
  1258. break;
  1259. }
  1260. } else {
  1261. break;
  1262. }
  1263. }
  1264. break;
  1265. default:
  1266. break;
  1267. }
  1268. switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
  1269. case VT1636_LVDS:
  1270. for (i = 0; i < 2; i++) {
  1271. value = strsep(&pbuf, " ");
  1272. if (value != NULL) {
  1273. strict_strtoul(value, 0,
  1274. (unsigned long *)&reg_val.Data);
  1275. switch (i) {
  1276. case 0:
  1277. reg_val.Index = 0x08;
  1278. reg_val.Mask = 0x0f;
  1279. viafb_gpio_i2c_write_mask_lvds
  1280. (viaparinfo->lvds_setting_info2,
  1281. &viaparinfo->
  1282. chip_info->lvds_chip_info2,
  1283. reg_val);
  1284. break;
  1285. case 1:
  1286. reg_val.Index = 0x09;
  1287. reg_val.Mask = 0x1f;
  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. default:
  1295. break;
  1296. }
  1297. } else {
  1298. break;
  1299. }
  1300. }
  1301. break;
  1302. default:
  1303. break;
  1304. }
  1305. return count;
  1306. }
  1307. static const struct file_operations viafb_vt1636_proc_fops = {
  1308. .owner = THIS_MODULE,
  1309. .open = viafb_vt1636_proc_open,
  1310. .read = seq_read,
  1311. .llseek = seq_lseek,
  1312. .release = single_release,
  1313. .write = viafb_vt1636_proc_write,
  1314. };
  1315. #endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
  1316. static int viafb_sup_odev_proc_show(struct seq_file *m, void *v)
  1317. {
  1318. via_odev_to_seq(m, supported_odev_map[
  1319. viaparinfo->shared->chip_info.gfx_chip_name]);
  1320. return 0;
  1321. }
  1322. static int viafb_sup_odev_proc_open(struct inode *inode, struct file *file)
  1323. {
  1324. return single_open(file, viafb_sup_odev_proc_show, NULL);
  1325. }
  1326. static const struct file_operations viafb_sup_odev_proc_fops = {
  1327. .owner = THIS_MODULE,
  1328. .open = viafb_sup_odev_proc_open,
  1329. .read = seq_read,
  1330. .llseek = seq_lseek,
  1331. .release = single_release,
  1332. };
  1333. static ssize_t odev_update(const char __user *buffer, size_t count, u32 *odev)
  1334. {
  1335. char buf[64], *ptr = buf;
  1336. u32 devices;
  1337. bool add, sub;
  1338. if (count < 1 || count > 63)
  1339. return -EINVAL;
  1340. if (copy_from_user(&buf[0], buffer, count))
  1341. return -EFAULT;
  1342. buf[count] = '\0';
  1343. add = buf[0] == '+';
  1344. sub = buf[0] == '-';
  1345. if (add || sub)
  1346. ptr++;
  1347. devices = via_parse_odev(ptr, &ptr);
  1348. if (*ptr == '\n')
  1349. ptr++;
  1350. if (*ptr != 0)
  1351. return -EINVAL;
  1352. if (add)
  1353. *odev |= devices;
  1354. else if (sub)
  1355. *odev &= ~devices;
  1356. else
  1357. *odev = devices;
  1358. return count;
  1359. }
  1360. static int viafb_iga1_odev_proc_show(struct seq_file *m, void *v)
  1361. {
  1362. via_odev_to_seq(m, viaparinfo->shared->iga1_devices);
  1363. return 0;
  1364. }
  1365. static int viafb_iga1_odev_proc_open(struct inode *inode, struct file *file)
  1366. {
  1367. return single_open(file, viafb_iga1_odev_proc_show, NULL);
  1368. }
  1369. static ssize_t viafb_iga1_odev_proc_write(struct file *file,
  1370. const char __user *buffer, size_t count, loff_t *pos)
  1371. {
  1372. u32 dev_on, dev_off, dev_old, dev_new;
  1373. ssize_t res;
  1374. dev_old = dev_new = viaparinfo->shared->iga1_devices;
  1375. res = odev_update(buffer, count, &dev_new);
  1376. if (res != count)
  1377. return res;
  1378. dev_off = dev_old & ~dev_new;
  1379. dev_on = dev_new & ~dev_old;
  1380. viaparinfo->shared->iga1_devices = dev_new;
  1381. viaparinfo->shared->iga2_devices &= ~dev_new;
  1382. via_set_state(dev_off, VIA_STATE_OFF);
  1383. via_set_source(dev_new, IGA1);
  1384. via_set_state(dev_on, VIA_STATE_ON);
  1385. return res;
  1386. }
  1387. static const struct file_operations viafb_iga1_odev_proc_fops = {
  1388. .owner = THIS_MODULE,
  1389. .open = viafb_iga1_odev_proc_open,
  1390. .read = seq_read,
  1391. .llseek = seq_lseek,
  1392. .release = single_release,
  1393. .write = viafb_iga1_odev_proc_write,
  1394. };
  1395. static int viafb_iga2_odev_proc_show(struct seq_file *m, void *v)
  1396. {
  1397. via_odev_to_seq(m, viaparinfo->shared->iga2_devices);
  1398. return 0;
  1399. }
  1400. static int viafb_iga2_odev_proc_open(struct inode *inode, struct file *file)
  1401. {
  1402. return single_open(file, viafb_iga2_odev_proc_show, NULL);
  1403. }
  1404. static ssize_t viafb_iga2_odev_proc_write(struct file *file,
  1405. const char __user *buffer, size_t count, loff_t *pos)
  1406. {
  1407. u32 dev_on, dev_off, dev_old, dev_new;
  1408. ssize_t res;
  1409. dev_old = dev_new = viaparinfo->shared->iga2_devices;
  1410. res = odev_update(buffer, count, &dev_new);
  1411. if (res != count)
  1412. return res;
  1413. dev_off = dev_old & ~dev_new;
  1414. dev_on = dev_new & ~dev_old;
  1415. viaparinfo->shared->iga2_devices = dev_new;
  1416. viaparinfo->shared->iga1_devices &= ~dev_new;
  1417. via_set_state(dev_off, VIA_STATE_OFF);
  1418. via_set_source(dev_new, IGA2);
  1419. via_set_state(dev_on, VIA_STATE_ON);
  1420. return res;
  1421. }
  1422. static const struct file_operations viafb_iga2_odev_proc_fops = {
  1423. .owner = THIS_MODULE,
  1424. .open = viafb_iga2_odev_proc_open,
  1425. .read = seq_read,
  1426. .llseek = seq_lseek,
  1427. .release = single_release,
  1428. .write = viafb_iga2_odev_proc_write,
  1429. };
  1430. #define IS_VT1636(lvds_chip) ((lvds_chip).lvds_chip_name == VT1636_LVDS)
  1431. static void viafb_init_proc(struct viafb_shared *shared)
  1432. {
  1433. struct proc_dir_entry *iga1_entry, *iga2_entry,
  1434. *viafb_entry = proc_mkdir("viafb", NULL);
  1435. shared->proc_entry = viafb_entry;
  1436. if (viafb_entry) {
  1437. #ifdef CONFIG_FB_VIA_DIRECT_PROCFS
  1438. proc_create("dvp0", 0, viafb_entry, &viafb_dvp0_proc_fops);
  1439. proc_create("dvp1", 0, viafb_entry, &viafb_dvp1_proc_fops);
  1440. proc_create("dfph", 0, viafb_entry, &viafb_dfph_proc_fops);
  1441. proc_create("dfpl", 0, viafb_entry, &viafb_dfpl_proc_fops);
  1442. if (IS_VT1636(shared->chip_info.lvds_chip_info)
  1443. || IS_VT1636(shared->chip_info.lvds_chip_info2))
  1444. proc_create("vt1636", 0, viafb_entry,
  1445. &viafb_vt1636_proc_fops);
  1446. #endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
  1447. proc_create("supported_output_devices", 0, viafb_entry,
  1448. &viafb_sup_odev_proc_fops);
  1449. iga1_entry = proc_mkdir("iga1", viafb_entry);
  1450. shared->iga1_proc_entry = iga1_entry;
  1451. proc_create("output_devices", 0, iga1_entry,
  1452. &viafb_iga1_odev_proc_fops);
  1453. iga2_entry = proc_mkdir("iga2", viafb_entry);
  1454. shared->iga2_proc_entry = iga2_entry;
  1455. proc_create("output_devices", 0, iga2_entry,
  1456. &viafb_iga2_odev_proc_fops);
  1457. }
  1458. }
  1459. static void viafb_remove_proc(struct viafb_shared *shared)
  1460. {
  1461. struct proc_dir_entry *viafb_entry = shared->proc_entry,
  1462. *iga1_entry = shared->iga1_proc_entry,
  1463. *iga2_entry = shared->iga2_proc_entry;
  1464. if (!viafb_entry)
  1465. return;
  1466. remove_proc_entry("output_devices", iga2_entry);
  1467. remove_proc_entry("iga2", viafb_entry);
  1468. remove_proc_entry("output_devices", iga1_entry);
  1469. remove_proc_entry("iga1", viafb_entry);
  1470. remove_proc_entry("supported_output_devices", viafb_entry);
  1471. #ifdef CONFIG_FB_VIA_DIRECT_PROCFS
  1472. remove_proc_entry("dvp0", viafb_entry);/* parent dir */
  1473. remove_proc_entry("dvp1", viafb_entry);
  1474. remove_proc_entry("dfph", viafb_entry);
  1475. remove_proc_entry("dfpl", viafb_entry);
  1476. if (IS_VT1636(shared->chip_info.lvds_chip_info)
  1477. || IS_VT1636(shared->chip_info.lvds_chip_info2))
  1478. remove_proc_entry("vt1636", viafb_entry);
  1479. #endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
  1480. remove_proc_entry("viafb", NULL);
  1481. }
  1482. #undef IS_VT1636
  1483. static int parse_mode(const char *str, u32 *xres, u32 *yres)
  1484. {
  1485. char *ptr;
  1486. if (!str) {
  1487. *xres = 640;
  1488. *yres = 480;
  1489. return 0;
  1490. }
  1491. *xres = simple_strtoul(str, &ptr, 10);
  1492. if (ptr[0] != 'x')
  1493. return -EINVAL;
  1494. *yres = simple_strtoul(&ptr[1], &ptr, 10);
  1495. if (ptr[0])
  1496. return -EINVAL;
  1497. return 0;
  1498. }
  1499. #ifdef CONFIG_PM
  1500. static int viafb_suspend(void *unused)
  1501. {
  1502. console_lock();
  1503. fb_set_suspend(viafbinfo, 1);
  1504. viafb_sync(viafbinfo);
  1505. console_unlock();
  1506. return 0;
  1507. }
  1508. static int viafb_resume(void *unused)
  1509. {
  1510. console_lock();
  1511. if (viaparinfo->shared->vdev->engine_mmio)
  1512. viafb_reset_engine(viaparinfo);
  1513. viafb_set_par(viafbinfo);
  1514. if (viafb_dual_fb)
  1515. viafb_set_par(viafbinfo1);
  1516. fb_set_suspend(viafbinfo, 0);
  1517. console_unlock();
  1518. return 0;
  1519. }
  1520. static struct viafb_pm_hooks viafb_fb_pm_hooks = {
  1521. .suspend = viafb_suspend,
  1522. .resume = viafb_resume
  1523. };
  1524. #endif
  1525. int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
  1526. {
  1527. u32 default_xres, default_yres;
  1528. struct VideoModeTable *vmode_entry;
  1529. struct fb_var_screeninfo default_var;
  1530. int rc;
  1531. u32 viafb_par_length;
  1532. DEBUG_MSG(KERN_INFO "VIAFB PCI Probe!!\n");
  1533. memset(&default_var, 0, sizeof(default_var));
  1534. viafb_par_length = ALIGN(sizeof(struct viafb_par), BITS_PER_LONG/8);
  1535. /* Allocate fb_info and ***_par here, also including some other needed
  1536. * variables
  1537. */
  1538. viafbinfo = framebuffer_alloc(viafb_par_length +
  1539. ALIGN(sizeof(struct viafb_shared), BITS_PER_LONG/8),
  1540. &vdev->pdev->dev);
  1541. if (!viafbinfo) {
  1542. printk(KERN_ERR"Could not allocate memory for viafb_info.\n");
  1543. return -ENOMEM;
  1544. }
  1545. viaparinfo = (struct viafb_par *)viafbinfo->par;
  1546. viaparinfo->shared = viafbinfo->par + viafb_par_length;
  1547. viaparinfo->shared->vdev = vdev;
  1548. viaparinfo->vram_addr = 0;
  1549. viaparinfo->tmds_setting_info = &viaparinfo->shared->tmds_setting_info;
  1550. viaparinfo->lvds_setting_info = &viaparinfo->shared->lvds_setting_info;
  1551. viaparinfo->lvds_setting_info2 =
  1552. &viaparinfo->shared->lvds_setting_info2;
  1553. viaparinfo->chip_info = &viaparinfo->shared->chip_info;
  1554. if (viafb_dual_fb)
  1555. viafb_SAMM_ON = 1;
  1556. parse_lcd_port();
  1557. parse_dvi_port();
  1558. viafb_init_chip_info(vdev->chip_type);
  1559. /*
  1560. * The framebuffer will have been successfully mapped by
  1561. * the core (or we'd not be here), but we still need to
  1562. * set up our own accounting.
  1563. */
  1564. viaparinfo->fbmem = vdev->fbmem_start;
  1565. viaparinfo->memsize = vdev->fbmem_len;
  1566. viaparinfo->fbmem_free = viaparinfo->memsize;
  1567. viaparinfo->fbmem_used = 0;
  1568. viafbinfo->screen_base = vdev->fbmem;
  1569. viafbinfo->fix.mmio_start = vdev->engine_start;
  1570. viafbinfo->fix.mmio_len = vdev->engine_len;
  1571. viafbinfo->node = 0;
  1572. viafbinfo->fbops = &viafb_ops;
  1573. viafbinfo->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  1574. viafbinfo->pseudo_palette = pseudo_pal;
  1575. if (viafb_accel && !viafb_setup_engine(viafbinfo)) {
  1576. viafbinfo->flags |= FBINFO_HWACCEL_COPYAREA |
  1577. FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_IMAGEBLIT;
  1578. default_var.accel_flags = FB_ACCELF_TEXT;
  1579. } else {
  1580. viafbinfo->flags |= FBINFO_HWACCEL_DISABLED;
  1581. default_var.accel_flags = 0;
  1582. }
  1583. if (viafb_second_size && (viafb_second_size < 8)) {
  1584. viafb_second_offset = viaparinfo->fbmem_free -
  1585. viafb_second_size * 1024 * 1024;
  1586. } else {
  1587. viafb_second_size = 8;
  1588. viafb_second_offset = viaparinfo->fbmem_free -
  1589. viafb_second_size * 1024 * 1024;
  1590. }
  1591. parse_mode(viafb_mode, &default_xres, &default_yres);
  1592. vmode_entry = viafb_get_mode(default_xres, default_yres);
  1593. if (viafb_SAMM_ON == 1)
  1594. parse_mode(viafb_mode1, &viafb_second_xres,
  1595. &viafb_second_yres);
  1596. default_var.xres = default_xres;
  1597. default_var.yres = default_yres;
  1598. default_var.xres_virtual = default_xres;
  1599. default_var.yres_virtual = default_yres;
  1600. default_var.bits_per_pixel = viafb_bpp;
  1601. viafb_fill_var_timing_info(&default_var, viafb_get_refresh(
  1602. default_var.xres, default_var.yres, viafb_refresh),
  1603. viafb_get_mode(default_var.xres, default_var.yres));
  1604. viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo);
  1605. viafbinfo->var = default_var;
  1606. if (viafb_dual_fb) {
  1607. viafbinfo1 = framebuffer_alloc(viafb_par_length,
  1608. &vdev->pdev->dev);
  1609. if (!viafbinfo1) {
  1610. printk(KERN_ERR
  1611. "allocate the second framebuffer struct error\n");
  1612. rc = -ENOMEM;
  1613. goto out_fb_release;
  1614. }
  1615. viaparinfo1 = viafbinfo1->par;
  1616. memcpy(viaparinfo1, viaparinfo, viafb_par_length);
  1617. viaparinfo1->vram_addr = viafb_second_offset;
  1618. viaparinfo1->memsize = viaparinfo->memsize -
  1619. viafb_second_offset;
  1620. viaparinfo->memsize = viafb_second_offset;
  1621. viaparinfo1->fbmem = viaparinfo->fbmem + viafb_second_offset;
  1622. viaparinfo1->fbmem_used = viaparinfo->fbmem_used;
  1623. viaparinfo1->fbmem_free = viaparinfo1->memsize -
  1624. viaparinfo1->fbmem_used;
  1625. viaparinfo->fbmem_free = viaparinfo->memsize;
  1626. viaparinfo->fbmem_used = 0;
  1627. viaparinfo->iga_path = IGA1;
  1628. viaparinfo1->iga_path = IGA2;
  1629. memcpy(viafbinfo1, viafbinfo, sizeof(struct fb_info));
  1630. viafbinfo1->par = viaparinfo1;
  1631. viafbinfo1->screen_base = viafbinfo->screen_base +
  1632. viafb_second_offset;
  1633. default_var.xres = viafb_second_xres;
  1634. default_var.yres = viafb_second_yres;
  1635. default_var.xres_virtual = viafb_second_xres;
  1636. default_var.yres_virtual = viafb_second_yres;
  1637. default_var.bits_per_pixel = viafb_bpp1;
  1638. viafb_fill_var_timing_info(&default_var, viafb_get_refresh(
  1639. default_var.xres, default_var.yres, viafb_refresh1),
  1640. viafb_get_mode(default_var.xres, default_var.yres));
  1641. viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1);
  1642. viafb_check_var(&default_var, viafbinfo1);
  1643. viafbinfo1->var = default_var;
  1644. viafb_update_fix(viafbinfo1);
  1645. viaparinfo1->depth = fb_get_color_depth(&viafbinfo1->var,
  1646. &viafbinfo1->fix);
  1647. }
  1648. viafb_check_var(&viafbinfo->var, viafbinfo);
  1649. viafb_update_fix(viafbinfo);
  1650. viaparinfo->depth = fb_get_color_depth(&viafbinfo->var,
  1651. &viafbinfo->fix);
  1652. default_var.activate = FB_ACTIVATE_NOW;
  1653. rc = fb_alloc_cmap(&viafbinfo->cmap, 256, 0);
  1654. if (rc)
  1655. goto out_fb1_release;
  1656. if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
  1657. && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)) {
  1658. rc = register_framebuffer(viafbinfo1);
  1659. if (rc)
  1660. goto out_dealloc_cmap;
  1661. }
  1662. rc = register_framebuffer(viafbinfo);
  1663. if (rc)
  1664. goto out_fb1_unreg_lcd_cle266;
  1665. if (viafb_dual_fb && ((viafb_primary_dev != LCD_Device)
  1666. || (viaparinfo->chip_info->gfx_chip_name !=
  1667. UNICHROME_CLE266))) {
  1668. rc = register_framebuffer(viafbinfo1);
  1669. if (rc)
  1670. goto out_fb_unreg;
  1671. }
  1672. DEBUG_MSG(KERN_INFO "fb%d: %s frame buffer device %dx%d-%dbpp\n",
  1673. viafbinfo->node, viafbinfo->fix.id, default_var.xres,
  1674. default_var.yres, default_var.bits_per_pixel);
  1675. viafb_init_proc(viaparinfo->shared);
  1676. viafb_init_dac(IGA2);
  1677. #ifdef CONFIG_PM
  1678. viafb_pm_register(&viafb_fb_pm_hooks);
  1679. #endif
  1680. return 0;
  1681. out_fb_unreg:
  1682. unregister_framebuffer(viafbinfo);
  1683. out_fb1_unreg_lcd_cle266:
  1684. if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
  1685. && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266))
  1686. unregister_framebuffer(viafbinfo1);
  1687. out_dealloc_cmap:
  1688. fb_dealloc_cmap(&viafbinfo->cmap);
  1689. out_fb1_release:
  1690. if (viafbinfo1)
  1691. framebuffer_release(viafbinfo1);
  1692. out_fb_release:
  1693. framebuffer_release(viafbinfo);
  1694. return rc;
  1695. }
  1696. void __devexit via_fb_pci_remove(struct pci_dev *pdev)
  1697. {
  1698. DEBUG_MSG(KERN_INFO "via_pci_remove!\n");
  1699. fb_dealloc_cmap(&viafbinfo->cmap);
  1700. unregister_framebuffer(viafbinfo);
  1701. if (viafb_dual_fb)
  1702. unregister_framebuffer(viafbinfo1);
  1703. viafb_remove_proc(viaparinfo->shared);
  1704. framebuffer_release(viafbinfo);
  1705. if (viafb_dual_fb)
  1706. framebuffer_release(viafbinfo1);
  1707. }
  1708. #ifndef MODULE
  1709. static int __init viafb_setup(char *options)
  1710. {
  1711. char *this_opt;
  1712. DEBUG_MSG(KERN_INFO "viafb_setup!\n");
  1713. if (!options || !*options)
  1714. return 0;
  1715. while ((this_opt = strsep(&options, ",")) != NULL) {
  1716. if (!*this_opt)
  1717. continue;
  1718. if (!strncmp(this_opt, "viafb_mode1=", 12))
  1719. viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
  1720. else if (!strncmp(this_opt, "viafb_mode=", 11))
  1721. viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
  1722. else if (!strncmp(this_opt, "viafb_bpp1=", 11))
  1723. strict_strtoul(this_opt + 11, 0,
  1724. (unsigned long *)&viafb_bpp1);
  1725. else if (!strncmp(this_opt, "viafb_bpp=", 10))
  1726. strict_strtoul(this_opt + 10, 0,
  1727. (unsigned long *)&viafb_bpp);
  1728. else if (!strncmp(this_opt, "viafb_refresh1=", 15))
  1729. strict_strtoul(this_opt + 15, 0,
  1730. (unsigned long *)&viafb_refresh1);
  1731. else if (!strncmp(this_opt, "viafb_refresh=", 14))
  1732. strict_strtoul(this_opt + 14, 0,
  1733. (unsigned long *)&viafb_refresh);
  1734. else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21))
  1735. strict_strtoul(this_opt + 21, 0,
  1736. (unsigned long *)&viafb_lcd_dsp_method);
  1737. else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19))
  1738. strict_strtoul(this_opt + 19, 0,
  1739. (unsigned long *)&viafb_lcd_panel_id);
  1740. else if (!strncmp(this_opt, "viafb_accel=", 12))
  1741. strict_strtoul(this_opt + 12, 0,
  1742. (unsigned long *)&viafb_accel);
  1743. else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14))
  1744. strict_strtoul(this_opt + 14, 0,
  1745. (unsigned long *)&viafb_SAMM_ON);
  1746. else if (!strncmp(this_opt, "viafb_active_dev=", 17))
  1747. viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
  1748. else if (!strncmp(this_opt,
  1749. "viafb_display_hardware_layout=", 30))
  1750. strict_strtoul(this_opt + 30, 0,
  1751. (unsigned long *)&viafb_display_hardware_layout);
  1752. else if (!strncmp(this_opt, "viafb_second_size=", 18))
  1753. strict_strtoul(this_opt + 18, 0,
  1754. (unsigned long *)&viafb_second_size);
  1755. else if (!strncmp(this_opt,
  1756. "viafb_platform_epia_dvi=", 24))
  1757. strict_strtoul(this_opt + 24, 0,
  1758. (unsigned long *)&viafb_platform_epia_dvi);
  1759. else if (!strncmp(this_opt,
  1760. "viafb_device_lcd_dualedge=", 26))
  1761. strict_strtoul(this_opt + 26, 0,
  1762. (unsigned long *)&viafb_device_lcd_dualedge);
  1763. else if (!strncmp(this_opt, "viafb_bus_width=", 16))
  1764. strict_strtoul(this_opt + 16, 0,
  1765. (unsigned long *)&viafb_bus_width);
  1766. else if (!strncmp(this_opt, "viafb_lcd_mode=", 15))
  1767. strict_strtoul(this_opt + 15, 0,
  1768. (unsigned long *)&viafb_lcd_mode);
  1769. else if (!strncmp(this_opt, "viafb_lcd_port=", 15))
  1770. viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
  1771. else if (!strncmp(this_opt, "viafb_dvi_port=", 15))
  1772. viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
  1773. }
  1774. return 0;
  1775. }
  1776. #endif
  1777. /*
  1778. * These are called out of via-core for now.
  1779. */
  1780. int __init viafb_init(void)
  1781. {
  1782. u32 dummy_x, dummy_y;
  1783. #ifndef MODULE
  1784. char *option = NULL;
  1785. if (fb_get_options("viafb", &option))
  1786. return -ENODEV;
  1787. viafb_setup(option);
  1788. #endif
  1789. if (parse_mode(viafb_mode, &dummy_x, &dummy_y)
  1790. || !viafb_get_mode(dummy_x, dummy_y)
  1791. || parse_mode(viafb_mode1, &dummy_x, &dummy_y)
  1792. || !viafb_get_mode(dummy_x, dummy_y)
  1793. || viafb_bpp < 0 || viafb_bpp > 32
  1794. || viafb_bpp1 < 0 || viafb_bpp1 > 32
  1795. || parse_active_dev())
  1796. return -EINVAL;
  1797. printk(KERN_INFO
  1798. "VIA Graphics Intergration Chipset framebuffer %d.%d initializing\n",
  1799. VERSION_MAJOR, VERSION_MINOR);
  1800. return 0;
  1801. }
  1802. void __exit viafb_exit(void)
  1803. {
  1804. DEBUG_MSG(KERN_INFO "viafb_exit!\n");
  1805. }
  1806. static struct fb_ops viafb_ops = {
  1807. .owner = THIS_MODULE,
  1808. .fb_open = viafb_open,
  1809. .fb_release = viafb_release,
  1810. .fb_check_var = viafb_check_var,
  1811. .fb_set_par = viafb_set_par,
  1812. .fb_setcolreg = viafb_setcolreg,
  1813. .fb_pan_display = viafb_pan_display,
  1814. .fb_blank = viafb_blank,
  1815. .fb_fillrect = viafb_fillrect,
  1816. .fb_copyarea = viafb_copyarea,
  1817. .fb_imageblit = viafb_imageblit,
  1818. .fb_cursor = viafb_cursor,
  1819. .fb_ioctl = viafb_ioctl,
  1820. .fb_sync = viafb_sync,
  1821. };
  1822. #ifdef MODULE
  1823. module_param(viafb_mode, charp, S_IRUSR);
  1824. MODULE_PARM_DESC(viafb_mode, "Set resolution (default=640x480)");
  1825. module_param(viafb_mode1, charp, S_IRUSR);
  1826. MODULE_PARM_DESC(viafb_mode1, "Set resolution (default=640x480)");
  1827. module_param(viafb_bpp, int, S_IRUSR);
  1828. MODULE_PARM_DESC(viafb_bpp, "Set color depth (default=32bpp)");
  1829. module_param(viafb_bpp1, int, S_IRUSR);
  1830. MODULE_PARM_DESC(viafb_bpp1, "Set color depth (default=32bpp)");
  1831. module_param(viafb_refresh, int, S_IRUSR);
  1832. MODULE_PARM_DESC(viafb_refresh,
  1833. "Set CRT viafb_refresh rate (default = 60)");
  1834. module_param(viafb_refresh1, int, S_IRUSR);
  1835. MODULE_PARM_DESC(viafb_refresh1,
  1836. "Set CRT refresh rate (default = 60)");
  1837. module_param(viafb_lcd_panel_id, int, S_IRUSR);
  1838. MODULE_PARM_DESC(viafb_lcd_panel_id,
  1839. "Set Flat Panel type(Default=1024x768)");
  1840. module_param(viafb_lcd_dsp_method, int, S_IRUSR);
  1841. MODULE_PARM_DESC(viafb_lcd_dsp_method,
  1842. "Set Flat Panel display scaling method.(Default=Expandsion)");
  1843. module_param(viafb_SAMM_ON, int, S_IRUSR);
  1844. MODULE_PARM_DESC(viafb_SAMM_ON,
  1845. "Turn on/off flag of SAMM(Default=OFF)");
  1846. module_param(viafb_accel, int, S_IRUSR);
  1847. MODULE_PARM_DESC(viafb_accel,
  1848. "Set 2D Hardware Acceleration: 0 = OFF, 1 = ON (default)");
  1849. module_param(viafb_active_dev, charp, S_IRUSR);
  1850. MODULE_PARM_DESC(viafb_active_dev, "Specify active devices.");
  1851. module_param(viafb_display_hardware_layout, int, S_IRUSR);
  1852. MODULE_PARM_DESC(viafb_display_hardware_layout,
  1853. "Display Hardware Layout (LCD Only, DVI Only...,etc)");
  1854. module_param(viafb_second_size, int, S_IRUSR);
  1855. MODULE_PARM_DESC(viafb_second_size,
  1856. "Set secondary device memory size");
  1857. module_param(viafb_dual_fb, int, S_IRUSR);
  1858. MODULE_PARM_DESC(viafb_dual_fb,
  1859. "Turn on/off flag of dual framebuffer devices.(Default = OFF)");
  1860. module_param(viafb_platform_epia_dvi, int, S_IRUSR);
  1861. MODULE_PARM_DESC(viafb_platform_epia_dvi,
  1862. "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)");
  1863. module_param(viafb_device_lcd_dualedge, int, S_IRUSR);
  1864. MODULE_PARM_DESC(viafb_device_lcd_dualedge,
  1865. "Turn on/off flag of dual edge panel.(Default = OFF)");
  1866. module_param(viafb_bus_width, int, S_IRUSR);
  1867. MODULE_PARM_DESC(viafb_bus_width,
  1868. "Set bus width of panel.(Default = 12)");
  1869. module_param(viafb_lcd_mode, int, S_IRUSR);
  1870. MODULE_PARM_DESC(viafb_lcd_mode,
  1871. "Set Flat Panel mode(Default=OPENLDI)");
  1872. module_param(viafb_lcd_port, charp, S_IRUSR);
  1873. MODULE_PARM_DESC(viafb_lcd_port, "Specify LCD output port.");
  1874. module_param(viafb_dvi_port, charp, S_IRUSR);
  1875. MODULE_PARM_DESC(viafb_dvi_port, "Specify DVI output port.");
  1876. MODULE_LICENSE("GPL");
  1877. #endif