i810_gtf.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*-*- linux-c -*-
  2. * linux/drivers/video/i810_main.h -- Intel 810 Non-discrete Video Timings
  3. * (VESA GTF)
  4. *
  5. * Copyright (C) 2001 Antonino Daplas<adaplas@pol.net>
  6. * All Rights Reserved
  7. *
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file COPYING in the main directory of this archive for
  11. * more details.
  12. */
  13. #include <linux/kernel.h>
  14. #include "i810_regs.h"
  15. #include "i810.h"
  16. #include "i810_main.h"
  17. /*
  18. * FIFO and Watermark tables - based almost wholly on i810_wmark.c in
  19. * XFree86 v4.03 by Precision Insight. Slightly modified for integer
  20. * operation, instead of float
  21. */
  22. struct wm_info {
  23. u32 freq;
  24. u32 wm;
  25. };
  26. static struct wm_info i810_wm_8_100[] = {
  27. { 15, 0x0070c000 }, { 19, 0x0070c000 }, { 25, 0x22003000 },
  28. { 28, 0x22003000 }, { 31, 0x22003000 }, { 36, 0x22007000 },
  29. { 40, 0x22007000 }, { 45, 0x22007000 }, { 49, 0x22008000 },
  30. { 50, 0x22008000 }, { 56, 0x22008000 }, { 65, 0x22008000 },
  31. { 75, 0x22008000 }, { 78, 0x22008000 }, { 80, 0x22008000 },
  32. { 94, 0x22008000 }, { 96, 0x22107000 }, { 99, 0x22107000 },
  33. { 108, 0x22107000 }, { 121, 0x22107000 }, { 128, 0x22107000 },
  34. { 132, 0x22109000 }, { 135, 0x22109000 }, { 157, 0x2210b000 },
  35. { 162, 0x2210b000 }, { 175, 0x2210b000 }, { 189, 0x2220e000 },
  36. { 195, 0x2220e000 }, { 202, 0x2220e000 }, { 204, 0x2220e000 },
  37. { 218, 0x2220f000 }, { 229, 0x22210000 }, { 234, 0x22210000 },
  38. };
  39. static struct wm_info i810_wm_16_100[] = {
  40. { 15, 0x0070c000 }, { 19, 0x0020c000 }, { 25, 0x22006000 },
  41. { 28, 0x22006000 }, { 31, 0x22007000 }, { 36, 0x22007000 },
  42. { 40, 0x22007000 }, { 45, 0x22007000 }, { 49, 0x22009000 },
  43. { 50, 0x22009000 }, { 56, 0x22108000 }, { 65, 0x2210e000 },
  44. { 75, 0x2210e000 }, { 78, 0x2210e000 }, { 80, 0x22210000 },
  45. { 94, 0x22210000 }, { 96, 0x22210000 }, { 99, 0x22210000 },
  46. { 108, 0x22210000 }, { 121, 0x22210000 }, { 128, 0x22210000 },
  47. { 132, 0x22314000 }, { 135, 0x22314000 }, { 157, 0x22415000 },
  48. { 162, 0x22416000 }, { 175, 0x22416000 }, { 189, 0x22416000 },
  49. { 195, 0x22416000 }, { 202, 0x22416000 }, { 204, 0x22416000 },
  50. { 218, 0x22416000 }, { 229, 0x22416000 },
  51. };
  52. static struct wm_info i810_wm_24_100[] = {
  53. { 15, 0x0020c000 }, { 19, 0x0040c000 }, { 25, 0x22009000 },
  54. { 28, 0x22009000 }, { 31, 0x2200a000 }, { 36, 0x2210c000 },
  55. { 40, 0x2210c000 }, { 45, 0x2210c000 }, { 49, 0x22111000 },
  56. { 50, 0x22111000 }, { 56, 0x22111000 }, { 65, 0x22214000 },
  57. { 75, 0x22214000 }, { 78, 0x22215000 }, { 80, 0x22216000 },
  58. { 94, 0x22218000 }, { 96, 0x22418000 }, { 99, 0x22418000 },
  59. { 108, 0x22418000 }, { 121, 0x22418000 }, { 128, 0x22419000 },
  60. { 132, 0x22519000 }, { 135, 0x4441d000 }, { 157, 0x44419000 },
  61. { 162, 0x44419000 }, { 175, 0x44419000 }, { 189, 0x44419000 },
  62. { 195, 0x44419000 }, { 202, 0x44419000 }, { 204, 0x44419000 },
  63. };
  64. static struct wm_info i810_wm_8_133[] = {
  65. { 15, 0x0070c000 }, { 19, 0x0070c000 }, { 25, 0x22003000 },
  66. { 28, 0x22003000 }, { 31, 0x22003000 }, { 36, 0x22007000 },
  67. { 40, 0x22007000 }, { 45, 0x22007000 }, { 49, 0x22008000 },
  68. { 50, 0x22008000 }, { 56, 0x22008000 }, { 65, 0x22008000 },
  69. { 75, 0x22008000 }, { 78, 0x22008000 }, { 80, 0x22008000 },
  70. { 94, 0x22008000 }, { 96, 0x22107000 }, { 99, 0x22107000 },
  71. { 108, 0x22107000 }, { 121, 0x22107000 }, { 128, 0x22107000 },
  72. { 132, 0x22109000 }, { 135, 0x22109000 }, { 157, 0x2210b000 },
  73. { 162, 0x2210b000 }, { 175, 0x2210b000 }, { 189, 0x2220e000 },
  74. { 195, 0x2220e000 }, { 202, 0x2220e000 }, { 204, 0x2220e000 },
  75. { 218, 0x2220f000 }, { 229, 0x22210000 }, { 234, 0x22210000 },
  76. };
  77. static struct wm_info i810_wm_16_133[] = {
  78. { 15, 0x0020c000 }, { 19, 0x0020c000 }, { 25, 0x22006000 },
  79. { 28, 0x22006000 }, { 31, 0x22007000 }, { 36, 0x22007000 },
  80. { 40, 0x22007000 }, { 45, 0x22007000 }, { 49, 0x22009000 },
  81. { 50, 0x22009000 }, { 56, 0x22108000 }, { 65, 0x2210e000 },
  82. { 75, 0x2210e000 }, { 78, 0x2210e000 }, { 80, 0x22210000 },
  83. { 94, 0x22210000 }, { 96, 0x22210000 }, { 99, 0x22210000 },
  84. { 108, 0x22210000 }, { 121, 0x22210000 }, { 128, 0x22210000 },
  85. { 132, 0x22314000 }, { 135, 0x22314000 }, { 157, 0x22415000 },
  86. { 162, 0x22416000 }, { 175, 0x22416000 }, { 189, 0x22416000 },
  87. { 195, 0x22416000 }, { 202, 0x22416000 }, { 204, 0x22416000 },
  88. { 218, 0x22416000 }, { 229, 0x22416000 },
  89. };
  90. static struct wm_info i810_wm_24_133[] = {
  91. { 15, 0x0020c000 }, { 19, 0x00408000 }, { 25, 0x22009000 },
  92. { 28, 0x22009000 }, { 31, 0x2200a000 }, { 36, 0x2210c000 },
  93. { 40, 0x2210c000 }, { 45, 0x2210c000 }, { 49, 0x22111000 },
  94. { 50, 0x22111000 }, { 56, 0x22111000 }, { 65, 0x22214000 },
  95. { 75, 0x22214000 }, { 78, 0x22215000 }, { 80, 0x22216000 },
  96. { 94, 0x22218000 }, { 96, 0x22418000 }, { 99, 0x22418000 },
  97. { 108, 0x22418000 }, { 121, 0x22418000 }, { 128, 0x22419000 },
  98. { 132, 0x22519000 }, { 135, 0x4441d000 }, { 157, 0x44419000 },
  99. { 162, 0x44419000 }, { 175, 0x44419000 }, { 189, 0x44419000 },
  100. { 195, 0x44419000 }, { 202, 0x44419000 }, { 204, 0x44419000 },
  101. };
  102. void round_off_xres(u32 *xres) { }
  103. void round_off_yres(u32 *xres, u32 *yres) { }
  104. /**
  105. * i810fb_encode_registers - encode @var to hardware register values
  106. * @var: pointer to var structure
  107. * @par: pointer to hardware par structure
  108. *
  109. * DESCRIPTION:
  110. * Timing values in @var will be converted to appropriate
  111. * register values of @par.
  112. */
  113. void i810fb_encode_registers(const struct fb_var_screeninfo *var,
  114. struct i810fb_par *par, u32 xres, u32 yres)
  115. {
  116. int n, blank_s, blank_e;
  117. u8 __iomem *mmio = par->mmio_start_virtual;
  118. u8 msr = 0;
  119. /* Horizontal */
  120. /* htotal */
  121. n = ((xres + var->right_margin + var->hsync_len +
  122. var->left_margin) >> 3) - 5;
  123. par->regs.cr00 = (u8) n;
  124. par->regs.cr35 = (u8) ((n >> 8) & 1);
  125. /* xres */
  126. par->regs.cr01 = (u8) ((xres >> 3) - 1);
  127. /* hblank */
  128. blank_e = (xres + var->right_margin + var->hsync_len +
  129. var->left_margin) >> 3;
  130. blank_e--;
  131. blank_s = blank_e - 127;
  132. if (blank_s < (xres >> 3))
  133. blank_s = xres >> 3;
  134. par->regs.cr02 = (u8) blank_s;
  135. par->regs.cr03 = (u8) (blank_e & 0x1F);
  136. par->regs.cr05 = (u8) ((blank_e & (1 << 5)) << 2);
  137. par->regs.cr39 = (u8) ((blank_e >> 6) & 1);
  138. /* hsync */
  139. par->regs.cr04 = (u8) ((xres + var->right_margin) >> 3);
  140. par->regs.cr05 |= (u8) (((xres + var->right_margin +
  141. var->hsync_len) >> 3) & 0x1F);
  142. /* Vertical */
  143. /* vtotal */
  144. n = yres + var->lower_margin + var->vsync_len + var->upper_margin - 2;
  145. par->regs.cr06 = (u8) (n & 0xFF);
  146. par->regs.cr30 = (u8) ((n >> 8) & 0x0F);
  147. /* vsync */
  148. n = yres + var->lower_margin;
  149. par->regs.cr10 = (u8) (n & 0xFF);
  150. par->regs.cr32 = (u8) ((n >> 8) & 0x0F);
  151. par->regs.cr11 = i810_readb(CR11, mmio) & ~0x0F;
  152. par->regs.cr11 |= (u8) ((yres + var->lower_margin +
  153. var->vsync_len) & 0x0F);
  154. /* yres */
  155. n = yres - 1;
  156. par->regs.cr12 = (u8) (n & 0xFF);
  157. par->regs.cr31 = (u8) ((n >> 8) & 0x0F);
  158. /* vblank */
  159. blank_e = yres + var->lower_margin + var->vsync_len +
  160. var->upper_margin;
  161. blank_e--;
  162. blank_s = blank_e - 127;
  163. if (blank_s < yres)
  164. blank_s = yres;
  165. par->regs.cr15 = (u8) (blank_s & 0xFF);
  166. par->regs.cr33 = (u8) ((blank_s >> 8) & 0x0F);
  167. par->regs.cr16 = (u8) (blank_e & 0xFF);
  168. par->regs.cr09 = 0;
  169. /* sync polarity */
  170. if (!(var->sync & FB_SYNC_HOR_HIGH_ACT))
  171. msr |= 1 << 6;
  172. if (!(var->sync & FB_SYNC_VERT_HIGH_ACT))
  173. msr |= 1 << 7;
  174. par->regs.msr = msr;
  175. /* interlace */
  176. if (var->vmode & FB_VMODE_INTERLACED)
  177. par->interlace = (1 << 7) | ((u8) (var->yres >> 4));
  178. else
  179. par->interlace = 0;
  180. if (var->vmode & FB_VMODE_DOUBLE)
  181. par->regs.cr09 |= 1 << 7;
  182. /* overlay */
  183. par->ovract = ((var->xres + var->right_margin + var->hsync_len +
  184. var->left_margin - 32) | ((var->xres - 32) << 16));
  185. }
  186. void i810fb_fill_var_timings(struct fb_var_screeninfo *var) { }
  187. /**
  188. * i810_get_watermark - gets watermark
  189. * @var: pointer to fb_var_screeninfo
  190. * @par: pointer to i810fb_par structure
  191. *
  192. * DESCRIPTION:
  193. * Gets the required watermark based on
  194. * pixelclock and RAMBUS frequency.
  195. *
  196. * RETURNS:
  197. * watermark
  198. */
  199. u32 i810_get_watermark(const struct fb_var_screeninfo *var,
  200. struct i810fb_par *par)
  201. {
  202. struct wm_info *wmark = NULL;
  203. u32 i, size = 0, pixclock, wm_best = 0, min, diff;
  204. if (par->mem_freq == 100) {
  205. switch (var->bits_per_pixel) {
  206. case 8:
  207. wmark = i810_wm_8_100;
  208. size = ARRAY_SIZE(i810_wm_8_100);
  209. break;
  210. case 16:
  211. wmark = i810_wm_16_100;
  212. size = ARRAY_SIZE(i810_wm_16_100);
  213. break;
  214. case 24:
  215. case 32:
  216. wmark = i810_wm_24_100;
  217. size = ARRAY_SIZE(i810_wm_24_100);
  218. }
  219. } else {
  220. switch(var->bits_per_pixel) {
  221. case 8:
  222. wmark = i810_wm_8_133;
  223. size = ARRAY_SIZE(i810_wm_8_133);
  224. break;
  225. case 16:
  226. wmark = i810_wm_16_133;
  227. size = ARRAY_SIZE(i810_wm_16_133);
  228. break;
  229. case 24:
  230. case 32:
  231. wmark = i810_wm_24_133;
  232. size = ARRAY_SIZE(i810_wm_24_133);
  233. }
  234. }
  235. pixclock = 1000000/var->pixclock;
  236. min = ~0;
  237. for (i = 0; i < size; i++) {
  238. if (pixclock <= wmark[i].freq)
  239. diff = wmark[i].freq - pixclock;
  240. else
  241. diff = pixclock - wmark[i].freq;
  242. if (diff < min) {
  243. wm_best = wmark[i].wm;
  244. min = diff;
  245. }
  246. }
  247. return wm_best;
  248. }