neofb.c 55 KB

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