neofb.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352
  1. /*
  2. * linux/drivers/video/neofb.c -- NeoMagic Framebuffer Driver
  3. *
  4. * Copyright (c) 2001-2002 Denis Oliver Kropp <dok@directfb.org>
  5. *
  6. *
  7. * Card specific code is based on XFree86's neomagic driver.
  8. * Framebuffer framework code is based on code of cyber2000fb.
  9. *
  10. * This file is subject to the terms and conditions of the GNU General
  11. * Public License. See the file COPYING in the main directory of this
  12. * archive for more details.
  13. *
  14. *
  15. * 0.4.1
  16. * - Cosmetic changes (dok)
  17. *
  18. * 0.4
  19. * - Toshiba Libretto support, allow modes larger than LCD size if
  20. * LCD is disabled, keep BIOS settings if internal/external display
  21. * haven't been enabled explicitly
  22. * (Thomas J. Moore <dark@mama.indstate.edu>)
  23. *
  24. * 0.3.3
  25. * - Porting over to new fbdev api. (jsimmons)
  26. *
  27. * 0.3.2
  28. * - got rid of all floating point (dok)
  29. *
  30. * 0.3.1
  31. * - added module license (dok)
  32. *
  33. * 0.3
  34. * - hardware accelerated clear and move for 2200 and above (dok)
  35. * - maximum allowed dotclock is handled now (dok)
  36. *
  37. * 0.2.1
  38. * - correct panning after X usage (dok)
  39. * - added module and kernel parameters (dok)
  40. * - no stretching if external display is enabled (dok)
  41. *
  42. * 0.2
  43. * - initial version (dok)
  44. *
  45. *
  46. * TODO
  47. * - ioctl for internal/external switching
  48. * - blanking
  49. * - 32bit depth support, maybe impossible
  50. * - disable pan-on-sync, need specs
  51. *
  52. * BUGS
  53. * - white margin on bootup like with tdfxfb (colormap problem?)
  54. *
  55. */
  56. #include <linux/module.h>
  57. #include <linux/kernel.h>
  58. #include <linux/errno.h>
  59. #include <linux/string.h>
  60. #include <linux/mm.h>
  61. #include <linux/slab.h>
  62. #include <linux/delay.h>
  63. #include <linux/fb.h>
  64. #include <linux/pci.h>
  65. #include <linux/init.h>
  66. #ifdef CONFIG_TOSHIBA
  67. #include <linux/toshiba.h>
  68. #endif
  69. #include <asm/io.h>
  70. #include <asm/irq.h>
  71. #include <asm/pgtable.h>
  72. #include <asm/system.h>
  73. #ifdef CONFIG_MTRR
  74. #include <asm/mtrr.h>
  75. #endif
  76. #include <video/vga.h>
  77. #include <video/neomagic.h>
  78. #define NEOFB_VERSION "0.4.2"
  79. /* --------------------------------------------------------------------- */
  80. static int internal;
  81. static int external;
  82. static int libretto;
  83. static int nostretch;
  84. static int nopciburst;
  85. static char *mode_option __devinitdata = NULL;
  86. #ifdef MODULE
  87. MODULE_AUTHOR("(c) 2001-2002 Denis Oliver Kropp <dok@convergence.de>");
  88. MODULE_LICENSE("GPL");
  89. MODULE_DESCRIPTION("FBDev driver for NeoMagic PCI Chips");
  90. module_param(internal, bool, 0);
  91. MODULE_PARM_DESC(internal, "Enable output on internal LCD Display.");
  92. module_param(external, bool, 0);
  93. MODULE_PARM_DESC(external, "Enable output on external CRT.");
  94. module_param(libretto, bool, 0);
  95. MODULE_PARM_DESC(libretto, "Force Libretto 100/110 800x480 LCD.");
  96. module_param(nostretch, bool, 0);
  97. MODULE_PARM_DESC(nostretch,
  98. "Disable stretching of modes smaller than LCD.");
  99. module_param(nopciburst, bool, 0);
  100. MODULE_PARM_DESC(nopciburst, "Disable PCI burst mode.");
  101. module_param(mode_option, charp, 0);
  102. MODULE_PARM_DESC(mode_option, "Preferred video mode ('640x480-8@60', etc)");
  103. #endif
  104. /* --------------------------------------------------------------------- */
  105. static biosMode bios8[] = {
  106. {320, 240, 0x40},
  107. {300, 400, 0x42},
  108. {640, 400, 0x20},
  109. {640, 480, 0x21},
  110. {800, 600, 0x23},
  111. {1024, 768, 0x25},
  112. };
  113. static biosMode bios16[] = {
  114. {320, 200, 0x2e},
  115. {320, 240, 0x41},
  116. {300, 400, 0x43},
  117. {640, 480, 0x31},
  118. {800, 600, 0x34},
  119. {1024, 768, 0x37},
  120. };
  121. static biosMode bios24[] = {
  122. {640, 480, 0x32},
  123. {800, 600, 0x35},
  124. {1024, 768, 0x38}
  125. };
  126. #ifdef NO_32BIT_SUPPORT_YET
  127. /* FIXME: guessed values, wrong */
  128. static biosMode bios32[] = {
  129. {640, 480, 0x33},
  130. {800, 600, 0x36},
  131. {1024, 768, 0x39}
  132. };
  133. #endif
  134. static inline void write_le32(int regindex, u32 val, const struct neofb_par *par)
  135. {
  136. writel(val, par->neo2200 + par->cursorOff + regindex);
  137. }
  138. static int neoFindMode(int xres, int yres, int depth)
  139. {
  140. int xres_s;
  141. int i, size;
  142. biosMode *mode;
  143. switch (depth) {
  144. case 8:
  145. size = ARRAY_SIZE(bios8);
  146. mode = bios8;
  147. break;
  148. case 16:
  149. size = ARRAY_SIZE(bios16);
  150. mode = bios16;
  151. break;
  152. case 24:
  153. size = ARRAY_SIZE(bios24);
  154. mode = bios24;
  155. break;
  156. #ifdef NO_32BIT_SUPPORT_YET
  157. case 32:
  158. size = ARRAY_SIZE(bios32);
  159. mode = bios32;
  160. break;
  161. #endif
  162. default:
  163. return 0;
  164. }
  165. for (i = 0; i < size; i++) {
  166. if (xres <= mode[i].x_res) {
  167. xres_s = mode[i].x_res;
  168. for (; i < size; i++) {
  169. if (mode[i].x_res != xres_s)
  170. return mode[i - 1].mode;
  171. if (yres <= mode[i].y_res)
  172. return mode[i].mode;
  173. }
  174. }
  175. }
  176. return mode[size - 1].mode;
  177. }
  178. /*
  179. * neoCalcVCLK --
  180. *
  181. * Determine the closest clock frequency to the one requested.
  182. */
  183. #define MAX_N 127
  184. #define MAX_D 31
  185. #define MAX_F 1
  186. static void neoCalcVCLK(const struct fb_info *info,
  187. struct neofb_par *par, long freq)
  188. {
  189. int n, d, f;
  190. int n_best = 0, d_best = 0, f_best = 0;
  191. long f_best_diff = 0x7ffff;
  192. for (f = 0; f <= MAX_F; f++)
  193. for (d = 0; d <= MAX_D; d++)
  194. for (n = 0; n <= MAX_N; n++) {
  195. long f_out;
  196. long f_diff;
  197. f_out = ((14318 * (n + 1)) / (d + 1)) >> f;
  198. f_diff = abs(f_out - freq);
  199. if (f_diff <= f_best_diff) {
  200. f_best_diff = f_diff;
  201. n_best = n;
  202. d_best = d;
  203. f_best = f;
  204. }
  205. if (f_out > freq)
  206. break;
  207. }
  208. if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 ||
  209. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2230 ||
  210. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2360 ||
  211. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2380) {
  212. /* NOT_DONE: We are trying the full range of the 2200 clock.
  213. We should be able to try n up to 2047 */
  214. par->VCLK3NumeratorLow = n_best;
  215. par->VCLK3NumeratorHigh = (f_best << 7);
  216. } else
  217. par->VCLK3NumeratorLow = n_best | (f_best << 7);
  218. par->VCLK3Denominator = d_best;
  219. #ifdef NEOFB_DEBUG
  220. printk(KERN_DEBUG "neoVCLK: f:%ld NumLow=%d NumHi=%d Den=%d Df=%ld\n",
  221. freq,
  222. par->VCLK3NumeratorLow,
  223. par->VCLK3NumeratorHigh,
  224. par->VCLK3Denominator, f_best_diff);
  225. #endif
  226. }
  227. /*
  228. * vgaHWInit --
  229. * Handle the initialization, etc. of a screen.
  230. * Return FALSE on failure.
  231. */
  232. static int vgaHWInit(const struct fb_var_screeninfo *var,
  233. const struct fb_info *info,
  234. struct neofb_par *par, struct xtimings *timings)
  235. {
  236. par->MiscOutReg = 0x23;
  237. if (!(timings->sync & FB_SYNC_HOR_HIGH_ACT))
  238. par->MiscOutReg |= 0x40;
  239. if (!(timings->sync & FB_SYNC_VERT_HIGH_ACT))
  240. par->MiscOutReg |= 0x80;
  241. /*
  242. * Time Sequencer
  243. */
  244. par->Sequencer[0] = 0x00;
  245. par->Sequencer[1] = 0x01;
  246. par->Sequencer[2] = 0x0F;
  247. par->Sequencer[3] = 0x00; /* Font select */
  248. par->Sequencer[4] = 0x0E; /* Misc */
  249. /*
  250. * CRTC Controller
  251. */
  252. par->CRTC[0] = (timings->HTotal >> 3) - 5;
  253. par->CRTC[1] = (timings->HDisplay >> 3) - 1;
  254. par->CRTC[2] = (timings->HDisplay >> 3) - 1;
  255. par->CRTC[3] = (((timings->HTotal >> 3) - 1) & 0x1F) | 0x80;
  256. par->CRTC[4] = (timings->HSyncStart >> 3);
  257. par->CRTC[5] = ((((timings->HTotal >> 3) - 1) & 0x20) << 2)
  258. | (((timings->HSyncEnd >> 3)) & 0x1F);
  259. par->CRTC[6] = (timings->VTotal - 2) & 0xFF;
  260. par->CRTC[7] = (((timings->VTotal - 2) & 0x100) >> 8)
  261. | (((timings->VDisplay - 1) & 0x100) >> 7)
  262. | ((timings->VSyncStart & 0x100) >> 6)
  263. | (((timings->VDisplay - 1) & 0x100) >> 5)
  264. | 0x10 | (((timings->VTotal - 2) & 0x200) >> 4)
  265. | (((timings->VDisplay - 1) & 0x200) >> 3)
  266. | ((timings->VSyncStart & 0x200) >> 2);
  267. par->CRTC[8] = 0x00;
  268. par->CRTC[9] = (((timings->VDisplay - 1) & 0x200) >> 4) | 0x40;
  269. if (timings->dblscan)
  270. par->CRTC[9] |= 0x80;
  271. par->CRTC[10] = 0x00;
  272. par->CRTC[11] = 0x00;
  273. par->CRTC[12] = 0x00;
  274. par->CRTC[13] = 0x00;
  275. par->CRTC[14] = 0x00;
  276. par->CRTC[15] = 0x00;
  277. par->CRTC[16] = timings->VSyncStart & 0xFF;
  278. par->CRTC[17] = (timings->VSyncEnd & 0x0F) | 0x20;
  279. par->CRTC[18] = (timings->VDisplay - 1) & 0xFF;
  280. par->CRTC[19] = var->xres_virtual >> 4;
  281. par->CRTC[20] = 0x00;
  282. par->CRTC[21] = (timings->VDisplay - 1) & 0xFF;
  283. par->CRTC[22] = (timings->VTotal - 1) & 0xFF;
  284. par->CRTC[23] = 0xC3;
  285. par->CRTC[24] = 0xFF;
  286. /*
  287. * are these unnecessary?
  288. * vgaHWHBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN | KGA_ENABLE_ON_ZERO);
  289. * vgaHWVBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN | KGA_ENABLE_ON_ZERO);
  290. */
  291. /*
  292. * Graphics Display Controller
  293. */
  294. par->Graphics[0] = 0x00;
  295. par->Graphics[1] = 0x00;
  296. par->Graphics[2] = 0x00;
  297. par->Graphics[3] = 0x00;
  298. par->Graphics[4] = 0x00;
  299. par->Graphics[5] = 0x40;
  300. par->Graphics[6] = 0x05; /* only map 64k VGA memory !!!! */
  301. par->Graphics[7] = 0x0F;
  302. par->Graphics[8] = 0xFF;
  303. par->Attribute[0] = 0x00; /* standard colormap translation */
  304. par->Attribute[1] = 0x01;
  305. par->Attribute[2] = 0x02;
  306. par->Attribute[3] = 0x03;
  307. par->Attribute[4] = 0x04;
  308. par->Attribute[5] = 0x05;
  309. par->Attribute[6] = 0x06;
  310. par->Attribute[7] = 0x07;
  311. par->Attribute[8] = 0x08;
  312. par->Attribute[9] = 0x09;
  313. par->Attribute[10] = 0x0A;
  314. par->Attribute[11] = 0x0B;
  315. par->Attribute[12] = 0x0C;
  316. par->Attribute[13] = 0x0D;
  317. par->Attribute[14] = 0x0E;
  318. par->Attribute[15] = 0x0F;
  319. par->Attribute[16] = 0x41;
  320. par->Attribute[17] = 0xFF;
  321. par->Attribute[18] = 0x0F;
  322. par->Attribute[19] = 0x00;
  323. par->Attribute[20] = 0x00;
  324. return 0;
  325. }
  326. static void vgaHWLock(struct vgastate *state)
  327. {
  328. /* Protect CRTC[0-7] */
  329. vga_wcrt(state->vgabase, 0x11, vga_rcrt(state->vgabase, 0x11) | 0x80);
  330. }
  331. static void vgaHWUnlock(void)
  332. {
  333. /* Unprotect CRTC[0-7] */
  334. vga_wcrt(NULL, 0x11, vga_rcrt(NULL, 0x11) & ~0x80);
  335. }
  336. static void neoLock(struct vgastate *state)
  337. {
  338. vga_wgfx(state->vgabase, 0x09, 0x00);
  339. vgaHWLock(state);
  340. }
  341. static void neoUnlock(void)
  342. {
  343. vgaHWUnlock();
  344. vga_wgfx(NULL, 0x09, 0x26);
  345. }
  346. /*
  347. * VGA Palette management
  348. */
  349. static int paletteEnabled = 0;
  350. static inline void VGAenablePalette(void)
  351. {
  352. vga_r(NULL, VGA_IS1_RC);
  353. vga_w(NULL, VGA_ATT_W, 0x00);
  354. paletteEnabled = 1;
  355. }
  356. static inline void VGAdisablePalette(void)
  357. {
  358. vga_r(NULL, VGA_IS1_RC);
  359. vga_w(NULL, VGA_ATT_W, 0x20);
  360. paletteEnabled = 0;
  361. }
  362. static inline void VGAwATTR(u8 index, u8 value)
  363. {
  364. if (paletteEnabled)
  365. index &= ~0x20;
  366. else
  367. index |= 0x20;
  368. vga_r(NULL, VGA_IS1_RC);
  369. vga_wattr(NULL, index, value);
  370. }
  371. static void vgaHWProtect(int on)
  372. {
  373. unsigned char tmp;
  374. if (on) {
  375. /*
  376. * Turn off screen and disable sequencer.
  377. */
  378. tmp = vga_rseq(NULL, 0x01);
  379. vga_wseq(NULL, 0x00, 0x01); /* Synchronous Reset */
  380. vga_wseq(NULL, 0x01, tmp | 0x20); /* disable the display */
  381. VGAenablePalette();
  382. } else {
  383. /*
  384. * Reenable sequencer, then turn on screen.
  385. */
  386. tmp = vga_rseq(NULL, 0x01);
  387. vga_wseq(NULL, 0x01, tmp & ~0x20); /* reenable display */
  388. vga_wseq(NULL, 0x00, 0x03); /* clear synchronousreset */
  389. VGAdisablePalette();
  390. }
  391. }
  392. static void vgaHWRestore(const struct fb_info *info,
  393. const struct neofb_par *par)
  394. {
  395. int i;
  396. vga_w(NULL, VGA_MIS_W, par->MiscOutReg);
  397. for (i = 1; i < 5; i++)
  398. vga_wseq(NULL, i, par->Sequencer[i]);
  399. /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 or CRTC[17] */
  400. vga_wcrt(NULL, 17, par->CRTC[17] & ~0x80);
  401. for (i = 0; i < 25; i++)
  402. vga_wcrt(NULL, i, par->CRTC[i]);
  403. for (i = 0; i < 9; i++)
  404. vga_wgfx(NULL, i, par->Graphics[i]);
  405. VGAenablePalette();
  406. for (i = 0; i < 21; i++)
  407. VGAwATTR(i, par->Attribute[i]);
  408. VGAdisablePalette();
  409. }
  410. /* -------------------- Hardware specific routines ------------------------- */
  411. /*
  412. * Hardware Acceleration for Neo2200+
  413. */
  414. static inline int neo2200_sync(struct fb_info *info)
  415. {
  416. struct neofb_par *par = info->par;
  417. while (readl(&par->neo2200->bltStat) & 1);
  418. return 0;
  419. }
  420. static inline void neo2200_wait_fifo(struct fb_info *info,
  421. int requested_fifo_space)
  422. {
  423. // ndev->neo.waitfifo_calls++;
  424. // ndev->neo.waitfifo_sum += requested_fifo_space;
  425. /* FIXME: does not work
  426. if (neo_fifo_space < requested_fifo_space)
  427. {
  428. neo_fifo_waitcycles++;
  429. while (1)
  430. {
  431. neo_fifo_space = (neo2200->bltStat >> 8);
  432. if (neo_fifo_space >= requested_fifo_space)
  433. break;
  434. }
  435. }
  436. else
  437. {
  438. neo_fifo_cache_hits++;
  439. }
  440. neo_fifo_space -= requested_fifo_space;
  441. */
  442. neo2200_sync(info);
  443. }
  444. static inline void neo2200_accel_init(struct fb_info *info,
  445. struct fb_var_screeninfo *var)
  446. {
  447. struct neofb_par *par = info->par;
  448. Neo2200 __iomem *neo2200 = par->neo2200;
  449. u32 bltMod, pitch;
  450. neo2200_sync(info);
  451. switch (var->bits_per_pixel) {
  452. case 8:
  453. bltMod = NEO_MODE1_DEPTH8;
  454. pitch = var->xres_virtual;
  455. break;
  456. case 15:
  457. case 16:
  458. bltMod = NEO_MODE1_DEPTH16;
  459. pitch = var->xres_virtual * 2;
  460. break;
  461. case 24:
  462. bltMod = NEO_MODE1_DEPTH24;
  463. pitch = var->xres_virtual * 3;
  464. break;
  465. default:
  466. printk(KERN_ERR
  467. "neofb: neo2200_accel_init: unexpected bits per pixel!\n");
  468. return;
  469. }
  470. writel(bltMod << 16, &neo2200->bltStat);
  471. writel((pitch << 16) | pitch, &neo2200->pitch);
  472. }
  473. /* --------------------------------------------------------------------- */
  474. static int
  475. neofb_open(struct fb_info *info, int user)
  476. {
  477. struct neofb_par *par = info->par;
  478. mutex_lock(&par->open_lock);
  479. if (!par->ref_count) {
  480. memset(&par->state, 0, sizeof(struct vgastate));
  481. par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS;
  482. save_vga(&par->state);
  483. }
  484. par->ref_count++;
  485. mutex_unlock(&par->open_lock);
  486. return 0;
  487. }
  488. static int
  489. neofb_release(struct fb_info *info, int user)
  490. {
  491. struct neofb_par *par = info->par;
  492. mutex_lock(&par->open_lock);
  493. if (!par->ref_count) {
  494. mutex_unlock(&par->open_lock);
  495. return -EINVAL;
  496. }
  497. if (par->ref_count == 1) {
  498. restore_vga(&par->state);
  499. }
  500. par->ref_count--;
  501. mutex_unlock(&par->open_lock);
  502. return 0;
  503. }
  504. static int
  505. neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  506. {
  507. struct neofb_par *par = info->par;
  508. unsigned int pixclock = var->pixclock;
  509. struct xtimings timings;
  510. int memlen, vramlen;
  511. int mode_ok = 0;
  512. DBG("neofb_check_var");
  513. if (!pixclock)
  514. pixclock = 10000; /* 10ns = 100MHz */
  515. timings.pixclock = 1000000000 / pixclock;
  516. if (timings.pixclock < 1)
  517. timings.pixclock = 1;
  518. if (timings.pixclock > par->maxClock)
  519. return -EINVAL;
  520. timings.dblscan = var->vmode & FB_VMODE_DOUBLE;
  521. timings.interlaced = var->vmode & FB_VMODE_INTERLACED;
  522. timings.HDisplay = var->xres;
  523. timings.HSyncStart = timings.HDisplay + var->right_margin;
  524. timings.HSyncEnd = timings.HSyncStart + var->hsync_len;
  525. timings.HTotal = timings.HSyncEnd + var->left_margin;
  526. timings.VDisplay = var->yres;
  527. timings.VSyncStart = timings.VDisplay + var->lower_margin;
  528. timings.VSyncEnd = timings.VSyncStart + var->vsync_len;
  529. timings.VTotal = timings.VSyncEnd + var->upper_margin;
  530. timings.sync = var->sync;
  531. /* Is the mode larger than the LCD panel? */
  532. if (par->internal_display &&
  533. ((var->xres > par->NeoPanelWidth) ||
  534. (var->yres > par->NeoPanelHeight))) {
  535. printk(KERN_INFO
  536. "Mode (%dx%d) larger than the LCD panel (%dx%d)\n",
  537. var->xres, var->yres, par->NeoPanelWidth,
  538. par->NeoPanelHeight);
  539. return -EINVAL;
  540. }
  541. /* Is the mode one of the acceptable sizes? */
  542. if (!par->internal_display)
  543. mode_ok = 1;
  544. else {
  545. switch (var->xres) {
  546. case 1280:
  547. if (var->yres == 1024)
  548. mode_ok = 1;
  549. break;
  550. case 1024:
  551. if (var->yres == 768)
  552. mode_ok = 1;
  553. break;
  554. case 800:
  555. if (var->yres == (par->libretto ? 480 : 600))
  556. mode_ok = 1;
  557. break;
  558. case 640:
  559. if (var->yres == 480)
  560. mode_ok = 1;
  561. break;
  562. }
  563. }
  564. if (!mode_ok) {
  565. printk(KERN_INFO
  566. "Mode (%dx%d) won't display properly on LCD\n",
  567. var->xres, var->yres);
  568. return -EINVAL;
  569. }
  570. var->red.msb_right = 0;
  571. var->green.msb_right = 0;
  572. var->blue.msb_right = 0;
  573. var->transp.msb_right = 0;
  574. switch (var->bits_per_pixel) {
  575. case 8: /* PSEUDOCOLOUR, 256 */
  576. var->transp.offset = 0;
  577. var->transp.length = 0;
  578. var->red.offset = 0;
  579. var->red.length = 8;
  580. var->green.offset = 0;
  581. var->green.length = 8;
  582. var->blue.offset = 0;
  583. var->blue.length = 8;
  584. break;
  585. case 16: /* DIRECTCOLOUR, 64k */
  586. var->transp.offset = 0;
  587. var->transp.length = 0;
  588. var->red.offset = 11;
  589. var->red.length = 5;
  590. var->green.offset = 5;
  591. var->green.length = 6;
  592. var->blue.offset = 0;
  593. var->blue.length = 5;
  594. break;
  595. case 24: /* TRUECOLOUR, 16m */
  596. var->transp.offset = 0;
  597. var->transp.length = 0;
  598. var->red.offset = 16;
  599. var->red.length = 8;
  600. var->green.offset = 8;
  601. var->green.length = 8;
  602. var->blue.offset = 0;
  603. var->blue.length = 8;
  604. break;
  605. #ifdef NO_32BIT_SUPPORT_YET
  606. case 32: /* TRUECOLOUR, 16m */
  607. var->transp.offset = 24;
  608. var->transp.length = 8;
  609. var->red.offset = 16;
  610. var->red.length = 8;
  611. var->green.offset = 8;
  612. var->green.length = 8;
  613. var->blue.offset = 0;
  614. var->blue.length = 8;
  615. break;
  616. #endif
  617. default:
  618. printk(KERN_WARNING "neofb: no support for %dbpp\n",
  619. var->bits_per_pixel);
  620. return -EINVAL;
  621. }
  622. vramlen = info->fix.smem_len;
  623. if (vramlen > 4 * 1024 * 1024)
  624. vramlen = 4 * 1024 * 1024;
  625. if (var->yres_virtual < var->yres)
  626. var->yres_virtual = var->yres;
  627. if (var->xres_virtual < var->xres)
  628. var->xres_virtual = var->xres;
  629. memlen = var->xres_virtual * var->bits_per_pixel * var->yres_virtual >> 3;
  630. if (memlen > vramlen) {
  631. var->yres_virtual = vramlen * 8 / (var->xres_virtual *
  632. var->bits_per_pixel);
  633. memlen = var->xres_virtual * var->bits_per_pixel *
  634. var->yres_virtual / 8;
  635. }
  636. /* we must round yres/xres down, we already rounded y/xres_virtual up
  637. if it was possible. We should return -EINVAL, but I disagree */
  638. if (var->yres_virtual < var->yres)
  639. var->yres = var->yres_virtual;
  640. if (var->xres_virtual < var->xres)
  641. var->xres = var->xres_virtual;
  642. if (var->xoffset + var->xres > var->xres_virtual)
  643. var->xoffset = var->xres_virtual - var->xres;
  644. if (var->yoffset + var->yres > var->yres_virtual)
  645. var->yoffset = var->yres_virtual - var->yres;
  646. var->nonstd = 0;
  647. var->height = -1;
  648. var->width = -1;
  649. if (var->bits_per_pixel >= 24 || !par->neo2200)
  650. var->accel_flags &= ~FB_ACCELF_TEXT;
  651. return 0;
  652. }
  653. static int neofb_set_par(struct fb_info *info)
  654. {
  655. struct neofb_par *par = info->par;
  656. struct xtimings timings;
  657. unsigned char temp;
  658. int i, clock_hi = 0;
  659. int lcd_stretch;
  660. int hoffset, voffset;
  661. DBG("neofb_set_par");
  662. neoUnlock();
  663. vgaHWProtect(1); /* Blank the screen */
  664. timings.dblscan = info->var.vmode & FB_VMODE_DOUBLE;
  665. timings.interlaced = info->var.vmode & FB_VMODE_INTERLACED;
  666. timings.HDisplay = info->var.xres;
  667. timings.HSyncStart = timings.HDisplay + info->var.right_margin;
  668. timings.HSyncEnd = timings.HSyncStart + info->var.hsync_len;
  669. timings.HTotal = timings.HSyncEnd + info->var.left_margin;
  670. timings.VDisplay = info->var.yres;
  671. timings.VSyncStart = timings.VDisplay + info->var.lower_margin;
  672. timings.VSyncEnd = timings.VSyncStart + info->var.vsync_len;
  673. timings.VTotal = timings.VSyncEnd + info->var.upper_margin;
  674. timings.sync = info->var.sync;
  675. timings.pixclock = PICOS2KHZ(info->var.pixclock);
  676. if (timings.pixclock < 1)
  677. timings.pixclock = 1;
  678. /*
  679. * This will allocate the datastructure and initialize all of the
  680. * generic VGA registers.
  681. */
  682. if (vgaHWInit(&info->var, info, par, &timings))
  683. return -EINVAL;
  684. /*
  685. * The default value assigned by vgaHW.c is 0x41, but this does
  686. * not work for NeoMagic.
  687. */
  688. par->Attribute[16] = 0x01;
  689. switch (info->var.bits_per_pixel) {
  690. case 8:
  691. par->CRTC[0x13] = info->var.xres_virtual >> 3;
  692. par->ExtCRTOffset = info->var.xres_virtual >> 11;
  693. par->ExtColorModeSelect = 0x11;
  694. break;
  695. case 16:
  696. par->CRTC[0x13] = info->var.xres_virtual >> 2;
  697. par->ExtCRTOffset = info->var.xres_virtual >> 10;
  698. par->ExtColorModeSelect = 0x13;
  699. break;
  700. case 24:
  701. par->CRTC[0x13] = (info->var.xres_virtual * 3) >> 3;
  702. par->ExtCRTOffset = (info->var.xres_virtual * 3) >> 11;
  703. par->ExtColorModeSelect = 0x14;
  704. break;
  705. #ifdef NO_32BIT_SUPPORT_YET
  706. case 32: /* FIXME: guessed values */
  707. par->CRTC[0x13] = info->var.xres_virtual >> 1;
  708. par->ExtCRTOffset = info->var.xres_virtual >> 9;
  709. par->ExtColorModeSelect = 0x15;
  710. break;
  711. #endif
  712. default:
  713. break;
  714. }
  715. par->ExtCRTDispAddr = 0x10;
  716. /* Vertical Extension */
  717. par->VerticalExt = (((timings.VTotal - 2) & 0x400) >> 10)
  718. | (((timings.VDisplay - 1) & 0x400) >> 9)
  719. | (((timings.VSyncStart) & 0x400) >> 8)
  720. | (((timings.VSyncStart) & 0x400) >> 7);
  721. /* Fast write bursts on unless disabled. */
  722. if (par->pci_burst)
  723. par->SysIfaceCntl1 = 0x30;
  724. else
  725. par->SysIfaceCntl1 = 0x00;
  726. par->SysIfaceCntl2 = 0xc0; /* VESA Bios sets this to 0x80! */
  727. /* Initialize: by default, we want display config register to be read */
  728. par->PanelDispCntlRegRead = 1;
  729. /* Enable any user specified display devices. */
  730. par->PanelDispCntlReg1 = 0x00;
  731. if (par->internal_display)
  732. par->PanelDispCntlReg1 |= 0x02;
  733. if (par->external_display)
  734. par->PanelDispCntlReg1 |= 0x01;
  735. /* If the user did not specify any display devices, then... */
  736. if (par->PanelDispCntlReg1 == 0x00) {
  737. /* Default to internal (i.e., LCD) only. */
  738. par->PanelDispCntlReg1 = vga_rgfx(NULL, 0x20) & 0x03;
  739. }
  740. /* If we are using a fixed mode, then tell the chip we are. */
  741. switch (info->var.xres) {
  742. case 1280:
  743. par->PanelDispCntlReg1 |= 0x60;
  744. break;
  745. case 1024:
  746. par->PanelDispCntlReg1 |= 0x40;
  747. break;
  748. case 800:
  749. par->PanelDispCntlReg1 |= 0x20;
  750. break;
  751. case 640:
  752. default:
  753. break;
  754. }
  755. /* Setup shadow register locking. */
  756. switch (par->PanelDispCntlReg1 & 0x03) {
  757. case 0x01: /* External CRT only mode: */
  758. par->GeneralLockReg = 0x00;
  759. /* We need to program the VCLK for external display only mode. */
  760. par->ProgramVCLK = 1;
  761. break;
  762. case 0x02: /* Internal LCD only mode: */
  763. case 0x03: /* Simultaneous internal/external (LCD/CRT) mode: */
  764. par->GeneralLockReg = 0x01;
  765. /* Don't program the VCLK when using the LCD. */
  766. par->ProgramVCLK = 0;
  767. break;
  768. }
  769. /*
  770. * If the screen is to be stretched, turn on stretching for the
  771. * various modes.
  772. *
  773. * OPTION_LCD_STRETCH means stretching should be turned off!
  774. */
  775. par->PanelDispCntlReg2 = 0x00;
  776. par->PanelDispCntlReg3 = 0x00;
  777. if (par->lcd_stretch && (par->PanelDispCntlReg1 == 0x02) && /* LCD only */
  778. (info->var.xres != par->NeoPanelWidth)) {
  779. switch (info->var.xres) {
  780. case 320: /* Needs testing. KEM -- 24 May 98 */
  781. case 400: /* Needs testing. KEM -- 24 May 98 */
  782. case 640:
  783. case 800:
  784. case 1024:
  785. lcd_stretch = 1;
  786. par->PanelDispCntlReg2 |= 0xC6;
  787. break;
  788. default:
  789. lcd_stretch = 0;
  790. /* No stretching in these modes. */
  791. }
  792. } else
  793. lcd_stretch = 0;
  794. /*
  795. * If the screen is to be centerd, turn on the centering for the
  796. * various modes.
  797. */
  798. par->PanelVertCenterReg1 = 0x00;
  799. par->PanelVertCenterReg2 = 0x00;
  800. par->PanelVertCenterReg3 = 0x00;
  801. par->PanelVertCenterReg4 = 0x00;
  802. par->PanelVertCenterReg5 = 0x00;
  803. par->PanelHorizCenterReg1 = 0x00;
  804. par->PanelHorizCenterReg2 = 0x00;
  805. par->PanelHorizCenterReg3 = 0x00;
  806. par->PanelHorizCenterReg4 = 0x00;
  807. par->PanelHorizCenterReg5 = 0x00;
  808. if (par->PanelDispCntlReg1 & 0x02) {
  809. if (info->var.xres == par->NeoPanelWidth) {
  810. /*
  811. * No centering required when the requested display width
  812. * equals the panel width.
  813. */
  814. } else {
  815. par->PanelDispCntlReg2 |= 0x01;
  816. par->PanelDispCntlReg3 |= 0x10;
  817. /* Calculate the horizontal and vertical offsets. */
  818. if (!lcd_stretch) {
  819. hoffset =
  820. ((par->NeoPanelWidth -
  821. info->var.xres) >> 4) - 1;
  822. voffset =
  823. ((par->NeoPanelHeight -
  824. info->var.yres) >> 1) - 2;
  825. } else {
  826. /* Stretched modes cannot be centered. */
  827. hoffset = 0;
  828. voffset = 0;
  829. }
  830. switch (info->var.xres) {
  831. case 320: /* Needs testing. KEM -- 24 May 98 */
  832. par->PanelHorizCenterReg3 = hoffset;
  833. par->PanelVertCenterReg2 = voffset;
  834. break;
  835. case 400: /* Needs testing. KEM -- 24 May 98 */
  836. par->PanelHorizCenterReg4 = hoffset;
  837. par->PanelVertCenterReg1 = voffset;
  838. break;
  839. case 640:
  840. par->PanelHorizCenterReg1 = hoffset;
  841. par->PanelVertCenterReg3 = voffset;
  842. break;
  843. case 800:
  844. par->PanelHorizCenterReg2 = hoffset;
  845. par->PanelVertCenterReg4 = voffset;
  846. break;
  847. case 1024:
  848. par->PanelHorizCenterReg5 = hoffset;
  849. par->PanelVertCenterReg5 = voffset;
  850. break;
  851. case 1280:
  852. default:
  853. /* No centering in these modes. */
  854. break;
  855. }
  856. }
  857. }
  858. par->biosMode =
  859. neoFindMode(info->var.xres, info->var.yres,
  860. info->var.bits_per_pixel);
  861. /*
  862. * Calculate the VCLK that most closely matches the requested dot
  863. * clock.
  864. */
  865. neoCalcVCLK(info, par, timings.pixclock);
  866. /* Since we program the clocks ourselves, always use VCLK3. */
  867. par->MiscOutReg |= 0x0C;
  868. /* alread unlocked above */
  869. /* BOGUS vga_wgfx(NULL, 0x09, 0x26); */
  870. /* don't know what this is, but it's 0 from bootup anyway */
  871. vga_wgfx(NULL, 0x15, 0x00);
  872. /* was set to 0x01 by my bios in text and vesa modes */
  873. vga_wgfx(NULL, 0x0A, par->GeneralLockReg);
  874. /*
  875. * The color mode needs to be set before calling vgaHWRestore
  876. * to ensure the DAC is initialized properly.
  877. *
  878. * NOTE: Make sure we don't change bits make sure we don't change
  879. * any reserved bits.
  880. */
  881. temp = vga_rgfx(NULL, 0x90);
  882. switch (info->fix.accel) {
  883. case FB_ACCEL_NEOMAGIC_NM2070:
  884. temp &= 0xF0; /* Save bits 7:4 */
  885. temp |= (par->ExtColorModeSelect & ~0xF0);
  886. break;
  887. case FB_ACCEL_NEOMAGIC_NM2090:
  888. case FB_ACCEL_NEOMAGIC_NM2093:
  889. case FB_ACCEL_NEOMAGIC_NM2097:
  890. case FB_ACCEL_NEOMAGIC_NM2160:
  891. case FB_ACCEL_NEOMAGIC_NM2200:
  892. case FB_ACCEL_NEOMAGIC_NM2230:
  893. case FB_ACCEL_NEOMAGIC_NM2360:
  894. case FB_ACCEL_NEOMAGIC_NM2380:
  895. temp &= 0x70; /* Save bits 6:4 */
  896. temp |= (par->ExtColorModeSelect & ~0x70);
  897. break;
  898. }
  899. vga_wgfx(NULL, 0x90, temp);
  900. /*
  901. * In some rare cases a lockup might occur if we don't delay
  902. * here. (Reported by Miles Lane)
  903. */
  904. //mdelay(200);
  905. /*
  906. * Disable horizontal and vertical graphics and text expansions so
  907. * that vgaHWRestore works properly.
  908. */
  909. temp = vga_rgfx(NULL, 0x25);
  910. temp &= 0x39;
  911. vga_wgfx(NULL, 0x25, temp);
  912. /*
  913. * Sleep for 200ms to make sure that the two operations above have
  914. * had time to take effect.
  915. */
  916. mdelay(200);
  917. /*
  918. * This function handles restoring the generic VGA registers. */
  919. vgaHWRestore(info, par);
  920. /* linear colormap for non palettized modes */
  921. switch (info->var.bits_per_pixel) {
  922. case 8:
  923. /* PseudoColor, 256 */
  924. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  925. break;
  926. case 16:
  927. /* TrueColor, 64k */
  928. info->fix.visual = FB_VISUAL_TRUECOLOR;
  929. for (i = 0; i < 64; i++) {
  930. outb(i, 0x3c8);
  931. outb(i << 1, 0x3c9);
  932. outb(i, 0x3c9);
  933. outb(i << 1, 0x3c9);
  934. }
  935. break;
  936. case 24:
  937. #ifdef NO_32BIT_SUPPORT_YET
  938. case 32:
  939. #endif
  940. /* TrueColor, 16m */
  941. info->fix.visual = FB_VISUAL_TRUECOLOR;
  942. for (i = 0; i < 256; i++) {
  943. outb(i, 0x3c8);
  944. outb(i, 0x3c9);
  945. outb(i, 0x3c9);
  946. outb(i, 0x3c9);
  947. }
  948. break;
  949. }
  950. vga_wgfx(NULL, 0x0E, par->ExtCRTDispAddr);
  951. vga_wgfx(NULL, 0x0F, par->ExtCRTOffset);
  952. temp = vga_rgfx(NULL, 0x10);
  953. temp &= 0x0F; /* Save bits 3:0 */
  954. temp |= (par->SysIfaceCntl1 & ~0x0F); /* VESA Bios sets bit 1! */
  955. vga_wgfx(NULL, 0x10, temp);
  956. vga_wgfx(NULL, 0x11, par->SysIfaceCntl2);
  957. vga_wgfx(NULL, 0x15, 0 /*par->SingleAddrPage */ );
  958. vga_wgfx(NULL, 0x16, 0 /*par->DualAddrPage */ );
  959. temp = vga_rgfx(NULL, 0x20);
  960. switch (info->fix.accel) {
  961. case FB_ACCEL_NEOMAGIC_NM2070:
  962. temp &= 0xFC; /* Save bits 7:2 */
  963. temp |= (par->PanelDispCntlReg1 & ~0xFC);
  964. break;
  965. case FB_ACCEL_NEOMAGIC_NM2090:
  966. case FB_ACCEL_NEOMAGIC_NM2093:
  967. case FB_ACCEL_NEOMAGIC_NM2097:
  968. case FB_ACCEL_NEOMAGIC_NM2160:
  969. temp &= 0xDC; /* Save bits 7:6,4:2 */
  970. temp |= (par->PanelDispCntlReg1 & ~0xDC);
  971. break;
  972. case FB_ACCEL_NEOMAGIC_NM2200:
  973. case FB_ACCEL_NEOMAGIC_NM2230:
  974. case FB_ACCEL_NEOMAGIC_NM2360:
  975. case FB_ACCEL_NEOMAGIC_NM2380:
  976. temp &= 0x98; /* Save bits 7,4:3 */
  977. temp |= (par->PanelDispCntlReg1 & ~0x98);
  978. break;
  979. }
  980. vga_wgfx(NULL, 0x20, temp);
  981. temp = vga_rgfx(NULL, 0x25);
  982. temp &= 0x38; /* Save bits 5:3 */
  983. temp |= (par->PanelDispCntlReg2 & ~0x38);
  984. vga_wgfx(NULL, 0x25, temp);
  985. if (info->fix.accel != FB_ACCEL_NEOMAGIC_NM2070) {
  986. temp = vga_rgfx(NULL, 0x30);
  987. temp &= 0xEF; /* Save bits 7:5 and bits 3:0 */
  988. temp |= (par->PanelDispCntlReg3 & ~0xEF);
  989. vga_wgfx(NULL, 0x30, temp);
  990. }
  991. vga_wgfx(NULL, 0x28, par->PanelVertCenterReg1);
  992. vga_wgfx(NULL, 0x29, par->PanelVertCenterReg2);
  993. vga_wgfx(NULL, 0x2a, par->PanelVertCenterReg3);
  994. if (info->fix.accel != FB_ACCEL_NEOMAGIC_NM2070) {
  995. vga_wgfx(NULL, 0x32, par->PanelVertCenterReg4);
  996. vga_wgfx(NULL, 0x33, par->PanelHorizCenterReg1);
  997. vga_wgfx(NULL, 0x34, par->PanelHorizCenterReg2);
  998. vga_wgfx(NULL, 0x35, par->PanelHorizCenterReg3);
  999. }
  1000. if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2160)
  1001. vga_wgfx(NULL, 0x36, par->PanelHorizCenterReg4);
  1002. if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 ||
  1003. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2230 ||
  1004. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2360 ||
  1005. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2380) {
  1006. vga_wgfx(NULL, 0x36, par->PanelHorizCenterReg4);
  1007. vga_wgfx(NULL, 0x37, par->PanelVertCenterReg5);
  1008. vga_wgfx(NULL, 0x38, par->PanelHorizCenterReg5);
  1009. clock_hi = 1;
  1010. }
  1011. /* Program VCLK3 if needed. */
  1012. if (par->ProgramVCLK && ((vga_rgfx(NULL, 0x9B) != par->VCLK3NumeratorLow)
  1013. || (vga_rgfx(NULL, 0x9F) != par->VCLK3Denominator)
  1014. || (clock_hi && ((vga_rgfx(NULL, 0x8F) & ~0x0f)
  1015. != (par->VCLK3NumeratorHigh &
  1016. ~0x0F))))) {
  1017. vga_wgfx(NULL, 0x9B, par->VCLK3NumeratorLow);
  1018. if (clock_hi) {
  1019. temp = vga_rgfx(NULL, 0x8F);
  1020. temp &= 0x0F; /* Save bits 3:0 */
  1021. temp |= (par->VCLK3NumeratorHigh & ~0x0F);
  1022. vga_wgfx(NULL, 0x8F, temp);
  1023. }
  1024. vga_wgfx(NULL, 0x9F, par->VCLK3Denominator);
  1025. }
  1026. if (par->biosMode)
  1027. vga_wcrt(NULL, 0x23, par->biosMode);
  1028. vga_wgfx(NULL, 0x93, 0xc0); /* Gives 5x faster framebuffer writes !!! */
  1029. /* Program vertical extension register */
  1030. if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 ||
  1031. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2230 ||
  1032. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2360 ||
  1033. info->fix.accel == FB_ACCEL_NEOMAGIC_NM2380) {
  1034. vga_wcrt(NULL, 0x70, par->VerticalExt);
  1035. }
  1036. vgaHWProtect(0); /* Turn on screen */
  1037. /* Calling this also locks offset registers required in update_start */
  1038. neoLock(&par->state);
  1039. info->fix.line_length =
  1040. info->var.xres_virtual * (info->var.bits_per_pixel >> 3);
  1041. switch (info->fix.accel) {
  1042. case FB_ACCEL_NEOMAGIC_NM2200:
  1043. case FB_ACCEL_NEOMAGIC_NM2230:
  1044. case FB_ACCEL_NEOMAGIC_NM2360:
  1045. case FB_ACCEL_NEOMAGIC_NM2380:
  1046. neo2200_accel_init(info, &info->var);
  1047. break;
  1048. default:
  1049. break;
  1050. }
  1051. return 0;
  1052. }
  1053. static void neofb_update_start(struct fb_info *info,
  1054. struct fb_var_screeninfo *var)
  1055. {
  1056. struct neofb_par *par = info->par;
  1057. struct vgastate *state = &par->state;
  1058. int oldExtCRTDispAddr;
  1059. int Base;
  1060. DBG("neofb_update_start");
  1061. Base = (var->yoffset * var->xres_virtual + var->xoffset) >> 2;
  1062. Base *= (var->bits_per_pixel + 7) / 8;
  1063. neoUnlock();
  1064. /*
  1065. * These are the generic starting address registers.
  1066. */
  1067. vga_wcrt(state->vgabase, 0x0C, (Base & 0x00FF00) >> 8);
  1068. vga_wcrt(state->vgabase, 0x0D, (Base & 0x00FF));
  1069. /*
  1070. * Make sure we don't clobber some other bits that might already
  1071. * have been set. NOTE: NM2200 has a writable bit 3, but it shouldn't
  1072. * be needed.
  1073. */
  1074. oldExtCRTDispAddr = vga_rgfx(NULL, 0x0E);
  1075. vga_wgfx(state->vgabase, 0x0E, (((Base >> 16) & 0x0f) | (oldExtCRTDispAddr & 0xf0)));
  1076. neoLock(state);
  1077. }
  1078. /*
  1079. * Pan or Wrap the Display
  1080. */
  1081. static int neofb_pan_display(struct fb_var_screeninfo *var,
  1082. struct fb_info *info)
  1083. {
  1084. u_int y_bottom;
  1085. y_bottom = var->yoffset;
  1086. if (!(var->vmode & FB_VMODE_YWRAP))
  1087. y_bottom += var->yres;
  1088. if (var->xoffset > (var->xres_virtual - var->xres))
  1089. return -EINVAL;
  1090. if (y_bottom > info->var.yres_virtual)
  1091. return -EINVAL;
  1092. neofb_update_start(info, var);
  1093. info->var.xoffset = var->xoffset;
  1094. info->var.yoffset = var->yoffset;
  1095. if (var->vmode & FB_VMODE_YWRAP)
  1096. info->var.vmode |= FB_VMODE_YWRAP;
  1097. else
  1098. info->var.vmode &= ~FB_VMODE_YWRAP;
  1099. return 0;
  1100. }
  1101. static int neofb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  1102. u_int transp, struct fb_info *fb)
  1103. {
  1104. if (regno >= fb->cmap.len || regno > 255)
  1105. return -EINVAL;
  1106. if (fb->var.bits_per_pixel <= 8) {
  1107. outb(regno, 0x3c8);
  1108. outb(red >> 10, 0x3c9);
  1109. outb(green >> 10, 0x3c9);
  1110. outb(blue >> 10, 0x3c9);
  1111. } else if (regno < 16) {
  1112. switch (fb->var.bits_per_pixel) {
  1113. case 16:
  1114. ((u32 *) fb->pseudo_palette)[regno] =
  1115. ((red & 0xf800)) | ((green & 0xfc00) >> 5) |
  1116. ((blue & 0xf800) >> 11);
  1117. break;
  1118. case 24:
  1119. ((u32 *) fb->pseudo_palette)[regno] =
  1120. ((red & 0xff00) << 8) | ((green & 0xff00)) |
  1121. ((blue & 0xff00) >> 8);
  1122. break;
  1123. #ifdef NO_32BIT_SUPPORT_YET
  1124. case 32:
  1125. ((u32 *) fb->pseudo_palette)[regno] =
  1126. ((transp & 0xff00) << 16) | ((red & 0xff00) << 8) |
  1127. ((green & 0xff00)) | ((blue & 0xff00) >> 8);
  1128. break;
  1129. #endif
  1130. default:
  1131. return 1;
  1132. }
  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. mutex_init(&par->open_lock);
  1786. par->pci_burst = !nopciburst;
  1787. par->lcd_stretch = !nostretch;
  1788. par->libretto = libretto;
  1789. par->internal_display = internal;
  1790. par->external_display = external;
  1791. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  1792. switch (info->fix.accel) {
  1793. case FB_ACCEL_NEOMAGIC_NM2070:
  1794. snprintf(info->fix.id, sizeof(info->fix.id),
  1795. "MagicGraph 128");
  1796. break;
  1797. case FB_ACCEL_NEOMAGIC_NM2090:
  1798. snprintf(info->fix.id, sizeof(info->fix.id),
  1799. "MagicGraph 128V");
  1800. break;
  1801. case FB_ACCEL_NEOMAGIC_NM2093:
  1802. snprintf(info->fix.id, sizeof(info->fix.id),
  1803. "MagicGraph 128ZV");
  1804. break;
  1805. case FB_ACCEL_NEOMAGIC_NM2097:
  1806. snprintf(info->fix.id, sizeof(info->fix.id),
  1807. "MagicGraph 128ZV+");
  1808. break;
  1809. case FB_ACCEL_NEOMAGIC_NM2160:
  1810. snprintf(info->fix.id, sizeof(info->fix.id),
  1811. "MagicGraph 128XD");
  1812. break;
  1813. case FB_ACCEL_NEOMAGIC_NM2200:
  1814. snprintf(info->fix.id, sizeof(info->fix.id),
  1815. "MagicGraph 256AV");
  1816. info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
  1817. FBINFO_HWACCEL_COPYAREA |
  1818. FBINFO_HWACCEL_FILLRECT;
  1819. break;
  1820. case FB_ACCEL_NEOMAGIC_NM2230:
  1821. snprintf(info->fix.id, sizeof(info->fix.id),
  1822. "MagicGraph 256AV+");
  1823. info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
  1824. FBINFO_HWACCEL_COPYAREA |
  1825. FBINFO_HWACCEL_FILLRECT;
  1826. break;
  1827. case FB_ACCEL_NEOMAGIC_NM2360:
  1828. snprintf(info->fix.id, sizeof(info->fix.id),
  1829. "MagicGraph 256ZX");
  1830. info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
  1831. FBINFO_HWACCEL_COPYAREA |
  1832. FBINFO_HWACCEL_FILLRECT;
  1833. break;
  1834. case FB_ACCEL_NEOMAGIC_NM2380:
  1835. snprintf(info->fix.id, sizeof(info->fix.id),
  1836. "MagicGraph 256XL+");
  1837. info->flags |= FBINFO_HWACCEL_IMAGEBLIT |
  1838. FBINFO_HWACCEL_COPYAREA |
  1839. FBINFO_HWACCEL_FILLRECT;
  1840. break;
  1841. }
  1842. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1843. info->fix.type_aux = 0;
  1844. info->fix.xpanstep = 0;
  1845. info->fix.ypanstep = 4;
  1846. info->fix.ywrapstep = 0;
  1847. info->fix.accel = id->driver_data;
  1848. info->fbops = &neofb_ops;
  1849. info->pseudo_palette = par->palette;
  1850. return info;
  1851. }
  1852. static void neo_free_fb_info(struct fb_info *info)
  1853. {
  1854. if (info) {
  1855. /*
  1856. * Free the colourmap
  1857. */
  1858. fb_dealloc_cmap(&info->cmap);
  1859. framebuffer_release(info);
  1860. }
  1861. }
  1862. /* --------------------------------------------------------------------- */
  1863. static int __devinit neofb_probe(struct pci_dev *dev,
  1864. const struct pci_device_id *id)
  1865. {
  1866. struct fb_info *info;
  1867. u_int h_sync, v_sync;
  1868. int video_len, err;
  1869. DBG("neofb_probe");
  1870. err = pci_enable_device(dev);
  1871. if (err)
  1872. return err;
  1873. err = -ENOMEM;
  1874. info = neo_alloc_fb_info(dev, id);
  1875. if (!info)
  1876. return err;
  1877. err = neo_map_mmio(info, dev);
  1878. if (err)
  1879. goto err_map_mmio;
  1880. err = neo_scan_monitor(info);
  1881. if (err)
  1882. goto err_scan_monitor;
  1883. video_len = neo_init_hw(info);
  1884. if (video_len < 0) {
  1885. err = video_len;
  1886. goto err_init_hw;
  1887. }
  1888. err = neo_map_video(info, dev, video_len);
  1889. if (err)
  1890. goto err_init_hw;
  1891. if (!fb_find_mode(&info->var, info, mode_option, NULL, 0,
  1892. info->monspecs.modedb, 16)) {
  1893. printk(KERN_ERR "neofb: Unable to find usable video mode.\n");
  1894. goto err_map_video;
  1895. }
  1896. /*
  1897. * Calculate the hsync and vsync frequencies. Note that
  1898. * we split the 1e12 constant up so that we can preserve
  1899. * the precision and fit the results into 32-bit registers.
  1900. * (1953125000 * 512 = 1e12)
  1901. */
  1902. h_sync = 1953125000 / info->var.pixclock;
  1903. h_sync =
  1904. h_sync * 512 / (info->var.xres + info->var.left_margin +
  1905. info->var.right_margin + info->var.hsync_len);
  1906. v_sync =
  1907. h_sync / (info->var.yres + info->var.upper_margin +
  1908. info->var.lower_margin + info->var.vsync_len);
  1909. printk(KERN_INFO "neofb v" NEOFB_VERSION
  1910. ": %dkB VRAM, using %dx%d, %d.%03dkHz, %dHz\n",
  1911. info->fix.smem_len >> 10, info->var.xres,
  1912. info->var.yres, h_sync / 1000, h_sync % 1000, v_sync);
  1913. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
  1914. goto err_map_video;
  1915. err = register_framebuffer(info);
  1916. if (err < 0)
  1917. goto err_reg_fb;
  1918. printk(KERN_INFO "fb%d: %s frame buffer device\n",
  1919. info->node, info->fix.id);
  1920. /*
  1921. * Our driver data
  1922. */
  1923. pci_set_drvdata(dev, info);
  1924. return 0;
  1925. err_reg_fb:
  1926. fb_dealloc_cmap(&info->cmap);
  1927. err_map_video:
  1928. neo_unmap_video(info);
  1929. err_init_hw:
  1930. fb_destroy_modedb(info->monspecs.modedb);
  1931. err_scan_monitor:
  1932. neo_unmap_mmio(info);
  1933. err_map_mmio:
  1934. neo_free_fb_info(info);
  1935. return err;
  1936. }
  1937. static void __devexit neofb_remove(struct pci_dev *dev)
  1938. {
  1939. struct fb_info *info = pci_get_drvdata(dev);
  1940. DBG("neofb_remove");
  1941. if (info) {
  1942. /*
  1943. * If unregister_framebuffer fails, then
  1944. * we will be leaving hooks that could cause
  1945. * oopsen laying around.
  1946. */
  1947. if (unregister_framebuffer(info))
  1948. printk(KERN_WARNING
  1949. "neofb: danger danger! Oopsen imminent!\n");
  1950. neo_unmap_video(info);
  1951. fb_destroy_modedb(info->monspecs.modedb);
  1952. neo_unmap_mmio(info);
  1953. neo_free_fb_info(info);
  1954. /*
  1955. * Ensure that the driver data is no longer
  1956. * valid.
  1957. */
  1958. pci_set_drvdata(dev, NULL);
  1959. }
  1960. }
  1961. static struct pci_device_id neofb_devices[] = {
  1962. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2070,
  1963. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2070},
  1964. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2090,
  1965. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2090},
  1966. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2093,
  1967. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2093},
  1968. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2097,
  1969. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2097},
  1970. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2160,
  1971. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2160},
  1972. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2200,
  1973. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2200},
  1974. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2230,
  1975. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2230},
  1976. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2360,
  1977. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2360},
  1978. {PCI_VENDOR_ID_NEOMAGIC, PCI_CHIP_NM2380,
  1979. PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_NEOMAGIC_NM2380},
  1980. {0, 0, 0, 0, 0, 0, 0}
  1981. };
  1982. MODULE_DEVICE_TABLE(pci, neofb_devices);
  1983. static struct pci_driver neofb_driver = {
  1984. .name = "neofb",
  1985. .id_table = neofb_devices,
  1986. .probe = neofb_probe,
  1987. .remove = __devexit_p(neofb_remove)
  1988. };
  1989. /* ************************* init in-kernel code ************************** */
  1990. #ifndef MODULE
  1991. static int __init neofb_setup(char *options)
  1992. {
  1993. char *this_opt;
  1994. DBG("neofb_setup");
  1995. if (!options || !*options)
  1996. return 0;
  1997. while ((this_opt = strsep(&options, ",")) != NULL) {
  1998. if (!*this_opt)
  1999. continue;
  2000. if (!strncmp(this_opt, "internal", 8))
  2001. internal = 1;
  2002. else if (!strncmp(this_opt, "external", 8))
  2003. external = 1;
  2004. else if (!strncmp(this_opt, "nostretch", 9))
  2005. nostretch = 1;
  2006. else if (!strncmp(this_opt, "nopciburst", 10))
  2007. nopciburst = 1;
  2008. else if (!strncmp(this_opt, "libretto", 8))
  2009. libretto = 1;
  2010. else
  2011. mode_option = this_opt;
  2012. }
  2013. return 0;
  2014. }
  2015. #endif /* MODULE */
  2016. static int __init neofb_init(void)
  2017. {
  2018. #ifndef MODULE
  2019. char *option = NULL;
  2020. if (fb_get_options("neofb", &option))
  2021. return -ENODEV;
  2022. neofb_setup(option);
  2023. #endif
  2024. return pci_register_driver(&neofb_driver);
  2025. }
  2026. module_init(neofb_init);
  2027. #ifdef MODULE
  2028. static void __exit neofb_exit(void)
  2029. {
  2030. pci_unregister_driver(&neofb_driver);
  2031. }
  2032. module_exit(neofb_exit);
  2033. #endif /* MODULE */