tadpolectl.c revision 1.3 1 1.3 jdc /* $NetBSD: tadpolectl.c,v 1.3 2000/02/23 11:33:58 jdc 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.1 garbled
90 1.1 garbled #define NUM_MIBS 28
91 1.1 garbled #define TABLE(n) { __STRING(n), 0, n }
92 1.1 garbled
93 1.1 garbled struct {
94 1.1 garbled char *mib;
95 1.1 garbled int value;
96 1.1 garbled int (*funcptr)(int, int, int);
97 1.1 garbled } table[NUM_MIBS] = {
98 1.1 garbled TABLE(hw_microcontroller_version),
99 1.1 garbled TABLE(hw_version),
100 1.1 garbled TABLE(hw_poweroncycles),
101 1.1 garbled TABLE(hw_poweronseconds),
102 1.1 garbled TABLE(hw_power_mains),
103 1.1 garbled TABLE(hw_power_battery_int),
104 1.1 garbled TABLE(hw_power_battery_ext),
105 1.1 garbled TABLE(hw_power_battery_chargedisabled),
106 1.1 garbled TABLE(hw_power_battery_int_chargerate),
107 1.1 garbled TABLE(hw_power_battery_ext_chargerate),
108 1.1 garbled TABLE(hw_power_battery_int_chargelevel),
109 1.1 garbled TABLE(hw_power_battery_ext_chargelevel),
110 1.1 garbled TABLE(hw_video_external),
111 1.1 garbled TABLE(hw_video_lid),
112 1.1 garbled TABLE(hw_video_syncinva),
113 1.1 garbled TABLE(hw_video_syncinvb),
114 1.1 garbled TABLE(hw_video_compsync),
115 1.1 garbled TABLE(hw_video_tft_brightness),
116 1.1 garbled TABLE(hw_speaker_freq),
117 1.1 garbled TABLE(hw_speaker_volume),
118 1.1 garbled TABLE(hw_kbd_repeat_delay),
119 1.1 garbled TABLE(hw_kbd_repeat_speed),
120 1.1 garbled TABLE(hw_kbd_click),
121 1.1 garbled TABLE(hw_mouse_recalibrate),
122 1.1 garbled TABLE(hw_mouse_disable),
123 1.1 garbled TABLE(hw_mouse_intclick),
124 1.1 garbled TABLE(hw_mouse_extclick),
125 1.1 garbled TABLE(hw_mouse_sensitivity),
126 1.1 garbled };
127 1.1 garbled
128 1.1 garbled #define FUNC(x) \
129 1.1 garbled int \
130 1.1 garbled x(read, new, num) \
131 1.1 garbled int read, new, num;
132 1.1 garbled
133 1.1 garbled #define READ_REQ(a, b, c) \
134 1.1 garbled req.cmdbuf[0] = a; \
135 1.1 garbled req.cmdlen = b; \
136 1.1 garbled req.rsplen = c; \
137 1.1 garbled ioctl(dev, TCTRL_CMD_REQ, &req)
138 1.1 garbled
139 1.1 garbled #define WRITE_REQ(a, b, c) \
140 1.1 garbled req.cmdbuf[0] = a; \
141 1.1 garbled req.cmdlen = b; \
142 1.1 garbled req.rsplen = c; \
143 1.1 garbled ioctl(dev, TCTRL_CMD_REQ, &req)
144 1.1 garbled
145 1.1 garbled #define READ_ONLY \
146 1.1 garbled if (!read) \
147 1.1 garbled return(0)
148 1.1 garbled
149 1.1 garbled /* hardware functions */
150 1.1 garbled
151 1.1 garbled FUNC(hw_mouse_sensitivity)
152 1.1 garbled {
153 1.1 garbled struct tctrl_req req;
154 1.1 garbled
155 1.1 garbled req.cmdbuf[1] = 0xff;
156 1.1 garbled req.cmdbuf[2] = 0x00;
157 1.1 garbled READ_REQ(0x2c, 3, 2);
158 1.1 garbled table[num].value = req.rspbuf[0];
159 1.1 garbled if (read)
160 1.1 garbled return(1);
161 1.1 garbled if (new == 0)
162 1.1 garbled req.cmdbuf[2] = 0x00;
163 1.1 garbled else if (new > 255)
164 1.1 garbled req.cmdbuf[2] = 0xff;
165 1.1 garbled else
166 1.1 garbled req.cmdbuf[2] = new;
167 1.1 garbled req.cmdbuf[1] = 0x00;
168 1.1 garbled WRITE_REQ(0x2c, 3, 2);
169 1.1 garbled req.cmdbuf[1] = 0xff;
170 1.1 garbled req.cmdbuf[2] = 0x00;
171 1.1 garbled READ_REQ(0x2c, 3, 2);
172 1.1 garbled table[num].value = req.rspbuf[0];
173 1.1 garbled return(1);
174 1.1 garbled }
175 1.1 garbled
176 1.1 garbled FUNC(hw_power_battery_chargedisabled)
177 1.1 garbled {
178 1.1 garbled struct tctrl_req req;
179 1.1 garbled
180 1.1 garbled req.cmdbuf[1] = 0xff;
181 1.1 garbled req.cmdbuf[2] = 0x00;
182 1.1 garbled READ_REQ(0x22, 3, 2);
183 1.1 garbled table[num].value = req.rspbuf[0]&0x01 ? 1 : 0;
184 1.1 garbled if (read)
185 1.1 garbled return(1);
186 1.1 garbled if (new == 0)
187 1.1 garbled req.cmdbuf[2] = 0x00;
188 1.1 garbled else
189 1.1 garbled req.cmdbuf[2] = 0x01;
190 1.1 garbled req.cmdbuf[1] = ~0x01;
191 1.1 garbled WRITE_REQ(0x22, 3, 2);
192 1.1 garbled req.cmdbuf[1] = 0xff;
193 1.1 garbled req.cmdbuf[2] = 0x00;
194 1.1 garbled READ_REQ(0x22, 3, 2);
195 1.1 garbled table[num].value = req.rspbuf[0]&0x01 ? 1 : 0;
196 1.1 garbled return(1);
197 1.1 garbled }
198 1.1 garbled
199 1.1 garbled FUNC(hw_mouse_disable)
200 1.1 garbled {
201 1.1 garbled struct tctrl_req req;
202 1.1 garbled
203 1.1 garbled req.cmdbuf[1] = 0xff;
204 1.1 garbled req.cmdbuf[2] = 0x00;
205 1.1 garbled READ_REQ(0x22, 3, 2);
206 1.1 garbled table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
207 1.1 garbled if (read)
208 1.1 garbled return(1);
209 1.1 garbled if (new == 0)
210 1.1 garbled req.cmdbuf[2] = 0x00;
211 1.1 garbled else
212 1.1 garbled req.cmdbuf[2] = 0x02;
213 1.1 garbled req.cmdbuf[1] = ~0x02;
214 1.1 garbled WRITE_REQ(0x22, 3, 2);
215 1.1 garbled req.cmdbuf[1] = 0xff;
216 1.1 garbled req.cmdbuf[2] = 0x00;
217 1.1 garbled READ_REQ(0x22, 3, 2);
218 1.1 garbled table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
219 1.1 garbled return(1);
220 1.1 garbled }
221 1.1 garbled
222 1.1 garbled FUNC(hw_kbd_click)
223 1.1 garbled {
224 1.1 garbled struct tctrl_req req;
225 1.1 garbled
226 1.1 garbled req.cmdbuf[1] = 0xff;
227 1.1 garbled req.cmdbuf[2] = 0x00;
228 1.1 garbled READ_REQ(0x22, 3, 2);
229 1.1 garbled table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
230 1.1 garbled if (read)
231 1.1 garbled return(1);
232 1.1 garbled if (new == 0)
233 1.1 garbled req.cmdbuf[2] = 0x00;
234 1.1 garbled else
235 1.1 garbled req.cmdbuf[2] = 0x04;
236 1.1 garbled req.cmdbuf[1] = ~0x04;
237 1.1 garbled WRITE_REQ(0x22, 3, 2);
238 1.1 garbled req.cmdbuf[1] = 0xff;
239 1.1 garbled req.cmdbuf[2] = 0x00;
240 1.1 garbled READ_REQ(0x22, 3, 2);
241 1.1 garbled table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
242 1.1 garbled return(1);
243 1.1 garbled }
244 1.1 garbled
245 1.1 garbled FUNC(hw_mouse_intclick)
246 1.1 garbled {
247 1.1 garbled struct tctrl_req req;
248 1.1 garbled
249 1.1 garbled req.cmdbuf[1] = 0xff;
250 1.1 garbled req.cmdbuf[2] = 0x00;
251 1.1 garbled READ_REQ(0x22, 3, 2);
252 1.1 garbled table[num].value = req.rspbuf[0]&0x08 ? 1 : 0;
253 1.1 garbled if (read)
254 1.1 garbled return(1);
255 1.1 garbled if (new == 0)
256 1.1 garbled req.cmdbuf[2] = 0x00;
257 1.1 garbled else
258 1.1 garbled req.cmdbuf[2] = 0x08;
259 1.1 garbled req.cmdbuf[1] = ~0x08;
260 1.1 garbled WRITE_REQ(0x22, 3, 2);
261 1.1 garbled req.cmdbuf[1] = 0xff;
262 1.1 garbled req.cmdbuf[2] = 0x00;
263 1.1 garbled READ_REQ(0x22, 3, 2);
264 1.1 garbled table[num].value = req.rspbuf[0]&0x08 ? 1 : 0;
265 1.1 garbled return(1);
266 1.1 garbled }
267 1.1 garbled
268 1.1 garbled FUNC(hw_mouse_extclick)
269 1.1 garbled {
270 1.1 garbled struct tctrl_req req;
271 1.1 garbled
272 1.1 garbled req.cmdbuf[1] = 0xff;
273 1.1 garbled req.cmdbuf[2] = 0x00;
274 1.1 garbled READ_REQ(0x22, 3, 2);
275 1.1 garbled table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
276 1.1 garbled if (read)
277 1.1 garbled return(1);
278 1.1 garbled if (new == 0)
279 1.1 garbled req.cmdbuf[2] = 0x00;
280 1.1 garbled else
281 1.1 garbled req.cmdbuf[2] = 0x10;
282 1.1 garbled req.cmdbuf[1] = ~0x10;
283 1.1 garbled WRITE_REQ(0x22, 3, 2);
284 1.1 garbled req.cmdbuf[1] = 0xff;
285 1.1 garbled req.cmdbuf[2] = 0x00;
286 1.1 garbled READ_REQ(0x22, 3, 2);
287 1.1 garbled table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
288 1.1 garbled return(1);
289 1.1 garbled }
290 1.1 garbled
291 1.1 garbled /* ARGSUSED */
292 1.1 garbled FUNC(hw_mouse_recalibrate)
293 1.1 garbled {
294 1.1 garbled struct tctrl_req req;
295 1.1 garbled
296 1.1 garbled table[num].value = 0;
297 1.1 garbled if (read)
298 1.1 garbled return(1);
299 1.1 garbled READ_REQ(0x36, 1, 1);
300 1.1 garbled return(1);
301 1.1 garbled }
302 1.1 garbled
303 1.1 garbled FUNC(hw_kbd_repeat_delay)
304 1.1 garbled {
305 1.1 garbled struct tctrl_req req;
306 1.1 garbled
307 1.1 garbled req.cmdbuf[1] = 0xff;
308 1.1 garbled req.cmdbuf[2] = 0x00;
309 1.1 garbled READ_REQ(0x28, 3, 2);
310 1.1 garbled table[num].value = req.rspbuf[0];
311 1.1 garbled if (read)
312 1.1 garbled return(1);
313 1.1 garbled if (new == 0)
314 1.1 garbled req.cmdbuf[2] = 0x00;
315 1.1 garbled else if (new > 255)
316 1.1 garbled req.cmdbuf[2] = 0xff;
317 1.1 garbled else
318 1.1 garbled req.cmdbuf[2] = new;
319 1.1 garbled req.cmdbuf[1] = 0x00;
320 1.1 garbled WRITE_REQ(0x28, 3, 2);
321 1.1 garbled req.cmdbuf[1] = 0xff;
322 1.1 garbled req.cmdbuf[2] = 0x00;
323 1.1 garbled READ_REQ(0x28, 3, 2);
324 1.1 garbled table[num].value = req.rspbuf[0];
325 1.1 garbled return(1);
326 1.1 garbled }
327 1.1 garbled
328 1.1 garbled FUNC(hw_kbd_repeat_speed)
329 1.1 garbled {
330 1.1 garbled struct tctrl_req req;
331 1.1 garbled
332 1.1 garbled req.cmdbuf[1] = 0xff;
333 1.1 garbled req.cmdbuf[2] = 0x00;
334 1.1 garbled READ_REQ(0x29, 3, 2);
335 1.1 garbled table[num].value = req.rspbuf[0];
336 1.1 garbled if (read)
337 1.1 garbled return(1);
338 1.1 garbled if (new == 0)
339 1.1 garbled req.cmdbuf[2] = 0x00;
340 1.1 garbled else if (new > 255)
341 1.1 garbled req.cmdbuf[2] = 0xff;
342 1.1 garbled else
343 1.1 garbled req.cmdbuf[2] = new;
344 1.1 garbled req.cmdbuf[1] = 0x00;
345 1.1 garbled WRITE_REQ(0x29, 3, 2);
346 1.1 garbled req.cmdbuf[1] = 0xff;
347 1.1 garbled req.cmdbuf[2] = 0x00;
348 1.1 garbled READ_REQ(0x29, 3, 2);
349 1.1 garbled table[num].value = req.rspbuf[0];
350 1.1 garbled return(1);
351 1.1 garbled }
352 1.1 garbled
353 1.1 garbled FUNC(hw_speaker_freq)
354 1.1 garbled {
355 1.1 garbled struct tctrl_req req;
356 1.1 garbled
357 1.1 garbled table[num].value = 0;
358 1.1 garbled if (read)
359 1.1 garbled return(1);
360 1.1 garbled req.cmdbuf[1] = new * 256;
361 1.1 garbled req.cmdbuf[2] = new % 256;
362 1.1 garbled WRITE_REQ(0x37, 3, 1);
363 1.1 garbled return(1);
364 1.1 garbled }
365 1.1 garbled
366 1.1 garbled FUNC(hw_speaker_volume)
367 1.1 garbled {
368 1.1 garbled struct tctrl_req req;
369 1.1 garbled
370 1.1 garbled req.cmdbuf[1] = 0xff;
371 1.1 garbled req.cmdbuf[2] = 0x00;
372 1.1 garbled READ_REQ(0x23, 3, 2);
373 1.1 garbled table[num].value = req.rspbuf[0];
374 1.1 garbled if (read)
375 1.1 garbled return(1);
376 1.1 garbled if (new == 0)
377 1.1 garbled req.cmdbuf[2] = 0x00;
378 1.1 garbled else if (new > 255)
379 1.1 garbled req.cmdbuf[2] = 0xff;
380 1.1 garbled else
381 1.1 garbled req.cmdbuf[2] = new;
382 1.1 garbled req.cmdbuf[1] = 0x00;
383 1.1 garbled WRITE_REQ(0x23, 3, 2);
384 1.1 garbled req.cmdbuf[1] = 0xff;
385 1.1 garbled req.cmdbuf[2] = 0x00;
386 1.1 garbled READ_REQ(0x23, 3, 2);
387 1.1 garbled table[num].value = req.rspbuf[0];
388 1.1 garbled return(1);
389 1.1 garbled }
390 1.1 garbled
391 1.1 garbled FUNC(hw_video_tft_brightness)
392 1.1 garbled {
393 1.1 garbled struct tctrl_req req;
394 1.1 garbled
395 1.1 garbled req.cmdbuf[1] = 0xff;
396 1.1 garbled req.cmdbuf[2] = 0x00;
397 1.1 garbled READ_REQ(0x24, 3, 2);
398 1.1 garbled table[num].value = req.rspbuf[0];
399 1.1 garbled if (read)
400 1.1 garbled return(1);
401 1.1 garbled if (new == 0)
402 1.1 garbled req.cmdbuf[2] = 0x00;
403 1.1 garbled else if (new > 255)
404 1.1 garbled req.cmdbuf[2] = 0xff;
405 1.1 garbled else
406 1.1 garbled req.cmdbuf[2] = new;
407 1.1 garbled req.cmdbuf[1] = 0x00;
408 1.1 garbled WRITE_REQ(0x24, 3, 2);
409 1.1 garbled req.cmdbuf[1] = 0xff;
410 1.1 garbled req.cmdbuf[2] = 0x00;
411 1.1 garbled READ_REQ(0x24, 3, 2);
412 1.1 garbled table[num].value = req.rspbuf[0];
413 1.1 garbled return(1);
414 1.1 garbled }
415 1.1 garbled
416 1.1 garbled FUNC(hw_video_syncinva)
417 1.1 garbled {
418 1.1 garbled struct tctrl_req req;
419 1.1 garbled
420 1.1 garbled req.cmdbuf[1] = 0xff;
421 1.1 garbled req.cmdbuf[2] = 0x00;
422 1.1 garbled READ_REQ(0x21, 3, 2);
423 1.1 garbled table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
424 1.1 garbled if (read)
425 1.1 garbled return(1);
426 1.1 garbled if (new == 0)
427 1.1 garbled req.cmdbuf[2] = 0x00;
428 1.1 garbled else
429 1.1 garbled req.cmdbuf[2] = 0x02;
430 1.1 garbled req.cmdbuf[1] = ~0x02;
431 1.1 garbled WRITE_REQ(0x21, 3, 2);
432 1.1 garbled req.cmdbuf[1] = 0xff;
433 1.1 garbled req.cmdbuf[2] = 0x00;
434 1.1 garbled READ_REQ(0x21, 3, 2);
435 1.1 garbled table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
436 1.1 garbled return(1);
437 1.1 garbled }
438 1.1 garbled
439 1.1 garbled FUNC(hw_video_syncinvb)
440 1.1 garbled {
441 1.1 garbled struct tctrl_req req;
442 1.1 garbled
443 1.1 garbled req.cmdbuf[1] = 0xff;
444 1.1 garbled req.cmdbuf[2] = 0x00;
445 1.1 garbled READ_REQ(0x21, 3, 2);
446 1.1 garbled table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
447 1.1 garbled if (read)
448 1.1 garbled return(1);
449 1.1 garbled if (new == 0)
450 1.1 garbled req.cmdbuf[2] = 0x00;
451 1.1 garbled else
452 1.1 garbled req.cmdbuf[2] = 0x04;
453 1.1 garbled req.cmdbuf[1] = ~0x04;
454 1.1 garbled WRITE_REQ(0x21, 3, 2);
455 1.1 garbled req.cmdbuf[1] = 0xff;
456 1.1 garbled req.cmdbuf[2] = 0x00;
457 1.1 garbled READ_REQ(0x21, 3, 2);
458 1.1 garbled table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
459 1.1 garbled return(1);
460 1.1 garbled }
461 1.1 garbled
462 1.1 garbled FUNC(hw_video_compsync)
463 1.1 garbled {
464 1.1 garbled struct tctrl_req req;
465 1.1 garbled
466 1.1 garbled req.cmdbuf[1] = 0xff;
467 1.1 garbled req.cmdbuf[2] = 0x00;
468 1.1 garbled READ_REQ(0x21, 3, 2);
469 1.1 garbled table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
470 1.1 garbled if (read)
471 1.1 garbled return(1);
472 1.1 garbled if (new == 0)
473 1.1 garbled req.cmdbuf[2] = 0x00;
474 1.1 garbled else
475 1.1 garbled req.cmdbuf[2] = 0x10;
476 1.1 garbled req.cmdbuf[1] = ~0x10;
477 1.1 garbled WRITE_REQ(0x21, 3, 2);
478 1.1 garbled req.cmdbuf[1] = 0xff;
479 1.1 garbled req.cmdbuf[2] = 0x00;
480 1.1 garbled READ_REQ(0x21, 3, 2);
481 1.1 garbled table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
482 1.1 garbled return(1);
483 1.1 garbled }
484 1.1 garbled
485 1.1 garbled /* ARGSUSED */
486 1.1 garbled FUNC(hw_video_lid)
487 1.1 garbled {
488 1.1 garbled struct tctrl_req req;
489 1.1 garbled short i;
490 1.1 garbled
491 1.1 garbled READ_ONLY;
492 1.1 garbled READ_REQ(0x11, 1, 3);
493 1.1 garbled i = (req.rspbuf[0]<<8) + req.rspbuf[1];
494 1.1 garbled table[num].value = i&0x0040 ? 0 : 1;
495 1.1 garbled return(1);
496 1.1 garbled }
497 1.1 garbled
498 1.1 garbled /* ARGSUSED */
499 1.1 garbled FUNC(hw_video_external)
500 1.1 garbled {
501 1.1 garbled struct tctrl_req req;
502 1.1 garbled short i;
503 1.1 garbled
504 1.1 garbled READ_ONLY;
505 1.1 garbled READ_REQ(0x11, 1, 3);
506 1.1 garbled i = (req.rspbuf[0]<<8) + req.rspbuf[1];
507 1.1 garbled table[num].value = i&0x0008 ? 1 : 0;
508 1.1 garbled return(1);
509 1.1 garbled }
510 1.1 garbled
511 1.1 garbled /* ARGSUSED */
512 1.1 garbled FUNC(hw_power_battery_int_chargelevel)
513 1.1 garbled {
514 1.1 garbled struct tctrl_req req;
515 1.1 garbled
516 1.1 garbled READ_ONLY;
517 1.1 garbled READ_REQ(0x7a, 1, 3);
518 1.1 garbled table[num].value = req.rspbuf[0] == 0xfb ? 0 : req.rspbuf[0];
519 1.1 garbled return(1);
520 1.1 garbled
521 1.1 garbled }
522 1.1 garbled
523 1.1 garbled /* ARGSUSED */
524 1.1 garbled FUNC(hw_power_battery_ext_chargelevel)
525 1.1 garbled {
526 1.1 garbled struct tctrl_req req;
527 1.1 garbled
528 1.1 garbled READ_ONLY;
529 1.1 garbled READ_REQ(0x7b, 1, 3);
530 1.1 garbled table[num].value = req.rspbuf[0] == 0xfb ? 0 : req.rspbuf[0];
531 1.1 garbled return(1);
532 1.1 garbled }
533 1.1 garbled
534 1.1 garbled FUNC(hw_power_battery_int_chargerate)
535 1.1 garbled {
536 1.1 garbled struct tctrl_req req;
537 1.1 garbled
538 1.1 garbled READ_REQ(0x18, 1, 2);
539 1.1 garbled table[num].value = req.rspbuf[0];
540 1.1 garbled if (read)
541 1.1 garbled return(1);
542 1.1 garbled req.cmdbuf[1] = new < 255 ? new : 255;
543 1.1 garbled WRITE_REQ(0x39, 2, 1);
544 1.1 garbled READ_REQ(0x18, 1, 2);
545 1.1 garbled table[num].value = req.rspbuf[0];
546 1.1 garbled return(1);
547 1.1 garbled }
548 1.1 garbled
549 1.1 garbled FUNC(hw_power_battery_ext_chargerate)
550 1.1 garbled {
551 1.1 garbled struct tctrl_req req;
552 1.1 garbled
553 1.1 garbled READ_REQ(0x18, 1, 2);
554 1.1 garbled table[num].value = req.rspbuf[0];
555 1.1 garbled if (read)
556 1.1 garbled return(1);
557 1.1 garbled req.cmdbuf[1] = new < 255 ? new : 255;
558 1.1 garbled WRITE_REQ(0x39, 2, 1);
559 1.1 garbled READ_REQ(0x18, 1, 2);
560 1.1 garbled table[num].value = req.rspbuf[0];
561 1.1 garbled return(1);
562 1.1 garbled }
563 1.1 garbled
564 1.1 garbled /* ARGSUSED */
565 1.1 garbled FUNC(hw_power_battery_ext)
566 1.1 garbled {
567 1.1 garbled int i;
568 1.1 garbled struct tctrl_req req;
569 1.1 garbled
570 1.1 garbled READ_ONLY;
571 1.1 garbled READ_REQ(0x11, 1, 3);
572 1.1 garbled i = (req.rspbuf[0]<<8) + req.rspbuf[1];
573 1.1 garbled table[num].value = i&0x0004 ? 1 : 0;
574 1.1 garbled return(1);
575 1.1 garbled }
576 1.1 garbled
577 1.1 garbled /* ARGSUSED */
578 1.1 garbled FUNC(hw_power_battery_int)
579 1.1 garbled {
580 1.1 garbled int i;
581 1.1 garbled struct tctrl_req req;
582 1.1 garbled
583 1.1 garbled READ_ONLY;
584 1.1 garbled READ_REQ(0x11, 1, 3);
585 1.1 garbled i = (req.rspbuf[0]<<8) + req.rspbuf[1];
586 1.1 garbled table[num].value = i&0x0002 ? 1 : 0;
587 1.1 garbled return(1);
588 1.1 garbled }
589 1.1 garbled
590 1.1 garbled /* ARGSUSED */
591 1.1 garbled FUNC(hw_power_mains)
592 1.1 garbled {
593 1.1 garbled int i;
594 1.1 garbled struct tctrl_req req;
595 1.1 garbled
596 1.1 garbled READ_ONLY;
597 1.1 garbled READ_REQ(0x11, 1, 3);
598 1.1 garbled i = (req.rspbuf[0]<<8) + req.rspbuf[1];
599 1.1 garbled table[num].value = i&0x0001 ? 1 : 0;
600 1.1 garbled return(1);
601 1.1 garbled }
602 1.1 garbled
603 1.1 garbled /* ARGSUSED */
604 1.1 garbled FUNC(hw_poweroncycles)
605 1.1 garbled {
606 1.1 garbled struct tctrl_req req;
607 1.1 garbled
608 1.1 garbled READ_ONLY;
609 1.1 garbled READ_REQ(0x09, 1, 5);
610 1.1 garbled table[num].value = (req.rspbuf[0]<<24)+(req.rspbuf[1]<<16)+
611 1.1 garbled (req.rspbuf[2]<<8)+req.rspbuf[3];
612 1.1 garbled return(1);
613 1.1 garbled }
614 1.1 garbled
615 1.1 garbled /* ARGSUSED */
616 1.1 garbled FUNC(hw_poweronseconds)
617 1.1 garbled {
618 1.1 garbled struct tctrl_req req;
619 1.1 garbled
620 1.1 garbled READ_ONLY;
621 1.1 garbled READ_REQ(0x0a, 1, 5);
622 1.1 garbled table[num].value = (req.rspbuf[0]<<24)+(req.rspbuf[1]<<16)+
623 1.1 garbled (req.rspbuf[2]<<8)+req.rspbuf[3];
624 1.1 garbled return(1);
625 1.1 garbled }
626 1.1 garbled
627 1.1 garbled /* ARGSUSED */
628 1.1 garbled FUNC(hw_microcontroller_version)
629 1.1 garbled {
630 1.1 garbled char *bufp, buf[BUFSIZ];
631 1.1 garbled struct tctrl_req req;
632 1.1 garbled
633 1.1 garbled READ_ONLY;
634 1.1 garbled READ_REQ(0x04, 1, 3);
635 1.1 garbled bufp = buf;
636 1.1 garbled sprintf(bufp, "%d%d", req.rspbuf[0]*1000, req.rspbuf[1]*10);
637 1.1 garbled table[num].value = atoi(strdup(bufp));
638 1.1 garbled return(1);
639 1.1 garbled }
640 1.1 garbled
641 1.1 garbled
642 1.1 garbled /* ARGSUSED */
643 1.1 garbled FUNC(hw_version)
644 1.1 garbled {
645 1.1 garbled char *bufp, buf[BUFSIZ];
646 1.1 garbled struct tctrl_req req;
647 1.1 garbled
648 1.1 garbled READ_ONLY;
649 1.1 garbled READ_REQ(0x03, 1, 3);
650 1.1 garbled bufp = buf;
651 1.1 garbled sprintf(bufp, "%d%d", req.rspbuf[0]*1000, req.rspbuf[1]*10);
652 1.1 garbled table[num].value = atoi(strdup(bufp));
653 1.1 garbled return(1);
654 1.1 garbled }
655 1.1 garbled
656 1.1 garbled void
657 1.1 garbled usage()
658 1.1 garbled {
659 1.1 garbled (void)fprintf(stderr,
660 1.1 garbled "usage: tadpolectl [-n] name ...\n"
661 1.1 garbled " tadpolectl [-n] -w name=value\n"
662 1.1 garbled " tadpolectl [-n] -a\n");
663 1.1 garbled exit(1);
664 1.1 garbled }
665 1.1 garbled
666 1.1 garbled static void
667 1.1 garbled parse(string)
668 1.1 garbled char *string;
669 1.1 garbled {
670 1.1 garbled char *cp, buf[BUFSIZ];
671 1.1 garbled int newval = 0;
672 1.1 garbled int i, j, ret;
673 1.1 garbled
674 1.1 garbled string = dashdot(string);
675 1.1 garbled snprintf(buf, (size_t)BUFSIZ, "%s", string);
676 1.1 garbled if ((cp = strchr(string, '=')) != NULL) {
677 1.1 garbled if (!wflag)
678 1.1 garbled errx(2, "Must specify -w to set variables");
679 1.1 garbled *strchr(buf, '=') = '\0';
680 1.1 garbled *cp++ = '\0';
681 1.1 garbled while (isspace((unsigned char) *cp))
682 1.1 garbled cp++;
683 1.1 garbled newval = atoi(cp);
684 1.1 garbled }
685 1.1 garbled for (j=0,i=-1; j < NUM_MIBS; j++) {
686 1.1 garbled if (strcmp(string, table[j].mib) == 0) {
687 1.1 garbled i = j;
688 1.1 garbled break;
689 1.1 garbled }
690 1.1 garbled }
691 1.1 garbled if (i == -1)
692 1.1 garbled errx(2, "Named value does not exist");
693 1.1 garbled
694 1.1 garbled if (wflag) {
695 1.1 garbled ret = (*table[i].funcptr)(0, newval, i);
696 1.1 garbled if (!ret)
697 1.1 garbled errx(2, "Cannot modify this value");
698 1.1 garbled } else
699 1.1 garbled ret = (*table[i].funcptr)(1, 0, i);
700 1.1 garbled if (nflag)
701 1.1 garbled printf("%d\n", table[i].value);
702 1.1 garbled else
703 1.1 garbled printf("%s = %d\n", dashdot(table[i].mib), table[i].value);
704 1.1 garbled }
705 1.1 garbled
706 1.1 garbled char *
707 1.1 garbled dashdot(string)
708 1.1 garbled char *string;
709 1.1 garbled {
710 1.1 garbled char *p;
711 1.1 garbled char *save;
712 1.1 garbled
713 1.1 garbled p = strdup(string);
714 1.1 garbled save = p;
715 1.1 garbled
716 1.1 garbled for (; (*p = *string) != '\0'; ++p, ++string) {
717 1.1 garbled if (*p == '.')
718 1.1 garbled *p = '_';
719 1.1 garbled else if (*p == '_')
720 1.1 garbled *p = '.';
721 1.1 garbled }
722 1.1 garbled return(save);
723 1.1 garbled }
724 1.1 garbled
725 1.1 garbled int
726 1.1 garbled main(argc, argv)
727 1.1 garbled int argc;
728 1.1 garbled char *argv[];
729 1.1 garbled {
730 1.1 garbled extern int optind;
731 1.1 garbled int ch, j;
732 1.1 garbled
733 1.1 garbled while ((ch = getopt(argc, argv, "anw")) != -1) {
734 1.1 garbled switch (ch) {
735 1.1 garbled
736 1.1 garbled case 'a':
737 1.1 garbled aflag = 1;
738 1.1 garbled break;
739 1.1 garbled case 'n':
740 1.1 garbled nflag = 1;
741 1.1 garbled break;
742 1.1 garbled case 'w':
743 1.1 garbled wflag = 1;
744 1.1 garbled break;
745 1.1 garbled default:
746 1.1 garbled usage();
747 1.1 garbled }
748 1.1 garbled }
749 1.1 garbled argc -= optind;
750 1.1 garbled argv += optind;
751 1.1 garbled
752 1.3 jdc if ((dev = open(TCTRL_DEV, O_RDONLY, NULL)) == -1)
753 1.3 jdc err(1, "%s", TCTRL_DEV);
754 1.1 garbled
755 1.1 garbled if (aflag) {
756 1.1 garbled for (j=0; j < NUM_MIBS; j++) {
757 1.1 garbled (void)(*table[j].funcptr)(1, 0, j);
758 1.1 garbled if (nflag)
759 1.1 garbled printf("%d\n", table[j].value);
760 1.1 garbled else
761 1.1 garbled printf("%s = %d\n", dashdot(table[j].mib),
762 1.1 garbled table[j].value);
763 1.1 garbled }
764 1.1 garbled return(0);
765 1.1 garbled }
766 1.1 garbled if (argc == 0)
767 1.1 garbled usage();
768 1.1 garbled while (argc-- > 0)
769 1.1 garbled parse(*argv++);
770 1.1 garbled return(0);
771 1.1 garbled }
772