home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / console / svgatext.3 / svgatext / SVGATextMode-1.3 / XFREE / common_hw / I2061Aset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-29  |  3.8 KB  |  143 lines

  1. /* $XConsortium: I2061Aset.c,v 1.1 95/01/26 15:25:49 kaleb Exp $ */
  2. /* Based on the number 9 Inc code */
  3. /* Copyright (c) 1992, Number Nine Computer Corp.  All Rights Reserved. 
  4.  *
  5.  * Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation, and that the name of Number Nine Computer Corp not be used 
  10.  * in advertising or publicity pertaining to distribution of the software 
  11.  * without specific, written prior permission.  Number Nine Computer Corp 
  12.  * makes no representations about the suitability of this software for any 
  13.  * purpose.  It is provided "as is" without express or implied warranty.
  14.  *
  15.  * NUMBER NINE COMPUTER CORP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
  16.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, 
  17.  * IN NO EVENT SHALL NUMBER NINE COMPUTER CORP BE LIABLE FOR ANY SPECIAL, 
  18.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 
  19.  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 
  20.  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 
  21.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  */
  24. /* Header: /home/src/xfree86/mit/server/ddx/xf86/common_hw/RCS/ICD2061Aset.c,v 1.1 1993/03/22 00:25:21 jon Exp jon
  25.  */
  26.  
  27. #include "compiler.h"
  28. #include "ICD2061A.h"
  29.  
  30.  
  31. int clock_m;
  32. int clock_n;
  33. int clock_p;
  34.  
  35. void
  36. ICD2061ASetClock(clock_value)
  37. register long clock_value;              /* 7bits M, 7bits N, 2bits P */
  38. {
  39.   register long         index;
  40.   register char         iotemp;
  41.   int select;
  42.   unsigned short crtcaddr;
  43.  
  44.   select = (clock_value >> 22) & 3;
  45.  
  46.   crtcaddr = (inb(0x3CC) & 0x01) ? 0x3D4 : 0x3B4;
  47.  
  48.   /* Unlock the S3 registers */
  49.   outb(crtcaddr, LOCK_INDEX);
  50.   outb(crtcaddr+1, UNLOCK_PATTERN);
  51.  
  52.   /* Shut off screen */
  53.   outb(0x3C4, 0x01);
  54.   iotemp = inb(0x3C5);
  55.   outb(0x3C5, iotemp | 0x20);
  56.  
  57.   /* set clock inbut to 11 binary */
  58.   iotemp = inb(0x3CC);
  59.   outb(0x3C2, iotemp | 0x0C);
  60.  
  61.   outb(crtcaddr, SSW_WRITE_INDEX);
  62.   outb(crtcaddr+1, 0);
  63.  
  64.   outb(crtcaddr, MODE_CTRL_INDEX);
  65.   iotemp = inb(crtcaddr+1) & 0xF0;
  66.  
  67.   /* Set up the softswitch write value */
  68. #define CLOCK(x) outb(crtcaddr+1, iotemp | (x))
  69. #define C_DATA  2
  70. #define C_CLK   1
  71. #define C_BOTH  3
  72. #define C_NONE  0
  73.  
  74.   /* Program the IC Designs ICD2061A frequency generator */
  75.   CLOCK(C_NONE);
  76.  
  77.   /* Unlock sequence */
  78.   CLOCK(C_DATA);
  79.   for (index = 0; index < 6; index++)
  80.     {
  81.       CLOCK(C_BOTH);
  82.       CLOCK(C_DATA);
  83.     }
  84.   CLOCK(C_NONE);
  85.   CLOCK(C_CLK);
  86.   CLOCK(C_NONE);
  87.   CLOCK(C_CLK);
  88.   
  89.   /* Program the 24 bit value into REG0 */
  90.   for (index = 0; index < 24; index++)
  91.     {
  92.       /* Clock in the next bit */
  93.       clock_value >>= 1;
  94.       if (clock_value & 1)
  95.         {
  96.           CLOCK(C_CLK);
  97.           CLOCK(C_NONE);
  98.           CLOCK(C_DATA);
  99.           CLOCK(C_BOTH);
  100.         }
  101.       else
  102.         {
  103.           CLOCK(C_BOTH);
  104.           CLOCK(C_DATA);
  105.           CLOCK(C_NONE);
  106.           CLOCK(C_CLK);
  107.         }
  108.     }
  109.  
  110.   CLOCK(C_BOTH);
  111.   CLOCK(C_DATA);
  112.   CLOCK(C_BOTH);
  113.  
  114.   /* If necessary, reprogram other ICD2061A registers to defaults */
  115.  
  116.   /* Select the CLOCK in the frequency synthesizer */
  117.   CLOCK(C_NONE | select);
  118.  
  119.   /* Turn screen back on */
  120.   outb(0x3C4, 0x01);
  121.   iotemp = inb(0x3C5);
  122.   outb(0x3C5, iotemp & 0xDF);
  123.  
  124. }
  125.  
  126.  
  127. long
  128. ICD2061AGetClock(clock_value)
  129. register long clock_value;              /* 7bits M, 7bits N, 2bits P */
  130. {
  131.   long                  temp;
  132.  
  133.   /* Unpack the clock value */
  134.   clock_m = ((clock_value >>  1) & 0x7F) + 2;
  135.   clock_n = ((clock_value >> 11) & 0x7F) + 3;
  136.   clock_p = ((clock_value >>  8) & 0x03);
  137.  
  138.   temp = (((CRYSTAL_FREQUENCY / 2) * clock_n) / clock_m) << 1;
  139.   temp >>= clock_p;
  140.  
  141.   return temp;
  142. }
  143.