home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / IBMGPMI / S3LACUNA.C < prev   
C/C++ Source or Header  |  1995-04-14  |  19KB  |  568 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  4. /*                                                                           */
  5. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  6. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  7. /*    drivers. You may use this code in accordance with the IBM License      */
  8. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  9. /*    Copyright statement may not be removed.                                */
  10. /*                                                                           */
  11. /*****************************************************************************/
  12. /**************************************************************************
  13.  *
  14.  * SOURCE FILE NAME = s3lacuna.c
  15.  *
  16.  * DESCRIPTIVE NAME = Chip specific PMI functions
  17.  *
  18.  *
  19.  * VERSION = V2.1
  20.  *
  21.  * DATE
  22.  *
  23.  * DESCRIPTION PMI-file handler - Exported entry points
  24.  *
  25.  * FUNCTIONS
  26.  *
  27.  * DEPENDENCIES:
  28.  *
  29.  * NOTES
  30.  *
  31.  * STRUCTURES
  32.  *
  33.  * EXTERNAL REFERENCES
  34.  *
  35.  * EXTERNAL FUNCTIONS
  36.  *
  37. */
  38.  
  39. #pragma langlvl(extended)
  40. #include "ipmitype.h"
  41. #include <conio.h>
  42. /*****************************************************************************
  43.  *
  44.  *  FUNCTION NAME:      pfnSetS3Lacuna()
  45.  *
  46.  *  DESCRIPTIVE NAME:   Program the clock related registers based on the input data.
  47.  *
  48.  *  FUNCTION:
  49.  *
  50.  *  INPUT:              PVIDEO_ADAPTER - Pointer to current state of the adapter/mode
  51.  *                      PREGS- Pointer to current register state
  52.  *
  53.  *  EXIT:               APIRET - return code
  54.  *
  55.  *  NOTES:              Program the S3864 adapters with ICD2061 clock chip
  56.  *
  57.  *  INTERNAL REFERENCES:
  58.  *    ROUTINES:
  59.  *
  60.  *  EXTERNAL REFERENCES:
  61.  *    ROUTINES:
  62.  ****************************************************************************/
  63. APIRET EXPENTRY  pfnSetS3Lacuna(PVIDEO_ADAPTER pAdapter,PREGS pRegs)
  64. {
  65.   ULONG rc = NO_ERROR;
  66.   USHORT crtcport = (_inp(0x3cc) & 0x01) ? 0x3D4 : 0x3B4;
  67.   BYTE r0, r1, r2;
  68.  
  69.   if (!(pAdapter->ModeInfo.usType & MODE_FLAG_GRAPHICS))
  70.       return (ERROR_REFRESH_NOT_SUPPORTED);
  71.   else
  72.   {
  73.     _outp(crtcport, 0x11);                   //yee dbug
  74.     r0 = _inp(crtcport+1);
  75.     _outp(crtcport+1, (r0 & 0x7F));
  76.  
  77.     switch(pAdapter->ModeInfo.usXResolution)
  78.     {
  79.       case 640:
  80.          _outpw(crtcport, 0x0b06);
  81.          _outpw(crtcport, 0xea10);
  82.          _outpw(crtcport, 0x0b16);
  83.          switch(pAdapter->ModeInfo.bBitsPerPixel)
  84.          {
  85.             case 8:
  86.             case 4:
  87.                _outpw(crtcport, 0x5f00);
  88.                _outpw(crtcport, 0x8203);
  89.                _outpw(crtcport, 0x5304);
  90.  
  91.                _outp(crtcport, 0x34);
  92.                r0 = _inp(crtcport+1);
  93.                _outp(crtcport+1, (r0 & 0xef));
  94.  
  95.                _outp(crtcport, 0x43);
  96.                r0 = _inp(crtcport+1);
  97.                _outp(crtcport+1, (r0 & 0x7f));
  98.  
  99.                _outp(crtcport, 0x5d);
  100.                r0 = _inp(crtcport+1);
  101.                _outp(crtcport+1, (r0 & 0x80));
  102.  
  103.                _outp(crtcport, 0x5c);
  104.                r0 = _inp(crtcport+1);
  105.  
  106.                switch(pAdapter->ModeInfo.bVrtRefresh)
  107.                {
  108.                   case 75:
  109.                     _outp(crtcport+1, ((r0 & 0xcf) | 0x20));
  110.                     _outpw(crtcport, 0x5204);
  111.                     _outpw(crtcport, 0x9e05);
  112.                     _outpw(crtcport, 0x8c11);
  113.                     break;
  114.  
  115.                   case 72:
  116.                     _outp(crtcport+1, ((r0 & 0xcf) | 0x20));
  117.                     _outpw(crtcport, 0x6300);
  118.                     _outpw(crtcport, 0x8603);
  119.                     _outpw(crtcport, 0x9805);
  120.                     _outpw(crtcport, 0x0606);
  121.                     _outpw(crtcport, 0xe810);
  122.                     _outpw(crtcport, 0x8b11);
  123.                     _outpw(crtcport, 0x0616);
  124.                     break;
  125.  
  126.                   case 60:
  127.                   default:
  128.                     _outp(crtcport+1, (r0 & 0xcf));
  129.                     _outpw(crtcport, 0x9f05);
  130.                     _outpw(crtcport, 0x8c11);
  131.                     break;
  132.                }
  133.                break;
  134.  
  135.             case 16:
  136.                _outpw(crtcport, 0xc300);
  137.                _outpw(crtcport, 0x8603);
  138.                _outpw(crtcport, 0xa404);
  139.                _outpw(crtcport, 0x1c05);
  140.                _outpw(crtcport, 0x0442);
  141.  
  142.                _outp(crtcport, 0x34);
  143.                r0 = _inp(crtcport+1);
  144.                _outp(crtcport+1, (r0 & 0xef));
  145.  
  146.                _outp(crtcport, 0x43);
  147.                r0 = _inp(crtcport+1);
  148.                _outp(crtcport+1, (r0 & 0x7f));
  149.  
  150.                _outp(crtcport, 0x5d);
  151.                r0 = _inp(crtcport+1);
  152.                _outp(crtcport+1, (r0 & 0x80));
  153.  
  154.                _outp(crtcport, 0x5c);
  155.                r0 = _inp(crtcport+1);
  156.  
  157.                switch(pAdapter->ModeInfo.bVrtRefresh)
  158.                {
  159.                   case 75:
  160.                     _outp(crtcport+1, ((r0 & 0xcf) | 0x30));
  161.                     _outpw(crtcport, 0x8c11);
  162.                     break;
  163.  
  164.                   case 72:
  165.                     _outp(crtcport+1, ((r0 & 0xcf) | 0x10));
  166.                     _outpw(crtcport, 0xcb00);
  167.                     _outpw(crtcport, 0x8e03);
  168.                     _outpw(crtcport, 0xa604);
  169.                     _outpw(crtcport, 0x1005);
  170.                     _outpw(crtcport, 0x0606);
  171.                     _outpw(crtcport, 0xe810);
  172.                     _outpw(crtcport, 0x8b11);
  173.                     _outpw(crtcport, 0x0616);
  174.                     break;
  175.  
  176.                   case 60:
  177.                   default:
  178.                     _outp(crtcport+1, ((r0 & 0xcf) | 0x10));
  179.                     _outpw(crtcport, 0x8c11);
  180.                     _outpw(crtcport, 0x0042);
  181.                     break;
  182.                }
  183.                break;
  184.  
  185.             case 24:
  186.                _outpw(crtcport, 0x9100);
  187.                _outpw(crtcport, 0x7701);
  188.                _outpw(crtcport, 0x7702);
  189.                _outpw(crtcport, 0x9203);
  190.                _outpw(crtcport, 0x7b04);
  191.                _outpw(crtcport, 0x0d05);
  192.                _outpw(crtcport, 0x0742);
  193.  
  194.                _outp(crtcport, 0x34);
  195.                r0 = _inp(crtcport+1);
  196.                _outp(crtcport+1, (r0 & 0xef));
  197.  
  198.                _outp(crtcport, 0x5d);
  199.                r0 = _inp(crtcport+1);
  200.  
  201.                _outp(crtcport, 0x5c);
  202.                r1 = _inp(crtcport+1);
  203.  
  204.                _outp(crtcport, 0x43);
  205.                r2 = _inp(crtcport+1);
  206.  
  207.                switch(pAdapter->ModeInfo.bVrtRefresh)
  208.                {
  209.                   case 75:
  210.                     _outp(crtcport+1, ((r2 & 0x7f) | 0x80));
  211.                     _outpw(crtcport, 0x8c11);
  212.  
  213.                     _outp(crtcport, 0x5c);
  214.                     _outp(crtcport+1, ((r1 & 0xcf) | 0x20));
  215.  
  216.                     _outp(crtcport, 0x5d);
  217.                     _outp(crtcport+1, ((r0 & 0x80) | 0x00));
  218.                     break;
  219.  
  220.                   case 72:
  221.                     _outp(crtcport+1, ((r0 & 0x7f) | 0x00));
  222.                     _outpw(crtcport, 0x3300);
  223.                     _outpw(crtcport, 0xef01);
  224.                     _outpw(crtcport, 0xef02);
  225.                     _outpw(crtcport, 0x9503);
  226.                     _outpw(crtcport, 0xf904);
  227.                     _outpw(crtcport, 0x8805);
  228.                     _outpw(crtcport, 0x0606);
  229.                     _outpw(crtcport, 0xe810);
  230.                     _outpw(crtcport, 0x8b11);
  231.                     _outpw(crtcport, 0x0616);
  232.  
  233.                     _outp(crtcport, 0x5c);
  234.                     _outp(crtcport+1, ((r1 & 0xcf) | 0x30));
  235.  
  236.                     _outp(crtcport, 0x5d);
  237.                     _outp(crtcport+1, ((r0 & 0x80) | 0x01));
  238.                     break;
  239.  
  240.                   case 60:
  241.                   default:
  242.                     _outp(crtcport+1, ((r0 & 0x7f) | 0x80));
  243.  
  244.                     _outpw(crtcport, 0x8c11);
  245.                     _outpw(crtcport, 0x0442);
  246.  
  247.                     _outp(crtcport, 0x5c);
  248.                     _outp(crtcport+1, ((r1 & 0xcf) | 0x20));
  249.  
  250.                     _outp(crtcport, 0x5d);
  251.                     _outp(crtcport+1, ((r0 & 0x80) | 0x00));
  252.                     break;
  253.                }
  254.                break;
  255.          }
  256.          break;
  257.  
  258.       case 800:
  259.          _outpw(crtcport, 0x9806);
  260.          _outpw(crtcport, 0x7c10);
  261.          _outpw(crtcport, 0x9816);
  262.  
  263.          switch(pAdapter->ModeInfo.bBitsPerPixel)
  264.          {
  265.             case 8:
  266.             case 4:
  267.               _outpw(crtcport, 0x7d00);
  268.               _outpw(crtcport, 0x8003);
  269.               _outpw(crtcport, 0x6c04);
  270.               _outpw(crtcport, 0x1b05);
  271.  
  272.                _outp(crtcport, 0x34);
  273.                r0 = _inp(crtcport+1);
  274.                _outp(crtcport+1, (r0 & 0xef));
  275.  
  276.                _outp(crtcport, 0x5d);
  277.                r0 = _inp(crtcport+1);
  278.                _outp(crtcport+1, (r0 & 0x80));
  279.  
  280.                _outp(crtcport, 0x5c);
  281.                r0 = _inp(crtcport+1);
  282.  
  283.               switch(pAdapter->ModeInfo.bVrtRefresh)
  284.               {
  285.                  case 75:
  286.                    _outp(crtcport+1, ((r0 & 0xcf) | 20)); //set CR5C
  287.                    _outpw(crtcport, 0x8211);
  288.                    break;
  289.  
  290.                  case 72:
  291.                    _outp(crtcport+1, ((r0 & 0xcf) | 10)); //set CR5C
  292.                    _outpw(crtcport, 0x8211);
  293.                    break;
  294.  
  295.                  case 60:
  296.                  default:
  297.                    _outpw(crtcport, 0x7f00);
  298.                    _outpw(crtcport, 0x8203);
  299.                    _outpw(crtcport, 0x6a04);
  300.                    _outpw(crtcport, 0x1a05);
  301.                    _outpw(crtcport, 0x7206);
  302.                    _outpw(crtcport, 0x5810);
  303.                    _outpw(crtcport, 0x8c11);
  304.                    _outpw(crtcport, 0x7216);
  305.                    break;
  306.               }
  307.               break;
  308.  
  309.             case 16:
  310.               _outpw(crtcport, 0xff00);
  311.               _outpw(crtcport, 0x8203);
  312.               _outpw(crtcport, 0xd604);
  313.               _outpw(crtcport, 0x1405);
  314.               _outpw(crtcport, 0x003c);
  315.               _outpw(crtcport, 0x0642);
  316.  
  317.                _outp(crtcport, 0x43);
  318.                r0 = _inp(crtcport+1);
  319.                _outp(crtcport+1, (r0 & 0x7f));
  320.  
  321.                _outp(crtcport, 0x5d);
  322.                r0 = _inp(crtcport+1);
  323.  
  324.                _outp(crtcport, 0x5c);
  325.                r1 = _inp(crtcport+1);
  326.  
  327.                _outp(crtcport, 0x34);
  328.                r2 = _inp(crtcport+1);
  329.  
  330.               switch(pAdapter->ModeInfo.bVrtRefresh)
  331.               {
  332.                  case 75:
  333.                    _outp(crtcport+1, (r2 & 0x10)); //set CR34
  334.                    _outpw(crtcport, 0x8211);
  335.                    _outpw(crtcport, 0xeb3c);
  336.  
  337.                     _outp(crtcport, 0x5c);
  338.                     _outp(crtcport+1, ((r1 & 0xcf) | 0x10));
  339.  
  340.                     _outp(crtcport, 0x5d);
  341.                     _outp(crtcport+1, (r0 & 0x80));
  342.                    break;
  343.  
  344.                  case 72:
  345.                    _outp(crtcport+1, (r2 & 0x34)); //set CR34
  346.                    _outpw(crtcport, 0x8211);
  347.  
  348.                     _outp(crtcport, 0x5c);
  349.                     _outp(crtcport+1, (r1 & 0xcf));
  350.  
  351.                     _outp(crtcport, 0x5d);
  352.                     _outp(crtcport+1, (r0 & 0x80));
  353.                    break;
  354.  
  355.                  case 60:
  356.                  default:
  357.                    _outp(crtcport+1, (r2 & 0x34)); //set CR34
  358.                    _outpw(crtcport, 0x0300);
  359.                    _outpw(crtcport, 0x8603);
  360.                    _outpw(crtcport, 0xd204);
  361.                    _outpw(crtcport, 0x1205);
  362.                    _outpw(crtcport, 0x7206);
  363.                    _outpw(crtcport, 0x5810);
  364.                    _outpw(crtcport, 0x8c11);
  365.                    _outpw(crtcport, 0x7216);
  366.                    _outpw(crtcport, 0x0242);
  367.  
  368.                     _outp(crtcport, 0x5c);
  369.                     _outp(crtcport+1, ((r1 & 0xcf) | 0x30));
  370.  
  371.                     _outp(crtcport, 0x5d);
  372.                     _outp(crtcport+1, ((r0 & 0x80) | 0x01));
  373.                    break;
  374.               }
  375.               break;
  376.          }
  377.          break;
  378.  
  379.       case 1024:
  380.  
  381.          switch(pAdapter->ModeInfo.bBitsPerPixel)
  382.          {
  383.             case 8:
  384.             case 4:
  385.               _outpw(crtcport, 0xf507);
  386.               _outpw(crtcport, 0x6009);
  387.               _outpw(crtcport, 0xff12);
  388.               _outpw(crtcport, 0xff15);
  389.  
  390.               _outp(crtcport,0x34);
  391.               r0 = _inp(crtcport+1);
  392.               _outp(crtcport+1, (r0 & 0xef));
  393.  
  394.               _outp(crtcport,0x43);
  395.               r0 = _inp(crtcport+1);
  396.               _outp(crtcport+1, (r0 & 0x7f));
  397.  
  398.               _outp(crtcport,0x5d);
  399.               r0 = _inp(crtcport+1);
  400.               _outp(crtcport+1, (r0 & 0x80));
  401.  
  402.               _outp(crtcport,0x5c);
  403.               r0 = _inp(crtcport+1);
  404.  
  405.               switch(pAdapter->ModeInfo.bVrtRefresh)
  406.               {
  407.                  case 80:
  408.                    _outp(crtcport+1, ((r1 & 0xcf) | 0x20)); //set CR5C
  409.                    _outpw(crtcport, 0xa400);
  410.                    _outpw(crtcport, 0x8703);
  411.                    _outpw(crtcport, 0x8504);
  412.                    _outpw(crtcport, 0x9305);
  413.                    _outpw(crtcport, 0x2206);
  414.                    _outpw(crtcport, 0x0210);
  415.                    _outpw(crtcport, 0x8511);
  416.                    _outpw(crtcport, 0x2216);
  417.                    _outpw(crtcport, 0x0742);
  418.                    break;
  419.  
  420.                  case 75:
  421.                    _outp(crtcport+1, ((r1 & 0xcf) | 0x30)); //set CR5C
  422.                    _outpw(crtcport, 0xab00);
  423.                    _outpw(crtcport, 0x8e03);
  424.                    _outpw(crtcport, 0x8504);
  425.                    _outpw(crtcport, 0x8505);
  426.                    _outpw(crtcport, 0x2406);
  427.                    _outpw(crtcport, 0x0010);
  428.                    _outpw(crtcport, 0x8811);
  429.                    _outpw(crtcport, 0x2416);
  430.                    _outpw(crtcport, 0x0542);
  431.                    break;
  432.  
  433.                  case 72:
  434.                    _outp(crtcport+1, ((r1 & 0xcf) | 0x20)); //set CR5C
  435.                    _outpw(crtcport, 0xa500);
  436.                    _outpw(crtcport, 0x8803);
  437.                    _outpw(crtcport, 0x8204);
  438.                    _outpw(crtcport, 0x8205);
  439.                    _outpw(crtcport, 0x2506);
  440.                    _outpw(crtcport, 0x0010);
  441.                    _outpw(crtcport, 0x8811);
  442.                    _outpw(crtcport, 0x2516);
  443.                    _outpw(crtcport, 0x0542);
  444.                    break;
  445.  
  446.                  case 70:
  447.                    _outp(crtcport+1, ((r1 & 0xcf) | 0x10)); //set CR5C
  448.                    _outpw(crtcport, 0xa100);
  449.                    _outpw(crtcport, 0x8403);
  450.                    _outpw(crtcport, 0x8404);
  451.                    _outpw(crtcport, 0x9505);
  452.                    _outpw(crtcport, 0x2406);
  453.                    _outpw(crtcport, 0x0210);
  454.                    _outpw(crtcport, 0x8811);
  455.                    _outpw(crtcport, 0x2416);
  456.                    _outpw(crtcport, 0x0542);
  457.                    break;
  458.  
  459.                  case 60:
  460.                    _outp(crtcport+1, (r1 & 0xcf)); //set CR5C
  461.                    _outpw(crtcport, 0xa300);
  462.                    _outpw(crtcport, 0x8603);
  463.                    _outpw(crtcport, 0x8404);
  464.                    _outpw(crtcport, 0x9505);
  465.                    _outpw(crtcport, 0x2406);
  466.                    _outpw(crtcport, 0x0210);
  467.                    _outpw(crtcport, 0x8811);
  468.                    _outpw(crtcport, 0x2416);
  469.                    _outpw(crtcport, 0x0542);
  470.                    break;
  471.  
  472.                    case 44:                   //interlace
  473.                    default:
  474.                    _outp(crtcport+1, ((r1 & 0xcf) | 0x30)); //set CR5C
  475.                    _outpw(crtcport, 0x9900);
  476.                    _outpw(crtcport, 0x9c03);
  477.                    _outpw(crtcport, 0x8104);
  478.                    _outpw(crtcport, 0x1705);
  479.                    _outpw(crtcport, 0x9706);
  480.                    _outpw(crtcport, 0x1f07);
  481.                    _outpw(crtcport, 0x4009);
  482.                    _outpw(crtcport, 0x8010);
  483.                    _outpw(crtcport, 0x8411);
  484.                    _outpw(crtcport, 0x7f12);
  485.                    _outpw(crtcport, 0x8015);
  486.                    _outpw(crtcport, 0x9616);
  487.                    _outpw(crtcport, 0x403c);
  488.                    _outpw(crtcport, 0x2142);
  489.                    break;
  490.               }
  491.               break;
  492.  
  493.             case 16:            // execute from PMI file
  494.               rc = ERROR_REFRESH_NOT_SUPPORTED;
  495.               break;
  496.          }
  497.          break;
  498.  
  499.       case 1280:
  500.          switch(pAdapter->ModeInfo.bBitsPerPixel)
  501.          {
  502.             case 8:
  503.               switch(pAdapter->ModeInfo.bVrtRefresh)
  504.               {
  505.                  case 60:
  506.                    _outpw(crtcport, 0xd300);
  507.                    _outpw(crtcport, 0x9603);
  508.                    _outpw(crtcport, 0xa104);
  509.                    _outpw(crtcport, 0x1a05);
  510.                    _outpw(crtcport, 0x1e06);
  511.                    _outpw(crtcport, 0x5a07);
  512.                    _outpw(crtcport, 0x8511);
  513.                    _outpw(crtcport, 0xff15);
  514.                    _outpw(crtcport, 0x1e16);
  515.                    _outpw(crtcport, 0x0642);
  516.  
  517.                    _outp(crtcport, 0x43);
  518.                    r0 = _inp(crtcport+1);
  519.                    _outp(crtcport+1, (r0 & 0x7f));
  520.  
  521.                    _outp(crtcport, 0x5c);
  522.                    r0 = _inp(crtcport+1);
  523.                    _outp(crtcport+1, ((r0 & 0xcf) | 0x20));
  524.  
  525.                    _outp(crtcport, 0x5d);
  526.                    r0 = _inp(crtcport+1);
  527.                    _outp(crtcport+1, (r0 & 0x80));
  528.  
  529.                    _outpw(crtcport, 0x115e);
  530.                    break;
  531.  
  532.                  case 53:
  533.                  default:
  534.                    _outpw(crtcport, 0xd200);
  535.                    _outpw(crtcport, 0x9503);
  536.                    _outpw(crtcport, 0xa304);
  537.                    _outpw(crtcport, 0x0305);
  538.                    _outpw(crtcport, 0x2306);
  539.                    _outpw(crtcport, 0xb207);
  540.                    _outpw(crtcport, 0x8611);
  541.                    _outpw(crtcport, 0x0015);
  542.                    _outpw(crtcport, 0x2216);
  543.                    _outpw(crtcport, 0x4f42);
  544.  
  545.                    _outp(crtcport, 0x43);
  546.                    r0 = _inp(crtcport+1);
  547.                    _outp(crtcport+1, (r0 & 0x26));
  548.  
  549.                    _outp(crtcport, 0x5c);
  550.                    r0 = _inp(crtcport+1);
  551.                    _outp(crtcport+1, ((r0 & 0x40) | 0xcf));
  552.  
  553.                    _outp(crtcport, 0x5d);
  554.                    r0 = _inp(crtcport+1);
  555.                    _outp(crtcport+1, ((r0 & 0x00) | 0x80));
  556.  
  557.                    _outpw(crtcport, 0x005e);
  558.                    break;
  559.               }
  560.               break;
  561.          }
  562.          break;
  563.  
  564.     }
  565.   }               /* end MODE_FLAG_GRAPHICS test   */
  566.   return rc;
  567. }
  568.