cyberfb.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296
  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/tty.h>
  83. #include <linux/slab.h>
  84. #include <linux/delay.h>
  85. #include <linux/zorro.h>
  86. #include <linux/fb.h>
  87. #include <linux/init.h>
  88. #include <asm/uaccess.h>
  89. #include <asm/system.h>
  90. #include <asm/irq.h>
  91. #include <asm/pgtable.h>
  92. #include <asm/amigahw.h>
  93. #include <asm/io.h>
  94. #include "cyberfb.h"
  95. #include <video/fbcon.h>
  96. #include <video/fbcon-cfb8.h>
  97. #include <video/fbcon-cfb16.h>
  98. /*#define CYBERFBDEBUG*/
  99. #ifdef CYBERFBDEBUG
  100. #define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
  101. static void cv64_dump(void);
  102. #else
  103. #define DPRINTK(fmt, args...)
  104. #endif
  105. #define wb_64(regs,reg,dat) (*(((volatile unsigned char *)regs) + reg) = dat)
  106. #define rb_64(regs, reg) (*(((volatile unsigned char *)regs) + reg))
  107. #define ww_64(regs,reg,dat) (*((volatile unsigned short *)(regs + reg) = dat)
  108. struct cyberfb_par {
  109. struct fb_var_screeninfo var;
  110. __u32 type;
  111. __u32 type_aux;
  112. __u32 visual;
  113. __u32 line_length;
  114. };
  115. static struct cyberfb_par current_par;
  116. static int current_par_valid = 0;
  117. static struct display disp;
  118. static struct fb_info fb_info;
  119. /*
  120. * Frame Buffer Name
  121. */
  122. static char cyberfb_name[16] = "Cybervision";
  123. /*
  124. * CyberVision Graphics Board
  125. */
  126. static unsigned char Cyber_colour_table [256][3];
  127. static unsigned long CyberSize;
  128. static volatile unsigned char *CyberBase;
  129. static volatile unsigned char *CyberMem;
  130. static volatile unsigned char *CyberRegs;
  131. static unsigned long CyberMem_phys;
  132. static unsigned long CyberRegs_phys;
  133. /*
  134. * Predefined Video Modes
  135. */
  136. static struct {
  137. const char *name;
  138. struct fb_var_screeninfo var;
  139. } cyberfb_predefined[] __initdata = {
  140. { "640x480-8", { /* Default 8 BPP mode (cyber8) */
  141. 640, 480, 640, 480, 0, 0, 8, 0,
  142. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  143. 0, 0, -1, -1, FB_ACCELF_TEXT, 39722, 40, 24, 32, 11, 96, 2,
  144. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  145. FB_VMODE_NONINTERLACED
  146. }},
  147. { "640x480-16", { /* Default 16 BPP mode (cyber16) */
  148. 640, 480, 640, 480, 0, 0, 16, 0,
  149. {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
  150. 0, 0, -1, -1, FB_ACCELF_TEXT, 39722, 40, 24, 32, 11, 96, 2,
  151. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  152. FB_VMODE_NONINTERLACED
  153. }},
  154. { "640x480-24", { /* Default 24 BPP mode */
  155. 640, 480, 640, 480, 0, 0, 24, 0,
  156. {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0},
  157. 0, 0, -1, -1, FB_ACCELF_TEXT, 39722, 40, 24, 32, 11, 96, 2,
  158. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  159. FB_VMODE_NONINTERLACED
  160. }},
  161. { "800x490-8", { /* Cybervision 8 bpp */
  162. /* NO Acceleration */
  163. 800, 490, 800, 490, 0, 0, 8, 0,
  164. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  165. 0, 0, -1, -1, FB_ACCEL_NONE, 33333, 80, 24, 23, 1, 56, 8,
  166. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  167. FB_VMODE_NONINTERLACED
  168. }},
  169. /* I can't test these with my monitor, but I suspect they will
  170. * be OK, since Antonio Santos indicated he had tested them in
  171. * his system.
  172. */
  173. { "800x600-8", { /* Cybervision 8 bpp */
  174. 800, 600, 800, 600, 0, 0, 8, 0,
  175. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  176. 0, 0, -1, -1, FB_ACCELF_TEXT, 27778, 64, 24, 22, 1, 72, 2,
  177. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  178. FB_VMODE_NONINTERLACED
  179. }},
  180. { "1024x768-8", { /* Cybervision 8 bpp */
  181. 1024, 768, 1024, 768, 0, 0, 8, 0,
  182. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  183. 0, 0, -1, -1, FB_ACCELF_TEXT, 16667, 224, 72, 60, 12, 168, 4,
  184. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  185. FB_VMODE_NONINTERLACED
  186. }},
  187. { "1152x886-8", { /* Cybervision 8 bpp */
  188. 1152, 886, 1152, 886, 0, 0, 8, 0,
  189. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  190. 0, 0, -1, -1, FB_ACCELF_TEXT, 15873, 184, 40, 24, 1, 56, 16,
  191. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  192. FB_VMODE_NONINTERLACED
  193. }},
  194. { "1280x1024-8", { /* Cybervision 8 bpp */
  195. 1280, 1024, 1280, 1024, 0, 0, 8, 0,
  196. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  197. 0, 0, -1, -1, FB_ACCELF_TEXT, 16667, 256, 48, 50, 12, 72, 4,
  198. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
  199. FB_VMODE_INTERLACED
  200. }}
  201. };
  202. #define NUM_TOTAL_MODES ARRAY_SIZE(cyberfb_predefined)
  203. static int Cyberfb_inverse = 0;
  204. /*
  205. * Some default modes
  206. */
  207. #define CYBER8_DEFMODE (0)
  208. #define CYBER16_DEFMODE (1)
  209. static struct fb_var_screeninfo cyberfb_default;
  210. static int cyberfb_usermode __initdata = 0;
  211. /*
  212. * Interface used by the world
  213. */
  214. int cyberfb_setup(char *options);
  215. static int cyberfb_get_fix(struct fb_fix_screeninfo *fix, int con,
  216. struct fb_info *info);
  217. static int cyberfb_get_var(struct fb_var_screeninfo *var, int con,
  218. struct fb_info *info);
  219. static int cyberfb_set_var(struct fb_var_screeninfo *var, int con,
  220. struct fb_info *info);
  221. static int cyberfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
  222. struct fb_info *info);
  223. static int cyberfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  224. u_int transp, struct fb_info *info);
  225. static int cyberfb_blank(int blank, struct fb_info *info);
  226. /*
  227. * Interface to the low level console driver
  228. */
  229. int cyberfb_init(void);
  230. static int Cyberfb_switch(int con, struct fb_info *info);
  231. static int Cyberfb_updatevar(int con, struct fb_info *info);
  232. /*
  233. * Text console acceleration
  234. */
  235. #ifdef FBCON_HAS_CFB8
  236. static struct display_switch fbcon_cyber8;
  237. #endif
  238. /*
  239. * Accelerated Functions used by the low level console driver
  240. */
  241. static void Cyber_WaitQueue(u_short fifo);
  242. static void Cyber_WaitBlit(void);
  243. static void Cyber_BitBLT(u_short curx, u_short cury, u_short destx,
  244. u_short desty, u_short width, u_short height,
  245. u_short mode);
  246. static void Cyber_RectFill(u_short x, u_short y, u_short width, u_short height,
  247. u_short mode, u_short color);
  248. #if 0
  249. static void Cyber_MoveCursor(u_short x, u_short y);
  250. #endif
  251. /*
  252. * Hardware Specific Routines
  253. */
  254. static int Cyber_init(void);
  255. static int Cyber_encode_fix(struct fb_fix_screeninfo *fix,
  256. struct cyberfb_par *par);
  257. static int Cyber_decode_var(struct fb_var_screeninfo *var,
  258. struct cyberfb_par *par);
  259. static int Cyber_encode_var(struct fb_var_screeninfo *var,
  260. struct cyberfb_par *par);
  261. static int Cyber_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
  262. u_int *transp, struct fb_info *info);
  263. /*
  264. * Internal routines
  265. */
  266. static void cyberfb_get_par(struct cyberfb_par *par);
  267. static void cyberfb_set_par(struct cyberfb_par *par);
  268. static int do_fb_set_var(struct fb_var_screeninfo *var, int isactive);
  269. static void cyberfb_set_disp(int con, struct fb_info *info);
  270. static int get_video_mode(const char *name);
  271. /* For cvision_core.c */
  272. static unsigned short cv64_compute_clock(unsigned long);
  273. static int cv_has_4mb (volatile unsigned char *);
  274. static void cv64_board_init (void);
  275. static void cv64_load_video_mode (struct fb_var_screeninfo *);
  276. /* -------------------- Hardware specific routines ------------------------- */
  277. /*
  278. * Initialization
  279. *
  280. * Set the default video mode for this chipset. If a video mode was
  281. * specified on the command line, it will override the default mode.
  282. */
  283. static int Cyber_init(void)
  284. {
  285. volatile unsigned char *regs = CyberRegs;
  286. volatile unsigned long *CursorBase;
  287. int i;
  288. DPRINTK("ENTER\n");
  289. /* Init local cmap as greyscale levels */
  290. for (i = 0; i < 256; i++) {
  291. Cyber_colour_table [i][0] = i;
  292. Cyber_colour_table [i][1] = i;
  293. Cyber_colour_table [i][2] = i;
  294. }
  295. /* Initialize the board and determine fbmem size */
  296. cv64_board_init();
  297. #ifdef CYBERFBDEBUG
  298. DPRINTK("Register state after initing board\n");
  299. cv64_dump();
  300. #endif
  301. /* Clear framebuffer memory */
  302. DPRINTK("Clear framebuffer memory\n");
  303. memset ((char *)CyberMem, 0, CyberSize);
  304. /* Disable hardware cursor */
  305. DPRINTK("Disable HW cursor\n");
  306. wb_64(regs, S3_CRTC_ADR, S3_REG_LOCK2);
  307. wb_64(regs, S3_CRTC_DATA, 0xa0);
  308. wb_64(regs, S3_CRTC_ADR, S3_HGC_MODE);
  309. wb_64(regs, S3_CRTC_DATA, 0x00);
  310. wb_64(regs, S3_CRTC_ADR, S3_HWGC_DX);
  311. wb_64(regs, S3_CRTC_DATA, 0x00);
  312. wb_64(regs, S3_CRTC_ADR, S3_HWGC_DY);
  313. wb_64(regs, S3_CRTC_DATA, 0x00);
  314. /* Initialize hardware cursor */
  315. DPRINTK("Init HW cursor\n");
  316. CursorBase = (u_long *)((char *)(CyberMem) + CyberSize - 0x400);
  317. for (i=0; i < 8; i++)
  318. {
  319. *(CursorBase +(i*4)) = 0xffffff00;
  320. *(CursorBase+1+(i*4)) = 0xffff0000;
  321. *(CursorBase+2+(i*4)) = 0xffff0000;
  322. *(CursorBase+3+(i*4)) = 0xffff0000;
  323. }
  324. for (i=8; i < 64; i++)
  325. {
  326. *(CursorBase +(i*4)) = 0xffff0000;
  327. *(CursorBase+1+(i*4)) = 0xffff0000;
  328. *(CursorBase+2+(i*4)) = 0xffff0000;
  329. *(CursorBase+3+(i*4)) = 0xffff0000;
  330. }
  331. cyberfb_setcolreg (255, 56<<8, 100<<8, 160<<8, 0, NULL /* unused */);
  332. cyberfb_setcolreg (254, 0, 0, 0, 0, NULL /* unused */);
  333. DPRINTK("EXIT\n");
  334. return 0;
  335. }
  336. /*
  337. * This function should fill in the `fix' structure based on the
  338. * values in the `par' structure.
  339. */
  340. static int Cyber_encode_fix(struct fb_fix_screeninfo *fix,
  341. struct cyberfb_par *par)
  342. {
  343. DPRINTK("ENTER\n");
  344. memset(fix, 0, sizeof(struct fb_fix_screeninfo));
  345. strcpy(fix->id, cyberfb_name);
  346. fix->smem_start = CyberMem_phys;
  347. fix->smem_len = CyberSize;
  348. fix->mmio_start = CyberRegs_phys;
  349. fix->mmio_len = 0x10000;
  350. fix->type = FB_TYPE_PACKED_PIXELS;
  351. fix->type_aux = 0;
  352. if (par->var.bits_per_pixel == 15 || par->var.bits_per_pixel == 16 ||
  353. par->var.bits_per_pixel == 24 || par->var.bits_per_pixel == 32) {
  354. fix->visual = FB_VISUAL_DIRECTCOLOR;
  355. } else {
  356. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  357. }
  358. fix->xpanstep = 0;
  359. fix->ypanstep = 0;
  360. fix->ywrapstep = 0;
  361. fix->line_length = 0;
  362. fix->accel = FB_ACCEL_S3_TRIO64;
  363. DPRINTK("EXIT\n");
  364. return(0);
  365. }
  366. /*
  367. * Fill the `par' structure based on the values in `var'.
  368. * TODO: Verify and adjust values, return -EINVAL if bad.
  369. */
  370. static int Cyber_decode_var(struct fb_var_screeninfo *var,
  371. struct cyberfb_par *par)
  372. {
  373. DPRINTK("ENTER\n");
  374. par->var.xres = var->xres;
  375. par->var.yres = var->yres;
  376. par->var.xres_virtual = var->xres_virtual;
  377. par->var.yres_virtual = var->yres_virtual;
  378. par->var.xoffset = var->xoffset;
  379. par->var.yoffset = var->yoffset;
  380. par->var.bits_per_pixel = var->bits_per_pixel;
  381. par->var.grayscale = var->grayscale;
  382. par->var.red = var->red;
  383. par->var.green = var->green;
  384. par->var.blue = var->blue;
  385. par->var.transp = var->transp;
  386. par->var.nonstd = var->nonstd;
  387. par->var.activate = var->activate;
  388. par->var.height = var->height;
  389. par->var.width = var->width;
  390. if (var->accel_flags & FB_ACCELF_TEXT) {
  391. par->var.accel_flags = FB_ACCELF_TEXT;
  392. } else {
  393. par->var.accel_flags = 0;
  394. }
  395. par->var.pixclock = var->pixclock;
  396. par->var.left_margin = var->left_margin;
  397. par->var.right_margin = var->right_margin;
  398. par->var.upper_margin = var->upper_margin;
  399. par->var.lower_margin = var->lower_margin;
  400. par->var.hsync_len = var->hsync_len;
  401. par->var.vsync_len = var->vsync_len;
  402. par->var.sync = var->sync;
  403. par->var.vmode = var->vmode;
  404. DPRINTK("EXIT\n");
  405. return(0);
  406. }
  407. /*
  408. * Fill the `var' structure based on the values in `par' and maybe
  409. * other values read out of the hardware.
  410. */
  411. static int Cyber_encode_var(struct fb_var_screeninfo *var,
  412. struct cyberfb_par *par)
  413. {
  414. DPRINTK("ENTER\n");
  415. var->xres = par->var.xres;
  416. var->yres = par->var.yres;
  417. var->xres_virtual = par->var.xres_virtual;
  418. var->yres_virtual = par->var.yres_virtual;
  419. var->xoffset = par->var.xoffset;
  420. var->yoffset = par->var.yoffset;
  421. var->bits_per_pixel = par->var.bits_per_pixel;
  422. var->grayscale = par->var.grayscale;
  423. var->red = par->var.red;
  424. var->green = par->var.green;
  425. var->blue = par->var.blue;
  426. var->transp = par->var.transp;
  427. var->nonstd = par->var.nonstd;
  428. var->activate = par->var.activate;
  429. var->height = par->var.height;
  430. var->width = par->var.width;
  431. var->accel_flags = par->var.accel_flags;
  432. var->pixclock = par->var.pixclock;
  433. var->left_margin = par->var.left_margin;
  434. var->right_margin = par->var.right_margin;
  435. var->upper_margin = par->var.upper_margin;
  436. var->lower_margin = par->var.lower_margin;
  437. var->hsync_len = par->var.hsync_len;
  438. var->vsync_len = par->var.vsync_len;
  439. var->sync = par->var.sync;
  440. var->vmode = par->var.vmode;
  441. DPRINTK("EXIT\n");
  442. return(0);
  443. }
  444. /*
  445. * Set a single color register. Return != 0 for invalid regno.
  446. */
  447. static int cyberfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  448. u_int transp, struct fb_info *info)
  449. {
  450. volatile unsigned char *regs = CyberRegs;
  451. /*DPRINTK("ENTER\n");*/
  452. if (regno > 255) {
  453. DPRINTK("EXIT - Register # > 255\n");
  454. return (1);
  455. }
  456. wb_64(regs, 0x3c8, (unsigned char) regno);
  457. red >>= 10;
  458. green >>= 10;
  459. blue >>= 10;
  460. Cyber_colour_table [regno][0] = red;
  461. Cyber_colour_table [regno][1] = green;
  462. Cyber_colour_table [regno][2] = blue;
  463. wb_64(regs, 0x3c9, red);
  464. wb_64(regs, 0x3c9, green);
  465. wb_64(regs, 0x3c9, blue);
  466. /*DPRINTK("EXIT\n");*/
  467. return (0);
  468. }
  469. /*
  470. * Read a single color register and split it into
  471. * colors/transparent. Return != 0 for invalid regno.
  472. */
  473. static int Cyber_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
  474. u_int *transp, struct fb_info *info)
  475. {
  476. int t;
  477. /*DPRINTK("ENTER\n");*/
  478. if (regno > 255) {
  479. DPRINTK("EXIT - Register # > 255\n");
  480. return (1);
  481. }
  482. /* ARB This shifting & oring seems VERY strange */
  483. t = Cyber_colour_table [regno][0];
  484. *red = (t<<10) | (t<<4) | (t>>2);
  485. t = Cyber_colour_table [regno][1];
  486. *green = (t<<10) | (t<<4) | (t>>2);
  487. t = Cyber_colour_table [regno][2];
  488. *blue = (t<<10) | (t<<4) | (t>>2);
  489. *transp = 0;
  490. /*DPRINTK("EXIT\n");*/
  491. return (0);
  492. }
  493. /*
  494. * (Un)Blank the screen
  495. * blank: 1 = zero fb cmap
  496. * 0 = restore fb cmap from local cmap
  497. */
  498. static int cyberfb_blank(int blank, struct fb_info *info)
  499. {
  500. volatile unsigned char *regs = CyberRegs;
  501. int i;
  502. DPRINTK("ENTER\n");
  503. #if 0
  504. /* Blank by turning gfx off */
  505. gfx_on_off (1, regs);
  506. #else
  507. if (blank) {
  508. for (i = 0; i < 256; i++) {
  509. wb_64(regs, 0x3c8, (unsigned char) i);
  510. /* ARB Pale red to detect this blanking method */
  511. wb_64(regs, 0x3c9, 48);
  512. wb_64(regs, 0x3c9, 0);
  513. wb_64(regs, 0x3c9, 0);
  514. }
  515. } else {
  516. for (i = 0; i < 256; i++) {
  517. wb_64(regs, 0x3c8, (unsigned char) i);
  518. wb_64(regs, 0x3c9, Cyber_colour_table[i][0]);
  519. wb_64(regs, 0x3c9, Cyber_colour_table[i][1]);
  520. wb_64(regs, 0x3c9, Cyber_colour_table[i][2]);
  521. }
  522. }
  523. #endif
  524. DPRINTK("EXIT\n");
  525. return 0;
  526. }
  527. /**************************************************************
  528. * We are waiting for "fifo" FIFO-slots empty
  529. */
  530. static void Cyber_WaitQueue (u_short fifo)
  531. {
  532. unsigned short status;
  533. DPRINTK("ENTER\n");
  534. do {
  535. status = *((u_short volatile *)(CyberRegs + S3_GP_STAT));
  536. } while (status & fifo);
  537. DPRINTK("EXIT\n");
  538. }
  539. /**************************************************************
  540. * We are waiting for Hardware (Graphics Engine) not busy
  541. */
  542. static void Cyber_WaitBlit (void)
  543. {
  544. unsigned short status;
  545. DPRINTK("ENTER\n");
  546. do {
  547. status = *((u_short volatile *)(CyberRegs + S3_GP_STAT));
  548. } while (status & S3_HDW_BUSY);
  549. DPRINTK("EXIT\n");
  550. }
  551. /**************************************************************
  552. * BitBLT - Through the Plane
  553. */
  554. static void Cyber_BitBLT (u_short curx, u_short cury, u_short destx,
  555. u_short desty, u_short width, u_short height,
  556. u_short mode)
  557. {
  558. volatile unsigned char *regs = CyberRegs;
  559. u_short blitcmd = S3_BITBLT;
  560. DPRINTK("ENTER\n");
  561. /* Set drawing direction */
  562. /* -Y, X maj, -X (default) */
  563. if (curx > destx) {
  564. blitcmd |= 0x0020; /* Drawing direction +X */
  565. } else {
  566. curx += (width - 1);
  567. destx += (width - 1);
  568. }
  569. if (cury > desty) {
  570. blitcmd |= 0x0080; /* Drawing direction +Y */
  571. } else {
  572. cury += (height - 1);
  573. desty += (height - 1);
  574. }
  575. Cyber_WaitQueue (0x8000);
  576. *((u_short volatile *)(regs + S3_PIXEL_CNTL)) = 0xa000;
  577. *((u_short volatile *)(regs + S3_FRGD_MIX)) = (0x0060 | mode);
  578. *((u_short volatile *)(regs + S3_CUR_X)) = curx;
  579. *((u_short volatile *)(regs + S3_CUR_Y)) = cury;
  580. *((u_short volatile *)(regs + S3_DESTX_DIASTP)) = destx;
  581. *((u_short volatile *)(regs + S3_DESTY_AXSTP)) = desty;
  582. *((u_short volatile *)(regs + S3_MIN_AXIS_PCNT)) = height - 1;
  583. *((u_short volatile *)(regs + S3_MAJ_AXIS_PCNT)) = width - 1;
  584. *((u_short volatile *)(regs + S3_CMD)) = blitcmd;
  585. DPRINTK("EXIT\n");
  586. }
  587. /**************************************************************
  588. * Rectangle Fill Solid
  589. */
  590. static void Cyber_RectFill (u_short x, u_short y, u_short width,
  591. u_short height, u_short mode, u_short color)
  592. {
  593. volatile unsigned char *regs = CyberRegs;
  594. u_short blitcmd = S3_FILLEDRECT;
  595. DPRINTK("ENTER\n");
  596. Cyber_WaitQueue (0x8000);
  597. *((u_short volatile *)(regs + S3_PIXEL_CNTL)) = 0xa000;
  598. *((u_short volatile *)(regs + S3_FRGD_MIX)) = (0x0020 | mode);
  599. *((u_short volatile *)(regs + S3_MULT_MISC)) = 0xe000;
  600. *((u_short volatile *)(regs + S3_FRGD_COLOR)) = color;
  601. *((u_short volatile *)(regs + S3_CUR_X)) = x;
  602. *((u_short volatile *)(regs + S3_CUR_Y)) = y;
  603. *((u_short volatile *)(regs + S3_MIN_AXIS_PCNT)) = height - 1;
  604. *((u_short volatile *)(regs + S3_MAJ_AXIS_PCNT)) = width - 1;
  605. *((u_short volatile *)(regs + S3_CMD)) = blitcmd;
  606. DPRINTK("EXIT\n");
  607. }
  608. #if 0
  609. /**************************************************************
  610. * Move cursor to x, y
  611. */
  612. static void Cyber_MoveCursor (u_short x, u_short y)
  613. {
  614. volatile unsigned char *regs = CyberRegs;
  615. DPRINTK("ENTER\n");
  616. *(regs + S3_CRTC_ADR) = 0x39;
  617. *(regs + S3_CRTC_DATA) = 0xa0;
  618. *(regs + S3_CRTC_ADR) = S3_HWGC_ORGX_H;
  619. *(regs + S3_CRTC_DATA) = (char)((x & 0x0700) >> 8);
  620. *(regs + S3_CRTC_ADR) = S3_HWGC_ORGX_L;
  621. *(regs + S3_CRTC_DATA) = (char)(x & 0x00ff);
  622. *(regs + S3_CRTC_ADR) = S3_HWGC_ORGY_H;
  623. *(regs + S3_CRTC_DATA) = (char)((y & 0x0700) >> 8);
  624. *(regs + S3_CRTC_ADR) = S3_HWGC_ORGY_L;
  625. *(regs + S3_CRTC_DATA) = (char)(y & 0x00ff);
  626. DPRINTK("EXIT\n");
  627. }
  628. #endif
  629. /* -------------------- Generic routines ---------------------------------- */
  630. /*
  631. * Fill the hardware's `par' structure.
  632. */
  633. static void cyberfb_get_par(struct cyberfb_par *par)
  634. {
  635. DPRINTK("ENTER\n");
  636. if (current_par_valid) {
  637. *par = current_par;
  638. } else {
  639. Cyber_decode_var(&cyberfb_default, par);
  640. }
  641. DPRINTK("EXIT\n");
  642. }
  643. static void cyberfb_set_par(struct cyberfb_par *par)
  644. {
  645. DPRINTK("ENTER\n");
  646. current_par = *par;
  647. current_par_valid = 1;
  648. DPRINTK("EXIT\n");
  649. }
  650. static void cyber_set_video(struct fb_var_screeninfo *var)
  651. {
  652. /* Load the video mode defined by the 'var' data */
  653. cv64_load_video_mode (var);
  654. #ifdef CYBERFBDEBUG
  655. DPRINTK("Register state after loading video mode\n");
  656. cv64_dump();
  657. #endif
  658. }
  659. static int do_fb_set_var(struct fb_var_screeninfo *var, int isactive)
  660. {
  661. int err, activate;
  662. struct cyberfb_par par;
  663. DPRINTK("ENTER\n");
  664. if ((err = Cyber_decode_var(var, &par))) {
  665. DPRINTK("EXIT - decode_var failed\n");
  666. return(err);
  667. }
  668. activate = var->activate;
  669. if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW && isactive)
  670. cyberfb_set_par(&par);
  671. Cyber_encode_var(var, &par);
  672. var->activate = activate;
  673. cyber_set_video(var);
  674. DPRINTK("EXIT\n");
  675. return 0;
  676. }
  677. /*
  678. * Get the Fixed Part of the Display
  679. */
  680. static int cyberfb_get_fix(struct fb_fix_screeninfo *fix, int con,
  681. struct fb_info *info)
  682. {
  683. struct cyberfb_par par;
  684. int error = 0;
  685. DPRINTK("ENTER\n");
  686. if (con == -1) {
  687. cyberfb_get_par(&par);
  688. } else {
  689. error = Cyber_decode_var(&fb_display[con].var, &par);
  690. }
  691. DPRINTK("EXIT\n");
  692. return(error ? error : Cyber_encode_fix(fix, &par));
  693. }
  694. /*
  695. * Get the User Defined Part of the Display
  696. */
  697. static int cyberfb_get_var(struct fb_var_screeninfo *var, int con,
  698. struct fb_info *info)
  699. {
  700. struct cyberfb_par par;
  701. int error = 0;
  702. DPRINTK("ENTER\n");
  703. if (con == -1) {
  704. cyberfb_get_par(&par);
  705. error = Cyber_encode_var(var, &par);
  706. disp.var = *var; /* ++Andre: don't know if this is the right place */
  707. } else {
  708. *var = fb_display[con].var;
  709. }
  710. DPRINTK("EXIT\n");
  711. return(error);
  712. }
  713. static void cyberfb_set_disp(int con, struct fb_info *info)
  714. {
  715. struct fb_fix_screeninfo fix;
  716. struct display *display;
  717. DPRINTK("ENTER\n");
  718. if (con >= 0)
  719. display = &fb_display[con];
  720. else
  721. display = &disp; /* used during initialization */
  722. cyberfb_get_fix(&fix, con, info);
  723. if (con == -1)
  724. con = 0;
  725. display->visual = fix.visual;
  726. display->type = fix.type;
  727. display->type_aux = fix.type_aux;
  728. display->ypanstep = fix.ypanstep;
  729. display->ywrapstep = fix.ywrapstep;
  730. display->can_soft_blank = 1;
  731. display->inverse = Cyberfb_inverse;
  732. switch (display->var.bits_per_pixel) {
  733. #ifdef FBCON_HAS_CFB8
  734. case 8:
  735. if (display->var.accel_flags & FB_ACCELF_TEXT) {
  736. display->dispsw = &fbcon_cyber8;
  737. #warning FIXME: We should reinit the graphics engine here
  738. } else
  739. display->dispsw = &fbcon_cfb8;
  740. break;
  741. #endif
  742. #ifdef FBCON_HAS_CFB16
  743. case 16:
  744. display->dispsw = &fbcon_cfb16;
  745. break;
  746. #endif
  747. default:
  748. display->dispsw = NULL;
  749. break;
  750. }
  751. DPRINTK("EXIT\n");
  752. }
  753. /*
  754. * Set the User Defined Part of the Display
  755. */
  756. static int cyberfb_set_var(struct fb_var_screeninfo *var, int con,
  757. struct fb_info *info)
  758. {
  759. int err, oldxres, oldyres, oldvxres, oldvyres, oldbpp, oldaccel;
  760. DPRINTK("ENTER\n");
  761. if ((err = do_fb_set_var(var, con == info->currcon))) {
  762. DPRINTK("EXIT - do_fb_set_var failed\n");
  763. return(err);
  764. }
  765. if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
  766. oldxres = fb_display[con].var.xres;
  767. oldyres = fb_display[con].var.yres;
  768. oldvxres = fb_display[con].var.xres_virtual;
  769. oldvyres = fb_display[con].var.yres_virtual;
  770. oldbpp = fb_display[con].var.bits_per_pixel;
  771. oldaccel = fb_display[con].var.accel_flags;
  772. fb_display[con].var = *var;
  773. if (oldxres != var->xres || oldyres != var->yres ||
  774. oldvxres != var->xres_virtual ||
  775. oldvyres != var->yres_virtual ||
  776. oldbpp != var->bits_per_pixel ||
  777. oldaccel != var->accel_flags) {
  778. cyberfb_set_disp(con, info);
  779. (*fb_info.changevar)(con);
  780. fb_alloc_cmap(&fb_display[con].cmap, 0, 0);
  781. do_install_cmap(con, info);
  782. }
  783. }
  784. var->activate = 0;
  785. DPRINTK("EXIT\n");
  786. return(0);
  787. }
  788. /*
  789. * Get the Colormap
  790. */
  791. static int cyberfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
  792. struct fb_info *info)
  793. {
  794. DPRINTK("ENTER\n");
  795. if (con == info->currcon) { /* current console? */
  796. DPRINTK("EXIT - console is current console\n");
  797. return(fb_get_cmap(cmap, kspc, Cyber_getcolreg, info));
  798. } else if (fb_display[con].cmap.len) { /* non default colormap? */
  799. DPRINTK("Use console cmap\n");
  800. fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
  801. } else {
  802. DPRINTK("Use default cmap\n");
  803. fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),
  804. cmap, kspc ? 0 : 2);
  805. }
  806. DPRINTK("EXIT\n");
  807. return(0);
  808. }
  809. static struct fb_ops cyberfb_ops = {
  810. .owner = THIS_MODULE,
  811. .fb_get_fix = cyberfb_get_fix,
  812. .fb_get_var = cyberfb_get_var,
  813. .fb_set_var = cyberfb_set_var,
  814. .fb_get_cmap = cyberfb_get_cmap,
  815. .fb_set_cmap = gen_set_cmap,
  816. .fb_setcolreg = cyberfb_setcolreg,
  817. .fb_blank = cyberfb_blank,
  818. };
  819. int __init cyberfb_setup(char *options)
  820. {
  821. char *this_opt;
  822. DPRINTK("ENTER\n");
  823. fb_info.fontname[0] = '\0';
  824. if (!options || !*options) {
  825. DPRINTK("EXIT - no options\n");
  826. return 0;
  827. }
  828. while ((this_opt = strsep(&options, ",")) != NULL) {
  829. if (!*this_opt)
  830. continue;
  831. if (!strcmp(this_opt, "inverse")) {
  832. Cyberfb_inverse = 1;
  833. fb_invert_cmaps();
  834. } else if (!strncmp(this_opt, "font:", 5)) {
  835. strcpy(fb_info.fontname, this_opt+5);
  836. } else if (!strcmp (this_opt, "cyber8")) {
  837. cyberfb_default = cyberfb_predefined[CYBER8_DEFMODE].var;
  838. cyberfb_usermode = 1;
  839. } else if (!strcmp (this_opt, "cyber16")) {
  840. cyberfb_default = cyberfb_predefined[CYBER16_DEFMODE].var;
  841. cyberfb_usermode = 1;
  842. } else get_video_mode(this_opt);
  843. }
  844. DPRINTK("default mode: xres=%d, yres=%d, bpp=%d\n",
  845. cyberfb_default.xres,
  846. cyberfb_default.yres,
  847. cyberfb_default.bits_per_pixel);
  848. DPRINTK("EXIT\n");
  849. return 0;
  850. }
  851. /*
  852. * Initialization
  853. */
  854. int __init cyberfb_init(void)
  855. {
  856. unsigned long board_addr, board_size;
  857. struct cyberfb_par par;
  858. struct zorro_dev *z = NULL;
  859. DPRINTK("ENTER\n");
  860. while ((z = zorro_find_device(ZORRO_PROD_PHASE5_CYBERVISION64, z))) {
  861. board_addr = z->resource.start;
  862. board_size = z->resource.end-z->resource.start+1;
  863. CyberMem_phys = board_addr + 0x01400000;
  864. CyberRegs_phys = CyberMem_phys + 0x00c00000;
  865. if (!request_mem_region(CyberRegs_phys, 0x10000, "S3 Trio64"))
  866. continue;
  867. if (!request_mem_region(CyberMem_phys, 0x400000, "RAM")) {
  868. release_mem_region(CyberRegs_phys, 0x10000);
  869. continue;
  870. }
  871. DPRINTK("board_addr=%08lx\n", board_addr);
  872. DPRINTK("board_size=%08lx\n", board_size);
  873. CyberBase = ioremap(board_addr, board_size);
  874. CyberRegs = CyberBase + 0x02000000;
  875. CyberMem = CyberBase + 0x01400000;
  876. DPRINTK("CyberBase=%08lx CyberRegs=%08lx CyberMem=%08lx\n",
  877. CyberBase, (long unsigned int)CyberRegs, CyberMem);
  878. #ifdef CYBERFBDEBUG
  879. DPRINTK("Register state just after mapping memory\n");
  880. cv64_dump();
  881. #endif
  882. strcpy(fb_info.modename, cyberfb_name);
  883. fb_info.changevar = NULL;
  884. fb_info.fbops = &cyberfb_ops;
  885. fb_info.screen_base = (unsigned char *)CyberMem;
  886. fb_info.disp = &disp;
  887. fb_info.currcon = -1;
  888. fb_info.switch_con = &Cyberfb_switch;
  889. fb_info.updatevar = &Cyberfb_updatevar;
  890. Cyber_init();
  891. /* ++Andre: set cyberfb default mode */
  892. if (!cyberfb_usermode) {
  893. cyberfb_default = cyberfb_predefined[CYBER8_DEFMODE].var;
  894. DPRINTK("Use default cyber8 mode\n");
  895. }
  896. Cyber_decode_var(&cyberfb_default, &par);
  897. Cyber_encode_var(&cyberfb_default, &par);
  898. do_fb_set_var(&cyberfb_default, 1);
  899. cyberfb_get_var(&fb_display[0].var, -1, &fb_info);
  900. cyberfb_set_disp(-1, &fb_info);
  901. do_install_cmap(0, &fb_info);
  902. if (register_framebuffer(&fb_info) < 0) {
  903. DPRINTK("EXIT - register_framebuffer failed\n");
  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