neofb.c 55 KB

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