cyberfb.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297
  1. /*
  2. * linux/drivers/video/cyberfb.c -- CyberVision64 frame buffer device
  3. * $Id: cyberfb.c,v 1.6 1998/09/11 04:54:58 abair Exp $
  4. *
  5. * Copyright (C) 1998 Alan Bair
  6. *
  7. * This file is based on two CyberVision64 frame buffer device drivers
  8. *
  9. * The second CyberVision64 frame buffer device (cvision.c cvision_core.c):
  10. *
  11. * Copyright (c) 1997 Antonio Santos
  12. *
  13. * Released as a patch to 2.1.35, but never included in the source tree.
  14. * This is based on work from the NetBSD CyberVision64 frame buffer driver
  15. * and support files (grf_cv.c, grf_cvreg.h, ite_cv.c):
  16. * Permission to use the source of this driver was obtained from the
  17. * author Michael Teske by Alan Bair.
  18. *
  19. * Copyright (c) 1995 Michael Teske
  20. *
  21. * The first CyberVision64 frame buffer device (cyberfb.c):
  22. *
  23. * Copyright (C) 1996 Martin Apel
  24. * Geert Uytterhoeven
  25. *
  26. * Which is based on the Amiga frame buffer device (amifb.c):
  27. *
  28. * Copyright (C) 1995 Geert Uytterhoeven
  29. *
  30. *
  31. * History:
  32. * - 22 Dec 95: Original version by Martin Apel
  33. * - 05 Jan 96: Geert: integration into the current source tree
  34. * - 01 Aug 98: Alan: Merge in code from cvision.c and cvision_core.c
  35. * $Log: cyberfb.c,v $
  36. * Revision 1.6 1998/09/11 04:54:58 abair
  37. * Update for 2.1.120 change in include file location.
  38. * Clean up for public release.
  39. *
  40. * Revision 1.5 1998/09/03 04:27:13 abair
  41. * Move cv64_load_video_mode to cyber_set_video so a new video mode is install
  42. * with each change of the 'var' data.
  43. *
  44. * Revision 1.4 1998/09/01 00:31:17 abair
  45. * Put in a set of default 8,16,24 bpp modes and map cyber8,16 to them.
  46. * Update operations with 'par' to handle a more complete set of parameter
  47. * values for encode/decode process.
  48. *
  49. * Revision 1.3 1998/08/31 21:31:33 abair
  50. * Swap 800x490 for 640x480 video mode and more cleanup.
  51. * Abandon idea to resurrect "custom" mode setting via kernel opts,
  52. * instead work on making use of fbset program to do this.
  53. *
  54. * Revision 1.2 1998/08/31 06:17:08 abair
  55. * Make updates for changes in cyberfb.c released in 2.1.119
  56. * and do some cleanup of the code.
  57. *
  58. * Revision 1.1 1998/08/29 18:38:31 abair
  59. * Initial revision
  60. *
  61. * Revision 1.3 1998/08/17 06:21:53 abair
  62. * Remove more redundant code after merging in cvision_core.c
  63. * Set blanking by colormap to pale red to detect this vs trying to
  64. * use video blanking. More formating to Linux code style.
  65. *
  66. * Revision 1.2 1998/08/15 17:51:37 abair
  67. * Added cvision_core.c code from 2.1.35 patches.
  68. * Changed to compile correctly and switch to using initialization
  69. * code. Added debugging and dropping of duplicate code.
  70. *
  71. *
  72. *
  73. * This file is subject to the terms and conditions of the GNU General Public
  74. * License. See the file COPYING in the main directory of this archive
  75. * for more details.
  76. */
  77. #include <linux/module.h>
  78. #include <linux/kernel.h>
  79. #include <linux/errno.h>
  80. #include <linux/string.h>
  81. #include <linux/mm.h>
  82. #include <linux/slab.h>
  83. #include <linux/delay.h>
  84. #include <linux/zorro.h>
  85. #include <linux/fb.h>
  86. #include <linux/init.h>
  87. #include <asm/uaccess.h>
  88. #include <asm/system.h>
  89. #include <asm/irq.h>
  90. #include <asm/pgtable.h>
  91. #include <asm/amigahw.h>
  92. #include <asm/io.h>
  93. #include "cyberfb.h"
  94. #include <video/fbcon.h>
  95. #include <video/fbcon-cfb8.h>
  96. #include <video/fbcon-cfb16.h>
  97. /*#define CYBERFBDEBUG*/
  98. #ifdef CYBERFBDEBUG
  99. #define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
  100. static void cv64_dump(void);
  101. #else
  102. #define DPRINTK(fmt, args...)
  103. #endif
  104. #define wb_64(regs,reg,dat) (*(((volatile unsigned char *)regs) + reg) = dat)
  105. #define rb_64(regs, reg) (*(((volatile unsigned char *)regs) + reg))
  106. #define ww_64(regs,reg,dat) (*((volatile unsigned short *)(regs + reg) = dat)
  107. struct cyberfb_par {
  108. struct fb_var_screeninfo var;
  109. __u32 type;
  110. __u32 type_aux;
  111. __u32 visual;
  112. __u32 line_length;
  113. };
  114. static struct cyberfb_par current_par;
  115. static int current_par_valid = 0;
  116. static struct display disp;
  117. static struct fb_info fb_info;
  118. /*
  119. * Frame Buffer Name
  120. */
  121. static char cyberfb_name[16] = "Cybervision";
  122. /*
  123. * CyberVision Graphics Board
  124. */
  125. static unsigned char Cyber_colour_table [256][3];
  126. static unsigned long CyberSize;
  127. static volatile unsigned char *CyberBase;
  128. static volatile unsigned char *CyberMem;
  129. static volatile unsigned char *CyberRegs;
  130. static unsigned long CyberMem_phys;
  131. static unsigned long CyberRegs_phys;
  132. /*
  133. * Predefined Video Modes
  134. */
  135. static struct {
  136. const char *name;
  137. struct fb_var_screeninfo var;
  138. } cyberfb_predefined[] __initdata = {
  139. { "640x480-8", { /* Default 8 BPP mode (cyber8) */
  140. 640, 480, 640, 480, 0, 0, 8, 0,
  141. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  142. 0, 0, -1, -1, FB_ACCELF_TEXT, 39722, 40, 24, 32, 11, 96, 2,
  143. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  144. FB_VMODE_NONINTERLACED
  145. }},
  146. { "640x480-16", { /* Default 16 BPP mode (cyber16) */
  147. 640, 480, 640, 480, 0, 0, 16, 0,
  148. {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
  149. 0, 0, -1, -1, FB_ACCELF_TEXT, 39722, 40, 24, 32, 11, 96, 2,
  150. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  151. FB_VMODE_NONINTERLACED
  152. }},
  153. { "640x480-24", { /* Default 24 BPP mode */
  154. 640, 480, 640, 480, 0, 0, 24, 0,
  155. {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0},
  156. 0, 0, -1, -1, FB_ACCELF_TEXT, 39722, 40, 24, 32, 11, 96, 2,
  157. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  158. FB_VMODE_NONINTERLACED
  159. }},
  160. { "800x490-8", { /* Cybervision 8 bpp */
  161. /* NO Acceleration */
  162. 800, 490, 800, 490, 0, 0, 8, 0,
  163. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  164. 0, 0, -1, -1, FB_ACCEL_NONE, 33333, 80, 24, 23, 1, 56, 8,
  165. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  166. FB_VMODE_NONINTERLACED
  167. }},
  168. /* I can't test these with my monitor, but I suspect they will
  169. * be OK, since Antonio Santos indicated he had tested them in
  170. * his system.
  171. */
  172. { "800x600-8", { /* Cybervision 8 bpp */
  173. 800, 600, 800, 600, 0, 0, 8, 0,
  174. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  175. 0, 0, -1, -1, FB_ACCELF_TEXT, 27778, 64, 24, 22, 1, 72, 2,
  176. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  177. FB_VMODE_NONINTERLACED
  178. }},
  179. { "1024x768-8", { /* Cybervision 8 bpp */
  180. 1024, 768, 1024, 768, 0, 0, 8, 0,
  181. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  182. 0, 0, -1, -1, FB_ACCELF_TEXT, 16667, 224, 72, 60, 12, 168, 4,
  183. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  184. FB_VMODE_NONINTERLACED
  185. }},
  186. { "1152x886-8", { /* Cybervision 8 bpp */
  187. 1152, 886, 1152, 886, 0, 0, 8, 0,
  188. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  189. 0, 0, -1, -1, FB_ACCELF_TEXT, 15873, 184, 40, 24, 1, 56, 16,
  190. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  191. FB_VMODE_NONINTERLACED
  192. }},
  193. { "1280x1024-8", { /* Cybervision 8 bpp */
  194. 1280, 1024, 1280, 1024, 0, 0, 8, 0,
  195. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  196. 0, 0, -1, -1, FB_ACCELF_TEXT, 16667, 256, 48, 50, 12, 72, 4,
  197. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  198. FB_VMODE_INTERLACED
  199. }}
  200. };
  201. #define NUM_TOTAL_MODES ARRAY_SIZE(cyberfb_predefined)
  202. static int Cyberfb_inverse = 0;
  203. /*
  204. * Some default modes
  205. */
  206. #define CYBER8_DEFMODE (0)
  207. #define CYBER16_DEFMODE (1)
  208. static struct fb_var_screeninfo cyberfb_default;
  209. static int cyberfb_usermode __initdata = 0;
  210. /*
  211. * Interface used by the world
  212. */
  213. int cyberfb_setup(char *options);
  214. static int cyberfb_get_fix(struct fb_fix_screeninfo *fix, int con,
  215. struct fb_info *info);
  216. static int cyberfb_get_var(struct fb_var_screeninfo *var, int con,
  217. struct fb_info *info);
  218. static int cyberfb_set_var(struct fb_var_screeninfo *var, int con,
  219. struct fb_info *info);
  220. static int cyberfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
  221. struct fb_info *info);
  222. static int cyberfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  223. u_int transp, struct fb_info *info);
  224. static int cyberfb_blank(int blank, struct fb_info *info);
  225. /*
  226. * Interface to the low level console driver
  227. */
  228. int cyberfb_init(void);
  229. static int Cyberfb_switch(int con, struct fb_info *info);
  230. static int Cyberfb_updatevar(int con, struct fb_info *info);
  231. /*
  232. * Text console acceleration
  233. */
  234. #ifdef FBCON_HAS_CFB8
  235. static struct display_switch fbcon_cyber8;
  236. #endif
  237. /*
  238. * Accelerated Functions used by the low level console driver
  239. */
  240. static void Cyber_WaitQueue(u_short fifo);
  241. static void Cyber_WaitBlit(void);
  242. static void Cyber_BitBLT(u_short curx, u_short cury, u_short destx,
  243. u_short desty, u_short width, u_short height,
  244. u_short mode);
  245. static void Cyber_RectFill(u_short x, u_short y, u_short width, u_short height,
  246. u_short mode, u_short color);
  247. #if 0
  248. static void Cyber_MoveCursor(u_short x, u_short y);
  249. #endif
  250. /*
  251. * Hardware Specific Routines
  252. */
  253. static int Cyber_init(void);
  254. static int Cyber_encode_fix(struct fb_fix_screeninfo *fix,
  255. struct cyberfb_par *par);
  256. static int Cyber_decode_var(struct fb_var_screeninfo *var,
  257. struct cyberfb_par *par);
  258. static int Cyber_encode_var(struct fb_var_screeninfo *var,
  259. struct cyberfb_par *par);
  260. static int Cyber_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
  261. u_int *transp, struct fb_info *info);
  262. /*
  263. * Internal routines
  264. */
  265. static void cyberfb_get_par(struct cyberfb_par *par);
  266. static void cyberfb_set_par(struct cyberfb_par *par);
  267. static int do_fb_set_var(struct fb_var_screeninfo *var, int isactive);
  268. static void cyberfb_set_disp(int con, struct fb_info *info);
  269. static int get_video_mode(const char *name);
  270. /* For cvision_core.c */
  271. static unsigned short cv64_compute_clock(unsigned long);
  272. static int cv_has_4mb (volatile unsigned char *);
  273. static void cv64_board_init (void);
  274. static void cv64_load_video_mode (struct fb_var_screeninfo *);
  275. /* -------------------- Hardware specific routines ------------------------- */
  276. /*
  277. * Initialization
  278. *
  279. * Set the default video mode for this chipset. If a video mode was
  280. * specified on the command line, it will override the default mode.
  281. */
  282. static int Cyber_init(void)
  283. {
  284. volatile unsigned char *regs = CyberRegs;
  285. volatile unsigned long *CursorBase;
  286. int i;
  287. DPRINTK("ENTER\n");
  288. /* Init local cmap as greyscale levels */
  289. for (i = 0; i < 256; i++) {
  290. Cyber_colour_table [i][0] = i;
  291. Cyber_colour_table [i][1] = i;
  292. Cyber_colour_table [i][2] = i;
  293. }
  294. /* Initialize the board and determine fbmem size */
  295. cv64_board_init();
  296. #ifdef CYBERFBDEBUG
  297. DPRINTK("Register state after initing board\n");
  298. cv64_dump();
  299. #endif
  300. /* Clear framebuffer memory */
  301. DPRINTK("Clear framebuffer memory\n");
  302. memset ((char *)CyberMem, 0, CyberSize);
  303. /* Disable hardware cursor */
  304. DPRINTK("Disable HW cursor\n");
  305. wb_64(regs, S3_CRTC_ADR, S3_REG_LOCK2);
  306. wb_64(regs, S3_CRTC_DATA, 0xa0);
  307. wb_64(regs, S3_CRTC_ADR, S3_HGC_MODE);
  308. wb_64(regs, S3_CRTC_DATA, 0x00);
  309. wb_64(regs, S3_CRTC_ADR, S3_HWGC_DX);
  310. wb_64(regs, S3_CRTC_DATA, 0x00);
  311. wb_64(regs, S3_CRTC_ADR, S3_HWGC_DY);
  312. wb_64(regs, S3_CRTC_DATA, 0x00);
  313. /* Initialize hardware cursor */
  314. DPRINTK("Init HW cursor\n");
  315. CursorBase = (u_long *)((char *)(CyberMem) + CyberSize - 0x400);
  316. for (i=0; i < 8; i++)
  317. {
  318. *(CursorBase +(i*4)) = 0xffffff00;
  319. *(CursorBase+1+(i*4)) = 0xffff0000;
  320. *(CursorBase+2+(i*4)) = 0xffff0000;
  321. *(CursorBase+3+(i*4)) = 0xffff0000;
  322. }
  323. for (i=8; i < 64; i++)
  324. {
  325. *(CursorBase +(i*4)) = 0xffff0000;
  326. *(CursorBase+1+(i*4)) = 0xffff0000;
  327. *(CursorBase+2+(i*4)) = 0xffff0000;
  328. *(CursorBase+3+(i*4)) = 0xffff0000;
  329. }
  330. cyberfb_setcolreg (255, 56<<8, 100<<8, 160<<8, 0, NULL /* unused */);
  331. cyberfb_setcolreg (254, 0, 0, 0, 0, NULL /* unused */);
  332. DPRINTK("EXIT\n");
  333. return 0;
  334. }
  335. /*
  336. * This function should fill in the `fix' structure based on the
  337. * values in the `par' structure.
  338. */
  339. static int Cyber_encode_fix(struct fb_fix_screeninfo *fix,
  340. struct cyberfb_par *par)
  341. {
  342. DPRINTK("ENTER\n");
  343. memset(fix, 0, sizeof(struct fb_fix_screeninfo));
  344. strcpy(fix->id, cyberfb_name);
  345. fix->smem_start = CyberMem_phys;
  346. fix->smem_len = CyberSize;
  347. fix->mmio_start = CyberRegs_phys;
  348. fix->mmio_len = 0x10000;
  349. fix->type = FB_TYPE_PACKED_PIXELS;
  350. fix->type_aux = 0;
  351. if (par->var.bits_per_pixel == 15 || par->var.bits_per_pixel == 16 ||
  352. par->var.bits_per_pixel == 24 || par->var.bits_per_pixel == 32) {
  353. fix->visual = FB_VISUAL_DIRECTCOLOR;
  354. } else {
  355. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  356. }
  357. fix->xpanstep = 0;
  358. fix->ypanstep = 0;
  359. fix->ywrapstep = 0;
  360. fix->line_length = 0;
  361. fix->accel = FB_ACCEL_S3_TRIO64;
  362. DPRINTK("EXIT\n");
  363. return(0);
  364. }
  365. /*
  366. * Fill the `par' structure based on the values in `var'.
  367. * TODO: Verify and adjust values, return -EINVAL if bad.
  368. */
  369. static int Cyber_decode_var(struct fb_var_screeninfo *var,
  370. struct cyberfb_par *par)
  371. {
  372. DPRINTK("ENTER\n");
  373. par->var.xres = var->xres;
  374. par->var.yres = var->yres;
  375. par->var.xres_virtual = var->xres_virtual;
  376. par->var.yres_virtual = var->yres_virtual;
  377. par->var.xoffset = var->xoffset;
  378. par->var.yoffset = var->yoffset;
  379. par->var.bits_per_pixel = var->bits_per_pixel;
  380. par->var.grayscale = var->grayscale;
  381. par->var.red = var->red;
  382. par->var.green = var->green;
  383. par->var.blue = var->blue;
  384. par->var.transp = var->transp;
  385. par->var.nonstd = var->nonstd;
  386. par->var.activate = var->activate;
  387. par->var.height = var->height;
  388. par->var.width = var->width;
  389. if (var->accel_flags & FB_ACCELF_TEXT) {
  390. par->var.accel_flags = FB_ACCELF_TEXT;
  391. } else {
  392. par->var.accel_flags = 0;
  393. }
  394. par->var.pixclock = var->pixclock;
  395. par->var.left_margin = var->left_margin;
  396. par->var.right_margin = var->right_margin;
  397. par->var.upper_margin = var->upper_margin;
  398. par->var.lower_margin = var->lower_margin;
  399. par->var.hsync_len = var->hsync_len;
  400. par->var.vsync_len = var->vsync_len;
  401. par->var.sync = var->sync;
  402. par->var.vmode = var->vmode;
  403. DPRINTK("EXIT\n");
  404. return(0);
  405. }
  406. /*
  407. * Fill the `var' structure based on the values in `par' and maybe
  408. * other values read out of the hardware.
  409. */
  410. static int Cyber_encode_var(struct fb_var_screeninfo *var,
  411. struct cyberfb_par *par)
  412. {
  413. DPRINTK("ENTER\n");
  414. var->xres = par->var.xres;
  415. var->yres = par->var.yres;
  416. var->xres_virtual = par->var.xres_virtual;
  417. var->yres_virtual = par->var.yres_virtual;
  418. var->xoffset = par->var.xoffset;
  419. var->yoffset = par->var.yoffset;
  420. var->bits_per_pixel = par->var.bits_per_pixel;
  421. var->grayscale = par->var.grayscale;
  422. var->red = par->var.red;
  423. var->green = par->var.green;
  424. var->blue = par->var.blue;
  425. var->transp = par->var.transp;
  426. var->nonstd = par->var.nonstd;
  427. var->activate = par->var.activate;
  428. var->height = par->var.height;
  429. var->width = par->var.width;
  430. var->accel_flags = par->var.accel_flags;
  431. var->pixclock = par->var.pixclock;
  432. var->left_margin = par->var.left_margin;
  433. var->right_margin = par->var.right_margin;
  434. var->upper_margin = par->var.upper_margin;
  435. var->lower_margin = par->var.lower_margin;
  436. var->hsync_len = par->var.hsync_len;
  437. var->vsync_len = par->var.vsync_len;
  438. var->sync = par->var.sync;
  439. var->vmode = par->var.vmode;
  440. DPRINTK("EXIT\n");
  441. return(0);
  442. }
  443. /*
  444. * Set a single color register. Return != 0 for invalid regno.
  445. */
  446. static int cyberfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  447. u_int transp, struct fb_info *info)
  448. {
  449. volatile unsigned char *regs = CyberRegs;
  450. /*DPRINTK("ENTER\n");*/
  451. if (regno > 255) {
  452. DPRINTK("EXIT - Register # > 255\n");
  453. return (1);
  454. }
  455. wb_64(regs, 0x3c8, (unsigned char) regno);
  456. red >>= 10;
  457. green >>= 10;
  458. blue >>= 10;
  459. Cyber_colour_table [regno][0] = red;
  460. Cyber_colour_table [regno][1] = green;
  461. Cyber_colour_table [regno][2] = blue;
  462. wb_64(regs, 0x3c9, red);
  463. wb_64(regs, 0x3c9, green);
  464. wb_64(regs, 0x3c9, blue);
  465. /*DPRINTK("EXIT\n");*/
  466. return (0);
  467. }
  468. /*
  469. * Read a single color register and split it into
  470. * colors/transparent. Return != 0 for invalid regno.
  471. */
  472. static int Cyber_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
  473. u_int *transp, struct fb_info *info)
  474. {
  475. int t;
  476. /*DPRINTK("ENTER\n");*/
  477. if (regno > 255) {
  478. DPRINTK("EXIT - Register # > 255\n");
  479. return (1);
  480. }
  481. /* ARB This shifting & oring seems VERY strange */
  482. t = Cyber_colour_table [regno][0];
  483. *red = (t<<10) | (t<<4) | (t>>2);
  484. t = Cyber_colour_table [regno][1];
  485. *green = (t<<10) | (t<<4) | (t>>2);
  486. t = Cyber_colour_table [regno][2];
  487. *blue = (t<<10) | (t<<4) | (t>>2);
  488. *transp = 0;
  489. /*DPRINTK("EXIT\n");*/
  490. return (0);
  491. }
  492. /*
  493. * (Un)Blank the screen
  494. * blank: 1 = zero fb cmap
  495. * 0 = restore fb cmap from local cmap
  496. */
  497. static int cyberfb_blank(int blank, struct fb_info *info)
  498. {
  499. volatile unsigned char *regs = CyberRegs;
  500. int i;
  501. DPRINTK("ENTER\n");
  502. #if 0
  503. /* Blank by turning gfx off */
  504. gfx_on_off (1, regs);
  505. #else
  506. if (blank) {
  507. for (i = 0; i < 256; i++) {
  508. wb_64(regs, 0x3c8, (unsigned char) i);
  509. /* ARB Pale red to detect this blanking method */
  510. wb_64(regs, 0x3c9, 48);
  511. wb_64(regs, 0x3c9, 0);
  512. wb_64(regs, 0x3c9, 0);
  513. }
  514. } else {
  515. for (i = 0; i < 256; i++) {
  516. wb_64(regs, 0x3c8, (unsigned char) i);
  517. wb_64(regs, 0x3c9, Cyber_colour_table[i][0]);
  518. wb_64(regs, 0x3c9, Cyber_colour_table[i][1]);
  519. wb_64(regs, 0x3c9, Cyber_colour_table[i][2]);
  520. }
  521. }
  522. #endif
  523. DPRINTK("EXIT\n");
  524. return 0;
  525. }
  526. /**************************************************************
  527. * We are waiting for "fifo" FIFO-slots empty
  528. */
  529. static void Cyber_WaitQueue (u_short fifo)
  530. {
  531. unsigned short status;
  532. DPRINTK("ENTER\n");
  533. do {
  534. status = *((u_short volatile *)(CyberRegs + S3_GP_STAT));
  535. } while (status & fifo);
  536. DPRINTK("EXIT\n");
  537. }
  538. /**************************************************************
  539. * We are waiting for Hardware (Graphics Engine) not busy
  540. */
  541. static void Cyber_WaitBlit (void)
  542. {
  543. unsigned short status;
  544. DPRINTK("ENTER\n");
  545. do {
  546. status = *((u_short volatile *)(CyberRegs + S3_GP_STAT));
  547. } while (status & S3_HDW_BUSY);
  548. DPRINTK("EXIT\n");
  549. }
  550. /**************************************************************
  551. * BitBLT - Through the Plane
  552. */
  553. static void Cyber_BitBLT (u_short curx, u_short cury, u_short destx,
  554. u_short desty, u_short width, u_short height,
  555. u_short mode)
  556. {
  557. volatile unsigned char *regs = CyberRegs;
  558. u_short blitcmd = S3_BITBLT;
  559. DPRINTK("ENTER\n");
  560. /* Set drawing direction */
  561. /* -Y, X maj, -X (default) */
  562. if (curx > destx) {
  563. blitcmd |= 0x0020; /* Drawing direction +X */
  564. } else {
  565. curx += (width - 1);
  566. destx += (width - 1);
  567. }
  568. if (cury > desty) {
  569. blitcmd |= 0x0080; /* Drawing direction +Y */
  570. } else {
  571. cury += (height - 1);
  572. desty += (height - 1);
  573. }
  574. Cyber_WaitQueue (0x8000);
  575. *((u_short volatile *)(regs + S3_PIXEL_CNTL)) = 0xa000;
  576. *((u_short volatile *)(regs + S3_FRGD_MIX)) = (0x0060 | mode);
  577. *((u_short volatile *)(regs + S3_CUR_X)) = curx;
  578. *((u_short volatile *)(regs + S3_CUR_Y)) = cury;
  579. *((u_short volatile *)(regs + S3_DESTX_DIASTP)) = destx;
  580. *((u_short volatile *)(regs + S3_DESTY_AXSTP)) = desty;
  581. *((u_short volatile *)(regs + S3_MIN_AXIS_PCNT)) = height - 1;
  582. *((u_short volatile *)(regs + S3_MAJ_AXIS_PCNT)) = width - 1;
  583. *((u_short volatile *)(regs + S3_CMD)) = blitcmd;
  584. DPRINTK("EXIT\n");
  585. }
  586. /**************************************************************
  587. * Rectangle Fill Solid
  588. */
  589. static void Cyber_RectFill (u_short x, u_short y, u_short width,
  590. u_short height, u_short mode, u_short color)
  591. {
  592. volatile unsigned char *regs = CyberRegs;
  593. u_short blitcmd = S3_FILLEDRECT;
  594. DPRINTK("ENTER\n");
  595. Cyber_WaitQueue (0x8000);
  596. *((u_short volatile *)(regs + S3_PIXEL_CNTL)) = 0xa000;
  597. *((u_short volatile *)(regs + S3_FRGD_MIX)) = (0x0020 | mode);
  598. *((u_short volatile *)(regs + S3_MULT_MISC)) = 0xe000;
  599. *((u_short volatile *)(regs + S3_FRGD_COLOR)) = color;
  600. *((u_short volatile *)(regs + S3_CUR_X)) = x;
  601. *((u_short volatile *)(regs + S3_CUR_Y)) = y;
  602. *((u_short volatile *)(regs + S3_MIN_AXIS_PCNT)) = height - 1;
  603. *((u_short volatile *)(regs + S3_MAJ_AXIS_PCNT)) = width - 1;
  604. *((u_short volatile *)(regs + S3_CMD)) = blitcmd;
  605. DPRINTK("EXIT\n");
  606. }
  607. #if 0
  608. /**************************************************************
  609. * Move cursor to x, y
  610. */
  611. static void Cyber_MoveCursor (u_short x, u_short y)
  612. {
  613. volatile unsigned char *regs = CyberRegs;
  614. DPRINTK("ENTER\n");
  615. *(regs + S3_CRTC_ADR) = 0x39;
  616. *(regs + S3_CRTC_DATA) = 0xa0;
  617. *(regs + S3_CRTC_ADR) = S3_HWGC_ORGX_H;
  618. *(regs + S3_CRTC_DATA) = (char)((x & 0x0700) >> 8);
  619. *(regs + S3_CRTC_ADR) = S3_HWGC_ORGX_L;
  620. *(regs + S3_CRTC_DATA) = (char)(x & 0x00ff);
  621. *(regs + S3_CRTC_ADR) = S3_HWGC_ORGY_H;
  622. *(regs + S3_CRTC_DATA) = (char)((y & 0x0700) >> 8);
  623. *(regs + S3_CRTC_ADR) = S3_HWGC_ORGY_L;
  624. *(regs + S3_CRTC_DATA) = (char)(y & 0x00ff);
  625. DPRINTK("EXIT\n");
  626. }
  627. #endif
  628. /* -------------------- Generic routines ---------------------------------- */
  629. /*
  630. * Fill the hardware's `par' structure.
  631. */
  632. static void cyberfb_get_par(struct cyberfb_par *par)
  633. {
  634. DPRINTK("ENTER\n");
  635. if (current_par_valid) {
  636. *par = current_par;
  637. } else {
  638. Cyber_decode_var(&cyberfb_default, par);
  639. }
  640. DPRINTK("EXIT\n");
  641. }
  642. static void cyberfb_set_par(struct cyberfb_par *par)
  643. {
  644. DPRINTK("ENTER\n");
  645. current_par = *par;
  646. current_par_valid = 1;
  647. DPRINTK("EXIT\n");
  648. }
  649. static void cyber_set_video(struct fb_var_screeninfo *var)
  650. {
  651. /* Load the video mode defined by the 'var' data */
  652. cv64_load_video_mode (var);
  653. #ifdef CYBERFBDEBUG
  654. DPRINTK("Register state after loading video mode\n");
  655. cv64_dump();
  656. #endif
  657. }
  658. static int do_fb_set_var(struct fb_var_screeninfo *var, int isactive)
  659. {
  660. int err, activate;
  661. struct cyberfb_par par;
  662. DPRINTK("ENTER\n");
  663. if ((err = Cyber_decode_var(var, &par))) {
  664. DPRINTK("EXIT - decode_var failed\n");
  665. return(err);
  666. }
  667. activate = var->activate;
  668. if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW && isactive)
  669. cyberfb_set_par(&par);
  670. Cyber_encode_var(var, &par);
  671. var->activate = activate;
  672. cyber_set_video(var);
  673. DPRINTK("EXIT\n");
  674. return 0;
  675. }
  676. /*
  677. * Get the Fixed Part of the Display
  678. */
  679. static int cyberfb_get_fix(struct fb_fix_screeninfo *fix, int con,
  680. struct fb_info *info)
  681. {
  682. struct cyberfb_par par;
  683. int error = 0;
  684. DPRINTK("ENTER\n");
  685. if (con == -1) {
  686. cyberfb_get_par(&par);
  687. } else {
  688. error = Cyber_decode_var(&fb_display[con].var, &par);
  689. }
  690. DPRINTK("EXIT\n");
  691. return(error ? error : Cyber_encode_fix(fix, &par));
  692. }
  693. /*
  694. * Get the User Defined Part of the Display
  695. */
  696. static int cyberfb_get_var(struct fb_var_screeninfo *var, int con,
  697. struct fb_info *info)
  698. {
  699. struct cyberfb_par par;
  700. int error = 0;
  701. DPRINTK("ENTER\n");
  702. if (con == -1) {
  703. cyberfb_get_par(&par);
  704. error = Cyber_encode_var(var, &par);
  705. disp.var = *var; /* ++Andre: don't know if this is the right place */
  706. } else {
  707. *var = fb_display[con].var;
  708. }
  709. DPRINTK("EXIT\n");
  710. return(error);
  711. }
  712. static void cyberfb_set_disp(int con, struct fb_info *info)
  713. {
  714. struct fb_fix_screeninfo fix;
  715. struct display *display;
  716. DPRINTK("ENTER\n");
  717. if (con >= 0)
  718. display = &fb_display[con];
  719. else
  720. display = &disp; /* used during initialization */
  721. cyberfb_get_fix(&fix, con, info);
  722. if (con == -1)
  723. con = 0;
  724. display->visual = fix.visual;
  725. display->type = fix.type;
  726. display->type_aux = fix.type_aux;
  727. display->ypanstep = fix.ypanstep;
  728. display->ywrapstep = fix.ywrapstep;
  729. display->can_soft_blank = 1;
  730. display->inverse = Cyberfb_inverse;
  731. switch (display->var.bits_per_pixel) {
  732. #ifdef FBCON_HAS_CFB8
  733. case 8:
  734. if (display->var.accel_flags & FB_ACCELF_TEXT) {
  735. display->dispsw = &fbcon_cyber8;
  736. #warning FIXME: We should reinit the graphics engine here
  737. } else
  738. display->dispsw = &fbcon_cfb8;
  739. break;
  740. #endif
  741. #ifdef FBCON_HAS_CFB16
  742. case 16:
  743. display->dispsw = &fbcon_cfb16;
  744. break;
  745. #endif
  746. default:
  747. display->dispsw = NULL;
  748. break;
  749. }
  750. DPRINTK("EXIT\n");
  751. }
  752. /*
  753. * Set the User Defined Part of the Display
  754. */
  755. static int cyberfb_set_var(struct fb_var_screeninfo *var, int con,
  756. struct fb_info *info)
  757. {
  758. int err, oldxres, oldyres, oldvxres, oldvyres, oldbpp, oldaccel;
  759. DPRINTK("ENTER\n");
  760. if ((err = do_fb_set_var(var, con == info->currcon))) {
  761. DPRINTK("EXIT - do_fb_set_var failed\n");
  762. return(err);
  763. }
  764. if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
  765. oldxres = fb_display[con].var.xres;
  766. oldyres = fb_display[con].var.yres;
  767. oldvxres = fb_display[con].var.xres_virtual;
  768. oldvyres = fb_display[con].var.yres_virtual;
  769. oldbpp = fb_display[con].var.bits_per_pixel;
  770. oldaccel = fb_display[con].var.accel_flags;
  771. fb_display[con].var = *var;
  772. if (oldxres != var->xres || oldyres != var->yres ||
  773. oldvxres != var->xres_virtual ||
  774. oldvyres != var->yres_virtual ||
  775. oldbpp != var->bits_per_pixel ||
  776. oldaccel != var->accel_flags) {
  777. cyberfb_set_disp(con, info);
  778. (*fb_info.changevar)(con);
  779. fb_alloc_cmap(&fb_display[con].cmap, 0, 0);
  780. do_install_cmap(con, info);
  781. }
  782. }
  783. var->activate = 0;
  784. DPRINTK("EXIT\n");
  785. return(0);
  786. }
  787. /*
  788. * Get the Colormap
  789. */
  790. static int cyberfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
  791. struct fb_info *info)
  792. {
  793. DPRINTK("ENTER\n");
  794. if (con == info->currcon) { /* current console? */
  795. DPRINTK("EXIT - console is current console\n");
  796. return(fb_get_cmap(cmap, kspc, Cyber_getcolreg, info));
  797. } else if (fb_display[con].cmap.len) { /* non default colormap? */
  798. DPRINTK("Use console cmap\n");
  799. fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
  800. } else {
  801. DPRINTK("Use default cmap\n");
  802. fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),
  803. cmap, kspc ? 0 : 2);
  804. }
  805. DPRINTK("EXIT\n");
  806. return(0);
  807. }
  808. static struct fb_ops cyberfb_ops = {
  809. .owner = THIS_MODULE,
  810. .fb_get_fix = cyberfb_get_fix,
  811. .fb_get_var = cyberfb_get_var,
  812. .fb_set_var = cyberfb_set_var,
  813. .fb_get_cmap = cyberfb_get_cmap,
  814. .fb_set_cmap = gen_set_cmap,
  815. .fb_setcolreg = cyberfb_setcolreg,
  816. .fb_blank = cyberfb_blank,
  817. };
  818. int __init cyberfb_setup(char *options)
  819. {
  820. char *this_opt;
  821. DPRINTK("ENTER\n");
  822. fb_info.fontname[0] = '\0';
  823. if (!options || !*options) {
  824. DPRINTK("EXIT - no options\n");
  825. return 0;
  826. }
  827. while ((this_opt = strsep(&options, ",")) != NULL) {
  828. if (!*this_opt)
  829. continue;
  830. if (!strcmp(this_opt, "inverse")) {
  831. Cyberfb_inverse = 1;
  832. fb_invert_cmaps();
  833. } else if (!strncmp(this_opt, "font:", 5)) {
  834. strcpy(fb_info.fontname, this_opt+5);
  835. } else if (!strcmp (this_opt, "cyber8")) {
  836. cyberfb_default = cyberfb_predefined[CYBER8_DEFMODE].var;
  837. cyberfb_usermode = 1;
  838. } else if (!strcmp (this_opt, "cyber16")) {
  839. cyberfb_default = cyberfb_predefined[CYBER16_DEFMODE].var;
  840. cyberfb_usermode = 1;
  841. } else get_video_mode(this_opt);
  842. }
  843. DPRINTK("default mode: xres=%d, yres=%d, bpp=%d\n",
  844. cyberfb_default.xres,
  845. cyberfb_default.yres,
  846. cyberfb_default.bits_per_pixel);
  847. DPRINTK("EXIT\n");
  848. return 0;
  849. }
  850. /*
  851. * Initialization
  852. */
  853. int __init cyberfb_init(void)
  854. {
  855. unsigned long board_addr, board_size;
  856. struct cyberfb_par par;
  857. struct zorro_dev *z = NULL;
  858. DPRINTK("ENTER\n");
  859. while ((z = zorro_find_device(ZORRO_PROD_PHASE5_CYBERVISION64, z))) {
  860. board_addr = z->resource.start;
  861. board_size = z->resource.end-z->resource.start+1;
  862. CyberMem_phys = board_addr + 0x01400000;
  863. CyberRegs_phys = CyberMem_phys + 0x00c00000;
  864. if (!request_mem_region(CyberRegs_phys, 0x10000, "S3 Trio64"))
  865. continue;
  866. if (!request_mem_region(CyberMem_phys, 0x400000, "RAM")) {
  867. release_mem_region(CyberRegs_phys, 0x10000);
  868. continue;
  869. }
  870. DPRINTK("board_addr=%08lx\n", board_addr);
  871. DPRINTK("board_size=%08lx\n", board_size);
  872. CyberBase = ioremap(board_addr, board_size);
  873. CyberRegs = CyberBase + 0x02000000;
  874. CyberMem = CyberBase + 0x01400000;
  875. DPRINTK("CyberBase=%08lx CyberRegs=%08lx CyberMem=%08lx\n",
  876. CyberBase, (long unsigned int)CyberRegs, CyberMem);
  877. #ifdef CYBERFBDEBUG
  878. DPRINTK("Register state just after mapping memory\n");
  879. cv64_dump();
  880. #endif
  881. strcpy(fb_info.modename, cyberfb_name);
  882. fb_info.changevar = NULL;
  883. fb_info.fbops = &cyberfb_ops;
  884. fb_info.screen_base = (unsigned char *)CyberMem;
  885. fb_info.disp = &disp;
  886. fb_info.currcon = -1;
  887. fb_info.switch_con = &Cyberfb_switch;
  888. fb_info.updatevar = &Cyberfb_updatevar;
  889. Cyber_init();
  890. /* ++Andre: set cyberfb default mode */
  891. if (!cyberfb_usermode) {
  892. cyberfb_default = cyberfb_predefined[CYBER8_DEFMODE].var;
  893. DPRINTK("Use default cyber8 mode\n");
  894. }
  895. Cyber_decode_var(&cyberfb_default, &par);
  896. Cyber_encode_var(&cyberfb_default, &par);
  897. do_fb_set_var(&cyberfb_default, 1);
  898. cyberfb_get_var(&fb_display[0].var, -1, &fb_info);
  899. cyberfb_set_disp(-1, &fb_info);
  900. do_install_cmap(0, &fb_info);
  901. if (register_framebuffer(&fb_info) < 0) {
  902. DPRINTK("EXIT - register_framebuffer failed\n");
  903. if (CyberBase)
  904. iounmap(CyberBase);
  905. release_mem_region(CyberMem_phys, 0x400000);
  906. release_mem_region(CyberRegs_phys, 0x10000);
  907. return -EINVAL;
  908. }
  909. printk("fb%d: %s frame buffer device, using %ldK of video memory\n",
  910. fb_info.node, fb_info.modename, CyberSize>>10);
  911. /* TODO: This driver cannot be unloaded yet */
  912. DPRINTK("EXIT\n");
  913. return 0;
  914. }
  915. return -ENXIO;
  916. }
  917. static int Cyberfb_switch(int con, struct fb_info *info)
  918. {
  919. DPRINTK("ENTER\n");
  920. /* Do we have to save the colormap? */
  921. if (fb_display[info->currcon].cmap.len) {
  922. fb_get_cmap(&fb_display[info->currcon].cmap, 1, Cyber_getcolreg,
  923. info);
  924. }
  925. do_fb_set_var(&fb_display[con].var, 1);
  926. info->currcon = con;
  927. /* Install new colormap */
  928. do_install_cmap(con, info);
  929. DPRINTK("EXIT\n");
  930. return(0);
  931. }
  932. /*
  933. * Update the `var' structure (called by fbcon.c)
  934. *
  935. * This call looks only at yoffset and the FB_VMODE_YWRAP flag in `var'.
  936. * Since it's called by a kernel driver, no range checking is done.
  937. */
  938. static int Cyberfb_updatevar(int con, struct fb_info *info)
  939. {
  940. DPRINTK("Enter - Exit\n");
  941. return(0);
  942. }
  943. /*
  944. * Get a Video Mode
  945. */
  946. static int __init get_video_mode(const char *name)
  947. {
  948. int i;
  949. DPRINTK("ENTER\n");
  950. for (i = 0; i < NUM_TOTAL_MODES; i++) {
  951. if (!strcmp(name, cyberfb_predefined[i].name)) {
  952. cyberfb_default = cyberfb_predefined[i].var;
  953. cyberfb_usermode = 1;
  954. DPRINTK("EXIT - Matched predefined mode\n");
  955. return(i);
  956. }
  957. }
  958. return(0);
  959. }
  960. /*
  961. * Text console acceleration
  962. */
  963. #ifdef FBCON_HAS_CFB8
  964. static void fbcon_cyber8_bmove(struct display *p, int sy, int sx, int dy,
  965. int dx, int height, int width)
  966. {
  967. DPRINTK("ENTER\n");
  968. sx *= 8; dx *= 8; width *= 8;
  969. Cyber_BitBLT((u_short)sx, (u_short)(sy*fontheight(p)), (u_short)dx,
  970. (u_short)(dy*fontheight(p)), (u_short)width,
  971. (u_short)(height*fontheight(p)), (u_short)S3_NEW);
  972. DPRINTK("EXIT\n");
  973. }
  974. static void fbcon_cyber8_clear(struct vc_data *conp, struct display *p, int sy,
  975. int sx, int height, int width)
  976. {
  977. unsigned char bg;
  978. DPRINTK("ENTER\n");
  979. sx *= 8; width *= 8;
  980. bg = attr_bgcol_ec(p,conp);
  981. Cyber_RectFill((u_short)sx,
  982. (u_short)(sy*fontheight(p)),
  983. (u_short)width,
  984. (u_short)(height*fontheight(p)),
  985. (u_short)S3_NEW,
  986. (u_short)bg);
  987. DPRINTK("EXIT\n");
  988. }
  989. static void fbcon_cyber8_putc(struct vc_data *conp, struct display *p, int c,
  990. int yy, int xx)
  991. {
  992. DPRINTK("ENTER\n");
  993. Cyber_WaitBlit();
  994. fbcon_cfb8_putc(conp, p, c, yy, xx);
  995. DPRINTK("EXIT\n");
  996. }
  997. static void fbcon_cyber8_putcs(struct vc_data *conp, struct display *p,
  998. const unsigned short *s, int count,
  999. int yy, int xx)
  1000. {
  1001. DPRINTK("ENTER\n");
  1002. Cyber_WaitBlit();
  1003. fbcon_cfb8_putcs(conp, p, s, count, yy, xx);
  1004. DPRINTK("EXIT\n");
  1005. }
  1006. static void fbcon_cyber8_revc(struct display *p, int xx, int yy)
  1007. {
  1008. DPRINTK("ENTER\n");
  1009. Cyber_WaitBlit();
  1010. fbcon_cfb8_revc(p, xx, yy);
  1011. DPRINTK("EXIT\n");
  1012. }
  1013. static struct display_switch fbcon_cyber8 = {
  1014. .setup = fbcon_cfb8_setup,
  1015. .bmove = fbcon_cyber8_bmove,
  1016. .clear = fbcon_cyber8_clear,
  1017. .putc = fbcon_cyber8_putc,
  1018. .putcs = fbcon_cyber8_putcs,
  1019. .revc = fbcon_cyber8_revc,
  1020. .clear_margins =fbcon_cfb8_clear_margins,
  1021. .fontwidthmask =FONTWIDTH(8)
  1022. };
  1023. #endif
  1024. #ifdef MODULE
  1025. MODULE_LICENSE("GPL");
  1026. int init_module(void)
  1027. {
  1028. return cyberfb_init();
  1029. }
  1030. #endif /* MODULE */
  1031. /*
  1032. *
  1033. * Low level initialization routines for the CyberVision64 graphics card
  1034. *
  1035. * Most of the following code is from cvision_core.c
  1036. *
  1037. */
  1038. #define MAXPIXELCLOCK 135000000 /* safety */
  1039. #ifdef CV_AGGRESSIVE_TIMING
  1040. long cv64_memclk = 55000000;
  1041. #else
  1042. long cv64_memclk = 50000000;
  1043. #endif
  1044. /*********************/
  1045. static unsigned char clocks[]={
  1046. 0x13, 0x61, 0x6b, 0x6d, 0x51, 0x69, 0x54, 0x69,
  1047. 0x4f, 0x68, 0x6b, 0x6b, 0x18, 0x61, 0x7b, 0x6c,
  1048. 0x51, 0x67, 0x24, 0x62, 0x56, 0x67, 0x77, 0x6a,
  1049. 0x1d, 0x61, 0x53, 0x66, 0x6b, 0x68, 0x79, 0x69,
  1050. 0x7c, 0x69, 0x7f, 0x69, 0x22, 0x61, 0x54, 0x65,
  1051. 0x56, 0x65, 0x58, 0x65, 0x67, 0x66, 0x41, 0x63,
  1052. 0x27, 0x61, 0x13, 0x41, 0x37, 0x62, 0x6b, 0x4d,
  1053. 0x23, 0x43, 0x51, 0x49, 0x79, 0x66, 0x54, 0x49,
  1054. 0x7d, 0x66, 0x34, 0x56, 0x4f, 0x63, 0x1f, 0x42,
  1055. 0x6b, 0x4b, 0x7e, 0x4d, 0x18, 0x41, 0x2a, 0x43,
  1056. 0x7b, 0x4c, 0x74, 0x4b, 0x51, 0x47, 0x65, 0x49,
  1057. 0x24, 0x42, 0x68, 0x49, 0x56, 0x47, 0x75, 0x4a,
  1058. 0x77, 0x4a, 0x31, 0x43, 0x1d, 0x41, 0x71, 0x49,
  1059. 0x53, 0x46, 0x29, 0x42, 0x6b, 0x48, 0x1f, 0x41,
  1060. 0x79, 0x49, 0x6f, 0x48, 0x7c, 0x49, 0x38, 0x43,
  1061. 0x7f, 0x49, 0x5d, 0x46, 0x22, 0x41, 0x53, 0x45,
  1062. 0x54, 0x45, 0x55, 0x45, 0x56, 0x45, 0x57, 0x45,
  1063. 0x58, 0x45, 0x25, 0x41, 0x67, 0x46, 0x5b, 0x45,
  1064. 0x41, 0x43, 0x78, 0x47, 0x27, 0x41, 0x51, 0x44,
  1065. 0x13, 0x21, 0x7d, 0x47, 0x37, 0x42, 0x71, 0x46,
  1066. 0x6b, 0x2d, 0x14, 0x21, 0x23, 0x23, 0x7d, 0x2f,
  1067. 0x51, 0x29, 0x61, 0x2b, 0x79, 0x46, 0x1d, 0x22,
  1068. 0x54, 0x29, 0x45, 0x27, 0x7d, 0x46, 0x7f, 0x46,
  1069. 0x4f, 0x43, 0x2f, 0x41, 0x1f, 0x22, 0x6a, 0x2b,
  1070. 0x6b, 0x2b, 0x5b, 0x29, 0x7e, 0x2d, 0x65, 0x44,
  1071. 0x18, 0x21, 0x5e, 0x29, 0x2a, 0x23, 0x45, 0x26,
  1072. 0x7b, 0x2c, 0x19, 0x21, 0x74, 0x2b, 0x75, 0x2b,
  1073. 0x51, 0x27, 0x3f, 0x25, 0x65, 0x29, 0x40, 0x25,
  1074. 0x24, 0x22, 0x41, 0x25, 0x68, 0x29, 0x42, 0x25,
  1075. 0x56, 0x27, 0x7e, 0x2b, 0x75, 0x2a, 0x1c, 0x21,
  1076. 0x77, 0x2a, 0x4f, 0x26, 0x31, 0x23, 0x6f, 0x29,
  1077. 0x1d, 0x21, 0x32, 0x23, 0x71, 0x29, 0x72, 0x29,
  1078. 0x53, 0x26, 0x69, 0x28, 0x29, 0x22, 0x75, 0x29,
  1079. 0x6b, 0x28, 0x1f, 0x21, 0x1f, 0x21, 0x6d, 0x28,
  1080. 0x79, 0x29, 0x2b, 0x22, 0x6f, 0x28, 0x59, 0x26,
  1081. 0x7c, 0x29, 0x7d, 0x29, 0x38, 0x23, 0x21, 0x21,
  1082. 0x7f, 0x29, 0x39, 0x23, 0x5d, 0x26, 0x75, 0x28,
  1083. 0x22, 0x21, 0x77, 0x28, 0x53, 0x25, 0x6c, 0x27,
  1084. 0x54, 0x25, 0x61, 0x26, 0x55, 0x25, 0x30, 0x22,
  1085. 0x56, 0x25, 0x63, 0x26, 0x57, 0x25, 0x71, 0x27,
  1086. 0x58, 0x25, 0x7f, 0x28, 0x25, 0x21, 0x74, 0x27,
  1087. 0x67, 0x26, 0x40, 0x23, 0x5b, 0x25, 0x26, 0x21,
  1088. 0x41, 0x23, 0x34, 0x22, 0x78, 0x27, 0x6b, 0x26,
  1089. 0x27, 0x21, 0x35, 0x22, 0x51, 0x24, 0x7b, 0x27,
  1090. 0x13, 0x1, 0x13, 0x1, 0x7d, 0x27, 0x4c, 0x9,
  1091. 0x37, 0x22, 0x5b, 0xb, 0x71, 0x26, 0x5c, 0xb,
  1092. 0x6b, 0xd, 0x47, 0x23, 0x14, 0x1, 0x4f, 0x9,
  1093. 0x23, 0x3, 0x75, 0x26, 0x7d, 0xf, 0x1c, 0x2,
  1094. 0x51, 0x9, 0x59, 0x24, 0x61, 0xb, 0x69, 0x25,
  1095. 0x79, 0x26, 0x34, 0x5, 0x1d, 0x2, 0x6b, 0x25,
  1096. 0x54, 0x9, 0x35, 0x5, 0x45, 0x7, 0x6d, 0x25,
  1097. 0x7d, 0x26, 0x16, 0x1, 0x7f, 0x26, 0x77, 0xd,
  1098. 0x4f, 0x23, 0x78, 0xd, 0x2f, 0x21, 0x27, 0x3,
  1099. 0x1f, 0x2, 0x59, 0x9, 0x6a, 0xb, 0x73, 0x25,
  1100. 0x6b, 0xb, 0x63, 0x24, 0x5b, 0x9, 0x20, 0x2,
  1101. 0x7e, 0xd, 0x4b, 0x7, 0x65, 0x24, 0x43, 0x22,
  1102. 0x18, 0x1, 0x6f, 0xb, 0x5e, 0x9, 0x70, 0xb,
  1103. 0x2a, 0x3, 0x33, 0x4, 0x45, 0x6, 0x60, 0x9,
  1104. 0x7b, 0xc, 0x19, 0x1, 0x19, 0x1, 0x7d, 0xc,
  1105. 0x74, 0xb, 0x50, 0x7, 0x75, 0xb, 0x63, 0x9,
  1106. 0x51, 0x7, 0x23, 0x2, 0x3f, 0x5, 0x1a, 0x1,
  1107. 0x65, 0x9, 0x2d, 0x3, 0x40, 0x5, 0x0, 0x0,
  1108. };
  1109. /* Console colors */
  1110. unsigned char cvconscolors[16][3] = { /* background, foreground, hilite */
  1111. /* R G B */
  1112. {0x30, 0x30, 0x30},
  1113. {0x00, 0x00, 0x00},
  1114. {0x80, 0x00, 0x00},
  1115. {0x00, 0x80, 0x00},
  1116. {0x00, 0x00, 0x80},
  1117. {0x80, 0x80, 0x00},
  1118. {0x00, 0x80, 0x80},
  1119. {0x80, 0x00, 0x80},
  1120. {0xff, 0xff, 0xff},
  1121. {0x40, 0x40, 0x40},
  1122. {0xff, 0x00, 0x00},
  1123. {0x00, 0xff, 0x00},
  1124. {0x00, 0x00, 0xff},
  1125. {0xff, 0xff, 0x00},
  1126. {0x00, 0xff, 0xff},
  1127. {0x00, 0x00, 0xff}
  1128. };
  1129. /* -------------------- Hardware specific routines ------------------------- */
  1130. /* Read Attribute Controller Register=idx */
  1131. inline unsigned char RAttr (volatile unsigned char *regs, short idx)
  1132. {
  1133. wb_64 (regs, ACT_ADDRESS_W, idx);
  1134. mb();
  1135. udelay(100);
  1136. return (rb_64(regs, ACT_ADDRESS_R));
  1137. }
  1138. /* Read Sequencer Register=idx */
  1139. inline unsigned char RSeq (volatile unsigned char *regs, short idx)
  1140. {
  1141. wb_64 (regs, SEQ_ADDRESS, idx);
  1142. mb();
  1143. return (rb_64(regs, SEQ_ADDRESS_R));
  1144. }
  1145. /* Read CRT Controller Register=idx */
  1146. inline unsigned char RCrt (volatile unsigned char *regs, short idx)
  1147. {
  1148. wb_64 (regs, CRT_ADDRESS, idx);
  1149. mb();
  1150. return (rb_64(regs, CRT_ADDRESS_R));
  1151. }
  1152. /* Read Graphics Controller Register=idx */
  1153. inline unsigned char RGfx (volatile unsigned char *regs, short idx)
  1154. {
  1155. wb_64 (regs, GCT_ADDRESS, idx);
  1156. mb();
  1157. return (rb_64(regs, GCT_ADDRESS_R));
  1158. }
  1159. /*
  1160. * Special wakeup/passthrough registers on graphics boards
  1161. */
  1162. inline void cv64_write_port (unsigned short bits,
  1163. volatile unsigned char *base)
  1164. {
  1165. volatile unsigned char *addr;
  1166. static unsigned char cvportbits = 0; /* Mirror port bits here */
  1167. DPRINTK("ENTER\n");
  1168. addr = base + 0x40001;
  1169. if (bits & 0x8000) {
  1170. cvportbits |= bits & 0xff; /* Set bits */
  1171. DPRINTK("Set bits: %04x\n", bits);
  1172. } else {
  1173. bits = bits & 0xff;
  1174. bits = (~bits) & 0xff;
  1175. cvportbits &= bits; /* Clear bits */
  1176. DPRINTK("Clear bits: %04x\n", bits);
  1177. }
  1178. *addr = cvportbits;
  1179. DPRINTK("EXIT\n");
  1180. }
  1181. /*
  1182. * Monitor switch on CyberVision board
  1183. *
  1184. * toggle:
  1185. * 0 = CyberVision Signal
  1186. * 1 = Amiga Signal
  1187. * board = board addr
  1188. *
  1189. */
  1190. inline void cvscreen (int toggle, volatile unsigned char *board)
  1191. {
  1192. DPRINTK("ENTER\n");
  1193. if (toggle == 1) {
  1194. DPRINTK("Show Amiga video\n");
  1195. cv64_write_port (0x10, board);
  1196. } else {
  1197. DPRINTK("Show CyberVision video\n");
  1198. cv64_write_port (0x8010, board);
  1199. }
  1200. DPRINTK("EXIT\n");
  1201. }
  1202. /* Control screen display */
  1203. /* toggle: 0 = on, 1 = off */
  1204. /* board = registerbase */
  1205. inline void gfx_on_off(int toggle, volatile unsigned char *regs)
  1206. {
  1207. int r;
  1208. DPRINTK("ENTER\n");
  1209. toggle &= 0x1;
  1210. toggle = toggle << 5;
  1211. DPRINTK("Turn display %s\n", (toggle ? "off" : "on"));
  1212. r = (int) RSeq(regs, SEQ_ID_CLOCKING_MODE);
  1213. r &= 0xdf; /* Set bit 5 to 0 */
  1214. WSeq (regs, SEQ_ID_CLOCKING_MODE, r | toggle);
  1215. DPRINTK("EXIT\n");
  1216. }
  1217. /*
  1218. * Computes M, N, and R values from
  1219. * given input frequency. It uses a table of
  1220. * precomputed values, to keep CPU time low.
  1221. *
  1222. * The return value consist of:
  1223. * lower byte: Bits 4-0: N Divider Value
  1224. * Bits 5-6: R Value for e.g. SR10 or SR12
  1225. * higher byte: Bits 0-6: M divider value for e.g. SR11 or SR13
  1226. */
  1227. static unsigned short cv64_compute_clock(unsigned long freq)
  1228. {
  1229. static unsigned char *mnr, *save; /* M, N + R vals */
  1230. unsigned long work_freq, r;
  1231. unsigned short erg;
  1232. long diff, d2;
  1233. DPRINTK("ENTER\n");
  1234. if (freq < 12500000 || freq > MAXPIXELCLOCK) {
  1235. printk("CV64 driver: Illegal clock frequency %ld, using 25MHz\n",
  1236. freq);
  1237. freq = 25000000;
  1238. }
  1239. DPRINTK("Freq = %ld\n", freq);
  1240. mnr = clocks; /* there the vals are stored */
  1241. d2 = 0x7fffffff;
  1242. while (*mnr) { /* mnr vals are 0-terminated */
  1243. work_freq = (0x37EE * (mnr[0] + 2)) / ((mnr[1] & 0x1F) + 2);
  1244. r = (mnr[1] >> 5) & 0x03;
  1245. if (r != 0) {
  1246. work_freq = work_freq >> r; /* r is the freq divider */
  1247. }
  1248. work_freq *= 0x3E8; /* 2nd part of OSC */
  1249. diff = abs(freq - work_freq);
  1250. if (d2 >= diff) {
  1251. d2 = diff;
  1252. /* In save are the vals for minimal diff */
  1253. save = mnr;
  1254. }
  1255. mnr += 2;
  1256. }
  1257. erg = *((unsigned short *)save);
  1258. DPRINTK("EXIT\n");
  1259. return (erg);
  1260. }
  1261. static int cv_has_4mb (volatile unsigned char *fb)
  1262. {
  1263. volatile unsigned long *tr, *tw;
  1264. DPRINTK("ENTER\n");
  1265. /* write patterns in memory and test if they can be read */
  1266. tw = (volatile unsigned long *) fb;
  1267. tr = (volatile unsigned long *) (fb + 0x02000000);
  1268. *tw = 0x87654321;
  1269. if (*tr != 0x87654321) {
  1270. DPRINTK("EXIT - <4MB\n");
  1271. return (0);
  1272. }
  1273. /* upper memory region */
  1274. tw = (volatile unsigned long *) (fb + 0x00200000);
  1275. tr = (volatile unsigned long *) (fb + 0x02200000);
  1276. *tw = 0x87654321;
  1277. if (*tr != 0x87654321) {
  1278. DPRINTK("EXIT - <4MB\n");
  1279. return (0);
  1280. }
  1281. *tw = 0xAAAAAAAA;
  1282. if (*tr != 0xAAAAAAAA) {
  1283. DPRINTK("EXIT - <4MB\n");
  1284. return (0);
  1285. }
  1286. *tw = 0x55555555;
  1287. if (*tr != 0x55555555) {
  1288. DPRINTK("EXIT - <4MB\n");
  1289. return (0);
  1290. }
  1291. DPRINTK("EXIT\n");
  1292. return (1);
  1293. }
  1294. static void cv64_board_init (void)
  1295. {
  1296. volatile unsigned char *regs = CyberRegs;
  1297. int i;
  1298. unsigned int clockpar;
  1299. unsigned char test;
  1300. DPRINTK("ENTER\n");
  1301. /*
  1302. * Special CyberVision 64 board operations
  1303. */
  1304. /* Reset board */
  1305. for (i = 0; i < 6; i++) {
  1306. cv64_write_port (0xff, CyberBase);
  1307. }
  1308. /* Return to operational mode */
  1309. cv64_write_port (0x8004, CyberBase);
  1310. /*
  1311. * Generic (?) S3 chip wakeup
  1312. */
  1313. /* Disable I/O & memory decoders, video in setup mode */
  1314. wb_64 (regs, SREG_VIDEO_SUBS_ENABLE, 0x10);
  1315. /* Video responds to cmds, addrs & data */
  1316. wb_64 (regs, SREG_OPTION_SELECT, 0x1);
  1317. /* Enable I/O & memory decoders, video in operational mode */
  1318. wb_64 (regs, SREG_VIDEO_SUBS_ENABLE, 0x8);
  1319. /* VGA color emulation, enable cpu access to display mem */
  1320. wb_64 (regs, GREG_MISC_OUTPUT_W, 0x03);
  1321. /* Unlock S3 VGA regs */
  1322. WCrt (regs, CRT_ID_REGISTER_LOCK_1, 0x48);
  1323. /* Unlock system control & extension registers */
  1324. WCrt (regs, CRT_ID_REGISTER_LOCK_2, 0xA5);
  1325. /* GRF - Enable interrupts */
  1326. /* Enable enhanced regs access, Ready cntl 0 wait states */
  1327. test = RCrt (regs, CRT_ID_SYSTEM_CONFIG);
  1328. test = test | 0x01; /* enable enhanced register access */
  1329. test = test & 0xEF; /* clear bit 4, 0 wait state */
  1330. WCrt (regs, CRT_ID_SYSTEM_CONFIG, test);
  1331. /*
  1332. * bit 0=1: Enable enhaced mode functions
  1333. * bit 2=0: Enhanced mode 8+ bits/pixel
  1334. * bit 4=1: Enable linear addressing
  1335. * bit 5=1: Enable MMIO
  1336. */
  1337. wb_64 (regs, ECR_ADV_FUNC_CNTL, 0x31);
  1338. /*
  1339. * bit 0=1: Color emulation
  1340. * bit 1=1: Enable CPU access to display memory
  1341. * bit 5=1: Select high 64K memory page
  1342. */
  1343. /* GRF - 0xE3 */
  1344. wb_64 (regs, GREG_MISC_OUTPUT_W, 0x23);
  1345. /* Cpu base addr */
  1346. WCrt (regs, CRT_ID_EXT_SYS_CNTL_4, 0x0);
  1347. /* Reset. This does nothing on Trio, but standard VGA practice */
  1348. /* WSeq (CyberRegs, SEQ_ID_RESET, 0x03); */
  1349. /* Character clocks 8 dots wide */
  1350. WSeq (regs, SEQ_ID_CLOCKING_MODE, 0x01);
  1351. /* Enable cpu write to all color planes */
  1352. WSeq (regs, SEQ_ID_MAP_MASK, 0x0F);
  1353. /* Font table in 1st 8k of plane 2, font A=B disables swtich */
  1354. WSeq (regs, SEQ_ID_CHAR_MAP_SELECT, 0x0);
  1355. /* Allow mem access to 256kb */
  1356. WSeq (regs, SEQ_ID_MEMORY_MODE, 0x2);
  1357. /* Unlock S3 extensions to VGA Sequencer regs */
  1358. WSeq (regs, SEQ_ID_UNLOCK_EXT, 0x6);
  1359. /* Enable 4MB fast page mode */
  1360. test = RSeq (regs, SEQ_ID_BUS_REQ_CNTL);
  1361. test = test | 1 << 6;
  1362. WSeq (regs, SEQ_ID_BUS_REQ_CNTL, test);
  1363. /* Faster LUT write: 1 DCLK LUT write cycle, RAMDAC clk doubled */
  1364. WSeq (regs, SEQ_ID_RAMDAC_CNTL, 0xC0);
  1365. /* Clear immediate clock load bit */
  1366. test = RSeq (regs, SEQ_ID_CLKSYN_CNTL_2);
  1367. test = test & 0xDF;
  1368. /* If > 55MHz, enable 2 cycle memory write */
  1369. if (cv64_memclk >= 55000000) {
  1370. test |= 0x80;
  1371. }
  1372. WSeq (regs, SEQ_ID_CLKSYN_CNTL_2, test);
  1373. /* Set MCLK value */
  1374. clockpar = cv64_compute_clock (cv64_memclk);
  1375. test = (clockpar & 0xFF00) >> 8;
  1376. WSeq (regs, SEQ_ID_MCLK_HI, test);
  1377. test = clockpar & 0xFF;
  1378. WSeq (regs, SEQ_ID_MCLK_LO, test);
  1379. /* Chip rev specific: Not in my Trio manual!!! */
  1380. if (RCrt (regs, CRT_ID_REVISION) == 0x10)
  1381. WSeq (regs, SEQ_ID_MORE_MAGIC, test);
  1382. /* We now load an 25 MHz, 31kHz, 640x480 standard VGA Mode. */
  1383. /* Set DCLK value */
  1384. WSeq (regs, SEQ_ID_DCLK_HI, 0x13);
  1385. WSeq (regs, SEQ_ID_DCLK_LO, 0x41);
  1386. /* Load DCLK (and MCLK?) immediately */
  1387. test = RSeq (regs, SEQ_ID_CLKSYN_CNTL_2);
  1388. test = test | 0x22;
  1389. WSeq (regs, SEQ_ID_CLKSYN_CNTL_2, test);
  1390. /* Enable loading of DCLK */
  1391. test = rb_64(regs, GREG_MISC_OUTPUT_R);
  1392. test = test | 0x0C;
  1393. wb_64 (regs, GREG_MISC_OUTPUT_W, test);
  1394. /* Turn off immediate xCLK load */
  1395. WSeq (regs, SEQ_ID_CLKSYN_CNTL_2, 0x2);
  1396. /* Horizontal character clock counts */
  1397. /* 8 LSB of 9 bits = total line - 5 */
  1398. WCrt (regs, CRT_ID_HOR_TOTAL, 0x5F);
  1399. /* Active display line */
  1400. WCrt (regs, CRT_ID_HOR_DISP_ENA_END, 0x4F);
  1401. /* Blank assertion start */
  1402. WCrt (regs, CRT_ID_START_HOR_BLANK, 0x50);
  1403. /* Blank assertion end */
  1404. WCrt (regs, CRT_ID_END_HOR_BLANK, 0x82);
  1405. /* HSYNC assertion start */
  1406. WCrt (regs, CRT_ID_START_HOR_RETR, 0x54);
  1407. /* HSYNC assertion end */
  1408. WCrt (regs, CRT_ID_END_HOR_RETR, 0x80);
  1409. WCrt (regs, CRT_ID_VER_TOTAL, 0xBF);
  1410. WCrt (regs, CRT_ID_OVERFLOW, 0x1F);
  1411. WCrt (regs, CRT_ID_PRESET_ROW_SCAN, 0x0);
  1412. WCrt (regs, CRT_ID_MAX_SCAN_LINE, 0x40);
  1413. WCrt (regs, CRT_ID_CURSOR_START, 0x00);
  1414. WCrt (regs, CRT_ID_CURSOR_END, 0x00);
  1415. WCrt (regs, CRT_ID_START_ADDR_HIGH, 0x00);
  1416. WCrt (regs, CRT_ID_START_ADDR_LOW, 0x00);
  1417. WCrt (regs, CRT_ID_CURSOR_LOC_HIGH, 0x00);
  1418. WCrt (regs, CRT_ID_CURSOR_LOC_LOW, 0x00);
  1419. WCrt (regs, CRT_ID_START_VER_RETR, 0x9C);
  1420. WCrt (regs, CRT_ID_END_VER_RETR, 0x0E);
  1421. WCrt (regs, CRT_ID_VER_DISP_ENA_END, 0x8F);
  1422. WCrt (regs, CRT_ID_SCREEN_OFFSET, 0x50);
  1423. WCrt (regs, CRT_ID_UNDERLINE_LOC, 0x00);
  1424. WCrt (regs, CRT_ID_START_VER_BLANK, 0x96);
  1425. WCrt (regs, CRT_ID_END_VER_BLANK, 0xB9);
  1426. WCrt (regs, CRT_ID_MODE_CONTROL, 0xE3);
  1427. WCrt (regs, CRT_ID_LINE_COMPARE, 0xFF);
  1428. WCrt (regs, CRT_ID_BACKWAD_COMP_3, 0x10); /* FIFO enabled */
  1429. WCrt (regs, CRT_ID_MISC_1, 0x35);
  1430. WCrt (regs, CRT_ID_DISPLAY_FIFO, 0x5A);
  1431. WCrt (regs, CRT_ID_EXT_MEM_CNTL_2, 0x70);
  1432. WCrt (regs, CRT_ID_LAW_POS_LO, 0x40);
  1433. WCrt (regs, CRT_ID_EXT_MEM_CNTL_3, 0xFF);
  1434. WGfx (regs, GCT_ID_SET_RESET, 0x0);
  1435. WGfx (regs, GCT_ID_ENABLE_SET_RESET, 0x0);
  1436. WGfx (regs, GCT_ID_COLOR_COMPARE, 0x0);
  1437. WGfx (regs, GCT_ID_DATA_ROTATE, 0x0);
  1438. WGfx (regs, GCT_ID_READ_MAP_SELECT, 0x0);
  1439. WGfx (regs, GCT_ID_GRAPHICS_MODE, 0x40);
  1440. WGfx (regs, GCT_ID_MISC, 0x01);
  1441. WGfx (regs, GCT_ID_COLOR_XCARE, 0x0F);
  1442. WGfx (regs, GCT_ID_BITMASK, 0xFF);
  1443. /* Colors for text mode */
  1444. for (i = 0; i < 0xf; i++)
  1445. WAttr (regs, i, i);
  1446. WAttr (regs, ACT_ID_ATTR_MODE_CNTL, 0x41);
  1447. WAttr (regs, ACT_ID_OVERSCAN_COLOR, 0x01);
  1448. WAttr (regs, ACT_ID_COLOR_PLANE_ENA, 0x0F);
  1449. WAttr (regs, ACT_ID_HOR_PEL_PANNING, 0x0);
  1450. WAttr (regs, ACT_ID_COLOR_SELECT, 0x0);
  1451. wb_64 (regs, VDAC_MASK, 0xFF);
  1452. *((unsigned long *) (regs + ECR_FRGD_COLOR)) = 0xFF;
  1453. *((unsigned long *) (regs + ECR_BKGD_COLOR)) = 0;
  1454. /* Colors initially set to grayscale */
  1455. wb_64 (regs, VDAC_ADDRESS_W, 0);
  1456. for (i = 255; i >= 0; i--) {
  1457. wb_64(regs, VDAC_DATA, i);
  1458. wb_64(regs, VDAC_DATA, i);
  1459. wb_64(regs, VDAC_DATA, i);
  1460. }
  1461. /* GFx hardware cursor off */
  1462. WCrt (regs, CRT_ID_HWGC_MODE, 0x00);
  1463. /* Set first to 4MB, so test will work */
  1464. WCrt (regs, CRT_ID_LAW_CNTL, 0x13);
  1465. /* Find "correct" size of fbmem of Z3 board */
  1466. if (cv_has_4mb (CyberMem)) {
  1467. CyberSize = 1024 * 1024 * 4;
  1468. WCrt (regs, CRT_ID_LAW_CNTL, 0x13);
  1469. DPRINTK("4MB board\n");
  1470. } else {
  1471. CyberSize = 1024 * 1024 * 2;
  1472. WCrt (regs, CRT_ID_LAW_CNTL, 0x12);
  1473. DPRINTK("2MB board\n");
  1474. }
  1475. /* Initialize graphics engine */
  1476. Cyber_WaitBlit();
  1477. vgaw16 (regs, ECR_FRGD_MIX, 0x27);
  1478. vgaw16 (regs, ECR_BKGD_MIX, 0x07);
  1479. vgaw16 (regs, ECR_READ_REG_DATA, 0x1000);
  1480. udelay(200);
  1481. vgaw16 (regs, ECR_READ_REG_DATA, 0x2000);
  1482. Cyber_WaitBlit();
  1483. vgaw16 (regs, ECR_READ_REG_DATA, 0x3FFF);
  1484. Cyber_WaitBlit();
  1485. udelay(200);
  1486. vgaw16 (regs, ECR_READ_REG_DATA, 0x4FFF);
  1487. Cyber_WaitBlit();
  1488. vgaw16 (regs, ECR_BITPLANE_WRITE_MASK, ~0);
  1489. Cyber_WaitBlit();
  1490. vgaw16 (regs, ECR_READ_REG_DATA, 0xE000);
  1491. vgaw16 (regs, ECR_CURRENT_Y_POS2, 0x00);
  1492. vgaw16 (regs, ECR_CURRENT_X_POS2, 0x00);
  1493. vgaw16 (regs, ECR_READ_REG_DATA, 0xA000);
  1494. vgaw16 (regs, ECR_DEST_Y__AX_STEP, 0x00);
  1495. vgaw16 (regs, ECR_DEST_Y2__AX_STEP2, 0x00);
  1496. vgaw16 (regs, ECR_DEST_X__DIA_STEP, 0x00);
  1497. vgaw16 (regs, ECR_DEST_X2__DIA_STEP2, 0x00);
  1498. vgaw16 (regs, ECR_SHORT_STROKE, 0x00);
  1499. vgaw16 (regs, ECR_DRAW_CMD, 0x01);
  1500. Cyber_WaitBlit();
  1501. vgaw16 (regs, ECR_READ_REG_DATA, 0x4FFF);
  1502. vgaw16 (regs, ECR_BKGD_COLOR, 0x01);
  1503. vgaw16 (regs, ECR_FRGD_COLOR, 0x00);
  1504. /* Enable video display (set bit 5) */
  1505. /* ARB - Would also seem to write to AR13.
  1506. * May want to use parts of WAttr to set JUST bit 5
  1507. */
  1508. WAttr (regs, 0x33, 0);
  1509. /* GRF - function code ended here */
  1510. /* Turn gfx on again */
  1511. gfx_on_off (0, regs);
  1512. /* Pass-through */
  1513. cvscreen (0, CyberBase);
  1514. DPRINTK("EXIT\n");
  1515. }
  1516. static void cv64_load_video_mode (struct fb_var_screeninfo *video_mode)
  1517. {
  1518. volatile unsigned char *regs = CyberRegs;
  1519. int fx, fy;
  1520. unsigned short mnr;
  1521. unsigned short HT, HDE, HBS, HBE, HSS, HSE, VDE, VBS, VBE, VSS, VSE, VT;
  1522. char LACE, DBLSCAN, TEXT, CONSOLE;
  1523. int cr50, sr15, sr18, clock_mode, test;
  1524. int m, n;
  1525. int tfillm, temptym;
  1526. int hmul;
  1527. /* ---------------- */
  1528. int xres, hfront, hsync, hback;
  1529. int yres, vfront, vsync, vback;
  1530. int bpp;
  1531. #if 0
  1532. float freq_f;
  1533. #endif
  1534. long freq;
  1535. /* ---------------- */
  1536. DPRINTK("ENTER\n");
  1537. TEXT = 0; /* if depth == 4 */
  1538. CONSOLE = 0; /* mode num == 255 (console) */
  1539. fx = fy = 8; /* force 8x8 font */
  1540. /* GRF - Disable interrupts */
  1541. gfx_on_off (1, regs);
  1542. switch (video_mode->bits_per_pixel) {
  1543. case 15:
  1544. case 16:
  1545. hmul = 2;
  1546. break;
  1547. default:
  1548. hmul = 1;
  1549. break;
  1550. }
  1551. bpp = video_mode->bits_per_pixel;
  1552. xres = video_mode->xres;
  1553. hfront = video_mode->right_margin;
  1554. hsync = video_mode->hsync_len;
  1555. hback = video_mode->left_margin;
  1556. LACE = 0;
  1557. DBLSCAN = 0;
  1558. if (video_mode->vmode & FB_VMODE_DOUBLE) {
  1559. yres = video_mode->yres * 2;
  1560. vfront = video_mode->lower_margin * 2;
  1561. vsync = video_mode->vsync_len * 2;
  1562. vback = video_mode->upper_margin * 2;
  1563. DBLSCAN = 1;
  1564. } else if (video_mode->vmode & FB_VMODE_INTERLACED) {
  1565. yres = (video_mode->yres + 1) / 2;
  1566. vfront = (video_mode->lower_margin + 1) / 2;
  1567. vsync = (video_mode->vsync_len + 1) / 2;
  1568. vback = (video_mode->upper_margin + 1) / 2;
  1569. LACE = 1;
  1570. } else {
  1571. yres = video_mode->yres;
  1572. vfront = video_mode->lower_margin;
  1573. vsync = video_mode->vsync_len;
  1574. vback = video_mode->upper_margin;
  1575. }
  1576. /* ARB Dropping custom setup method from cvision.c */
  1577. #if 0
  1578. if (cvision_custom_mode) {
  1579. HBS = hbs / 8 * hmul;
  1580. HBE = hbe / 8 * hmul;
  1581. HSS = hss / 8 * hmul;
  1582. HSE = hse / 8 * hmul;
  1583. HT = ht / 8 * hmul - 5;
  1584. VBS = vbs - 1;
  1585. VSS = vss;
  1586. VSE = vse;
  1587. VBE = vbe;
  1588. VT = vt - 2;
  1589. } else {
  1590. #else
  1591. {
  1592. #endif
  1593. HBS = hmul * (xres / 8);
  1594. HBE = hmul * ((xres/8) + (hfront/8) + (hsync/8) + (hback/8) - 2);
  1595. HSS = hmul * ((xres/8) + (hfront/8) + 2);
  1596. HSE = hmul * ((xres/8) + (hfront/8) + (hsync/8) + 1);
  1597. HT = hmul * ((xres/8) + (hfront/8) + (hsync/8) + (hback/8));
  1598. VBS = yres;
  1599. VBE = yres + vfront + vsync + vback - 2;
  1600. VSS = yres + vfront - 1;
  1601. VSE = yres + vfront + vsync - 1;
  1602. VT = yres + vfront + vsync + vback - 2;
  1603. }
  1604. wb_64 (regs, ECR_ADV_FUNC_CNTL, (TEXT ? 0x00 : 0x31));
  1605. if (TEXT)
  1606. HDE = ((video_mode->xres + fx - 1) / fx) - 1;
  1607. else
  1608. HDE = (video_mode->xres + 3) * hmul / 8 - 1;
  1609. VDE = video_mode->yres - 1;
  1610. WCrt (regs, CRT_ID_HWGC_MODE, 0x00);
  1611. WCrt (regs, CRT_ID_EXT_DAC_CNTL, 0x00);
  1612. WSeq (regs, SEQ_ID_MEMORY_MODE,
  1613. (TEXT || (video_mode->bits_per_pixel == 1)) ? 0x06 : 0x0e);
  1614. WGfx (regs, GCT_ID_READ_MAP_SELECT, 0x00);
  1615. WSeq (regs, SEQ_ID_MAP_MASK,
  1616. (video_mode->bits_per_pixel == 1) ? 0x01 : 0xFF);
  1617. WSeq (regs, SEQ_ID_CHAR_MAP_SELECT, 0x00);
  1618. /* cv64_compute_clock accepts arguments in Hz */
  1619. /* pixclock is in ps ... convert to Hz */
  1620. #if 0
  1621. freq_f = (1.0 / (float) video_mode->pixclock) * 1000000000;
  1622. freq = ((long) freq_f) * 1000;
  1623. #else
  1624. /* freq = (long) ((long long)1000000000000 / (long long) video_mode->pixclock);
  1625. */
  1626. freq = (1000000000 / video_mode->pixclock) * 1000;
  1627. #endif
  1628. mnr = cv64_compute_clock (freq);
  1629. WSeq (regs, SEQ_ID_DCLK_HI, ((mnr & 0xFF00) >> 8));
  1630. WSeq (regs, SEQ_ID_DCLK_LO, (mnr & 0xFF));
  1631. /* Load display parameters into board */
  1632. WCrt (regs, CRT_ID_EXT_HOR_OVF,
  1633. ((HT & 0x100) ? 0x01 : 0x00) |
  1634. ((HDE & 0x100) ? 0x02 : 0x00) |
  1635. ((HBS & 0x100) ? 0x04 : 0x00) |
  1636. /* ((HBE & 0x40) ? 0x08 : 0x00) | */
  1637. ((HSS & 0x100) ? 0x10 : 0x00) |
  1638. /* ((HSE & 0x20) ? 0x20 : 0x00) | */
  1639. (((HT-5) & 0x100) ? 0x40 : 0x00)
  1640. );
  1641. WCrt (regs, CRT_ID_EXT_VER_OVF,
  1642. 0x40 |
  1643. ((VT & 0x400) ? 0x01 : 0x00) |
  1644. ((VDE & 0x400) ? 0x02 : 0x00) |
  1645. ((VBS & 0x400) ? 0x04 : 0x00) |
  1646. ((VSS & 0x400) ? 0x10 : 0x00)
  1647. );
  1648. WCrt (regs, CRT_ID_HOR_TOTAL, HT);
  1649. WCrt (regs, CRT_ID_DISPLAY_FIFO, HT - 5);
  1650. WCrt (regs, CRT_ID_HOR_DISP_ENA_END, ((HDE >= HBS) ? (HBS - 1) : HDE));
  1651. WCrt (regs, CRT_ID_START_HOR_BLANK, HBS);
  1652. WCrt (regs, CRT_ID_END_HOR_BLANK, ((HBE & 0x1F) | 0x80));
  1653. WCrt (regs, CRT_ID_START_HOR_RETR, HSS);
  1654. WCrt (regs, CRT_ID_END_HOR_RETR,
  1655. (HSE & 0x1F) |
  1656. ((HBE & 0x20) ? 0x80 : 0x00)
  1657. );
  1658. WCrt (regs, CRT_ID_VER_TOTAL, VT);
  1659. WCrt (regs, CRT_ID_OVERFLOW,
  1660. 0x10 |
  1661. ((VT & 0x100) ? 0x01 : 0x00) |
  1662. ((VDE & 0x100) ? 0x02 : 0x00) |
  1663. ((VSS & 0x100) ? 0x04 : 0x00) |
  1664. ((VBS & 0x100) ? 0x08 : 0x00) |
  1665. ((VT & 0x200) ? 0x20 : 0x00) |
  1666. ((VDE & 0x200) ? 0x40 : 0x00) |
  1667. ((VSS & 0x200) ? 0x80 : 0x00)
  1668. );
  1669. WCrt (regs, CRT_ID_MAX_SCAN_LINE,
  1670. 0x40 |
  1671. (DBLSCAN ? 0x80 : 0x00) |
  1672. ((VBS & 0x200) ? 0x20 : 0x00) |
  1673. (TEXT ? ((fy - 1) & 0x1F) : 0x00)
  1674. );
  1675. WCrt (regs, CRT_ID_MODE_CONTROL, 0xE3);
  1676. /* Text cursor */
  1677. if (TEXT) {
  1678. #if 1
  1679. WCrt (regs, CRT_ID_CURSOR_START, (fy & 0x1f) - 2);
  1680. WCrt (regs, CRT_ID_CURSOR_END, (fy & 0x1F) - 1);
  1681. #else
  1682. WCrt (regs, CRT_ID_CURSOR_START, 0x00);
  1683. WCrt (regs, CRT_ID_CURSOR_END, fy & 0x1F);
  1684. #endif
  1685. WCrt (regs, CRT_ID_UNDERLINE_LOC, (fy - 1) & 0x1F);
  1686. WCrt (regs, CRT_ID_CURSOR_LOC_HIGH, 0x00);
  1687. WCrt (regs, CRT_ID_CURSOR_LOC_LOW, 0x00);
  1688. }
  1689. WCrt (regs, CRT_ID_START_ADDR_HIGH, 0x00);
  1690. WCrt (regs, CRT_ID_START_ADDR_LOW, 0x00);
  1691. WCrt (regs, CRT_ID_START_VER_RETR, VSS);
  1692. WCrt (regs, CRT_ID_END_VER_RETR, (VSE & 0x0F));
  1693. WCrt (regs, CRT_ID_VER_DISP_ENA_END, VDE);
  1694. WCrt (regs, CRT_ID_START_VER_BLANK, VBS);
  1695. WCrt (regs, CRT_ID_END_VER_BLANK, VBE);
  1696. WCrt (regs, CRT_ID_LINE_COMPARE, 0xFF);
  1697. WCrt (regs, CRT_ID_LACE_RETR_START, HT / 2);
  1698. WCrt (regs, CRT_ID_LACE_CONTROL, (LACE ? 0x20 : 0x00));
  1699. WGfx (regs, GCT_ID_GRAPHICS_MODE,
  1700. ((TEXT || (video_mode->bits_per_pixel == 1)) ? 0x00 : 0x40));
  1701. WGfx (regs, GCT_ID_MISC, (TEXT ? 0x04 : 0x01));
  1702. WSeq (regs, SEQ_ID_MEMORY_MODE,
  1703. ((TEXT || (video_mode->bits_per_pixel == 1)) ? 0x06 : 0x02));
  1704. wb_64 (regs, VDAC_MASK, 0xFF);
  1705. /* Blank border */
  1706. test = RCrt (regs, CRT_ID_BACKWAD_COMP_2);
  1707. WCrt (regs, CRT_ID_BACKWAD_COMP_2, (test | 0x20));
  1708. sr15 = RSeq (regs, SEQ_ID_CLKSYN_CNTL_2);
  1709. sr15 &= 0xEF;
  1710. sr18 = RSeq (regs, SEQ_ID_RAMDAC_CNTL);
  1711. sr18 &= 0x7F;
  1712. clock_mode = 0x00;
  1713. cr50 = 0x00;
  1714. test = RCrt (regs, CRT_ID_EXT_MISC_CNTL_2);
  1715. test &= 0xD;
  1716. /* Clear roxxler byte-swapping... */
  1717. cv64_write_port (0x0040, CyberBase);
  1718. cv64_write_port (0x0020, CyberBase);
  1719. switch (video_mode->bits_per_pixel) {
  1720. case 1:
  1721. case 4: /* text */
  1722. HDE = video_mode->xres / 16;
  1723. break;
  1724. case 8:
  1725. if (freq > 80000000) {
  1726. clock_mode = 0x10 | 0x02;
  1727. sr15 |= 0x10;
  1728. sr18 |= 0x80;
  1729. }
  1730. HDE = video_mode->xres / 8;
  1731. cr50 |= 0x00;
  1732. break;
  1733. case 15:
  1734. cv64_write_port (0x8020, CyberBase);
  1735. clock_mode = 0x30;
  1736. HDE = video_mode->xres / 4;
  1737. cr50 |= 0x10;
  1738. break;
  1739. case 16:
  1740. cv64_write_port (0x8020, CyberBase);
  1741. clock_mode = 0x50;
  1742. HDE = video_mode->xres / 4;
  1743. cr50 |= 0x10;
  1744. break;
  1745. case 24:
  1746. case 32:
  1747. cv64_write_port (0x8040, CyberBase);
  1748. clock_mode = 0xD0;
  1749. HDE = video_mode->xres / 2;
  1750. cr50 |= 0x30;
  1751. break;
  1752. }
  1753. WCrt (regs, CRT_ID_EXT_MISC_CNTL_2, clock_mode | test);
  1754. WSeq (regs, SEQ_ID_CLKSYN_CNTL_2, sr15);
  1755. WSeq (regs, SEQ_ID_RAMDAC_CNTL, sr18);
  1756. WCrt (regs, CRT_ID_SCREEN_OFFSET, HDE);
  1757. WCrt (regs, CRT_ID_MISC_1, (TEXT ? 0x05 : 0x35));
  1758. test = RCrt (regs, CRT_ID_EXT_SYS_CNTL_2);
  1759. test &= ~0x30;
  1760. test |= (HDE >> 4) & 0x30;
  1761. WCrt (regs, CRT_ID_EXT_SYS_CNTL_2, test);
  1762. /* Set up graphics engine */
  1763. switch (video_mode->xres) {
  1764. case 1024:
  1765. cr50 |= 0x00;
  1766. break;
  1767. case 640:
  1768. cr50 |= 0x40;
  1769. break;
  1770. case 800:
  1771. cr50 |= 0x80;
  1772. break;
  1773. case 1280:
  1774. cr50 |= 0xC0;
  1775. break;
  1776. case 1152:
  1777. cr50 |= 0x01;
  1778. break;
  1779. case 1600:
  1780. cr50 |= 0x81;
  1781. break;
  1782. default: /* XXX */
  1783. break;
  1784. }
  1785. WCrt (regs, CRT_ID_EXT_SYS_CNTL_1, cr50);
  1786. udelay(100);
  1787. WAttr (regs, ACT_ID_ATTR_MODE_CNTL, (TEXT ? 0x08 : 0x41));
  1788. udelay(100);
  1789. WAttr (regs, ACT_ID_COLOR_PLANE_ENA,
  1790. (video_mode->bits_per_pixel == 1) ? 0x01 : 0x0F);
  1791. udelay(100);
  1792. tfillm = (96 * (cv64_memclk / 1000)) / 240000;
  1793. switch (video_mode->bits_per_pixel) {
  1794. case 32:
  1795. case 24:
  1796. temptym = (24 * (cv64_memclk / 1000)) / (freq / 1000);
  1797. break;
  1798. case 15:
  1799. case 16:
  1800. temptym = (48 * (cv64_memclk / 1000)) / (freq / 1000);
  1801. break;
  1802. case 4:
  1803. temptym = (192 * (cv64_memclk / 1000)) / (freq / 1000);
  1804. break;
  1805. default:
  1806. temptym = (96 * (cv64_memclk / 1000)) / (freq / 1000);
  1807. break;
  1808. }
  1809. m = (temptym - tfillm - 9) / 2;
  1810. if (m < 0)
  1811. m = 0;
  1812. m = (m & 0x1F) << 3;
  1813. if (m < 0x18)
  1814. m = 0x18;
  1815. n = 0xFF;
  1816. WCrt (regs, CRT_ID_EXT_MEM_CNTL_2, m);
  1817. WCrt (regs, CRT_ID_EXT_MEM_CNTL_3, n);
  1818. udelay(10);
  1819. /* Text initialization */
  1820. if (TEXT) {
  1821. /* Do text initialization here ! */
  1822. }
  1823. if (CONSOLE) {
  1824. int i;
  1825. wb_64 (regs, VDAC_ADDRESS_W, 0);
  1826. for (i = 0; i < 4; i++) {
  1827. wb_64 (regs, VDAC_DATA, cvconscolors [i][0]);
  1828. wb_64 (regs, VDAC_DATA, cvconscolors [i][1]);
  1829. wb_64 (regs, VDAC_DATA, cvconscolors [i][2]);
  1830. }
  1831. }
  1832. WAttr (regs, 0x33, 0);
  1833. /* Turn gfx on again */
  1834. gfx_on_off (0, (volatile unsigned char *) regs);
  1835. /* Pass-through */
  1836. cvscreen (0, CyberBase);
  1837. DPRINTK("EXIT\n");
  1838. }
  1839. void cvision_bitblt (u_short sx, u_short sy, u_short dx, u_short dy,
  1840. u_short w, u_short h)
  1841. {
  1842. volatile unsigned char *regs = CyberRegs;
  1843. unsigned short drawdir = 0;
  1844. DPRINTK("ENTER\n");
  1845. if (sx > dx) {
  1846. drawdir |= 1 << 5;
  1847. } else {
  1848. sx += w - 1;
  1849. dx += w - 1;
  1850. }
  1851. if (sy > dy) {
  1852. drawdir |= 1 << 7;
  1853. } else {
  1854. sy += h - 1;
  1855. dy += h - 1;
  1856. }
  1857. Cyber_WaitBlit();
  1858. vgaw16 (regs, ECR_READ_REG_DATA, 0xA000);
  1859. vgaw16 (regs, ECR_BKGD_MIX, 0x7);
  1860. vgaw16 (regs, ECR_FRGD_MIX, 0x67);
  1861. vgaw16 (regs, ECR_BKGD_COLOR, 0x0);
  1862. vgaw16 (regs, ECR_FRGD_COLOR, 0x1);
  1863. vgaw16 (regs, ECR_BITPLANE_READ_MASK, 0x1);
  1864. vgaw16 (regs, ECR_BITPLANE_WRITE_MASK, 0xFFF);
  1865. vgaw16 (regs, ECR_CURRENT_Y_POS, sy);
  1866. vgaw16 (regs, ECR_CURRENT_X_POS, sx);
  1867. vgaw16 (regs, ECR_DEST_Y__AX_STEP, dy);
  1868. vgaw16 (regs, ECR_DEST_X__DIA_STEP, dx);
  1869. vgaw16 (regs, ECR_READ_REG_DATA, h - 1);
  1870. vgaw16 (regs, ECR_MAJ_AXIS_PIX_CNT, w - 1);
  1871. vgaw16 (regs, ECR_DRAW_CMD, 0xC051 | drawdir);
  1872. DPRINTK("EXIT\n");
  1873. }
  1874. void cvision_clear (u_short dx, u_short dy, u_short w, u_short h, u_short bg)
  1875. {
  1876. volatile unsigned char *regs = CyberRegs;
  1877. DPRINTK("ENTER\n");
  1878. Cyber_WaitBlit();
  1879. vgaw16 (regs, ECR_FRGD_MIX, 0x0027);
  1880. vgaw16 (regs, ECR_FRGD_COLOR, bg);
  1881. vgaw16 (regs, ECR_READ_REG_DATA, 0xA000);
  1882. vgaw16 (regs, ECR_CURRENT_Y_POS, dy);
  1883. vgaw16 (regs, ECR_CURRENT_X_POS, dx);
  1884. vgaw16 (regs, ECR_READ_REG_DATA, h - 1);
  1885. vgaw16 (regs, ECR_MAJ_AXIS_PIX_CNT, w - 1);
  1886. vgaw16 (regs, ECR_DRAW_CMD, 0x40B1);
  1887. DPRINTK("EXIT\n");
  1888. }
  1889. #ifdef CYBERFBDEBUG
  1890. /*
  1891. * Dump internal settings of CyberVision board
  1892. */
  1893. static void cv64_dump (void)
  1894. {
  1895. volatile unsigned char *regs = CyberRegs;
  1896. DPRINTK("ENTER\n");
  1897. /* Dump the VGA setup values */
  1898. *(regs + S3_CRTC_ADR) = 0x00;
  1899. DPRINTK("CR00 = %x\n", *(regs + S3_CRTC_DATA));
  1900. *(regs + S3_CRTC_ADR) = 0x01;
  1901. DPRINTK("CR01 = %x\n", *(regs + S3_CRTC_DATA));
  1902. *(regs + S3_CRTC_ADR) = 0x02;
  1903. DPRINTK("CR02 = %x\n", *(regs + S3_CRTC_DATA));
  1904. *(regs + S3_CRTC_ADR) = 0x03;
  1905. DPRINTK("CR03 = %x\n", *(regs + S3_CRTC_DATA));
  1906. *(regs + S3_CRTC_ADR) = 0x04;
  1907. DPRINTK("CR04 = %x\n", *(regs + S3_CRTC_DATA));
  1908. *(regs + S3_CRTC_ADR) = 0x05;
  1909. DPRINTK("CR05 = %x\n", *(regs + S3_CRTC_DATA));
  1910. *(regs + S3_CRTC_ADR) = 0x06;
  1911. DPRINTK("CR06 = %x\n", *(regs + S3_CRTC_DATA));
  1912. *(regs + S3_CRTC_ADR) = 0x07;
  1913. DPRINTK("CR07 = %x\n", *(regs + S3_CRTC_DATA));
  1914. *(regs + S3_CRTC_ADR) = 0x08;
  1915. DPRINTK("CR08 = %x\n", *(regs + S3_CRTC_DATA));
  1916. *(regs + S3_CRTC_ADR) = 0x09;
  1917. DPRINTK("CR09 = %x\n", *(regs + S3_CRTC_DATA));
  1918. *(regs + S3_CRTC_ADR) = 0x10;
  1919. DPRINTK("CR10 = %x\n", *(regs + S3_CRTC_DATA));
  1920. *(regs + S3_CRTC_ADR) = 0x11;
  1921. DPRINTK("CR11 = %x\n", *(regs + S3_CRTC_DATA));
  1922. *(regs + S3_CRTC_ADR) = 0x12;
  1923. DPRINTK("CR12 = %x\n", *(regs + S3_CRTC_DATA));
  1924. *(regs + S3_CRTC_ADR) = 0x13;
  1925. DPRINTK("CR13 = %x\n", *(regs + S3_CRTC_DATA));
  1926. *(regs + S3_CRTC_ADR) = 0x15;
  1927. DPRINTK("CR15 = %x\n", *(regs + S3_CRTC_DATA));
  1928. *(regs + S3_CRTC_ADR) = 0x16;
  1929. DPRINTK("CR16 = %x\n", *(regs + S3_CRTC_DATA));
  1930. *(regs + S3_CRTC_ADR) = 0x36;
  1931. DPRINTK("CR36 = %x\n", *(regs + S3_CRTC_DATA));
  1932. *(regs + S3_CRTC_ADR) = 0x37;
  1933. DPRINTK("CR37 = %x\n", *(regs + S3_CRTC_DATA));
  1934. *(regs + S3_CRTC_ADR) = 0x42;
  1935. DPRINTK("CR42 = %x\n", *(regs + S3_CRTC_DATA));
  1936. *(regs + S3_CRTC_ADR) = 0x43;
  1937. DPRINTK("CR43 = %x\n", *(regs + S3_CRTC_DATA));
  1938. *(regs + S3_CRTC_ADR) = 0x50;
  1939. DPRINTK("CR50 = %x\n", *(regs + S3_CRTC_DATA));
  1940. *(regs + S3_CRTC_ADR) = 0x51;
  1941. DPRINTK("CR51 = %x\n", *(regs + S3_CRTC_DATA));
  1942. *(regs + S3_CRTC_ADR) = 0x53;
  1943. DPRINTK("CR53 = %x\n", *(regs + S3_CRTC_DATA));
  1944. *(regs + S3_CRTC_ADR) = 0x58;
  1945. DPRINTK("CR58 = %x\n", *(regs + S3_CRTC_DATA));
  1946. *(regs + S3_CRTC_ADR) = 0x59;
  1947. DPRINTK("CR59 = %x\n", *(regs + S3_CRTC_DATA));
  1948. *(regs + S3_CRTC_ADR) = 0x5A;
  1949. DPRINTK("CR5A = %x\n", *(regs + S3_CRTC_DATA));
  1950. *(regs + S3_CRTC_ADR) = 0x5D;
  1951. DPRINTK("CR5D = %x\n", *(regs + S3_CRTC_DATA));
  1952. *(regs + S3_CRTC_ADR) = 0x5E;
  1953. DPRINTK("CR5E = %x\n", *(regs + S3_CRTC_DATA));
  1954. DPRINTK("MISC = %x\n", *(regs + GREG_MISC_OUTPUT_R));
  1955. *(regs + SEQ_ADDRESS) = 0x01;
  1956. DPRINTK("SR01 = %x\n", *(regs + SEQ_ADDRESS_R));
  1957. *(regs + SEQ_ADDRESS) = 0x02;
  1958. DPRINTK("SR02 = %x\n", *(regs + SEQ_ADDRESS_R));
  1959. *(regs + SEQ_ADDRESS) = 0x03;
  1960. DPRINTK("SR03 = %x\n", *(regs + SEQ_ADDRESS_R));
  1961. *(regs + SEQ_ADDRESS) = 0x09;
  1962. DPRINTK("SR09 = %x\n", *(regs + SEQ_ADDRESS_R));
  1963. *(regs + SEQ_ADDRESS) = 0x10;
  1964. DPRINTK("SR10 = %x\n", *(regs + SEQ_ADDRESS_R));
  1965. *(regs + SEQ_ADDRESS) = 0x11;
  1966. DPRINTK("SR11 = %x\n", *(regs + SEQ_ADDRESS_R));
  1967. *(regs + SEQ_ADDRESS) = 0x12;
  1968. DPRINTK("SR12 = %x\n", *(regs + SEQ_ADDRESS_R));
  1969. *(regs + SEQ_ADDRESS) = 0x13;
  1970. DPRINTK("SR13 = %x\n", *(regs + SEQ_ADDRESS_R));
  1971. *(regs + SEQ_ADDRESS) = 0x15;
  1972. DPRINTK("SR15 = %x\n", *(regs + SEQ_ADDRESS_R));
  1973. return;
  1974. }
  1975. #endif