Home | History | Annotate | Line # | Download | only in dev
pfckbd.c revision 1.23.16.1
      1  1.23.16.1       mjf /*	$NetBSD: pfckbd.c,v 1.23.16.1 2008/04/03 12:42:17 mjf Exp $	*/
      2        1.1       uch 
      3        1.1       uch /*-
      4        1.4       uch  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
      5        1.1       uch  * All rights reserved.
      6        1.1       uch  *
      7        1.1       uch  * This code is derived from software contributed to The NetBSD Foundation
      8        1.1       uch  * by UCHIYAMA Yasushi.
      9        1.1       uch  *
     10        1.1       uch  * Redistribution and use in source and binary forms, with or without
     11        1.1       uch  * modification, are permitted provided that the following conditions
     12        1.1       uch  * are met:
     13        1.1       uch  * 1. Redistributions of source code must retain the above copyright
     14        1.1       uch  *    notice, this list of conditions and the following disclaimer.
     15        1.1       uch  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1       uch  *    notice, this list of conditions and the following disclaimer in the
     17        1.1       uch  *    documentation and/or other materials provided with the distribution.
     18        1.1       uch  * 3. All advertising materials mentioning features or use of this software
     19        1.1       uch  *    must display the following acknowledgement:
     20        1.1       uch  *        This product includes software developed by the NetBSD
     21        1.1       uch  *        Foundation, Inc. and its contributors.
     22        1.1       uch  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23        1.1       uch  *    contributors may be used to endorse or promote products derived
     24        1.1       uch  *    from this software without specific prior written permission.
     25        1.1       uch  *
     26        1.1       uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27        1.1       uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28        1.1       uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29        1.1       uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30        1.1       uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31        1.1       uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32        1.1       uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33        1.1       uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34        1.1       uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35        1.1       uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36        1.1       uch  * POSSIBILITY OF SUCH DAMAGE.
     37        1.1       uch  */
     38       1.11     lukem 
     39       1.19       uwe /*
     40       1.19       uwe  * Matrix scan keyboard connected to SH7709, SH7709A PFC module.
     41       1.19       uwe  * currently, HP Jornada 680/690, HITACHI PERSONA HPW-50PAD only.
     42       1.19       uwe  */
     43       1.11     lukem #include <sys/cdefs.h>
     44  1.23.16.1       mjf __KERNEL_RCSID(0, "$NetBSD: pfckbd.c,v 1.23.16.1 2008/04/03 12:42:17 mjf Exp $");
     45        1.4       uch 
     46        1.4       uch #include "debug_hpcsh.h"
     47        1.1       uch 
     48        1.1       uch #include <sys/param.h>
     49        1.1       uch #include <sys/systm.h>
     50        1.1       uch #include <sys/device.h>
     51        1.1       uch #include <sys/callout.h>
     52        1.1       uch 
     53        1.1       uch #include <machine/bus.h>
     54        1.3       uch #include <machine/platid.h>
     55        1.3       uch #include <machine/platid_mask.h>
     56        1.3       uch 
     57        1.1       uch #include <dev/hpc/hpckbdvar.h>
     58        1.1       uch 
     59        1.1       uch #include <sh3/pfcreg.h>
     60        1.1       uch 
     61        1.1       uch #include <hpcsh/dev/pfckbdvar.h>
     62        1.1       uch 
     63        1.4       uch #ifdef	PFCKBD_DEBUG
     64        1.4       uch #define DPRINTF_ENABLE
     65        1.4       uch #define DPRINTF_DEBUG	pfckbd_debug
     66        1.1       uch #endif
     67        1.5       uch #include <machine/debug.h>
     68        1.1       uch 
     69       1.19       uwe static struct pfckbd_core {
     70        1.1       uch 	int pc_attached;
     71        1.1       uch 	int pc_enabled;
     72        1.1       uch 	struct callout pc_soft_ch;
     73        1.1       uch 	struct hpckbd_ic_if pc_if;
     74        1.1       uch 	struct hpckbd_if *pc_hpckbd;
     75       1.14       uwe 	uint16_t pc_column[8];
     76        1.3       uch 	void (*pc_callout)(void *);
     77        1.1       uch } pfckbd_core;
     78        1.1       uch 
     79  1.23.16.1       mjf static int pfckbd_match(device_t, cfdata_t, void *);
     80  1.23.16.1       mjf static void pfckbd_attach(device_t, device_t, void *);
     81       1.20       uwe 
     82  1.23.16.1       mjf CFATTACH_DECL_NEW(pfckbd, 0,
     83       1.20       uwe     pfckbd_match, pfckbd_attach, NULL, NULL);
     84       1.20       uwe 
     85       1.20       uwe static void pfckbd_ifsetup(struct pfckbd_core *);
     86       1.20       uwe 
     87       1.20       uwe /* callbacks for hpckbd */
     88       1.20       uwe static int pfckbd_input_establish(void *, struct hpckbd_if *);
     89       1.20       uwe static int pfckbd_poll(void *);
     90       1.20       uwe 
     91       1.20       uwe static void pfckbd_input(struct pfckbd_core *, int, uint16_t);
     92       1.20       uwe 
     93       1.20       uwe static void (*pfckbd_callout_lookup(void))(void *);
     94       1.20       uwe static void pfckbd_callout_unknown(void *);
     95       1.20       uwe static void pfckbd_callout_hp(void *);
     96       1.20       uwe static void pfckbd_callout_hitachi(void *);
     97       1.22  kiyohara void pfckbd_poll_hitachi_power(void);
     98       1.22  kiyohara 
     99       1.20       uwe 
    100        1.3       uch /* callout function table. this function is platfrom specific. */
    101       1.19       uwe static const struct {
    102        1.3       uch 	platid_mask_t *platform;
    103        1.3       uch 	void (*func)(void *);
    104        1.3       uch } pfckbd_calloutfunc_table[] = {
    105        1.3       uch 	{ &platid_mask_MACH_HP		, pfckbd_callout_hp },
    106        1.3       uch 	{ &platid_mask_MACH_HITACHI	, pfckbd_callout_hitachi }
    107        1.1       uch };
    108        1.1       uch 
    109        1.1       uch 
    110        1.1       uch void
    111        1.1       uch pfckbd_cnattach()
    112        1.1       uch {
    113        1.1       uch 	struct pfckbd_core *pc = &pfckbd_core;
    114       1.20       uwe 
    115       1.20       uwe 	if ((cpu_product != CPU_PRODUCT_7709)
    116       1.20       uwe 	    && (cpu_product != CPU_PRODUCT_7709A))
    117        1.7       uch 		return;
    118        1.7       uch 
    119        1.1       uch 	/* initialize interface */
    120        1.1       uch 	pfckbd_ifsetup(pc);
    121        1.3       uch 
    122       1.20       uwe 	/* attach descendants */
    123        1.1       uch 	hpckbd_cnattach(&pc->pc_if);
    124        1.1       uch }
    125        1.1       uch 
    126       1.19       uwe static int
    127  1.23.16.1       mjf pfckbd_match(device_t parent, cfdata_t cf, void *aux)
    128        1.1       uch {
    129        1.1       uch 
    130       1.20       uwe 	if ((cpu_product != CPU_PRODUCT_7709)
    131       1.20       uwe 	    && (cpu_product != CPU_PRODUCT_7709A))
    132       1.20       uwe 		return 0;
    133        1.7       uch 
    134       1.20       uwe 	return !pfckbd_core.pc_attached; /* attach only once */
    135        1.1       uch }
    136        1.1       uch 
    137       1.19       uwe static void
    138  1.23.16.1       mjf pfckbd_attach(device_t parent, device_t self, void *aux)
    139        1.1       uch {
    140        1.1       uch 	struct hpckbd_attach_args haa;
    141       1.20       uwe 
    142  1.23.16.1       mjf 	aprint_naive("\n");
    143  1.23.16.1       mjf 	aprint_normal("\n");
    144        1.1       uch 
    145        1.1       uch 	pfckbd_core.pc_attached = 1;
    146       1.20       uwe 
    147        1.1       uch 	pfckbd_ifsetup(&pfckbd_core);
    148        1.1       uch 
    149        1.1       uch 	/* attach hpckbd */
    150       1.20       uwe 	haa.haa_ic = &pfckbd_core.pc_if; /* tell hpckbd our interface */
    151        1.1       uch 	config_found(self, &haa, hpckbd_print);
    152        1.1       uch 
    153        1.1       uch 	/* install callout handler */
    154       1.21        ad 	callout_init(&pfckbd_core.pc_soft_ch, 0);
    155       1.20       uwe 	callout_reset(&pfckbd_core.pc_soft_ch, 1,
    156       1.20       uwe 		      pfckbd_core.pc_callout, &pfckbd_core);
    157        1.1       uch }
    158        1.1       uch 
    159       1.20       uwe static void
    160       1.20       uwe pfckbd_ifsetup(struct pfckbd_core *pc)
    161       1.20       uwe {
    162       1.20       uwe 	int i;
    163       1.20       uwe 
    164       1.20       uwe 	pc->pc_if.hii_ctx = pc;
    165       1.20       uwe 	pc->pc_if.hii_establish	= pfckbd_input_establish;
    166       1.20       uwe 	pc->pc_if.hii_poll = pfckbd_poll;
    167       1.20       uwe 
    168       1.20       uwe 	for (i = 0; i < 8; i++)
    169       1.20       uwe 		pc->pc_column[i] = 0xdfff;
    170       1.20       uwe 
    171       1.20       uwe 	/* select PFC access method */
    172       1.20       uwe 	pc->pc_callout = pfckbd_callout_lookup();
    173       1.20       uwe }
    174       1.20       uwe 
    175       1.20       uwe 
    176       1.20       uwe /*
    177       1.20       uwe  * Callback for hpckbd_initif
    178       1.20       uwe  */
    179       1.19       uwe static int
    180        1.1       uch pfckbd_input_establish(void *ic, struct hpckbd_if *kbdif)
    181        1.1       uch {
    182        1.1       uch 	struct pfckbd_core *pc = ic;
    183        1.1       uch 
    184       1.20       uwe 	pc->pc_hpckbd = kbdif;	/* save hpckbd interface */
    185       1.20       uwe 	pc->pc_enabled = 1;	/* ok to talk to hpckbd */
    186        1.1       uch 
    187        1.1       uch 	return 0;
    188        1.1       uch }
    189        1.1       uch 
    190       1.20       uwe /*
    191       1.20       uwe  * Callback for hpckbd_cngetc
    192       1.20       uwe  */
    193       1.19       uwe static int
    194       1.20       uwe pfckbd_poll(void *ic)
    195        1.1       uch {
    196       1.20       uwe 	struct pfckbd_core *pc = ic;
    197        1.1       uch 
    198        1.1       uch 	if (pc->pc_enabled)
    199       1.20       uwe 		(*pc->pc_callout)(pc);
    200        1.1       uch 
    201        1.1       uch 	return 0;
    202        1.1       uch }
    203        1.1       uch 
    204       1.20       uwe /*
    205       1.20       uwe  * Called by platform specific scan routines to report key events to hpckbd
    206       1.20       uwe  */
    207       1.19       uwe static void
    208       1.20       uwe pfckbd_input(struct pfckbd_core *pc, int column, uint16_t data)
    209        1.3       uch {
    210        1.3       uch 	int row, type, val;
    211       1.18       uwe 	unsigned int edge, mask;
    212        1.3       uch 
    213       1.20       uwe 	edge = data ^ pc->pc_column[column];
    214       1.20       uwe 	if (edge == 0)
    215       1.20       uwe 		return;		/* no changes in this column */
    216       1.20       uwe 
    217       1.20       uwe 	pc->pc_column[column] = data;
    218       1.20       uwe 
    219       1.20       uwe 	for (row = 0, mask = 1; row < 16; ++row, mask <<= 1) {
    220       1.20       uwe 		if (mask & edge) {
    221       1.20       uwe 			type = mask & data ? /* up */ 0 : /* down */ 1;
    222       1.20       uwe 			DPRINTF("(%2d, %2d) %d \n", row, column, type);
    223       1.20       uwe 
    224       1.20       uwe 			val = row * 8 + column;
    225       1.20       uwe 			hpckbd_input(pc->pc_hpckbd, type, val);
    226        1.3       uch 		}
    227        1.3       uch 	}
    228        1.1       uch }
    229        1.1       uch 
    230       1.20       uwe 
    231        1.3       uch /*
    232       1.20       uwe  * Platform dependent scan routines.
    233        1.3       uch  */
    234        1.3       uch 
    235        1.3       uch /* Look up appropriate callback handler */
    236       1.19       uwe static void
    237       1.19       uwe (*pfckbd_callout_lookup())(void *)
    238        1.3       uch {
    239       1.20       uwe 	int i, n;
    240       1.20       uwe 
    241       1.20       uwe 	n = sizeof(pfckbd_calloutfunc_table)
    242       1.20       uwe 		/ sizeof(pfckbd_calloutfunc_table[0]);
    243       1.20       uwe 
    244        1.3       uch 	for (i = 0; i < n; i++)
    245        1.3       uch 		if (platid_match(&platid,
    246       1.20       uwe 				 pfckbd_calloutfunc_table[i].platform))
    247       1.20       uwe 			return pfckbd_calloutfunc_table[i].func;
    248        1.3       uch 
    249       1.20       uwe 	return pfckbd_callout_unknown;
    250        1.3       uch }
    251        1.3       uch 
    252        1.3       uch /* Placeholder for unknown platform */
    253       1.19       uwe static void
    254        1.3       uch pfckbd_callout_unknown(void *arg)
    255        1.3       uch {
    256        1.3       uch 
    257       1.17       uwe 	printf("%s: unknown keyboard switch\n", __func__);
    258        1.3       uch }
    259        1.3       uch 
    260       1.20       uwe /*
    261       1.20       uwe  * HP Jornada680/690, HP620LX
    262       1.20       uwe  */
    263       1.19       uwe static void
    264        1.3       uch pfckbd_callout_hp(void *arg)
    265        1.1       uch {
    266       1.10       uwe #define PFCKBD_HP_PDCR_MASK 0xcc0c
    267       1.10       uwe #define PFCKBD_HP_PECR_MASK 0xf0cf
    268       1.10       uwe 
    269       1.10       uwe 	/*
    270       1.10       uwe 	 * Disable output on all lines but the n'th line in D.
    271       1.10       uwe 	 * Pull the n'th scan line in D low.
    272       1.10       uwe 	 */
    273       1.10       uwe #define PD(n)								\
    274       1.14       uwe 	{ (uint16_t)(PFCKBD_HP_PDCR_MASK & (~(1 << (2*(n)+1)))),	\
    275       1.14       uwe 	  (uint16_t)(PFCKBD_HP_PECR_MASK & 0xffff),			\
    276       1.14       uwe 	  (uint8_t)~(1 << (n)),						\
    277       1.10       uwe 	  0xff }
    278       1.10       uwe 
    279       1.10       uwe 	/* Ditto for E */
    280       1.10       uwe #define PE(n)								\
    281       1.14       uwe 	{ (uint16_t)(PFCKBD_HP_PDCR_MASK & 0xffff),			\
    282       1.14       uwe 	  (uint16_t)(PFCKBD_HP_PECR_MASK & (~(1 << (2*(n)+1)))),	\
    283       1.10       uwe 	  0xff,								\
    284       1.14       uwe 	  (uint8_t)~(1 << (n)) }
    285       1.10       uwe 
    286        1.1       uch 	static const struct {
    287       1.14       uwe 		uint16_t dc, ec; uint8_t d, e;
    288        1.1       uch 	} scan[] = {
    289       1.10       uwe 		PD(1), PD(5), PE(1), PE(6), PE(7), PE(3), PE(0), PD(7)
    290        1.1       uch 	};
    291       1.10       uwe 
    292       1.10       uwe #undef PD
    293       1.10       uwe #undef PE
    294       1.10       uwe 
    295        1.1       uch 	struct pfckbd_core *pc = arg;
    296       1.14       uwe 	uint16_t dc, ec;
    297        1.3       uch 	int column;
    298       1.14       uwe 	uint16_t data;
    299        1.1       uch 
    300        1.1       uch 	if (!pc->pc_enabled)
    301        1.1       uch 		goto reinstall;
    302        1.1       uch 
    303       1.10       uwe 	/* bits in D/E control regs we do not touch (XXX: can they change?) */
    304       1.10       uwe 	dc = _reg_read_2(SH7709_PDCR) & ~PFCKBD_HP_PDCR_MASK;
    305       1.10       uwe 	ec = _reg_read_2(SH7709_PECR) & ~PFCKBD_HP_PECR_MASK;
    306       1.10       uwe 
    307        1.1       uch 	for (column = 0; column < 8; column++) {
    308       1.10       uwe 		/* disable output to all lines except the one we scan */
    309       1.10       uwe 		_reg_write_2(SH7709_PDCR, dc | scan[column].dc);
    310       1.10       uwe 		_reg_write_2(SH7709_PECR, ec | scan[column].ec);
    311       1.10       uwe 		delay(5);
    312       1.10       uwe 
    313       1.10       uwe 		/* pull the scan line low */
    314        1.7       uch 		_reg_write_1(SH7709_PDDR, scan[column].d);
    315        1.7       uch 		_reg_write_1(SH7709_PEDR, scan[column].e);
    316        1.1       uch 		delay(50);
    317       1.10       uwe 
    318       1.10       uwe 		/* read sense */
    319       1.20       uwe 		data = _reg_read_1(SH7709_PFDR)
    320       1.20       uwe 			| (_reg_read_1(SH7709_PCDR) << 8);
    321        1.2       uch 
    322       1.20       uwe 		pfckbd_input(pc, column, data);
    323        1.3       uch 	}
    324        1.3       uch 
    325       1.10       uwe 	/* scan no lines */
    326        1.7       uch 	_reg_write_1(SH7709_PDDR, 0xff);
    327        1.7       uch 	_reg_write_1(SH7709_PEDR, 0xff);
    328       1.10       uwe 
    329       1.10       uwe 	/* enable all scan lines */
    330       1.10       uwe 	_reg_write_2(SH7709_PDCR, dc | (0x5555 & PFCKBD_HP_PDCR_MASK));
    331       1.10       uwe 	_reg_write_2(SH7709_PECR, ec | (0x5555 & PFCKBD_HP_PECR_MASK));
    332       1.10       uwe 
    333       1.12       uwe #if 0
    334       1.10       uwe 	/* (ignore) extra keys/events (recorder buttons, lid, cable &c) */
    335        1.7       uch 	data = _reg_read_1(SH7709_PGDR) | (_reg_read_1(SH7709_PHDR) << 8);
    336       1.12       uwe #endif
    337        1.3       uch 
    338        1.3       uch  reinstall:
    339       1.12       uwe 	callout_schedule(&pc->pc_soft_ch, 1);
    340        1.3       uch }
    341        1.3       uch 
    342       1.20       uwe /*
    343       1.20       uwe  * HITACH PERSONA (HPW-50PAD)
    344       1.20       uwe  */
    345       1.19       uwe static void
    346        1.3       uch pfckbd_callout_hitachi(void *arg)
    347        1.3       uch {
    348       1.15  kiyohara #define PFCKBD_HITACHI_PCCR_MASK 0xfff3
    349       1.13       uwe #define PFCKBD_HITACHI_PDCR_MASK 0x000c
    350       1.13       uwe #define PFCKBD_HITACHI_PECR_MASK 0x30cf
    351       1.13       uwe 
    352       1.15  kiyohara #define PFCKBD_HITACHI_PCDR_SCN_MASK 0xfd
    353       1.22  kiyohara #define PFCKBD_HITACHI_PDDR_SCN_MASK 0x02
    354       1.22  kiyohara #define PFCKBD_HITACHI_PEDR_SCN_MASK 0x4b
    355       1.13       uwe 
    356       1.13       uwe #define PFCKBD_HITACHI_PCDR_SNS_MASK 0x01
    357       1.13       uwe #define PFCKBD_HITACHI_PFDR_SNS_MASK 0xfe
    358       1.13       uwe 
    359       1.13       uwe 	/*
    360       1.13       uwe 	 * Disable output on all lines but the n'th line in C.
    361       1.13       uwe 	 * Pull the n'th scan line in C low.
    362       1.13       uwe 	 */
    363       1.13       uwe #define PC(n)								\
    364       1.14       uwe 	{ (uint16_t)(PFCKBD_HITACHI_PCCR_MASK & (~(1 << (2*(n)+1)))),	\
    365       1.14       uwe 	  (uint16_t)(PFCKBD_HITACHI_PDCR_MASK & 0xffff),		\
    366       1.14       uwe 	  (uint16_t)(PFCKBD_HITACHI_PECR_MASK & 0xffff),		\
    367       1.14       uwe 	  (uint8_t)(PFCKBD_HITACHI_PCDR_SCN_MASK & ~(1 << (n))),	\
    368       1.13       uwe 	  PFCKBD_HITACHI_PDDR_SCN_MASK,					\
    369       1.13       uwe 	  PFCKBD_HITACHI_PEDR_SCN_MASK }
    370       1.13       uwe 
    371       1.13       uwe 	/* Ditto for D */
    372       1.13       uwe #define PD(n)								\
    373       1.14       uwe 	{ (uint16_t)(PFCKBD_HITACHI_PCCR_MASK & 0xffff),		\
    374       1.14       uwe 	  (uint16_t)(PFCKBD_HITACHI_PDCR_MASK & (~(1 << (2*(n)+1)))),	\
    375       1.14       uwe 	  (uint16_t)(PFCKBD_HITACHI_PECR_MASK & 0xffff),		\
    376       1.13       uwe 	  PFCKBD_HITACHI_PCDR_SCN_MASK,					\
    377       1.14       uwe 	  (uint8_t)(PFCKBD_HITACHI_PDDR_SCN_MASK & ~(1 << (n))),	\
    378       1.13       uwe 	  PFCKBD_HITACHI_PEDR_SCN_MASK }
    379       1.13       uwe 
    380       1.13       uwe 	/* Ditto for E */
    381       1.13       uwe #define PE(n)								\
    382       1.14       uwe 	{ (uint16_t)(PFCKBD_HITACHI_PCCR_MASK & 0xffff),		\
    383       1.14       uwe 	  (uint16_t)(PFCKBD_HITACHI_PDCR_MASK & 0xffff),		\
    384       1.14       uwe 	  (uint16_t)(PFCKBD_HITACHI_PECR_MASK & (~(1 << (2*(n)+1)))),	\
    385       1.13       uwe 	  PFCKBD_HITACHI_PCDR_SCN_MASK,					\
    386       1.13       uwe 	  PFCKBD_HITACHI_PDDR_SCN_MASK,					\
    387       1.14       uwe 	  (uint8_t)(PFCKBD_HITACHI_PEDR_SCN_MASK & ~(1 << (n))) }
    388       1.13       uwe 
    389        1.3       uch 	static const struct {
    390       1.14       uwe 		uint16_t cc, dc, ec; uint8_t c, d, e;
    391        1.3       uch 	} scan[] = {
    392       1.13       uwe 		PE(6), PE(3), PE(1), PE(0), PC(7), PC(6), PC(5), PC(4),
    393       1.15  kiyohara 		PC(3), PC(2), PD(1), PC(0)
    394        1.3       uch 	};
    395       1.13       uwe 
    396        1.3       uch 	struct pfckbd_core *pc = arg;
    397       1.14       uwe 	uint16_t cc, dc, ec;
    398       1.15  kiyohara 	uint8_t data[2], cd, dd, ed;
    399       1.13       uwe 	int i;
    400        1.3       uch 
    401        1.3       uch 	if (!pc->pc_enabled)
    402        1.3       uch 		goto reinstall;
    403        1.3       uch 
    404       1.13       uwe 	/* bits in C/D/E control regs we do not touch (XXX: can they change?) */
    405       1.13       uwe 	cc = _reg_read_2(SH7709_PCCR) & ~PFCKBD_HITACHI_PCCR_MASK;
    406       1.13       uwe 	dc = _reg_read_2(SH7709_PDCR) & ~PFCKBD_HITACHI_PDCR_MASK;
    407       1.13       uwe 	ec = _reg_read_2(SH7709_PECR) & ~PFCKBD_HITACHI_PECR_MASK;
    408       1.13       uwe 
    409       1.13       uwe 	for (i = 0; i < 12; i++) {
    410       1.13       uwe 		/* disable output to all lines except the one we scan */
    411       1.15  kiyohara 		_reg_write_2(SH7709_PCCR, cc | scan[i].cc);
    412       1.13       uwe 		_reg_write_2(SH7709_PDCR, dc | scan[i].dc);
    413       1.13       uwe 		_reg_write_2(SH7709_PECR, ec | scan[i].ec);
    414       1.13       uwe 		delay(5);
    415       1.13       uwe 
    416       1.22  kiyohara 		cd = _reg_read_1(SH7709_PCDR) & ~PFCKBD_HITACHI_PCDR_SCN_MASK;
    417       1.22  kiyohara 		dd = _reg_read_1(SH7709_PDDR) & ~PFCKBD_HITACHI_PDDR_SCN_MASK;
    418       1.22  kiyohara 		ed = _reg_read_1(SH7709_PEDR) & ~PFCKBD_HITACHI_PEDR_SCN_MASK;
    419       1.22  kiyohara 
    420       1.13       uwe 		/* pull the scan line low */
    421       1.22  kiyohara 		_reg_write_1(SH7709_PCDR, cd | scan[i].c);
    422       1.22  kiyohara 		_reg_write_1(SH7709_PDDR, dd | scan[i].d);
    423       1.22  kiyohara 		_reg_write_1(SH7709_PEDR, ed | scan[i].e);
    424        1.3       uch 		delay(50);
    425        1.1       uch 
    426       1.13       uwe 		/* read sense */
    427       1.13       uwe 		data[i & 0x1] =
    428       1.20       uwe 		    (_reg_read_1(SH7709_PCDR) & PFCKBD_HITACHI_PCDR_SNS_MASK)
    429       1.20       uwe 		  | (_reg_read_1(SH7709_PFDR) & PFCKBD_HITACHI_PFDR_SNS_MASK);
    430       1.13       uwe 
    431       1.13       uwe 		if (i & 0x1)
    432       1.20       uwe 			pfckbd_input(pc, (i >> 1), (data[0] | (data[1] << 8)));
    433        1.1       uch 	}
    434        1.1       uch 
    435       1.13       uwe 	/* enable all scan lines */
    436       1.13       uwe 	_reg_write_2(SH7709_PCCR, cc | (0x5555 & PFCKBD_HITACHI_PCCR_MASK));
    437       1.13       uwe 	_reg_write_2(SH7709_PDCR, dc | (0x5555 & PFCKBD_HITACHI_PDCR_MASK));
    438       1.13       uwe 	_reg_write_2(SH7709_PECR, ec | (0x5555 & PFCKBD_HITACHI_PECR_MASK));
    439        1.1       uch 
    440        1.1       uch  reinstall:
    441       1.12       uwe 	callout_schedule(&pc->pc_soft_ch, 1);
    442        1.1       uch }
    443       1.22  kiyohara 
    444       1.22  kiyohara void
    445       1.22  kiyohara pfckbd_poll_hitachi_power()
    446       1.22  kiyohara {
    447       1.22  kiyohara 	static const struct {
    448       1.22  kiyohara 		uint16_t cc, dc, ec; uint8_t c, d, e;
    449       1.22  kiyohara 	} poll = PD(1);
    450       1.22  kiyohara 
    451       1.22  kiyohara #undef PC
    452       1.22  kiyohara #undef PD
    453       1.22  kiyohara #undef PE
    454       1.22  kiyohara 
    455       1.22  kiyohara 	uint16_t cc, dc, ec;
    456       1.22  kiyohara 	uint8_t cd, dd, ed;
    457       1.22  kiyohara 
    458       1.22  kiyohara 	/* bits in C/D/E control regs we do not touch (XXX: can they change?) */
    459       1.22  kiyohara 	cc = _reg_read_2(SH7709_PCCR) & ~PFCKBD_HITACHI_PCCR_MASK;
    460       1.22  kiyohara 	dc = _reg_read_2(SH7709_PDCR) & ~PFCKBD_HITACHI_PDCR_MASK;
    461       1.22  kiyohara 	ec = _reg_read_2(SH7709_PECR) & ~PFCKBD_HITACHI_PECR_MASK;
    462       1.22  kiyohara 
    463       1.22  kiyohara 	/* disable output to all lines except the one we scan */
    464       1.22  kiyohara 	_reg_write_2(SH7709_PCCR, cc | poll.cc);
    465       1.22  kiyohara 	_reg_write_2(SH7709_PDCR, dc | poll.dc);
    466       1.22  kiyohara 	_reg_write_2(SH7709_PECR, ec | poll.ec);
    467       1.22  kiyohara 	delay(5);
    468       1.22  kiyohara 
    469       1.22  kiyohara 	cd = _reg_read_1(SH7709_PCDR) & ~PFCKBD_HITACHI_PCDR_SCN_MASK;
    470       1.22  kiyohara 	dd = _reg_read_1(SH7709_PDDR) & ~PFCKBD_HITACHI_PDDR_SCN_MASK;
    471       1.22  kiyohara 	ed = _reg_read_1(SH7709_PEDR) & ~PFCKBD_HITACHI_PEDR_SCN_MASK;
    472       1.22  kiyohara 
    473       1.22  kiyohara 	/* pull the scan line low */
    474       1.22  kiyohara 	_reg_write_1(SH7709_PCDR, cd | poll.c);
    475       1.22  kiyohara 	_reg_write_1(SH7709_PDDR, dd | poll.d);
    476       1.22  kiyohara 	_reg_write_1(SH7709_PEDR, ed | poll.e);
    477       1.22  kiyohara 	delay(50);
    478       1.22  kiyohara 
    479       1.22  kiyohara 	/* poll POWER On */
    480       1.22  kiyohara 	while (_reg_read_1(SH7709_PCDR) & PFCKBD_HITACHI_PCDR_SNS_MASK & 0x01);
    481       1.22  kiyohara 
    482       1.22  kiyohara 	/* enable all scan lines */
    483       1.22  kiyohara 	_reg_write_2(SH7709_PCCR, cc | (0x5555 & PFCKBD_HITACHI_PCCR_MASK));
    484       1.22  kiyohara 	_reg_write_2(SH7709_PDCR, dc | (0x5555 & PFCKBD_HITACHI_PDCR_MASK));
    485       1.22  kiyohara 	_reg_write_2(SH7709_PECR, ec | (0x5555 & PFCKBD_HITACHI_PECR_MASK));
    486       1.22  kiyohara }
    487