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