svgalib.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /*
  2. * Common utility functions for VGA-based graphics cards.
  3. *
  4. * Copyright (c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive for
  8. * more details.
  9. *
  10. * Some parts are based on David Boucher's viafb (http://davesdomain.org.uk/viafb/)
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/string.h>
  15. #include <linux/fb.h>
  16. #include <linux/svga.h>
  17. #include <linux/slab.h>
  18. #include <asm/types.h>
  19. #include <asm/io.h>
  20. /* Write a CRT register value spread across multiple registers */
  21. void svga_wcrt_multi(const struct vga_regset *regset, u32 value) {
  22. u8 regval, bitval, bitnum;
  23. while (regset->regnum != VGA_REGSET_END_VAL) {
  24. regval = vga_rcrt(NULL, regset->regnum);
  25. bitnum = regset->lowbit;
  26. while (bitnum <= regset->highbit) {
  27. bitval = 1 << bitnum;
  28. regval = regval & ~bitval;
  29. if (value & 1) regval = regval | bitval;
  30. bitnum ++;
  31. value = value >> 1;
  32. }
  33. vga_wcrt(NULL, regset->regnum, regval);
  34. regset ++;
  35. }
  36. }
  37. /* Write a sequencer register value spread across multiple registers */
  38. void svga_wseq_multi(const struct vga_regset *regset, u32 value) {
  39. u8 regval, bitval, bitnum;
  40. while (regset->regnum != VGA_REGSET_END_VAL) {
  41. regval = vga_rseq(NULL, regset->regnum);
  42. bitnum = regset->lowbit;
  43. while (bitnum <= regset->highbit) {
  44. bitval = 1 << bitnum;
  45. regval = regval & ~bitval;
  46. if (value & 1) regval = regval | bitval;
  47. bitnum ++;
  48. value = value >> 1;
  49. }
  50. vga_wseq(NULL, regset->regnum, regval);
  51. regset ++;
  52. }
  53. }
  54. static unsigned int svga_regset_size(const struct vga_regset *regset)
  55. {
  56. u8 count = 0;
  57. while (regset->regnum != VGA_REGSET_END_VAL) {
  58. count += regset->highbit - regset->lowbit + 1;
  59. regset ++;
  60. }
  61. return 1 << count;
  62. }
  63. /* ------------------------------------------------------------------------- */
  64. /* Set graphics controller registers to sane values */
  65. void svga_set_default_gfx_regs(void)
  66. {
  67. /* All standard GFX registers (GR00 - GR08) */
  68. vga_wgfx(NULL, VGA_GFX_SR_VALUE, 0x00);
  69. vga_wgfx(NULL, VGA_GFX_SR_ENABLE, 0x00);
  70. vga_wgfx(NULL, VGA_GFX_COMPARE_VALUE, 0x00);
  71. vga_wgfx(NULL, VGA_GFX_DATA_ROTATE, 0x00);
  72. vga_wgfx(NULL, VGA_GFX_PLANE_READ, 0x00);
  73. vga_wgfx(NULL, VGA_GFX_MODE, 0x00);
  74. /* vga_wgfx(NULL, VGA_GFX_MODE, 0x20); */
  75. /* vga_wgfx(NULL, VGA_GFX_MODE, 0x40); */
  76. vga_wgfx(NULL, VGA_GFX_MISC, 0x05);
  77. /* vga_wgfx(NULL, VGA_GFX_MISC, 0x01); */
  78. vga_wgfx(NULL, VGA_GFX_COMPARE_MASK, 0x0F);
  79. vga_wgfx(NULL, VGA_GFX_BIT_MASK, 0xFF);
  80. }
  81. /* Set attribute controller registers to sane values */
  82. void svga_set_default_atc_regs(void)
  83. {
  84. u8 count;
  85. vga_r(NULL, 0x3DA);
  86. vga_w(NULL, VGA_ATT_W, 0x00);
  87. /* All standard ATC registers (AR00 - AR14) */
  88. for (count = 0; count <= 0xF; count ++)
  89. svga_wattr(count, count);
  90. svga_wattr(VGA_ATC_MODE, 0x01);
  91. /* svga_wattr(VGA_ATC_MODE, 0x41); */
  92. svga_wattr(VGA_ATC_OVERSCAN, 0x00);
  93. svga_wattr(VGA_ATC_PLANE_ENABLE, 0x0F);
  94. svga_wattr(VGA_ATC_PEL, 0x00);
  95. svga_wattr(VGA_ATC_COLOR_PAGE, 0x00);
  96. vga_r(NULL, 0x3DA);
  97. vga_w(NULL, VGA_ATT_W, 0x20);
  98. }
  99. /* Set sequencer registers to sane values */
  100. void svga_set_default_seq_regs(void)
  101. {
  102. /* Standard sequencer registers (SR01 - SR04), SR00 is not set */
  103. vga_wseq(NULL, VGA_SEQ_CLOCK_MODE, VGA_SR01_CHAR_CLK_8DOTS);
  104. vga_wseq(NULL, VGA_SEQ_PLANE_WRITE, VGA_SR02_ALL_PLANES);
  105. vga_wseq(NULL, VGA_SEQ_CHARACTER_MAP, 0x00);
  106. /* vga_wseq(NULL, VGA_SEQ_MEMORY_MODE, VGA_SR04_EXT_MEM | VGA_SR04_SEQ_MODE | VGA_SR04_CHN_4M); */
  107. vga_wseq(NULL, VGA_SEQ_MEMORY_MODE, VGA_SR04_EXT_MEM | VGA_SR04_SEQ_MODE);
  108. }
  109. /* Set CRTC registers to sane values */
  110. void svga_set_default_crt_regs(void)
  111. {
  112. /* Standard CRT registers CR03 CR08 CR09 CR14 CR17 */
  113. svga_wcrt_mask(0x03, 0x80, 0x80); /* Enable vertical retrace EVRA */
  114. vga_wcrt(NULL, VGA_CRTC_PRESET_ROW, 0);
  115. svga_wcrt_mask(VGA_CRTC_MAX_SCAN, 0, 0x1F);
  116. vga_wcrt(NULL, VGA_CRTC_UNDERLINE, 0);
  117. vga_wcrt(NULL, VGA_CRTC_MODE, 0xE3);
  118. }
  119. void svga_set_textmode_vga_regs(void)
  120. {
  121. /* svga_wseq_mask(0x1, 0x00, 0x01); */ /* Switch 8/9 pixel per char */
  122. vga_wseq(NULL, VGA_SEQ_MEMORY_MODE, VGA_SR04_EXT_MEM);
  123. vga_wseq(NULL, VGA_SEQ_PLANE_WRITE, 0x03);
  124. vga_wcrt(NULL, VGA_CRTC_MAX_SCAN, 0x0f); /* 0x4f */
  125. vga_wcrt(NULL, VGA_CRTC_UNDERLINE, 0x1f);
  126. svga_wcrt_mask(VGA_CRTC_MODE, 0x23, 0x7f);
  127. vga_wcrt(NULL, VGA_CRTC_CURSOR_START, 0x0d);
  128. vga_wcrt(NULL, VGA_CRTC_CURSOR_END, 0x0e);
  129. vga_wcrt(NULL, VGA_CRTC_CURSOR_HI, 0x00);
  130. vga_wcrt(NULL, VGA_CRTC_CURSOR_LO, 0x00);
  131. vga_wgfx(NULL, VGA_GFX_MODE, 0x10); /* Odd/even memory mode */
  132. vga_wgfx(NULL, VGA_GFX_MISC, 0x0E); /* Misc graphics register - text mode enable */
  133. vga_wgfx(NULL, VGA_GFX_COMPARE_MASK, 0x00);
  134. vga_r(NULL, 0x3DA);
  135. vga_w(NULL, VGA_ATT_W, 0x00);
  136. svga_wattr(0x10, 0x0C); /* Attribute Mode Control Register - text mode, blinking and line graphics */
  137. svga_wattr(0x13, 0x08); /* Horizontal Pixel Panning Register */
  138. vga_r(NULL, 0x3DA);
  139. vga_w(NULL, VGA_ATT_W, 0x20);
  140. }
  141. #if 0
  142. void svga_dump_var(struct fb_var_screeninfo *var, int node)
  143. {
  144. pr_debug("fb%d: var.vmode : 0x%X\n", node, var->vmode);
  145. pr_debug("fb%d: var.xres : %d\n", node, var->xres);
  146. pr_debug("fb%d: var.yres : %d\n", node, var->yres);
  147. pr_debug("fb%d: var.bits_per_pixel: %d\n", node, var->bits_per_pixel);
  148. pr_debug("fb%d: var.xres_virtual : %d\n", node, var->xres_virtual);
  149. pr_debug("fb%d: var.yres_virtual : %d\n", node, var->yres_virtual);
  150. pr_debug("fb%d: var.left_margin : %d\n", node, var->left_margin);
  151. pr_debug("fb%d: var.right_margin : %d\n", node, var->right_margin);
  152. pr_debug("fb%d: var.upper_margin : %d\n", node, var->upper_margin);
  153. pr_debug("fb%d: var.lower_margin : %d\n", node, var->lower_margin);
  154. pr_debug("fb%d: var.hsync_len : %d\n", node, var->hsync_len);
  155. pr_debug("fb%d: var.vsync_len : %d\n", node, var->vsync_len);
  156. pr_debug("fb%d: var.sync : 0x%X\n", node, var->sync);
  157. pr_debug("fb%d: var.pixclock : %d\n\n", node, var->pixclock);
  158. }
  159. #endif /* 0 */
  160. /* ------------------------------------------------------------------------- */
  161. void svga_settile(struct fb_info *info, struct fb_tilemap *map)
  162. {
  163. const u8 *font = map->data;
  164. u8 __iomem *fb = (u8 __iomem *)info->screen_base;
  165. int i, c;
  166. if ((map->width != 8) || (map->height != 16) ||
  167. (map->depth != 1) || (map->length != 256)) {
  168. printk(KERN_ERR "fb%d: unsupported font parameters: width %d, height %d, depth %d, length %d\n",
  169. info->node, map->width, map->height, map->depth, map->length);
  170. return;
  171. }
  172. fb += 2;
  173. for (c = 0; c < map->length; c++) {
  174. for (i = 0; i < map->height; i++) {
  175. fb_writeb(font[i], fb + i * 4);
  176. // fb[i * 4] = font[i];
  177. }
  178. fb += 128;
  179. font += map->height;
  180. }
  181. }
  182. /* Copy area in text (tileblit) mode */
  183. void svga_tilecopy(struct fb_info *info, struct fb_tilearea *area)
  184. {
  185. int dx, dy;
  186. /* colstride is halved in this function because u16 are used */
  187. int colstride = 1 << (info->fix.type_aux & FB_AUX_TEXT_SVGA_MASK);
  188. int rowstride = colstride * (info->var.xres_virtual / 8);
  189. u16 __iomem *fb = (u16 __iomem *) info->screen_base;
  190. u16 __iomem *src, *dst;
  191. if ((area->sy > area->dy) ||
  192. ((area->sy == area->dy) && (area->sx > area->dx))) {
  193. src = fb + area->sx * colstride + area->sy * rowstride;
  194. dst = fb + area->dx * colstride + area->dy * rowstride;
  195. } else {
  196. src = fb + (area->sx + area->width - 1) * colstride
  197. + (area->sy + area->height - 1) * rowstride;
  198. dst = fb + (area->dx + area->width - 1) * colstride
  199. + (area->dy + area->height - 1) * rowstride;
  200. colstride = -colstride;
  201. rowstride = -rowstride;
  202. }
  203. for (dy = 0; dy < area->height; dy++) {
  204. u16 __iomem *src2 = src;
  205. u16 __iomem *dst2 = dst;
  206. for (dx = 0; dx < area->width; dx++) {
  207. fb_writew(fb_readw(src2), dst2);
  208. // *dst2 = *src2;
  209. src2 += colstride;
  210. dst2 += colstride;
  211. }
  212. src += rowstride;
  213. dst += rowstride;
  214. }
  215. }
  216. /* Fill area in text (tileblit) mode */
  217. void svga_tilefill(struct fb_info *info, struct fb_tilerect *rect)
  218. {
  219. int dx, dy;
  220. int colstride = 2 << (info->fix.type_aux & FB_AUX_TEXT_SVGA_MASK);
  221. int rowstride = colstride * (info->var.xres_virtual / 8);
  222. int attr = (0x0F & rect->bg) << 4 | (0x0F & rect->fg);
  223. u8 __iomem *fb = (u8 __iomem *)info->screen_base;
  224. fb += rect->sx * colstride + rect->sy * rowstride;
  225. for (dy = 0; dy < rect->height; dy++) {
  226. u8 __iomem *fb2 = fb;
  227. for (dx = 0; dx < rect->width; dx++) {
  228. fb_writeb(rect->index, fb2);
  229. fb_writeb(attr, fb2 + 1);
  230. fb2 += colstride;
  231. }
  232. fb += rowstride;
  233. }
  234. }
  235. /* Write text in text (tileblit) mode */
  236. void svga_tileblit(struct fb_info *info, struct fb_tileblit *blit)
  237. {
  238. int dx, dy, i;
  239. int colstride = 2 << (info->fix.type_aux & FB_AUX_TEXT_SVGA_MASK);
  240. int rowstride = colstride * (info->var.xres_virtual / 8);
  241. int attr = (0x0F & blit->bg) << 4 | (0x0F & blit->fg);
  242. u8 __iomem *fb = (u8 __iomem *)info->screen_base;
  243. fb += blit->sx * colstride + blit->sy * rowstride;
  244. i=0;
  245. for (dy=0; dy < blit->height; dy ++) {
  246. u8 __iomem *fb2 = fb;
  247. for (dx = 0; dx < blit->width; dx ++) {
  248. fb_writeb(blit->indices[i], fb2);
  249. fb_writeb(attr, fb2 + 1);
  250. fb2 += colstride;
  251. i ++;
  252. if (i == blit->length) return;
  253. }
  254. fb += rowstride;
  255. }
  256. }
  257. /* Set cursor in text (tileblit) mode */
  258. void svga_tilecursor(struct fb_info *info, struct fb_tilecursor *cursor)
  259. {
  260. u8 cs = 0x0d;
  261. u8 ce = 0x0e;
  262. u16 pos = cursor->sx + (info->var.xoffset / 8)
  263. + (cursor->sy + (info->var.yoffset / 16))
  264. * (info->var.xres_virtual / 8);
  265. if (! cursor -> mode)
  266. return;
  267. svga_wcrt_mask(0x0A, 0x20, 0x20); /* disable cursor */
  268. if (cursor -> shape == FB_TILE_CURSOR_NONE)
  269. return;
  270. switch (cursor -> shape) {
  271. case FB_TILE_CURSOR_UNDERLINE:
  272. cs = 0x0d;
  273. break;
  274. case FB_TILE_CURSOR_LOWER_THIRD:
  275. cs = 0x09;
  276. break;
  277. case FB_TILE_CURSOR_LOWER_HALF:
  278. cs = 0x07;
  279. break;
  280. case FB_TILE_CURSOR_TWO_THIRDS:
  281. cs = 0x05;
  282. break;
  283. case FB_TILE_CURSOR_BLOCK:
  284. cs = 0x01;
  285. break;
  286. }
  287. /* set cursor position */
  288. vga_wcrt(NULL, 0x0E, pos >> 8);
  289. vga_wcrt(NULL, 0x0F, pos & 0xFF);
  290. vga_wcrt(NULL, 0x0B, ce); /* set cursor end */
  291. vga_wcrt(NULL, 0x0A, cs); /* set cursor start and enable it */
  292. }
  293. /* ------------------------------------------------------------------------- */
  294. /*
  295. * Compute PLL settings (M, N, R)
  296. * F_VCO = (F_BASE * M) / N
  297. * F_OUT = F_VCO / (2^R)
  298. */
  299. static inline u32 abs_diff(u32 a, u32 b)
  300. {
  301. return (a > b) ? (a - b) : (b - a);
  302. }
  303. int svga_compute_pll(const struct svga_pll *pll, u32 f_wanted, u16 *m, u16 *n, u16 *r, int node)
  304. {
  305. u16 am, an, ar;
  306. u32 f_vco, f_current, delta_current, delta_best;
  307. pr_debug("fb%d: ideal frequency: %d kHz\n", node, (unsigned int) f_wanted);
  308. ar = pll->r_max;
  309. f_vco = f_wanted << ar;
  310. /* overflow check */
  311. if ((f_vco >> ar) != f_wanted)
  312. return -EINVAL;
  313. /* It is usually better to have greater VCO clock
  314. because of better frequency stability.
  315. So first try r_max, then r smaller. */
  316. while ((ar > pll->r_min) && (f_vco > pll->f_vco_max)) {
  317. ar--;
  318. f_vco = f_vco >> 1;
  319. }
  320. /* VCO bounds check */
  321. if ((f_vco < pll->f_vco_min) || (f_vco > pll->f_vco_max))
  322. return -EINVAL;
  323. delta_best = 0xFFFFFFFF;
  324. *m = 0;
  325. *n = 0;
  326. *r = ar;
  327. am = pll->m_min;
  328. an = pll->n_min;
  329. while ((am <= pll->m_max) && (an <= pll->n_max)) {
  330. f_current = (pll->f_base * am) / an;
  331. delta_current = abs_diff (f_current, f_vco);
  332. if (delta_current < delta_best) {
  333. delta_best = delta_current;
  334. *m = am;
  335. *n = an;
  336. }
  337. if (f_current <= f_vco) {
  338. am ++;
  339. } else {
  340. an ++;
  341. }
  342. }
  343. f_current = (pll->f_base * *m) / *n;
  344. pr_debug("fb%d: found frequency: %d kHz (VCO %d kHz)\n", node, (int) (f_current >> ar), (int) f_current);
  345. pr_debug("fb%d: m = %d n = %d r = %d\n", node, (unsigned int) *m, (unsigned int) *n, (unsigned int) *r);
  346. return 0;
  347. }
  348. /* ------------------------------------------------------------------------- */
  349. /* Check CRT timing values */
  350. int svga_check_timings(const struct svga_timing_regs *tm, struct fb_var_screeninfo *var, int node)
  351. {
  352. u32 value;
  353. var->xres = (var->xres+7)&~7;
  354. var->left_margin = (var->left_margin+7)&~7;
  355. var->right_margin = (var->right_margin+7)&~7;
  356. var->hsync_len = (var->hsync_len+7)&~7;
  357. /* Check horizontal total */
  358. value = var->xres + var->left_margin + var->right_margin + var->hsync_len;
  359. if (((value / 8) - 5) >= svga_regset_size (tm->h_total_regs))
  360. return -EINVAL;
  361. /* Check horizontal display and blank start */
  362. value = var->xres;
  363. if (((value / 8) - 1) >= svga_regset_size (tm->h_display_regs))
  364. return -EINVAL;
  365. if (((value / 8) - 1) >= svga_regset_size (tm->h_blank_start_regs))
  366. return -EINVAL;
  367. /* Check horizontal sync start */
  368. value = var->xres + var->right_margin;
  369. if (((value / 8) - 1) >= svga_regset_size (tm->h_sync_start_regs))
  370. return -EINVAL;
  371. /* Check horizontal blank end (or length) */
  372. value = var->left_margin + var->right_margin + var->hsync_len;
  373. if ((value == 0) || ((value / 8) >= svga_regset_size (tm->h_blank_end_regs)))
  374. return -EINVAL;
  375. /* Check horizontal sync end (or length) */
  376. value = var->hsync_len;
  377. if ((value == 0) || ((value / 8) >= svga_regset_size (tm->h_sync_end_regs)))
  378. return -EINVAL;
  379. /* Check vertical total */
  380. value = var->yres + var->upper_margin + var->lower_margin + var->vsync_len;
  381. if ((value - 1) >= svga_regset_size(tm->v_total_regs))
  382. return -EINVAL;
  383. /* Check vertical display and blank start */
  384. value = var->yres;
  385. if ((value - 1) >= svga_regset_size(tm->v_display_regs))
  386. return -EINVAL;
  387. if ((value - 1) >= svga_regset_size(tm->v_blank_start_regs))
  388. return -EINVAL;
  389. /* Check vertical sync start */
  390. value = var->yres + var->lower_margin;
  391. if ((value - 1) >= svga_regset_size(tm->v_sync_start_regs))
  392. return -EINVAL;
  393. /* Check vertical blank end (or length) */
  394. value = var->upper_margin + var->lower_margin + var->vsync_len;
  395. if ((value == 0) || (value >= svga_regset_size (tm->v_blank_end_regs)))
  396. return -EINVAL;
  397. /* Check vertical sync end (or length) */
  398. value = var->vsync_len;
  399. if ((value == 0) || (value >= svga_regset_size (tm->v_sync_end_regs)))
  400. return -EINVAL;
  401. return 0;
  402. }
  403. /* Set CRT timing registers */
  404. void svga_set_timings(const struct svga_timing_regs *tm, struct fb_var_screeninfo *var,
  405. u32 hmul, u32 hdiv, u32 vmul, u32 vdiv, u32 hborder, int node)
  406. {
  407. u8 regval;
  408. u32 value;
  409. value = var->xres + var->left_margin + var->right_margin + var->hsync_len;
  410. value = (value * hmul) / hdiv;
  411. pr_debug("fb%d: horizontal total : %d\n", node, value);
  412. svga_wcrt_multi(tm->h_total_regs, (value / 8) - 5);
  413. value = var->xres;
  414. value = (value * hmul) / hdiv;
  415. pr_debug("fb%d: horizontal display : %d\n", node, value);
  416. svga_wcrt_multi(tm->h_display_regs, (value / 8) - 1);
  417. value = var->xres;
  418. value = (value * hmul) / hdiv;
  419. pr_debug("fb%d: horizontal blank start: %d\n", node, value);
  420. svga_wcrt_multi(tm->h_blank_start_regs, (value / 8) - 1 + hborder);
  421. value = var->xres + var->left_margin + var->right_margin + var->hsync_len;
  422. value = (value * hmul) / hdiv;
  423. pr_debug("fb%d: horizontal blank end : %d\n", node, value);
  424. svga_wcrt_multi(tm->h_blank_end_regs, (value / 8) - 1 - hborder);
  425. value = var->xres + var->right_margin;
  426. value = (value * hmul) / hdiv;
  427. pr_debug("fb%d: horizontal sync start : %d\n", node, value);
  428. svga_wcrt_multi(tm->h_sync_start_regs, (value / 8));
  429. value = var->xres + var->right_margin + var->hsync_len;
  430. value = (value * hmul) / hdiv;
  431. pr_debug("fb%d: horizontal sync end : %d\n", node, value);
  432. svga_wcrt_multi(tm->h_sync_end_regs, (value / 8));
  433. value = var->yres + var->upper_margin + var->lower_margin + var->vsync_len;
  434. value = (value * vmul) / vdiv;
  435. pr_debug("fb%d: vertical total : %d\n", node, value);
  436. svga_wcrt_multi(tm->v_total_regs, value - 2);
  437. value = var->yres;
  438. value = (value * vmul) / vdiv;
  439. pr_debug("fb%d: vertical display : %d\n", node, value);
  440. svga_wcrt_multi(tm->v_display_regs, value - 1);
  441. value = var->yres;
  442. value = (value * vmul) / vdiv;
  443. pr_debug("fb%d: vertical blank start : %d\n", node, value);
  444. svga_wcrt_multi(tm->v_blank_start_regs, value);
  445. value = var->yres + var->upper_margin + var->lower_margin + var->vsync_len;
  446. value = (value * vmul) / vdiv;
  447. pr_debug("fb%d: vertical blank end : %d\n", node, value);
  448. svga_wcrt_multi(tm->v_blank_end_regs, value - 2);
  449. value = var->yres + var->lower_margin;
  450. value = (value * vmul) / vdiv;
  451. pr_debug("fb%d: vertical sync start : %d\n", node, value);
  452. svga_wcrt_multi(tm->v_sync_start_regs, value);
  453. value = var->yres + var->lower_margin + var->vsync_len;
  454. value = (value * vmul) / vdiv;
  455. pr_debug("fb%d: vertical sync end : %d\n", node, value);
  456. svga_wcrt_multi(tm->v_sync_end_regs, value);
  457. /* Set horizontal and vertical sync pulse polarity in misc register */
  458. regval = vga_r(NULL, VGA_MIS_R);
  459. if (var->sync & FB_SYNC_HOR_HIGH_ACT) {
  460. pr_debug("fb%d: positive horizontal sync\n", node);
  461. regval = regval & ~0x80;
  462. } else {
  463. pr_debug("fb%d: negative horizontal sync\n", node);
  464. regval = regval | 0x80;
  465. }
  466. if (var->sync & FB_SYNC_VERT_HIGH_ACT) {
  467. pr_debug("fb%d: positive vertical sync\n", node);
  468. regval = regval & ~0x40;
  469. } else {
  470. pr_debug("fb%d: negative vertical sync\n\n", node);
  471. regval = regval | 0x40;
  472. }
  473. vga_w(NULL, VGA_MIS_W, regval);
  474. }
  475. /* ------------------------------------------------------------------------- */
  476. int svga_match_format(const struct svga_fb_format *frm, struct fb_var_screeninfo *var, struct fb_fix_screeninfo *fix)
  477. {
  478. int i = 0;
  479. while (frm->bits_per_pixel != SVGA_FORMAT_END_VAL)
  480. {
  481. if ((var->bits_per_pixel == frm->bits_per_pixel) &&
  482. (var->red.length <= frm->red.length) &&
  483. (var->green.length <= frm->green.length) &&
  484. (var->blue.length <= frm->blue.length) &&
  485. (var->transp.length <= frm->transp.length) &&
  486. (var->nonstd == frm->nonstd)) {
  487. var->bits_per_pixel = frm->bits_per_pixel;
  488. var->red = frm->red;
  489. var->green = frm->green;
  490. var->blue = frm->blue;
  491. var->transp = frm->transp;
  492. var->nonstd = frm->nonstd;
  493. if (fix != NULL) {
  494. fix->type = frm->type;
  495. fix->type_aux = frm->type_aux;
  496. fix->visual = frm->visual;
  497. fix->xpanstep = frm->xpanstep;
  498. }
  499. return i;
  500. }
  501. i++;
  502. frm++;
  503. }
  504. return -EINVAL;
  505. }
  506. EXPORT_SYMBOL(svga_wcrt_multi);
  507. EXPORT_SYMBOL(svga_wseq_multi);
  508. EXPORT_SYMBOL(svga_set_default_gfx_regs);
  509. EXPORT_SYMBOL(svga_set_default_atc_regs);
  510. EXPORT_SYMBOL(svga_set_default_seq_regs);
  511. EXPORT_SYMBOL(svga_set_default_crt_regs);
  512. EXPORT_SYMBOL(svga_set_textmode_vga_regs);
  513. EXPORT_SYMBOL(svga_settile);
  514. EXPORT_SYMBOL(svga_tilecopy);
  515. EXPORT_SYMBOL(svga_tilefill);
  516. EXPORT_SYMBOL(svga_tileblit);
  517. EXPORT_SYMBOL(svga_tilecursor);
  518. EXPORT_SYMBOL(svga_compute_pll);
  519. EXPORT_SYMBOL(svga_check_timings);
  520. EXPORT_SYMBOL(svga_set_timings);
  521. EXPORT_SYMBOL(svga_match_format);
  522. MODULE_AUTHOR("Ondrej Zajicek <santiago@crfreenet.org>");
  523. MODULE_DESCRIPTION("Common utility functions for VGA-based graphics cards");
  524. MODULE_LICENSE("GPL");