acornfb.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *  linux/include/asm-arm/arch-rpc/acornfb.h
  3.  *
  4.  *  Copyright (C) 1999 Russell King
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License version 2 as
  8.  * published by the Free Software Foundation.
  9.  *
  10.  *  AcornFB architecture specific code
  11.  */
  12. #define acornfb_valid_pixrate(rate) (1)
  13. /*
  14.  * Try to find the best PLL parameters for the pixel clock.
  15.  * This algorithm seems to give best predictable results,
  16.  * and produces the same values as detailed in the VIDC20
  17.  * data sheet.
  18.  */
  19. static inline u_int
  20. acornfb_vidc20_find_pll(u_int pixclk)
  21. {
  22. u_int r, best_r = 2, best_v = 2;
  23. int best_d = 0x7fffffff;
  24. for (r = 2; r <= 32; r++) {
  25. u_int rr, v, p;
  26. int d;
  27. rr = 41667 * r;
  28. v = (rr + pixclk / 2) / pixclk;
  29. if (v > 32 || v < 2)
  30. continue;
  31. p = (rr + v / 2) / v;
  32. d = pixclk - p;
  33. if (d < 0)
  34. d = -d;
  35. if (d < best_d) {
  36. best_d = d;
  37. best_v = v - 1;
  38. best_r = r - 1;
  39. }
  40. if (d == 0)
  41. break;
  42. }
  43. return best_v << 8 | best_r;
  44. }
  45. static inline void
  46. acornfb_vidc20_find_rates(struct vidc_timing *vidc,
  47.   struct fb_var_screeninfo *var)
  48. {
  49. u_int div, bandwidth;
  50. /* Select pixel-clock divisor to keep PLL in range */
  51. div = var->pixclock / 9090; /*9921*/
  52. /* Limit divisor */
  53. if (div == 0)
  54. div = 1;
  55. if (div > 8)
  56. div = 8;
  57. /* Encode divisor to VIDC20 setting */
  58. switch (div) {
  59. case 1: vidc->control |= VIDC20_CTRL_PIX_CK;  break;
  60. case 2: vidc->control |= VIDC20_CTRL_PIX_CK2; break;
  61. case 3: vidc->control |= VIDC20_CTRL_PIX_CK3; break;
  62. case 4: vidc->control |= VIDC20_CTRL_PIX_CK4; break;
  63. case 5: vidc->control |= VIDC20_CTRL_PIX_CK5; break;
  64. case 6: vidc->control |= VIDC20_CTRL_PIX_CK6; break;
  65. case 7: vidc->control |= VIDC20_CTRL_PIX_CK7; break;
  66. case 8: vidc->control |= VIDC20_CTRL_PIX_CK8; break;
  67. }
  68. /* Calculate bandwidth */
  69. bandwidth = var->pixclock * 8 / var->bits_per_pixel;
  70. /* Encode bandwidth as VIDC20 setting */
  71. if (bandwidth > 33334)
  72. vidc->control |= VIDC20_CTRL_FIFO_16; /* < 30.0MB/s */
  73. else if (bandwidth > 26666)
  74. vidc->control |= VIDC20_CTRL_FIFO_20; /* < 37.5MB/s */
  75. else if (bandwidth > 22222)
  76. vidc->control |= VIDC20_CTRL_FIFO_24; /* < 45.0MB/s */
  77. else
  78. vidc->control |= VIDC20_CTRL_FIFO_28; /* > 45.0MB/s */
  79. /* Find the PLL values */
  80. vidc->pll_ctl  = acornfb_vidc20_find_pll(var->pixclock / div);
  81. }
  82. #define acornfb_default_control() (VIDC20_CTRL_PIX_VCLK)
  83. #define acornfb_default_econtrol() (VIDC20_ECTL_DAC | VIDC20_ECTL_REG(3))