retz3fb.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587
  1. /*
  2. * Linux/drivers/video/retz3fb.c -- RetinaZ3 frame buffer device
  3. *
  4. * Copyright (C) 1997 Jes Sorensen
  5. *
  6. * This file is based on the CyberVision64 frame buffer device and
  7. * the generic Cirrus Logic driver.
  8. *
  9. * cyberfb.c: Copyright (C) 1996 Martin Apel,
  10. * Geert Uytterhoeven
  11. * clgen.c: Copyright (C) 1996 Frank Neumann
  12. *
  13. * History:
  14. * - 22 Jan 97: Initial work
  15. * - 14 Feb 97: Screen initialization works somewhat, still only
  16. * 8-bit packed pixel is supported.
  17. *
  18. * This file is subject to the terms and conditions of the GNU General Public
  19. * License. See the file COPYING in the main directory of this archive
  20. * for more details.
  21. */
  22. #include <linux/module.h>
  23. #include <linux/kernel.h>
  24. #include <linux/errno.h>
  25. #include <linux/string.h>
  26. #include <linux/mm.h>
  27. #include <linux/tty.h>
  28. #include <linux/slab.h>
  29. #include <linux/delay.h>
  30. #include <linux/fb.h>
  31. #include <linux/zorro.h>
  32. #include <linux/init.h>
  33. #include <asm/uaccess.h>
  34. #include <asm/system.h>
  35. #include <asm/irq.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/io.h>
  38. #include <video/fbcon.h>
  39. #include <video/fbcon-cfb8.h>
  40. #include <video/fbcon-cfb16.h>
  41. #include "retz3fb.h"
  42. /* #define DEBUG if(1) */
  43. #define DEBUG if(0)
  44. /*
  45. * Reserve space for one pattern line.
  46. *
  47. * For the time being we only support 4MB boards!
  48. */
  49. #define PAT_MEM_SIZE 16*3
  50. #define PAT_MEM_OFF (4*1024*1024 - PAT_MEM_SIZE)
  51. struct retz3fb_par {
  52. int xres;
  53. int yres;
  54. int xres_vir;
  55. int yres_vir;
  56. int xoffset;
  57. int yoffset;
  58. int bpp;
  59. struct fb_bitfield red;
  60. struct fb_bitfield green;
  61. struct fb_bitfield blue;
  62. struct fb_bitfield transp;
  63. int pixclock;
  64. int left_margin; /* time from sync to picture */
  65. int right_margin; /* time from picture to sync */
  66. int upper_margin; /* time from sync to picture */
  67. int lower_margin;
  68. int hsync_len; /* length of horizontal sync */
  69. int vsync_len; /* length of vertical sync */
  70. int vmode;
  71. int accel;
  72. };
  73. struct display_data {
  74. long h_total; /* Horizontal Total */
  75. long h_sstart; /* Horizontal Sync Start */
  76. long h_sstop; /* Horizontal Sync Stop */
  77. long h_bstart; /* Horizontal Blank Start */
  78. long h_bstop; /* Horizontal Blank Stop */
  79. long h_dispend; /* Horizontal Display End */
  80. long v_total; /* Vertical Total */
  81. long v_sstart; /* Vertical Sync Start */
  82. long v_sstop; /* Vertical Sync Stop */
  83. long v_bstart; /* Vertical Blank Start */
  84. long v_bstop; /* Vertical Blank Stop */
  85. long v_dispend; /* Horizontal Display End */
  86. };
  87. struct retz3_fb_info {
  88. struct fb_info info;
  89. unsigned char *base;
  90. unsigned char *fbmem;
  91. unsigned long fbsize;
  92. volatile unsigned char *regs;
  93. unsigned long physfbmem;
  94. unsigned long physregs;
  95. int current_par_valid; /* set to 0 by memset */
  96. int blitbusy;
  97. struct display disp;
  98. struct retz3fb_par current_par;
  99. unsigned char color_table [256][3];
  100. };
  101. static char fontname[40] __initdata = { 0 };
  102. #define retz3info(info) ((struct retz3_fb_info *)(info))
  103. #define fbinfo(info) ((struct fb_info *)(info))
  104. /*
  105. * Frame Buffer Name
  106. */
  107. static char retz3fb_name[16] = "RetinaZ3";
  108. /*
  109. * A small info on how to convert XFree86 timing values into fb
  110. * timings - by Frank Neumann:
  111. *
  112. An XFree86 mode line consists of the following fields:
  113. "800x600" 50 800 856 976 1040 600 637 643 666
  114. < name > DCF HR SH1 SH2 HFL VR SV1 SV2 VFL
  115. The fields in the fb_var_screeninfo structure are:
  116. unsigned long pixclock; * pixel clock in ps (pico seconds) *
  117. unsigned long left_margin; * time from sync to picture *
  118. unsigned long right_margin; * time from picture to sync *
  119. unsigned long upper_margin; * time from sync to picture *
  120. unsigned long lower_margin;
  121. unsigned long hsync_len; * length of horizontal sync *
  122. unsigned long vsync_len; * length of vertical sync *
  123. 1) Pixelclock:
  124. xfree: in MHz
  125. fb: In Picoseconds (ps)
  126. pixclock = 1000000 / DCF
  127. 2) horizontal timings:
  128. left_margin = HFL - SH2
  129. right_margin = SH1 - HR
  130. hsync_len = SH2 - SH1
  131. 3) vertical timings:
  132. upper_margin = VFL - SV2
  133. lower_margin = SV1 - VR
  134. vsync_len = SV2 - SV1
  135. Good examples for VESA timings can be found in the XFree86 source tree,
  136. under "programs/Xserver/hw/xfree86/doc/modeDB.txt".
  137. */
  138. /*
  139. * Predefined Video Modes
  140. */
  141. static struct {
  142. const char *name;
  143. struct fb_var_screeninfo var;
  144. } retz3fb_predefined[] __initdata = {
  145. /*
  146. * NB: it is very important to adjust the pixel-clock to the color-depth.
  147. */
  148. {
  149. "640x480", { /* 640x480, 8 bpp */
  150. 640, 480, 640, 480, 0, 0, 8, 0,
  151. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  152. 0, 0, -1, -1, FB_ACCEL_NONE, 39722, 48, 16, 33, 10, 96, 2,
  153. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED
  154. }
  155. },
  156. /*
  157. ModeLine "800x600" 36 800 824 896 1024 600 601 603 625
  158. < name > DCF HR SH1 SH2 HFL VR SV1 SV2 VFL
  159. */
  160. {
  161. "800x600", { /* 800x600, 8 bpp */
  162. 800, 600, 800, 600, 0, 0, 8, 0,
  163. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  164. 0, 0, -1, -1, FB_ACCELF_TEXT, 27778, 64, 24, 22, 1, 120, 2,
  165. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  166. }
  167. },
  168. {
  169. "800x600-60", { /* 800x600, 8 bpp */
  170. 800, 600, 800, 600, 0, 0, 8, 0,
  171. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  172. 0, 0, -1, -1, FB_ACCELF_TEXT, 25000, 88, 40, 23, 1, 128, 4,
  173. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  174. }
  175. },
  176. {
  177. "800x600-70", { /* 800x600, 8 bpp */
  178. 800, 600, 800, 600, 0, 0, 8, 0,
  179. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  180. 0, 0, -1, -1, FB_ACCELF_TEXT, 22272, 40, 24, 15, 9, 144, 12,
  181. FB_SYNC_COMP_HIGH_ACT, FB_VMODE_NONINTERLACED
  182. }
  183. },
  184. /*
  185. ModeLine "1024x768i" 45 1024 1064 1224 1264 768 777 785 817 interlace
  186. < name > DCF HR SH1 SH2 HFL VR SV1 SV2 VFL
  187. */
  188. {
  189. "1024x768i", { /* 1024x768, 8 bpp, interlaced */
  190. 1024, 768, 1024, 768, 0, 0, 8, 0,
  191. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  192. 0, 0, -1, -1, FB_ACCELF_TEXT, 22222, 40, 40, 32, 9, 160, 8,
  193. FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_INTERLACED
  194. }
  195. },
  196. {
  197. "1024x768", {
  198. 1024, 768, 1024, 768, 0, 0, 8, 0,
  199. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  200. 0, 0, -1, -1, FB_ACCEL_NONE, 12500, 92, 112, 31, 2, 204, 4,
  201. FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  202. }
  203. },
  204. {
  205. "640x480-16", { /* 640x480, 16 bpp */
  206. 640, 480, 640, 480, 0, 0, 16, 0,
  207. {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
  208. 0, 0, -1, -1, 0, 38461/2, 28, 32, 12, 10, 96, 2,
  209. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED
  210. }
  211. },
  212. {
  213. "640x480-24", { /* 640x480, 24 bpp */
  214. 640, 480, 640, 480, 0, 0, 24, 0,
  215. {8, 8, 8}, {8, 8, 8}, {8, 8, 8}, {0, 0, 0},
  216. 0, 0, -1, -1, 0, 38461/3, 28, 32, 12, 10, 96, 2,
  217. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED
  218. }
  219. },
  220. };
  221. #define NUM_TOTAL_MODES ARRAY_SIZE(retz3fb_predefined)
  222. static struct fb_var_screeninfo retz3fb_default;
  223. static int z3fb_inverse = 0;
  224. static int z3fb_mode __initdata = 0;
  225. /*
  226. * Interface used by the world
  227. */
  228. int retz3fb_setup(char *options);
  229. static int retz3fb_get_fix(struct fb_fix_screeninfo *fix, int con,
  230. struct fb_info *info);
  231. static int retz3fb_get_var(struct fb_var_screeninfo *var, int con,
  232. struct fb_info *info);
  233. static int retz3fb_set_var(struct fb_var_screeninfo *var, int con,
  234. struct fb_info *info);
  235. static int retz3fb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
  236. struct fb_info *info);
  237. static int retz3fb_setcolreg(unsigned int regno, unsigned int red,
  238. unsigned int green, unsigned int blue,
  239. unsigned int transp, struct fb_info *info);
  240. static int retz3fb_blank(int blank, struct fb_info *info);
  241. /*
  242. * Interface to the low level console driver
  243. */
  244. int retz3fb_init(void);
  245. static int z3fb_switch(int con, struct fb_info *info);
  246. static int z3fb_updatevar(int con, struct fb_info *info);
  247. /*
  248. * Text console acceleration
  249. */
  250. #ifdef FBCON_HAS_CFB8
  251. static struct display_switch fbcon_retz3_8;
  252. #endif
  253. /*
  254. * Accelerated Functions used by the low level console driver
  255. */
  256. static void retz3_bitblt(struct display *p,
  257. unsigned short curx, unsigned short cury, unsigned
  258. short destx, unsigned short desty, unsigned short
  259. width, unsigned short height, unsigned short cmd,
  260. unsigned short mask);
  261. /*
  262. * Hardware Specific Routines
  263. */
  264. static int retz3_encode_fix(struct fb_info *info,
  265. struct fb_fix_screeninfo *fix,
  266. struct retz3fb_par *par);
  267. static int retz3_decode_var(struct fb_var_screeninfo *var,
  268. struct retz3fb_par *par);
  269. static int retz3_encode_var(struct fb_var_screeninfo *var,
  270. struct retz3fb_par *par);
  271. static int retz3_getcolreg(unsigned int regno, unsigned int *red,
  272. unsigned int *green, unsigned int *blue,
  273. unsigned int *transp, struct fb_info *info);
  274. /*
  275. * Internal routines
  276. */
  277. static void retz3fb_get_par(struct fb_info *info, struct retz3fb_par *par);
  278. static void retz3fb_set_par(struct fb_info *info, struct retz3fb_par *par);
  279. static int do_fb_set_var(struct fb_info *info,
  280. struct fb_var_screeninfo *var, int isactive);
  281. static void retz3fb_set_disp(int con, struct fb_info *info);
  282. static int get_video_mode(const char *name);
  283. /* -------------------- Hardware specific routines ------------------------- */
  284. static unsigned short find_fq(unsigned int freq)
  285. {
  286. unsigned long f;
  287. long tmp;
  288. long prev = 0x7fffffff;
  289. long n2, n1 = 3;
  290. unsigned long m;
  291. unsigned short res = 0;
  292. if (freq <= 31250000)
  293. n2 = 3;
  294. else if (freq <= 62500000)
  295. n2 = 2;
  296. else if (freq <= 125000000)
  297. n2 = 1;
  298. else if (freq <= 250000000)
  299. n2 = 0;
  300. else
  301. return 0;
  302. do {
  303. f = freq >> (10 - n2);
  304. m = (f * n1) / (14318180/1024);
  305. if (m > 129)
  306. break;
  307. tmp = (((m * 14318180) >> n2) / n1) - freq;
  308. if (tmp < 0)
  309. tmp = -tmp;
  310. if (tmp < prev) {
  311. prev = tmp;
  312. res = (((n2 << 5) | (n1-2)) << 8) | (m-2);
  313. }
  314. } while ( (++n1) <= 21);
  315. return res;
  316. }
  317. static int retz3_set_video(struct fb_info *info,
  318. struct fb_var_screeninfo *var,
  319. struct retz3fb_par *par)
  320. {
  321. volatile unsigned char *regs = retz3info(info)->regs;
  322. unsigned int freq;
  323. int xres, hfront, hsync, hback;
  324. int yres, vfront, vsync, vback;
  325. unsigned char tmp;
  326. unsigned short best_freq;
  327. struct display_data data;
  328. short clocksel = 0; /* Apparantly this is always zero */
  329. int bpp = var->bits_per_pixel;
  330. /*
  331. * XXX
  332. */
  333. if (bpp == 24)
  334. return 0;
  335. if ((bpp != 8) && (bpp != 16) && (bpp != 24))
  336. return -EFAULT;
  337. par->xoffset = 0;
  338. par->yoffset = 0;
  339. xres = var->xres * bpp / 4;
  340. hfront = var->right_margin * bpp / 4;
  341. hsync = var->hsync_len * bpp / 4;
  342. hback = var->left_margin * bpp / 4;
  343. if (var->vmode & FB_VMODE_DOUBLE)
  344. {
  345. yres = var->yres * 2;
  346. vfront = var->lower_margin * 2;
  347. vsync = var->vsync_len * 2;
  348. vback = var->upper_margin * 2;
  349. }
  350. else if (var->vmode & FB_VMODE_INTERLACED)
  351. {
  352. yres = (var->yres + 1) / 2;
  353. vfront = (var->lower_margin + 1) / 2;
  354. vsync = (var->vsync_len + 1) / 2;
  355. vback = (var->upper_margin + 1) / 2;
  356. }
  357. else
  358. {
  359. yres = var->yres; /* -1 ? */
  360. vfront = var->lower_margin;
  361. vsync = var->vsync_len;
  362. vback = var->upper_margin;
  363. }
  364. data.h_total = (hback / 8) + (xres / 8)
  365. + (hfront / 8) + (hsync / 8) - 1 /* + 1 */;
  366. data.h_dispend = ((xres + bpp - 1)/ 8) - 1;
  367. data.h_bstart = xres / 8 - 1 /* + 1 */;
  368. data.h_bstop = data.h_total+1 + 2 + 1;
  369. data.h_sstart = (xres / 8) + (hfront / 8) + 1;
  370. data.h_sstop = (xres / 8) + (hfront / 8) + (hsync / 8) + 1;
  371. data.v_total = yres + vfront + vsync + vback - 1;
  372. data.v_dispend = yres - 1;
  373. data.v_bstart = yres - 1;
  374. data.v_bstop = data.v_total;
  375. data.v_sstart = yres + vfront - 1 - 2;
  376. data.v_sstop = yres + vfront + vsync - 1;
  377. #if 0 /* testing */
  378. printk("HBS: %i\n", data.h_bstart);
  379. printk("HSS: %i\n", data.h_sstart);
  380. printk("HSE: %i\n", data.h_sstop);
  381. printk("HBE: %i\n", data.h_bstop);
  382. printk("HT: %i\n", data.h_total);
  383. printk("hsync: %i\n", hsync);
  384. printk("hfront: %i\n", hfront);
  385. printk("hback: %i\n", hback);
  386. printk("VBS: %i\n", data.v_bstart);
  387. printk("VSS: %i\n", data.v_sstart);
  388. printk("VSE: %i\n", data.v_sstop);
  389. printk("VBE: %i\n", data.v_bstop);
  390. printk("VT: %i\n", data.v_total);
  391. printk("vsync: %i\n", vsync);
  392. printk("vfront: %i\n", vfront);
  393. printk("vback: %i\n", vback);
  394. #endif
  395. if (data.v_total >= 1024)
  396. printk(KERN_ERR "MAYDAY: v_total >= 1024; bailing out!\n");
  397. reg_w(regs, GREG_MISC_OUTPUT_W, 0xe3 | ((clocksel & 3) * 0x04));
  398. reg_w(regs, GREG_FEATURE_CONTROL_W, 0x00);
  399. seq_w(regs, SEQ_RESET, 0x00);
  400. seq_w(regs, SEQ_RESET, 0x03); /* reset sequencer logic */
  401. /*
  402. * CLOCKING_MODE bits:
  403. * 2: This one is only set for certain text-modes, wonder if
  404. * it may be for EGA-lines? (it was referred to as CLKDIV2)
  405. * (The CL drivers sets it to 0x21 with the comment:
  406. * FullBandwidth (video off) and 8/9 dot clock)
  407. */
  408. seq_w(regs, SEQ_CLOCKING_MODE, 0x01 | 0x00 /* 0x08 */);
  409. seq_w(regs, SEQ_MAP_MASK, 0x0f); /* enable writing to plane 0-3 */
  410. seq_w(regs, SEQ_CHAR_MAP_SELECT, 0x00); /* doesn't matter in gfx-mode */
  411. seq_w(regs, SEQ_MEMORY_MODE, 0x06); /* CL driver says 0x0e for 256 col mode*/
  412. seq_w(regs, SEQ_RESET, 0x01);
  413. seq_w(regs, SEQ_RESET, 0x03);
  414. seq_w(regs, SEQ_EXTENDED_ENABLE, 0x05);
  415. seq_w(regs, SEQ_CURSOR_CONTROL, 0x00); /* disable cursor */
  416. seq_w(regs, SEQ_PRIM_HOST_OFF_HI, 0x00);
  417. seq_w(regs, SEQ_PRIM_HOST_OFF_HI, 0x00);
  418. seq_w(regs, SEQ_LINEAR_0, 0x4a);
  419. seq_w(regs, SEQ_LINEAR_1, 0x00);
  420. seq_w(regs, SEQ_SEC_HOST_OFF_HI, 0x00);
  421. seq_w(regs, SEQ_SEC_HOST_OFF_LO, 0x00);
  422. seq_w(regs, SEQ_EXTENDED_MEM_ENA, 0x3 | 0x4 | 0x10 | 0x40);
  423. /*
  424. * The lower 4 bits (0-3) are used to set the font-width for
  425. * text-mode - DON'T try to set this for gfx-mode.
  426. */
  427. seq_w(regs, SEQ_EXT_CLOCK_MODE, 0x10);
  428. seq_w(regs, SEQ_EXT_VIDEO_ADDR, 0x03);
  429. /*
  430. * Extended Pixel Control:
  431. * bit 0: text-mode=0, gfx-mode=1 (Graphics Byte ?)
  432. * bit 1: (Packed/Nibble Pixel Format ?)
  433. * bit 4-5: depth, 0=1-8bpp, 1=9-16bpp, 2=17-24bpp
  434. */
  435. seq_w(regs, SEQ_EXT_PIXEL_CNTL, 0x01 | (((bpp / 8) - 1) << 4));
  436. seq_w(regs, SEQ_BUS_WIDTH_FEEDB, 0x04);
  437. seq_w(regs, SEQ_COLOR_EXP_WFG, 0x01);
  438. seq_w(regs, SEQ_COLOR_EXP_WBG, 0x00);
  439. seq_w(regs, SEQ_EXT_RW_CONTROL, 0x00);
  440. seq_w(regs, SEQ_MISC_FEATURE_SEL, (0x51 | (clocksel & 8)));
  441. seq_w(regs, SEQ_COLOR_KEY_CNTL, 0x40);
  442. seq_w(regs, SEQ_COLOR_KEY_MATCH0, 0x00);
  443. seq_w(regs, SEQ_COLOR_KEY_MATCH1, 0x00);
  444. seq_w(regs, SEQ_COLOR_KEY_MATCH2, 0x00);
  445. seq_w(regs, SEQ_CRC_CONTROL, 0x00);
  446. seq_w(regs, SEQ_PERF_SELECT, 0x10);
  447. seq_w(regs, SEQ_ACM_APERTURE_1, 0x00);
  448. seq_w(regs, SEQ_ACM_APERTURE_2, 0x30);
  449. seq_w(regs, SEQ_ACM_APERTURE_3, 0x00);
  450. seq_w(regs, SEQ_MEMORY_MAP_CNTL, 0x03);
  451. /* unlock register CRT0..CRT7 */
  452. crt_w(regs, CRT_END_VER_RETR, (data.v_sstop & 0x0f) | 0x20);
  453. /* Zuerst zu schreibende Werte nur per printk ausgeben */
  454. DEBUG printk("CRT_HOR_TOTAL: %ld\n", data.h_total);
  455. crt_w(regs, CRT_HOR_TOTAL, data.h_total & 0xff);
  456. DEBUG printk("CRT_HOR_DISP_ENA_END: %ld\n", data.h_dispend);
  457. crt_w(regs, CRT_HOR_DISP_ENA_END, (data.h_dispend) & 0xff);
  458. DEBUG printk("CRT_START_HOR_BLANK: %ld\n", data.h_bstart);
  459. crt_w(regs, CRT_START_HOR_BLANK, data.h_bstart & 0xff);
  460. DEBUG printk("CRT_END_HOR_BLANK: 128+%ld\n", data.h_bstop % 32);
  461. crt_w(regs, CRT_END_HOR_BLANK, 0x80 | (data.h_bstop & 0x1f));
  462. DEBUG printk("CRT_START_HOR_RETR: %ld\n", data.h_sstart);
  463. crt_w(regs, CRT_START_HOR_RETR, data.h_sstart & 0xff);
  464. tmp = (data.h_sstop & 0x1f);
  465. if (data.h_bstop & 0x20)
  466. tmp |= 0x80;
  467. DEBUG printk("CRT_END_HOR_RETR: %d\n", tmp);
  468. crt_w(regs, CRT_END_HOR_RETR, tmp);
  469. DEBUG printk("CRT_VER_TOTAL: %ld\n", data.v_total & 0xff);
  470. crt_w(regs, CRT_VER_TOTAL, (data.v_total & 0xff));
  471. tmp = 0x10; /* LineCompare bit #9 */
  472. if (data.v_total & 256)
  473. tmp |= 0x01;
  474. if (data.v_dispend & 256)
  475. tmp |= 0x02;
  476. if (data.v_sstart & 256)
  477. tmp |= 0x04;
  478. if (data.v_bstart & 256)
  479. tmp |= 0x08;
  480. if (data.v_total & 512)
  481. tmp |= 0x20;
  482. if (data.v_dispend & 512)
  483. tmp |= 0x40;
  484. if (data.v_sstart & 512)
  485. tmp |= 0x80;
  486. DEBUG printk("CRT_OVERFLOW: %d\n", tmp);
  487. crt_w(regs, CRT_OVERFLOW, tmp);
  488. crt_w(regs, CRT_PRESET_ROW_SCAN, 0x00); /* not CL !!! */
  489. tmp = 0x40; /* LineCompare bit #8 */
  490. if (data.v_bstart & 512)
  491. tmp |= 0x20;
  492. if (var->vmode & FB_VMODE_DOUBLE)
  493. tmp |= 0x80;
  494. DEBUG printk("CRT_MAX_SCAN_LINE: %d\n", tmp);
  495. crt_w(regs, CRT_MAX_SCAN_LINE, tmp);
  496. crt_w(regs, CRT_CURSOR_START, 0x00);
  497. crt_w(regs, CRT_CURSOR_END, 8 & 0x1f); /* font height */
  498. crt_w(regs, CRT_START_ADDR_HIGH, 0x00);
  499. crt_w(regs, CRT_START_ADDR_LOW, 0x00);
  500. crt_w(regs, CRT_CURSOR_LOC_HIGH, 0x00);
  501. crt_w(regs, CRT_CURSOR_LOC_LOW, 0x00);
  502. DEBUG printk("CRT_START_VER_RETR: %ld\n", data.v_sstart & 0xff);
  503. crt_w(regs, CRT_START_VER_RETR, (data.v_sstart & 0xff));
  504. #if 1
  505. /* 5 refresh cycles per scanline */
  506. DEBUG printk("CRT_END_VER_RETR: 64+32+%ld\n", data.v_sstop % 16);
  507. crt_w(regs, CRT_END_VER_RETR, ((data.v_sstop & 0x0f) | 0x40 | 0x20));
  508. #else
  509. DEBUG printk("CRT_END_VER_RETR: 128+32+%ld\n", data.v_sstop % 16);
  510. crt_w(regs, CRT_END_VER_RETR, ((data.v_sstop & 0x0f) | 128 | 32));
  511. #endif
  512. DEBUG printk("CRT_VER_DISP_ENA_END: %ld\n", data.v_dispend & 0xff);
  513. crt_w(regs, CRT_VER_DISP_ENA_END, (data.v_dispend & 0xff));
  514. DEBUG printk("CRT_START_VER_BLANK: %ld\n", data.v_bstart & 0xff);
  515. crt_w(regs, CRT_START_VER_BLANK, (data.v_bstart & 0xff));
  516. DEBUG printk("CRT_END_VER_BLANK: %ld\n", data.v_bstop & 0xff);
  517. crt_w(regs, CRT_END_VER_BLANK, (data.v_bstop & 0xff));
  518. DEBUG printk("CRT_MODE_CONTROL: 0xe3\n");
  519. crt_w(regs, CRT_MODE_CONTROL, 0xe3);
  520. DEBUG printk("CRT_LINE_COMPARE: 0xff\n");
  521. crt_w(regs, CRT_LINE_COMPARE, 0xff);
  522. tmp = (var->xres_virtual / 8) * (bpp / 8);
  523. crt_w(regs, CRT_OFFSET, tmp);
  524. crt_w(regs, CRT_UNDERLINE_LOC, 0x07); /* probably font-height - 1 */
  525. tmp = 0x20; /* Enable extended end bits */
  526. if (data.h_total & 0x100)
  527. tmp |= 0x01;
  528. if ((data.h_dispend) & 0x100)
  529. tmp |= 0x02;
  530. if (data.h_bstart & 0x100)
  531. tmp |= 0x04;
  532. if (data.h_sstart & 0x100)
  533. tmp |= 0x08;
  534. if (var->vmode & FB_VMODE_INTERLACED)
  535. tmp |= 0x10;
  536. DEBUG printk("CRT_EXT_HOR_TIMING1: %d\n", tmp);
  537. crt_w(regs, CRT_EXT_HOR_TIMING1, tmp);
  538. tmp = 0x00;
  539. if (((var->xres_virtual / 8) * (bpp / 8)) & 0x100)
  540. tmp |= 0x10;
  541. crt_w(regs, CRT_EXT_START_ADDR, tmp);
  542. tmp = 0x00;
  543. if (data.h_total & 0x200)
  544. tmp |= 0x01;
  545. if ((data.h_dispend) & 0x200)
  546. tmp |= 0x02;
  547. if (data.h_bstart & 0x200)
  548. tmp |= 0x04;
  549. if (data.h_sstart & 0x200)
  550. tmp |= 0x08;
  551. tmp |= ((data.h_bstop & 0xc0) >> 2);
  552. tmp |= ((data.h_sstop & 0x60) << 1);
  553. crt_w(regs, CRT_EXT_HOR_TIMING2, tmp);
  554. DEBUG printk("CRT_EXT_HOR_TIMING2: %d\n", tmp);
  555. tmp = 0x10; /* Line compare bit 10 */
  556. if (data.v_total & 0x400)
  557. tmp |= 0x01;
  558. if ((data.v_dispend) & 0x400)
  559. tmp |= 0x02;
  560. if (data.v_bstart & 0x400)
  561. tmp |= 0x04;
  562. if (data.v_sstart & 0x400)
  563. tmp |= 0x08;
  564. tmp |= ((data.v_bstop & 0x300) >> 3);
  565. if (data.v_sstop & 0x10)
  566. tmp |= 0x80;
  567. crt_w(regs, CRT_EXT_VER_TIMING, tmp);
  568. DEBUG printk("CRT_EXT_VER_TIMING: %d\n", tmp);
  569. crt_w(regs, CRT_MONITOR_POWER, 0x00);
  570. /*
  571. * Convert from ps to Hz.
  572. */
  573. freq = 2000000000 / var->pixclock;
  574. freq = freq * 500;
  575. best_freq = find_fq(freq);
  576. pll_w(regs, 0x02, best_freq);
  577. best_freq = find_fq(61000000);
  578. pll_w(regs, 0x0a, best_freq);
  579. pll_w(regs, 0x0e, 0x22);
  580. gfx_w(regs, GFX_SET_RESET, 0x00);
  581. gfx_w(regs, GFX_ENABLE_SET_RESET, 0x00);
  582. gfx_w(regs, GFX_COLOR_COMPARE, 0x00);
  583. gfx_w(regs, GFX_DATA_ROTATE, 0x00);
  584. gfx_w(regs, GFX_READ_MAP_SELECT, 0x00);
  585. gfx_w(regs, GFX_GRAPHICS_MODE, 0x00);
  586. gfx_w(regs, GFX_MISC, 0x05);
  587. gfx_w(regs, GFX_COLOR_XCARE, 0x0f);
  588. gfx_w(regs, GFX_BITMASK, 0xff);
  589. reg_r(regs, ACT_ADDRESS_RESET);
  590. attr_w(regs, ACT_PALETTE0 , 0x00);
  591. attr_w(regs, ACT_PALETTE1 , 0x01);
  592. attr_w(regs, ACT_PALETTE2 , 0x02);
  593. attr_w(regs, ACT_PALETTE3 , 0x03);
  594. attr_w(regs, ACT_PALETTE4 , 0x04);
  595. attr_w(regs, ACT_PALETTE5 , 0x05);
  596. attr_w(regs, ACT_PALETTE6 , 0x06);
  597. attr_w(regs, ACT_PALETTE7 , 0x07);
  598. attr_w(regs, ACT_PALETTE8 , 0x08);
  599. attr_w(regs, ACT_PALETTE9 , 0x09);
  600. attr_w(regs, ACT_PALETTE10, 0x0a);
  601. attr_w(regs, ACT_PALETTE11, 0x0b);
  602. attr_w(regs, ACT_PALETTE12, 0x0c);
  603. attr_w(regs, ACT_PALETTE13, 0x0d);
  604. attr_w(regs, ACT_PALETTE14, 0x0e);
  605. attr_w(regs, ACT_PALETTE15, 0x0f);
  606. reg_r(regs, ACT_ADDRESS_RESET);
  607. attr_w(regs, ACT_ATTR_MODE_CNTL, 0x09); /* 0x01 for CL */
  608. attr_w(regs, ACT_OVERSCAN_COLOR, 0x00);
  609. attr_w(regs, ACT_COLOR_PLANE_ENA, 0x0f);
  610. attr_w(regs, ACT_HOR_PEL_PANNING, 0x00);
  611. attr_w(regs, ACT_COLOR_SELECT, 0x00);
  612. reg_r(regs, ACT_ADDRESS_RESET);
  613. reg_w(regs, ACT_DATA, 0x20);
  614. reg_w(regs, VDAC_MASK, 0xff);
  615. /*
  616. * Extended palette addressing ???
  617. */
  618. switch (bpp){
  619. case 8:
  620. reg_w(regs, 0x83c6, 0x00);
  621. break;
  622. case 16:
  623. reg_w(regs, 0x83c6, 0x60);
  624. break;
  625. case 24:
  626. reg_w(regs, 0x83c6, 0xe0);
  627. break;
  628. default:
  629. printk(KERN_INFO "Illegal color-depth: %i\n", bpp);
  630. }
  631. reg_w(regs, VDAC_ADDRESS, 0x00);
  632. seq_w(regs, SEQ_MAP_MASK, 0x0f );
  633. return 0;
  634. }
  635. /*
  636. * This function should fill in the `fix' structure based on the
  637. * values in the `par' structure.
  638. */
  639. static int retz3_encode_fix(struct fb_info *info,
  640. struct fb_fix_screeninfo *fix,
  641. struct retz3fb_par *par)
  642. {
  643. struct retz3_fb_info *zinfo = retz3info(info);
  644. memset(fix, 0, sizeof(struct fb_fix_screeninfo));
  645. strcpy(fix->id, retz3fb_name);
  646. fix->smem_start = zinfo->physfbmem;
  647. fix->smem_len = zinfo->fbsize;
  648. fix->mmio_start = zinfo->physregs;
  649. fix->mmio_len = 0x00c00000;
  650. fix->type = FB_TYPE_PACKED_PIXELS;
  651. fix->type_aux = 0;
  652. if (par->bpp == 8)
  653. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  654. else
  655. fix->visual = FB_VISUAL_TRUECOLOR;
  656. fix->xpanstep = 0;
  657. fix->ypanstep = 0;
  658. fix->ywrapstep = 0;
  659. fix->line_length = 0;
  660. fix->accel = FB_ACCEL_NCR_77C32BLT;
  661. return 0;
  662. }
  663. /*
  664. * Get the video params out of `var'. If a value doesn't fit, round
  665. * it up, if it's too big, return -EINVAL.
  666. */
  667. static int retz3_decode_var(struct fb_var_screeninfo *var,
  668. struct retz3fb_par *par)
  669. {
  670. par->xres = var->xres;
  671. par->yres = var->yres;
  672. par->xres_vir = var->xres_virtual;
  673. par->yres_vir = var->yres_virtual;
  674. par->bpp = var->bits_per_pixel;
  675. par->pixclock = var->pixclock;
  676. par->vmode = var->vmode;
  677. par->red = var->red;
  678. par->green = var->green;
  679. par->blue = var->blue;
  680. par->transp = var->transp;
  681. par->left_margin = var->left_margin;
  682. par->right_margin = var->right_margin;
  683. par->upper_margin = var->upper_margin;
  684. par->lower_margin = var->lower_margin;
  685. par->hsync_len = var->hsync_len;
  686. par->vsync_len = var->vsync_len;
  687. if (var->accel_flags & FB_ACCELF_TEXT)
  688. par->accel = FB_ACCELF_TEXT;
  689. else
  690. par->accel = 0;
  691. return 0;
  692. }
  693. /*
  694. * Fill the `var' structure based on the values in `par' and maybe
  695. * other values read out of the hardware.
  696. */
  697. static int retz3_encode_var(struct fb_var_screeninfo *var,
  698. struct retz3fb_par *par)
  699. {
  700. memset(var, 0, sizeof(struct fb_var_screeninfo));
  701. var->xres = par->xres;
  702. var->yres = par->yres;
  703. var->xres_virtual = par->xres_vir;
  704. var->yres_virtual = par->yres_vir;
  705. var->xoffset = 0;
  706. var->yoffset = 0;
  707. var->bits_per_pixel = par->bpp;
  708. var->grayscale = 0;
  709. var->red = par->red;
  710. var->green = par->green;
  711. var->blue = par->blue;
  712. var->transp = par->transp;
  713. var->nonstd = 0;
  714. var->activate = 0;
  715. var->height = -1;
  716. var->width = -1;
  717. var->accel_flags = (par->accel && par->bpp == 8) ? FB_ACCELF_TEXT : 0;
  718. var->pixclock = par->pixclock;
  719. var->sync = 0; /* ??? */
  720. var->left_margin = par->left_margin;
  721. var->right_margin = par->right_margin;
  722. var->upper_margin = par->upper_margin;
  723. var->lower_margin = par->lower_margin;
  724. var->hsync_len = par->hsync_len;
  725. var->vsync_len = par->vsync_len;
  726. var->vmode = par->vmode;
  727. return 0;
  728. }
  729. /*
  730. * Set a single color register. Return != 0 for invalid regno.
  731. */
  732. static int retz3fb_setcolreg(unsigned int regno, unsigned int red,
  733. unsigned int green, unsigned int blue,
  734. unsigned int transp, struct fb_info *info)
  735. {
  736. struct retz3_fb_info *zinfo = retz3info(info);
  737. volatile unsigned char *regs = zinfo->regs;
  738. /* We'll get to this */
  739. if (regno > 255)
  740. return 1;
  741. red >>= 10;
  742. green >>= 10;
  743. blue >>= 10;
  744. zinfo->color_table[regno][0] = red;
  745. zinfo->color_table[regno][1] = green;
  746. zinfo->color_table[regno][2] = blue;
  747. reg_w(regs, VDAC_ADDRESS_W, regno);
  748. reg_w(regs, VDAC_DATA, red);
  749. reg_w(regs, VDAC_DATA, green);
  750. reg_w(regs, VDAC_DATA, blue);
  751. return 0;
  752. }
  753. /*
  754. * Read a single color register and split it into
  755. * colors/transparent. Return != 0 for invalid regno.
  756. */
  757. static int retz3_getcolreg(unsigned int regno, unsigned int *red,
  758. unsigned int *green, unsigned int *blue,
  759. unsigned int *transp, struct fb_info *info)
  760. {
  761. struct retz3_fb_info *zinfo = retz3info(info);
  762. int t;
  763. if (regno > 255)
  764. return 1;
  765. t = zinfo->color_table[regno][0];
  766. *red = (t<<10) | (t<<4) | (t>>2);
  767. t = zinfo->color_table[regno][1];
  768. *green = (t<<10) | (t<<4) | (t>>2);
  769. t = zinfo->color_table[regno][2];
  770. *blue = (t<<10) | (t<<4) | (t>>2);
  771. *transp = 0;
  772. return 0;
  773. }
  774. static inline void retz3_busy(struct display *p)
  775. {
  776. struct retz3_fb_info *zinfo = retz3info(p->fb_info);
  777. volatile unsigned char *acm = zinfo->base + ACM_OFFSET;
  778. unsigned char blt_status;
  779. if (zinfo->blitbusy) {
  780. do{
  781. blt_status = *((acm) + (ACM_START_STATUS + 2));
  782. }while ((blt_status & 1) == 0);
  783. zinfo->blitbusy = 0;
  784. }
  785. }
  786. static void retz3_bitblt (struct display *p,
  787. unsigned short srcx, unsigned short srcy,
  788. unsigned short destx, unsigned short desty,
  789. unsigned short width, unsigned short height,
  790. unsigned short cmd, unsigned short mask)
  791. {
  792. struct fb_var_screeninfo *var = &p->var;
  793. struct retz3_fb_info *zinfo = retz3info(p->fb_info);
  794. volatile unsigned long *acm = (unsigned long *)(zinfo->base + ACM_OFFSET);
  795. unsigned long *pattern = (unsigned long *)(zinfo->fbmem + PAT_MEM_OFF);
  796. unsigned short mod;
  797. unsigned long tmp;
  798. unsigned long pat, src, dst;
  799. int i, xres_virtual = var->xres_virtual;
  800. short bpp = (var->bits_per_pixel & 0xff);
  801. if (bpp < 8)
  802. bpp = 8;
  803. tmp = mask | (mask << 16);
  804. retz3_busy(p);
  805. i = 0;
  806. do{
  807. *pattern++ = tmp;
  808. }while(i++ < bpp/4);
  809. tmp = cmd << 8;
  810. *(acm + ACM_RASTEROP_ROTATION/4) = tmp;
  811. mod = 0xc0c2;
  812. pat = 8 * PAT_MEM_OFF;
  813. dst = bpp * (destx + desty * xres_virtual);
  814. /*
  815. * Source is not set for clear.
  816. */
  817. if ((cmd != Z3BLTclear) && (cmd != Z3BLTset)) {
  818. src = bpp * (srcx + srcy * xres_virtual);
  819. if (destx > srcx) {
  820. mod &= ~0x8000;
  821. src += bpp * (width - 1);
  822. dst += bpp * (width - 1);
  823. pat += bpp * 2;
  824. }
  825. if (desty > srcy) {
  826. mod &= ~0x4000;
  827. src += bpp * (height - 1) * xres_virtual;
  828. dst += bpp * (height - 1) * xres_virtual;
  829. pat += bpp * 4;
  830. }
  831. *(acm + ACM_SOURCE/4) = cpu_to_le32(src);
  832. }
  833. *(acm + ACM_PATTERN/4) = cpu_to_le32(pat);
  834. *(acm + ACM_DESTINATION/4) = cpu_to_le32(dst);
  835. tmp = mod << 16;
  836. *(acm + ACM_CONTROL/4) = tmp;
  837. tmp = width | (height << 16);
  838. *(acm + ACM_BITMAP_DIMENSION/4) = cpu_to_le32(tmp);
  839. *(((volatile unsigned char *)acm) + ACM_START_STATUS) = 0x00;
  840. *(((volatile unsigned char *)acm) + ACM_START_STATUS) = 0x01;
  841. zinfo->blitbusy = 1;
  842. }
  843. #if 0
  844. /*
  845. * Move cursor to x, y
  846. */
  847. static void retz3_MoveCursor (unsigned short x, unsigned short y)
  848. {
  849. /* Guess we gotta deal with the cursor at some point */
  850. }
  851. #endif
  852. /*
  853. * Fill the hardware's `par' structure.
  854. */
  855. static void retz3fb_get_par(struct fb_info *info, struct retz3fb_par *par)
  856. {
  857. struct retz3_fb_info *zinfo = retz3info(info);
  858. if (zinfo->current_par_valid)
  859. *par = zinfo->current_par;
  860. else
  861. retz3_decode_var(&retz3fb_default, par);
  862. }
  863. static void retz3fb_set_par(struct fb_info *info, struct retz3fb_par *par)
  864. {
  865. struct retz3_fb_info *zinfo = retz3info(info);
  866. zinfo->current_par = *par;
  867. zinfo->current_par_valid = 1;
  868. }
  869. static int do_fb_set_var(struct fb_info *info,
  870. struct fb_var_screeninfo *var, int isactive)
  871. {
  872. int err, activate;
  873. struct retz3fb_par par;
  874. struct retz3_fb_info *zinfo = retz3info(info);
  875. if ((err = retz3_decode_var(var, &par)))
  876. return err;
  877. activate = var->activate;
  878. /* XXX ... what to do about isactive ? */
  879. if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW && isactive)
  880. retz3fb_set_par(info, &par);
  881. retz3_encode_var(var, &par);
  882. var->activate = activate;
  883. retz3_set_video(info, var, &zinfo->current_par);
  884. return 0;
  885. }
  886. /*
  887. * Get the Fixed Part of the Display
  888. */
  889. static int retz3fb_get_fix(struct fb_fix_screeninfo *fix, int con,
  890. struct fb_info *info)
  891. {
  892. struct retz3fb_par par;
  893. int error = 0;
  894. if (con == -1)
  895. retz3fb_get_par(info, &par);
  896. else
  897. error = retz3_decode_var(&fb_display[con].var, &par);
  898. return(error ? error : retz3_encode_fix(info, fix, &par));
  899. }
  900. /*
  901. * Get the User Defined Part of the Display
  902. */
  903. static int retz3fb_get_var(struct fb_var_screeninfo *var, int con,
  904. struct fb_info *info)
  905. {
  906. struct retz3fb_par par;
  907. int error = 0;
  908. if (con == -1) {
  909. retz3fb_get_par(info, &par);
  910. error = retz3_encode_var(var, &par);
  911. } else
  912. *var = fb_display[con].var;
  913. return error;
  914. }
  915. static void retz3fb_set_disp(int con, struct fb_info *info)
  916. {
  917. struct fb_fix_screeninfo fix;
  918. struct display *display;
  919. struct retz3_fb_info *zinfo = retz3info(info);
  920. if (con >= 0)
  921. display = &fb_display[con];
  922. else
  923. display = &zinfo->disp; /* used during initialization */
  924. retz3fb_get_fix(&fix, con, info);
  925. if (con == -1)
  926. con = 0;
  927. display->visual = fix.visual;
  928. display->type = fix.type;
  929. display->type_aux = fix.type_aux;
  930. display->ypanstep = fix.ypanstep;
  931. display->ywrapstep = fix.ywrapstep;
  932. display->can_soft_blank = 1;
  933. display->inverse = z3fb_inverse;
  934. /*
  935. * This seems to be about 20% faster.
  936. */
  937. display->scrollmode = SCROLL_YREDRAW;
  938. switch (display->var.bits_per_pixel) {
  939. #ifdef FBCON_HAS_CFB8
  940. case 8:
  941. if (display->var.accel_flags & FB_ACCELF_TEXT) {
  942. display->dispsw = &fbcon_retz3_8;
  943. retz3_set_video(info, &display->var, &zinfo->current_par);
  944. } else
  945. display->dispsw = &fbcon_cfb8;
  946. break;
  947. #endif
  948. #ifdef FBCON_HAS_CFB16
  949. case 16:
  950. display->dispsw = &fbcon_cfb16;
  951. break;
  952. #endif
  953. default:
  954. display->dispsw = &fbcon_dummy;
  955. break;
  956. }
  957. }
  958. /*
  959. * Set the User Defined Part of the Display
  960. */
  961. static int retz3fb_set_var(struct fb_var_screeninfo *var, int con,
  962. struct fb_info *info)
  963. {
  964. int err, oldxres, oldyres, oldvxres, oldvyres, oldbpp, oldaccel;
  965. struct display *display;
  966. struct retz3_fb_info *zinfo = retz3info(info);
  967. if (con >= 0)
  968. display = &fb_display[con];
  969. else
  970. display = &zinfo->disp; /* used during initialization */
  971. if ((err = do_fb_set_var(info, var, con == info->currcon)))
  972. return err;
  973. if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
  974. oldxres = display->var.xres;
  975. oldyres = display->var.yres;
  976. oldvxres = display->var.xres_virtual;
  977. oldvyres = display->var.yres_virtual;
  978. oldbpp = display->var.bits_per_pixel;
  979. oldaccel = display->var.accel_flags;
  980. display->var = *var;
  981. if (oldxres != var->xres || oldyres != var->yres ||
  982. oldvxres != var->xres_virtual ||
  983. oldvyres != var->yres_virtual ||
  984. oldbpp != var->bits_per_pixel ||
  985. oldaccel != var->accel_flags) {
  986. struct fb_fix_screeninfo fix;
  987. retz3fb_get_fix(&fix, con, info);
  988. display->visual = fix.visual;
  989. display->type = fix.type;
  990. display->type_aux = fix.type_aux;
  991. display->ypanstep = fix.ypanstep;
  992. display->ywrapstep = fix.ywrapstep;
  993. display->line_length = fix.line_length;
  994. display->can_soft_blank = 1;
  995. display->inverse = z3fb_inverse;
  996. switch (display->var.bits_per_pixel) {
  997. #ifdef FBCON_HAS_CFB8
  998. case 8:
  999. if (var->accel_flags & FB_ACCELF_TEXT) {
  1000. display->dispsw = &fbcon_retz3_8;
  1001. } else
  1002. display->dispsw = &fbcon_cfb8;
  1003. break;
  1004. #endif
  1005. #ifdef FBCON_HAS_CFB16
  1006. case 16:
  1007. display->dispsw = &fbcon_cfb16;
  1008. break;
  1009. #endif
  1010. default:
  1011. display->dispsw = &fbcon_dummy;
  1012. break;
  1013. }
  1014. /*
  1015. * We still need to find a way to tell the X
  1016. * server that the video mem has been fiddled with
  1017. * so it redraws the entire screen when switching
  1018. * between X and a text console.
  1019. */
  1020. retz3_set_video(info, var, &zinfo->current_par);
  1021. if (info->changevar)
  1022. (*info->changevar)(con);
  1023. }
  1024. if (oldbpp != var->bits_per_pixel) {
  1025. if ((err = fb_alloc_cmap(&display->cmap, 0, 0)))
  1026. return err;
  1027. do_install_cmap(con, info);
  1028. }
  1029. }
  1030. return 0;
  1031. }
  1032. /*
  1033. * Get the Colormap
  1034. */
  1035. static int retz3fb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
  1036. struct fb_info *info)
  1037. {
  1038. if (con == info->currcon) /* current console? */
  1039. return(fb_get_cmap(cmap, kspc, retz3_getcolreg, info));
  1040. else if (fb_display[con].cmap.len) /* non default colormap? */
  1041. fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
  1042. else
  1043. fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),
  1044. cmap, kspc ? 0 : 2);
  1045. return 0;
  1046. }
  1047. /*
  1048. * Blank the display.
  1049. */
  1050. static int retz3fb_blank(int blank, struct fb_info *info)
  1051. {
  1052. struct retz3_fb_info *zinfo = retz3info(info);
  1053. volatile unsigned char *regs = retz3info(info)->regs;
  1054. short i;
  1055. if (blank)
  1056. for (i = 0; i < 256; i++){
  1057. reg_w(regs, VDAC_ADDRESS_W, i);
  1058. reg_w(regs, VDAC_DATA, 0);
  1059. reg_w(regs, VDAC_DATA, 0);
  1060. reg_w(regs, VDAC_DATA, 0);
  1061. }
  1062. else
  1063. for (i = 0; i < 256; i++){
  1064. reg_w(regs, VDAC_ADDRESS_W, i);
  1065. reg_w(regs, VDAC_DATA, zinfo->color_table[i][0]);
  1066. reg_w(regs, VDAC_DATA, zinfo->color_table[i][1]);
  1067. reg_w(regs, VDAC_DATA, zinfo->color_table[i][2]);
  1068. }
  1069. return 0;
  1070. }
  1071. static struct fb_ops retz3fb_ops = {
  1072. .owner = THIS_MODULE,
  1073. .fb_get_fix = retz3fb_get_fix,
  1074. .fb_get_var = retz3fb_get_var,
  1075. .fb_set_var = retz3fb_set_var,
  1076. .fb_get_cmap = retz3fb_get_cmap,
  1077. .fb_set_cmap = gen_set_cmap,
  1078. .fb_setcolreg = retz3fb_setcolreg,
  1079. .fb_blank = retz3fb_blank,
  1080. };
  1081. int __init retz3fb_setup(char *options)
  1082. {
  1083. char *this_opt;
  1084. if (!options || !*options)
  1085. return 0;
  1086. while ((this_opt = strsep(&options, ",")) != NULL) {
  1087. if (!*this_opt)
  1088. continue;
  1089. if (!strcmp(this_opt, "inverse")) {
  1090. z3fb_inverse = 1;
  1091. fb_invert_cmaps();
  1092. } else if (!strncmp(this_opt, "font:", 5)) {
  1093. strlcpy(fontname, this_opt+5, sizeof(fontname));
  1094. } else
  1095. z3fb_mode = get_video_mode(this_opt);
  1096. }
  1097. return 0;
  1098. }
  1099. /*
  1100. * Initialization
  1101. */
  1102. int __init retz3fb_init(void)
  1103. {
  1104. unsigned long board_addr, board_size;
  1105. struct zorro_dev *z = NULL;
  1106. volatile unsigned char *regs;
  1107. struct retz3fb_par par;
  1108. struct retz3_fb_info *zinfo;
  1109. struct fb_info *fb_info;
  1110. short i;
  1111. int res = -ENXIO;
  1112. while ((z = zorro_find_device(ZORRO_PROD_MACROSYSTEMS_RETINA_Z3, z))) {
  1113. board_addr = z->resource.start;
  1114. board_size = z->resource.end-z->resource.start+1;
  1115. if (!request_mem_region(board_addr, 0x0c00000,
  1116. "ncr77c32blt")) {
  1117. continue;
  1118. if (!request_mem_region(board_addr+VIDEO_MEM_OFFSET,
  1119. 0x00400000, "RAM"))
  1120. release_mem_region(board_addr, 0x00c00000);
  1121. continue;
  1122. }
  1123. if (!(zinfo = kmalloc(sizeof(struct retz3_fb_info),
  1124. GFP_KERNEL)))
  1125. return -ENOMEM;
  1126. memset(zinfo, 0, sizeof(struct retz3_fb_info));
  1127. zinfo->base = ioremap(board_addr, board_size);
  1128. zinfo->regs = zinfo->base;
  1129. zinfo->fbmem = zinfo->base + VIDEO_MEM_OFFSET;
  1130. /* Get memory size - for now we asume it's a 4MB board */
  1131. zinfo->fbsize = 0x00400000; /* 4 MB */
  1132. zinfo->physregs = board_addr;
  1133. zinfo->physfbmem = board_addr + VIDEO_MEM_OFFSET;
  1134. fb_info = fbinfo(zinfo);
  1135. for (i = 0; i < 256; i++){
  1136. for (i = 0; i < 256; i++){
  1137. zinfo->color_table[i][0] = i;
  1138. zinfo->color_table[i][1] = i;
  1139. zinfo->color_table[i][2] = i;
  1140. }
  1141. }
  1142. regs = zinfo->regs;
  1143. /* Disable hardware cursor */
  1144. seq_w(regs, SEQ_CURSOR_Y_INDEX, 0x00);
  1145. retz3fb_setcolreg (255, 56<<8, 100<<8, 160<<8, 0, fb_info);
  1146. retz3fb_setcolreg (254, 0, 0, 0, 0, fb_info);
  1147. strcpy(fb_info->modename, retz3fb_name);
  1148. fb_info->changevar = NULL;
  1149. fb_info->fbops = &retz3fb_ops;
  1150. fb_info->screen_base = zinfo->fbmem;
  1151. fb_info->disp = &zinfo->disp;
  1152. fb_info->currcon = -1;
  1153. fb_info->switch_con = &z3fb_switch;
  1154. fb_info->updatevar = &z3fb_updatevar;
  1155. fb_info->flags = FBINFO_FLAG_DEFAULT;
  1156. strlcpy(fb_info->fontname, fontname, sizeof(fb_info->fontname));
  1157. if (z3fb_mode == -1)
  1158. retz3fb_default = retz3fb_predefined[0].var;
  1159. retz3_decode_var(&retz3fb_default, &par);
  1160. retz3_encode_var(&retz3fb_default, &par);
  1161. do_fb_set_var(fb_info, &retz3fb_default, 0);
  1162. retz3fb_get_var(&zinfo->disp.var, -1, fb_info);
  1163. retz3fb_set_disp(-1, fb_info);
  1164. do_install_cmap(0, fb_info);
  1165. if (register_framebuffer(fb_info) < 0)
  1166. return -EINVAL;
  1167. printk(KERN_INFO "fb%d: %s frame buffer device, using %ldK of "
  1168. "video memory\n", fb_info->node,
  1169. fb_info->modename, zinfo->fbsize>>10);
  1170. /* FIXME: This driver cannot be unloaded yet */
  1171. res = 0;
  1172. }
  1173. return res;
  1174. }
  1175. static int z3fb_switch(int con, struct fb_info *info)
  1176. {
  1177. /* Do we have to save the colormap? */
  1178. if (fb_display[info->currcon].cmap.len)
  1179. fb_get_cmap(&fb_display[info->currcon].cmap, 1,
  1180. retz3_getcolreg, info);
  1181. do_fb_set_var(info, &fb_display[con].var, 1);
  1182. info->currcon = con;
  1183. /* Install new colormap */
  1184. do_install_cmap(con, info);
  1185. return 0;
  1186. }
  1187. /*
  1188. * Update the `var' structure (called by fbcon.c)
  1189. *
  1190. * This call looks only at yoffset and the FB_VMODE_YWRAP flag in `var'.
  1191. * Since it's called by a kernel driver, no range checking is done.
  1192. */
  1193. static int z3fb_updatevar(int con, struct fb_info *info)
  1194. {
  1195. return 0;
  1196. }
  1197. /*
  1198. * Get a Video Mode
  1199. */
  1200. static int __init get_video_mode(const char *name)
  1201. {
  1202. short i;
  1203. for (i = 0; i < NUM_TOTAL_MODES; i++)
  1204. if (!strcmp(name, retz3fb_predefined[i].name)){
  1205. retz3fb_default = retz3fb_predefined[i].var;
  1206. return i;
  1207. }
  1208. return -1;
  1209. }
  1210. #ifdef MODULE
  1211. MODULE_LICENSE("GPL");
  1212. int init_module(void)
  1213. {
  1214. return retz3fb_init();
  1215. }
  1216. #endif
  1217. /*
  1218. * Text console acceleration
  1219. */
  1220. #ifdef FBCON_HAS_CFB8
  1221. static void retz3_8_bmove(struct display *p, int sy, int sx,
  1222. int dy, int dx, int height, int width)
  1223. {
  1224. int fontwidth = fontwidth(p);
  1225. sx *= fontwidth;
  1226. dx *= fontwidth;
  1227. width *= fontwidth;
  1228. retz3_bitblt(p,
  1229. (unsigned short)sx,
  1230. (unsigned short)(sy*fontheight(p)),
  1231. (unsigned short)dx,
  1232. (unsigned short)(dy*fontheight(p)),
  1233. (unsigned short)width,
  1234. (unsigned short)(height*fontheight(p)),
  1235. Z3BLTcopy,
  1236. 0xffff);
  1237. }
  1238. static void retz3_8_clear(struct vc_data *conp, struct display *p,
  1239. int sy, int sx, int height, int width)
  1240. {
  1241. unsigned short col;
  1242. int fontwidth = fontwidth(p);
  1243. sx *= fontwidth;
  1244. width *= fontwidth;
  1245. col = attr_bgcol_ec(p, conp);
  1246. col &= 0xff;
  1247. col |= (col << 8);
  1248. retz3_bitblt(p,
  1249. (unsigned short)sx,
  1250. (unsigned short)(sy*fontheight(p)),
  1251. (unsigned short)sx,
  1252. (unsigned short)(sy*fontheight(p)),
  1253. (unsigned short)width,
  1254. (unsigned short)(height*fontheight(p)),
  1255. Z3BLTset,
  1256. col);
  1257. }
  1258. static void retz3_putc(struct vc_data *conp, struct display *p, int c,
  1259. int yy, int xx)
  1260. {
  1261. retz3_busy(p);
  1262. fbcon_cfb8_putc(conp, p, c, yy, xx);
  1263. }
  1264. static void retz3_putcs(struct vc_data *conp, struct display *p,
  1265. const unsigned short *s, int count,
  1266. int yy, int xx)
  1267. {
  1268. retz3_busy(p);
  1269. fbcon_cfb8_putcs(conp, p, s, count, yy, xx);
  1270. }
  1271. static void retz3_revc(struct display *p, int xx, int yy)
  1272. {
  1273. retz3_busy(p);
  1274. fbcon_cfb8_revc(p, xx, yy);
  1275. }
  1276. static void retz3_clear_margins(struct vc_data* conp, struct display* p,
  1277. int bottom_only)
  1278. {
  1279. retz3_busy(p);
  1280. fbcon_cfb8_clear_margins(conp, p, bottom_only);
  1281. }
  1282. static struct display_switch fbcon_retz3_8 = {
  1283. .setup = fbcon_cfb8_setup,
  1284. .bmove = retz3_8_bmove,
  1285. .clear = retz3_8_clear,
  1286. .putc = retz3_putc,
  1287. .putcs = retz3_putcs,
  1288. .revc = retz3_revc,
  1289. .clear_margins = retz3_clear_margins,
  1290. .fontwidthmask = FONTWIDTH(8)
  1291. };
  1292. #endif