neofb.c 57 KB

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