display.c revision 1.14 1 /* $NetBSD: display.c,v 1.14 2006/08/13 23:52:11 uwe Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Juergen Hannken-Illjes.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/ioctl.h>
40 #include <sys/time.h>
41
42 #include <dev/wscons/wsconsio.h>
43
44 #include <err.h>
45 #include <errno.h>
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
49
50 #include "wsconsctl.h"
51
52 static int border;
53 static int dpytype;
54 static struct wsdisplay_usefontdata font;
55 static struct wsdisplay_param backlight;
56 static struct wsdisplay_param brightness;
57 static struct wsdisplay_param contrast;
58 static struct wsdisplay_scroll_data scroll_l;
59 static int msg_default_attrs, msg_default_bg, msg_default_fg;
60 static int msg_kernel_attrs, msg_kernel_bg, msg_kernel_fg;
61 static int splash_enable, splash_progress;
62
63 struct field display_field_tab[] = {
64 { "border", &border, FMT_COLOR, 0 },
65 { "type", &dpytype, FMT_DPYTYPE, FLG_RDONLY },
66 { "font", &font.name, FMT_STRING, FLG_WRONLY },
67 { "backlight", &backlight.curval, FMT_UINT, 0 },
68 { "brightness", &brightness.curval, FMT_UINT, FLG_MODIFY },
69 { "contrast", &contrast.curval, FMT_UINT, FLG_MODIFY },
70 { "scroll.fastlines", &scroll_l.fastlines, FMT_UINT, FLG_MODIFY },
71 { "scroll.slowlines", &scroll_l.slowlines, FMT_UINT, FLG_MODIFY },
72 { "msg.default.attrs", &msg_default_attrs, FMT_ATTRS, 0 },
73 { "msg.default.bg", &msg_default_bg, FMT_COLOR, 0 },
74 { "msg.default.fg", &msg_default_fg, FMT_COLOR, 0 },
75 { "msg.kernel.attrs", &msg_kernel_attrs, FMT_ATTRS, 0 },
76 { "msg.kernel.bg", &msg_kernel_bg, FMT_COLOR, 0 },
77 { "msg.kernel.fg", &msg_kernel_fg, FMT_COLOR, 0 },
78 { "splash.enable", &splash_enable, FMT_UINT, FLG_WRONLY },
79 { "splash.progress", &splash_progress, FMT_UINT, FLG_WRONLY },
80 };
81
82 int display_field_tab_len = sizeof(display_field_tab) /
83 sizeof(display_field_tab[0]);
84
85 void
86 display_get_values(int fd)
87 {
88
89 if (field_by_value(&dpytype)->flags & FLG_GET)
90 if (ioctl(fd, WSDISPLAYIO_GTYPE, &dpytype) < 0)
91 err(EXIT_FAILURE, "WSDISPLAYIO_GTYPE");
92
93 if (field_by_value(&border)->flags & FLG_GET)
94 if (ioctl(fd, WSDISPLAYIO_GBORDER, &border) < 0)
95 field_disable_by_value(&border);
96
97 if (field_by_value(&backlight.curval)->flags & FLG_GET) {
98 backlight.param = WSDISPLAYIO_PARAM_BACKLIGHT;
99 if (ioctl(fd, WSDISPLAYIO_GETPARAM, &backlight) < 0)
100 field_disable_by_value(&backlight.curval);
101 }
102
103 if (field_by_value(&brightness.curval)->flags & FLG_GET) {
104 brightness.param = WSDISPLAYIO_PARAM_BRIGHTNESS;
105 if (ioctl(fd, WSDISPLAYIO_GETPARAM, &brightness))
106 field_disable_by_value(&brightness.curval);
107 }
108
109 if (field_by_value(&contrast.curval)->flags & FLG_GET) {
110 contrast.param = WSDISPLAYIO_PARAM_CONTRAST;
111 if (ioctl(fd, WSDISPLAYIO_GETPARAM, &contrast))
112 field_disable_by_value(&contrast.curval);
113 }
114
115 if (field_by_value(&msg_default_attrs)->flags & FLG_GET ||
116 field_by_value(&msg_default_bg)->flags & FLG_GET ||
117 field_by_value(&msg_default_fg)->flags & FLG_GET ||
118 field_by_value(&msg_kernel_attrs)->flags & FLG_GET ||
119 field_by_value(&msg_kernel_bg)->flags & FLG_GET ||
120 field_by_value(&msg_kernel_fg)->flags & FLG_GET) {
121 struct wsdisplay_msgattrs ma;
122
123 if (ioctl(fd, WSDISPLAYIO_GMSGATTRS, &ma) < 0) {
124 field_disable_by_value(&msg_default_attrs);
125 field_disable_by_value(&msg_default_bg);
126 field_disable_by_value(&msg_default_fg);
127 field_disable_by_value(&msg_kernel_attrs);
128 field_disable_by_value(&msg_kernel_bg);
129 field_disable_by_value(&msg_kernel_fg);
130 } else {
131 msg_default_attrs = ma.default_attrs;
132 if (ma.default_attrs & WSATTR_WSCOLORS) {
133 msg_default_bg = ma.default_bg;
134 msg_default_fg = ma.default_fg;
135 } else
136 msg_default_bg = msg_default_fg = -1;
137
138 msg_kernel_attrs = ma.kernel_attrs;
139 if (ma.kernel_attrs & WSATTR_WSCOLORS) {
140 msg_kernel_bg = ma.kernel_bg;
141 msg_kernel_fg = ma.kernel_fg;
142 } else
143 msg_kernel_bg = msg_kernel_fg = -1;
144 }
145 }
146
147 if (field_by_value(&scroll_l.fastlines)->flags & FLG_GET ||
148 field_by_value(&scroll_l.slowlines)->flags & FLG_GET) {
149 if (ioctl(fd, WSDISPLAYIO_DGSCROLL, &scroll_l) < 0) {
150 field_disable_by_value(&scroll_l.fastlines);
151 field_disable_by_value(&scroll_l.slowlines);
152 }
153 }
154 }
155
156 void
157 display_put_values(fd)
158 int fd;
159 {
160
161 if (field_by_value(&font.name)->flags & FLG_SET) {
162 if (ioctl(fd, WSDISPLAYIO_SFONT, &font) < 0)
163 err(EXIT_FAILURE, "WSDISPLAYIO_SFONT");
164 pr_field(field_by_value(&font.name), " -> ");
165 }
166
167 if (field_by_value(&border)->flags & FLG_SET) {
168 if (ioctl(fd, WSDISPLAYIO_SBORDER, &border) < 0)
169 err(EXIT_FAILURE, "WSDISPLAYIO_SBORDER");
170 pr_field(field_by_value(&border), " -> ");
171 }
172
173 if (field_by_value(&backlight.curval)->flags & FLG_SET) {
174 backlight.param = WSDISPLAYIO_PARAM_BACKLIGHT;
175 if (ioctl(fd, WSDISPLAYIO_SETPARAM, &backlight) < 0)
176 err(EXIT_FAILURE, "WSDISPLAYIO_PARAM_BACKLIGHT");
177 pr_field(field_by_value(&backlight.curval), " -> ");
178 }
179
180 if (field_by_value(&brightness.curval)->flags & FLG_SET) {
181 brightness.param = WSDISPLAYIO_PARAM_BRIGHTNESS;
182 if (ioctl(fd, WSDISPLAYIO_SETPARAM, &brightness) < 0)
183 err(EXIT_FAILURE, "WSDISPLAYIO_PARAM_BRIGHTNESS");
184 pr_field(field_by_value(&brightness.curval), " -> ");
185 }
186
187 if (field_by_value(&contrast.curval)->flags & FLG_SET) {
188 contrast.param = WSDISPLAYIO_PARAM_CONTRAST;
189 if (ioctl(fd, WSDISPLAYIO_SETPARAM, &contrast) < 0)
190 err(EXIT_FAILURE, "WSDISPLAYIO_PARAM_CONTRAST");
191 pr_field(field_by_value(&contrast.curval), " -> ");
192 }
193
194 if (field_by_value(&splash_enable)->flags & FLG_SET) {
195 if (ioctl(fd, WSDISPLAYIO_SSPLASH, &splash_enable) < 0)
196 err(EXIT_FAILURE, "WSDISPLAYIO_SSPLASH");
197 pr_field(field_by_value(&splash_enable), " -> ");
198 }
199
200 if (field_by_value(&splash_progress)->flags & FLG_SET) {
201 if (ioctl(fd, WSDISPLAYIO_SPROGRESS, &splash_progress) < 0)
202 err(EXIT_FAILURE, "WSDISPLAYIO_SPROGRESS");
203 pr_field(field_by_value(&splash_progress), " -> ");
204 }
205
206 if (field_by_value(&msg_default_attrs)->flags & FLG_SET ||
207 field_by_value(&msg_default_bg)->flags & FLG_SET ||
208 field_by_value(&msg_default_fg)->flags & FLG_SET ||
209 field_by_value(&msg_kernel_attrs)->flags & FLG_SET ||
210 field_by_value(&msg_kernel_bg)->flags & FLG_SET ||
211 field_by_value(&msg_kernel_fg)->flags & FLG_SET) {
212 struct wsdisplay_msgattrs ma;
213
214 if (ioctl(fd, WSDISPLAYIO_GMSGATTRS, &ma) < 0)
215 err(EXIT_FAILURE, "WSDISPLAYIO_GMSGATTRS");
216
217 if (field_by_value(&msg_default_attrs)->flags & FLG_SET) {
218 ma.default_attrs = msg_default_attrs;
219 pr_field(field_by_value(&msg_default_attrs), " -> ");
220 }
221 if (ma.default_attrs & WSATTR_WSCOLORS) {
222 if (field_by_value(&msg_default_bg)->flags & FLG_SET) {
223 ma.default_bg = msg_default_bg;
224 pr_field(field_by_value(&msg_default_bg),
225 " -> ");
226 }
227 if (field_by_value(&msg_default_fg)->flags & FLG_SET) {
228 ma.default_fg = msg_default_fg;
229 pr_field(field_by_value(&msg_default_fg),
230 " -> ");
231 }
232 }
233
234 if (field_by_value(&msg_kernel_attrs)->flags & FLG_SET) {
235 ma.kernel_attrs = msg_kernel_attrs;
236 pr_field(field_by_value(&msg_kernel_attrs), " -> ");
237 }
238 if (ma.default_attrs & WSATTR_WSCOLORS) {
239 if (field_by_value(&msg_kernel_bg)->flags & FLG_SET) {
240 ma.kernel_bg = msg_kernel_bg;
241 pr_field(field_by_value(&msg_kernel_bg),
242 " -> ");
243 }
244 if (field_by_value(&msg_kernel_fg)->flags & FLG_SET) {
245 ma.kernel_fg = msg_kernel_fg;
246 pr_field(field_by_value(&msg_kernel_fg),
247 " -> ");
248 }
249 }
250
251 if (ioctl(fd, WSDISPLAYIO_SMSGATTRS, &ma) < 0)
252 err(EXIT_FAILURE, "WSDISPLAYIO_SMSGATTRS");
253 }
254
255 scroll_l.which = 0;
256 if (field_by_value(&scroll_l.fastlines)->flags & FLG_SET)
257 scroll_l.which |= WSDISPLAY_SCROLL_DOFASTLINES;
258 if (field_by_value(&scroll_l.slowlines)->flags & FLG_SET)
259 scroll_l.which |= WSDISPLAY_SCROLL_DOSLOWLINES;
260 if (scroll_l.which != 0 &&
261 ioctl(fd, WSDISPLAYIO_DSSCROLL, &scroll_l) < 0)
262 err(EXIT_FAILURE, "WSDISPLAYIO_DSSCROLL");
263 if (scroll_l.which & WSDISPLAY_SCROLL_DOFASTLINES)
264 pr_field(field_by_value(&scroll_l.fastlines), " -> ");
265 if (scroll_l.which & WSDISPLAY_SCROLL_DOSLOWLINES)
266 pr_field(field_by_value(&scroll_l.slowlines), " -> ");
267 }
268