ics2494.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Integrated Circuit Systems, Inc.
  3. * ICS2494[A] Dual Video/Memory Clock Generator.
  4. */
  5. #include <u.h>
  6. #include <libc.h>
  7. #include <bio.h>
  8. #include "pci.h"
  9. #include "vga.h"
  10. typedef struct {
  11. char* name[2];
  12. ulong frequency[16];
  13. } Pattern;
  14. static Pattern patterns[] = {
  15. { "237", "304",
  16. 50350000, 56644000, 65000000, 72000000, 80000000, 89800000, 63000000, 75000000,
  17. 25175000, 28322000, 31500000, 36000000, 40000000, 44900000, 50000000, 65000000,
  18. },
  19. { "324", 0,
  20. 50350000, 56644000, 65000000, 72000000, 80000000, 89800000, 63000000, 75000000,
  21. 83078000, 93463000, 100000000, 104000000, 108000000, 120000000, 130000000, 134700000,
  22. },
  23. { 0,
  24. },
  25. };
  26. static void
  27. init(Vga* vga, Ctlr* ctlr)
  28. {
  29. Pattern *pattern;
  30. char *p;
  31. int f, index, divisor, maxdivisor;
  32. if(ctlr->flag & Finit)
  33. return;
  34. if(vga->f[0] == 0)
  35. vga->f[0] = vga->mode->frequency;
  36. if((p = strchr(ctlr->name, '-')) == 0)
  37. error("%s: unknown pattern\n", ctlr->name);
  38. p++;
  39. for(pattern = patterns; pattern->name[0]; pattern++){
  40. if(strcmp(pattern->name[0], p) == 0)
  41. break;
  42. if(pattern->name[1] && strcmp(pattern->name[1], p) == 0)
  43. break;
  44. }
  45. if(pattern->name[0] == 0)
  46. error("%s: unknown pattern\n", ctlr->name);
  47. maxdivisor = 1;
  48. if(vga->ctlr && (vga->ctlr->flag & Hclkdiv))
  49. maxdivisor = 8;
  50. for(index = 0; index < 16; index++){
  51. for(divisor = 1; divisor <= maxdivisor; divisor <<= 1){
  52. f = vga->f[0] - pattern->frequency[index]/divisor;
  53. if(f < 0)
  54. f = -f;
  55. if(f < 1000000){
  56. /*vga->f = pattern->frequency[index];*/
  57. vga->d[0] = divisor;
  58. vga->i[0] = index;
  59. ctlr->flag |= Finit;
  60. return;
  61. }
  62. }
  63. }
  64. error("%s: can't find frequency %ld\n", ctlr->name, vga->f[0]);
  65. }
  66. Ctlr ics2494 = {
  67. "ics2494", /* name */
  68. 0, /* snarf */
  69. 0, /* options */
  70. init, /* init */
  71. 0, /* load */
  72. 0, /* dump */
  73. };
  74. Ctlr ics2494a = {
  75. "ics2494a", /* name */
  76. 0, /* snarf */
  77. 0, /* options */
  78. init, /* init */
  79. 0, /* load */
  80. 0, /* dump */
  81. };