tadpolectl.c revision 1.6 1 1.6 itojun /* $NetBSD: tadpolectl.c,v 1.6 2003/07/13 12:09:56 itojun Exp $ */
2 1.1 garbled
3 1.1 garbled /*-
4 1.1 garbled * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.1 garbled * All rights reserved.
6 1.1 garbled *
7 1.1 garbled * This code is derived from software contributed to The NetBSD Foundation
8 1.1 garbled * by Tim Rightnour.
9 1.1 garbled *
10 1.1 garbled * Redistribution and use in source and binary forms, with or without
11 1.1 garbled * modification, are permitted provided that the following conditions
12 1.1 garbled * are met:
13 1.1 garbled * 1. Redistributions of source code must retain the above copyright
14 1.1 garbled * notice, this list of conditions and the following disclaimer.
15 1.1 garbled * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 garbled * notice, this list of conditions and the following disclaimer in the
17 1.1 garbled * documentation and/or other materials provided with the distribution.
18 1.1 garbled * 3. All advertising materials mentioning features or use of this software
19 1.1 garbled * must display the following acknowledgement:
20 1.1 garbled * This product includes software developed by the NetBSD
21 1.1 garbled * Foundation, Inc. and its contributors.
22 1.1 garbled * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 garbled * contributors may be used to endorse or promote products derived
24 1.1 garbled * from this software without specific prior written permission.
25 1.1 garbled *
26 1.1 garbled * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 garbled * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 garbled * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 garbled * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 garbled * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 garbled * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 garbled * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 garbled * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 garbled * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 garbled * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 garbled * POSSIBILITY OF SUCH DAMAGE.
37 1.1 garbled */
38 1.1 garbled
39 1.1 garbled #include <ctype.h>
40 1.1 garbled #include <err.h>
41 1.1 garbled #include <stdio.h>
42 1.1 garbled #include <string.h>
43 1.1 garbled #include <stdlib.h>
44 1.1 garbled #include <fcntl.h>
45 1.1 garbled #include <unistd.h>
46 1.1 garbled #include <sys/ioctl.h>
47 1.1 garbled #include <sys/types.h>
48 1.1 garbled #include <sys/envsys.h>
49 1.2 jdc #include <machine/apmvar.h>
50 1.1 garbled #include <machine/tctrl.h>
51 1.1 garbled
52 1.3 jdc #define TCTRL_DEV "/dev/tctrl0"
53 1.3 jdc
54 1.1 garbled int aflag, nflag, wflag, dev;
55 1.1 garbled
56 1.1 garbled #define PROTO(x) int x __P((int, int, int));
57 1.2 jdc void usage __P((void));
58 1.2 jdc static void parse __P((char *));
59 1.1 garbled char *dashdot __P((char *));
60 1.2 jdc int main __P((int, char *[]));
61 1.1 garbled PROTO(hw_version)
62 1.1 garbled PROTO(hw_microcontroller_version)
63 1.1 garbled PROTO(hw_poweroncycles)
64 1.1 garbled PROTO(hw_poweronseconds)
65 1.1 garbled PROTO(hw_power_mains)
66 1.1 garbled PROTO(hw_power_battery_int)
67 1.1 garbled PROTO(hw_power_battery_ext)
68 1.1 garbled PROTO(hw_power_battery_int_chargerate)
69 1.1 garbled PROTO(hw_power_battery_ext_chargerate)
70 1.1 garbled PROTO(hw_power_battery_int_chargelevel)
71 1.1 garbled PROTO(hw_power_battery_ext_chargelevel)
72 1.1 garbled PROTO(hw_video_external)
73 1.1 garbled PROTO(hw_video_lid)
74 1.1 garbled PROTO(hw_video_syncinva)
75 1.1 garbled PROTO(hw_video_syncinvb)
76 1.1 garbled PROTO(hw_video_compsync)
77 1.1 garbled PROTO(hw_video_tft_brightness)
78 1.1 garbled PROTO(hw_speaker_freq)
79 1.1 garbled PROTO(hw_speaker_volume)
80 1.1 garbled PROTO(hw_kbd_repeat_delay)
81 1.1 garbled PROTO(hw_kbd_repeat_speed)
82 1.1 garbled PROTO(hw_mouse_recalibrate)
83 1.1 garbled PROTO(hw_power_battery_chargedisabled)
84 1.1 garbled PROTO(hw_mouse_disable)
85 1.1 garbled PROTO(hw_kbd_click)
86 1.1 garbled PROTO(hw_mouse_intclick)
87 1.1 garbled PROTO(hw_mouse_extclick)
88 1.1 garbled PROTO(hw_mouse_sensitivity)
89 1.4 jdc PROTO(hw_serial_power)
90 1.1 garbled
91 1.4 jdc #define NUM_MIBS 29
92 1.1 garbled #define TABLE(n) { __STRING(n), 0, n }
93 1.1 garbled
94 1.1 garbled struct {
95 1.1 garbled char *mib;
96 1.1 garbled int value;
97 1.1 garbled int (*funcptr)(int, int, int);
98 1.1 garbled } table[NUM_MIBS] = {
99 1.1 garbled TABLE(hw_microcontroller_version),
100 1.1 garbled TABLE(hw_version),
101 1.1 garbled TABLE(hw_poweroncycles),
102 1.1 garbled TABLE(hw_poweronseconds),
103 1.1 garbled TABLE(hw_power_mains),
104 1.1 garbled TABLE(hw_power_battery_int),
105 1.1 garbled TABLE(hw_power_battery_ext),
106 1.1 garbled TABLE(hw_power_battery_chargedisabled),
107 1.1 garbled TABLE(hw_power_battery_int_chargerate),
108 1.1 garbled TABLE(hw_power_battery_ext_chargerate),
109 1.1 garbled TABLE(hw_power_battery_int_chargelevel),
110 1.1 garbled TABLE(hw_power_battery_ext_chargelevel),
111 1.1 garbled TABLE(hw_video_external),
112 1.1 garbled TABLE(hw_video_lid),
113 1.1 garbled TABLE(hw_video_syncinva),
114 1.1 garbled TABLE(hw_video_syncinvb),
115 1.1 garbled TABLE(hw_video_compsync),
116 1.1 garbled TABLE(hw_video_tft_brightness),
117 1.1 garbled TABLE(hw_speaker_freq),
118 1.1 garbled TABLE(hw_speaker_volume),
119 1.1 garbled TABLE(hw_kbd_repeat_delay),
120 1.1 garbled TABLE(hw_kbd_repeat_speed),
121 1.1 garbled TABLE(hw_kbd_click),
122 1.1 garbled TABLE(hw_mouse_recalibrate),
123 1.1 garbled TABLE(hw_mouse_disable),
124 1.1 garbled TABLE(hw_mouse_intclick),
125 1.1 garbled TABLE(hw_mouse_extclick),
126 1.1 garbled TABLE(hw_mouse_sensitivity),
127 1.4 jdc TABLE(hw_serial_power),
128 1.1 garbled };
129 1.1 garbled
130 1.1 garbled #define FUNC(x) \
131 1.1 garbled int \
132 1.1 garbled x(read, new, num) \
133 1.1 garbled int read, new, num;
134 1.1 garbled
135 1.1 garbled #define READ_REQ(a, b, c) \
136 1.1 garbled req.cmdbuf[0] = a; \
137 1.1 garbled req.cmdlen = b; \
138 1.1 garbled req.rsplen = c; \
139 1.1 garbled ioctl(dev, TCTRL_CMD_REQ, &req)
140 1.1 garbled
141 1.1 garbled #define WRITE_REQ(a, b, c) \
142 1.1 garbled req.cmdbuf[0] = a; \
143 1.1 garbled req.cmdlen = b; \
144 1.1 garbled req.rsplen = c; \
145 1.1 garbled ioctl(dev, TCTRL_CMD_REQ, &req)
146 1.1 garbled
147 1.1 garbled #define READ_ONLY \
148 1.1 garbled if (!read) \
149 1.1 garbled return(0)
150 1.1 garbled
151 1.1 garbled /* hardware functions */
152 1.1 garbled
153 1.1 garbled FUNC(hw_mouse_sensitivity)
154 1.1 garbled {
155 1.1 garbled struct tctrl_req req;
156 1.1 garbled
157 1.1 garbled req.cmdbuf[1] = 0xff;
158 1.1 garbled req.cmdbuf[2] = 0x00;
159 1.1 garbled READ_REQ(0x2c, 3, 2);
160 1.1 garbled table[num].value = req.rspbuf[0];
161 1.1 garbled if (read)
162 1.1 garbled return(1);
163 1.1 garbled if (new == 0)
164 1.1 garbled req.cmdbuf[2] = 0x00;
165 1.1 garbled else if (new > 255)
166 1.1 garbled req.cmdbuf[2] = 0xff;
167 1.1 garbled else
168 1.1 garbled req.cmdbuf[2] = new;
169 1.1 garbled req.cmdbuf[1] = 0x00;
170 1.1 garbled WRITE_REQ(0x2c, 3, 2);
171 1.1 garbled req.cmdbuf[1] = 0xff;
172 1.1 garbled req.cmdbuf[2] = 0x00;
173 1.1 garbled READ_REQ(0x2c, 3, 2);
174 1.1 garbled table[num].value = req.rspbuf[0];
175 1.1 garbled return(1);
176 1.1 garbled }
177 1.1 garbled
178 1.1 garbled FUNC(hw_power_battery_chargedisabled)
179 1.1 garbled {
180 1.1 garbled struct tctrl_req req;
181 1.1 garbled
182 1.1 garbled req.cmdbuf[1] = 0xff;
183 1.1 garbled req.cmdbuf[2] = 0x00;
184 1.1 garbled READ_REQ(0x22, 3, 2);
185 1.1 garbled table[num].value = req.rspbuf[0]&0x01 ? 1 : 0;
186 1.1 garbled if (read)
187 1.1 garbled return(1);
188 1.1 garbled if (new == 0)
189 1.1 garbled req.cmdbuf[2] = 0x00;
190 1.1 garbled else
191 1.1 garbled req.cmdbuf[2] = 0x01;
192 1.1 garbled req.cmdbuf[1] = ~0x01;
193 1.1 garbled WRITE_REQ(0x22, 3, 2);
194 1.1 garbled req.cmdbuf[1] = 0xff;
195 1.1 garbled req.cmdbuf[2] = 0x00;
196 1.1 garbled READ_REQ(0x22, 3, 2);
197 1.1 garbled table[num].value = req.rspbuf[0]&0x01 ? 1 : 0;
198 1.1 garbled return(1);
199 1.1 garbled }
200 1.1 garbled
201 1.1 garbled FUNC(hw_mouse_disable)
202 1.1 garbled {
203 1.1 garbled struct tctrl_req req;
204 1.1 garbled
205 1.1 garbled req.cmdbuf[1] = 0xff;
206 1.1 garbled req.cmdbuf[2] = 0x00;
207 1.1 garbled READ_REQ(0x22, 3, 2);
208 1.1 garbled table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
209 1.1 garbled if (read)
210 1.1 garbled return(1);
211 1.1 garbled if (new == 0)
212 1.1 garbled req.cmdbuf[2] = 0x00;
213 1.1 garbled else
214 1.1 garbled req.cmdbuf[2] = 0x02;
215 1.1 garbled req.cmdbuf[1] = ~0x02;
216 1.1 garbled WRITE_REQ(0x22, 3, 2);
217 1.1 garbled req.cmdbuf[1] = 0xff;
218 1.1 garbled req.cmdbuf[2] = 0x00;
219 1.1 garbled READ_REQ(0x22, 3, 2);
220 1.1 garbled table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
221 1.1 garbled return(1);
222 1.1 garbled }
223 1.1 garbled
224 1.1 garbled FUNC(hw_kbd_click)
225 1.1 garbled {
226 1.1 garbled struct tctrl_req req;
227 1.1 garbled
228 1.1 garbled req.cmdbuf[1] = 0xff;
229 1.1 garbled req.cmdbuf[2] = 0x00;
230 1.1 garbled READ_REQ(0x22, 3, 2);
231 1.1 garbled table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
232 1.1 garbled if (read)
233 1.1 garbled return(1);
234 1.1 garbled if (new == 0)
235 1.1 garbled req.cmdbuf[2] = 0x00;
236 1.1 garbled else
237 1.1 garbled req.cmdbuf[2] = 0x04;
238 1.1 garbled req.cmdbuf[1] = ~0x04;
239 1.1 garbled WRITE_REQ(0x22, 3, 2);
240 1.1 garbled req.cmdbuf[1] = 0xff;
241 1.1 garbled req.cmdbuf[2] = 0x00;
242 1.1 garbled READ_REQ(0x22, 3, 2);
243 1.1 garbled table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
244 1.1 garbled return(1);
245 1.1 garbled }
246 1.1 garbled
247 1.1 garbled FUNC(hw_mouse_intclick)
248 1.1 garbled {
249 1.1 garbled struct tctrl_req req;
250 1.1 garbled
251 1.1 garbled req.cmdbuf[1] = 0xff;
252 1.1 garbled req.cmdbuf[2] = 0x00;
253 1.1 garbled READ_REQ(0x22, 3, 2);
254 1.1 garbled table[num].value = req.rspbuf[0]&0x08 ? 1 : 0;
255 1.1 garbled if (read)
256 1.1 garbled return(1);
257 1.1 garbled if (new == 0)
258 1.1 garbled req.cmdbuf[2] = 0x00;
259 1.1 garbled else
260 1.1 garbled req.cmdbuf[2] = 0x08;
261 1.1 garbled req.cmdbuf[1] = ~0x08;
262 1.1 garbled WRITE_REQ(0x22, 3, 2);
263 1.1 garbled req.cmdbuf[1] = 0xff;
264 1.1 garbled req.cmdbuf[2] = 0x00;
265 1.1 garbled READ_REQ(0x22, 3, 2);
266 1.1 garbled table[num].value = req.rspbuf[0]&0x08 ? 1 : 0;
267 1.1 garbled return(1);
268 1.1 garbled }
269 1.1 garbled
270 1.1 garbled FUNC(hw_mouse_extclick)
271 1.1 garbled {
272 1.1 garbled struct tctrl_req req;
273 1.1 garbled
274 1.1 garbled req.cmdbuf[1] = 0xff;
275 1.1 garbled req.cmdbuf[2] = 0x00;
276 1.1 garbled READ_REQ(0x22, 3, 2);
277 1.1 garbled table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
278 1.1 garbled if (read)
279 1.1 garbled return(1);
280 1.1 garbled if (new == 0)
281 1.1 garbled req.cmdbuf[2] = 0x00;
282 1.1 garbled else
283 1.1 garbled req.cmdbuf[2] = 0x10;
284 1.1 garbled req.cmdbuf[1] = ~0x10;
285 1.1 garbled WRITE_REQ(0x22, 3, 2);
286 1.1 garbled req.cmdbuf[1] = 0xff;
287 1.1 garbled req.cmdbuf[2] = 0x00;
288 1.1 garbled READ_REQ(0x22, 3, 2);
289 1.1 garbled table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
290 1.1 garbled return(1);
291 1.1 garbled }
292 1.1 garbled
293 1.1 garbled /* ARGSUSED */
294 1.1 garbled FUNC(hw_mouse_recalibrate)
295 1.1 garbled {
296 1.1 garbled struct tctrl_req req;
297 1.1 garbled
298 1.1 garbled table[num].value = 0;
299 1.1 garbled if (read)
300 1.1 garbled return(1);
301 1.1 garbled READ_REQ(0x36, 1, 1);
302 1.1 garbled return(1);
303 1.1 garbled }
304 1.1 garbled
305 1.1 garbled FUNC(hw_kbd_repeat_delay)
306 1.1 garbled {
307 1.1 garbled struct tctrl_req req;
308 1.1 garbled
309 1.1 garbled req.cmdbuf[1] = 0xff;
310 1.1 garbled req.cmdbuf[2] = 0x00;
311 1.1 garbled READ_REQ(0x28, 3, 2);
312 1.1 garbled table[num].value = req.rspbuf[0];
313 1.1 garbled if (read)
314 1.1 garbled return(1);
315 1.1 garbled if (new == 0)
316 1.1 garbled req.cmdbuf[2] = 0x00;
317 1.1 garbled else if (new > 255)
318 1.1 garbled req.cmdbuf[2] = 0xff;
319 1.1 garbled else
320 1.1 garbled req.cmdbuf[2] = new;
321 1.1 garbled req.cmdbuf[1] = 0x00;
322 1.1 garbled WRITE_REQ(0x28, 3, 2);
323 1.1 garbled req.cmdbuf[1] = 0xff;
324 1.1 garbled req.cmdbuf[2] = 0x00;
325 1.1 garbled READ_REQ(0x28, 3, 2);
326 1.1 garbled table[num].value = req.rspbuf[0];
327 1.1 garbled return(1);
328 1.1 garbled }
329 1.1 garbled
330 1.1 garbled FUNC(hw_kbd_repeat_speed)
331 1.1 garbled {
332 1.1 garbled struct tctrl_req req;
333 1.1 garbled
334 1.1 garbled req.cmdbuf[1] = 0xff;
335 1.1 garbled req.cmdbuf[2] = 0x00;
336 1.1 garbled READ_REQ(0x29, 3, 2);
337 1.1 garbled table[num].value = req.rspbuf[0];
338 1.1 garbled if (read)
339 1.1 garbled return(1);
340 1.1 garbled if (new == 0)
341 1.1 garbled req.cmdbuf[2] = 0x00;
342 1.1 garbled else if (new > 255)
343 1.1 garbled req.cmdbuf[2] = 0xff;
344 1.1 garbled else
345 1.1 garbled req.cmdbuf[2] = new;
346 1.1 garbled req.cmdbuf[1] = 0x00;
347 1.1 garbled WRITE_REQ(0x29, 3, 2);
348 1.1 garbled req.cmdbuf[1] = 0xff;
349 1.1 garbled req.cmdbuf[2] = 0x00;
350 1.1 garbled READ_REQ(0x29, 3, 2);
351 1.1 garbled table[num].value = req.rspbuf[0];
352 1.1 garbled return(1);
353 1.1 garbled }
354 1.1 garbled
355 1.1 garbled FUNC(hw_speaker_freq)
356 1.1 garbled {
357 1.1 garbled struct tctrl_req req;
358 1.1 garbled
359 1.1 garbled table[num].value = 0;
360 1.1 garbled if (read)
361 1.1 garbled return(1);
362 1.1 garbled req.cmdbuf[1] = new * 256;
363 1.1 garbled req.cmdbuf[2] = new % 256;
364 1.1 garbled WRITE_REQ(0x37, 3, 1);
365 1.1 garbled return(1);
366 1.1 garbled }
367 1.1 garbled
368 1.1 garbled FUNC(hw_speaker_volume)
369 1.1 garbled {
370 1.1 garbled struct tctrl_req req;
371 1.1 garbled
372 1.1 garbled req.cmdbuf[1] = 0xff;
373 1.1 garbled req.cmdbuf[2] = 0x00;
374 1.1 garbled READ_REQ(0x23, 3, 2);
375 1.1 garbled table[num].value = req.rspbuf[0];
376 1.1 garbled if (read)
377 1.1 garbled return(1);
378 1.1 garbled if (new == 0)
379 1.1 garbled req.cmdbuf[2] = 0x00;
380 1.1 garbled else if (new > 255)
381 1.1 garbled req.cmdbuf[2] = 0xff;
382 1.1 garbled else
383 1.1 garbled req.cmdbuf[2] = new;
384 1.1 garbled req.cmdbuf[1] = 0x00;
385 1.1 garbled WRITE_REQ(0x23, 3, 2);
386 1.1 garbled req.cmdbuf[1] = 0xff;
387 1.1 garbled req.cmdbuf[2] = 0x00;
388 1.1 garbled READ_REQ(0x23, 3, 2);
389 1.1 garbled table[num].value = req.rspbuf[0];
390 1.1 garbled return(1);
391 1.1 garbled }
392 1.1 garbled
393 1.1 garbled FUNC(hw_video_tft_brightness)
394 1.1 garbled {
395 1.1 garbled struct tctrl_req req;
396 1.1 garbled
397 1.1 garbled req.cmdbuf[1] = 0xff;
398 1.1 garbled req.cmdbuf[2] = 0x00;
399 1.1 garbled READ_REQ(0x24, 3, 2);
400 1.1 garbled table[num].value = req.rspbuf[0];
401 1.1 garbled if (read)
402 1.1 garbled return(1);
403 1.1 garbled if (new == 0)
404 1.1 garbled req.cmdbuf[2] = 0x00;
405 1.1 garbled else if (new > 255)
406 1.1 garbled req.cmdbuf[2] = 0xff;
407 1.1 garbled else
408 1.1 garbled req.cmdbuf[2] = new;
409 1.1 garbled req.cmdbuf[1] = 0x00;
410 1.1 garbled WRITE_REQ(0x24, 3, 2);
411 1.1 garbled req.cmdbuf[1] = 0xff;
412 1.1 garbled req.cmdbuf[2] = 0x00;
413 1.1 garbled READ_REQ(0x24, 3, 2);
414 1.1 garbled table[num].value = req.rspbuf[0];
415 1.1 garbled return(1);
416 1.1 garbled }
417 1.1 garbled
418 1.1 garbled FUNC(hw_video_syncinva)
419 1.1 garbled {
420 1.1 garbled struct tctrl_req req;
421 1.1 garbled
422 1.1 garbled req.cmdbuf[1] = 0xff;
423 1.1 garbled req.cmdbuf[2] = 0x00;
424 1.1 garbled READ_REQ(0x21, 3, 2);
425 1.1 garbled table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
426 1.1 garbled if (read)
427 1.1 garbled return(1);
428 1.1 garbled if (new == 0)
429 1.1 garbled req.cmdbuf[2] = 0x00;
430 1.1 garbled else
431 1.1 garbled req.cmdbuf[2] = 0x02;
432 1.1 garbled req.cmdbuf[1] = ~0x02;
433 1.1 garbled WRITE_REQ(0x21, 3, 2);
434 1.1 garbled req.cmdbuf[1] = 0xff;
435 1.1 garbled req.cmdbuf[2] = 0x00;
436 1.1 garbled READ_REQ(0x21, 3, 2);
437 1.1 garbled table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
438 1.1 garbled return(1);
439 1.1 garbled }
440 1.1 garbled
441 1.1 garbled FUNC(hw_video_syncinvb)
442 1.1 garbled {
443 1.1 garbled struct tctrl_req req;
444 1.1 garbled
445 1.1 garbled req.cmdbuf[1] = 0xff;
446 1.1 garbled req.cmdbuf[2] = 0x00;
447 1.1 garbled READ_REQ(0x21, 3, 2);
448 1.1 garbled table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
449 1.1 garbled if (read)
450 1.1 garbled return(1);
451 1.1 garbled if (new == 0)
452 1.1 garbled req.cmdbuf[2] = 0x00;
453 1.1 garbled else
454 1.1 garbled req.cmdbuf[2] = 0x04;
455 1.1 garbled req.cmdbuf[1] = ~0x04;
456 1.1 garbled WRITE_REQ(0x21, 3, 2);
457 1.1 garbled req.cmdbuf[1] = 0xff;
458 1.1 garbled req.cmdbuf[2] = 0x00;
459 1.1 garbled READ_REQ(0x21, 3, 2);
460 1.1 garbled table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
461 1.1 garbled return(1);
462 1.1 garbled }
463 1.1 garbled
464 1.1 garbled FUNC(hw_video_compsync)
465 1.1 garbled {
466 1.1 garbled struct tctrl_req req;
467 1.1 garbled
468 1.1 garbled req.cmdbuf[1] = 0xff;
469 1.1 garbled req.cmdbuf[2] = 0x00;
470 1.1 garbled READ_REQ(0x21, 3, 2);
471 1.1 garbled table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
472 1.1 garbled if (read)
473 1.1 garbled return(1);
474 1.1 garbled if (new == 0)
475 1.1 garbled req.cmdbuf[2] = 0x00;
476 1.1 garbled else
477 1.1 garbled req.cmdbuf[2] = 0x10;
478 1.1 garbled req.cmdbuf[1] = ~0x10;
479 1.1 garbled WRITE_REQ(0x21, 3, 2);
480 1.1 garbled req.cmdbuf[1] = 0xff;
481 1.1 garbled req.cmdbuf[2] = 0x00;
482 1.1 garbled READ_REQ(0x21, 3, 2);
483 1.1 garbled table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
484 1.1 garbled return(1);
485 1.1 garbled }
486 1.1 garbled
487 1.1 garbled /* ARGSUSED */
488 1.1 garbled FUNC(hw_video_lid)
489 1.1 garbled {
490 1.1 garbled struct tctrl_req req;
491 1.1 garbled short i;
492 1.1 garbled
493 1.1 garbled READ_ONLY;
494 1.1 garbled READ_REQ(0x11, 1, 3);
495 1.1 garbled i = (req.rspbuf[0]<<8) + req.rspbuf[1];
496 1.1 garbled table[num].value = i&0x0040 ? 0 : 1;
497 1.1 garbled return(1);
498 1.1 garbled }
499 1.1 garbled
500 1.1 garbled /* ARGSUSED */
501 1.1 garbled FUNC(hw_video_external)
502 1.1 garbled {
503 1.1 garbled struct tctrl_req req;
504 1.1 garbled short i;
505 1.1 garbled
506 1.1 garbled READ_ONLY;
507 1.1 garbled READ_REQ(0x11, 1, 3);
508 1.1 garbled i = (req.rspbuf[0]<<8) + req.rspbuf[1];
509 1.1 garbled table[num].value = i&0x0008 ? 1 : 0;
510 1.1 garbled return(1);
511 1.1 garbled }
512 1.1 garbled
513 1.1 garbled /* ARGSUSED */
514 1.1 garbled FUNC(hw_power_battery_int_chargelevel)
515 1.1 garbled {
516 1.1 garbled struct tctrl_req req;
517 1.1 garbled
518 1.1 garbled READ_ONLY;
519 1.1 garbled READ_REQ(0x7a, 1, 3);
520 1.1 garbled table[num].value = req.rspbuf[0] == 0xfb ? 0 : req.rspbuf[0];
521 1.1 garbled return(1);
522 1.1 garbled
523 1.1 garbled }
524 1.1 garbled
525 1.1 garbled /* ARGSUSED */
526 1.1 garbled FUNC(hw_power_battery_ext_chargelevel)
527 1.1 garbled {
528 1.1 garbled struct tctrl_req req;
529 1.1 garbled
530 1.1 garbled READ_ONLY;
531 1.1 garbled READ_REQ(0x7b, 1, 3);
532 1.1 garbled table[num].value = req.rspbuf[0] == 0xfb ? 0 : req.rspbuf[0];
533 1.1 garbled return(1);
534 1.1 garbled }
535 1.1 garbled
536 1.1 garbled FUNC(hw_power_battery_int_chargerate)
537 1.1 garbled {
538 1.1 garbled struct tctrl_req req;
539 1.1 garbled
540 1.1 garbled READ_REQ(0x18, 1, 2);
541 1.1 garbled table[num].value = req.rspbuf[0];
542 1.1 garbled if (read)
543 1.1 garbled return(1);
544 1.1 garbled req.cmdbuf[1] = new < 255 ? new : 255;
545 1.1 garbled WRITE_REQ(0x39, 2, 1);
546 1.1 garbled READ_REQ(0x18, 1, 2);
547 1.1 garbled table[num].value = req.rspbuf[0];
548 1.1 garbled return(1);
549 1.1 garbled }
550 1.1 garbled
551 1.1 garbled FUNC(hw_power_battery_ext_chargerate)
552 1.1 garbled {
553 1.1 garbled struct tctrl_req req;
554 1.1 garbled
555 1.1 garbled READ_REQ(0x18, 1, 2);
556 1.1 garbled table[num].value = req.rspbuf[0];
557 1.1 garbled if (read)
558 1.1 garbled return(1);
559 1.1 garbled req.cmdbuf[1] = new < 255 ? new : 255;
560 1.1 garbled WRITE_REQ(0x39, 2, 1);
561 1.1 garbled READ_REQ(0x18, 1, 2);
562 1.1 garbled table[num].value = req.rspbuf[0];
563 1.1 garbled return(1);
564 1.1 garbled }
565 1.1 garbled
566 1.1 garbled /* ARGSUSED */
567 1.1 garbled FUNC(hw_power_battery_ext)
568 1.1 garbled {
569 1.1 garbled int i;
570 1.1 garbled struct tctrl_req req;
571 1.1 garbled
572 1.1 garbled READ_ONLY;
573 1.1 garbled READ_REQ(0x11, 1, 3);
574 1.1 garbled i = (req.rspbuf[0]<<8) + req.rspbuf[1];
575 1.1 garbled table[num].value = i&0x0004 ? 1 : 0;
576 1.1 garbled return(1);
577 1.1 garbled }
578 1.1 garbled
579 1.1 garbled /* ARGSUSED */
580 1.1 garbled FUNC(hw_power_battery_int)
581 1.1 garbled {
582 1.1 garbled int i;
583 1.1 garbled struct tctrl_req req;
584 1.1 garbled
585 1.1 garbled READ_ONLY;
586 1.1 garbled READ_REQ(0x11, 1, 3);
587 1.1 garbled i = (req.rspbuf[0]<<8) + req.rspbuf[1];
588 1.1 garbled table[num].value = i&0x0002 ? 1 : 0;
589 1.1 garbled return(1);
590 1.1 garbled }
591 1.1 garbled
592 1.1 garbled /* ARGSUSED */
593 1.1 garbled FUNC(hw_power_mains)
594 1.1 garbled {
595 1.1 garbled int i;
596 1.1 garbled struct tctrl_req req;
597 1.1 garbled
598 1.1 garbled READ_ONLY;
599 1.1 garbled READ_REQ(0x11, 1, 3);
600 1.1 garbled i = (req.rspbuf[0]<<8) + req.rspbuf[1];
601 1.1 garbled table[num].value = i&0x0001 ? 1 : 0;
602 1.1 garbled return(1);
603 1.1 garbled }
604 1.1 garbled
605 1.1 garbled /* ARGSUSED */
606 1.1 garbled FUNC(hw_poweroncycles)
607 1.1 garbled {
608 1.1 garbled struct tctrl_req req;
609 1.1 garbled
610 1.1 garbled READ_ONLY;
611 1.1 garbled READ_REQ(0x09, 1, 5);
612 1.1 garbled table[num].value = (req.rspbuf[0]<<24)+(req.rspbuf[1]<<16)+
613 1.1 garbled (req.rspbuf[2]<<8)+req.rspbuf[3];
614 1.1 garbled return(1);
615 1.1 garbled }
616 1.1 garbled
617 1.1 garbled /* ARGSUSED */
618 1.1 garbled FUNC(hw_poweronseconds)
619 1.1 garbled {
620 1.1 garbled struct tctrl_req req;
621 1.1 garbled
622 1.1 garbled READ_ONLY;
623 1.1 garbled READ_REQ(0x0a, 1, 5);
624 1.1 garbled table[num].value = (req.rspbuf[0]<<24)+(req.rspbuf[1]<<16)+
625 1.1 garbled (req.rspbuf[2]<<8)+req.rspbuf[3];
626 1.1 garbled return(1);
627 1.1 garbled }
628 1.1 garbled
629 1.1 garbled /* ARGSUSED */
630 1.1 garbled FUNC(hw_microcontroller_version)
631 1.1 garbled {
632 1.6 itojun char buf[BUFSIZ];
633 1.1 garbled struct tctrl_req req;
634 1.1 garbled
635 1.1 garbled READ_ONLY;
636 1.1 garbled READ_REQ(0x04, 1, 3);
637 1.6 itojun snprintf(buf, sizeof(buf), "%d%d", req.rspbuf[0]*1000,
638 1.6 itojun req.rspbuf[1]*10);
639 1.6 itojun table[num].value = atoi(strdup(buf));
640 1.1 garbled return(1);
641 1.1 garbled }
642 1.1 garbled
643 1.1 garbled
644 1.1 garbled /* ARGSUSED */
645 1.1 garbled FUNC(hw_version)
646 1.1 garbled {
647 1.6 itojun char buf[BUFSIZ];
648 1.1 garbled struct tctrl_req req;
649 1.1 garbled
650 1.1 garbled READ_ONLY;
651 1.1 garbled READ_REQ(0x03, 1, 3);
652 1.6 itojun snprintf(buf, sizeof(buf), "%d%d", req.rspbuf[0]*1000,
653 1.6 itojun req.rspbuf[1]*10);
654 1.6 itojun table[num].value = atoi(strdup(buf));
655 1.4 jdc return(1);
656 1.4 jdc }
657 1.4 jdc
658 1.4 jdc FUNC(hw_serial_power)
659 1.4 jdc {
660 1.4 jdc struct tctrl_pwr pwrreq;
661 1.4 jdc
662 1.4 jdc if (!read) {
663 1.4 jdc pwrreq.rw = 0x00;
664 1.4 jdc pwrreq.state = new;
665 1.4 jdc ioctl(dev, TCTRL_SERIAL_PWR, &pwrreq);
666 1.4 jdc }
667 1.4 jdc pwrreq.rw = 0x01;
668 1.4 jdc ioctl(dev, TCTRL_SERIAL_PWR, &pwrreq);
669 1.4 jdc table[num].value = pwrreq.state;
670 1.1 garbled return(1);
671 1.1 garbled }
672 1.1 garbled
673 1.1 garbled void
674 1.1 garbled usage()
675 1.1 garbled {
676 1.1 garbled (void)fprintf(stderr,
677 1.1 garbled "usage: tadpolectl [-n] name ...\n"
678 1.1 garbled " tadpolectl [-n] -w name=value\n"
679 1.1 garbled " tadpolectl [-n] -a\n");
680 1.1 garbled exit(1);
681 1.1 garbled }
682 1.1 garbled
683 1.1 garbled static void
684 1.1 garbled parse(string)
685 1.1 garbled char *string;
686 1.1 garbled {
687 1.1 garbled char *cp, buf[BUFSIZ];
688 1.1 garbled int newval = 0;
689 1.1 garbled int i, j, ret;
690 1.1 garbled
691 1.1 garbled string = dashdot(string);
692 1.1 garbled snprintf(buf, (size_t)BUFSIZ, "%s", string);
693 1.1 garbled if ((cp = strchr(string, '=')) != NULL) {
694 1.1 garbled if (!wflag)
695 1.1 garbled errx(2, "Must specify -w to set variables");
696 1.1 garbled *strchr(buf, '=') = '\0';
697 1.1 garbled *cp++ = '\0';
698 1.1 garbled while (isspace((unsigned char) *cp))
699 1.1 garbled cp++;
700 1.1 garbled newval = atoi(cp);
701 1.1 garbled }
702 1.1 garbled for (j=0,i=-1; j < NUM_MIBS; j++) {
703 1.1 garbled if (strcmp(string, table[j].mib) == 0) {
704 1.1 garbled i = j;
705 1.1 garbled break;
706 1.1 garbled }
707 1.1 garbled }
708 1.1 garbled if (i == -1)
709 1.1 garbled errx(2, "Named value does not exist");
710 1.1 garbled
711 1.1 garbled if (wflag) {
712 1.1 garbled ret = (*table[i].funcptr)(0, newval, i);
713 1.1 garbled if (!ret)
714 1.1 garbled errx(2, "Cannot modify this value");
715 1.1 garbled } else
716 1.1 garbled ret = (*table[i].funcptr)(1, 0, i);
717 1.1 garbled if (nflag)
718 1.1 garbled printf("%d\n", table[i].value);
719 1.1 garbled else
720 1.1 garbled printf("%s = %d\n", dashdot(table[i].mib), table[i].value);
721 1.1 garbled }
722 1.1 garbled
723 1.1 garbled char *
724 1.1 garbled dashdot(string)
725 1.1 garbled char *string;
726 1.1 garbled {
727 1.1 garbled char *p;
728 1.1 garbled char *save;
729 1.1 garbled
730 1.1 garbled p = strdup(string);
731 1.1 garbled save = p;
732 1.1 garbled
733 1.1 garbled for (; (*p = *string) != '\0'; ++p, ++string) {
734 1.1 garbled if (*p == '.')
735 1.1 garbled *p = '_';
736 1.1 garbled else if (*p == '_')
737 1.1 garbled *p = '.';
738 1.1 garbled }
739 1.1 garbled return(save);
740 1.1 garbled }
741 1.1 garbled
742 1.1 garbled int
743 1.1 garbled main(argc, argv)
744 1.1 garbled int argc;
745 1.1 garbled char *argv[];
746 1.1 garbled {
747 1.1 garbled int ch, j;
748 1.1 garbled
749 1.1 garbled while ((ch = getopt(argc, argv, "anw")) != -1) {
750 1.1 garbled switch (ch) {
751 1.1 garbled
752 1.1 garbled case 'a':
753 1.1 garbled aflag = 1;
754 1.1 garbled break;
755 1.1 garbled case 'n':
756 1.1 garbled nflag = 1;
757 1.1 garbled break;
758 1.1 garbled case 'w':
759 1.1 garbled wflag = 1;
760 1.1 garbled break;
761 1.1 garbled default:
762 1.1 garbled usage();
763 1.1 garbled }
764 1.1 garbled }
765 1.1 garbled argc -= optind;
766 1.1 garbled argv += optind;
767 1.1 garbled
768 1.3 jdc if ((dev = open(TCTRL_DEV, O_RDONLY, NULL)) == -1)
769 1.3 jdc err(1, "%s", TCTRL_DEV);
770 1.1 garbled
771 1.1 garbled if (aflag) {
772 1.1 garbled for (j=0; j < NUM_MIBS; j++) {
773 1.1 garbled (void)(*table[j].funcptr)(1, 0, j);
774 1.1 garbled if (nflag)
775 1.1 garbled printf("%d\n", table[j].value);
776 1.1 garbled else
777 1.1 garbled printf("%s = %d\n", dashdot(table[j].mib),
778 1.1 garbled table[j].value);
779 1.1 garbled }
780 1.1 garbled return(0);
781 1.1 garbled }
782 1.1 garbled if (argc == 0)
783 1.1 garbled usage();
784 1.1 garbled while (argc-- > 0)
785 1.1 garbled parse(*argv++);
786 1.1 garbled return(0);
787 1.1 garbled }
788