viafbdev.c 59 KB

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