From 839ad527396286b846e58e11836f9091ceccc6d9 Mon Sep 17 00:00:00 2001 From: jkh Date: Sun, 5 Feb 1995 13:49:25 +0000 Subject: PCVT userland utilities. Submitted by: hm --- usr.sbin/pcvt/set2061/CAUTION | 28 +++ usr.sbin/pcvt/set2061/ICD2061Aalt.c | 297 +++++++++++++++++++++++++++++++ usr.sbin/pcvt/set2061/Makefile | 13 ++ usr.sbin/pcvt/set2061/README | 22 +++ usr.sbin/pcvt/set2061/compiler.h | 341 ++++++++++++++++++++++++++++++++++++ usr.sbin/pcvt/set2061/main.c | 112 ++++++++++++ 6 files changed, 813 insertions(+) create mode 100644 usr.sbin/pcvt/set2061/CAUTION create mode 100644 usr.sbin/pcvt/set2061/ICD2061Aalt.c create mode 100644 usr.sbin/pcvt/set2061/Makefile create mode 100644 usr.sbin/pcvt/set2061/README create mode 100644 usr.sbin/pcvt/set2061/compiler.h create mode 100644 usr.sbin/pcvt/set2061/main.c (limited to 'usr.sbin/pcvt/set2061') diff --git a/usr.sbin/pcvt/set2061/CAUTION b/usr.sbin/pcvt/set2061/CAUTION new file mode 100644 index 0000000..e1eba06 --- /dev/null +++ b/usr.sbin/pcvt/set2061/CAUTION @@ -0,0 +1,28 @@ +CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION +CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION +CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION + + THE USE OF THIS PROGRAM MAY DESTROY YOUR MONITOR !!! + ==================================================== + + IF YOU DON'T KNOW WHAT YOU ARE DOING, STAY AWAY FROM IT !!! + =========================================================== + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION +CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION +CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION + diff --git a/usr.sbin/pcvt/set2061/ICD2061Aalt.c b/usr.sbin/pcvt/set2061/ICD2061Aalt.c new file mode 100644 index 0000000..248476a --- /dev/null +++ b/usr.sbin/pcvt/set2061/ICD2061Aalt.c @@ -0,0 +1,297 @@ +/* + * This code is derived from code available from the STB bulletin board + */ + +/* $XFree86: mit/server/ddx/x386/common_hw/ICD2061Aalt.c,v 2.6 1994/04/15 05:10:30 dawes Exp $ */ + +#ifndef KERNEL +#include "compiler.h" +#else +#define GCCUSESGAS +#define PCVT_STANDALONE 1 +#endif + +#define SEQREG 0x03C4 +#define MISCREG 0x03C2 +#define MISCREAD 0x03CC + +double fref = 14.31818 * 2.0; +char ascclk[] = "VIDEO CLOCK ?"; + +unsigned short clknum; +unsigned short vlbus_flag; +unsigned short card; +unsigned short crtcaddr; +unsigned short clockreg; + +static double range[15] = {50.0, 51.0, 53.2, 58.5, 60.7, 64.4, 66.8, 73.5, + 75.6, 80.9, 83.2, 91.5, 100.0, 120.0, 120.0}; + +#ifdef __STDC__ +static double genratio(unsigned int *p, unsigned int *q, double tgt); +static double f(unsigned int p, unsigned int q, double basefreq); +#if 0 +static void prtbinary(unsigned int size, unsigned int val); +#endif +static void wait_vb(); +static void wrt_clk_bit(unsigned int value); +static void init_clock(unsigned long setup, unsigned short crtcport); +#else +static double genratio(); +static double f(); +#if 0 +static void prtbinary(); +#endif +static void wait_vb(); +static void wrt_clk_bit(); +static void init_clock(); +#endif + +void AltICD2061SetClock(frequency, select) +register long frequency; /* in Hz */ +int select; +{ + unsigned int m, mval, ival; + int i; + long dwv; + double realval; + double freq, fvco; + double dev, devx; + double delta, deltax; + unsigned int p, q; + unsigned int bestp, bestq; + unsigned char tmp; + + crtcaddr=(inb(0x3CC) & 0x01) ? 0x3D4 : 0x3B4; + + + outb(crtcaddr, 0x11); /* Unlock CRTC registers */ + tmp = inb(crtcaddr + 1); + outb(crtcaddr + 1, tmp & ~0x80); + + outw(crtcaddr, 0x4838); /* Unlock S3 register set */ + outw(crtcaddr, 0xA039); + + clknum = select; + + freq = ((double)frequency)/1000000.0; + if (freq > range[14]) + freq =range[14]; + else if (freq <= 6.99) + freq = 7.0; + +/* + * Calculate values to load into ICD 2061A clock chip to set frequency + */ + delta = 999.0; + dev = 999.0; + ival = 99; + mval = 99; + + fvco = freq / 2; + for (m = 0; m < 8; m++) { + fvco *= 2.0; + for (i = 14; i >= 0; i--) + if (fvco >= range[i]) + break; + if (i < 0) + continue; + if (i == 14) + break; + devx = (fvco - (range[i] + range[i+1])/2)/fvco; + if (devx < 0) + devx = -devx; + deltax = genratio(&p, &q, fvco); + if (delta < deltax) + continue; + if (deltax < delta || devx < dev) { + bestp = p; + bestq = q; + delta = deltax; + dev = devx; + ival = i; + mval = m; + } + } + fvco = fref; + for (m=0; m 128) + mmax = 128; + while (m < mmax) { + test = f(m, k, fref) - tgt; + if (test < 0) test = -test; + if (mindiff > test) { + mindiff = test; + *p = m; + *q = k; + } + m++; + } + } + return (mindiff); + } + +#if 0 +static void prtbinary(size, val) + unsigned int size; + unsigned int val; + { + unsigned int mask; + int k; + + mask = 1; + + for (k=size; --k > 0 || mask <= val/2;) + mask <<= 1; + + while (mask) { + fputc((mask&val)? '1': '0' , stderr); + mask >>= 1; + } + } +#endif + +static void wait_vb() + { + while ((inb(crtcaddr+6) & 0x08) == 0) + ; + while (inb(crtcaddr+6) & 0x08) + ; + } + + +#ifdef __STDC__ +static void init_clock(unsigned long setup, unsigned short crtcport) +#else +static void init_clock(setup, crtcport) + unsigned long setup; + unsigned short crtcport; +#endif + { + unsigned char nclk[2], clk[2]; + unsigned short restore42; + unsigned short oldclk; + unsigned short bitval; + int i; + unsigned char c; + +#ifndef PCVT_STANDALONE + (void)xf86DisableInterrupts(); +#endif + + oldclk = inb(0x3CC); + + outb(crtcport, 0x42); + restore42 = inb(crtcport+1); + + outw(0x3C4, 0x0100); + + outb(0x3C4, 1); + c = inb(0x3C5); + outb(0x3C5, 0x20 | c); + + outb(crtcport, 0x42); + outb(crtcport+1, 0x03); + + outw(0x3C4, 0x0300); + + nclk[0] = oldclk & 0xF3; + nclk[1] = nclk[0] | 0x08; + clk[0] = nclk[0] | 0x04; + clk[1] = nclk[0] | 0x0C; + + outb(crtcport, 0x42); + i = inw(crtcport); + + outw(0x3C4, 0x0100); + + wrt_clk_bit(oldclk | 0x08); + wrt_clk_bit(oldclk | 0x0C); + for (i=0; i<5; i++) { + wrt_clk_bit(nclk[1]); + wrt_clk_bit(clk[1]); + } + wrt_clk_bit(nclk[1]); + wrt_clk_bit(nclk[0]); + wrt_clk_bit(clk[0]); + wrt_clk_bit(nclk[0]); + wrt_clk_bit(clk[0]); + for (i=0; i<24; i++) { + bitval = setup & 0x01; + setup >>= 1; + wrt_clk_bit(clk[1-bitval]); + wrt_clk_bit(nclk[1-bitval]); + wrt_clk_bit(nclk[bitval]); + wrt_clk_bit(clk[bitval]); + } + wrt_clk_bit(clk[1]); + wrt_clk_bit(nclk[1]); + wrt_clk_bit(clk[1]); + + outb(0x3C4, 1); + c = inb(0x3C5); + outb(0x3C5, 0xDF & c); + + outb(crtcport, 0x42); + outb(crtcport+1, restore42); + + outb(0x3C2, oldclk); + + outw(0x3C4, 0x0300); + +#ifndef PCVT_STANDALONE + xf86EnableInterrupts(); +#endif + + } + +static void wrt_clk_bit(value) + unsigned int value; + { + int j; + + outb(0x3C2, value); + for (j=2; --j; ) + inb(0x200); + } diff --git a/usr.sbin/pcvt/set2061/Makefile b/usr.sbin/pcvt/set2061/Makefile new file mode 100644 index 0000000..ac9d317 --- /dev/null +++ b/usr.sbin/pcvt/set2061/Makefile @@ -0,0 +1,13 @@ +PROG= set2061 +SRCS= main.c ICD2061Aalt.c +CFLAGS+= -DGCCUSESGAS -DPCVT_STANDALONE +NOMAN= + +all: $(PROG) + +install: ${DEMOS} + @echo "set2061 is not installed automatically ...." + +.include + +$(PROG): compiler.h diff --git a/usr.sbin/pcvt/set2061/README b/usr.sbin/pcvt/set2061/README new file mode 100644 index 0000000..76109f9 --- /dev/null +++ b/usr.sbin/pcvt/set2061/README @@ -0,0 +1,22 @@ +CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION CAUTION + + THE USE OF THIS PROGRAM MAY DESTROY YOUR MONITOR !!! + ==================================================== + + IF YOU DON'T KNOW WHAT YOU ARE DOING, STAY AWAY FROM IT !!! + =========================================================== + +Read the file "CAUTION" before proceeding !!! + +The files: + + ICD2061Aalt.c and + compiler.h + +come from the Xfree86 2.1 distribution and have been slightly modified to +fit in a non-XFree environment. + +I use it to program the clock generator ICD2061a on my S3 928 based ELSA +Winner VGA board to 40MHz for clock generator #2: set2061 -n2 -f40000000. + +This enables me to use 132 columns mode on this VGA board. diff --git a/usr.sbin/pcvt/set2061/compiler.h b/usr.sbin/pcvt/set2061/compiler.h new file mode 100644 index 0000000..3a0e99a --- /dev/null +++ b/usr.sbin/pcvt/set2061/compiler.h @@ -0,0 +1,341 @@ +/* $XFree86: mit/server/ddx/x386/common/compiler.h,v 2.3 1993/10/03 14:55:28 dawes Exp $ */ +/* + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Thomas Roell not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Thomas Roell makes no representations + * about the suitability of this software for any purpose. It is provided + * "as is" without express or implied warranty. + * + * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + * $Header: /proj/X11/mit/server/ddx/x386/RCS/compiler.h,v 1.2 1991/06/27 00:01:11 root Exp $ + */ + + +#ifndef _COMPILER_H +#define _COMPILER_H + +#ifndef __STDC__ +# ifdef signed +# undef signed +# endif +# ifdef volatile +# undef volatile +# endif +# ifdef const +# undef const +# endif +# define signed /**/ +# ifdef __GNUC__ +# define volatile __volatile__ +# define const __const__ +# else +# define const /**/ +# endif /* __GNUC__ */ +#endif /* !__STDC__ */ + +#ifdef NO_INLINE + +extern void outb(); +extern void outw(); +extern unsigned int inb(); +extern unsigned int inw(); +#if NeedFunctionPrototypes +extern unsigned char rdinx(unsigned short, unsigned char); +extern void wrinx(unsigned short, unsigned char, unsigned char); +extern void modinx(unsigned short, unsigned char, unsigned char, unsigned char); +extern int testrg(unsigned short, unsigned char); +extern int textinx2(unsigned short, unsigned char, unsigned char); +extern int textinx(unsigned short, unsigned char); +#else /* NeedFunctionProtoypes */ +extern unsigned char rdinx(); +extern void wrinx(); +extern void modinx(); +extern int testrg(); +extern int textinx2(); +extern int textinx(); +#endif /* NeedFunctionProtoypes */ + +#else /* NO_INLINE */ + +#ifdef __GNUC__ + +#ifndef FAKEIT +#ifdef GCCUSESGAS + +/* + * If gcc uses gas rather than the native assembler, the syntax of these + * inlines has to be different. DHD + */ + +static __inline__ void +outb(port, val) +short port; +char val; +{ + __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port)); +} + + +static __inline__ void +outw(port, val) +short port; +short val; +{ + __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port)); +} + +static __inline__ unsigned int +inb(port) +short port; +{ + unsigned char ret; + __asm__ __volatile__("inb %1,%0" : + "=a" (ret) : + "d" (port)); + return ret; +} + +static __inline__ unsigned int +inw(port) +short port; +{ + unsigned short ret; + __asm__ __volatile__("inw %1,%0" : + "=a" (ret) : + "d" (port)); + return ret; +} + +#else /* GCCUSESGAS */ + +static __inline__ void +outb(port, val) + short port; + char val; +{ + __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port)); +} + +static __inline__ void +outw(port, val) + short port; + short val; +{ + __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port)); +} + +static __inline__ unsigned int +inb(port) + short port; +{ + unsigned char ret; + __asm__ __volatile__("in%B0 (%1)" : + "=a" (ret) : + "d" (port)); + return ret; +} + +static __inline__ unsigned int +inw(port) + short port; +{ + unsigned short ret; + __asm__ __volatile__("in%W0 (%1)" : + "=a" (ret) : + "d" (port)); + return ret; +} + +#endif /* GCCUSESGAS */ + +#else /* FAKEIT */ + +static __inline__ void +outb(port, val) + short port; + char val; +{ +} + +static __inline__ void +outw(port, val) + short port; + short val; +{ +} + +static __inline__ unsigned int +inb(port) + short port; +{ + return 0; +} + +static __inline__ unsigned int +inw(port) + short port; +{ + return 0; +} + +#endif /* FAKEIT */ + +#else /* __GNUC__ */ +#if !defined(AMOEBA) && !defined(_MINIX) +# if defined(__STDC__) && (__STDC__ == 1) +# define asm __asm +# endif +# ifdef SVR4 +# include +# ifndef __USLC__ +# define __USLC__ +# endif +# endif +# include +#endif +#endif + +/* + *----------------------------------------------------------------------- + * Port manipulation convenience functions + *----------------------------------------------------------------------- + */ + +#ifndef __GNUC__ +#define __inline__ /**/ +#endif + +/* + * rdinx - read the indexed byte port 'port', index 'ind', and return its value + */ +static __inline__ unsigned char +#ifdef __STDC__ +rdinx(unsigned short port, unsigned char ind) +#else +rdinx(port, ind) +unsigned short port; +unsigned char ind; +#endif +{ + if (port == 0x3C0) /* reset attribute flip-flop */ + (void) inb(0x3DA); + outb(port, ind); + return(inb(port+1)); +} + +/* + * wrinx - write 'val' to port 'port', index 'ind' + */ +static __inline__ void +#ifdef __STDC__ +wrinx(unsigned short port, unsigned char ind, unsigned char val) +#else +wrinx(port, ind, val) +unsigned short port; +unsigned char ind, val; +#endif +{ + outb(port, ind); + outb(port+1, val); +} + +/* + * modinx - in register 'port', index 'ind', set the bits in 'mask' as in 'new'; + * the other bits are unchanged. + */ +static __inline__ void +#ifdef __STDC__ +modinx(unsigned short port, unsigned char ind, + unsigned char mask, unsigned char new) +#else +modinx(port, ind, mask, new) +unsigned short port; +unsigned char ind, mask, new; +#endif +{ + unsigned char tmp; + + tmp = (rdinx(port, ind) & ~mask) | (new & mask); + wrinx(port, ind, tmp); +} + +/* + * tstrg - returns true iff the bits in 'mask' of register 'port' are + * readable & writable. + */ + +static __inline__ int +#ifdef __STDC__ +testrg(unsigned short port, unsigned char mask) +#else +tstrg(port, mask) +unsigned short port; +unsigned char mask; +#endif +{ + unsigned char old, new1, new2; + + old = inb(port); + outb(port, old & ~mask); + new1 = inb(port) & mask; + outb(port, old | mask); + new2 = inb(port) & mask; + outb(port, old); + return((new1 == 0) && (new2 == mask)); +} + +/* + * testinx2 - returns true iff the bits in 'mask' of register 'port', index + * 'ind' are readable & writable. + */ +static __inline__ int +#ifdef __STDC__ +testinx2(unsigned short port, unsigned char ind, unsigned char mask) +#else +testinx2(port, ind, mask) +unsigned short port; +unsigned char ind, mask; +#endif +{ + unsigned char old, new1, new2; + + old = rdinx(port, ind); + wrinx(port, ind, old & ~mask); + new1 = rdinx(port, ind) & mask; + wrinx(port, ind, old | mask); + new2 = rdinx(port, ind) & mask; + wrinx(port, ind, old); + return((new1 == 0) && (new2 == mask)); +} + +/* + * testinx - returns true iff all bits of register 'port', index 'ind' are + * readable & writable. + */ +static __inline__ int +#ifdef __STDC__ +testinx(unsigned short port, unsigned char ind) +#else +testinx(port, ind, mask) +unsigned short port; +unsigned char ind; +#endif +{ + return(testinx2(port, ind, 0xFF)); +} + +#endif /* NO_INLINE */ +#endif /* _COMPILER_H */ diff --git a/usr.sbin/pcvt/set2061/main.c b/usr.sbin/pcvt/set2061/main.c new file mode 100644 index 0000000..03a482d --- /dev/null +++ b/usr.sbin/pcvt/set2061/main.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 1994 Hellmuth Michaelis + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by + * Hellmuth Michaelis + * 4. The name authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +static char *id = + "@(#)set2061.c, 1.00, Last Edit-Date: [Sun Jan 15 19:52:05 1995]"; + +/*---------------------------------------------------------------------------* + * + * history: + * + * -hm start using 132 columns on my Elsa Winner + * + *---------------------------------------------------------------------------*/ + +#include +#include +#include + +#define DEFAULTFD 0 + +void AltICD2061SetClock(long frequency, int select); + +main(argc,argv) +int argc; +char *argv[]; +{ + extern int optind; + extern int opterr; + extern char *optarg; + + int fd; + int c; + long freq = -1; + int no = -1; + + while( (c = getopt(argc, argv, "f:n:")) != EOF) + { + switch(c) + { + case 'f': + freq = atoi(optarg); + break; + + case 'n': + no = atoi(optarg); + break; + + case '?': + default: + usage(); + break; + } + } + + if(freq == -1 || no == -1) + usage(); + + if((fd = open("/dev/console", O_RDONLY)) < 0) + fd = DEFAULTFD; + + if(ioctl(fd, KDENABIO, 0) < 0) + { + perror("ioctl(KDENABIO)"); + return 1; + } + + AltICD2061SetClock(freq, no); + + (void)ioctl(fd, KDDISABIO, 0); + + exit(0); +} + +usage() +{ + fprintf(stderr,"\nset2061 - program the ICD2061 video clock chip\n"); + fprintf(stderr,"usage: set2061 -f -n \n"); + fprintf(stderr," -f frequency in Hz\n"); + fprintf(stderr," -n clock generator number\n"); + exit(1); +} + -- cgit v1.1