File: probeclocks.c

package info (click to toggle)
svgatextmode 1.9-21
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,120 kB
  • ctags: 3,455
  • sloc: ansic: 15,544; makefile: 354; sh: 345; yacc: 341; lex: 226; sed: 15; asm: 12
file content (206 lines) | stat: -rw-r--r-- 6,114 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*  SVGATextMode -- An SVGA textmode manipulation/enhancement tool
 *
 *  Copyright (C) 1995-1998  Koen Gadeyne
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* THIS PROGRAM IS UNDER CONSTRUCTION --- NOT FUNCTIONAL YET */

/***
 *** probe_clocks: A standalone replacement for the XFREE86 "X -probeonly" command.
 ***               Probes all available pixel clocks using the mechanism specified
 ***               In the /etc/ClockConfig or the /etc/TextConfig file.
 ***               This doesn't need XFree86 to be installed.
 ***
 ***               Since the whole STM package has no chipset detection code in it,
 ***               you have to define the chipset AND the clocks in the config file.
 ***               The clock VALUES may be wrong, but the probe will only probe for
 ***               those that are mentionned in the config file.
 ***
 ***               This is not very nice. We need to use the XFree86 "save" functions
 ***               to save register contents before we go on, and then restore them
 ***               afterwards.
 ***/

#include "misc.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#include "vga_prg.h"
#include "setclock.h"
#include "validate.h"
#include "messages.h"

char *CommandName;
char ConfigFile[1024]=CLOCK_CONF_FILE;
bool debug_messages=FALSE;

void usage()
{
     PMESSAGE(("version %s. (c) 1995,1996,1997 Koen Gadeyne.\n Usage: %s [options]\n\n\
     Options: -n  Don't program VGA hardware (rather useless)\n\
              -d  print debugging information\n\
              -h  print usage information\n\
              -f  fast mode: probe only one clock `precisely', and the rest faster
                  and less accurate (XFree86 method for all but the first probe)
              -t <ConfigFile>  Use alternative config file instead of the default\n\
                 (= %s if that exists, or %s otherwise)\n\n",
     VERSION, CommandName, CLOCK_CONF_FILE, CONFIGFILE));
}

void Xfree_probe_clocks()
/* this is largely the code from the XFree86 file XFree86-3.1.1-1/xc/programs/Xserver/hw/xfree86/common_hw/xf86_ClkPr.c */
{
}

/****************************************************************************************************************************/

int main (int argc, char* argv[])
{
  bool program_hardware=TRUE;
  bool fast_mode=FALSE;
  int chipset=CS_NONE;
  const char *str_chipsets[NUM_CHIPSETS] = CHIPSET_STRINGS;
  FILE *param_file;
  int optionmask;
  int n;
  t_clockdef ck;
  char c;
  modestruct m, probe_m;
  char tempstr[1024]="";
    
 /*
  * check if default config file exists. If not, use TextConfig.
  */
  
  if ((param_file=fopen(ConfigFile,"r"))==NULL) strcpy(ConfigFile, CONFIGFILE);
  else fclose(param_file);

 /*
  * command-line argument parsing
  */

  CommandName = argv[0];

  while ((c = getopt (argc, argv, "ndfht:")) != EOF)
    switch (c)
    {
      case 'n': program_hardware=FALSE;
                break;
      case 'd': debug_messages=TRUE;
                break;
      case 'f': fast_mode=TRUE;
                break;
      case 'h': usage();
                exit(0);
                break;
      case 't': strcpy(ConfigFile, optarg);
                break;
      case '?': usage();
                PERROR(("Bad option '-%c'\n",(char)optopt));
                exit(-1);
                break;
      default: PERROR(("getopt returned unknown token '%c'.\n",c));
    }
   
  PVERSION;

  if (argc>optind+1)
  {
    usage();
    PERROR(("Too many parameters on command line.\n"));
  }

 /*
  * open parameter file
  */
  param_file = open_param_file(ConfigFile);


 /*
  * get chipset definition
  */
  sscanf(findlabel(param_file, "ChipSet", LABEL_REQUIRED+LABEL_FROMSTART), "%*s %s", tempstr);
  chipset = findoption(tempstr, str_chipsets, NUM_CHIPSETS, "chip set");


 /*
  * Option parsing. Not all chips support all options
  */

  optionmask = parse_opt(param_file, chipset, str_chipsets[chipset]);

 /*
  * parse clock configuration in config file, fill structure with info
  */

  parse_clock(param_file, chipset, &ck);
  if (ck.type & CK_CLOCKCHIP)
  {
    PWARNING(("\n\tThe config file defines a ClockChip on this system.\n"\
              "\tA ClockChip is supposed to be able to create ANY clock.\n"\
              "\tClock probing is a bit useless then.\n"));
  }
  
 /*
  * Close the config file. We don't need it anymore.
  */

  fclose(param_file);
  
 /*
  * finally do it... maybe
  */
  
  if (program_hardware)
  {
    get_VGA_io_perm(chipset);

    /* sync disks if requested. Is there any way to do this and be SURE _all_ data has been flushed? */
    if (optionmask & OPT_SYNC)
    {
      PDEBUG(("Syncing disks...\n"));
      sync(); sleep(2); /* same as in "reboot" command. Hopefully enough */
    }

    unlock(chipset);

    getmode(&m, TRUE); /* get the current pixel clock so we can restore it */
    
    PDEBUG(("pixel clock before tests = %1.2f\n", m.pclock));
    for (n=0; n<ck.num_clocks; n++)
    {
      if (ck.clocks[n]==CKVAL_PROGRAMMABLE)
        PMESSAGE(("pixel clock %d is programmable\n", n));
      else
      {
        do_clock(chipset, &ck, ck.clocks[n], n, optionmask);
        getmode(&probe_m, TRUE);
        PMESSAGE(("pixel clock %d = %1.2f\n", n, probe_m.pclock));
      }
    }

   PDEBUG(("restoring old pixel clock\n"));
   do_clock(chipset, &ck, m.pclock, 0, optionmask);  /* restore old clock */
      
  }
  return(0);
}