1 /* $NetBSD: display.c,v 1.14 2006/08/13 23:52:11 uwe Exp $ */
4 * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Juergen Hannken-Illjes.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/ioctl.h>
35 #include <dev/wscons/wsconsio.h>
43 #include "wsconsctl.h"
47 static struct wsdisplay_usefontdata font
;
48 static struct wsdisplay_param backlight
;
49 static struct wsdisplay_param brightness
;
50 static struct wsdisplay_param contrast
;
51 static struct wsdisplay_scroll_data scroll_l
;
52 static int msg_default_attrs
, msg_default_bg
, msg_default_fg
;
53 static int msg_kernel_attrs
, msg_kernel_bg
, msg_kernel_fg
;
54 static int splash_enable
, splash_progress
;
56 struct field display_field_tab
[] = {
57 { "border", &border
, FMT_COLOR
, 0 },
58 { "type", &dpytype
, FMT_DPYTYPE
, FLG_RDONLY
},
59 { "font", &font
.name
, FMT_STRING
, FLG_WRONLY
},
60 { "backlight", &backlight
.curval
, FMT_UINT
, 0 },
61 { "brightness", &brightness
.curval
, FMT_UINT
, FLG_MODIFY
},
62 { "contrast", &contrast
.curval
, FMT_UINT
, FLG_MODIFY
},
63 { "scroll.fastlines", &scroll_l
.fastlines
, FMT_UINT
, FLG_MODIFY
},
64 { "scroll.slowlines", &scroll_l
.slowlines
, FMT_UINT
, FLG_MODIFY
},
65 { "msg.default.attrs", &msg_default_attrs
, FMT_ATTRS
, 0 },
66 { "msg.default.bg", &msg_default_bg
, FMT_COLOR
, 0 },
67 { "msg.default.fg", &msg_default_fg
, FMT_COLOR
, 0 },
68 { "msg.kernel.attrs", &msg_kernel_attrs
, FMT_ATTRS
, 0 },
69 { "msg.kernel.bg", &msg_kernel_bg
, FMT_COLOR
, 0 },
70 { "msg.kernel.fg", &msg_kernel_fg
, FMT_COLOR
, 0 },
71 { "splash.enable", &splash_enable
, FMT_UINT
, FLG_WRONLY
},
72 { "splash.progress", &splash_progress
, FMT_UINT
, FLG_WRONLY
},
75 int display_field_tab_len
= sizeof(display_field_tab
) /
76 sizeof(display_field_tab
[0]);
79 display_get_values(int fd
)
82 if (field_by_value(&dpytype
)->flags
& FLG_GET
)
83 if (ioctl(fd
, WSDISPLAYIO_GTYPE
, &dpytype
) < 0)
84 err(EXIT_FAILURE
, "WSDISPLAYIO_GTYPE");
86 if (field_by_value(&border
)->flags
& FLG_GET
)
87 if (ioctl(fd
, WSDISPLAYIO_GBORDER
, &border
) < 0)
88 field_disable_by_value(&border
);
90 if (field_by_value(&backlight
.curval
)->flags
& FLG_GET
) {
91 backlight
.param
= WSDISPLAYIO_PARAM_BACKLIGHT
;
92 if (ioctl(fd
, WSDISPLAYIO_GETPARAM
, &backlight
) < 0)
93 field_disable_by_value(&backlight
.curval
);
96 if (field_by_value(&brightness
.curval
)->flags
& FLG_GET
) {
97 brightness
.param
= WSDISPLAYIO_PARAM_BRIGHTNESS
;
98 if (ioctl(fd
, WSDISPLAYIO_GETPARAM
, &brightness
))
99 field_disable_by_value(&brightness
.curval
);
102 if (field_by_value(&contrast
.curval
)->flags
& FLG_GET
) {
103 contrast
.param
= WSDISPLAYIO_PARAM_CONTRAST
;
104 if (ioctl(fd
, WSDISPLAYIO_GETPARAM
, &contrast
))
105 field_disable_by_value(&contrast
.curval
);
108 if (field_by_value(&msg_default_attrs
)->flags
& FLG_GET
||
109 field_by_value(&msg_default_bg
)->flags
& FLG_GET
||
110 field_by_value(&msg_default_fg
)->flags
& FLG_GET
||
111 field_by_value(&msg_kernel_attrs
)->flags
& FLG_GET
||
112 field_by_value(&msg_kernel_bg
)->flags
& FLG_GET
||
113 field_by_value(&msg_kernel_fg
)->flags
& FLG_GET
) {
114 struct wsdisplay_msgattrs ma
;
116 if (ioctl(fd
, WSDISPLAYIO_GMSGATTRS
, &ma
) < 0) {
117 field_disable_by_value(&msg_default_attrs
);
118 field_disable_by_value(&msg_default_bg
);
119 field_disable_by_value(&msg_default_fg
);
120 field_disable_by_value(&msg_kernel_attrs
);
121 field_disable_by_value(&msg_kernel_bg
);
122 field_disable_by_value(&msg_kernel_fg
);
124 msg_default_attrs
= ma
.default_attrs
;
125 if (ma
.default_attrs
& WSATTR_WSCOLORS
) {
126 msg_default_bg
= ma
.default_bg
;
127 msg_default_fg
= ma
.default_fg
;
129 msg_default_bg
= msg_default_fg
= -1;
131 msg_kernel_attrs
= ma
.kernel_attrs
;
132 if (ma
.kernel_attrs
& WSATTR_WSCOLORS
) {
133 msg_kernel_bg
= ma
.kernel_bg
;
134 msg_kernel_fg
= ma
.kernel_fg
;
136 msg_kernel_bg
= msg_kernel_fg
= -1;
140 if (field_by_value(&scroll_l
.fastlines
)->flags
& FLG_GET
||
141 field_by_value(&scroll_l
.slowlines
)->flags
& FLG_GET
) {
142 if (ioctl(fd
, WSDISPLAYIO_DGSCROLL
, &scroll_l
) < 0) {
143 field_disable_by_value(&scroll_l
.fastlines
);
144 field_disable_by_value(&scroll_l
.slowlines
);
150 display_put_values(fd
)
154 if (field_by_value(&font
.name
)->flags
& FLG_SET
) {
155 if (ioctl(fd
, WSDISPLAYIO_SFONT
, &font
) < 0)
156 err(EXIT_FAILURE
, "WSDISPLAYIO_SFONT");
157 pr_field(field_by_value(&font
.name
), " -> ");
160 if (field_by_value(&border
)->flags
& FLG_SET
) {
161 if (ioctl(fd
, WSDISPLAYIO_SBORDER
, &border
) < 0)
162 err(EXIT_FAILURE
, "WSDISPLAYIO_SBORDER");
163 pr_field(field_by_value(&border
), " -> ");
166 if (field_by_value(&backlight
.curval
)->flags
& FLG_SET
) {
167 backlight
.param
= WSDISPLAYIO_PARAM_BACKLIGHT
;
168 if (ioctl(fd
, WSDISPLAYIO_SETPARAM
, &backlight
) < 0)
169 err(EXIT_FAILURE
, "WSDISPLAYIO_PARAM_BACKLIGHT");
170 pr_field(field_by_value(&backlight
.curval
), " -> ");
173 if (field_by_value(&brightness
.curval
)->flags
& FLG_SET
) {
174 brightness
.param
= WSDISPLAYIO_PARAM_BRIGHTNESS
;
175 if (ioctl(fd
, WSDISPLAYIO_SETPARAM
, &brightness
) < 0)
176 err(EXIT_FAILURE
, "WSDISPLAYIO_PARAM_BRIGHTNESS");
177 pr_field(field_by_value(&brightness
.curval
), " -> ");
180 if (field_by_value(&contrast
.curval
)->flags
& FLG_SET
) {
181 contrast
.param
= WSDISPLAYIO_PARAM_CONTRAST
;
182 if (ioctl(fd
, WSDISPLAYIO_SETPARAM
, &contrast
) < 0)
183 err(EXIT_FAILURE
, "WSDISPLAYIO_PARAM_CONTRAST");
184 pr_field(field_by_value(&contrast
.curval
), " -> ");
187 if (field_by_value(&splash_enable
)->flags
& FLG_SET
) {
188 if (ioctl(fd
, WSDISPLAYIO_SSPLASH
, &splash_enable
) < 0)
189 err(EXIT_FAILURE
, "WSDISPLAYIO_SSPLASH");
190 pr_field(field_by_value(&splash_enable
), " -> ");
193 if (field_by_value(&splash_progress
)->flags
& FLG_SET
) {
194 if (ioctl(fd
, WSDISPLAYIO_SPROGRESS
, &splash_progress
) < 0)
195 err(EXIT_FAILURE
, "WSDISPLAYIO_SPROGRESS");
196 pr_field(field_by_value(&splash_progress
), " -> ");
199 if (field_by_value(&msg_default_attrs
)->flags
& FLG_SET
||
200 field_by_value(&msg_default_bg
)->flags
& FLG_SET
||
201 field_by_value(&msg_default_fg
)->flags
& FLG_SET
||
202 field_by_value(&msg_kernel_attrs
)->flags
& FLG_SET
||
203 field_by_value(&msg_kernel_bg
)->flags
& FLG_SET
||
204 field_by_value(&msg_kernel_fg
)->flags
& FLG_SET
) {
205 struct wsdisplay_msgattrs ma
;
207 if (ioctl(fd
, WSDISPLAYIO_GMSGATTRS
, &ma
) < 0)
208 err(EXIT_FAILURE
, "WSDISPLAYIO_GMSGATTRS");
210 if (field_by_value(&msg_default_attrs
)->flags
& FLG_SET
) {
211 ma
.default_attrs
= msg_default_attrs
;
212 pr_field(field_by_value(&msg_default_attrs
), " -> ");
214 if (ma
.default_attrs
& WSATTR_WSCOLORS
) {
215 if (field_by_value(&msg_default_bg
)->flags
& FLG_SET
) {
216 ma
.default_bg
= msg_default_bg
;
217 pr_field(field_by_value(&msg_default_bg
),
220 if (field_by_value(&msg_default_fg
)->flags
& FLG_SET
) {
221 ma
.default_fg
= msg_default_fg
;
222 pr_field(field_by_value(&msg_default_fg
),
227 if (field_by_value(&msg_kernel_attrs
)->flags
& FLG_SET
) {
228 ma
.kernel_attrs
= msg_kernel_attrs
;
229 pr_field(field_by_value(&msg_kernel_attrs
), " -> ");
231 if (ma
.default_attrs
& WSATTR_WSCOLORS
) {
232 if (field_by_value(&msg_kernel_bg
)->flags
& FLG_SET
) {
233 ma
.kernel_bg
= msg_kernel_bg
;
234 pr_field(field_by_value(&msg_kernel_bg
),
237 if (field_by_value(&msg_kernel_fg
)->flags
& FLG_SET
) {
238 ma
.kernel_fg
= msg_kernel_fg
;
239 pr_field(field_by_value(&msg_kernel_fg
),
244 if (ioctl(fd
, WSDISPLAYIO_SMSGATTRS
, &ma
) < 0)
245 err(EXIT_FAILURE
, "WSDISPLAYIO_SMSGATTRS");
249 if (field_by_value(&scroll_l
.fastlines
)->flags
& FLG_SET
)
250 scroll_l
.which
|= WSDISPLAY_SCROLL_DOFASTLINES
;
251 if (field_by_value(&scroll_l
.slowlines
)->flags
& FLG_SET
)
252 scroll_l
.which
|= WSDISPLAY_SCROLL_DOSLOWLINES
;
253 if (scroll_l
.which
!= 0 &&
254 ioctl(fd
, WSDISPLAYIO_DSSCROLL
, &scroll_l
) < 0)
255 err(EXIT_FAILURE
, "WSDISPLAYIO_DSSCROLL");
256 if (scroll_l
.which
& WSDISPLAY_SCROLL_DOFASTLINES
)
257 pr_field(field_by_value(&scroll_l
.fastlines
), " -> ");
258 if (scroll_l
.which
& WSDISPLAY_SCROLL_DOSLOWLINES
)
259 pr_field(field_by_value(&scroll_l
.slowlines
), " -> ");