cyberfb.c 61 KB

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