svgalib.c 20 KB

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