neofb.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236
  1. /*
  2. * linux/drivers/video/neofb.c -- NeoMagic Framebuffer Driver
  3. *
  4. * Copyright (c) 2001-2002 Denis Oliver Kropp <dok@directfb.org>
  5. *
  6. *
  7. * Card specific code is based on XFree86's neomagic driver.
  8. * Framebuffer framework code is based on code of cyber2000fb.
  9. *
  10. * This file is subject to the terms and conditions of the GNU General
  11. * Public License. See the file COPYING in the main directory of this
  12. * archive for more details.
  13. *
  14. *
  15. * 0.4.1
  16. * - Cosmetic changes (dok)
  17. *
  18. * 0.4
  19. * - Toshiba Libretto support, allow modes larger than LCD size if
  20. * LCD is disabled, keep BIOS settings if internal/external display
  21. * haven't been enabled explicitly
  22. * (Thomas J. Moore <dark@mama.indstate.edu>)
  23. *
  24. * 0.3.3
  25. * - Porting over to new fbdev api. (jsimmons)
  26. *
  27. * 0.3.2
  28. * - got rid of all floating point (dok)
  29. *
  30. * 0.3.1
  31. * - added module license (dok)
  32. *
  33. * 0.3
  34. * - hardware accelerated clear and move for 2200 and above (dok)
  35. * - maximum allowed dotclock is handled now (dok)
  36. *
  37. * 0.2.1
  38. * - correct panning after X usage (dok)
  39. * - added module and kernel parameters (dok)
  40. * - no stretching if external display is enabled (dok)
  41. *
  42. * 0.2
  43. * - initial version (dok)
  44. *
  45. *
  46. * TODO
  47. * - ioctl for internal/external switching
  48. * - blanking
  49. * - 32bit depth support, maybe impossible
  50. * - disable pan-on-sync, need specs
  51. *
  52. * BUGS
  53. * - white margin on bootup like with tdfxfb (colormap problem?)
  54. *
  55. */
  56. #include <linux/module.h>
  57. #include <linux/kernel.h>
  58. #include <linux/errno.h>
  59. #include <linux/string.h>
  60. #include <linux/mm.h>
  61. #include <linux/slab.h>
  62. #include <linux/delay.h>
  63. #include <linux/fb.h>
  64. #include <linux/pci.h>
  65. #include <linux/init.h>
  66. #ifdef CONFIG_TOSHIBA
  67. #include <linux/toshiba.h>
  68. #endif
  69. #include <asm/io.h>
  70. #include <asm/irq.h>
  71. #include <asm/pgtable.h>
  72. #include <video/vga.h>
  73. #include <video/neomagic.h>
  74. #define NEOFB_VERSION "0.4.2"
  75. /* --------------------------------------------------------------------- */
  76. static bool internal;
  77. static bool external;
  78. static bool libretto;
  79. static bool nostretch;
  80. static bool nopciburst;
  81. static char *mode_option = NULL;
  82. #ifdef MODULE
  83. MODULE_AUTHOR("(c) 2001-2002 Denis Oliver Kropp <dok@convergence.de>");
  84. MODULE_LICENSE("GPL");
  85. MODULE_DESCRIPTION("FBDev driver for NeoMagic PCI Chips");
  86. module_param(internal, bool, 0);
  87. MODULE_PARM_DESC(internal, "Enable output on internal LCD Display.");
  88. module_param(external, bool, 0);
  89. MODULE_PARM_DESC(external, "Enable output on external CRT.");
  90. module_param(libretto, bool, 0);
  91. MODULE_PARM_DESC(libretto, "Force Libretto 100/110 800x480 LCD.");
  92. module_param(nostretch, bool, 0);
  93. MODULE_PARM_DESC(nostretch,
  94. "Disable stretching of modes smaller than LCD.");
  95. module_param(nopciburst, bool, 0);
  96. MODULE_PARM_DESC(nopciburst, "Disable PCI burst mode.");
  97. module_param(mode_option, charp, 0);
  98. MODULE_PARM_DESC(mode_option, "Preferred video mode ('640x480-8@60', etc)");
  99. #endif
  100. /* --------------------------------------------------------------------- */
  101. static biosMode bios8[] = {
  102. {320, 240, 0x40},
  103. {300, 400, 0x42},
  104. {640, 400, 0x20},
  105. {640, 480, 0x21},
  106. {800, 600, 0x23},
  107. {1024, 768, 0x25},
  108. };
  109. static biosMode bios16[] = {
  110. {320, 200, 0x2e},
  111. {320, 240, 0x41},
  112. {300, 400, 0x43},
  113. {640, 480, 0x31},
  114. {800, 600, 0x34},
  115. {1024, 768, 0x37},
  116. };
  117. static biosMode bios24[] = {
  118. {640, 480, 0x32},
  119. {800, 600, 0x35},
  120. {1024, 768, 0x38}
  121. };
  122. #ifdef NO_32BIT_SUPPORT_YET
  123. /* FIXME: guessed values, wrong */
  124. static biosMode bios32[] = {
  125. {640, 480, 0x33},
  126. {800, 600, 0x36},
  127. {1024, 768, 0x39}
  128. };
  129. #endif
  130. static inline void write_le32(int regindex, u32 val, const struct neofb_par *par)
  131. {
  132. writel(val, par->neo2200 + par->cursorOff + regindex);
  133. }
  134. static int neoFindMode(int xres, int yres, int depth)
  135. {
  136. int xres_s;
  137. int i, size;
  138. biosMode *mode;
  139. switch (depth) {
  140. case 8:
  141. size = ARRAY_SIZE(bios8);
  142. mode = bios8;
  143. break;
  144. case 16:
  145. size = ARRAY_SIZE(bios16);
  146. mode = bios16;
  147. break;
  148. case 24:
  149. size = ARRAY_SIZE(bios24);
  150. mode = bios24;
  151. break;
  152. #ifdef NO_32BIT_SUPPORT_YET
  153. case 32:
  154. size = ARRAY_SIZE(bios32);
  155. mode = bios32;
  156. break;
  157. #endif
  158. default:
  159. return 0;
  160. }
  161. for (i = 0; i < size; i++) {
  162. if (xres <= mode[i].x_res) {
  163. xres_s = mode[i].x_res;
  164. for (; i < size; i++) {
  165. if (mode[i].x_res != xres_s)
  166. return mode[i - 1].mode;
  167. if (yres <= mode[i].y_res)
  168. return mode[i].mode;
  169. }
  170. }
  171. }
  172. return mode[size - 1].mode;
  173. }
  174. /*
  175. * neoCalcVCLK --
  176. *
  177. * Determine the closest clock frequency to the one requested.
  178. */
  179. #define MAX_N 127
  180. #define MAX_D 31
  181. #define MAX_F 1
  182. static void neoCalcVCLK(const struct fb_info *info,
  183. struct neofb_par *par, long freq)
  184. {
  185. int n, d, f;
  186. int n_best = 0, d_best = 0, f_best = 0;
  187. long f_best_diff = 0x7ffff;
  188. for (f = 0; f <= MAX_F; f++)
  189. for (d = 0; d <= MAX_D; d++)
  190. for (n = 0; n <= MAX_N; n++) {
  191. long f_out;
  192. long f_diff;
  193. f_out = ((14318 * (n + 1)) / (d + 1)) >> f;
  194. f_diff = abs(f_out - freq);
  195. if (f_diff <= f_best_diff) {
  196. f_best_diff = f_diff;
  197. n_best = n;
  198. d_best = d;
  199. f_best = f;
  200. }
  201. if (f_out > freq)
  202. break;
  203. }
  204. if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 ||
  205. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2230 ||
  206. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2360 ||
  207. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2380) {
  208. /* NOT_DONE: We are trying the full range of the 2200 clock.
  209. We should be able to try n up to 2047 */
  210. par->VCLK3NumeratorLow = n_best;
  211. par->VCLK3NumeratorHigh = (f_best << 7);
  212. } else
  213. par->VCLK3NumeratorLow = n_best | (f_best << 7);
  214. par->VCLK3Denominator = d_best;
  215. #ifdef NEOFB_DEBUG
  216. printk(KERN_DEBUG "neoVCLK: f:%ld NumLow=%d NumHi=%d Den=%d Df=%ld\n",
  217. freq,
  218. par->VCLK3NumeratorLow,
  219. par->VCLK3NumeratorHigh,
  220. par->VCLK3Denominator, f_best_diff);
  221. #endif
  222. }
  223. /*
  224. * vgaHWInit --
  225. * Handle the initialization, etc. of a screen.
  226. * Return FALSE on failure.
  227. */
  228. static int vgaHWInit(const struct fb_var_screeninfo *var,
  229. struct neofb_par *par)
  230. {
  231. int hsync_end = var->xres + var->right_margin + var->hsync_len;
  232. int htotal = (hsync_end + var->left_margin) >> 3;
  233. int vsync_start = var->yres + var->lower_margin;
  234. int vsync_end = vsync_start + var->vsync_len;
  235. int vtotal = vsync_end + var->upper_margin;
  236. par->MiscOutReg = 0x23;
  237. if (!(var->sync & FB_SYNC_HOR_HIGH_ACT))
  238. par->MiscOutReg |= 0x40;
  239. if (!(var->sync & FB_SYNC_VERT_HIGH_ACT))
  240. par->MiscOutReg |= 0x80;
  241. /*
  242. * Time Sequencer
  243. */
  244. par->Sequencer[0] = 0x00;
  245. par->Sequencer[1] = 0x01;
  246. par->Sequencer[2] = 0x0F;
  247. par->Sequencer[3] = 0x00; /* Font select */
  248. par->Sequencer[4] = 0x0E; /* Misc */
  249. /*
  250. * CRTC Controller
  251. */
  252. par->CRTC[0] = htotal - 5;
  253. par->CRTC[1] = (var->xres >> 3) - 1;
  254. par->CRTC[2] = (var->xres >> 3) - 1;
  255. par->CRTC[3] = ((htotal - 1) & 0x1F) | 0x80;
  256. par->CRTC[4] = ((var->xres + var->right_margin) >> 3);
  257. par->CRTC[5] = (((htotal - 1) & 0x20) << 2)
  258. | (((hsync_end >> 3)) & 0x1F);
  259. par->CRTC[6] = (vtotal - 2) & 0xFF;
  260. par->CRTC[7] = (((vtotal - 2) & 0x100) >> 8)
  261. | (((var->yres - 1) & 0x100) >> 7)
  262. | ((vsync_start & 0x100) >> 6)
  263. | (((var->yres - 1) & 0x100) >> 5)
  264. | 0x10 | (((vtotal - 2) & 0x200) >> 4)
  265. | (((var->yres - 1) & 0x200) >> 3)
  266. | ((vsync_start & 0x200) >> 2);
  267. par->CRTC[8] = 0x00;
  268. par->CRTC[9] = (((var->yres - 1) & 0x200) >> 4) | 0x40;
  269. if (var->vmode & FB_VMODE_DOUBLE)
  270. par->CRTC[9] |= 0x80;
  271. par->CRTC[10] = 0x00;
  272. par->CRTC[11] = 0x00;
  273. par->CRTC[12] = 0x00;
  274. par->CRTC[13] = 0x00;
  275. par->CRTC[14] = 0x00;
  276. par->CRTC[15] = 0x00;
  277. par->CRTC[16] = vsync_start & 0xFF;
  278. par->CRTC[17] = (vsync_end & 0x0F) | 0x20;
  279. par->CRTC[18] = (var->yres - 1) & 0xFF;
  280. par->CRTC[19] = var->xres_virtual >> 4;
  281. par->CRTC[20] = 0x00;
  282. par->CRTC[21] = (var->yres - 1) & 0xFF;
  283. par->CRTC[22] = (vtotal - 1) & 0xFF;
  284. par->CRTC[23] = 0xC3;
  285. par->CRTC[24] = 0xFF;
  286. /*
  287. * are these unnecessary?
  288. * vgaHWHBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN | KGA_ENABLE_ON_ZERO);
  289. * vgaHWVBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN | KGA_ENABLE_ON_ZERO);
  290. */
  291. /*
  292. * Graphics Display Controller
  293. */
  294. par->Graphics[0] = 0x00;
  295. par->Graphics[1] = 0x00;
  296. par->Graphics[2] = 0x00;
  297. par->Graphics[3] = 0x00;
  298. par->Graphics[4] = 0x00;
  299. par->Graphics[5] = 0x40;
  300. par->Graphics[6] = 0x05; /* only map 64k VGA memory !!!! */
  301. par->Graphics[7] = 0x0F;
  302. par->Graphics[8] = 0xFF;
  303. par->Attribute[0] = 0x00; /* standard colormap translation */
  304. par->Attribute[1] = 0x01;
  305. par->Attribute[2] = 0x02;
  306. par->Attribute[3] = 0x03;
  307. par->Attribute[4] = 0x04;
  308. par->Attribute[5] = 0x05;
  309. par->Attribute[6] = 0x06;
  310. par->Attribute[7] = 0x07;
  311. par->Attribute[8] = 0x08;
  312. par->Attribute[9] = 0x09;
  313. par->Attribute[10] = 0x0A;
  314. par->Attribute[11] = 0x0B;
  315. par->Attribute[12] = 0x0C;
  316. par->Attribute[13] = 0x0D;
  317. par->Attribute[14] = 0x0E;
  318. par->Attribute[15] = 0x0F;
  319. par->Attribute[16] = 0x41;
  320. par->Attribute[17] = 0xFF;
  321. par->Attribute[18] = 0x0F;
  322. par->Attribute[19] = 0x00;
  323. par->Attribute[20] = 0x00;
  324. return 0;
  325. }
  326. static void vgaHWLock(struct vgastate *state)
  327. {
  328. /* Protect CRTC[0-7] */
  329. vga_wcrt(state->vgabase, 0x11, vga_rcrt(state->vgabase, 0x11) | 0x80);
  330. }
  331. static void vgaHWUnlock(void)
  332. {
  333. /* Unprotect CRTC[0-7] */
  334. vga_wcrt(NULL, 0x11, vga_rcrt(NULL, 0x11) & ~0x80);
  335. }
  336. static void neoLock(struct vgastate *state)
  337. {
  338. vga_wgfx(state->vgabase, 0x09, 0x00);
  339. vgaHWLock(state);
  340. }
  341. static void neoUnlock(void)
  342. {
  343. vgaHWUnlock();
  344. vga_wgfx(NULL, 0x09, 0x26);
  345. }
  346. /*
  347. * VGA Palette management
  348. */
  349. static int paletteEnabled = 0;
  350. static inline void VGAenablePalette(void)
  351. {
  352. vga_r(NULL, VGA_IS1_RC);
  353. vga_w(NULL, VGA_ATT_W, 0x00);
  354. paletteEnabled = 1;
  355. }
  356. static inline void VGAdisablePalette(void)
  357. {
  358. vga_r(NULL, VGA_IS1_RC);
  359. vga_w(NULL, VGA_ATT_W, 0x20);
  360. paletteEnabled = 0;
  361. }
  362. static inline void VGAwATTR(u8 index, u8 value)
  363. {
  364. if (paletteEnabled)
  365. index &= ~0x20;
  366. else
  367. index |= 0x20;
  368. vga_r(NULL, VGA_IS1_RC);
  369. vga_wattr(NULL, index, value);
  370. }
  371. static void vgaHWProtect(int on)
  372. {
  373. unsigned char tmp;
  374. tmp = vga_rseq(NULL, 0x01);
  375. if (on) {
  376. /*
  377. * Turn off screen and disable sequencer.
  378. */
  379. vga_wseq(NULL, 0x00, 0x01); /* Synchronous Reset */
  380. vga_wseq(NULL, 0x01, tmp | 0x20); /* disable the display */
  381. VGAenablePalette();
  382. } else {
  383. /*
  384. * Reenable sequencer, then turn on screen.
  385. */
  386. vga_wseq(NULL, 0x01, tmp & ~0x20); /* reenable display */
  387. vga_wseq(NULL, 0x00, 0x03); /* clear synchronousreset */
  388. VGAdisablePalette();
  389. }
  390. }
  391. static void vgaHWRestore(const struct fb_info *info,
  392. const struct neofb_par *par)
  393. {
  394. int i;
  395. vga_w(NULL, VGA_MIS_W, par->MiscOutReg);
  396. for (i = 1; i < 5; i++)
  397. vga_wseq(NULL, i, par->Sequencer[i]);
  398. /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 or CRTC[17] */
  399. vga_wcrt(NULL, 17, par->CRTC[17] & ~0x80);
  400. for (i = 0; i < 25; i++)
  401. vga_wcrt(NULL, i, par->CRTC[i]);
  402. for (i = 0; i < 9; i++)
  403. vga_wgfx(NULL, i, par->Graphics[i]);
  404. VGAenablePalette();
  405. for (i = 0; i < 21; i++)
  406. VGAwATTR(i, par->Attribute[i]);
  407. VGAdisablePalette();
  408. }
  409. /* -------------------- Hardware specific routines ------------------------- */
  410. /*
  411. * Hardware Acceleration for Neo2200+
  412. */
  413. static inline int neo2200_sync(struct fb_info *info)
  414. {
  415. struct neofb_par *par = info->par;
  416. while (readl(&par->neo2200->bltStat) & 1)
  417. cpu_relax();
  418. return 0;
  419. }
  420. static inline void neo2200_wait_fifo(struct fb_info *info,
  421. int requested_fifo_space)
  422. {
  423. // ndev->neo.waitfifo_calls++;
  424. // ndev->neo.waitfifo_sum += requested_fifo_space;
  425. /* FIXME: does not work
  426. if (neo_fifo_space < requested_fifo_space)
  427. {
  428. neo_fifo_waitcycles++;
  429. while (1)
  430. {
  431. neo_fifo_space = (neo2200->bltStat >> 8);
  432. if (neo_fifo_space >= requested_fifo_space)
  433. break;
  434. }
  435. }
  436. else
  437. {
  438. neo_fifo_cache_hits++;
  439. }
  440. neo_fifo_space -= requested_fifo_space;
  441. */
  442. neo2200_sync(info);
  443. }
  444. static inline void neo2200_accel_init(struct fb_info *info,
  445. struct fb_var_screeninfo *var)
  446. {
  447. struct neofb_par *par = info->par;
  448. Neo2200 __iomem *neo2200 = par->neo2200;
  449. u32 bltMod, pitch;
  450. neo2200_sync(info);
  451. switch (var->bits_per_pixel) {
  452. case 8:
  453. bltMod = NEO_MODE1_DEPTH8;
  454. pitch = var->xres_virtual;
  455. break;
  456. case 15:
  457. case 16:
  458. bltMod = NEO_MODE1_DEPTH16;
  459. pitch = var->xres_virtual * 2;
  460. break;
  461. case 24:
  462. bltMod = NEO_MODE1_DEPTH24;
  463. pitch = var->xres_virtual * 3;
  464. break;
  465. default:
  466. printk(KERN_ERR
  467. "neofb: neo2200_accel_init: unexpected bits per pixel!\n");
  468. return;
  469. }
  470. writel(bltMod << 16, &neo2200->bltStat);
  471. writel((pitch << 16) | pitch, &neo2200->pitch);
  472. }
  473. /* --------------------------------------------------------------------- */
  474. static int
  475. neofb_open(struct fb_info *info, int user)
  476. {
  477. struct neofb_par *par = info->par;
  478. if (!par->ref_count) {
  479. memset(&par->state, 0, sizeof(struct vgastate));
  480. par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS;
  481. save_vga(&par->state);
  482. }
  483. par->ref_count++;
  484. return 0;
  485. }
  486. static int
  487. neofb_release(struct fb_info *info, int user)
  488. {
  489. struct neofb_par *par = info->par;
  490. if (!par->ref_count)
  491. return -EINVAL;
  492. if (par->ref_count == 1) {
  493. restore_vga(&par->state);
  494. }
  495. par->ref_count--;
  496. return 0;
  497. }
  498. static int
  499. neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  500. {
  501. struct neofb_par *par = info->par;
  502. int memlen, vramlen;
  503. int mode_ok = 0;
  504. DBG("neofb_check_var");
  505. if (PICOS2KHZ(var->pixclock) > par->maxClock)
  506. return -EINVAL;
  507. /* Is the mode larger than the LCD panel? */
  508. if (par->internal_display &&
  509. ((var->xres > par->NeoPanelWidth) ||
  510. (var->yres > par->NeoPanelHeight))) {
  511. printk(KERN_INFO
  512. "Mode (%dx%d) larger than the LCD panel (%dx%d)\n",
  513. var->xres, var->yres, par->NeoPanelWidth,
  514. par->NeoPanelHeight);
  515. return -EINVAL;
  516. }
  517. /* Is the mode one of the acceptable sizes? */
  518. if (!par->internal_display)
  519. mode_ok = 1;
  520. else {
  521. switch (var->xres) {
  522. case 1280:
  523. if (var->yres == 1024)
  524. mode_ok = 1;
  525. break;
  526. case 1024:
  527. if (var->yres == 768)
  528. mode_ok = 1;
  529. break;
  530. case 800:
  531. if (var->yres == (par->libretto ? 480 : 600))
  532. mode_ok = 1;
  533. break;
  534. case 640:
  535. if (var->yres == 480)
  536. mode_ok = 1;
  537. break;
  538. }
  539. }
  540. if (!mode_ok) {
  541. printk(KERN_INFO
  542. "Mode (%dx%d) won't display properly on LCD\n",
  543. var->xres, var->yres);
  544. return -EINVAL;
  545. }
  546. var->red.msb_right = 0;
  547. var->green.msb_right = 0;
  548. var->blue.msb_right = 0;
  549. var->transp.msb_right = 0;
  550. var->transp.offset = 0;
  551. var->transp.length = 0;
  552. switch (var->bits_per_pixel) {
  553. case 8: /* PSEUDOCOLOUR, 256 */
  554. var->red.offset = 0;
  555. var->red.length = 8;
  556. var->green.offset = 0;
  557. var->green.length = 8;
  558. var->blue.offset = 0;
  559. var->blue.length = 8;
  560. break;
  561. case 16: /* DIRECTCOLOUR, 64k */
  562. var->red.offset = 11;
  563. var->red.length = 5;
  564. var->green.offset = 5;
  565. var->green.length = 6;
  566. var->blue.offset = 0;
  567. var->blue.length = 5;
  568. break;
  569. case 24: /* TRUECOLOUR, 16m */
  570. var->red.offset = 16;
  571. var->red.length = 8;
  572. var->green.offset = 8;
  573. var->green.length = 8;
  574. var->blue.offset = 0;
  575. var->blue.length = 8;
  576. break;
  577. #ifdef NO_32BIT_SUPPORT_YET
  578. case 32: /* TRUECOLOUR, 16m */
  579. var->transp.offset = 24;
  580. var->transp.length = 8;
  581. var->red.offset = 16;
  582. var->red.length = 8;
  583. var->green.offset = 8;
  584. var->green.length = 8;
  585. var->blue.offset = 0;
  586. var->blue.length = 8;
  587. break;
  588. #endif
  589. default:
  590. printk(KERN_WARNING "neofb: no support for %dbpp\n",
  591. var->bits_per_pixel);
  592. return -EINVAL;
  593. }
  594. vramlen = info->fix.smem_len;
  595. if (vramlen > 4 * 1024 * 1024)
  596. vramlen = 4 * 1024 * 1024;
  597. if (var->xres_virtual < var->xres)
  598. var->xres_virtual = var->xres;
  599. memlen = var->xres_virtual * var->bits_per_pixel * var->yres_virtual >> 3;
  600. if (memlen > vramlen) {
  601. var->yres_virtual = vramlen * 8 / (var->xres_virtual *
  602. var->bits_per_pixel);
  603. memlen = var->xres_virtual * var->bits_per_pixel *
  604. var->yres_virtual / 8;
  605. }
  606. /* we must round yres/xres down, we already rounded y/xres_virtual up
  607. if it was possible. We should return -EINVAL, but I disagree */
  608. if (var->yres_virtual < var->yres)
  609. var->yres = var->yres_virtual;
  610. if (var->xoffset + var->xres > var->xres_virtual)
  611. var->xoffset = var->xres_virtual - var->xres;
  612. if (var->yoffset + var->yres > var->yres_virtual)
  613. var->yoffset = var->yres_virtual - var->yres;
  614. var->nonstd = 0;
  615. var->height = -1;
  616. var->width = -1;
  617. if (var->bits_per_pixel >= 24 || !par->neo2200)
  618. var->accel_flags &= ~FB_ACCELF_TEXT;
  619. return 0;
  620. }
  621. static int neofb_set_par(struct fb_info *info)
  622. {
  623. struct neofb_par *par = info->par;
  624. unsigned char temp;
  625. int i, clock_hi = 0;
  626. int lcd_stretch;
  627. int hoffset, voffset;
  628. int vsync_start, vtotal;
  629. DBG("neofb_set_par");
  630. neoUnlock();
  631. vgaHWProtect(1); /* Blank the screen */
  632. vsync_start = info->var.yres + info->var.lower_margin;
  633. vtotal = vsync_start + info->var.vsync_len + info->var.upper_margin;
  634. /*
  635. * This will allocate the datastructure and initialize all of the
  636. * generic VGA registers.
  637. */
  638. if (vgaHWInit(&info->var, par))
  639. return -EINVAL;
  640. /*
  641. * The default value assigned by vgaHW.c is 0x41, but this does
  642. * not work for NeoMagic.
  643. */
  644. par->Attribute[16] = 0x01;
  645. switch (info->var.bits_per_pixel) {
  646. case 8:
  647. par->CRTC[0x13] = info->var.xres_virtual >> 3;
  648. par->ExtCRTOffset = info->var.xres_virtual >> 11;
  649. par->ExtColorModeSelect = 0x11;
  650. break;
  651. case 16:
  652. par->CRTC[0x13] = info->var.xres_virtual >> 2;
  653. par->ExtCRTOffset = info->var.xres_virtual >> 10;
  654. par->ExtColorModeSelect = 0x13;
  655. break;
  656. case 24:
  657. par->CRTC[0x13] = (info->var.xres_virtual * 3) >> 3;
  658. par->ExtCRTOffset = (info->var.xres_virtual * 3) >> 11;
  659. par->ExtColorModeSelect = 0x14;
  660. break;
  661. #ifdef NO_32BIT_SUPPORT_YET
  662. case 32: /* FIXME: guessed values */
  663. par->CRTC[0x13] = info->var.xres_virtual >> 1;
  664. par->ExtCRTOffset = info->var.xres_virtual >> 9;
  665. par->ExtColorModeSelect = 0x15;
  666. break;
  667. #endif
  668. default:
  669. break;
  670. }
  671. par->ExtCRTDispAddr = 0x10;
  672. /* Vertical Extension */
  673. par->VerticalExt = (((vtotal - 2) & 0x400) >> 10)
  674. | (((info->var.yres - 1) & 0x400) >> 9)
  675. | (((vsync_start) & 0x400) >> 8)
  676. | (((vsync_start) & 0x400) >> 7);
  677. /* Fast write bursts on unless disabled. */
  678. if (par->pci_burst)
  679. par->SysIfaceCntl1 = 0x30;
  680. else
  681. par->SysIfaceCntl1 = 0x00;
  682. par->SysIfaceCntl2 = 0xc0; /* VESA Bios sets this to 0x80! */
  683. /* Initialize: by default, we want display config register to be read */
  684. par->PanelDispCntlRegRead = 1;
  685. /* Enable any user specified display devices. */
  686. par->PanelDispCntlReg1 = 0x00;
  687. if (par->internal_display)
  688. par->PanelDispCntlReg1 |= 0x02;
  689. if (par->external_display)
  690. par->PanelDispCntlReg1 |= 0x01;
  691. /* If the user did not specify any display devices, then... */
  692. if (par->PanelDispCntlReg1 == 0x00) {
  693. /* Default to internal (i.e., LCD) only. */
  694. par->PanelDispCntlReg1 = vga_rgfx(NULL, 0x20) & 0x03;
  695. }
  696. /* If we are using a fixed mode, then tell the chip we are. */
  697. switch (info->var.xres) {
  698. case 1280:
  699. par->PanelDispCntlReg1 |= 0x60;
  700. break;
  701. case 1024:
  702. par->PanelDispCntlReg1 |= 0x40;
  703. break;
  704. case 800:
  705. par->PanelDispCntlReg1 |= 0x20;
  706. break;
  707. case 640:
  708. default:
  709. break;
  710. }
  711. /* Setup shadow register locking. */
  712. switch (par->PanelDispCntlReg1 & 0x03) {
  713. case 0x01: /* External CRT only mode: */
  714. par->GeneralLockReg = 0x00;
  715. /* We need to program the VCLK for external display only mode. */
  716. par->ProgramVCLK = 1;
  717. break;
  718. case 0x02: /* Internal LCD only mode: */
  719. case 0x03: /* Simultaneous internal/external (LCD/CRT) mode: */
  720. par->GeneralLockReg = 0x01;
  721. /* Don't program the VCLK when using the LCD. */
  722. par->ProgramVCLK = 0;
  723. break;
  724. }
  725. /*
  726. * If the screen is to be stretched, turn on stretching for the
  727. * various modes.
  728. *
  729. * OPTION_LCD_STRETCH means stretching should be turned off!
  730. */
  731. par->PanelDispCntlReg2 = 0x00;
  732. par->PanelDispCntlReg3 = 0x00;
  733. if (par->lcd_stretch && (par->PanelDispCntlReg1 == 0x02) && /* LCD only */
  734. (info->var.xres != par->NeoPanelWidth)) {
  735. switch (info->var.xres) {
  736. case 320: /* Needs testing. KEM -- 24 May 98 */
  737. case 400: /* Needs testing. KEM -- 24 May 98 */
  738. case 640:
  739. case 800:
  740. case 1024:
  741. lcd_stretch = 1;
  742. par->PanelDispCntlReg2 |= 0xC6;
  743. break;
  744. default:
  745. lcd_stretch = 0;
  746. /* No stretching in these modes. */
  747. }
  748. } else
  749. lcd_stretch = 0;
  750. /*
  751. * If the screen is to be centerd, turn on the centering for the
  752. * various modes.
  753. */
  754. par->PanelVertCenterReg1 = 0x00;
  755. par->PanelVertCenterReg2 = 0x00;
  756. par->PanelVertCenterReg3 = 0x00;
  757. par->PanelVertCenterReg4 = 0x00;
  758. par->PanelVertCenterReg5 = 0x00;
  759. par->PanelHorizCenterReg1 = 0x00;
  760. par->PanelHorizCenterReg2 = 0x00;
  761. par->PanelHorizCenterReg3 = 0x00;
  762. par->PanelHorizCenterReg4 = 0x00;
  763. par->PanelHorizCenterReg5 = 0x00;
  764. if (par->PanelDispCntlReg1 & 0x02) {
  765. if (info->var.xres == par->NeoPanelWidth) {
  766. /*
  767. * No centering required when the requested display width
  768. * equals the panel width.
  769. */
  770. } else {
  771. par->PanelDispCntlReg2 |= 0x01;
  772. par->PanelDispCntlReg3 |= 0x10;
  773. /* Calculate the horizontal and vertical offsets. */
  774. if (!lcd_stretch) {
  775. hoffset =
  776. ((par->NeoPanelWidth -
  777. info->var.xres) >> 4) - 1;
  778. voffset =
  779. ((par->NeoPanelHeight -
  780. info->var.yres) >> 1) - 2;
  781. } else {
  782. /* Stretched modes cannot be centered. */
  783. hoffset = 0;
  784. voffset = 0;
  785. }
  786. switch (info->var.xres) {
  787. case 320: /* Needs testing. KEM -- 24 May 98 */
  788. par->PanelHorizCenterReg3 = hoffset;
  789. par->PanelVertCenterReg2 = voffset;
  790. break;
  791. case 400: /* Needs testing. KEM -- 24 May 98 */
  792. par->PanelHorizCenterReg4 = hoffset;
  793. par->PanelVertCenterReg1 = voffset;
  794. break;
  795. case 640:
  796. par->PanelHorizCenterReg1 = hoffset;
  797. par->PanelVertCenterReg3 = voffset;
  798. break;
  799. case 800:
  800. par->PanelHorizCenterReg2 = hoffset;
  801. par->PanelVertCenterReg4 = voffset;
  802. break;
  803. case 1024:
  804. par->PanelHorizCenterReg5 = hoffset;
  805. par->PanelVertCenterReg5 = voffset;
  806. break;
  807. case 1280:
  808. default:
  809. /* No centering in these modes. */
  810. break;
  811. }
  812. }
  813. }
  814. par->biosMode =
  815. neoFindMode(info->var.xres, info->var.yres,
  816. info->var.bits_per_pixel);
  817. /*
  818. * Calculate the VCLK that most closely matches the requested dot
  819. * clock.
  820. */
  821. neoCalcVCLK(info, par, PICOS2KHZ(info->var.pixclock));
  822. /* Since we program the clocks ourselves, always use VCLK3. */
  823. par->MiscOutReg |= 0x0C;
  824. /* alread unlocked above */
  825. /* BOGUS vga_wgfx(NULL, 0x09, 0x26); */
  826. /* don't know what this is, but it's 0 from bootup anyway */
  827. vga_wgfx(NULL, 0x15, 0x00);
  828. /* was set to 0x01 by my bios in text and vesa modes */
  829. vga_wgfx(NULL, 0x0A, par->GeneralLockReg);
  830. /*
  831. * The color mode needs to be set before calling vgaHWRestore
  832. * to ensure the DAC is initialized properly.
  833. *
  834. * NOTE: Make sure we don't change bits make sure we don't change
  835. * any reserved bits.
  836. */
  837. temp = vga_rgfx(NULL, 0x90);
  838. switch (info->fix.accel) {
  839. case FB_ACCEL_NEOMAGIC_NM2070:
  840. temp &= 0xF0; /* Save bits 7:4 */
  841. temp |= (par->ExtColorModeSelect & ~0xF0);
  842. break;
  843. case FB_ACCEL_NEOMAGIC_NM2090:
  844. case FB_ACCEL_NEOMAGIC_NM2093:
  845. case FB_ACCEL_NEOMAGIC_NM2097:
  846. case FB_ACCEL_NEOMAGIC_NM2160:
  847. case FB_ACCEL_NEOMAGIC_NM2200:
  848. case FB_ACCEL_NEOMAGIC_NM2230:
  849. case FB_ACCEL_NEOMAGIC_NM2360:
  850. case FB_ACCEL_NEOMAGIC_NM2380:
  851. temp &= 0x70; /* Save bits 6:4 */
  852. temp |= (par->ExtColorModeSelect & ~0x70);
  853. break;
  854. }
  855. vga_wgfx(NULL, 0x90, temp);
  856. /*
  857. * In some rare cases a lockup might occur if we don't delay
  858. * here. (Reported by Miles Lane)
  859. */
  860. //mdelay(200);
  861. /*
  862. * Disable horizontal and vertical graphics and text expansions so
  863. * that vgaHWRestore works properly.
  864. */
  865. temp = vga_rgfx(NULL, 0x25);
  866. temp &= 0x39;
  867. vga_wgfx(NULL, 0x25, temp);
  868. /*
  869. * Sleep for 200ms to make sure that the two operations above have
  870. * had time to take effect.
  871. */
  872. mdelay(200);
  873. /*
  874. * This function handles restoring the generic VGA registers. */
  875. vgaHWRestore(info, par);
  876. /* linear colormap for non palettized modes */
  877. switch (info->var.bits_per_pixel) {
  878. case 8:
  879. /* PseudoColor, 256 */
  880. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  881. break;
  882. case 16:
  883. /* TrueColor, 64k */
  884. info->fix.visual = FB_VISUAL_TRUECOLOR;
  885. for (i = 0; i < 64; i++) {
  886. outb(i, 0x3c8);
  887. outb(i << 1, 0x3c9);
  888. outb(i, 0x3c9);
  889. outb(i << 1, 0x3c9);
  890. }
  891. break;
  892. case 24:
  893. #ifdef NO_32BIT_SUPPORT_YET
  894. case 32:
  895. #endif
  896. /* TrueColor, 16m */
  897. info->fix.visual = FB_VISUAL_TRUECOLOR;
  898. for (i = 0; i < 256; i++) {
  899. outb(i, 0x3c8);
  900. outb(i, 0x3c9);
  901. outb(i, 0x3c9);
  902. outb(i, 0x3c9);
  903. }
  904. break;
  905. }
  906. vga_wgfx(NULL, 0x0E, par->ExtCRTDispAddr);
  907. vga_wgfx(NULL, 0x0F, par->ExtCRTOffset);
  908. temp = vga_rgfx(NULL, 0x10);
  909. temp &= 0x0F; /* Save bits 3:0 */
  910. temp |= (par->SysIfaceCntl1 & ~0x0F); /* VESA Bios sets bit 1! */
  911. vga_wgfx(NULL, 0x10, temp);
  912. vga_wgfx(NULL, 0x11, par->SysIfaceCntl2);
  913. vga_wgfx(NULL, 0x15, 0 /*par->SingleAddrPage */ );
  914. vga_wgfx(NULL, 0x16, 0 /*par->DualAddrPage */ );
  915. temp = vga_rgfx(NULL, 0x20);
  916. switch (info->fix.accel) {
  917. case FB_ACCEL_NEOMAGIC_NM2070:
  918. temp &= 0xFC; /* Save bits 7:2 */
  919. temp |= (par->PanelDispCntlReg1 & ~0xFC);
  920. break;
  921. case FB_ACCEL_NEOMAGIC_NM2090:
  922. case FB_ACCEL_NEOMAGIC_NM2093:
  923. case FB_ACCEL_NEOMAGIC_NM2097:
  924. case FB_ACCEL_NEOMAGIC_NM2160:
  925. temp &= 0xDC; /* Save bits 7:6,4:2 */
  926. temp |= (par->PanelDispCntlReg1 & ~0xDC);
  927. break;
  928. case FB_ACCEL_NEOMAGIC_NM2200:
  929. case FB_ACCEL_NEOMAGIC_NM2230:
  930. case FB_ACCEL_NEOMAGIC_NM2360:
  931. case FB_ACCEL_NEOMAGIC_NM2380:
  932. temp &= 0x98; /* Save bits 7,4:3 */
  933. temp |= (par->PanelDispCntlReg1 & ~0x98);
  934. break;
  935. }
  936. vga_wgfx(NULL, 0x20, temp);
  937. temp = vga_rgfx(NULL, 0x25);
  938. temp &= 0x38; /* Save bits 5:3 */
  939. temp |= (par->PanelDispCntlReg2 & ~0x38);
  940. vga_wgfx(NULL, 0x25, temp);
  941. if (info->fix.accel != FB_ACCEL_NEOMAGIC_NM2070) {
  942. temp = vga_rgfx(NULL, 0x30);
  943. temp &= 0xEF; /* Save bits 7:5 and bits 3:0 */
  944. temp |= (par->PanelDispCntlReg3 & ~0xEF);
  945. vga_wgfx(NULL, 0x30, temp);
  946. }
  947. vga_wgfx(NULL, 0x28, par->PanelVertCenterReg1);
  948. vga_wgfx(NULL, 0x29, par->PanelVertCenterReg2);
  949. vga_wgfx(NULL, 0x2a, par->PanelVertCenterReg3);
  950. if (info->fix.accel != FB_ACCEL_NEOMAGIC_NM2070) {
  951. vga_wgfx(NULL, 0x32, par->PanelVertCenterReg4);
  952. vga_wgfx(NULL, 0x33, par->PanelHorizCenterReg1);
  953. vga_wgfx(NULL, 0x34, par->PanelHorizCenterReg2);
  954. vga_wgfx(NULL, 0x35, par->PanelHorizCenterReg3);
  955. }
  956. if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2160)
  957. vga_wgfx(NULL, 0x36, par->PanelHorizCenterReg4);
  958. if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 ||
  959. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2230 ||
  960. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2360 ||
  961. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2380) {
  962. vga_wgfx(NULL, 0x36, par->PanelHorizCenterReg4);
  963. vga_wgfx(NULL, 0x37, par->PanelVertCenterReg5);
  964. vga_wgfx(NULL, 0x38, par->PanelHorizCenterReg5);
  965. clock_hi = 1;
  966. }
  967. /* Program VCLK3 if needed. */
  968. if (par->ProgramVCLK && ((vga_rgfx(NULL, 0x9B) != par->VCLK3NumeratorLow)
  969. || (vga_rgfx(NULL, 0x9F) != par->VCLK3Denominator)
  970. || (clock_hi && ((vga_rgfx(NULL, 0x8F) & ~0x0f)
  971. != (par->VCLK3NumeratorHigh &
  972. ~0x0F))))) {
  973. vga_wgfx(NULL, 0x9B, par->VCLK3NumeratorLow);
  974. if (clock_hi) {
  975. temp = vga_rgfx(NULL, 0x8F);
  976. temp &= 0x0F; /* Save bits 3:0 */
  977. temp |= (par->VCLK3NumeratorHigh & ~0x0F);
  978. vga_wgfx(NULL, 0x8F, temp);
  979. }
  980. vga_wgfx(NULL, 0x9F, par->VCLK3Denominator);
  981. }
  982. if (par->biosMode)
  983. vga_wcrt(NULL, 0x23, par->biosMode);
  984. vga_wgfx(NULL, 0x93, 0xc0); /* Gives 5x faster framebuffer writes !!! */
  985. /* Program vertical extension register */
  986. if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 ||
  987. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2230 ||
  988. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2360 ||
  989. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2380) {
  990. vga_wcrt(NULL, 0x70, par->VerticalExt);
  991. }
  992. vgaHWProtect(0); /* Turn on screen */
  993. /* Calling this also locks offset registers required in update_start */
  994. neoLock(&par->state);
  995. info->fix.line_length =
  996. info->var.xres_virtual * (info->var.bits_per_pixel >> 3);
  997. switch (info->fix.accel) {
  998. case FB_ACCEL_NEOMAGIC_NM2200:
  999. case FB_ACCEL_NEOMAGIC_NM2230:
  1000. case FB_ACCEL_NEOMAGIC_NM2360:
  1001. case FB_ACCEL_NEOMAGIC_NM2380:
  1002. neo2200_accel_init(info, &info->var);
  1003. break;
  1004. default:
  1005. break;
  1006. }
  1007. return 0;
  1008. }
  1009. /*
  1010. * Pan or Wrap the Display
  1011. */
  1012. static int neofb_pan_display(struct fb_var_screeninfo *var,
  1013. struct fb_info *info)
  1014. {
  1015. struct neofb_par *par = info->par;
  1016. struct vgastate *state = &par->state;
  1017. int oldExtCRTDispAddr;
  1018. int Base;
  1019. DBG("neofb_update_start");
  1020. Base = (var->yoffset * info->var.xres_virtual + var->xoffset) >> 2;
  1021. Base *= (info->var.bits_per_pixel + 7) / 8;
  1022. neoUnlock();
  1023. /*
  1024. * These are the generic starting address registers.
  1025. */
  1026. vga_wcrt(state->vgabase, 0x0C, (Base & 0x00FF00) >> 8);
  1027. vga_wcrt(state->vgabase, 0x0D, (Base & 0x00FF));
  1028. /*
  1029. * Make sure we don't clobber some other bits that might already
  1030. * have been set. NOTE: NM2200 has a writable bit 3, but it shouldn't
  1031. * be needed.
  1032. */
  1033. oldExtCRTDispAddr = vga_rgfx(NULL, 0x0E);
  1034. vga_wgfx(state->vgabase, 0x0E, (((Base >> 16) & 0x0f) | (oldExtCRTDispAddr & 0xf0)));
  1035. neoLock(state);
  1036. return 0;
  1037. }
  1038. static int neofb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  1039. u_int transp, struct fb_info *fb)
  1040. {
  1041. if (regno >= fb->cmap.len || regno > 255)
  1042. return -EINVAL;
  1043. if (fb->var.bits_per_pixel <= 8) {
  1044. outb(regno, 0x3c8);
  1045. outb(red >> 10, 0x3c9);
  1046. outb(green >> 10, 0x3c9);
  1047. outb(blue >> 10, 0x3c9);
  1048. } else if (regno < 16) {
  1049. switch (fb->var.bits_per_pixel) {
  1050. case 16:
  1051. ((u32 *) fb->pseudo_palette)[regno] =
  1052. ((red & 0xf800)) | ((green & 0xfc00) >> 5) |
  1053. ((blue & 0xf800) >> 11);
  1054. break;
  1055. case 24:
  1056. ((u32 *) fb->pseudo_palette)[regno] =
  1057. ((red & 0xff00) << 8) | ((green & 0xff00)) |
  1058. ((blue & 0xff00) >> 8);
  1059. break;
  1060. #ifdef NO_32BIT_SUPPORT_YET
  1061. case 32:
  1062. ((u32 *) fb->pseudo_palette)[regno] =
  1063. ((transp & 0xff00) << 16) | ((red & 0xff00) << 8) |
  1064. ((green & 0xff00)) | ((blue & 0xff00) >> 8);
  1065. break;
  1066. #endif
  1067. default:
  1068. return 1;
  1069. }
  1070. }
  1071. return 0;
  1072. }
  1073. /*
  1074. * (Un)Blank the display.
  1075. */
  1076. static int neofb_blank(int blank_mode, struct fb_info *info)
  1077. {
  1078. /*
  1079. * Blank the screen if blank_mode != 0, else unblank.
  1080. * Return 0 if blanking succeeded, != 0 if un-/blanking failed due to
  1081. * e.g. a video mode which doesn't support it. Implements VESA suspend
  1082. * and powerdown modes for monitors, and backlight control on LCDs.
  1083. * blank_mode == 0: unblanked (backlight on)
  1084. * blank_mode == 1: blank (backlight on)
  1085. * blank_mode == 2: suspend vsync (backlight off)
  1086. * blank_mode == 3: suspend hsync (backlight off)
  1087. * blank_mode == 4: powerdown (backlight off)
  1088. *
  1089. * wms...Enable VESA DPMS compatible powerdown mode
  1090. * run "setterm -powersave powerdown" to take advantage
  1091. */
  1092. struct neofb_par *par = info->par;
  1093. int seqflags, lcdflags, dpmsflags, reg, tmpdisp;
  1094. /*
  1095. * Read back the register bits related to display configuration. They might
  1096. * have been changed underneath the driver via Fn key stroke.
  1097. */
  1098. neoUnlock();
  1099. tmpdisp = vga_rgfx(NULL, 0x20) & 0x03;
  1100. neoLock(&par->state);
  1101. /* In case we blank the screen, we want to store the possibly new
  1102. * configuration in the driver. During un-blank, we re-apply this setting,
  1103. * since the LCD bit will be cleared in order to switch off the backlight.
  1104. */
  1105. if (par->PanelDispCntlRegRead) {
  1106. par->PanelDispCntlReg1 = tmpdisp;
  1107. }
  1108. par->PanelDispCntlRegRead = !blank_mode;
  1109. switch (blank_mode) {
  1110. case FB_BLANK_POWERDOWN: /* powerdown - both sync lines down */
  1111. seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
  1112. lcdflags = 0; /* LCD off */
  1113. dpmsflags = NEO_GR01_SUPPRESS_HSYNC |
  1114. NEO_GR01_SUPPRESS_VSYNC;
  1115. #ifdef CONFIG_TOSHIBA
  1116. /* Do we still need this ? */
  1117. /* attempt to turn off backlight on toshiba; also turns off external */
  1118. {
  1119. SMMRegisters regs;
  1120. regs.eax = 0xff00; /* HCI_SET */
  1121. regs.ebx = 0x0002; /* HCI_BACKLIGHT */
  1122. regs.ecx = 0x0000; /* HCI_DISABLE */
  1123. tosh_smm(&regs);
  1124. }
  1125. #endif
  1126. break;
  1127. case FB_BLANK_HSYNC_SUSPEND: /* hsync off */
  1128. seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
  1129. lcdflags = 0; /* LCD off */
  1130. dpmsflags = NEO_GR01_SUPPRESS_HSYNC;
  1131. break;
  1132. case FB_BLANK_VSYNC_SUSPEND: /* vsync off */
  1133. seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
  1134. lcdflags = 0; /* LCD off */
  1135. dpmsflags = NEO_GR01_SUPPRESS_VSYNC;
  1136. break;
  1137. case FB_BLANK_NORMAL: /* just blank screen (backlight stays on) */
  1138. seqflags = VGA_SR01_SCREEN_OFF; /* Disable sequencer */
  1139. /*
  1140. * During a blank operation with the LID shut, we might store "LCD off"
  1141. * by mistake. Due to timing issues, the BIOS may switch the lights
  1142. * back on, and we turn it back off once we "unblank".
  1143. *
  1144. * So here is an attempt to implement ">=" - if we are in the process
  1145. * of unblanking, and the LCD bit is unset in the driver but set in the
  1146. * register, we must keep it.
  1147. */
  1148. lcdflags = ((par->PanelDispCntlReg1 | tmpdisp) & 0x02); /* LCD normal */
  1149. dpmsflags = 0x00; /* no hsync/vsync suppression */
  1150. break;
  1151. case FB_BLANK_UNBLANK: /* unblank */
  1152. seqflags = 0; /* Enable sequencer */
  1153. lcdflags = ((par->PanelDispCntlReg1 | tmpdisp) & 0x02); /* LCD normal */
  1154. dpmsflags = 0x00; /* no hsync/vsync suppression */
  1155. #ifdef CONFIG_TOSHIBA
  1156. /* Do we still need this ? */
  1157. /* attempt to re-enable backlight/external on toshiba */
  1158. {
  1159. SMMRegisters regs;
  1160. regs.eax = 0xff00; /* HCI_SET */
  1161. regs.ebx = 0x0002; /* HCI_BACKLIGHT */
  1162. regs.ecx = 0x0001; /* HCI_ENABLE */
  1163. tosh_smm(&regs);
  1164. }
  1165. #endif
  1166. break;
  1167. default: /* Anything else we don't understand; return 1 to tell
  1168. * fb_blank we didn't aactually do anything */
  1169. return 1;
  1170. }
  1171. neoUnlock();
  1172. reg = (vga_rseq(NULL, 0x01) & ~0x20) | seqflags;
  1173. vga_wseq(NULL, 0x01, reg);
  1174. reg = (vga_rgfx(NULL, 0x20) & ~0x02) | lcdflags;
  1175. vga_wgfx(NULL, 0x20, reg);
  1176. reg = (vga_rgfx(NULL, 0x01) & ~0xF0) | 0x80 | dpmsflags;
  1177. vga_wgfx(NULL, 0x01, reg);
  1178. neoLock(&par->state);
  1179. return 0;
  1180. }
  1181. static void
  1182. neo2200_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  1183. {
  1184. struct neofb_par *par = info->par;
  1185. u_long dst, rop;
  1186. dst = rect->dx + rect->dy * info->var.xres_virtual;
  1187. rop = rect->rop ? 0x060000 : 0x0c0000;
  1188. neo2200_wait_fifo(info, 4);
  1189. /* set blt control */
  1190. writel(NEO_BC3_FIFO_EN |
  1191. NEO_BC0_SRC_IS_FG | NEO_BC3_SKIP_MAPPING |
  1192. // NEO_BC3_DST_XY_ADDR |
  1193. // NEO_BC3_SRC_XY_ADDR |
  1194. rop, &par->neo2200->bltCntl);
  1195. switch (info->var.bits_per_pixel) {
  1196. case 8:
  1197. writel(rect->color, &par->neo2200->fgColor);
  1198. break;
  1199. case 16:
  1200. case 24:
  1201. writel(((u32 *) (info->pseudo_palette))[rect->color],
  1202. &par->neo2200->fgColor);
  1203. break;
  1204. }
  1205. writel(dst * ((info->var.bits_per_pixel + 7) >> 3),
  1206. &par->neo2200->dstStart);
  1207. writel((rect->height << 16) | (rect->width & 0xffff),
  1208. &par->neo2200->xyExt);
  1209. }
  1210. static void
  1211. neo2200_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  1212. {
  1213. u32 sx = area->sx, sy = area->sy, dx = area->dx, dy = area->dy;
  1214. struct neofb_par *par = info->par;
  1215. u_long src, dst, bltCntl;
  1216. bltCntl = NEO_BC3_FIFO_EN | NEO_BC3_SKIP_MAPPING | 0x0C0000;
  1217. if ((dy > sy) || ((dy == sy) && (dx > sx))) {
  1218. /* Start with the lower right corner */
  1219. sy += (area->height - 1);
  1220. dy += (area->height - 1);
  1221. sx += (area->width - 1);
  1222. dx += (area->width - 1);
  1223. bltCntl |= NEO_BC0_X_DEC | NEO_BC0_DST_Y_DEC | NEO_BC0_SRC_Y_DEC;
  1224. }
  1225. src = sx * (info->var.bits_per_pixel >> 3) + sy*info->fix.line_length;
  1226. dst = dx * (info->var.bits_per_pixel >> 3) + dy*info->fix.line_length;
  1227. neo2200_wait_fifo(info, 4);
  1228. /* set blt control */
  1229. writel(bltCntl, &par->neo2200->bltCntl);
  1230. writel(src, &par->neo2200->srcStart);
  1231. writel(dst, &par->neo2200->dstStart);
  1232. writel((area->height << 16) | (area->width & 0xffff),
  1233. &par->neo2200->xyExt);
  1234. }
  1235. static void
  1236. neo2200_imageblit(struct fb_info *info, const struct fb_image *image)
  1237. {
  1238. struct neofb_par *par = info->par;
  1239. int s_pitch = (image->width * image->depth + 7) >> 3;
  1240. int scan_align = info->pixmap.scan_align - 1;
  1241. int buf_align = info->pixmap.buf_align - 1;
  1242. int bltCntl_flags, d_pitch, data_len;
  1243. // The data is padded for the hardware
  1244. d_pitch = (s_pitch + scan_align) & ~scan_align;
  1245. data_len = ((d_pitch * image->height) + buf_align) & ~buf_align;
  1246. neo2200_sync(info);
  1247. if (image->depth == 1) {
  1248. if (info->var.bits_per_pixel == 24 && image->width < 16) {
  1249. /* FIXME. There is a bug with accelerated color-expanded
  1250. * transfers in 24 bit mode if the image being transferred
  1251. * is less than 16 bits wide. This is due to insufficient
  1252. * padding when writing the image. We need to adjust
  1253. * struct fb_pixmap. Not yet done. */
  1254. cfb_imageblit(info, image);
  1255. return;
  1256. }
  1257. bltCntl_flags = NEO_BC0_SRC_MONO;
  1258. } else if (image->depth == info->var.bits_per_pixel) {
  1259. bltCntl_flags = 0;
  1260. } else {
  1261. /* We don't currently support hardware acceleration if image
  1262. * depth is different from display */
  1263. cfb_imageblit(info, image);
  1264. return;
  1265. }
  1266. switch (info->var.bits_per_pixel) {
  1267. case 8:
  1268. writel(image->fg_color, &par->neo2200->fgColor);
  1269. writel(image->bg_color, &par->neo2200->bgColor);
  1270. break;
  1271. case 16:
  1272. case 24:
  1273. writel(((u32 *) (info->pseudo_palette))[image->fg_color],
  1274. &par->neo2200->fgColor);
  1275. writel(((u32 *) (info->pseudo_palette))[image->bg_color],
  1276. &par->neo2200->bgColor);
  1277. break;
  1278. }
  1279. writel(NEO_BC0_SYS_TO_VID |
  1280. NEO_BC3_SKIP_MAPPING | bltCntl_flags |
  1281. // NEO_BC3_DST_XY_ADDR |
  1282. 0x0c0000, &par->neo2200->bltCntl);
  1283. writel(0, &par->neo2200->srcStart);
  1284. // par->neo2200->dstStart = (image->dy << 16) | (image->dx & 0xffff);
  1285. writel(((image->dx & 0xffff) * (info->var.bits_per_pixel >> 3) +
  1286. image->dy * info->fix.line_length), &par->neo2200->dstStart);
  1287. writel((image->height << 16) | (image->width & 0xffff),
  1288. &par->neo2200->xyExt);
  1289. memcpy_toio(par->mmio_vbase + 0x100000, image->data, data_len);
  1290. }
  1291. static void
  1292. neofb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  1293. {
  1294. switch (info->fix.accel) {
  1295. case FB_ACCEL_NEOMAGIC_NM2200:
  1296. case FB_ACCEL_NEOMAGIC_NM2230:
  1297. case FB_ACCEL_NEOMAGIC_NM2360:
  1298. case FB_ACCEL_NEOMAGIC_NM2380:
  1299. neo2200_fillrect(info, rect);
  1300. break;
  1301. default:
  1302. cfb_fillrect(info, rect);
  1303. break;
  1304. }
  1305. }
  1306. static void
  1307. neofb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  1308. {
  1309. switch (info->fix.accel) {
  1310. case FB_ACCEL_NEOMAGIC_NM2200:
  1311. case FB_ACCEL_NEOMAGIC_NM2230:
  1312. case FB_ACCEL_NEOMAGIC_NM2360:
  1313. case FB_ACCEL_NEOMAGIC_NM2380:
  1314. neo2200_copyarea(info, area);
  1315. break;
  1316. default:
  1317. cfb_copyarea(info, area);
  1318. break;
  1319. }
  1320. }
  1321. static void
  1322. neofb_imageblit(struct fb_info *info, const struct fb_image *image)
  1323. {
  1324. switch (info->fix.accel) {
  1325. case FB_ACCEL_NEOMAGIC_NM2200:
  1326. case FB_ACCEL_NEOMAGIC_NM2230:
  1327. case FB_ACCEL_NEOMAGIC_NM2360:
  1328. case FB_ACCEL_NEOMAGIC_NM2380:
  1329. neo2200_imageblit(info, image);
  1330. break;
  1331. default:
  1332. cfb_imageblit(info, image);
  1333. break;
  1334. }
  1335. }
  1336. static int
  1337. neofb_sync(struct fb_info *info)
  1338. {
  1339. switch (info->fix.accel) {
  1340. case FB_ACCEL_NEOMAGIC_NM2200:
  1341. case FB_ACCEL_NEOMAGIC_NM2230:
  1342. case FB_ACCEL_NEOMAGIC_NM2360:
  1343. case FB_ACCEL_NEOMAGIC_NM2380:
  1344. neo2200_sync(info);
  1345. break;
  1346. default:
  1347. break;
  1348. }
  1349. return 0;
  1350. }
  1351. /*
  1352. static void
  1353. neofb_draw_cursor(struct fb_info *info, u8 *dst, u8 *src, unsigned int width)
  1354. {
  1355. //memset_io(info->sprite.addr, 0xff, 1);
  1356. }
  1357. static int
  1358. neofb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  1359. {
  1360. struct neofb_par *par = (struct neofb_par *) info->par;
  1361. * Disable cursor *
  1362. write_le32(NEOREG_CURSCNTL, ~NEO_CURS_ENABLE, par);
  1363. if (cursor->set & FB_CUR_SETPOS) {
  1364. u32 x = cursor->image.dx;
  1365. u32 y = cursor->image.dy;
  1366. info->cursor.image.dx = x;
  1367. info->cursor.image.dy = y;
  1368. write_le32(NEOREG_CURSX, x, par);
  1369. write_le32(NEOREG_CURSY, y, par);
  1370. }
  1371. if (cursor->set & FB_CUR_SETSIZE) {
  1372. info->cursor.image.height = cursor->image.height;
  1373. info->cursor.image.width = cursor->image.width;
  1374. }
  1375. if (cursor->set & FB_CUR_SETHOT)
  1376. info->cursor.hot = cursor->hot;
  1377. if (cursor->set & FB_CUR_SETCMAP) {
  1378. if (cursor->image.depth == 1) {
  1379. u32 fg = cursor->image.fg_color;
  1380. u32 bg = cursor->image.bg_color;
  1381. info->cursor.image.fg_color = fg;
  1382. info->cursor.image.bg_color = bg;
  1383. fg = ((fg & 0xff0000) >> 16) | ((fg & 0xff) << 16) | (fg & 0xff00);
  1384. bg = ((bg & 0xff0000) >> 16) | ((bg & 0xff) << 16) | (bg & 0xff00);
  1385. write_le32(NEOREG_CURSFGCOLOR, fg, par);
  1386. write_le32(NEOREG_CURSBGCOLOR, bg, par);
  1387. }
  1388. }
  1389. if (cursor->set & FB_CUR_SETSHAPE)
  1390. fb_load_cursor_image(info);
  1391. if (info->cursor.enable)
  1392. write_le32(NEOREG_CURSCNTL, NEO_CURS_ENABLE, par);
  1393. return 0;
  1394. }
  1395. */
  1396. static struct fb_ops neofb_ops = {
  1397. .owner = THIS_MODULE,
  1398. .fb_open = neofb_open,
  1399. .fb_release = neofb_release,
  1400. .fb_check_var = neofb_check_var,
  1401. .fb_set_par = neofb_set_par,
  1402. .fb_setcolreg = neofb_setcolreg,
  1403. .fb_pan_display = neofb_pan_display,
  1404. .fb_blank = neofb_blank,
  1405. .fb_sync = neofb_sync,
  1406. .fb_fillrect = neofb_fillrect,
  1407. .fb_copyarea = neofb_copyarea,
  1408. .fb_imageblit = neofb_imageblit,
  1409. };
  1410. /* --------------------------------------------------------------------- */
  1411. static struct fb_videomode mode800x480 = {
  1412. .xres = 800,
  1413. .yres = 480,
  1414. .pixclock = 25000,
  1415. .left_margin = 88,
  1416. .right_margin = 40,
  1417. .upper_margin = 23,
  1418. .lower_margin = 1,
  1419. .hsync_len = 128,
  1420. .vsync_len = 4,
  1421. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  1422. .vmode = FB_VMODE_NONINTERLACED
  1423. };
  1424. static int neo_map_mmio(struct fb_info *info, struct pci_dev *dev)
  1425. {
  1426. struct neofb_par *par = info->par;
  1427. DBG("neo_map_mmio");
  1428. switch (info->fix.accel) {
  1429. case FB_ACCEL_NEOMAGIC_NM2070:
  1430. info->fix.mmio_start = pci_resource_start(dev, 0)+
  1431. 0x100000;
  1432. break;
  1433. case FB_ACCEL_NEOMAGIC_NM2090:
  1434. case FB_ACCEL_NEOMAGIC_NM2093:
  1435. info->fix.mmio_start = pci_resource_start(dev, 0)+
  1436. 0x200000;
  1437. break;
  1438. case FB_ACCEL_NEOMAGIC_NM2160:
  1439. case FB_ACCEL_NEOMAGIC_NM2097:
  1440. case FB_ACCEL_NEOMAGIC_NM2200:
  1441. case FB_ACCEL_NEOMAGIC_NM2230:
  1442. case FB_ACCEL_NEOMAGIC_NM2360:
  1443. case FB_ACCEL_NEOMAGIC_NM2380:
  1444. info->fix.mmio_start = pci_resource_start(dev, 1);
  1445. break;
  1446. default:
  1447. info->fix.mmio_start = pci_resource_start(dev, 0);
  1448. }
  1449. info->fix.mmio_len = MMIO_SIZE;
  1450. if (!request_mem_region
  1451. (info->fix.mmio_start, MMIO_SIZE, "memory mapped I/O")) {
  1452. printk("neofb: memory mapped IO in use\n");
  1453. return -EBUSY;
  1454. }
  1455. par->mmio_vbase = ioremap(info->fix.mmio_start, MMIO_SIZE);
  1456. if (!par->mmio_vbase) {
  1457. printk("neofb: unable to map memory mapped IO\n");
  1458. release_mem_region(info->fix.mmio_start,
  1459. info->fix.mmio_len);
  1460. return -ENOMEM;
  1461. } else
  1462. printk(KERN_INFO "neofb: mapped io at %p\n",
  1463. par->mmio_vbase);
  1464. return 0;
  1465. }
  1466. static void neo_unmap_mmio(struct fb_info *info)
  1467. {
  1468. struct neofb_par *par = info->par;
  1469. DBG("neo_unmap_mmio");
  1470. iounmap(par->mmio_vbase);
  1471. par->mmio_vbase = NULL;
  1472. release_mem_region(info->fix.mmio_start,
  1473. info->fix.mmio_len);
  1474. }
  1475. static int neo_map_video(struct fb_info *info, struct pci_dev *dev,
  1476. int video_len)
  1477. {
  1478. //unsigned long addr;
  1479. struct neofb_par *par = info->par;
  1480. DBG("neo_map_video");
  1481. info->fix.smem_start = pci_resource_start(dev, 0);
  1482. info->fix.smem_len = video_len;
  1483. if (!request_mem_region(info->fix.smem_start, info->fix.smem_len,
  1484. "frame buffer")) {
  1485. printk("neofb: frame buffer in use\n");
  1486. return -EBUSY;
  1487. }
  1488. info->screen_base =
  1489. ioremap_wc(info->fix.smem_start, info->fix.smem_len);
  1490. if (!info->screen_base) {
  1491. printk("neofb: unable to map screen memory\n");
  1492. release_mem_region(info->fix.smem_start,
  1493. info->fix.smem_len);
  1494. return -ENOMEM;
  1495. } else
  1496. printk(KERN_INFO "neofb: mapped framebuffer at %p\n",
  1497. info->screen_base);
  1498. par->wc_cookie = arch_phys_wc_add(info->fix.smem_start,
  1499. pci_resource_len(dev, 0));
  1500. /* Clear framebuffer, it's all white in memory after boot */
  1501. memset_io(info->screen_base, 0, info->fix.smem_len);
  1502. /* Allocate Cursor drawing pad.
  1503. info->fix.smem_len -= PAGE_SIZE;
  1504. addr = info->fix.smem_start + info->fix.smem_len;
  1505. write_le32(NEOREG_CURSMEMPOS, ((0x000f & (addr >> 10)) << 8) |
  1506. ((0x0ff0 & (addr >> 10)) >> 4), par);
  1507. addr = (unsigned long) info->screen_base + info->fix.smem_len;
  1508. info->sprite.addr = (u8 *) addr; */
  1509. return 0;
  1510. }
  1511. static void neo_unmap_video(struct fb_info *info)
  1512. {
  1513. struct neofb_par *par = info->par;
  1514. DBG("neo_unmap_video");
  1515. arch_phys_wc_del(par->wc_cookie);
  1516. iounmap(info->screen_base);
  1517. info->screen_base = NULL;
  1518. release_mem_region(info->fix.smem_start,
  1519. info->fix.smem_len);
  1520. }
  1521. static int neo_scan_monitor(struct fb_info *info)
  1522. {
  1523. struct neofb_par *par = info->par;
  1524. unsigned char type, display;
  1525. int w;
  1526. // Eventually we will have i2c support.
  1527. info->monspecs.modedb = kmalloc(sizeof(struct fb_videomode), GFP_KERNEL);
  1528. if (!info->monspecs.modedb)
  1529. return -ENOMEM;
  1530. info->monspecs.modedb_len = 1;
  1531. /* Determine the panel type */
  1532. vga_wgfx(NULL, 0x09, 0x26);
  1533. type = vga_rgfx(NULL, 0x21);
  1534. display = vga_rgfx(NULL, 0x20);
  1535. if (!par->internal_display && !par->external_display) {
  1536. par->internal_display = display & 2 || !(display & 3) ? 1 : 0;
  1537. par->external_display = display & 1;
  1538. printk (KERN_INFO "Autodetected %s display\n",
  1539. par->internal_display && par->external_display ? "simultaneous" :
  1540. par->internal_display ? "internal" : "external");
  1541. }
  1542. /* Determine panel width -- used in NeoValidMode. */
  1543. w = vga_rgfx(NULL, 0x20);
  1544. vga_wgfx(NULL, 0x09, 0x00);
  1545. switch ((w & 0x18) >> 3) {
  1546. case 0x00:
  1547. // 640x480@60
  1548. par->NeoPanelWidth = 640;
  1549. par->NeoPanelHeight = 480;
  1550. memcpy(info->monspecs.modedb, &vesa_modes[3], sizeof(struct fb_videomode));
  1551. break;
  1552. case 0x01:
  1553. par->NeoPanelWidth = 800;
  1554. if (par->libretto) {
  1555. par->NeoPanelHeight = 480;
  1556. memcpy(info->monspecs.modedb, &mode800x480, sizeof(struct fb_videomode));
  1557. } else {
  1558. // 800x600@60
  1559. par->NeoPanelHeight = 600;
  1560. memcpy(info->monspecs.modedb, &vesa_modes[8], sizeof(struct fb_videomode));
  1561. }
  1562. break;
  1563. case 0x02:
  1564. // 1024x768@60
  1565. par->NeoPanelWidth = 1024;
  1566. par->NeoPanelHeight = 768;
  1567. memcpy(info->monspecs.modedb, &vesa_modes[13], sizeof(struct fb_videomode));
  1568. break;
  1569. case 0x03:
  1570. /* 1280x1024@60 panel support needs to be added */
  1571. #ifdef NOT_DONE
  1572. par->NeoPanelWidth = 1280;
  1573. par->NeoPanelHeight = 1024;
  1574. memcpy(info->monspecs.modedb, &vesa_modes[20], sizeof(struct fb_videomode));
  1575. break;
  1576. #else
  1577. printk(KERN_ERR
  1578. "neofb: Only 640x480, 800x600/480 and 1024x768 panels are currently supported\n");
  1579. return -1;
  1580. #endif
  1581. default:
  1582. // 640x480@60
  1583. par->NeoPanelWidth = 640;
  1584. par->NeoPanelHeight = 480;
  1585. memcpy(info->monspecs.modedb, &vesa_modes[3], sizeof(struct fb_videomode));
  1586. break;
  1587. }
  1588. printk(KERN_INFO "Panel is a %dx%d %s %s display\n",
  1589. par->NeoPanelWidth,
  1590. par->NeoPanelHeight,
  1591. (type & 0x02) ? "color" : "monochrome",
  1592. (type & 0x10) ? "TFT" : "dual scan");
  1593. return 0;
  1594. }
  1595. static int neo_init_hw(struct fb_info *info)
  1596. {
  1597. struct neofb_par *par = info->par;
  1598. int videoRam = 896;
  1599. int maxClock = 65000;
  1600. int CursorMem = 1024;
  1601. int CursorOff = 0x100;
  1602. DBG("neo_init_hw");
  1603. neoUnlock();
  1604. #if 0
  1605. printk(KERN_DEBUG "--- Neo extended register dump ---\n");
  1606. for (int w = 0; w < 0x85; w++)
  1607. printk(KERN_DEBUG "CR %p: %p\n", (void *) w,
  1608. (void *) vga_rcrt(NULL, w));
  1609. for (int w = 0; w < 0xC7; w++)
  1610. printk(KERN_DEBUG "GR %p: %p\n", (void *) w,
  1611. (void *) vga_rgfx(NULL, w));
  1612. #endif
  1613. switch (info->fix.accel) {
  1614. case FB_ACCEL_NEOMAGIC_NM2070:
  1615. videoRam = 896;
  1616. maxClock = 65000;
  1617. break;
  1618. case FB_ACCEL_NEOMAGIC_NM2090:
  1619. case FB_ACCEL_NEOMAGIC_NM2093:
  1620. case FB_ACCEL_NEOMAGIC_NM2097:
  1621. videoRam = 1152;
  1622. maxClock = 80000;
  1623. break;
  1624. case FB_ACCEL_NEOMAGIC_NM2160:
  1625. videoRam = 2048;
  1626. maxClock = 90000;
  1627. break;
  1628. case FB_ACCEL_NEOMAGIC_NM2200:
  1629. videoRam = 2560;
  1630. maxClock = 110000;
  1631. break;
  1632. case FB_ACCEL_NEOMAGIC_NM2230:
  1633. videoRam = 3008;
  1634. maxClock = 110000;
  1635. break;
  1636. case FB_ACCEL_NEOMAGIC_NM2360:
  1637. videoRam = 4096;
  1638. maxClock = 110000;
  1639. break;
  1640. case FB_ACCEL_NEOMAGIC_NM2380:
  1641. videoRam = 6144;
  1642. maxClock = 110000;
  1643. break;
  1644. }
  1645. switch (info->fix.accel) {
  1646. case FB_ACCEL_NEOMAGIC_NM2070:
  1647. case FB_ACCEL_NEOMAGIC_NM2090:
  1648. case FB_ACCEL_NEOMAGIC_NM2093:
  1649. CursorMem = 2048;
  1650. CursorOff = 0x100;
  1651. break;
  1652. case FB_ACCEL_NEOMAGIC_NM2097:
  1653. case FB_ACCEL_NEOMAGIC_NM2160:
  1654. CursorMem = 1024;
  1655. CursorOff = 0x100;
  1656. break;
  1657. case FB_ACCEL_NEOMAGIC_NM2200:
  1658. case FB_ACCEL_NEOMAGIC_NM2230:
  1659. case FB_ACCEL_NEOMAGIC_NM2360:
  1660. case FB_ACCEL_NEOMAGIC_NM2380:
  1661. CursorMem = 1024;
  1662. CursorOff = 0x1000;
  1663. par->neo2200 = (Neo2200 __iomem *) par->mmio_vbase;
  1664. break;
  1665. }
  1666. /*
  1667. info->sprite.size = CursorMem;
  1668. info->sprite.scan_align = 1;
  1669. info->sprite.buf_align = 1;
  1670. info->sprite.flags = FB_PIXMAP_IO;
  1671. info->sprite.outbuf = neofb_draw_cursor;
  1672. */
  1673. par->maxClock = maxClock;
  1674. par->cursorOff = CursorOff;
  1675. return videoRam * 1024;
  1676. }
  1677. static struct fb_info *neo_alloc_fb_info(struct pci_dev *dev,
  1678. const struct pci_device_id *id)
  1679. {
  1680. struct fb_info *info;
  1681. struct neofb_par *par;
  1682. info = framebuffer_alloc(sizeof(struct neofb_par), &dev->dev);
  1683. if (!info)
  1684. return NULL;
  1685. par = info->par;
  1686. info->fix.accel = id->driver_data;
  1687. par->pci_burst = !nopciburst;
  1688. par->lcd_stretch = !nostretch;
  1689. par->libretto = libretto;
  1690. par->internal_display = internal;
  1691. par->external_display = external;
  1692. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  1693. switch (info->fix.accel) {
  1694. case FB_ACCEL_NEOMAGIC_NM2070:
  1695. snprintf(info->fix.id, sizeof(info->fix.id),
  1696. "MagicGraph 128");
  1697. break;
  1698. case FB_ACCEL_NEOMAGIC_NM2090:
  1699. snprintf(info->fix.id, sizeof(info->fix.id),
  1700. "MagicGraph 128V");
  1701. break;
  1702. case FB_ACCEL_NEOMAGIC_NM2093:
  1703. snprintf(info->fix.id, sizeof(info->fix.id),
  1704. "MagicGraph 128ZV");
  1705. break;
  1706. case FB_ACCEL_NEOMAGIC_NM2097:
  1707. snprintf(info->fix.id, sizeof(info->fix.id),
  1708. "MagicGraph 128ZV+");
  1709. break;
  1710. case FB_ACCEL_NEOMAGIC_NM2160:
  1711. snprintf(info->fix.id, sizeof(info->fix.id),
  1712. "MagicGraph 128XD");
  1713. break;
  1714. case FB_ACCEL_NEOMAGIC_NM2200:
  1715. snprintf(info->fix.id, sizeof(info->fix.id),
  1716. "MagicGraph 256AV");
  1717. info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
  1718. FBINFO_HWACCEL_COPYAREA |
  1719. FBINFO_HWACCEL_FILLRECT;
  1720. break;
  1721. case FB_ACCEL_NEOMAGIC_NM2230:
  1722. snprintf(info->fix.id, sizeof(info->fix.id),
  1723. "MagicGraph 256AV+");
  1724. info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
  1725. FBINFO_HWACCEL_COPYAREA |
  1726. FBINFO_HWACCEL_FILLRECT;
  1727. break;
  1728. case FB_ACCEL_NEOMAGIC_NM2360:
  1729. snprintf(info->fix.id, sizeof(info->fix.id),
  1730. "MagicGraph 256ZX");
  1731. info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
  1732. FBINFO_HWACCEL_COPYAREA |
  1733. FBINFO_HWACCEL_FILLRECT;
  1734. break;
  1735. case FB_ACCEL_NEOMAGIC_NM2380:
  1736. snprintf(info->fix.id, sizeof(info->fix.id),
  1737. "MagicGraph 256XL+");
  1738. info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
  1739. FBINFO_HWACCEL_COPYAREA |
  1740. FBINFO_HWACCEL_FILLRECT;
  1741. break;
  1742. }
  1743. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1744. info->fix.type_aux = 0;
  1745. info->fix.xpanstep = 0;
  1746. info->fix.ypanstep = 4;
  1747. info->fix.ywrapstep = 0;
  1748. info->fix.accel = id->driver_data;
  1749. info->fbops = &neofb_ops;
  1750. info->pseudo_palette = par->palette;
  1751. return info;
  1752. }
  1753. static void neo_free_fb_info(struct fb_info *info)
  1754. {
  1755. if (info) {
  1756. /*
  1757. * Free the colourmap
  1758. */
  1759. fb_dealloc_cmap(&info->cmap);
  1760. framebuffer_release(info);
  1761. }
  1762. }
  1763. /* --------------------------------------------------------------------- */
  1764. static int neofb_probe(struct pci_dev *dev, const struct pci_device_id *id)
  1765. {
  1766. struct fb_info *info;
  1767. u_int h_sync, v_sync;
  1768. int video_len, err;
  1769. DBG("neofb_probe");
  1770. err = pci_enable_device(dev);
  1771. if (err)
  1772. return err;
  1773. err = -ENOMEM;
  1774. info = neo_alloc_fb_info(dev, id);
  1775. if (!info)
  1776. return err;
  1777. err = neo_map_mmio(info, dev);
  1778. if (err)
  1779. goto err_map_mmio;
  1780. err = neo_scan_monitor(info);
  1781. if (err)
  1782. goto err_scan_monitor;
  1783. video_len = neo_init_hw(info);
  1784. if (video_len < 0) {
  1785. err = video_len;
  1786. goto err_init_hw;
  1787. }
  1788. err = neo_map_video(info, dev, video_len);
  1789. if (err)
  1790. goto err_init_hw;
  1791. if (!fb_find_mode(&info->var, info, mode_option, NULL, 0,
  1792. info->monspecs.modedb, 16)) {
  1793. printk(KERN_ERR "neofb: Unable to find usable video mode.\n");
  1794. err = -EINVAL;
  1795. goto err_map_video;
  1796. }
  1797. /*
  1798. * Calculate the hsync and vsync frequencies. Note that
  1799. * we split the 1e12 constant up so that we can preserve
  1800. * the precision and fit the results into 32-bit registers.
  1801. * (1953125000 * 512 = 1e12)
  1802. */
  1803. h_sync = 1953125000 / info->var.pixclock;
  1804. h_sync =
  1805. h_sync * 512 / (info->var.xres + info->var.left_margin +
  1806. info->var.right_margin + info->var.hsync_len);
  1807. v_sync =
  1808. h_sync / (info->var.yres + info->var.upper_margin +
  1809. info->var.lower_margin + info->var.vsync_len);
  1810. printk(KERN_INFO "neofb v" NEOFB_VERSION
  1811. ": %dkB VRAM, using %dx%d, %d.%03dkHz, %dHz\n",
  1812. info->fix.smem_len >> 10, info->var.xres,
  1813. info->var.yres, h_sync / 1000, h_sync % 1000, v_sync);
  1814. err = fb_alloc_cmap(&info->cmap, 256, 0);
  1815. if (err < 0)
  1816. goto err_map_video;
  1817. err = register_framebuffer(info);
  1818. if (err < 0)
  1819. goto err_reg_fb;
  1820. fb_info(info, "%s frame buffer device\n", info->fix.id);
  1821. /*
  1822. * Our driver data
  1823. */
  1824. pci_set_drvdata(dev, info);
  1825. return 0;
  1826. err_reg_fb:
  1827. fb_dealloc_cmap(&info->cmap);
  1828. err_map_video:
  1829. neo_unmap_video(info);
  1830. err_init_hw:
  1831. fb_destroy_modedb(info->monspecs.modedb);
  1832. err_scan_monitor:
  1833. neo_unmap_mmio(info);
  1834. err_map_mmio:
  1835. neo_free_fb_info(info);
  1836. return err;
  1837. }
  1838. static void neofb_remove(struct pci_dev *dev)
  1839. {
  1840. struct fb_info *info = pci_get_drvdata(dev);
  1841. DBG("neofb_remove");
  1842. if (info) {
  1843. /*
  1844. * If unregister_framebuffer fails, then
  1845. * we will be leaving hooks that could cause
  1846. * oopsen laying around.
  1847. */
  1848. if (unregister_framebuffer(info))
  1849. printk(KERN_WARNING
  1850. "neofb: danger danger! Oopsen imminent!\n");
  1851. neo_unmap_video(info);
  1852. fb_destroy_modedb(info->monspecs.modedb);
  1853. neo_unmap_mmio(info);
  1854. neo_free_fb_info(info);
  1855. }
  1856. }
  1857. static struct pci_device_id neofb_devices[] = {
  1858. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2070,
  1859. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2070},
  1860. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2090,
  1861. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2090},
  1862. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2093,
  1863. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2093},
  1864. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2097,
  1865. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2097},
  1866. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2160,
  1867. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2160},
  1868. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2200,
  1869. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2200},
  1870. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2230,
  1871. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2230},
  1872. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2360,
  1873. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2360},
  1874. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2380,
  1875. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2380},
  1876. {0, 0, 0, 0, 0, 0, 0}
  1877. };
  1878. MODULE_DEVICE_TABLE(pci, neofb_devices);
  1879. static struct pci_driver neofb_driver = {
  1880. .name = "neofb",
  1881. .id_table = neofb_devices,
  1882. .probe = neofb_probe,
  1883. .remove = neofb_remove,
  1884. };
  1885. /* ************************* init in-kernel code ************************** */
  1886. #ifndef MODULE
  1887. static int __init neofb_setup(char *options)
  1888. {
  1889. char *this_opt;
  1890. DBG("neofb_setup");
  1891. if (!options || !*options)
  1892. return 0;
  1893. while ((this_opt = strsep(&options, ",")) != NULL) {
  1894. if (!*this_opt)
  1895. continue;
  1896. if (!strncmp(this_opt, "internal", 8))
  1897. internal = 1;
  1898. else if (!strncmp(this_opt, "external", 8))
  1899. external = 1;
  1900. else if (!strncmp(this_opt, "nostretch", 9))
  1901. nostretch = 1;
  1902. else if (!strncmp(this_opt, "nopciburst", 10))
  1903. nopciburst = 1;
  1904. else if (!strncmp(this_opt, "libretto", 8))
  1905. libretto = 1;
  1906. else
  1907. mode_option = this_opt;
  1908. }
  1909. return 0;
  1910. }
  1911. #endif /* MODULE */
  1912. static int __init neofb_init(void)
  1913. {
  1914. #ifndef MODULE
  1915. char *option = NULL;
  1916. if (fb_get_options("neofb", &option))
  1917. return -ENODEV;
  1918. neofb_setup(option);
  1919. #endif
  1920. return pci_register_driver(&neofb_driver);
  1921. }
  1922. module_init(neofb_init);
  1923. #ifdef MODULE
  1924. static void __exit neofb_exit(void)
  1925. {
  1926. pci_unregister_driver(&neofb_driver);
  1927. }
  1928. module_exit(neofb_exit);
  1929. #endif /* MODULE */