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