neofb.c 58 KB

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