Home | History | Annotate | Line # | Download | only in vr
vrpiu.c revision 1.13
      1  1.13      sato /*	$NetBSD: vrpiu.c,v 1.13 2001/06/14 08:43:41 sato Exp $	*/
      2   1.1  takemura 
      3   1.1  takemura /*
      4   1.1  takemura  * Copyright (c) 1999 Shin Takemura All rights reserved.
      5   1.6      sato  * Copyright (c) 2000 SATO Kazumi, All rights reserved.
      6   1.6      sato  * Copyright (c) 1999,2000 PocketBSD Project. All rights reserved.
      7   1.1  takemura  *
      8   1.1  takemura  * Redistribution and use in source and binary forms, with or without
      9   1.1  takemura  * modification, are permitted provided that the following conditions
     10   1.1  takemura  * are met:
     11   1.1  takemura  * 1. Redistributions of source code must retain the above copyright
     12   1.1  takemura  *    notice, this list of conditions and the following disclaimer.
     13   1.1  takemura  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1  takemura  *    notice, this list of conditions and the following disclaimer in the
     15   1.1  takemura  *    documentation and/or other materials provided with the distribution.
     16   1.1  takemura  *
     17   1.1  takemura  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     18   1.1  takemura  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19   1.1  takemura  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20   1.1  takemura  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     21   1.1  takemura  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22   1.1  takemura  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23   1.1  takemura  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24   1.1  takemura  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25   1.1  takemura  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26   1.1  takemura  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27   1.1  takemura  * SUCH DAMAGE.
     28   1.1  takemura  *
     29   1.1  takemura  */
     30   1.1  takemura 
     31   1.6      sato /*
     32   1.6      sato  * A/D polling part written by SATO Kazumi.
     33   1.6      sato  */
     34   1.6      sato 
     35   1.1  takemura #include <sys/param.h>
     36   1.1  takemura #include <sys/systm.h>
     37   1.1  takemura #include <sys/device.h>
     38   1.1  takemura #include <sys/kernel.h>
     39   1.6      sato #include <sys/callout.h>
     40   1.6      sato #include <sys/boot_flag.h>
     41   1.1  takemura 
     42   1.1  takemura #include <dev/wscons/wsconsio.h>
     43   1.1  takemura #include <dev/wscons/wsmousevar.h>
     44   1.1  takemura 
     45   1.1  takemura #include <machine/bus.h>
     46   1.5      matt #include <machine/platid.h>
     47   1.5      matt #include <machine/platid_mask.h>
     48   1.6      sato #include <machine/config_hook.h>
     49   1.1  takemura 
     50  1.11       uch #include <dev/hpc/tpcalibvar.h>
     51  1.11       uch 
     52   1.6      sato #include <hpcmips/hpcmips/machdep.h>
     53   1.1  takemura #include <hpcmips/vr/vripvar.h>
     54   1.1  takemura #include <hpcmips/vr/cmureg.h>
     55   1.1  takemura #include <hpcmips/vr/vrpiuvar.h>
     56   1.1  takemura #include <hpcmips/vr/vrpiureg.h>
     57   1.1  takemura 
     58   1.1  takemura /*
     59   1.1  takemura  * contant and macro definitions
     60   1.1  takemura  */
     61   1.1  takemura #define VRPIUDEBUG
     62   1.1  takemura #ifdef VRPIUDEBUG
     63   1.1  takemura int	vrpiu_debug = 0;
     64   1.1  takemura #define	DPRINTF(arg) if (vrpiu_debug) printf arg;
     65   1.6      sato #define	VPRINTF(arg) if (bootverbose || vrpiu_debug) printf arg;
     66   1.1  takemura #else
     67   1.1  takemura #define	DPRINTF(arg)
     68   1.6      sato #define	VPRINTF(arg) if (bootverbose) printf arg;
     69   1.1  takemura #endif
     70   1.1  takemura 
     71   1.6      sato #ifndef VRPIU_AD_POLL_INTERVAL
     72   1.6      sato #define VRPIU_AD_POLL_INTERVAL	60	/* interval is 60 sec */
     73   1.6      sato #endif /* VRPIU_AD_POLL_INTERTVAL */
     74   1.8  takemura 
     75   1.8  takemura #define	PIUSIVL_SCANINTVAL_MIN	333			/* 10msec	*/
     76   1.8  takemura #define	PIUSIVL_SCANINTVAL_MAX	PIUSIVL_SCANINTVAL_MASK	/* 60msec	*/
     77  1.10  takemura #define VRPIU_TP_SCAN_TIMEOUT	(hz/10)		/* timeout is 100msec	*/
     78   1.8  takemura 
     79   1.8  takemura #define TP_INTR	(PIUINT_ALLINTR & ~PIUINT_PADADPINTR)
     80   1.8  takemura #define AD_INTR	(PIUINT_PADADPINTR)
     81   1.8  takemura 
     82   1.1  takemura /*
     83   1.1  takemura  * data types
     84   1.1  takemura  */
     85   1.1  takemura /* struct vrpiu_softc is defined in vrpiuvar.h */
     86   1.1  takemura 
     87   1.1  takemura /*
     88   1.1  takemura  * function prototypes
     89   1.1  takemura  */
     90   1.1  takemura static int	vrpiumatch __P((struct device *, struct cfdata *, void *));
     91   1.1  takemura static void	vrpiuattach __P((struct device *, struct device *, void *));
     92   1.1  takemura 
     93   1.1  takemura static void	vrpiu_write __P((struct vrpiu_softc *, int, unsigned short));
     94   1.1  takemura static u_short	vrpiu_read __P((struct vrpiu_softc *, int));
     95   1.1  takemura 
     96   1.1  takemura static int	vrpiu_intr __P((void *));
     97   1.6      sato static void	vrpiu_tp_intr __P((struct vrpiu_softc *));
     98   1.6      sato static void	vrpiu_ad_intr __P((struct vrpiu_softc *));
     99   1.1  takemura #ifdef DEBUG
    100   1.1  takemura static void	vrpiu_dump_cntreg __P((unsigned int cmd));
    101   1.1  takemura #endif
    102   1.1  takemura 
    103   1.6      sato static int	vrpiu_tp_enable __P((void *));
    104   1.6      sato static int	vrpiu_tp_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
    105   1.6      sato static void	vrpiu_tp_disable __P((void *));
    106  1.10  takemura static void	vrpiu_tp_up __P((struct vrpiu_softc *));
    107  1.10  takemura static void	vrpiu_tp_timeout __P((void *));
    108   1.6      sato int		vrpiu_ad_enable __P((void *));
    109   1.6      sato void		vrpiu_ad_disable __P((void *));
    110   1.6      sato static void	vrpiu_start_powerstate __P((void *));
    111   1.6      sato static void	vrpiu_calc_powerstate __P((struct vrpiu_softc *));
    112   1.6      sato static void	vrpiu_power __P((int, void *));
    113   1.8  takemura static u_int	scan_interval __P((u_int data));
    114   1.1  takemura 
    115   1.1  takemura /* mra is defined in mra.c */
    116   1.1  takemura int mra_Y_AX1_BX2_C __P((int *y, int ys, int *x1, int x1s, int *x2, int x2s,
    117   1.1  takemura 			 int n, int scale, int *a, int *b, int *c));
    118   1.1  takemura 
    119   1.1  takemura /*
    120   1.1  takemura  * static or global variables
    121   1.1  takemura  */
    122   1.1  takemura struct cfattach vrpiu_ca = {
    123   1.1  takemura 	sizeof(struct vrpiu_softc), vrpiumatch, vrpiuattach
    124   1.1  takemura };
    125   1.1  takemura 
    126   1.1  takemura const struct wsmouse_accessops vrpiu_accessops = {
    127   1.6      sato 	vrpiu_tp_enable,
    128   1.6      sato 	vrpiu_tp_ioctl,
    129   1.6      sato 	vrpiu_tp_disable,
    130   1.1  takemura };
    131   1.1  takemura 
    132   1.6      sato int vrpiu_ad_poll_interval = VRPIU_AD_POLL_INTERVAL;
    133   1.6      sato 
    134   1.1  takemura /*
    135   1.1  takemura  * function definitions
    136   1.1  takemura  */
    137   1.1  takemura static inline void
    138   1.1  takemura vrpiu_write(sc, port, val)
    139   1.1  takemura 	struct vrpiu_softc *sc;
    140   1.1  takemura 	int port;
    141   1.1  takemura 	unsigned short val;
    142   1.1  takemura {
    143   1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, port, val);
    144   1.1  takemura }
    145   1.1  takemura 
    146   1.1  takemura static inline u_short
    147   1.1  takemura vrpiu_read(sc, port)
    148   1.1  takemura 	struct vrpiu_softc *sc;
    149   1.1  takemura 	int port;
    150   1.1  takemura {
    151   1.1  takemura 	return bus_space_read_2(sc->sc_iot, sc->sc_ioh, port);
    152   1.1  takemura }
    153   1.1  takemura 
    154   1.1  takemura static int
    155   1.1  takemura vrpiumatch(parent, cf, aux)
    156   1.1  takemura 	struct device *parent;
    157   1.1  takemura 	struct cfdata *cf;
    158   1.1  takemura 	void *aux;
    159   1.1  takemura {
    160   1.1  takemura 	return 1;
    161   1.1  takemura }
    162   1.1  takemura 
    163   1.1  takemura static void
    164   1.1  takemura vrpiuattach(parent, self, aux)
    165   1.1  takemura 	struct device *parent;
    166   1.1  takemura 	struct device *self;
    167   1.1  takemura 	void *aux;
    168   1.1  takemura {
    169   1.1  takemura 	struct vrpiu_softc *sc = (struct vrpiu_softc *)self;
    170   1.1  takemura 	struct vrip_attach_args *va = aux;
    171   1.1  takemura 	struct wsmousedev_attach_args wsmaa;
    172   1.1  takemura 
    173   1.1  takemura 	bus_space_tag_t iot = va->va_iot;
    174   1.1  takemura 	bus_space_handle_t ioh;
    175   1.1  takemura 
    176   1.1  takemura 	if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
    177   1.9  takemura 	    printf(": can't map bus space\n");
    178   1.9  takemura 	    return;
    179   1.1  takemura 	}
    180   1.1  takemura 
    181   1.1  takemura 	sc->sc_iot = iot;
    182   1.1  takemura 	sc->sc_ioh = ioh;
    183   1.1  takemura 	sc->sc_vrip = va->va_vc;
    184   1.1  takemura 
    185   1.8  takemura 	sc->sc_interval = scan_interval(WSMOUSE_RES_DEFAULT);
    186   1.8  takemura 
    187   1.1  takemura 	/*
    188   1.1  takemura 	 * disable device until vrpiu_enable called
    189   1.1  takemura 	 */
    190   1.6      sato 	sc->sc_tpstat = VRPIU_TP_STAT_DISABLE;
    191   1.1  takemura 
    192  1.10  takemura 	/* initialize touch panel timeout structure	*/
    193  1.10  takemura 	callout_init(&sc->sc_tptimeout);
    194  1.10  takemura 
    195  1.10  takemura 	/* initialize calibration context	*/
    196   1.3  takemura 	tpcalib_init(&sc->sc_tpcalib);
    197   1.1  takemura #if 1
    198   1.1  takemura 	/*
    199   1.1  takemura 	 * XXX, calibrate parameters
    200   1.1  takemura 	 */
    201   1.1  takemura 	{
    202   1.9  takemura 	    int i;
    203   1.9  takemura 	    static const struct {
    204   1.9  takemura 		platid_mask_t *mask;
    205   1.9  takemura 		struct wsmouse_calibcoords coords;
    206   1.9  takemura 	    } calibrations[] = {
    207  1.12      sato 		{ &platid_mask_MACH_NEC_MCR_700,
    208  1.12      sato 		  { 0, 0, 799, 599,
    209  1.12      sato 		    4,
    210  1.12      sato 		    { { 115,  80,   0,   0 },
    211  1.12      sato 		      { 115, 966,   0, 599 },
    212  1.12      sato 		      { 912,  80, 799,   0 },
    213  1.12      sato 		      { 912, 966, 799, 599 } } } },
    214  1.12      sato 
    215   1.9  takemura 		{ &platid_mask_MACH_NEC_MCR_700A,
    216  1.12      sato 		  { 0, 0, 799, 599,
    217  1.12      sato 		    4,
    218  1.12      sato 		    { { 115,  80,   0,   0 },
    219  1.12      sato 		      { 115, 966,   0, 599 },
    220  1.12      sato 		      { 912,  80, 799,   0 },
    221  1.12      sato 		      { 912, 966, 799, 599 } } } },
    222  1.12      sato 
    223  1.12      sato 		{ &platid_mask_MACH_NEC_MCR_730,
    224   1.9  takemura 		  { 0, 0, 799, 599,
    225   1.9  takemura 		    4,
    226   1.9  takemura 		    { { 115,  80,   0,   0 },
    227   1.9  takemura 		      { 115, 966,   0, 599 },
    228   1.9  takemura 		      { 912,  80, 799,   0 },
    229   1.9  takemura 		      { 912, 966, 799, 599 } } } },
    230   1.9  takemura 
    231   1.9  takemura 		{ NULL,		/* samples got on my MC-R500 */
    232   1.9  takemura 		  { 0, 0, 639, 239,
    233   1.9  takemura 		    5,
    234   1.9  takemura 		    { { 502, 486, 320, 120 },
    235   1.9  takemura 		      {  55, 109,   0,   0 },
    236   1.9  takemura 		      {  54, 913,   0, 239 },
    237   1.9  takemura 		      { 973, 924, 639, 239 },
    238   1.9  takemura 		      { 975, 123, 639,   0 } } } },
    239   1.9  takemura 	    };
    240   1.9  takemura 	    for (i = 0; ; i++) {
    241   1.9  takemura 		if (calibrations[i].mask == NULL
    242   1.9  takemura 		    || platid_match(&platid, calibrations[i].mask))
    243   1.9  takemura 		    break;
    244   1.9  takemura 	    }
    245   1.9  takemura 	    tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
    246   1.9  takemura 			  (caddr_t)&calibrations[i].coords, 0, 0);
    247   1.1  takemura 	}
    248   1.1  takemura #endif
    249   1.1  takemura 
    250   1.1  takemura 	/* install interrupt handler and enable interrupt */
    251   1.1  takemura 	if (!(sc->sc_handler =
    252   1.9  takemura 	    vrip_intr_establish(va->va_vc, va->va_intr, IPL_TTY,
    253   1.9  takemura 				vrpiu_intr, sc))) {
    254   1.9  takemura 	    printf (": can't map interrupt line.\n");
    255   1.9  takemura 	    return;
    256   1.1  takemura 	}
    257   1.1  takemura 
    258   1.1  takemura 	/* mask level2 interrupt, stop scan sequencer and mask clock to piu */
    259   1.6      sato 	vrpiu_tp_disable(sc);
    260   1.1  takemura 
    261   1.1  takemura 	printf("\n");
    262   1.1  takemura 
    263   1.1  takemura 	wsmaa.accessops = &vrpiu_accessops;
    264   1.1  takemura 	wsmaa.accesscookie = sc;
    265   1.1  takemura 
    266   1.1  takemura 	/*
    267   1.1  takemura 	 * attach the wsmouse
    268   1.1  takemura 	 */
    269   1.1  takemura 	sc->sc_wsmousedev = config_found(self, &wsmaa, wsmousedevprint);
    270   1.6      sato 
    271   1.6      sato 	/*
    272   1.6      sato 	 * power management events
    273   1.6      sato 	 */
    274   1.6      sato 	sc->sc_power_hook = powerhook_establish(vrpiu_power, sc);
    275   1.6      sato 
    276   1.6      sato 	/*
    277   1.6      sato 	 * init A/D port polling.
    278   1.6      sato 	 */
    279   1.6      sato 	sc->sc_battery.n_values = 3;
    280   1.6      sato 	sc->sc_battery.value[0] = -1;
    281   1.6      sato 	sc->sc_battery.value[1] = -1;
    282   1.6      sato 	sc->sc_battery.value[2] = -1;
    283   1.6      sato 	sc->sc_battery.nextpoll = hz*vrpiu_ad_poll_interval;
    284   1.6      sato 	callout_init(&sc->sc_adpoll);
    285   1.9  takemura 	callout_reset(&sc->sc_adpoll, hz, vrpiu_start_powerstate, sc);
    286   1.1  takemura }
    287   1.1  takemura 
    288   1.8  takemura /*
    289   1.8  takemura  * calculate interval value
    290   1.8  takemura  *  input: WSMOUSE_RES_MIN - WSMOUSE_RES_MAX
    291   1.8  takemura  * output: value for PIUSIVL_REG
    292   1.8  takemura  */
    293   1.8  takemura static u_int
    294   1.8  takemura scan_interval(u_int data)
    295   1.8  takemura {
    296   1.8  takemura 	int scale;
    297   1.8  takemura 
    298   1.8  takemura 	if (data < WSMOUSE_RES_MIN)
    299   1.9  takemura 	    data = WSMOUSE_RES_MIN;
    300   1.8  takemura 
    301   1.8  takemura 	if (WSMOUSE_RES_MAX < data)
    302   1.9  takemura 	    data = WSMOUSE_RES_MAX;
    303   1.8  takemura 
    304   1.8  takemura 	scale = WSMOUSE_RES_MAX - WSMOUSE_RES_MIN;
    305   1.8  takemura 	data += WSMOUSE_RES_MIN;
    306   1.8  takemura 
    307   1.8  takemura 	return PIUSIVL_SCANINTVAL_MIN +
    308   1.8  takemura 	    (PIUSIVL_SCANINTVAL_MAX - PIUSIVL_SCANINTVAL_MIN) *
    309   1.8  takemura 	    (scale - data) / scale;
    310   1.8  takemura }
    311   1.8  takemura 
    312   1.1  takemura int
    313   1.6      sato vrpiu_ad_enable(v)
    314   1.1  takemura 	void *v;
    315   1.1  takemura {
    316   1.1  takemura 	struct vrpiu_softc *sc = v;
    317   1.1  takemura 	int s;
    318   1.1  takemura 	unsigned int cnt;
    319   1.1  takemura 
    320   1.8  takemura 	DPRINTF(("%s(%d): vrpiu_ad_enable(): interval=0x%03x\n",
    321   1.9  takemura 		 __FILE__, __LINE__, sc->sc_interval));
    322   1.6      sato 	if (sc->sc_adstat != VRPIU_AD_STAT_DISABLE)
    323   1.9  takemura 	    return EBUSY;
    324   1.1  takemura 
    325   1.1  takemura 	/* supply clock to PIU */
    326   1.1  takemura 	__vrcmu_supply(CMUMSKPIU, 1);
    327   1.1  takemura 
    328   1.8  takemura 	/* set scan interval */
    329   1.8  takemura 	vrpiu_write(sc, PIUSIVL_REG_W, sc->sc_interval);
    330   1.1  takemura 
    331   1.1  takemura 	s = spltty();
    332   1.1  takemura 
    333   1.1  takemura 	/* clear interrupt status */
    334   1.8  takemura 	vrpiu_write(sc, PIUINT_REG_W, AD_INTR);
    335   1.1  takemura 
    336   1.1  takemura 	/* Disable -> Standby */
    337   1.1  takemura 	cnt = PIUCNT_PIUPWR |
    338   1.1  takemura 		PIUCNT_PIUMODE_COORDINATE |
    339   1.1  takemura 		PIUCNT_PADATSTART | PIUCNT_PADATSTOP;
    340   1.1  takemura 	vrpiu_write(sc, PIUCNT_REG_W, cnt);
    341   1.1  takemura 
    342   1.6      sato 	/* Level2 interrupt register setting */
    343   1.8  takemura 	vrip_intr_setmask2(sc->sc_vrip, sc->sc_handler, AD_INTR, 1);
    344   1.6      sato 
    345   1.1  takemura 	/* save pen status, touch or release */
    346   1.1  takemura 	cnt = vrpiu_read(sc, PIUCNT_REG_W);
    347   1.1  takemura 
    348   1.6      sato 	/*
    349   1.6      sato 	 * Enable scan sequencer operation
    350   1.6      sato 	 * Standby -> WaitPenTouch
    351   1.6      sato 	 */
    352   1.6      sato 	cnt |= PIUCNT_PIUSEQEN;
    353   1.6      sato 	vrpiu_write(sc, PIUCNT_REG_W, cnt);
    354   1.6      sato 
    355   1.6      sato 	sc->sc_adstat = VRPIU_AD_STAT_ENABLE;
    356   1.6      sato 
    357   1.6      sato 	splx(s);
    358   1.6      sato 
    359   1.6      sato 	return 0;
    360   1.6      sato }
    361   1.6      sato 
    362   1.6      sato void
    363   1.6      sato vrpiu_ad_disable(v)
    364   1.6      sato 	void *v;
    365   1.6      sato {
    366   1.6      sato 	struct vrpiu_softc *sc = v;
    367   1.6      sato 
    368   1.6      sato 	DPRINTF(("%s(%d): vrpiu_ad_disable()\n", __FILE__, __LINE__));
    369   1.6      sato 
    370   1.6      sato 	/* Set level2 interrupt register to mask interrupts */
    371   1.8  takemura 	vrip_intr_setmask2(sc->sc_vrip, sc->sc_handler, AD_INTR, 0);
    372   1.6      sato 
    373   1.6      sato 	sc->sc_adstat = VRPIU_AD_STAT_DISABLE;
    374   1.6      sato 
    375   1.6      sato 	if (sc->sc_tpstat == VRPIU_TP_STAT_DISABLE){
    376   1.9  takemura 	    /* Disable scan sequencer operation and power off */
    377   1.9  takemura 	    vrpiu_write(sc, PIUCNT_REG_W, 0);
    378   1.6      sato 
    379   1.9  takemura 	    /* mask clock to PIU */
    380  1.13      sato 	    __vrcmu_supply(CMUMSKPIU, 0);
    381   1.6      sato 	}
    382   1.6      sato }
    383   1.6      sato 
    384   1.6      sato int
    385   1.6      sato vrpiu_tp_enable(v)
    386   1.6      sato 	void *v;
    387   1.6      sato {
    388   1.6      sato 	struct vrpiu_softc *sc = v;
    389   1.6      sato 	int s;
    390   1.6      sato 	unsigned int cnt;
    391   1.6      sato 
    392   1.8  takemura 	DPRINTF(("%s(%d): vrpiu_tp_enable(): interval=0x%03x\n",
    393   1.9  takemura 		 __FILE__, __LINE__, sc->sc_interval));
    394   1.6      sato 	if (sc->sc_tpstat != VRPIU_TP_STAT_DISABLE)
    395   1.9  takemura 	    return EBUSY;
    396   1.6      sato 
    397   1.6      sato 	/* supply clock to PIU */
    398   1.6      sato 	__vrcmu_supply(CMUMSKPIU, 1);
    399   1.6      sato 
    400   1.8  takemura 	/* set scan interval */
    401   1.8  takemura 	vrpiu_write(sc, PIUSIVL_REG_W, sc->sc_interval);
    402   1.6      sato 
    403   1.6      sato 	s = spltty();
    404   1.6      sato 
    405   1.6      sato 	/* clear interrupt status */
    406   1.8  takemura 	vrpiu_write(sc, PIUINT_REG_W, TP_INTR);
    407   1.6      sato 
    408   1.6      sato 	/* Disable -> Standby */
    409   1.6      sato 	cnt = PIUCNT_PIUPWR |
    410   1.6      sato 		PIUCNT_PIUMODE_COORDINATE |
    411   1.6      sato 		PIUCNT_PADATSTART | PIUCNT_PADATSTOP;
    412   1.6      sato 	vrpiu_write(sc, PIUCNT_REG_W, cnt);
    413   1.6      sato 
    414   1.1  takemura 	/* Level2 interrupt register setting */
    415   1.8  takemura 	vrip_intr_setmask2(sc->sc_vrip, sc->sc_handler, TP_INTR, 1);
    416   1.6      sato 
    417   1.6      sato 	/* save pen status, touch or release */
    418   1.6      sato 	cnt = vrpiu_read(sc, PIUCNT_REG_W);
    419   1.1  takemura 
    420   1.1  takemura 	/*
    421   1.1  takemura 	 * Enable scan sequencer operation
    422   1.1  takemura 	 * Standby -> WaitPenTouch
    423   1.1  takemura 	 */
    424   1.1  takemura 	cnt |= PIUCNT_PIUSEQEN;
    425   1.1  takemura 	vrpiu_write(sc, PIUCNT_REG_W, cnt);
    426   1.1  takemura 
    427   1.1  takemura 	/* transit status DISABLE -> TOUCH or RELEASE */
    428   1.6      sato 	sc->sc_tpstat = (cnt & PIUCNT_PENSTC) ?
    429   1.6      sato 		VRPIU_TP_STAT_TOUCH : VRPIU_TP_STAT_RELEASE;
    430   1.1  takemura 
    431   1.1  takemura 	splx(s);
    432   1.1  takemura 
    433   1.1  takemura 	return 0;
    434   1.1  takemura }
    435   1.1  takemura 
    436   1.1  takemura void
    437   1.6      sato vrpiu_tp_disable(v)
    438   1.1  takemura 	void *v;
    439   1.1  takemura {
    440   1.1  takemura 	struct vrpiu_softc *sc = v;
    441   1.1  takemura 
    442   1.6      sato 	DPRINTF(("%s(%d): vrpiu_tp_disable()\n", __FILE__, __LINE__));
    443   1.1  takemura 
    444   1.1  takemura 	/* Set level2 interrupt register to mask interrupts */
    445   1.8  takemura 	vrip_intr_setmask2(sc->sc_vrip, sc->sc_handler, TP_INTR, 0);
    446   1.1  takemura 
    447   1.6      sato 	sc->sc_tpstat = VRPIU_TP_STAT_DISABLE;
    448   1.1  takemura 
    449   1.6      sato 	if (sc->sc_adstat == VRPIU_AD_STAT_DISABLE){
    450   1.9  takemura 	    /* Disable scan sequencer operation and power off */
    451   1.9  takemura 	    vrpiu_write(sc, PIUCNT_REG_W, 0);
    452   1.1  takemura 
    453   1.9  takemura 	    /* mask clock to PIU */
    454  1.13      sato 	    __vrcmu_supply(CMUMSKPIU, 0);
    455   1.6      sato 	}
    456   1.1  takemura }
    457   1.1  takemura 
    458   1.1  takemura int
    459   1.6      sato vrpiu_tp_ioctl(v, cmd, data, flag, p)
    460   1.1  takemura 	void *v;
    461   1.1  takemura 	u_long cmd;
    462   1.1  takemura 	caddr_t data;
    463   1.1  takemura 	int flag;
    464   1.1  takemura 	struct proc *p;
    465   1.1  takemura {
    466   1.1  takemura 	struct vrpiu_softc *sc = v;
    467   1.1  takemura 
    468   1.6      sato 	DPRINTF(("%s(%d): vrpiu_tp_ioctl(%08lx)\n", __FILE__, __LINE__, cmd));
    469   1.1  takemura 
    470   1.1  takemura 	switch (cmd) {
    471   1.1  takemura 	case WSMOUSEIO_GTYPE:
    472   1.9  takemura 	    *(u_int *)data = WSMOUSE_TYPE_TPANEL;
    473   1.9  takemura 	    break;
    474   1.1  takemura 
    475   1.1  takemura 	case WSMOUSEIO_SRES:
    476   1.8  takemura 	    {
    477   1.8  takemura 		int tp_enable;
    478   1.8  takemura 		int ad_enable;
    479   1.8  takemura 
    480   1.8  takemura 		tp_enable = (sc->sc_tpstat != VRPIU_TP_STAT_DISABLE);
    481   1.8  takemura 		ad_enable = (sc->sc_adstat != VRPIU_AD_STAT_DISABLE);
    482   1.8  takemura 
    483   1.8  takemura 		if (tp_enable)
    484   1.9  takemura 		    vrpiu_tp_disable(sc);
    485   1.8  takemura 		if (ad_enable)
    486   1.9  takemura 		    vrpiu_ad_disable(sc);
    487   1.8  takemura 
    488   1.8  takemura 		sc->sc_interval = scan_interval(*(u_int *)data);
    489   1.8  takemura 		DPRINTF(("%s(%d): WSMOUSEIO_SRES: *data=%d, interval=0x%03x\n",
    490   1.8  takemura 		    __FILE__, __LINE__, *(u_int *)data, sc->sc_interval));
    491   1.8  takemura 
    492   1.8  takemura 		if (sc->sc_interval < PIUSIVL_SCANINTVAL_MIN)
    493   1.9  takemura 		    sc->sc_interval = PIUSIVL_SCANINTVAL_MIN;
    494   1.8  takemura 
    495   1.8  takemura 		if (PIUSIVL_SCANINTVAL_MAX < sc->sc_interval)
    496   1.9  takemura 		    sc->sc_interval = PIUSIVL_SCANINTVAL_MAX;
    497   1.8  takemura 
    498   1.8  takemura 		if (tp_enable)
    499   1.9  takemura 		    vrpiu_tp_enable(sc);
    500   1.8  takemura 		if (ad_enable)
    501   1.9  takemura 		     vrpiu_ad_enable(sc);
    502   1.8  takemura 	    }
    503   1.8  takemura 	    break;
    504   1.3  takemura 
    505   1.3  takemura 	case WSMOUSEIO_SCALIBCOORDS:
    506   1.3  takemura 	case WSMOUSEIO_GCALIBCOORDS:
    507   1.9  takemura             return tpcalib_ioctl(&sc->sc_tpcalib, cmd, data, flag, p);
    508   1.1  takemura 
    509   1.1  takemura 	default:
    510   1.9  takemura 	    return (-1);
    511   1.1  takemura 	}
    512   1.1  takemura 	return (0);
    513   1.1  takemura }
    514   1.1  takemura 
    515   1.1  takemura /*
    516   1.6      sato  * PIU AD interrupt handler.
    517   1.6      sato  */
    518   1.6      sato void
    519   1.6      sato vrpiu_ad_intr(sc)
    520   1.6      sato 	struct vrpiu_softc *sc;
    521   1.6      sato {
    522   1.6      sato 	unsigned int i;
    523   1.6      sato 	unsigned int intrstat;
    524   1.6      sato 
    525   1.6      sato 	intrstat = vrpiu_read(sc, PIUINT_REG_W);
    526   1.6      sato 
    527   1.6      sato 	if (sc->sc_adstat == VRPIU_AD_STAT_DISABLE) {
    528   1.9  takemura 	    /*
    529   1.9  takemura 	     * the device isn't enabled. just clear interrupt.
    530   1.9  takemura 	     */
    531   1.9  takemura 	    vrpiu_write(sc, PIUINT_REG_W, AD_INTR);
    532   1.9  takemura 	    return;
    533   1.6      sato 	}
    534   1.6      sato 
    535   1.6      sato 	if (intrstat & PIUINT_PADADPINTR) {
    536   1.9  takemura 	    sc->sc_battery.value[0] = (unsigned int)vrpiu_read(sc, PIUAB(0));
    537   1.9  takemura 	    sc->sc_battery.value[1] = (unsigned int)vrpiu_read(sc, PIUAB(1));
    538   1.9  takemura 	    sc->sc_battery.value[2] = (unsigned int)vrpiu_read(sc, PIUAB(2));
    539   1.6      sato 	}
    540   1.6      sato 
    541   1.6      sato 	if (intrstat & PIUINT_PADADPINTR) {
    542   1.9  takemura 	    for (i = 0; i < 3; i++) {
    543   1.9  takemura 		if (sc->sc_battery.value[i] & PIUAB_VALID)
    544   1.9  takemura 		    sc->sc_battery.value[i] &= PIUAB_PADDATA_MASK;
    545   1.9  takemura 		else
    546   1.9  takemura 		    sc->sc_battery.value[i] = 0;
    547   1.9  takemura 	    }
    548   1.9  takemura 	    vrpiu_calc_powerstate(sc);
    549   1.6      sato 	}
    550   1.8  takemura 	vrpiu_write(sc, PIUINT_REG_W, AD_INTR);
    551   1.6      sato 
    552   1.6      sato 	return;
    553   1.6      sato }
    554   1.6      sato /*
    555   1.6      sato  * PIU TP interrupt handler.
    556   1.1  takemura  */
    557   1.6      sato void
    558   1.6      sato vrpiu_tp_intr(sc)
    559   1.6      sato 	struct vrpiu_softc *sc;
    560   1.1  takemura {
    561   1.1  takemura 	unsigned int cnt, i;
    562   1.1  takemura 	unsigned int intrstat, page;
    563   1.1  takemura 	int tpx0, tpx1, tpy0, tpy1;
    564   1.1  takemura 	int x, y, xraw, yraw;
    565   1.1  takemura 
    566   1.1  takemura 	intrstat = vrpiu_read(sc, PIUINT_REG_W);
    567   1.1  takemura 
    568   1.6      sato 	if (sc->sc_tpstat == VRPIU_TP_STAT_DISABLE) {
    569   1.9  takemura 	    /*
    570   1.9  takemura 	     * the device isn't enabled. just clear interrupt.
    571   1.9  takemura 	     */
    572   1.9  takemura 	    vrpiu_write(sc, PIUINT_REG_W, intrstat & TP_INTR);
    573   1.9  takemura 	    return;
    574   1.1  takemura 	}
    575   1.1  takemura 
    576   1.1  takemura 	page = (intrstat & PIUINT_OVP) ? 1 : 0;
    577   1.1  takemura 	if (intrstat & (PIUINT_PADPAGE0INTR | PIUINT_PADPAGE1INTR)) {
    578   1.9  takemura 	    tpx0 = vrpiu_read(sc, PIUPB(page, 0));
    579   1.9  takemura 	    tpx1 = vrpiu_read(sc, PIUPB(page, 1));
    580   1.9  takemura 	    tpy0 = vrpiu_read(sc, PIUPB(page, 2));
    581   1.9  takemura 	    tpy1 = vrpiu_read(sc, PIUPB(page, 3));
    582   1.1  takemura 	}
    583   1.1  takemura 
    584   1.1  takemura 	if (intrstat & PIUINT_PADDLOSTINTR) {
    585   1.9  takemura 	    page = page ? 0 : 1;
    586   1.9  takemura 	    for (i = 0; i < 4; i++)
    587   1.9  takemura 		vrpiu_read(sc, PIUPB(page, i));
    588   1.1  takemura 	}
    589   1.1  takemura 
    590   1.1  takemura 	cnt = vrpiu_read(sc, PIUCNT_REG_W);
    591   1.1  takemura #ifdef DEBUG
    592   1.1  takemura 	if (vrpiu_debug)
    593   1.9  takemura 	    vrpiu_dump_cntreg(cnt);
    594   1.1  takemura #endif
    595   1.1  takemura 
    596   1.1  takemura 	/* clear interrupt status */
    597   1.8  takemura 	vrpiu_write(sc, PIUINT_REG_W, intrstat & TP_INTR);
    598   1.1  takemura 
    599   1.1  takemura #if 0
    600   1.1  takemura 	DPRINTF(("vrpiu_intr: OVP=%d", page));
    601   1.1  takemura 	if (intrstat & PIUINT_PADCMDINTR)
    602   1.9  takemura 	    DPRINTF((" CMD"));
    603   1.1  takemura 	if (intrstat & PIUINT_PADADPINTR)
    604   1.9  takemura 	    DPRINTF((" A/D"));
    605   1.1  takemura 	if (intrstat & PIUINT_PADPAGE1INTR)
    606   1.9  takemura 	    DPRINTF((" PAGE1"));
    607   1.1  takemura 	if (intrstat & PIUINT_PADPAGE0INTR)
    608   1.9  takemura 	    DPRINTF((" PAGE0"));
    609   1.1  takemura 	if (intrstat & PIUINT_PADDLOSTINTR)
    610   1.9  takemura 	    DPRINTF((" DLOST"));
    611   1.1  takemura 	if (intrstat & PIUINT_PENCHGINTR)
    612   1.9  takemura 	    DPRINTF((" PENCHG"));
    613   1.1  takemura 	DPRINTF(("\n"));
    614   1.1  takemura #endif
    615   1.1  takemura 	if (intrstat & (PIUINT_PADPAGE0INTR | PIUINT_PADPAGE1INTR)) {
    616  1.10  takemura 	    /*
    617  1.10  takemura 	     * just ignore scan data if status isn't Touch.
    618  1.10  takemura 	     */
    619  1.10  takemura 	    if (sc->sc_tpstat == VRPIU_TP_STAT_TOUCH) {
    620  1.10  takemura 		/* reset tp scan timeout	*/
    621  1.10  takemura 		callout_reset(&sc->sc_tptimeout, VRPIU_TP_SCAN_TIMEOUT,
    622  1.10  takemura 			      vrpiu_tp_timeout, sc);
    623  1.10  takemura 
    624  1.10  takemura 		if (!((tpx0 & PIUPB_VALID) && (tpx1 & PIUPB_VALID) &&
    625  1.10  takemura 		    (tpy0 & PIUPB_VALID) && (tpy1 & PIUPB_VALID))) {
    626  1.10  takemura 		    printf("vrpiu: internal error, data is not valid!\n");
    627  1.10  takemura 		} else {
    628  1.10  takemura 		    tpx0 &= PIUPB_PADDATA_MASK;
    629  1.10  takemura 		    tpx1 &= PIUPB_PADDATA_MASK;
    630  1.10  takemura 		    tpy0 &= PIUPB_PADDATA_MASK;
    631  1.10  takemura 		    tpy1 &= PIUPB_PADDATA_MASK;
    632   1.1  takemura #define ISVALID(n, c, m)	((c) - (m) < (n) && (n) < (c) + (m))
    633  1.10  takemura 		    if (ISVALID(tpx0 + tpx1, 1024, 200) &&
    634  1.10  takemura 			ISVALID(tpy0 + tpy1, 1024, 200)) {
    635   1.1  takemura #if 0
    636  1.10  takemura 			DPRINTF(("%04x %04x %04x %04x\n",
    637  1.10  takemura 				 tpx0, tpx1, tpy0, tpy1));
    638  1.10  takemura 			DPRINTF(("%3d %3d (%4d %4d)->", tpx0, tpy0,
    639  1.10  takemura 				 tpx0 + tpx1, tpy0 + tpy1));
    640   1.1  takemura #endif
    641  1.10  takemura 			xraw = tpy1 * 1024 / (tpy0 + tpy1);
    642  1.10  takemura 			yraw = tpx1 * 1024 / (tpx0 + tpx1);
    643  1.10  takemura 			DPRINTF(("%3d %3d", xraw, yraw));
    644  1.10  takemura 
    645  1.10  takemura 			tpcalib_trans(&sc->sc_tpcalib, xraw, yraw, &x, &y);
    646  1.10  takemura 
    647  1.10  takemura 			DPRINTF(("->%4d %4d", x, y));
    648  1.10  takemura 			wsmouse_input(sc->sc_wsmousedev,
    649  1.10  takemura 				      1, /* button 0 down */
    650  1.10  takemura 				      x, /* x */
    651  1.10  takemura 				      y, /* y */
    652  1.10  takemura 				      0, /* z */
    653  1.10  takemura 				      WSMOUSE_INPUT_ABSOLUTE_X |
    654  1.10  takemura 				      WSMOUSE_INPUT_ABSOLUTE_Y);
    655  1.10  takemura 			DPRINTF(("\n"));
    656  1.10  takemura 		    }
    657   1.4  takemura 		}
    658   1.9  takemura 	    }
    659   1.4  takemura 	}
    660   1.4  takemura 
    661   1.4  takemura 	if (cnt & PIUCNT_PENSTC) {
    662   1.9  takemura 	    if (sc->sc_tpstat == VRPIU_TP_STAT_RELEASE) {
    663   1.9  takemura 		/*
    664   1.9  takemura 		 * pen touch
    665   1.9  takemura 		 */
    666   1.9  takemura 		DPRINTF(("PEN TOUCH\n"));
    667   1.9  takemura 		sc->sc_tpstat = VRPIU_TP_STAT_TOUCH;
    668   1.9  takemura 		/*
    669   1.9  takemura 		 * We should not report button down event while
    670   1.9  takemura 		 * we don't know where it occur.
    671   1.9  takemura 		 */
    672  1.10  takemura 
    673  1.10  takemura 		/* set tp scan timeout	*/
    674  1.10  takemura 		callout_reset(&sc->sc_tptimeout, VRPIU_TP_SCAN_TIMEOUT,
    675  1.10  takemura 			      vrpiu_tp_timeout, sc);
    676   1.9  takemura 	    }
    677   1.4  takemura 	} else {
    678  1.10  takemura 	    vrpiu_tp_up(sc);
    679   1.1  takemura 	}
    680   1.1  takemura 
    681   1.1  takemura 	if (intrstat & PIUINT_PADDLOSTINTR) {
    682   1.9  takemura 	    cnt |= PIUCNT_PIUSEQEN;
    683   1.9  takemura 	    vrpiu_write(sc, PIUCNT_REG_W, cnt);
    684   1.1  takemura 	}
    685   1.1  takemura 
    686   1.6      sato 	return;
    687  1.10  takemura }
    688  1.10  takemura 
    689  1.10  takemura void
    690  1.10  takemura vrpiu_tp_up(sc)
    691  1.10  takemura 	struct vrpiu_softc *sc;
    692  1.10  takemura {
    693  1.10  takemura 	if (sc->sc_tpstat == VRPIU_TP_STAT_TOUCH) {
    694  1.10  takemura 	    /*
    695  1.10  takemura 	     * pen release
    696  1.10  takemura 	     */
    697  1.10  takemura 	    DPRINTF(("RELEASE\n"));
    698  1.10  takemura 	    sc->sc_tpstat = VRPIU_TP_STAT_RELEASE;
    699  1.10  takemura 
    700  1.10  takemura 	    /* clear tp scan timeout	*/
    701  1.10  takemura 	    callout_stop(&sc->sc_tptimeout);
    702  1.10  takemura 
    703  1.10  takemura 	    /* button 0 UP */
    704  1.10  takemura 	    wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, 0);
    705  1.10  takemura 	}
    706  1.10  takemura }
    707  1.10  takemura 
    708  1.10  takemura /* touch panel timeout handler */
    709  1.10  takemura void
    710  1.10  takemura vrpiu_tp_timeout(v)
    711  1.10  takemura 	void *v;
    712  1.10  takemura {
    713  1.10  takemura 	struct vrpiu_softc *sc = (struct vrpiu_softc *)v;
    714  1.10  takemura 
    715  1.10  takemura #ifdef VRPIUDEBUG
    716  1.10  takemura 	{
    717  1.10  takemura 	    unsigned int cnt = vrpiu_read(sc, PIUCNT_REG_W);
    718  1.10  takemura 	    DPRINTF(("TIMEOUT: stat=%s  reg=%s\n",
    719  1.10  takemura 		(sc->sc_tpstat == VRPIU_TP_STAT_TOUCH)?"touch":"release",
    720  1.10  takemura 		(cnt & PIUCNT_PENSTC)?"touch":"release"));
    721  1.10  takemura 	}
    722  1.10  takemura #endif
    723  1.10  takemura 	vrpiu_tp_up(sc);
    724   1.6      sato }
    725   1.6      sato 
    726   1.6      sato /*
    727   1.6      sato  * PIU interrupt handler.
    728   1.6      sato  */
    729   1.6      sato int
    730   1.6      sato vrpiu_intr(arg)
    731   1.6      sato 	void *arg;
    732   1.6      sato {
    733   1.6      sato         struct vrpiu_softc *sc = arg;
    734   1.6      sato 
    735   1.6      sato 	vrpiu_ad_intr(sc);
    736   1.6      sato 	vrpiu_tp_intr(sc);
    737   1.6      sato 
    738   1.1  takemura 	return 0;
    739   1.6      sato }
    740   1.6      sato 
    741   1.6      sato void
    742   1.6      sato vrpiu_start_powerstate(v)
    743   1.6      sato 	void *v;
    744   1.6      sato {
    745   1.6      sato 	int mask;
    746   1.6      sato 	struct vrpiu_softc *sc = (struct vrpiu_softc *)v;
    747   1.6      sato 
    748   1.6      sato 	vrpiu_ad_enable(sc);
    749   1.6      sato 	mask = vrpiu_read(sc, PIUAMSK_REG_W);
    750   1.6      sato 	mask &= 0xff8f; /* XXX */
    751   1.6      sato 	vrpiu_write(sc, PIUAMSK_REG_W, mask);
    752   1.6      sato 	vrpiu_write(sc, PIUASCN_REG_W, PIUACN_ADPSSTART);
    753   1.6      sato 	/*
    754   1.6      sato 	 * restart next A/D polling
    755   1.6      sato 	 */
    756   1.6      sato 	callout_reset(&sc->sc_adpoll, hz*vrpiu_ad_poll_interval,
    757   1.9  takemura 		      vrpiu_start_powerstate, sc);
    758   1.6      sato }
    759   1.6      sato 
    760   1.6      sato void
    761   1.6      sato vrpiu_calc_powerstate(sc)
    762   1.6      sato 	struct vrpiu_softc *sc;
    763   1.6      sato {
    764   1.6      sato 	extern void vrgiu_diff_io __P((void));
    765   1.6      sato 	vrpiu_ad_disable(sc);
    766   1.6      sato 	VPRINTF(("vrpiu:AD: %d, %d, %d\n",
    767   1.6      sato 		sc->sc_battery.value[0],
    768   1.6      sato 		sc->sc_battery.value[1],
    769   1.6      sato 		sc->sc_battery.value[2]));
    770   1.6      sato 	sc->sc_battery.nextpoll = hz*vrpiu_ad_poll_interval;
    771   1.6      sato #ifdef notyet
    772   1.7      sato 	config_hook_call(CONFIG_HOOK_SET,
    773   1.7      sato 			 CONFIG_HOOK_BATTERYVAL,
    774   1.6      sato 			 (void *)&sc->sc_battery);
    775   1.6      sato #endif /* notyet */
    776   1.6      sato 	/*
    777   1.6      sato 	 * restart next A/D polling if change polling timming.
    778   1.6      sato 	 */
    779   1.6      sato 	if (sc->sc_battery.nextpoll != hz*vrpiu_ad_poll_interval)
    780   1.9  takemura 	    callout_reset(&sc->sc_adpoll, sc->sc_battery.nextpoll,
    781   1.9  takemura 			  vrpiu_start_powerstate, sc);
    782   1.6      sato 	if (bootverbose)
    783   1.9  takemura 	    vrgiu_diff_io();
    784   1.6      sato 
    785   1.6      sato }
    786   1.6      sato 
    787   1.6      sato static void
    788   1.6      sato vrpiu_power(why, arg)
    789   1.6      sato 	int why;
    790   1.6      sato 	void *arg;
    791   1.6      sato {
    792   1.6      sato 	struct vrpiu_softc *sc = arg;
    793   1.6      sato 
    794   1.6      sato 	switch (why) {
    795   1.6      sato 	case PWR_STANDBY:
    796   1.6      sato 	case PWR_SUSPEND:
    797   1.9  takemura 	    break;
    798   1.6      sato 	case PWR_RESUME:
    799   1.9  takemura 	    callout_reset(&sc->sc_adpoll, hz,
    800   1.9  takemura 			  vrpiu_start_powerstate, sc);
    801   1.9  takemura 	    break;
    802   1.6      sato 	}
    803   1.1  takemura }
    804   1.1  takemura 
    805   1.1  takemura #ifdef DEBUG
    806   1.1  takemura void
    807   1.1  takemura vrpiu_dump_cntreg(cnt)
    808   1.1  takemura 	unsigned int cnt;
    809   1.1  takemura {
    810   1.1  takemura 	printf("%s", (cnt & PIUCNT_PENSTC) ? "Touch" : "Release");
    811   1.1  takemura 	printf(" state=");
    812   1.1  takemura 	if ((cnt & PIUCNT_PADSTATE_MASK) == PIUCNT_PADSTATE_CmdScan)
    813   1.9  takemura 	    printf("CmdScan");
    814   1.1  takemura 	if ((cnt & PIUCNT_PADSTATE_MASK) == PIUCNT_PADSTATE_IntervalNextScan)
    815   1.9  takemura 	    printf("IntervalNextScan");
    816   1.1  takemura 	if ((cnt & PIUCNT_PADSTATE_MASK) == PIUCNT_PADSTATE_PenDataScan)
    817   1.9  takemura 	    printf("PenDataScan");
    818   1.1  takemura 	if ((cnt & PIUCNT_PADSTATE_MASK) == PIUCNT_PADSTATE_WaitPenTouch)
    819   1.9  takemura 	    printf("WaitPenTouch");
    820   1.1  takemura 	if ((cnt & PIUCNT_PADSTATE_MASK) == PIUCNT_PADSTATE_RFU)
    821   1.9  takemura 	    printf("???");
    822   1.1  takemura 	if ((cnt & PIUCNT_PADSTATE_MASK) == PIUCNT_PADSTATE_ADPortScan)
    823   1.9  takemura 	    printf("ADPortScan");
    824   1.1  takemura 	if ((cnt & PIUCNT_PADSTATE_MASK) == PIUCNT_PADSTATE_Standby)
    825   1.9  takemura 	    printf("Standby");
    826   1.1  takemura 	if ((cnt & PIUCNT_PADSTATE_MASK) == PIUCNT_PADSTATE_Disable)
    827   1.9  takemura 	    printf("Disable");
    828   1.1  takemura 	if (cnt & PIUCNT_PADATSTOP)
    829   1.9  takemura 	    printf(" AutoStop");
    830   1.1  takemura 	if (cnt & PIUCNT_PADATSTART)
    831   1.9  takemura 	    printf(" AutoStart");
    832   1.1  takemura 	if (cnt & PIUCNT_PADSCANSTOP)
    833   1.9  takemura 	    printf(" Stop");
    834   1.1  takemura 	if (cnt & PIUCNT_PADSCANSTART)
    835   1.9  takemura 	    printf(" Start");
    836   1.1  takemura 	if (cnt & PIUCNT_PADSCANTYPE)
    837   1.9  takemura 	    printf(" ScanPressure");
    838   1.1  takemura 	if ((cnt & PIUCNT_PIUMODE_MASK) == PIUCNT_PIUMODE_ADCONVERTER)
    839   1.9  takemura 	    printf(" A/D");
    840   1.1  takemura 	if ((cnt & PIUCNT_PIUMODE_MASK) == PIUCNT_PIUMODE_COORDINATE)
    841   1.9  takemura 	    printf(" Coordinate");
    842   1.1  takemura 	if (cnt & PIUCNT_PIUSEQEN)
    843   1.9  takemura 	    printf(" SeqEn");
    844   1.1  takemura 	if ((cnt & PIUCNT_PIUPWR) == 0)
    845   1.9  takemura 	    printf(" PowerOff");
    846   1.1  takemura 	if ((cnt & PIUCNT_PADRST) == 0)
    847   1.9  takemura 	    printf(" Reset");
    848   1.1  takemura 	printf("\n");
    849   1.1  takemura }
    850   1.1  takemura #endif
    851