xref: /freebsd/sys/dev/syscons/blank/blank_saver.c (revision 33b77e2decd50e53798014b70bf7ca3bdc4c0c7e)
1 /*-
2  * Copyright (c) 1995 S�ren Schmidt
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer
10  *    in this position and unchanged.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software withough specific prior written permission
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  *	$Id: blank_saver.c,v 1.10 1997/07/15 14:49:09 yokota Exp $
29  */
30 
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/exec.h>
34 #include <sys/sysent.h>
35 #include <sys/lkm.h>
36 
37 #include <i386/isa/isa.h>
38 
39 #include <saver.h>
40 
41 MOD_MISC(blank_saver);
42 
43 static void
44 blank_saver(int blank)
45 {
46 	u_char val;
47 	if (blank) {
48 		scrn_blanked = 1;
49 		switch (crtc_type) {
50 		case KD_VGA:
51 			outb(TSIDX, 0x01); val = inb(TSREG);
52 			outb(TSIDX, 0x01); outb(TSREG, val | 0x20);
53 			break;
54 		case KD_EGA:
55 			/* not yet done XXX */
56 			break;
57 		case KD_CGA:
58 			outb(crtc_addr + 4, 0x25);
59 			break;
60 		case KD_MONO:
61 		case KD_HERCULES:
62 			outb(crtc_addr + 4, 0x21);
63 			break;
64 		default:
65 			break;
66 		}
67 	}
68 	else {
69 		switch (crtc_type) {
70 		case KD_VGA:
71 			outb(TSIDX, 0x01); val = inb(TSREG);
72 			outb(TSIDX, 0x01); outb(TSREG, val & 0xDF);
73 			break;
74 		case KD_EGA:
75 			/* not yet done XXX */
76 			break;
77 		case KD_CGA:
78 			outb(crtc_addr + 4, 0x2d);
79 			break;
80 		case KD_MONO:
81 		case KD_HERCULES:
82 			outb(crtc_addr + 4, 0x29);
83 			break;
84 		default:
85 			break;
86 		}
87 		scrn_blanked = 0;
88 	}
89 }
90 
91 static int
92 blank_saver_load(struct lkm_table *lkmtp, int cmd)
93 {
94 	switch (crtc_type) {
95 	case KD_MONO:
96 	case KD_HERCULES:
97 	case KD_CGA:
98 	case KD_VGA:
99 		break;
100 	case KD_EGA:
101 		/* EGA is yet to be supported */
102 	default:
103 		return ENODEV;
104 	}
105 	return add_scrn_saver(blank_saver);
106 }
107 
108 static int
109 blank_saver_unload(struct lkm_table *lkmtp, int cmd)
110 {
111 	return remove_scrn_saver(blank_saver);
112 }
113 
114 int
115 blank_saver_mod(struct lkm_table *lkmtp, int cmd, int ver)
116 {
117 	MOD_DISPATCH(blank_saver, lkmtp, cmd, ver,
118 		blank_saver_load, blank_saver_unload, lkm_nullcmd);
119 }
120