w30c516.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include "pci.h"
  5. #include "vga.h"
  6. /*
  7. * IC Works W30C516 ZOOMDAC.
  8. * DSP-based Multimedia RAMDAC.
  9. */
  10. enum {
  11. Cr0 = 0x00, /* Control register 0 */
  12. Mid = 0x01, /* Manufacturer's identification register */
  13. Did = 0x02, /* Device identification register */
  14. Cr1 = 0x03, /* Control register 1 */
  15. Reserve1 = 0x04, /* Reserved (16-bit) */
  16. Reserve2 = 0x06, /* Reserved (16-bit) */
  17. Reserve3 = 0x08, /* Reserved (16-bit) */
  18. Reserve4 = 0x0A, /* Reserved (16-bit) */
  19. IstartX = 0x0C, /* Image Start X (16-bit) */
  20. IstartY = 0x0E, /* Image Start Y (16-bit) */
  21. IendX = 0x10, /* Image End X (16-bit) */
  22. IendY = 0x12, /* Image End Y (16-bit) */
  23. RatioX = 0x14, /* Ratio X (16-bit) */
  24. RatioY = 0x16, /* Ratio Y (16-bit) */
  25. OffsetX = 0x18, /* Offset X (16-bit) */
  26. OffsetY = 0x1A, /* Offset Y (16-bit) */
  27. TestR = 0x1C, /* Red signature analysis register */
  28. TestG = 0x1D, /* Green signature analysis register */
  29. TestB = 0x1E, /* Blue signature analysis register */
  30. Nir = 0x1F, /* number of indirect registers */
  31. };
  32. static void
  33. options(Vga*, Ctlr* ctlr)
  34. {
  35. ctlr->flag |= Hpclk2x8|Foptions;
  36. }
  37. static void
  38. init(Vga* vga, Ctlr* ctlr)
  39. {
  40. ulong grade, pclk;
  41. char *p;
  42. /*
  43. * Part comes in -170, -135 and -110MHz speed-grades.
  44. * In 8-bit mode the max. PCLK is 135MHz for the -170 part
  45. * and the speed-grade for the others. In 2x8-bit mode, the max.
  46. * PCLK is the speed-grade, using the 2x doubler.
  47. * Work out the part speed-grade from name. Name can have,
  48. * e.g. '-135' on the end for 135MHz part.
  49. */
  50. grade = 110000000;
  51. if(p = strrchr(ctlr->name, '-'))
  52. grade = strtoul(p+1, 0, 0) * 1000000;
  53. if(grade == 170000000)
  54. pclk = 135000000;
  55. else
  56. pclk = grade;
  57. /*
  58. * If we don't already have a desired pclk,
  59. * take it from the mode.
  60. * Check it's within range.
  61. */
  62. if(vga->f[0] == 0)
  63. vga->f[0] = vga->mode->frequency;
  64. /*
  65. * Determine whether to use 2x8-bit mode or not.
  66. * If yes and the clock has already been initialised,
  67. * initialise it again. There is no real frequency
  68. * restriction, it's really just a lower limit on what's
  69. * available in some clock generator chips.
  70. */
  71. if(vga->ctlr && (vga->ctlr->flag & Hpclk2x8) && vga->mode->z == 8 && vga->f[0] >= 60000000){
  72. vga->f[0] /= 2;
  73. resyncinit(vga, ctlr, Upclk2x8, 0);
  74. }
  75. if(vga->f[0] > pclk)
  76. error("%s: invalid pclk - %ld\n", ctlr->name, vga->f[0]);
  77. ctlr->flag |= Finit;
  78. }
  79. static void
  80. load(Vga* vga, Ctlr* ctlr)
  81. {
  82. uchar mode, x;
  83. /*
  84. * Put the chip to sleep.
  85. */
  86. attdaco(Cr0, 0x08);
  87. mode = 0x00;
  88. if(ctlr->flag & Upclk2x8)
  89. mode = 0x20;
  90. /*
  91. * Set the mode in the RAMDAC, setting 6/8-bit colour
  92. * as appropriate and waking the chip back up.
  93. */
  94. if(vga->mode->z == 8 && 0)
  95. mode |= 0x02;
  96. x = attdaci(Cr1) & 0x80;
  97. attdaco(Cr1, x);
  98. attdaco(Cr0, mode);
  99. ctlr->flag |= Fload;
  100. }
  101. static void
  102. dump(Vga*, Ctlr* ctlr)
  103. {
  104. int i;
  105. printitem(ctlr->name, "");
  106. for(i = 0; i < Nir; i++)
  107. printreg(attdaci(i));
  108. }
  109. Ctlr w30c516 = {
  110. "w30c516", /* name */
  111. 0, /* snarf */
  112. options, /* options */
  113. init, /* init */
  114. load, /* load */
  115. dump, /* dump */
  116. };