bt485.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include "pci.h"
  5. #include "vga.h"
  6. /*
  7. * Brooktree Bt485 Monolithic True-Color RAMDAC.
  8. * Assumes hooked up to an S3 86C928.
  9. *
  10. * There are only 16 directly addressable registers,
  11. * Cmd3 is accessed indirectly and overlays the
  12. * status register. We make this register index 0x1A.
  13. * Cmd4 is an artifact of the Tvp3025 in Bt485
  14. * emulation mode.
  15. */
  16. enum {
  17. AddrW = 0x00, /* Address register; palette/cursor RAM write */
  18. Palette = 0x01, /* 6/8-bit color palette data */
  19. Pmask = 0x02, /* Pixel mask register */
  20. AddrR = 0x03, /* Address register; palette/cursor RAM read */
  21. ColorW = 0x04, /* Address register; cursor/overscan color write */
  22. Color = 0x05, /* Cursor/overscan color data */
  23. Cmd0 = 0x06, /* Command register 0 */
  24. ColorR = 0x07, /* Address register; cursor/overscan color read */
  25. Cmd1 = 0x08, /* Command register 1 */
  26. Cmd2 = 0x09, /* Command register 2 */
  27. Status = 0x0A, /* Status */
  28. Cram = 0x0B, /* Cursor RAM array data */
  29. Cxlr = 0x0C, /* Cursor x-low register */
  30. Cxhr = 0x0D, /* Cursor x-high register */
  31. Cylr = 0x0E, /* Cursor y-low register */
  32. Cyhr = 0x0F, /* Cursor y-high register */
  33. Nreg = 0x10,
  34. Cmd3 = 0x1A, /* Command register 3 */
  35. Cmd4 = 0x2A, /* Command register 4 */
  36. };
  37. static uchar
  38. bt485io(uchar reg)
  39. {
  40. uchar crt55, cr0;
  41. if(reg >= Nreg && (reg & 0x0F) != Status)
  42. error("%s: bad reg - 0x%X\n", bt485.name, reg);
  43. crt55 = vgaxi(Crtx, 0x55) & 0xFC;
  44. if((reg & 0x0F) == Status){
  45. /*
  46. * 1,2: Set indirect addressing for Status or
  47. * Cmd[34] - set bit7 of Cr0.
  48. */
  49. vgaxo(Crtx, 0x55, crt55|((Cmd0>>2) & 0x03));
  50. cr0 = vgai(dacxreg[Cmd0 & 0x03])|0x80;
  51. vgao(dacxreg[Cmd0 & 0x03], cr0);
  52. /*
  53. * 3,4: Set the index into the Write register,
  54. * index == 0x00 for Status, 0x01 for Cmd3,
  55. * 0x02 for Cmd4.
  56. */
  57. vgaxo(Crtx, 0x55, crt55|((AddrW>>2) & 0x03));
  58. vgao(dacxreg[AddrW & 0x03], (reg>>4) & 0x0F);
  59. /*
  60. * 5,6: Get the contents of the appropriate
  61. * register at 0x0A.
  62. */
  63. }
  64. return crt55;
  65. }
  66. uchar
  67. bt485i(uchar reg)
  68. {
  69. uchar crt55, r;
  70. crt55 = bt485io(reg);
  71. vgaxo(Crtx, 0x55, crt55|((reg>>2) & 0x03));
  72. r = vgai(dacxreg[reg & 0x03]);
  73. vgaxo(Crtx, 0x55, crt55);
  74. return r;
  75. }
  76. void
  77. bt485o(uchar reg, uchar data)
  78. {
  79. uchar crt55;
  80. crt55 = bt485io(reg);
  81. vgaxo(Crtx, 0x55, crt55|((reg>>2) & 0x03));
  82. vgao(dacxreg[reg & 0x03], data);
  83. vgaxo(Crtx, 0x55, crt55);
  84. }
  85. static void
  86. options(Vga*, Ctlr* ctlr)
  87. {
  88. ctlr->flag |= Hsid32|Hclk2|Hextsid|Henhanced|Foptions;
  89. }
  90. static void
  91. init(Vga* vga, Ctlr* ctlr)
  92. {
  93. ulong grade;
  94. char *p;
  95. /*
  96. * Work out the part speed-grade from name. Name can have,
  97. * e.g. '-135' on the end for 135MHz part.
  98. */
  99. grade = 110000000;
  100. if(p = strrchr(ctlr->name, '-'))
  101. grade = strtoul(p+1, 0, 0) * 1000000;
  102. /*
  103. * If we don't already have a desired pclk,
  104. * take it from the mode.
  105. * Check it's within range.
  106. */
  107. if(vga->f[0] == 0)
  108. vga->f[0] = vga->mode->frequency;
  109. if(vga->f[0] > grade)
  110. error("%s: invalid pclk - %ld\n", ctlr->name, vga->f[0]);
  111. /*
  112. * Determine whether to use clock-doubler or not.
  113. */
  114. if((ctlr->flag & Uclk2) == 0 && vga->f[0] > 67500000){
  115. vga->f[0] /= 2;
  116. resyncinit(vga, ctlr, Uclk2, 0);
  117. }
  118. ctlr->flag |= Finit;
  119. }
  120. static void
  121. load(Vga*, Ctlr* ctlr)
  122. {
  123. uchar x;
  124. /*
  125. * Put the chip to sleep before (possibly) changing the clock-source
  126. * to ensure the integrity of the palette.
  127. */
  128. x = bt485i(Cmd0);
  129. bt485o(Cmd0, x|0x01); /* sleep mode */
  130. /*
  131. * Set the clock-source, clock-doubler and frequency
  132. * appropriately:
  133. * if using the pixel-port, use Pclock1;
  134. * use the doubler if fvco > 67.5MHz.
  135. * set the frequency.
  136. */
  137. x = bt485i(Cmd2);
  138. if(ctlr->flag & Uenhanced)
  139. x |= 0x10; /* Pclock1 */
  140. else
  141. x &= ~0x10;
  142. bt485o(Cmd2, x);
  143. x = bt485i(Cmd3);
  144. if(ctlr->flag & Uclk2)
  145. x |= 0x08; /* clock-doubler */
  146. else
  147. x &= ~0x08;
  148. bt485o(Cmd3, x);
  149. /*
  150. * Set 4:1 multiplex and portselect bits on the
  151. * Bt485 appropriately for using the pixel-port.
  152. */
  153. x = bt485i(Cmd2);
  154. if(ctlr->flag & Uenhanced){
  155. bt485o(Cmd1, 0x40); /* 4:1 multiplex */
  156. x |= 0x20; /* portselect */
  157. }
  158. else{
  159. bt485o(Cmd1, 0x00);
  160. x &= ~0x20;
  161. }
  162. bt485o(Cmd2, x);
  163. x = bt485i(Cmd4);
  164. if(ctlr->flag & Uenhanced)
  165. x |= 0x01;
  166. else
  167. x &= ~0x01;
  168. bt485o(Cmd4, x);
  169. /*
  170. * All done, wake the chip back up.
  171. * Set 6/8-bit colour as appropriate.
  172. */
  173. x = bt485i(Cmd0) & ~0x01;
  174. /*if(vga->mode.z == 8)
  175. x |= 0x02;
  176. else*/
  177. x &= ~0x02;
  178. bt485o(Cmd0, x);
  179. ctlr->flag |= Fload;
  180. }
  181. static void
  182. dump(Vga*, Ctlr* ctlr)
  183. {
  184. int i;
  185. printitem(ctlr->name, "direct");
  186. for(i = 0; i < 0x10; i++)
  187. printreg(bt485i(i));
  188. printitem(ctlr->name, "indirect");
  189. printreg(bt485i(Cmd3));
  190. printreg(bt485i(Cmd4));
  191. }
  192. Ctlr bt485 = {
  193. "bt485", /* name */
  194. 0, /* snarf */
  195. options, /* options */
  196. init, /* init */
  197. load, /* load */
  198. dump, /* dump */
  199. };