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