neofb.c 58 KB

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