viafbdev.c 59 KB

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