viafbdev.c 56 KB

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