neofb.c 57 KB

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