neofb.c 56 KB

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