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