stg1702.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include "pci.h"
  5. #include "vga.h"
  6. /*
  7. * SGS-Thompson STG1702 Enhanced True Color Palette-DAC
  8. * with 16-bit Pixel Port.
  9. */
  10. enum {
  11. Command = 0x00, /* Pixel Command Register */
  12. IndexLO = 0x01, /* LO-byte of 16-bit Index */
  13. IndexHI = 0x02, /* HI-byte of 16-bit Index */
  14. Index = 0x03, /* Indexed Register */
  15. CompanyID = 0x00, /* Company ID = 0x44 */
  16. DeviceID = 0x01, /* Device ID = 0x02 */
  17. Pmode = 0x03, /* Primary Pixel Mode Select */
  18. Smode = 0x04, /* Secondary Pixel Mode Select */
  19. Pipeline = 0x05, /* Pipeline Timing Control */
  20. Sreset = 0x06, /* Soft Reset */
  21. Power = 0x07, /* Power Management */
  22. Nindex = 0x08,
  23. };
  24. static void
  25. pixmask(void)
  26. {
  27. inportb(PaddrW);
  28. }
  29. static void
  30. commandrw(void)
  31. {
  32. int i;
  33. pixmask();
  34. for(i = 0; i < 4; i++)
  35. inportb(Pixmask);
  36. }
  37. static uchar
  38. commandr(void)
  39. {
  40. uchar command;
  41. commandrw();
  42. command = inportb(Pixmask);
  43. pixmask();
  44. return command;
  45. }
  46. static void
  47. commandw(uchar command)
  48. {
  49. commandrw();
  50. outportb(Pixmask, command);
  51. pixmask();
  52. }
  53. static void
  54. indexrw(uchar index)
  55. {
  56. uchar command;
  57. command = commandr();
  58. commandw(command|0x10);
  59. commandrw();
  60. inportb(Pixmask);
  61. outportb(Pixmask, index & 0xFF);
  62. outportb(Pixmask, (index>>8) & 0xFF);
  63. }
  64. static void
  65. options(Vga*, Ctlr* ctlr)
  66. {
  67. ctlr->flag |= Hpclk2x8|Foptions;
  68. }
  69. static void
  70. init(Vga* vga, Ctlr* ctlr)
  71. {
  72. ulong pclk;
  73. /*
  74. * Part comes in -135MHz speed-grade.
  75. * In 8-bit mode the max. PCLK is 110MHz. In 2x8-bit mode
  76. * the max. PCLK is the speed-grade, using the 2x doubler.
  77. * We can use mode 2 (2x8-bit, internal clock doubler)
  78. * if connected to a suitable graphics chip, e.g. the
  79. * ET4000-w32p.
  80. */
  81. if(vga->ctlr && ((vga->ctlr->flag & Hpclk2x8) && vga->mode->z == 8))
  82. pclk = 135000000;
  83. else
  84. pclk = 110000000;
  85. /*
  86. * If we don't already have a desired pclk,
  87. * take it from the mode.
  88. * Check it's within range.
  89. */
  90. if(vga->f[0] == 0)
  91. vga->f[0] = vga->mode->frequency;
  92. if(vga->f[0] < 16000000 || vga->f[0] > pclk)
  93. error("%s: invalid pclk - %ld\n", ctlr->name, vga->f[0]);
  94. /*
  95. * Determine whether to use 2x8-bit mode or not.
  96. * If yes and the clock has already been initialised,
  97. * initialise it again.
  98. */
  99. if(vga->ctlr && (vga->ctlr->flag & Hpclk2x8) && vga->mode->z == 8 && vga->f[0] >= 110000000){
  100. vga->f[0] /= 2;
  101. resyncinit(vga, ctlr, Upclk2x8, 0);
  102. }
  103. ctlr->flag |= Finit;
  104. }
  105. static void
  106. load(Vga* vga, Ctlr* ctlr)
  107. {
  108. uchar command, mode, pipeline;
  109. command = 0x00;
  110. mode = 0x00;
  111. pipeline = 0x02;
  112. if(ctlr->flag & Upclk2x8){
  113. command = 0x08;
  114. mode = 0x05;
  115. pipeline = 0x02;
  116. if(vga->f[0] < 16000000)
  117. pipeline = 0x00;
  118. else if(vga->f[0] < 32000000)
  119. pipeline = 0x01;
  120. }
  121. indexrw(Pmode);
  122. outportb(Pixmask, mode);
  123. outportb(Pixmask, mode);
  124. outportb(Pixmask, pipeline);
  125. sleep(1);
  126. commandw(command);
  127. ctlr->flag |= Fload;
  128. }
  129. static void
  130. dump(Vga*, Ctlr* ctlr)
  131. {
  132. int i;
  133. printitem(ctlr->name, "command");
  134. printreg(commandr());
  135. printitem(ctlr->name, "index");
  136. indexrw(CompanyID);
  137. for(i = 0; i < Nindex; i++)
  138. printreg(inportb(Pixmask));
  139. pixmask();
  140. }
  141. Ctlr stg1702 = {
  142. "stg1702", /* name */
  143. 0, /* snarf */
  144. options, /* options */
  145. init, /* init */
  146. load, /* load */
  147. dump, /* dump */
  148. };