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. #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. release_mem_region(CyberMem_phys, 0x400000);
  904. release_mem_region(CyberRegs_phys, 0x10000);
  905. return -EINVAL;
  906. }
  907. printk("fb%d: %s frame buffer device, using %ldK of video memory\n",
  908. fb_info.node, fb_info.modename, CyberSize>>10);
  909. /* TODO: This driver cannot be unloaded yet */
  910. DPRINTK("EXIT\n");
  911. return 0;
  912. }
  913. return -ENXIO;
  914. }
  915. static int Cyberfb_switch(int con, struct fb_info *info)
  916. {
  917. DPRINTK("ENTER\n");
  918. /* Do we have to save the colormap? */
  919. if (fb_display[info->currcon].cmap.len) {
  920. fb_get_cmap(&fb_display[info->currcon].cmap, 1, Cyber_getcolreg,
  921. info);
  922. }
  923. do_fb_set_var(&fb_display[con].var, 1);
  924. info->currcon = con;
  925. /* Install new colormap */
  926. do_install_cmap(con, info);
  927. DPRINTK("EXIT\n");
  928. return(0);
  929. }
  930. /*
  931. * Update the `var' structure (called by fbcon.c)
  932. *
  933. * This call looks only at yoffset and the FB_VMODE_YWRAP flag in `var'.
  934. * Since it's called by a kernel driver, no range checking is done.
  935. */
  936. static int Cyberfb_updatevar(int con, struct fb_info *info)
  937. {
  938. DPRINTK("Enter - Exit\n");
  939. return(0);
  940. }
  941. /*
  942. * Get a Video Mode
  943. */
  944. static int __init get_video_mode(const char *name)
  945. {
  946. int i;
  947. DPRINTK("ENTER\n");
  948. for (i = 0; i < NUM_TOTAL_MODES; i++) {
  949. if (!strcmp(name, cyberfb_predefined[i].name)) {
  950. cyberfb_default = cyberfb_predefined[i].var;
  951. cyberfb_usermode = 1;
  952. DPRINTK("EXIT - Matched predefined mode\n");
  953. return(i);
  954. }
  955. }
  956. return(0);
  957. }
  958. /*
  959. * Text console acceleration
  960. */
  961. #ifdef FBCON_HAS_CFB8
  962. static void fbcon_cyber8_bmove(struct display *p, int sy, int sx, int dy,
  963. int dx, int height, int width)
  964. {
  965. DPRINTK("ENTER\n");
  966. sx *= 8; dx *= 8; width *= 8;
  967. Cyber_BitBLT((u_short)sx, (u_short)(sy*fontheight(p)), (u_short)dx,
  968. (u_short)(dy*fontheight(p)), (u_short)width,
  969. (u_short)(height*fontheight(p)), (u_short)S3_NEW);
  970. DPRINTK("EXIT\n");
  971. }
  972. static void fbcon_cyber8_clear(struct vc_data *conp, struct display *p, int sy,
  973. int sx, int height, int width)
  974. {
  975. unsigned char bg;
  976. DPRINTK("ENTER\n");
  977. sx *= 8; width *= 8;
  978. bg = attr_bgcol_ec(p,conp);
  979. Cyber_RectFill((u_short)sx,
  980. (u_short)(sy*fontheight(p)),
  981. (u_short)width,
  982. (u_short)(height*fontheight(p)),
  983. (u_short)S3_NEW,
  984. (u_short)bg);
  985. DPRINTK("EXIT\n");
  986. }
  987. static void fbcon_cyber8_putc(struct vc_data *conp, struct display *p, int c,
  988. int yy, int xx)
  989. {
  990. DPRINTK("ENTER\n");
  991. Cyber_WaitBlit();
  992. fbcon_cfb8_putc(conp, p, c, yy, xx);
  993. DPRINTK("EXIT\n");
  994. }
  995. static void fbcon_cyber8_putcs(struct vc_data *conp, struct display *p,
  996. const unsigned short *s, int count,
  997. int yy, int xx)
  998. {
  999. DPRINTK("ENTER\n");
  1000. Cyber_WaitBlit();
  1001. fbcon_cfb8_putcs(conp, p, s, count, yy, xx);
  1002. DPRINTK("EXIT\n");
  1003. }
  1004. static void fbcon_cyber8_revc(struct display *p, int xx, int yy)
  1005. {
  1006. DPRINTK("ENTER\n");
  1007. Cyber_WaitBlit();
  1008. fbcon_cfb8_revc(p, xx, yy);
  1009. DPRINTK("EXIT\n");
  1010. }
  1011. static struct display_switch fbcon_cyber8 = {
  1012. .setup = fbcon_cfb8_setup,
  1013. .bmove = fbcon_cyber8_bmove,
  1014. .clear = fbcon_cyber8_clear,
  1015. .putc = fbcon_cyber8_putc,
  1016. .putcs = fbcon_cyber8_putcs,
  1017. .revc = fbcon_cyber8_revc,
  1018. .clear_margins =fbcon_cfb8_clear_margins,
  1019. .fontwidthmask =FONTWIDTH(8)
  1020. };
  1021. #endif
  1022. #ifdef MODULE
  1023. MODULE_LICENSE("GPL");
  1024. int init_module(void)
  1025. {
  1026. return cyberfb_init();
  1027. }
  1028. #endif /* MODULE */
  1029. /*
  1030. *
  1031. * Low level initialization routines for the CyberVision64 graphics card
  1032. *
  1033. * Most of the following code is from cvision_core.c
  1034. *
  1035. */
  1036. #define MAXPIXELCLOCK 135000000 /* safety */
  1037. #ifdef CV_AGGRESSIVE_TIMING
  1038. long cv64_memclk = 55000000;
  1039. #else
  1040. long cv64_memclk = 50000000;
  1041. #endif
  1042. /*********************/
  1043. static unsigned char clocks[]={
  1044. 0x13, 0x61, 0x6b, 0x6d, 0x51, 0x69, 0x54, 0x69,
  1045. 0x4f, 0x68, 0x6b, 0x6b, 0x18, 0x61, 0x7b, 0x6c,
  1046. 0x51, 0x67, 0x24, 0x62, 0x56, 0x67, 0x77, 0x6a,
  1047. 0x1d, 0x61, 0x53, 0x66, 0x6b, 0x68, 0x79, 0x69,
  1048. 0x7c, 0x69, 0x7f, 0x69, 0x22, 0x61, 0x54, 0x65,
  1049. 0x56, 0x65, 0x58, 0x65, 0x67, 0x66, 0x41, 0x63,
  1050. 0x27, 0x61, 0x13, 0x41, 0x37, 0x62, 0x6b, 0x4d,
  1051. 0x23, 0x43, 0x51, 0x49, 0x79, 0x66, 0x54, 0x49,
  1052. 0x7d, 0x66, 0x34, 0x56, 0x4f, 0x63, 0x1f, 0x42,
  1053. 0x6b, 0x4b, 0x7e, 0x4d, 0x18, 0x41, 0x2a, 0x43,
  1054. 0x7b, 0x4c, 0x74, 0x4b, 0x51, 0x47, 0x65, 0x49,
  1055. 0x24, 0x42, 0x68, 0x49, 0x56, 0x47, 0x75, 0x4a,
  1056. 0x77, 0x4a, 0x31, 0x43, 0x1d, 0x41, 0x71, 0x49,
  1057. 0x53, 0x46, 0x29, 0x42, 0x6b, 0x48, 0x1f, 0x41,
  1058. 0x79, 0x49, 0x6f, 0x48, 0x7c, 0x49, 0x38, 0x43,
  1059. 0x7f, 0x49, 0x5d, 0x46, 0x22, 0x41, 0x53, 0x45,
  1060. 0x54, 0x45, 0x55, 0x45, 0x56, 0x45, 0x57, 0x45,
  1061. 0x58, 0x45, 0x25, 0x41, 0x67, 0x46, 0x5b, 0x45,
  1062. 0x41, 0x43, 0x78, 0x47, 0x27, 0x41, 0x51, 0x44,
  1063. 0x13, 0x21, 0x7d, 0x47, 0x37, 0x42, 0x71, 0x46,
  1064. 0x6b, 0x2d, 0x14, 0x21, 0x23, 0x23, 0x7d, 0x2f,
  1065. 0x51, 0x29, 0x61, 0x2b, 0x79, 0x46, 0x1d, 0x22,
  1066. 0x54, 0x29, 0x45, 0x27, 0x7d, 0x46, 0x7f, 0x46,
  1067. 0x4f, 0x43, 0x2f, 0x41, 0x1f, 0x22, 0x6a, 0x2b,
  1068. 0x6b, 0x2b, 0x5b, 0x29, 0x7e, 0x2d, 0x65, 0x44,
  1069. 0x18, 0x21, 0x5e, 0x29, 0x2a, 0x23, 0x45, 0x26,
  1070. 0x7b, 0x2c, 0x19, 0x21, 0x74, 0x2b, 0x75, 0x2b,
  1071. 0x51, 0x27, 0x3f, 0x25, 0x65, 0x29, 0x40, 0x25,
  1072. 0x24, 0x22, 0x41, 0x25, 0x68, 0x29, 0x42, 0x25,
  1073. 0x56, 0x27, 0x7e, 0x2b, 0x75, 0x2a, 0x1c, 0x21,
  1074. 0x77, 0x2a, 0x4f, 0x26, 0x31, 0x23, 0x6f, 0x29,
  1075. 0x1d, 0x21, 0x32, 0x23, 0x71, 0x29, 0x72, 0x29,
  1076. 0x53, 0x26, 0x69, 0x28, 0x29, 0x22, 0x75, 0x29,
  1077. 0x6b, 0x28, 0x1f, 0x21, 0x1f, 0x21, 0x6d, 0x28,
  1078. 0x79, 0x29, 0x2b, 0x22, 0x6f, 0x28, 0x59, 0x26,
  1079. 0x7c, 0x29, 0x7d, 0x29, 0x38, 0x23, 0x21, 0x21,
  1080. 0x7f, 0x29, 0x39, 0x23, 0x5d, 0x26, 0x75, 0x28,
  1081. 0x22, 0x21, 0x77, 0x28, 0x53, 0x25, 0x6c, 0x27,
  1082. 0x54, 0x25, 0x61, 0x26, 0x55, 0x25, 0x30, 0x22,
  1083. 0x56, 0x25, 0x63, 0x26, 0x57, 0x25, 0x71, 0x27,
  1084. 0x58, 0x25, 0x7f, 0x28, 0x25, 0x21, 0x74, 0x27,
  1085. 0x67, 0x26, 0x40, 0x23, 0x5b, 0x25, 0x26, 0x21,
  1086. 0x41, 0x23, 0x34, 0x22, 0x78, 0x27, 0x6b, 0x26,
  1087. 0x27, 0x21, 0x35, 0x22, 0x51, 0x24, 0x7b, 0x27,
  1088. 0x13, 0x1, 0x13, 0x1, 0x7d, 0x27, 0x4c, 0x9,
  1089. 0x37, 0x22, 0x5b, 0xb, 0x71, 0x26, 0x5c, 0xb,
  1090. 0x6b, 0xd, 0x47, 0x23, 0x14, 0x1, 0x4f, 0x9,
  1091. 0x23, 0x3, 0x75, 0x26, 0x7d, 0xf, 0x1c, 0x2,
  1092. 0x51, 0x9, 0x59, 0x24, 0x61, 0xb, 0x69, 0x25,
  1093. 0x79, 0x26, 0x34, 0x5, 0x1d, 0x2, 0x6b, 0x25,
  1094. 0x54, 0x9, 0x35, 0x5, 0x45, 0x7, 0x6d, 0x25,
  1095. 0x7d, 0x26, 0x16, 0x1, 0x7f, 0x26, 0x77, 0xd,
  1096. 0x4f, 0x23, 0x78, 0xd, 0x2f, 0x21, 0x27, 0x3,
  1097. 0x1f, 0x2, 0x59, 0x9, 0x6a, 0xb, 0x73, 0x25,
  1098. 0x6b, 0xb, 0x63, 0x24, 0x5b, 0x9, 0x20, 0x2,
  1099. 0x7e, 0xd, 0x4b, 0x7, 0x65, 0x24, 0x43, 0x22,
  1100. 0x18, 0x1, 0x6f, 0xb, 0x5e, 0x9, 0x70, 0xb,
  1101. 0x2a, 0x3, 0x33, 0x4, 0x45, 0x6, 0x60, 0x9,
  1102. 0x7b, 0xc, 0x19, 0x1, 0x19, 0x1, 0x7d, 0xc,
  1103. 0x74, 0xb, 0x50, 0x7, 0x75, 0xb, 0x63, 0x9,
  1104. 0x51, 0x7, 0x23, 0x2, 0x3f, 0x5, 0x1a, 0x1,
  1105. 0x65, 0x9, 0x2d, 0x3, 0x40, 0x5, 0x0, 0x0,
  1106. };
  1107. /* Console colors */
  1108. unsigned char cvconscolors[16][3] = { /* background, foreground, hilite */
  1109. /* R G B */
  1110. {0x30, 0x30, 0x30},
  1111. {0x00, 0x00, 0x00},
  1112. {0x80, 0x00, 0x00},
  1113. {0x00, 0x80, 0x00},
  1114. {0x00, 0x00, 0x80},
  1115. {0x80, 0x80, 0x00},
  1116. {0x00, 0x80, 0x80},
  1117. {0x80, 0x00, 0x80},
  1118. {0xff, 0xff, 0xff},
  1119. {0x40, 0x40, 0x40},
  1120. {0xff, 0x00, 0x00},
  1121. {0x00, 0xff, 0x00},
  1122. {0x00, 0x00, 0xff},
  1123. {0xff, 0xff, 0x00},
  1124. {0x00, 0xff, 0xff},
  1125. {0x00, 0x00, 0xff}
  1126. };
  1127. /* -------------------- Hardware specific routines ------------------------- */
  1128. /* Read Attribute Controller Register=idx */
  1129. inline unsigned char RAttr (volatile unsigned char *regs, short idx)
  1130. {
  1131. wb_64 (regs, ACT_ADDRESS_W, idx);
  1132. mb();
  1133. udelay(100);
  1134. return (rb_64(regs, ACT_ADDRESS_R));
  1135. }
  1136. /* Read Sequencer Register=idx */
  1137. inline unsigned char RSeq (volatile unsigned char *regs, short idx)
  1138. {
  1139. wb_64 (regs, SEQ_ADDRESS, idx);
  1140. mb();
  1141. return (rb_64(regs, SEQ_ADDRESS_R));
  1142. }
  1143. /* Read CRT Controller Register=idx */
  1144. inline unsigned char RCrt (volatile unsigned char *regs, short idx)
  1145. {
  1146. wb_64 (regs, CRT_ADDRESS, idx);
  1147. mb();
  1148. return (rb_64(regs, CRT_ADDRESS_R));
  1149. }
  1150. /* Read Graphics Controller Register=idx */
  1151. inline unsigned char RGfx (volatile unsigned char *regs, short idx)
  1152. {
  1153. wb_64 (regs, GCT_ADDRESS, idx);
  1154. mb();
  1155. return (rb_64(regs, GCT_ADDRESS_R));
  1156. }
  1157. /*
  1158. * Special wakeup/passthrough registers on graphics boards
  1159. */
  1160. inline void cv64_write_port (unsigned short bits,
  1161. volatile unsigned char *base)
  1162. {
  1163. volatile unsigned char *addr;
  1164. static unsigned char cvportbits = 0; /* Mirror port bits here */
  1165. DPRINTK("ENTER\n");
  1166. addr = base + 0x40001;
  1167. if (bits & 0x8000) {
  1168. cvportbits |= bits & 0xff; /* Set bits */
  1169. DPRINTK("Set bits: %04x\n", bits);
  1170. } else {
  1171. bits = bits & 0xff;
  1172. bits = (~bits) & 0xff;
  1173. cvportbits &= bits; /* Clear bits */
  1174. DPRINTK("Clear bits: %04x\n", bits);
  1175. }
  1176. *addr = cvportbits;
  1177. DPRINTK("EXIT\n");
  1178. }
  1179. /*
  1180. * Monitor switch on CyberVision board
  1181. *
  1182. * toggle:
  1183. * 0 = CyberVision Signal
  1184. * 1 = Amiga Signal
  1185. * board = board addr
  1186. *
  1187. */
  1188. inline void cvscreen (int toggle, volatile unsigned char *board)
  1189. {
  1190. DPRINTK("ENTER\n");
  1191. if (toggle == 1) {
  1192. DPRINTK("Show Amiga video\n");
  1193. cv64_write_port (0x10, board);
  1194. } else {
  1195. DPRINTK("Show CyberVision video\n");
  1196. cv64_write_port (0x8010, board);
  1197. }
  1198. DPRINTK("EXIT\n");
  1199. }
  1200. /* Control screen display */
  1201. /* toggle: 0 = on, 1 = off */
  1202. /* board = registerbase */
  1203. inline void gfx_on_off(int toggle, volatile unsigned char *regs)
  1204. {
  1205. int r;
  1206. DPRINTK("ENTER\n");
  1207. toggle &= 0x1;
  1208. toggle = toggle << 5;
  1209. DPRINTK("Turn display %s\n", (toggle ? "off" : "on"));
  1210. r = (int) RSeq(regs, SEQ_ID_CLOCKING_MODE);
  1211. r &= 0xdf; /* Set bit 5 to 0 */
  1212. WSeq (regs, SEQ_ID_CLOCKING_MODE, r | toggle);
  1213. DPRINTK("EXIT\n");
  1214. }
  1215. /*
  1216. * Computes M, N, and R values from
  1217. * given input frequency. It uses a table of
  1218. * precomputed values, to keep CPU time low.
  1219. *
  1220. * The return value consist of:
  1221. * lower byte: Bits 4-0: N Divider Value
  1222. * Bits 5-6: R Value for e.g. SR10 or SR12
  1223. * higher byte: Bits 0-6: M divider value for e.g. SR11 or SR13
  1224. */
  1225. static unsigned short cv64_compute_clock(unsigned long freq)
  1226. {
  1227. static unsigned char *mnr, *save; /* M, N + R vals */
  1228. unsigned long work_freq, r;
  1229. unsigned short erg;
  1230. long diff, d2;
  1231. DPRINTK("ENTER\n");
  1232. if (freq < 12500000 || freq > MAXPIXELCLOCK) {
  1233. printk("CV64 driver: Illegal clock frequency %ld, using 25MHz\n",
  1234. freq);
  1235. freq = 25000000;
  1236. }
  1237. DPRINTK("Freq = %ld\n", freq);
  1238. mnr = clocks; /* there the vals are stored */
  1239. d2 = 0x7fffffff;
  1240. while (*mnr) { /* mnr vals are 0-terminated */
  1241. work_freq = (0x37EE * (mnr[0] + 2)) / ((mnr[1] & 0x1F) + 2);
  1242. r = (mnr[1] >> 5) & 0x03;
  1243. if (r != 0) {
  1244. work_freq = work_freq >> r; /* r is the freq divider */
  1245. }
  1246. work_freq *= 0x3E8; /* 2nd part of OSC */
  1247. diff = abs(freq - work_freq);
  1248. if (d2 >= diff) {
  1249. d2 = diff;
  1250. /* In save are the vals for minimal diff */
  1251. save = mnr;
  1252. }
  1253. mnr += 2;
  1254. }
  1255. erg = *((unsigned short *)save);
  1256. DPRINTK("EXIT\n");
  1257. return (erg);
  1258. }
  1259. static int cv_has_4mb (volatile unsigned char *fb)
  1260. {
  1261. volatile unsigned long *tr, *tw;
  1262. DPRINTK("ENTER\n");
  1263. /* write patterns in memory and test if they can be read */
  1264. tw = (volatile unsigned long *) fb;
  1265. tr = (volatile unsigned long *) (fb + 0x02000000);
  1266. *tw = 0x87654321;
  1267. if (*tr != 0x87654321) {
  1268. DPRINTK("EXIT - <4MB\n");
  1269. return (0);
  1270. }
  1271. /* upper memory region */
  1272. tw = (volatile unsigned long *) (fb + 0x00200000);
  1273. tr = (volatile unsigned long *) (fb + 0x02200000);
  1274. *tw = 0x87654321;
  1275. if (*tr != 0x87654321) {
  1276. DPRINTK("EXIT - <4MB\n");
  1277. return (0);
  1278. }
  1279. *tw = 0xAAAAAAAA;
  1280. if (*tr != 0xAAAAAAAA) {
  1281. DPRINTK("EXIT - <4MB\n");
  1282. return (0);
  1283. }
  1284. *tw = 0x55555555;
  1285. if (*tr != 0x55555555) {
  1286. DPRINTK("EXIT - <4MB\n");
  1287. return (0);
  1288. }
  1289. DPRINTK("EXIT\n");
  1290. return (1);
  1291. }
  1292. static void cv64_board_init (void)
  1293. {
  1294. volatile unsigned char *regs = CyberRegs;
  1295. int i;
  1296. unsigned int clockpar;
  1297. unsigned char test;
  1298. DPRINTK("ENTER\n");
  1299. /*
  1300. * Special CyberVision 64 board operations
  1301. */
  1302. /* Reset board */
  1303. for (i = 0; i < 6; i++) {
  1304. cv64_write_port (0xff, CyberBase);
  1305. }
  1306. /* Return to operational mode */
  1307. cv64_write_port (0x8004, CyberBase);
  1308. /*
  1309. * Generic (?) S3 chip wakeup
  1310. */
  1311. /* Disable I/O & memory decoders, video in setup mode */
  1312. wb_64 (regs, SREG_VIDEO_SUBS_ENABLE, 0x10);
  1313. /* Video responds to cmds, addrs & data */
  1314. wb_64 (regs, SREG_OPTION_SELECT, 0x1);
  1315. /* Enable I/O & memory decoders, video in operational mode */
  1316. wb_64 (regs, SREG_VIDEO_SUBS_ENABLE, 0x8);
  1317. /* VGA color emulation, enable cpu access to display mem */
  1318. wb_64 (regs, GREG_MISC_OUTPUT_W, 0x03);
  1319. /* Unlock S3 VGA regs */
  1320. WCrt (regs, CRT_ID_REGISTER_LOCK_1, 0x48);
  1321. /* Unlock system control & extension registers */
  1322. WCrt (regs, CRT_ID_REGISTER_LOCK_2, 0xA5);
  1323. /* GRF - Enable interrupts */
  1324. /* Enable enhanced regs access, Ready cntl 0 wait states */
  1325. test = RCrt (regs, CRT_ID_SYSTEM_CONFIG);
  1326. test = test | 0x01; /* enable enhanced register access */
  1327. test = test & 0xEF; /* clear bit 4, 0 wait state */
  1328. WCrt (regs, CRT_ID_SYSTEM_CONFIG, test);
  1329. /*
  1330. * bit 0=1: Enable enhaced mode functions
  1331. * bit 2=0: Enhanced mode 8+ bits/pixel
  1332. * bit 4=1: Enable linear addressing
  1333. * bit 5=1: Enable MMIO
  1334. */
  1335. wb_64 (regs, ECR_ADV_FUNC_CNTL, 0x31);
  1336. /*
  1337. * bit 0=1: Color emulation
  1338. * bit 1=1: Enable CPU access to display memory
  1339. * bit 5=1: Select high 64K memory page
  1340. */
  1341. /* GRF - 0xE3 */
  1342. wb_64 (regs, GREG_MISC_OUTPUT_W, 0x23);
  1343. /* Cpu base addr */
  1344. WCrt (regs, CRT_ID_EXT_SYS_CNTL_4, 0x0);
  1345. /* Reset. This does nothing on Trio, but standard VGA practice */
  1346. /* WSeq (CyberRegs, SEQ_ID_RESET, 0x03); */
  1347. /* Character clocks 8 dots wide */
  1348. WSeq (regs, SEQ_ID_CLOCKING_MODE, 0x01);
  1349. /* Enable cpu write to all color planes */
  1350. WSeq (regs, SEQ_ID_MAP_MASK, 0x0F);
  1351. /* Font table in 1st 8k of plane 2, font A=B disables swtich */
  1352. WSeq (regs, SEQ_ID_CHAR_MAP_SELECT, 0x0);
  1353. /* Allow mem access to 256kb */
  1354. WSeq (regs, SEQ_ID_MEMORY_MODE, 0x2);
  1355. /* Unlock S3 extensions to VGA Sequencer regs */
  1356. WSeq (regs, SEQ_ID_UNLOCK_EXT, 0x6);
  1357. /* Enable 4MB fast page mode */
  1358. test = RSeq (regs, SEQ_ID_BUS_REQ_CNTL);
  1359. test = test | 1 << 6;
  1360. WSeq (regs, SEQ_ID_BUS_REQ_CNTL, test);
  1361. /* Faster LUT write: 1 DCLK LUT write cycle, RAMDAC clk doubled */
  1362. WSeq (regs, SEQ_ID_RAMDAC_CNTL, 0xC0);
  1363. /* Clear immediate clock load bit */
  1364. test = RSeq (regs, SEQ_ID_CLKSYN_CNTL_2);
  1365. test = test & 0xDF;
  1366. /* If > 55MHz, enable 2 cycle memory write */
  1367. if (cv64_memclk >= 55000000) {
  1368. test |= 0x80;
  1369. }
  1370. WSeq (regs, SEQ_ID_CLKSYN_CNTL_2, test);
  1371. /* Set MCLK value */
  1372. clockpar = cv64_compute_clock (cv64_memclk);
  1373. test = (clockpar & 0xFF00) >> 8;
  1374. WSeq (regs, SEQ_ID_MCLK_HI, test);
  1375. test = clockpar & 0xFF;
  1376. WSeq (regs, SEQ_ID_MCLK_LO, test);
  1377. /* Chip rev specific: Not in my Trio manual!!! */
  1378. if (RCrt (regs, CRT_ID_REVISION) == 0x10)
  1379. WSeq (regs, SEQ_ID_MORE_MAGIC, test);
  1380. /* We now load an 25 MHz, 31kHz, 640x480 standard VGA Mode. */
  1381. /* Set DCLK value */
  1382. WSeq (regs, SEQ_ID_DCLK_HI, 0x13);
  1383. WSeq (regs, SEQ_ID_DCLK_LO, 0x41);
  1384. /* Load DCLK (and MCLK?) immediately */
  1385. test = RSeq (regs, SEQ_ID_CLKSYN_CNTL_2);
  1386. test = test | 0x22;
  1387. WSeq (regs, SEQ_ID_CLKSYN_CNTL_2, test);
  1388. /* Enable loading of DCLK */
  1389. test = rb_64(regs, GREG_MISC_OUTPUT_R);
  1390. test = test | 0x0C;
  1391. wb_64 (regs, GREG_MISC_OUTPUT_W, test);
  1392. /* Turn off immediate xCLK load */
  1393. WSeq (regs, SEQ_ID_CLKSYN_CNTL_2, 0x2);
  1394. /* Horizontal character clock counts */
  1395. /* 8 LSB of 9 bits = total line - 5 */
  1396. WCrt (regs, CRT_ID_HOR_TOTAL, 0x5F);
  1397. /* Active display line */
  1398. WCrt (regs, CRT_ID_HOR_DISP_ENA_END, 0x4F);
  1399. /* Blank assertion start */
  1400. WCrt (regs, CRT_ID_START_HOR_BLANK, 0x50);
  1401. /* Blank assertion end */
  1402. WCrt (regs, CRT_ID_END_HOR_BLANK, 0x82);
  1403. /* HSYNC assertion start */
  1404. WCrt (regs, CRT_ID_START_HOR_RETR, 0x54);
  1405. /* HSYNC assertion end */
  1406. WCrt (regs, CRT_ID_END_HOR_RETR, 0x80);
  1407. WCrt (regs, CRT_ID_VER_TOTAL, 0xBF);
  1408. WCrt (regs, CRT_ID_OVERFLOW, 0x1F);
  1409. WCrt (regs, CRT_ID_PRESET_ROW_SCAN, 0x0);
  1410. WCrt (regs, CRT_ID_MAX_SCAN_LINE, 0x40);
  1411. WCrt (regs, CRT_ID_CURSOR_START, 0x00);
  1412. WCrt (regs, CRT_ID_CURSOR_END, 0x00);
  1413. WCrt (regs, CRT_ID_START_ADDR_HIGH, 0x00);
  1414. WCrt (regs, CRT_ID_START_ADDR_LOW, 0x00);
  1415. WCrt (regs, CRT_ID_CURSOR_LOC_HIGH, 0x00);
  1416. WCrt (regs, CRT_ID_CURSOR_LOC_LOW, 0x00);
  1417. WCrt (regs, CRT_ID_START_VER_RETR, 0x9C);
  1418. WCrt (regs, CRT_ID_END_VER_RETR, 0x0E);
  1419. WCrt (regs, CRT_ID_VER_DISP_ENA_END, 0x8F);
  1420. WCrt (regs, CRT_ID_SCREEN_OFFSET, 0x50);
  1421. WCrt (regs, CRT_ID_UNDERLINE_LOC, 0x00);
  1422. WCrt (regs, CRT_ID_START_VER_BLANK, 0x96);
  1423. WCrt (regs, CRT_ID_END_VER_BLANK, 0xB9);
  1424. WCrt (regs, CRT_ID_MODE_CONTROL, 0xE3);
  1425. WCrt (regs, CRT_ID_LINE_COMPARE, 0xFF);
  1426. WCrt (regs, CRT_ID_BACKWAD_COMP_3, 0x10); /* FIFO enabled */
  1427. WCrt (regs, CRT_ID_MISC_1, 0x35);
  1428. WCrt (regs, CRT_ID_DISPLAY_FIFO, 0x5A);
  1429. WCrt (regs, CRT_ID_EXT_MEM_CNTL_2, 0x70);
  1430. WCrt (regs, CRT_ID_LAW_POS_LO, 0x40);
  1431. WCrt (regs, CRT_ID_EXT_MEM_CNTL_3, 0xFF);
  1432. WGfx (regs, GCT_ID_SET_RESET, 0x0);
  1433. WGfx (regs, GCT_ID_ENABLE_SET_RESET, 0x0);
  1434. WGfx (regs, GCT_ID_COLOR_COMPARE, 0x0);
  1435. WGfx (regs, GCT_ID_DATA_ROTATE, 0x0);
  1436. WGfx (regs, GCT_ID_READ_MAP_SELECT, 0x0);
  1437. WGfx (regs, GCT_ID_GRAPHICS_MODE, 0x40);
  1438. WGfx (regs, GCT_ID_MISC, 0x01);
  1439. WGfx (regs, GCT_ID_COLOR_XCARE, 0x0F);
  1440. WGfx (regs, GCT_ID_BITMASK, 0xFF);
  1441. /* Colors for text mode */
  1442. for (i = 0; i < 0xf; i++)
  1443. WAttr (regs, i, i);
  1444. WAttr (regs, ACT_ID_ATTR_MODE_CNTL, 0x41);
  1445. WAttr (regs, ACT_ID_OVERSCAN_COLOR, 0x01);
  1446. WAttr (regs, ACT_ID_COLOR_PLANE_ENA, 0x0F);
  1447. WAttr (regs, ACT_ID_HOR_PEL_PANNING, 0x0);
  1448. WAttr (regs, ACT_ID_COLOR_SELECT, 0x0);
  1449. wb_64 (regs, VDAC_MASK, 0xFF);
  1450. *((unsigned long *) (regs + ECR_FRGD_COLOR)) = 0xFF;
  1451. *((unsigned long *) (regs + ECR_BKGD_COLOR)) = 0;
  1452. /* Colors initially set to grayscale */
  1453. wb_64 (regs, VDAC_ADDRESS_W, 0);
  1454. for (i = 255; i >= 0; i--) {
  1455. wb_64(regs, VDAC_DATA, i);
  1456. wb_64(regs, VDAC_DATA, i);
  1457. wb_64(regs, VDAC_DATA, i);
  1458. }
  1459. /* GFx hardware cursor off */
  1460. WCrt (regs, CRT_ID_HWGC_MODE, 0x00);
  1461. /* Set first to 4MB, so test will work */
  1462. WCrt (regs, CRT_ID_LAW_CNTL, 0x13);
  1463. /* Find "correct" size of fbmem of Z3 board */
  1464. if (cv_has_4mb (CyberMem)) {
  1465. CyberSize = 1024 * 1024 * 4;
  1466. WCrt (regs, CRT_ID_LAW_CNTL, 0x13);
  1467. DPRINTK("4MB board\n");
  1468. } else {
  1469. CyberSize = 1024 * 1024 * 2;
  1470. WCrt (regs, CRT_ID_LAW_CNTL, 0x12);
  1471. DPRINTK("2MB board\n");
  1472. }
  1473. /* Initialize graphics engine */
  1474. Cyber_WaitBlit();
  1475. vgaw16 (regs, ECR_FRGD_MIX, 0x27);
  1476. vgaw16 (regs, ECR_BKGD_MIX, 0x07);
  1477. vgaw16 (regs, ECR_READ_REG_DATA, 0x1000);
  1478. udelay(200);
  1479. vgaw16 (regs, ECR_READ_REG_DATA, 0x2000);
  1480. Cyber_WaitBlit();
  1481. vgaw16 (regs, ECR_READ_REG_DATA, 0x3FFF);
  1482. Cyber_WaitBlit();
  1483. udelay(200);
  1484. vgaw16 (regs, ECR_READ_REG_DATA, 0x4FFF);
  1485. Cyber_WaitBlit();
  1486. vgaw16 (regs, ECR_BITPLANE_WRITE_MASK, ~0);
  1487. Cyber_WaitBlit();
  1488. vgaw16 (regs, ECR_READ_REG_DATA, 0xE000);
  1489. vgaw16 (regs, ECR_CURRENT_Y_POS2, 0x00);
  1490. vgaw16 (regs, ECR_CURRENT_X_POS2, 0x00);
  1491. vgaw16 (regs, ECR_READ_REG_DATA, 0xA000);
  1492. vgaw16 (regs, ECR_DEST_Y__AX_STEP, 0x00);
  1493. vgaw16 (regs, ECR_DEST_Y2__AX_STEP2, 0x00);
  1494. vgaw16 (regs, ECR_DEST_X__DIA_STEP, 0x00);
  1495. vgaw16 (regs, ECR_DEST_X2__DIA_STEP2, 0x00);
  1496. vgaw16 (regs, ECR_SHORT_STROKE, 0x00);
  1497. vgaw16 (regs, ECR_DRAW_CMD, 0x01);
  1498. Cyber_WaitBlit();
  1499. vgaw16 (regs, ECR_READ_REG_DATA, 0x4FFF);
  1500. vgaw16 (regs, ECR_BKGD_COLOR, 0x01);
  1501. vgaw16 (regs, ECR_FRGD_COLOR, 0x00);
  1502. /* Enable video display (set bit 5) */
  1503. /* ARB - Would also seem to write to AR13.
  1504. * May want to use parts of WAttr to set JUST bit 5
  1505. */
  1506. WAttr (regs, 0x33, 0);
  1507. /* GRF - function code ended here */
  1508. /* Turn gfx on again */
  1509. gfx_on_off (0, regs);
  1510. /* Pass-through */
  1511. cvscreen (0, CyberBase);
  1512. DPRINTK("EXIT\n");
  1513. }
  1514. static void cv64_load_video_mode (struct fb_var_screeninfo *video_mode)
  1515. {
  1516. volatile unsigned char *regs = CyberRegs;
  1517. int fx, fy;
  1518. unsigned short mnr;
  1519. unsigned short HT, HDE, HBS, HBE, HSS, HSE, VDE, VBS, VBE, VSS, VSE, VT;
  1520. char LACE, DBLSCAN, TEXT, CONSOLE;
  1521. int cr50, sr15, sr18, clock_mode, test;
  1522. int m, n;
  1523. int tfillm, temptym;
  1524. int hmul;
  1525. /* ---------------- */
  1526. int xres, hfront, hsync, hback;
  1527. int yres, vfront, vsync, vback;
  1528. int bpp;
  1529. #if 0
  1530. float freq_f;
  1531. #endif
  1532. long freq;
  1533. /* ---------------- */
  1534. DPRINTK("ENTER\n");
  1535. TEXT = 0; /* if depth == 4 */
  1536. CONSOLE = 0; /* mode num == 255 (console) */
  1537. fx = fy = 8; /* force 8x8 font */
  1538. /* GRF - Disable interrupts */
  1539. gfx_on_off (1, regs);
  1540. switch (video_mode->bits_per_pixel) {
  1541. case 15:
  1542. case 16:
  1543. hmul = 2;
  1544. break;
  1545. default:
  1546. hmul = 1;
  1547. break;
  1548. }
  1549. bpp = video_mode->bits_per_pixel;
  1550. xres = video_mode->xres;
  1551. hfront = video_mode->right_margin;
  1552. hsync = video_mode->hsync_len;
  1553. hback = video_mode->left_margin;
  1554. LACE = 0;
  1555. DBLSCAN = 0;
  1556. if (video_mode->vmode & FB_VMODE_DOUBLE) {
  1557. yres = video_mode->yres * 2;
  1558. vfront = video_mode->lower_margin * 2;
  1559. vsync = video_mode->vsync_len * 2;
  1560. vback = video_mode->upper_margin * 2;
  1561. DBLSCAN = 1;
  1562. } else if (video_mode->vmode & FB_VMODE_INTERLACED) {
  1563. yres = (video_mode->yres + 1) / 2;
  1564. vfront = (video_mode->lower_margin + 1) / 2;
  1565. vsync = (video_mode->vsync_len + 1) / 2;
  1566. vback = (video_mode->upper_margin + 1) / 2;
  1567. LACE = 1;
  1568. } else {
  1569. yres = video_mode->yres;
  1570. vfront = video_mode->lower_margin;
  1571. vsync = video_mode->vsync_len;
  1572. vback = video_mode->upper_margin;
  1573. }
  1574. /* ARB Dropping custom setup method from cvision.c */
  1575. #if 0
  1576. if (cvision_custom_mode) {
  1577. HBS = hbs / 8 * hmul;
  1578. HBE = hbe / 8 * hmul;
  1579. HSS = hss / 8 * hmul;
  1580. HSE = hse / 8 * hmul;
  1581. HT = ht / 8 * hmul - 5;
  1582. VBS = vbs - 1;
  1583. VSS = vss;
  1584. VSE = vse;
  1585. VBE = vbe;
  1586. VT = vt - 2;
  1587. } else {
  1588. #else
  1589. {
  1590. #endif
  1591. HBS = hmul * (xres / 8);
  1592. HBE = hmul * ((xres/8) + (hfront/8) + (hsync/8) + (hback/8) - 2);
  1593. HSS = hmul * ((xres/8) + (hfront/8) + 2);
  1594. HSE = hmul * ((xres/8) + (hfront/8) + (hsync/8) + 1);
  1595. HT = hmul * ((xres/8) + (hfront/8) + (hsync/8) + (hback/8));
  1596. VBS = yres;
  1597. VBE = yres + vfront + vsync + vback - 2;
  1598. VSS = yres + vfront - 1;
  1599. VSE = yres + vfront + vsync - 1;
  1600. VT = yres + vfront + vsync + vback - 2;
  1601. }
  1602. wb_64 (regs, ECR_ADV_FUNC_CNTL, (TEXT ? 0x00 : 0x31));
  1603. if (TEXT)
  1604. HDE = ((video_mode->xres + fx - 1) / fx) - 1;
  1605. else
  1606. HDE = (video_mode->xres + 3) * hmul / 8 - 1;
  1607. VDE = video_mode->yres - 1;
  1608. WCrt (regs, CRT_ID_HWGC_MODE, 0x00);
  1609. WCrt (regs, CRT_ID_EXT_DAC_CNTL, 0x00);
  1610. WSeq (regs, SEQ_ID_MEMORY_MODE,
  1611. (TEXT || (video_mode->bits_per_pixel == 1)) ? 0x06 : 0x0e);
  1612. WGfx (regs, GCT_ID_READ_MAP_SELECT, 0x00);
  1613. WSeq (regs, SEQ_ID_MAP_MASK,
  1614. (video_mode->bits_per_pixel == 1) ? 0x01 : 0xFF);
  1615. WSeq (regs, SEQ_ID_CHAR_MAP_SELECT, 0x00);
  1616. /* cv64_compute_clock accepts arguments in Hz */
  1617. /* pixclock is in ps ... convert to Hz */
  1618. #if 0
  1619. freq_f = (1.0 / (float) video_mode->pixclock) * 1000000000;
  1620. freq = ((long) freq_f) * 1000;
  1621. #else
  1622. /* freq = (long) ((long long)1000000000000 / (long long) video_mode->pixclock);
  1623. */
  1624. freq = (1000000000 / video_mode->pixclock) * 1000;
  1625. #endif
  1626. mnr = cv64_compute_clock (freq);
  1627. WSeq (regs, SEQ_ID_DCLK_HI, ((mnr & 0xFF00) >> 8));
  1628. WSeq (regs, SEQ_ID_DCLK_LO, (mnr & 0xFF));
  1629. /* Load display parameters into board */
  1630. WCrt (regs, CRT_ID_EXT_HOR_OVF,
  1631. ((HT & 0x100) ? 0x01 : 0x00) |
  1632. ((HDE & 0x100) ? 0x02 : 0x00) |
  1633. ((HBS & 0x100) ? 0x04 : 0x00) |
  1634. /* ((HBE & 0x40) ? 0x08 : 0x00) | */
  1635. ((HSS & 0x100) ? 0x10 : 0x00) |
  1636. /* ((HSE & 0x20) ? 0x20 : 0x00) | */
  1637. (((HT-5) & 0x100) ? 0x40 : 0x00)
  1638. );
  1639. WCrt (regs, CRT_ID_EXT_VER_OVF,
  1640. 0x40 |
  1641. ((VT & 0x400) ? 0x01 : 0x00) |
  1642. ((VDE & 0x400) ? 0x02 : 0x00) |
  1643. ((VBS & 0x400) ? 0x04 : 0x00) |
  1644. ((VSS & 0x400) ? 0x10 : 0x00)
  1645. );
  1646. WCrt (regs, CRT_ID_HOR_TOTAL, HT);
  1647. WCrt (regs, CRT_ID_DISPLAY_FIFO, HT - 5);
  1648. WCrt (regs, CRT_ID_HOR_DISP_ENA_END, ((HDE >= HBS) ? (HBS - 1) : HDE));
  1649. WCrt (regs, CRT_ID_START_HOR_BLANK, HBS);
  1650. WCrt (regs, CRT_ID_END_HOR_BLANK, ((HBE & 0x1F) | 0x80));
  1651. WCrt (regs, CRT_ID_START_HOR_RETR, HSS);
  1652. WCrt (regs, CRT_ID_END_HOR_RETR,
  1653. (HSE & 0x1F) |
  1654. ((HBE & 0x20) ? 0x80 : 0x00)
  1655. );
  1656. WCrt (regs, CRT_ID_VER_TOTAL, VT);
  1657. WCrt (regs, CRT_ID_OVERFLOW,
  1658. 0x10 |
  1659. ((VT & 0x100) ? 0x01 : 0x00) |
  1660. ((VDE & 0x100) ? 0x02 : 0x00) |
  1661. ((VSS & 0x100) ? 0x04 : 0x00) |
  1662. ((VBS & 0x100) ? 0x08 : 0x00) |
  1663. ((VT & 0x200) ? 0x20 : 0x00) |
  1664. ((VDE & 0x200) ? 0x40 : 0x00) |
  1665. ((VSS & 0x200) ? 0x80 : 0x00)
  1666. );
  1667. WCrt (regs, CRT_ID_MAX_SCAN_LINE,
  1668. 0x40 |
  1669. (DBLSCAN ? 0x80 : 0x00) |
  1670. ((VBS & 0x200) ? 0x20 : 0x00) |
  1671. (TEXT ? ((fy - 1) & 0x1F) : 0x00)
  1672. );
  1673. WCrt (regs, CRT_ID_MODE_CONTROL, 0xE3);
  1674. /* Text cursor */
  1675. if (TEXT) {
  1676. #if 1
  1677. WCrt (regs, CRT_ID_CURSOR_START, (fy & 0x1f) - 2);
  1678. WCrt (regs, CRT_ID_CURSOR_END, (fy & 0x1F) - 1);
  1679. #else
  1680. WCrt (regs, CRT_ID_CURSOR_START, 0x00);
  1681. WCrt (regs, CRT_ID_CURSOR_END, fy & 0x1F);
  1682. #endif
  1683. WCrt (regs, CRT_ID_UNDERLINE_LOC, (fy - 1) & 0x1F);
  1684. WCrt (regs, CRT_ID_CURSOR_LOC_HIGH, 0x00);
  1685. WCrt (regs, CRT_ID_CURSOR_LOC_LOW, 0x00);
  1686. }
  1687. WCrt (regs, CRT_ID_START_ADDR_HIGH, 0x00);
  1688. WCrt (regs, CRT_ID_START_ADDR_LOW, 0x00);
  1689. WCrt (regs, CRT_ID_START_VER_RETR, VSS);
  1690. WCrt (regs, CRT_ID_END_VER_RETR, (VSE & 0x0F));
  1691. WCrt (regs, CRT_ID_VER_DISP_ENA_END, VDE);
  1692. WCrt (regs, CRT_ID_START_VER_BLANK, VBS);
  1693. WCrt (regs, CRT_ID_END_VER_BLANK, VBE);
  1694. WCrt (regs, CRT_ID_LINE_COMPARE, 0xFF);
  1695. WCrt (regs, CRT_ID_LACE_RETR_START, HT / 2);
  1696. WCrt (regs, CRT_ID_LACE_CONTROL, (LACE ? 0x20 : 0x00));
  1697. WGfx (regs, GCT_ID_GRAPHICS_MODE,
  1698. ((TEXT || (video_mode->bits_per_pixel == 1)) ? 0x00 : 0x40));
  1699. WGfx (regs, GCT_ID_MISC, (TEXT ? 0x04 : 0x01));
  1700. WSeq (regs, SEQ_ID_MEMORY_MODE,
  1701. ((TEXT || (video_mode->bits_per_pixel == 1)) ? 0x06 : 0x02));
  1702. wb_64 (regs, VDAC_MASK, 0xFF);
  1703. /* Blank border */
  1704. test = RCrt (regs, CRT_ID_BACKWAD_COMP_2);
  1705. WCrt (regs, CRT_ID_BACKWAD_COMP_2, (test | 0x20));
  1706. sr15 = RSeq (regs, SEQ_ID_CLKSYN_CNTL_2);
  1707. sr15 &= 0xEF;
  1708. sr18 = RSeq (regs, SEQ_ID_RAMDAC_CNTL);
  1709. sr18 &= 0x7F;
  1710. clock_mode = 0x00;
  1711. cr50 = 0x00;
  1712. test = RCrt (regs, CRT_ID_EXT_MISC_CNTL_2);
  1713. test &= 0xD;
  1714. /* Clear roxxler byte-swapping... */
  1715. cv64_write_port (0x0040, CyberBase);
  1716. cv64_write_port (0x0020, CyberBase);
  1717. switch (video_mode->bits_per_pixel) {
  1718. case 1:
  1719. case 4: /* text */
  1720. HDE = video_mode->xres / 16;
  1721. break;
  1722. case 8:
  1723. if (freq > 80000000) {
  1724. clock_mode = 0x10 | 0x02;
  1725. sr15 |= 0x10;
  1726. sr18 |= 0x80;
  1727. }
  1728. HDE = video_mode->xres / 8;
  1729. cr50 |= 0x00;
  1730. break;
  1731. case 15:
  1732. cv64_write_port (0x8020, CyberBase);
  1733. clock_mode = 0x30;
  1734. HDE = video_mode->xres / 4;
  1735. cr50 |= 0x10;
  1736. break;
  1737. case 16:
  1738. cv64_write_port (0x8020, CyberBase);
  1739. clock_mode = 0x50;
  1740. HDE = video_mode->xres / 4;
  1741. cr50 |= 0x10;
  1742. break;
  1743. case 24:
  1744. case 32:
  1745. cv64_write_port (0x8040, CyberBase);
  1746. clock_mode = 0xD0;
  1747. HDE = video_mode->xres / 2;
  1748. cr50 |= 0x30;
  1749. break;
  1750. }
  1751. WCrt (regs, CRT_ID_EXT_MISC_CNTL_2, clock_mode | test);
  1752. WSeq (regs, SEQ_ID_CLKSYN_CNTL_2, sr15);
  1753. WSeq (regs, SEQ_ID_RAMDAC_CNTL, sr18);
  1754. WCrt (regs, CRT_ID_SCREEN_OFFSET, HDE);
  1755. WCrt (regs, CRT_ID_MISC_1, (TEXT ? 0x05 : 0x35));
  1756. test = RCrt (regs, CRT_ID_EXT_SYS_CNTL_2);
  1757. test &= ~0x30;
  1758. test |= (HDE >> 4) & 0x30;
  1759. WCrt (regs, CRT_ID_EXT_SYS_CNTL_2, test);
  1760. /* Set up graphics engine */
  1761. switch (video_mode->xres) {
  1762. case 1024:
  1763. cr50 |= 0x00;
  1764. break;
  1765. case 640:
  1766. cr50 |= 0x40;
  1767. break;
  1768. case 800:
  1769. cr50 |= 0x80;
  1770. break;
  1771. case 1280:
  1772. cr50 |= 0xC0;
  1773. break;
  1774. case 1152:
  1775. cr50 |= 0x01;
  1776. break;
  1777. case 1600:
  1778. cr50 |= 0x81;
  1779. break;
  1780. default: /* XXX */
  1781. break;
  1782. }
  1783. WCrt (regs, CRT_ID_EXT_SYS_CNTL_1, cr50);
  1784. udelay(100);
  1785. WAttr (regs, ACT_ID_ATTR_MODE_CNTL, (TEXT ? 0x08 : 0x41));
  1786. udelay(100);
  1787. WAttr (regs, ACT_ID_COLOR_PLANE_ENA,
  1788. (video_mode->bits_per_pixel == 1) ? 0x01 : 0x0F);
  1789. udelay(100);
  1790. tfillm = (96 * (cv64_memclk / 1000)) / 240000;
  1791. switch (video_mode->bits_per_pixel) {
  1792. case 32:
  1793. case 24:
  1794. temptym = (24 * (cv64_memclk / 1000)) / (freq / 1000);
  1795. break;
  1796. case 15:
  1797. case 16:
  1798. temptym = (48 * (cv64_memclk / 1000)) / (freq / 1000);
  1799. break;
  1800. case 4:
  1801. temptym = (192 * (cv64_memclk / 1000)) / (freq / 1000);
  1802. break;
  1803. default:
  1804. temptym = (96 * (cv64_memclk / 1000)) / (freq / 1000);
  1805. break;
  1806. }
  1807. m = (temptym - tfillm - 9) / 2;
  1808. if (m < 0)
  1809. m = 0;
  1810. m = (m & 0x1F) << 3;
  1811. if (m < 0x18)
  1812. m = 0x18;
  1813. n = 0xFF;
  1814. WCrt (regs, CRT_ID_EXT_MEM_CNTL_2, m);
  1815. WCrt (regs, CRT_ID_EXT_MEM_CNTL_3, n);
  1816. udelay(10);
  1817. /* Text initialization */
  1818. if (TEXT) {
  1819. /* Do text initialization here ! */
  1820. }
  1821. if (CONSOLE) {
  1822. int i;
  1823. wb_64 (regs, VDAC_ADDRESS_W, 0);
  1824. for (i = 0; i < 4; i++) {
  1825. wb_64 (regs, VDAC_DATA, cvconscolors [i][0]);
  1826. wb_64 (regs, VDAC_DATA, cvconscolors [i][1]);
  1827. wb_64 (regs, VDAC_DATA, cvconscolors [i][2]);
  1828. }
  1829. }
  1830. WAttr (regs, 0x33, 0);
  1831. /* Turn gfx on again */
  1832. gfx_on_off (0, (volatile unsigned char *) regs);
  1833. /* Pass-through */
  1834. cvscreen (0, CyberBase);
  1835. DPRINTK("EXIT\n");
  1836. }
  1837. void cvision_bitblt (u_short sx, u_short sy, u_short dx, u_short dy,
  1838. u_short w, u_short h)
  1839. {
  1840. volatile unsigned char *regs = CyberRegs;
  1841. unsigned short drawdir = 0;
  1842. DPRINTK("ENTER\n");
  1843. if (sx > dx) {
  1844. drawdir |= 1 << 5;
  1845. } else {
  1846. sx += w - 1;
  1847. dx += w - 1;
  1848. }
  1849. if (sy > dy) {
  1850. drawdir |= 1 << 7;
  1851. } else {
  1852. sy += h - 1;
  1853. dy += h - 1;
  1854. }
  1855. Cyber_WaitBlit();
  1856. vgaw16 (regs, ECR_READ_REG_DATA, 0xA000);
  1857. vgaw16 (regs, ECR_BKGD_MIX, 0x7);
  1858. vgaw16 (regs, ECR_FRGD_MIX, 0x67);
  1859. vgaw16 (regs, ECR_BKGD_COLOR, 0x0);
  1860. vgaw16 (regs, ECR_FRGD_COLOR, 0x1);
  1861. vgaw16 (regs, ECR_BITPLANE_READ_MASK, 0x1);
  1862. vgaw16 (regs, ECR_BITPLANE_WRITE_MASK, 0xFFF);
  1863. vgaw16 (regs, ECR_CURRENT_Y_POS, sy);
  1864. vgaw16 (regs, ECR_CURRENT_X_POS, sx);
  1865. vgaw16 (regs, ECR_DEST_Y__AX_STEP, dy);
  1866. vgaw16 (regs, ECR_DEST_X__DIA_STEP, dx);
  1867. vgaw16 (regs, ECR_READ_REG_DATA, h - 1);
  1868. vgaw16 (regs, ECR_MAJ_AXIS_PIX_CNT, w - 1);
  1869. vgaw16 (regs, ECR_DRAW_CMD, 0xC051 | drawdir);
  1870. DPRINTK("EXIT\n");
  1871. }
  1872. void cvision_clear (u_short dx, u_short dy, u_short w, u_short h, u_short bg)
  1873. {
  1874. volatile unsigned char *regs = CyberRegs;
  1875. DPRINTK("ENTER\n");
  1876. Cyber_WaitBlit();
  1877. vgaw16 (regs, ECR_FRGD_MIX, 0x0027);
  1878. vgaw16 (regs, ECR_FRGD_COLOR, bg);
  1879. vgaw16 (regs, ECR_READ_REG_DATA, 0xA000);
  1880. vgaw16 (regs, ECR_CURRENT_Y_POS, dy);
  1881. vgaw16 (regs, ECR_CURRENT_X_POS, dx);
  1882. vgaw16 (regs, ECR_READ_REG_DATA, h - 1);
  1883. vgaw16 (regs, ECR_MAJ_AXIS_PIX_CNT, w - 1);
  1884. vgaw16 (regs, ECR_DRAW_CMD, 0x40B1);
  1885. DPRINTK("EXIT\n");
  1886. }
  1887. #ifdef CYBERFBDEBUG
  1888. /*
  1889. * Dump internal settings of CyberVision board
  1890. */
  1891. static void cv64_dump (void)
  1892. {
  1893. volatile unsigned char *regs = CyberRegs;
  1894. DPRINTK("ENTER\n");
  1895. /* Dump the VGA setup values */
  1896. *(regs + S3_CRTC_ADR) = 0x00;
  1897. DPRINTK("CR00 = %x\n", *(regs + S3_CRTC_DATA));
  1898. *(regs + S3_CRTC_ADR) = 0x01;
  1899. DPRINTK("CR01 = %x\n", *(regs + S3_CRTC_DATA));
  1900. *(regs + S3_CRTC_ADR) = 0x02;
  1901. DPRINTK("CR02 = %x\n", *(regs + S3_CRTC_DATA));
  1902. *(regs + S3_CRTC_ADR) = 0x03;
  1903. DPRINTK("CR03 = %x\n", *(regs + S3_CRTC_DATA));
  1904. *(regs + S3_CRTC_ADR) = 0x04;
  1905. DPRINTK("CR04 = %x\n", *(regs + S3_CRTC_DATA));
  1906. *(regs + S3_CRTC_ADR) = 0x05;
  1907. DPRINTK("CR05 = %x\n", *(regs + S3_CRTC_DATA));
  1908. *(regs + S3_CRTC_ADR) = 0x06;
  1909. DPRINTK("CR06 = %x\n", *(regs + S3_CRTC_DATA));
  1910. *(regs + S3_CRTC_ADR) = 0x07;
  1911. DPRINTK("CR07 = %x\n", *(regs + S3_CRTC_DATA));
  1912. *(regs + S3_CRTC_ADR) = 0x08;
  1913. DPRINTK("CR08 = %x\n", *(regs + S3_CRTC_DATA));
  1914. *(regs + S3_CRTC_ADR) = 0x09;
  1915. DPRINTK("CR09 = %x\n", *(regs + S3_CRTC_DATA));
  1916. *(regs + S3_CRTC_ADR) = 0x10;
  1917. DPRINTK("CR10 = %x\n", *(regs + S3_CRTC_DATA));
  1918. *(regs + S3_CRTC_ADR) = 0x11;
  1919. DPRINTK("CR11 = %x\n", *(regs + S3_CRTC_DATA));
  1920. *(regs + S3_CRTC_ADR) = 0x12;
  1921. DPRINTK("CR12 = %x\n", *(regs + S3_CRTC_DATA));
  1922. *(regs + S3_CRTC_ADR) = 0x13;
  1923. DPRINTK("CR13 = %x\n", *(regs + S3_CRTC_DATA));
  1924. *(regs + S3_CRTC_ADR) = 0x15;
  1925. DPRINTK("CR15 = %x\n", *(regs + S3_CRTC_DATA));
  1926. *(regs + S3_CRTC_ADR) = 0x16;
  1927. DPRINTK("CR16 = %x\n", *(regs + S3_CRTC_DATA));
  1928. *(regs + S3_CRTC_ADR) = 0x36;
  1929. DPRINTK("CR36 = %x\n", *(regs + S3_CRTC_DATA));
  1930. *(regs + S3_CRTC_ADR) = 0x37;
  1931. DPRINTK("CR37 = %x\n", *(regs + S3_CRTC_DATA));
  1932. *(regs + S3_CRTC_ADR) = 0x42;
  1933. DPRINTK("CR42 = %x\n", *(regs + S3_CRTC_DATA));
  1934. *(regs + S3_CRTC_ADR) = 0x43;
  1935. DPRINTK("CR43 = %x\n", *(regs + S3_CRTC_DATA));
  1936. *(regs + S3_CRTC_ADR) = 0x50;
  1937. DPRINTK("CR50 = %x\n", *(regs + S3_CRTC_DATA));
  1938. *(regs + S3_CRTC_ADR) = 0x51;
  1939. DPRINTK("CR51 = %x\n", *(regs + S3_CRTC_DATA));
  1940. *(regs + S3_CRTC_ADR) = 0x53;
  1941. DPRINTK("CR53 = %x\n", *(regs + S3_CRTC_DATA));
  1942. *(regs + S3_CRTC_ADR) = 0x58;
  1943. DPRINTK("CR58 = %x\n", *(regs + S3_CRTC_DATA));
  1944. *(regs + S3_CRTC_ADR) = 0x59;
  1945. DPRINTK("CR59 = %x\n", *(regs + S3_CRTC_DATA));
  1946. *(regs + S3_CRTC_ADR) = 0x5A;
  1947. DPRINTK("CR5A = %x\n", *(regs + S3_CRTC_DATA));
  1948. *(regs + S3_CRTC_ADR) = 0x5D;
  1949. DPRINTK("CR5D = %x\n", *(regs + S3_CRTC_DATA));
  1950. *(regs + S3_CRTC_ADR) = 0x5E;
  1951. DPRINTK("CR5E = %x\n", *(regs + S3_CRTC_DATA));
  1952. DPRINTK("MISC = %x\n", *(regs + GREG_MISC_OUTPUT_R));
  1953. *(regs + SEQ_ADDRESS) = 0x01;
  1954. DPRINTK("SR01 = %x\n", *(regs + SEQ_ADDRESS_R));
  1955. *(regs + SEQ_ADDRESS) = 0x02;
  1956. DPRINTK("SR02 = %x\n", *(regs + SEQ_ADDRESS_R));
  1957. *(regs + SEQ_ADDRESS) = 0x03;
  1958. DPRINTK("SR03 = %x\n", *(regs + SEQ_ADDRESS_R));
  1959. *(regs + SEQ_ADDRESS) = 0x09;
  1960. DPRINTK("SR09 = %x\n", *(regs + SEQ_ADDRESS_R));
  1961. *(regs + SEQ_ADDRESS) = 0x10;
  1962. DPRINTK("SR10 = %x\n", *(regs + SEQ_ADDRESS_R));
  1963. *(regs + SEQ_ADDRESS) = 0x11;
  1964. DPRINTK("SR11 = %x\n", *(regs + SEQ_ADDRESS_R));
  1965. *(regs + SEQ_ADDRESS) = 0x12;
  1966. DPRINTK("SR12 = %x\n", *(regs + SEQ_ADDRESS_R));
  1967. *(regs + SEQ_ADDRESS) = 0x13;
  1968. DPRINTK("SR13 = %x\n", *(regs + SEQ_ADDRESS_R));
  1969. *(regs + SEQ_ADDRESS) = 0x15;
  1970. DPRINTK("SR15 = %x\n", *(regs + SEQ_ADDRESS_R));
  1971. return;
  1972. }
  1973. #endif