Home | History | Annotate | Line # | Download | only in smdk2xx0
smdk2410_kbd.c revision 1.2.4.1
      1  1.2.4.1    rpaulo /* $NetBSD: smdk2410_kbd.c,v 1.2.4.1 2006/09/09 02:38:55 rpaulo Exp $ */
      2      1.1       bsh 
      3      1.1       bsh /*
      4      1.1       bsh  * Copyright (c) 2004  Genetec Corporation.  All rights reserved.
      5      1.1       bsh  * Written by Hiroyuki Bessho for Genetec Corporation.
      6      1.1       bsh  *
      7      1.1       bsh  * Redistribution and use in source and binary forms, with or without
      8      1.1       bsh  * modification, are permitted provided that the following conditions
      9      1.1       bsh  * are met:
     10      1.1       bsh  * 1. Redistributions of source code must retain the above copyright
     11      1.1       bsh  *    notice, this list of conditions and the following disclaimer.
     12      1.1       bsh  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1       bsh  *    notice, this list of conditions and the following disclaimer in the
     14      1.1       bsh  *    documentation and/or other materials provided with the distribution.
     15      1.1       bsh  * 3. The name of Genetec Corporation may not be used to endorse or
     16      1.1       bsh  *    promote products derived from this software without specific prior
     17      1.1       bsh  *    written permission.
     18      1.1       bsh  *
     19      1.1       bsh  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     20      1.1       bsh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.1       bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.1       bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     23      1.1       bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.1       bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.1       bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.1       bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.1       bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.1       bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.1       bsh  * POSSIBILITY OF SUCH DAMAGE.
     30      1.1       bsh  */
     31      1.1       bsh 
     32      1.1       bsh /*
     33      1.1       bsh  * Support SMDK2410's keyboard.
     34      1.1       bsh  *
     35      1.1       bsh  * On-board keyboard controller is Semtech SPICoder SA01.
     36      1.1       bsh  * (http://www.semtech.com/pdf/doc5-spi-sa01-ds.pdf)
     37      1.1       bsh  *
     38      1.1       bsh  * The controller is connected to SPI1.
     39      1.1       bsh  * _ATN signal from the SPICoder is connected to EINT1.
     40      1.1       bsh  */
     41      1.1       bsh 
     42      1.1       bsh #include <sys/cdefs.h>
     43  1.2.4.1    rpaulo __KERNEL_RCSID(0, "$NetBSD: smdk2410_kbd.c,v 1.2.4.1 2006/09/09 02:38:55 rpaulo Exp $");
     44      1.1       bsh 
     45      1.1       bsh #include <sys/param.h>
     46      1.1       bsh #include <sys/systm.h>
     47      1.1       bsh #include <sys/conf.h>
     48      1.1       bsh 
     49      1.1       bsh #include <machine/bus.h>
     50      1.1       bsh #include <machine/cpu.h>
     51      1.1       bsh 
     52      1.1       bsh #include <dev/wscons/wsconsio.h>
     53      1.1       bsh #include <dev/wscons/wskbdvar.h>
     54      1.1       bsh #include <dev/wscons/wsksymdef.h>
     55      1.1       bsh #include <dev/wscons/wsksymvar.h>
     56      1.1       bsh 
     57      1.1       bsh #include <arm/s3c2xx0/s3c24x0var.h>
     58      1.1       bsh #include <arm/s3c2xx0/s3c24x0reg.h>
     59      1.1       bsh #include <arm/s3c2xx0/s3c2410reg.h>
     60      1.1       bsh 
     61      1.1       bsh #include <arm/s3c2xx0/s3c24x0_spi.h>
     62      1.1       bsh 
     63      1.1       bsh #include "locators.h"
     64      1.1       bsh 
     65      1.1       bsh /*
     66      1.1       bsh  * Keyboard driver for Semtech keyboard controller on SMDK2410.
     67      1.1       bsh  *
     68      1.1       bsh  * There are several keycoder products from Semtech.
     69      1.1       bsh  * This driver supports SPICoder(R) SA01 (UR5HCSPI-SA01) only.
     70      1.1       bsh  *
     71      1.1       bsh  * See http://www.semtech.com/products/ for detail.
     72      1.1       bsh  */
     73      1.1       bsh 
     74      1.1       bsh /*
     75      1.1       bsh  * Commands/responce
     76      1.1       bsh  */
     77      1.1       bsh #define	KCDR_INITIALIZE	0xa0	/* Initialize request */
     78      1.1       bsh #define	KCDR_INITCOMP	0xa1	/* Initialize complete */
     79      1.1       bsh #define	KCDR_HEARTBEAT	0xa2	/* Heaartbeat request/response */
     80      1.1       bsh #define	KCDR_IDENTIFY	0xf2	/* Identification request/response */
     81      1.1       bsh #define	KCDR_LEDSTATUS	0xa3	/* LED status request/report */
     82      1.1       bsh #define	KCDR_LEDMODIFY	0xa6	/* LED mode modify */
     83      1.1       bsh #define	KCDR_RESENTREQ	0xa5	/* Re-send request upon error */
     84      1.1       bsh #define	KCDR_IOMODE	0xa7	/* Input/output mode modify/report */
     85      1.1       bsh #define	KCDR_OUTPUT	0xa8	/* output to GPIO0 pin */
     86      1.1       bsh #define	KCDR_SETWAKEUP	0xa9	/* define wake-up keys */
     87      1.1       bsh 
     88      1.1       bsh #define	KCDR_CONTROL	0x80	/* Commands from KeyCorder to Host starts with
     89      1.1       bsh 				   this code. */
     90      1.1       bsh #define	KCDR_ESC	0x1b	/* Commands from host to KeyCorder starts with
     91      1.1       bsh 				   this code. */
     92      1.1       bsh 
     93      1.1       bsh /*
     94      1.1       bsh  * GPIO ports
     95      1.1       bsh  */
     96      1.1       bsh #define	SSKBD_WUP	0	/* nWUP = GPB0 */
     97      1.1       bsh #define	SSKBD_SS	6	/* nSS = GPB6 */
     98      1.1       bsh 
     99      1.1       bsh /*
    100      1.1       bsh  * keymap
    101      1.1       bsh  */
    102      1.1       bsh 
    103      1.1       bsh #define _(col,row)	KS_KEYCODE((col)*8+(row))
    104      1.1       bsh 
    105      1.1       bsh static const keysym_t sskbd_keydesc_0[] = {
    106      1.1       bsh /*	_(col,row)      normal		shifted */
    107      1.1       bsh 	_(0,0), 	KS_Alt_L,	KS_Alt_L,
    108      1.1       bsh 
    109      1.1       bsh 	_(1,0), 	KS_grave,	KS_asciitilde,
    110      1.1       bsh 	_(1,1),  	KS_backslash,	KS_bar,
    111      1.1       bsh 	_(1,2), 	KS_Tab,  	KS_Tab,
    112      1.1       bsh 	_(1,3),  	KS_z,    	KS_Z,
    113      1.1       bsh 	_(1,4),  	KS_a,  		KS_A,
    114      1.1       bsh 	_(1,5), 	KS_x,		KS_X,
    115      1.1       bsh 
    116      1.1       bsh 	_(2,1), 	KS_Shift_L,	KS_Shift_L,
    117      1.1       bsh 
    118      1.1       bsh 	_(3,0), 	KS_Control_L,	KS_Control_L,
    119      1.1       bsh 
    120      1.1       bsh 	_(4,0), 	KS_Meta_L,	KS_Meta_L,
    121      1.1       bsh 
    122      1.1       bsh 	_(5,0), 	KS_Escape, 	KS_Escape,
    123      1.1       bsh 	_(5,1),  	KS_Delete,	KS_Delete,
    124      1.1       bsh 	_(5,2), 	KS_q,		KS_Q,
    125      1.1       bsh 	_(5,3), 	KS_Caps_Lock,	KS_Caps_Lock,
    126      1.1       bsh 	_(5,4),  	KS_s,		KS_S,
    127      1.1       bsh 	_(5,5),  	KS_c,		KS_C,
    128      1.1       bsh 	_(5,6), 	KS_3,		KS_numbersign,
    129      1.1       bsh 
    130      1.1       bsh 	_(6,0), 	KS_1,		KS_exclam,
    131      1.1       bsh 	_(6,2),		KS_w,		KS_W,
    132      1.1       bsh 	_(6,4),		KS_d,		KS_D,
    133      1.1       bsh 	_(6,5),		KS_v,		KS_V,
    134      1.1       bsh 	_(6,6),		KS_4,		KS_dollar,
    135      1.1       bsh 
    136      1.1       bsh 	_(7,0),		KS_2,		KS_at,
    137      1.1       bsh 	_(7,1),		KS_t,		KS_T,
    138      1.1       bsh 	_(7,2),		KS_e,		KS_E,
    139      1.1       bsh 	_(7,4),		KS_f,		KS_F,
    140      1.1       bsh 	_(7,5),		KS_b,		KS_B,
    141      1.1       bsh 	_(7,6),		KS_5,		KS_percent,
    142      1.1       bsh 
    143      1.1       bsh 	_(8,0),		KS_9,		KS_parenleft,
    144      1.1       bsh 	_(8,1),		KS_y,		KS_Y,
    145      1.1       bsh 	_(8,2),		KS_r,		KS_R,
    146      1.1       bsh 	_(8,3),		KS_k,		KS_K,
    147      1.1       bsh 	_(8,4),		KS_g,		KS_G,
    148      1.1       bsh 	_(8,5),		KS_n,		KS_N,
    149      1.1       bsh 	_(8,6),		KS_6,		KS_asciicircum,
    150      1.1       bsh 
    151      1.1       bsh 	_(9,0),		KS_0,		KS_parenright,
    152      1.1       bsh 	_(9,1),		KS_u,		KS_U,
    153      1.1       bsh 	_(9,2),		KS_o,		KS_O,
    154      1.1       bsh 	_(9,3),		KS_l,		KS_L,
    155      1.1       bsh 	_(9,4),		KS_h,		KS_H,
    156      1.1       bsh 	_(9,5),		KS_m,		KS_M,
    157      1.1       bsh 	_(9,6),		KS_7,		KS_ampersand,
    158      1.1       bsh 
    159      1.1       bsh 	_(10,0),	KS_minus,	KS_underscore,
    160      1.1       bsh 	_(10,1),	KS_i,		KS_I,
    161      1.1       bsh 	_(10,2),	KS_p,		KS_P,
    162      1.1       bsh 	_(10,3),	KS_l,		KS_L,
    163      1.1       bsh 	_(10,4),	KS_j,		KS_J,
    164      1.1       bsh 	_(10,5),	KS_comma,	KS_less,
    165      1.1       bsh 	_(10,6),	KS_8,		KS_asterisk,
    166      1.1       bsh 
    167      1.1       bsh 	_(11,0),	KS_equal,	KS_plus,
    168      1.1       bsh 	_(11,1),	KS_Return,	KS_Return,
    169      1.1       bsh 	_(11,2),	KS_bracketleft,	KS_braceleft,
    170      1.1       bsh 	_(11,3),	KS_apostrophe,	KS_quotedbl,
    171      1.1       bsh 	_(11,4),	KS_slash,	KS_question,
    172      1.1       bsh 	_(11,5),	KS_period,	KS_greater,
    173      1.1       bsh 	_(11,6),	KS_Menu,	KS_Menu,	/* Prog key */
    174      1.1       bsh 
    175      1.1       bsh 	_(12,1),	KS_Shift_R,	KS_Shift_R,
    176      1.1       bsh 
    177      1.1       bsh 	_(13,0),	KS_BackSpace,	KS_BackSpace,
    178      1.1       bsh 	_(13,1),	KS_Down,	KS_Next,
    179      1.1       bsh 	_(13,2),	KS_bracketright,  KS_braceright,
    180      1.1       bsh 	_(13,3),	KS_Up,		KS_Prior,
    181      1.1       bsh 	_(13,4),	KS_Left,	KS_Home,
    182      1.1       bsh 	_(13,5),	KS_space,	KS_space,
    183      1.1       bsh 	_(13,6),	KS_Right,	KS_End,
    184      1.1       bsh };
    185      1.1       bsh 
    186      1.1       bsh #define KBD_MAP(name, base, map) \
    187      1.1       bsh 			{ name, base, sizeof(map)/sizeof(keysym_t), map }
    188      1.1       bsh 
    189      1.1       bsh static const struct wscons_keydesc sskbd_keydesctab[] = {
    190      1.1       bsh 	KBD_MAP(KB_MACHDEP, 0, sskbd_keydesc_0),
    191      1.1       bsh 	{0, 0, 0, 0}
    192      1.1       bsh };
    193      1.1       bsh 
    194      1.1       bsh const struct wskbd_mapdata sskbd_keymapdata = {
    195      1.1       bsh 	sskbd_keydesctab,
    196      1.1       bsh 	KB_MACHDEP,
    197      1.1       bsh };
    198      1.1       bsh 
    199      1.1       bsh 
    200      1.1       bsh /*
    201      1.1       bsh  * SMDK2410 keyboard driver.
    202      1.1       bsh  */
    203      1.1       bsh struct sskbd_softc {
    204      1.1       bsh         struct  device dev;
    205      1.1       bsh 
    206      1.1       bsh 	struct device *wskbddev;
    207      1.1       bsh 	void *atn_ih;			/* interrupt handler for nATN */
    208      1.1       bsh 	void *spi_ih;			/* interrupt handler for SPI rx */
    209      1.1       bsh 
    210      1.1       bsh 	void *soft_ih;			/* soft interrupt */
    211      1.1       bsh 
    212      1.1       bsh 	bus_space_tag_t  iot;
    213      1.1       bsh 	bus_space_handle_t ioh;
    214      1.1       bsh 	bus_space_handle_t gpioh;
    215      1.1       bsh 
    216      1.1       bsh #define RING_SIZE  16			/* must be power of 2 */
    217      1.1       bsh 	short  inptr, outptr;
    218      1.1       bsh 	unsigned char ring[RING_SIZE];
    219      1.1       bsh #define	advance_ring_ptr(p)	((p+1) & ~RING_SIZE)
    220      1.1       bsh 
    221      1.1       bsh 	short reading, enable;
    222      1.1       bsh };
    223      1.1       bsh 
    224      1.1       bsh 
    225      1.1       bsh int sskbd_match(struct device *, struct cfdata *, void *);
    226      1.1       bsh void sskbd_attach(struct device *, struct device *, void *);
    227      1.1       bsh 
    228      1.1       bsh CFATTACH_DECL(sskbd, sizeof(struct sskbd_softc),
    229      1.1       bsh     sskbd_match, sskbd_attach, NULL, NULL);
    230      1.1       bsh 
    231      1.1       bsh static  int	sskbd_enable(void *, int);
    232      1.1       bsh static  void	sskbd_set_leds(void *, int);
    233      1.2  christos static  int	sskbd_ioctl(void *, u_long, caddr_t, int, struct lwp *);
    234      1.1       bsh static	int	sskbd_atn_intr(void *);
    235      1.1       bsh static	int	sskbd_spi_intr(void *);
    236      1.1       bsh static	void	sskbd_soft_intr(void *);
    237      1.1       bsh 
    238      1.1       bsh const struct wskbd_accessops sskbd_accessops = {
    239      1.1       bsh 	sskbd_enable,
    240      1.1       bsh 	sskbd_set_leds,
    241      1.1       bsh 	sskbd_ioctl,
    242      1.1       bsh };
    243      1.1       bsh 
    244      1.1       bsh #if 0
    245      1.1       bsh void	sskbd_cngetc(void *, u_int *, int *);
    246      1.1       bsh void	sskbd_cnpollc(void *, int);
    247      1.1       bsh void	sskbd_cnbell(void *, u_int, u_int, u_int);
    248      1.1       bsh 
    249      1.1       bsh const struct wskbd_consops sskbd_consops = {
    250      1.1       bsh 	sskbd_cngetc,
    251      1.1       bsh 	sskbd_cnpollc,
    252      1.1       bsh 	sskbd_cnbell,
    253      1.1       bsh };
    254      1.1       bsh #endif
    255      1.1       bsh 
    256      1.1       bsh int
    257      1.1       bsh sskbd_match(struct device *parent, struct cfdata *cf, void *aux)
    258      1.1       bsh {
    259      1.1       bsh 	return 1;
    260      1.1       bsh }
    261      1.1       bsh 
    262      1.1       bsh void
    263      1.1       bsh sskbd_attach(struct device *parent, struct device *self, void *aux)
    264      1.1       bsh {
    265      1.1       bsh 	struct sskbd_softc *sc = (void *)self;
    266      1.1       bsh 	struct ssspi_attach_args *spia = aux;
    267      1.1       bsh 	uint32_t reg;
    268      1.1       bsh 	bus_space_handle_t gpioh;
    269      1.1       bsh 	bus_space_tag_t iot;
    270      1.1       bsh 	struct wskbddev_attach_args a;
    271      1.1       bsh 
    272      1.1       bsh 	aprint_normal("\n");
    273      1.1       bsh 
    274      1.1       bsh 	sc->iot = iot = spia->spia_iot;
    275      1.1       bsh 	sc->ioh = spia->spia_ioh;
    276      1.1       bsh 	sc->gpioh = gpioh = spia->spia_gpioh;
    277      1.1       bsh 
    278      1.1       bsh 	/* enable pullup register for MISO */
    279      1.1       bsh 	reg = bus_space_read_2(iot, gpioh, GPIO_PGUP);
    280      1.1       bsh 	bus_space_write_2(iot, gpioh, GPIO_PGUP, reg & ~(1<<5));
    281      1.1       bsh 
    282      1.1       bsh 	/* nSS and wakeup */
    283      1.1       bsh 	bus_space_write_2(iot, gpioh, GPIO_PBDAT,
    284      1.1       bsh 			  (1<<SSKBD_SS) | (1<<SSKBD_WUP) |
    285      1.1       bsh 			  bus_space_read_2(iot, gpioh, GPIO_PBDAT));
    286      1.1       bsh 	reg = bus_space_read_4(iot, gpioh, GPIO_PBCON);
    287      1.1       bsh 	reg = GPIO_SET_FUNC(reg, SSKBD_WUP, PCON_OUTPUT);
    288      1.1       bsh 	reg = GPIO_SET_FUNC(reg, SSKBD_SS, PCON_OUTPUT);
    289      1.1       bsh 	bus_space_write_4(iot, gpioh, GPIO_PBCON, reg);
    290      1.1       bsh 
    291      1.1       bsh 	/* nATN input to EINT1 */
    292      1.1       bsh 	reg = bus_space_read_4(iot, gpioh, GPIO_PFCON);
    293      1.1       bsh 	reg = GPIO_SET_FUNC(reg, 1, PCON_ALTFUN);
    294      1.1       bsh 	bus_space_write_4(iot, gpioh, GPIO_PFCON, reg);
    295      1.1       bsh 
    296      1.1       bsh #if 0 	/*  Controller doesn't seem to respond to this. */
    297      1.1       bsh 
    298      1.1       bsh 	/* wakeup pulse */
    299      1.1       bsh 	reg = bus_space_read_4(iot, gpioh, GPIO_PBDAT);
    300      1.1       bsh 	reg &= ~(1<<SSKBD_WUP);
    301      1.1       bsh 	bus_space_write_4(iot, gpioh, GPIO_PBDAT, reg);
    302      1.1       bsh 	delay(100);
    303      1.1       bsh 	reg |= (1<<SSKBD_WUP);
    304      1.1       bsh 	bus_space_write_4(iot, gpioh, GPIO_PBDAT, reg);
    305      1.1       bsh 
    306      1.1       bsh 	delay(1000);
    307      1.1       bsh 
    308      1.1       bsh 	/* Send initialize command. */
    309      1.1       bsh 	sskbd_send(sc, KCDR_ESC);
    310      1.1       bsh 	sskbd_send(sc, KCDR_INITIALIZE);
    311      1.1       bsh 	sskbd_send(sc, 0x7b);
    312      1.1       bsh #endif
    313      1.1       bsh 
    314      1.1       bsh 	sc->inptr = sc->outptr = 0;
    315      1.1       bsh 	sc->reading = sc->enable = 0;
    316      1.1       bsh 
    317      1.1       bsh 	sc->atn_ih = s3c24x0_intr_establish(spia->spia_aux_intr, IPL_TTY,
    318      1.1       bsh 	    IST_EDGE_FALLING, sskbd_atn_intr, sc);
    319      1.1       bsh 
    320      1.1       bsh 	sc->spi_ih = s3c24x0_intr_establish(spia->spia_intr, IPL_SERIAL,
    321      1.1       bsh 	    0, sskbd_spi_intr, sc);
    322      1.1       bsh 
    323      1.1       bsh 	sc->soft_ih = softintr_establish(IPL_SOFTSERIAL, sskbd_soft_intr,
    324      1.1       bsh 	    sc);
    325      1.1       bsh 
    326      1.1       bsh 	if (sc->atn_ih == NULL || sc->spi_ih == NULL)
    327      1.1       bsh 		aprint_error("%s: can't establish interrupt handler\n",
    328      1.1       bsh 		    sc->dev.dv_xname);
    329      1.1       bsh 
    330      1.1       bsh 	/* setup SPI control register, and prescaler */
    331  1.2.4.1    rpaulo 	s3c24x0_spi_setup((struct ssspi_softc *)device_parent(self),
    332      1.1       bsh 			  SPCON_SMOD_INT | SPCON_ENSCK |
    333      1.1       bsh 			  SPCON_MSTR | SPCON_IDLELOW_RISING,
    334      1.1       bsh 			  100*1000, 0);
    335      1.1       bsh 
    336      1.1       bsh 
    337      1.1       bsh 	/* Attach the wskbd. */
    338      1.1       bsh 	a.console = 0;
    339      1.1       bsh 	a.keymap = &sskbd_keymapdata;
    340      1.1       bsh 	a.accessops = &sskbd_accessops;
    341      1.1       bsh 	a.accesscookie = sc;
    342      1.1       bsh 
    343      1.1       bsh 	sc->wskbddev = config_found(self, &a, wskbddevprint);
    344      1.1       bsh }
    345      1.1       bsh 
    346      1.1       bsh 
    347      1.1       bsh /*
    348      1.1       bsh  * Interrupt handler for nATN signal.
    349      1.1       bsh  */
    350      1.1       bsh static int
    351      1.1       bsh sskbd_atn_intr(void *arg)
    352      1.1       bsh {
    353      1.1       bsh 	struct sskbd_softc *sc = arg;
    354      1.1       bsh 	int s;
    355      1.1       bsh 	uint32_t reg;
    356      1.1       bsh 
    357      1.1       bsh 	/* make sure SPI transmitter is ready */
    358      1.1       bsh 	if (!(bus_space_read_1(sc->iot, sc->ioh, SPI_SPSTA) & SPSTA_REDY))
    359      1.1       bsh 		return 1;
    360      1.1       bsh 
    361      1.1       bsh 
    362      1.1       bsh 	if (advance_ring_ptr(sc->inptr) == sc->outptr) {
    363      1.1       bsh 		/* ring buffer is full. ignore this nATN signale */
    364      1.1       bsh 		softintr_schedule(sc->soft_ih);
    365      1.1       bsh 		return 1;
    366      1.1       bsh 	}
    367      1.1       bsh 
    368      1.1       bsh 	/* nSS = L */
    369      1.1       bsh 	s = splserial();
    370      1.1       bsh 	sc->reading = 1;
    371      1.1       bsh 	reg = bus_space_read_2(sc->iot, sc->gpioh, GPIO_PBDAT);
    372      1.1       bsh 	bus_space_write_2(sc->iot, sc->gpioh, GPIO_PBDAT,
    373      1.1       bsh 	    reg & ~(1<<SSKBD_SS));
    374      1.1       bsh 
    375      1.1       bsh 	/* generate clock to receive data from the controller */
    376      1.1       bsh 	bus_space_write_1(sc->iot, sc->ioh, SPI_SPTDAT, 0xff);
    377      1.1       bsh 
    378      1.1       bsh 	splx(s);
    379      1.1       bsh 
    380      1.1       bsh 	return 1;
    381      1.1       bsh }
    382      1.1       bsh 
    383      1.1       bsh /*
    384      1.1       bsh  * Interrupt handler for SPI rx
    385      1.1       bsh  */
    386      1.1       bsh static int
    387      1.1       bsh sskbd_spi_intr(void *arg)
    388      1.1       bsh {
    389      1.1       bsh 	struct sskbd_softc *sc = arg;
    390      1.1       bsh 	int data;
    391      1.1       bsh 	uint32_t reg;
    392      1.1       bsh 
    393      1.1       bsh 	if (sc->reading == 0)
    394      1.1       bsh 		return 1;	/* Ignore garbate input. */
    395      1.1       bsh 
    396      1.1       bsh 	sc->reading = 0;
    397      1.1       bsh 
    398      1.1       bsh 	data = bus_space_read_1(sc->iot, sc->ioh, SPI_SPRDAT);
    399      1.1       bsh 
    400      1.1       bsh 	/* nSS = H */
    401      1.1       bsh 	reg = bus_space_read_2(sc->iot, sc->gpioh, GPIO_PBDAT);
    402      1.1       bsh 	bus_space_write_2(sc->iot, sc->gpioh, GPIO_PBDAT,
    403      1.1       bsh 	    reg | (1<<SSKBD_SS));
    404      1.1       bsh 
    405      1.1       bsh 	if (sc->enable) {
    406      1.1       bsh 		sc->ring[sc->inptr] = data;
    407      1.1       bsh 		sc->inptr = advance_ring_ptr(sc->inptr);
    408      1.1       bsh 
    409      1.1       bsh 		softintr_schedule(sc->soft_ih);
    410      1.1       bsh 	}
    411      1.1       bsh #ifdef KBD_DEBUG
    412      1.1       bsh 	else {
    413      1.1       bsh 		printf("discard %x\n", data);
    414      1.1       bsh 	}
    415      1.1       bsh #endif
    416      1.1       bsh 
    417      1.1       bsh 	return 1;
    418      1.1       bsh }
    419      1.1       bsh 
    420      1.1       bsh static void
    421      1.1       bsh sskbd_soft_intr(void *arg)
    422      1.1       bsh {
    423      1.1       bsh 	struct sskbd_softc *sc = arg;
    424      1.1       bsh 	int key, up;
    425      1.1       bsh 
    426      1.1       bsh 	while (sc->outptr != sc->inptr) {
    427      1.1       bsh 		key = sc->ring[sc->outptr];
    428      1.1       bsh 		sc->outptr = advance_ring_ptr(sc->outptr);
    429      1.1       bsh 
    430      1.1       bsh 		up = key & 0x80;
    431      1.1       bsh 		key &= ~0x80;
    432      1.1       bsh 
    433      1.1       bsh 		key -= 1;
    434      1.1       bsh 		if (key < 0 || 8*14 < key)
    435      1.1       bsh 			continue;
    436      1.1       bsh 
    437      1.1       bsh #ifdef KBD_DEBUG
    438      1.1       bsh 		printf("key %d %s\n", key, up ? "up" : "down");
    439      1.1       bsh #endif
    440      1.1       bsh 		wskbd_input(sc->wskbddev,
    441      1.1       bsh 		    up ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN,
    442      1.1       bsh 		    key);
    443      1.1       bsh 	}
    444      1.1       bsh }
    445      1.1       bsh 
    446      1.1       bsh static int
    447      1.1       bsh sskbd_enable(void *v, int on)
    448      1.1       bsh {
    449      1.1       bsh 	struct sskbd_softc *sc = v;
    450      1.1       bsh 
    451      1.1       bsh #ifdef KBD_DEBUG
    452      1.1       bsh 	printf("%s: enable\n", sc->dev.dv_xname);
    453      1.1       bsh #endif
    454      1.1       bsh 
    455      1.1       bsh #if 0
    456      1.1       bsh 	if (!on && isconsole(sc))
    457      1.1       bsh 		return EBUSY;
    458      1.1       bsh #endif
    459      1.1       bsh 
    460      1.1       bsh 	sc->enable = on;
    461      1.1       bsh 	return (0);
    462      1.1       bsh }
    463      1.1       bsh 
    464      1.1       bsh 
    465      1.1       bsh static void
    466      1.1       bsh sskbd_set_leds(void *v, int leds)
    467      1.1       bsh {
    468      1.1       bsh }
    469      1.1       bsh 
    470      1.1       bsh static int
    471      1.2  christos sskbd_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct lwp *l)
    472      1.1       bsh {
    473      1.1       bsh 	/*struct sskbd_softc *sc = v;*/
    474      1.1       bsh 
    475      1.1       bsh 	switch (cmd) {
    476      1.1       bsh 	    case WSKBDIO_GTYPE:
    477      1.1       bsh 		*(int *)data = WSKBD_TYPE_HPC_KBD; /* XXX */
    478      1.1       bsh 		return 0;
    479      1.1       bsh 	    case WSKBDIO_COMPLEXBELL:
    480      1.1       bsh #ifdef notyet
    481      1.1       bsh #define d ((struct wskbd_bell_data *)data)
    482      1.1       bsh 		/*
    483      1.1       bsh 		 * Keyboard can't beep directly; we have an
    484      1.1       bsh 		 * externally-provided global hook to do this.
    485      1.1       bsh 		 */
    486      1.1       bsh 		sskbd_bell(d->pitch, d->period, d->volume, 0);
    487      1.1       bsh #undef d
    488      1.1       bsh #endif
    489      1.1       bsh 		return (0);
    490      1.1       bsh #ifdef WSDISPLAY_COMPAT_RAWKBD
    491      1.1       bsh 	    case WSKBDIO_SETMODE:
    492      1.1       bsh 		sc->rawkbd = (*(int *)data == WSKBD_RAW);
    493      1.1       bsh 		return (0);
    494      1.1       bsh #endif
    495      1.1       bsh 
    496      1.1       bsh #if 0
    497      1.1       bsh 	    case WSKBDIO_SETLEDS:
    498      1.1       bsh 	    case WSKBDIO_GETLEDS:
    499      1.1       bsh 		    /* no LED support */
    500      1.1       bsh #endif
    501      1.1       bsh 	}
    502      1.1       bsh 	return EPASSTHROUGH;
    503      1.1       bsh }
    504