neofb.c 58 KB

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