Home | History | Annotate | Line # | Download | only in adb
adb_bt.c revision 1.1.2.2
      1  1.1.2.2  yamt /*	$NetBSD: adb_bt.c,v 1.1.2.2 2007/05/07 10:55:24 yamt Exp $ */
      2  1.1.2.2  yamt 
      3  1.1.2.2  yamt /*-
      4  1.1.2.2  yamt  * Copyright (c) 2006 Michael Lorenz
      5  1.1.2.2  yamt  * All rights reserved.
      6  1.1.2.2  yamt  *
      7  1.1.2.2  yamt  * Redistribution and use in source and binary forms, with or without
      8  1.1.2.2  yamt  * modification, are permitted provided that the following conditions
      9  1.1.2.2  yamt  * are met:
     10  1.1.2.2  yamt  * 1. Redistributions of source code must retain the above copyright
     11  1.1.2.2  yamt  *    notice, this list of conditions and the following disclaimer.
     12  1.1.2.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1.2.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     14  1.1.2.2  yamt  *    documentation and/or other materials provided with the distribution.
     15  1.1.2.2  yamt  * 3. Neither the name of The NetBSD Foundation nor the names of its
     16  1.1.2.2  yamt  *    contributors may be used to endorse or promote products derived
     17  1.1.2.2  yamt  *    from this software without specific prior written permission.
     18  1.1.2.2  yamt  *
     19  1.1.2.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1.2.2  yamt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1.2.2  yamt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1.2.2  yamt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1.2.2  yamt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1.2.2  yamt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1.2.2  yamt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1.2.2  yamt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1.2.2  yamt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1.2.2  yamt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1.2.2  yamt  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1.2.2  yamt  */
     31  1.1.2.2  yamt 
     32  1.1.2.2  yamt #include <sys/cdefs.h>
     33  1.1.2.2  yamt __KERNEL_RCSID(0, "$NetBSD: adb_bt.c,v 1.1.2.2 2007/05/07 10:55:24 yamt Exp $");
     34  1.1.2.2  yamt 
     35  1.1.2.2  yamt #include <sys/param.h>
     36  1.1.2.2  yamt #include <sys/systm.h>
     37  1.1.2.2  yamt #include <sys/kernel.h>
     38  1.1.2.2  yamt #include <sys/device.h>
     39  1.1.2.2  yamt #include <sys/proc.h>
     40  1.1.2.2  yamt 
     41  1.1.2.2  yamt #include <dev/wscons/wsconsio.h>
     42  1.1.2.2  yamt #include <dev/wscons/wskbdvar.h>
     43  1.1.2.2  yamt #include <dev/wscons/wsksymdef.h>
     44  1.1.2.2  yamt #include <dev/wscons/wsksymvar.h>
     45  1.1.2.2  yamt #include <dev/wscons/wsmousevar.h>
     46  1.1.2.2  yamt 
     47  1.1.2.2  yamt #include <dev/sysmon/sysmonvar.h>
     48  1.1.2.2  yamt #include <dev/sysmon/sysmon_taskq.h>
     49  1.1.2.2  yamt 
     50  1.1.2.2  yamt #include <machine/autoconf.h>
     51  1.1.2.2  yamt #include <machine/keyboard.h>
     52  1.1.2.2  yamt #include <machine/adbsys.h>
     53  1.1.2.2  yamt 
     54  1.1.2.2  yamt #include <dev/adb/adbvar.h>
     55  1.1.2.2  yamt #include <dev/adb/adb_keymap.h>
     56  1.1.2.2  yamt 
     57  1.1.2.2  yamt #include "opt_wsdisplay_compat.h"
     58  1.1.2.2  yamt #include "adbdebug.h"
     59  1.1.2.2  yamt 
     60  1.1.2.2  yamt #ifdef ADBBT_DEBUG
     61  1.1.2.2  yamt #define DPRINTF printf
     62  1.1.2.2  yamt #else
     63  1.1.2.2  yamt #define DPRINTF while (0) printf
     64  1.1.2.2  yamt #endif
     65  1.1.2.2  yamt 
     66  1.1.2.2  yamt #define BT_VOL_UP	0x06
     67  1.1.2.2  yamt #define BT_VOL_DOWN	0x07
     68  1.1.2.2  yamt #define BT_VOL_MUTE	0x08
     69  1.1.2.2  yamt #define BT_BRT_UP	0x09
     70  1.1.2.2  yamt #define BT_BRT_DOWN	0x0a
     71  1.1.2.2  yamt #define BT_EJECT	0x0b
     72  1.1.2.2  yamt #define BT_F7		0x0c
     73  1.1.2.2  yamt #define BT_NUMLOCK	0x7f
     74  1.1.2.2  yamt 
     75  1.1.2.2  yamt static int adbbt_match(struct device *, struct cfdata *, void *);
     76  1.1.2.2  yamt static void adbbt_attach(struct device *, struct device *, void *);
     77  1.1.2.2  yamt 
     78  1.1.2.2  yamt struct adbbt_softc {
     79  1.1.2.2  yamt 	struct device sc_dev;
     80  1.1.2.2  yamt 	struct adb_device *sc_adbdev;
     81  1.1.2.2  yamt 	struct adb_bus_accessops *sc_ops;
     82  1.1.2.2  yamt 	struct device *sc_wskbddev;
     83  1.1.2.2  yamt 	int sc_msg_len;
     84  1.1.2.2  yamt 	int sc_event;
     85  1.1.2.2  yamt 	int sc_poll;
     86  1.1.2.2  yamt 	int sc_polled_chars;
     87  1.1.2.2  yamt 	int sc_rawkbd;
     88  1.1.2.2  yamt 	uint8_t sc_buffer[16];
     89  1.1.2.2  yamt 	uint8_t sc_pollbuf[16];
     90  1.1.2.2  yamt 	uint8_t sc_trans[16];
     91  1.1.2.2  yamt 	uint8_t sc_us;
     92  1.1.2.2  yamt };
     93  1.1.2.2  yamt 
     94  1.1.2.2  yamt /* Driver definition. */
     95  1.1.2.2  yamt CFATTACH_DECL(adbbt, sizeof(struct adbbt_softc),
     96  1.1.2.2  yamt     adbbt_match, adbbt_attach, NULL, NULL);
     97  1.1.2.2  yamt 
     98  1.1.2.2  yamt extern struct cfdriver adbbt_cd;
     99  1.1.2.2  yamt 
    100  1.1.2.2  yamt static int adbbt_enable(void *, int);
    101  1.1.2.2  yamt static void adbbt_set_leds(void *, int);
    102  1.1.2.2  yamt static int adbbt_ioctl(void *, u_long, void *, int, struct lwp *);
    103  1.1.2.2  yamt static void adbbt_handler(void *, int, uint8_t *);
    104  1.1.2.2  yamt 
    105  1.1.2.2  yamt struct wskbd_accessops adbbt_accessops = {
    106  1.1.2.2  yamt 	adbbt_enable,
    107  1.1.2.2  yamt 	adbbt_set_leds,
    108  1.1.2.2  yamt 	adbbt_ioctl,
    109  1.1.2.2  yamt };
    110  1.1.2.2  yamt 
    111  1.1.2.2  yamt struct wskbd_mapdata adbbt_keymapdata = {
    112  1.1.2.2  yamt 	akbd_keydesctab,
    113  1.1.2.2  yamt #ifdef AKBD_LAYOUT
    114  1.1.2.2  yamt 	AKBD_LAYOUT,
    115  1.1.2.2  yamt #else
    116  1.1.2.2  yamt 	KB_US,
    117  1.1.2.2  yamt #endif
    118  1.1.2.2  yamt };
    119  1.1.2.2  yamt 
    120  1.1.2.2  yamt static int
    121  1.1.2.2  yamt adbbt_match(parent, cf, aux)
    122  1.1.2.2  yamt 	struct device *parent;
    123  1.1.2.2  yamt 	struct cfdata *cf;
    124  1.1.2.2  yamt 	void   *aux;
    125  1.1.2.2  yamt {
    126  1.1.2.2  yamt 	struct adb_attach_args *aaa = aux;
    127  1.1.2.2  yamt 
    128  1.1.2.2  yamt 	if ((aaa->dev->original_addr == ADBADDR_MISC) &&
    129  1.1.2.2  yamt 	    (aaa->dev->handler_id == 0x1f))
    130  1.1.2.2  yamt 		return 100;
    131  1.1.2.2  yamt 	else
    132  1.1.2.2  yamt 		return 0;
    133  1.1.2.2  yamt }
    134  1.1.2.2  yamt 
    135  1.1.2.2  yamt static void
    136  1.1.2.2  yamt adbbt_attach(struct device *parent, struct device *self, void *aux)
    137  1.1.2.2  yamt {
    138  1.1.2.2  yamt 	struct adbbt_softc *sc = (struct adbbt_softc *)self;
    139  1.1.2.2  yamt 	struct adb_attach_args *aaa = aux;
    140  1.1.2.2  yamt 	struct wskbddev_attach_args a;
    141  1.1.2.2  yamt 
    142  1.1.2.2  yamt 	sc->sc_ops = aaa->ops;
    143  1.1.2.2  yamt 	sc->sc_adbdev = aaa->dev;
    144  1.1.2.2  yamt 	sc->sc_adbdev->cookie = sc;
    145  1.1.2.2  yamt 	sc->sc_adbdev->handler = adbbt_handler;
    146  1.1.2.2  yamt 	sc->sc_us = ADBTALK(sc->sc_adbdev->current_addr, 0);
    147  1.1.2.2  yamt 
    148  1.1.2.2  yamt 	sc->sc_msg_len = 0;
    149  1.1.2.2  yamt 	sc->sc_rawkbd = 0;
    150  1.1.2.2  yamt 	sc->sc_trans[6]  = 96;	/* F5  */
    151  1.1.2.2  yamt 	sc->sc_trans[7]  = 118;	/* F4  */
    152  1.1.2.2  yamt 	sc->sc_trans[8]  = 99;	/* F3  */
    153  1.1.2.2  yamt 	sc->sc_trans[9]  = 120;	/* F2  */
    154  1.1.2.2  yamt 	sc->sc_trans[10] = 122;	/* F1  */
    155  1.1.2.2  yamt 	sc->sc_trans[11] = 111;	/* F12 */
    156  1.1.2.2  yamt 
    157  1.1.2.2  yamt 	printf(" addr %d: button device\n", sc->sc_adbdev->current_addr);
    158  1.1.2.2  yamt 
    159  1.1.2.2  yamt 	a.console = 0;
    160  1.1.2.2  yamt 	a.keymap = &adbbt_keymapdata;
    161  1.1.2.2  yamt 	a.accessops = &adbbt_accessops;
    162  1.1.2.2  yamt 	a.accesscookie = sc;
    163  1.1.2.2  yamt 
    164  1.1.2.2  yamt 	sc->sc_wskbddev = config_found_ia(self, "wskbddev", &a, wskbddevprint);
    165  1.1.2.2  yamt }
    166  1.1.2.2  yamt 
    167  1.1.2.2  yamt static void
    168  1.1.2.2  yamt adbbt_handler(void *cookie, int len, uint8_t *data)
    169  1.1.2.2  yamt {
    170  1.1.2.2  yamt 	struct adbbt_softc *sc = cookie;
    171  1.1.2.2  yamt 	int type;
    172  1.1.2.2  yamt 	uint8_t k, keyval, scancode;
    173  1.1.2.2  yamt 
    174  1.1.2.2  yamt #ifdef ADBBT_DEBUG
    175  1.1.2.2  yamt 	int i;
    176  1.1.2.2  yamt 	printf("%s: %02x - ", sc->sc_dev.dv_xname, sc->sc_us);
    177  1.1.2.2  yamt 	for (i = 0; i < len; i++) {
    178  1.1.2.2  yamt 		printf(" %02x", data[i]);
    179  1.1.2.2  yamt 	}
    180  1.1.2.2  yamt 	printf("\n");
    181  1.1.2.2  yamt #endif
    182  1.1.2.2  yamt 	k = data[2];
    183  1.1.2.2  yamt 	keyval = ADBK_KEYVAL(k);
    184  1.1.2.2  yamt 	if ((keyval < 6) || (keyval > 0x0c))
    185  1.1.2.2  yamt 		return;
    186  1.1.2.2  yamt 	scancode = sc->sc_trans[keyval];
    187  1.1.2.2  yamt 
    188  1.1.2.2  yamt #ifdef WSDISPLAY_COMPAT_RAWKBD
    189  1.1.2.2  yamt 	if (sc->sc_rawkbd) {
    190  1.1.2.2  yamt 		char cbuf[2];
    191  1.1.2.2  yamt 		int s;
    192  1.1.2.2  yamt 
    193  1.1.2.2  yamt 		cbuf[0] = scancode | (k & 0x80);
    194  1.1.2.2  yamt 
    195  1.1.2.2  yamt 		s = spltty();
    196  1.1.2.2  yamt 		wskbd_rawinput(sc->sc_wskbddev, cbuf, 1);
    197  1.1.2.2  yamt 		splx(s);
    198  1.1.2.2  yamt 	} else {
    199  1.1.2.2  yamt #endif
    200  1.1.2.2  yamt 
    201  1.1.2.2  yamt 	/* normal event */
    202  1.1.2.2  yamt 	type = ADBK_PRESS(k) ?
    203  1.1.2.2  yamt 	    WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP;
    204  1.1.2.2  yamt 	wskbd_input(sc->sc_wskbddev, type, scancode);
    205  1.1.2.2  yamt #ifdef WSDISPLAY_COMPAT_RAWKBD
    206  1.1.2.2  yamt 	}
    207  1.1.2.2  yamt #endif
    208  1.1.2.2  yamt }
    209  1.1.2.2  yamt 
    210  1.1.2.2  yamt static void
    211  1.1.2.2  yamt adbbt_set_leds(void *cookie, int leds)
    212  1.1.2.2  yamt {
    213  1.1.2.2  yamt 	/* we have no LEDs */
    214  1.1.2.2  yamt }
    215  1.1.2.2  yamt 
    216  1.1.2.2  yamt static int
    217  1.1.2.2  yamt adbbt_enable(void *v, int on)
    218  1.1.2.2  yamt {
    219  1.1.2.2  yamt 	return 0;
    220  1.1.2.2  yamt }
    221  1.1.2.2  yamt 
    222  1.1.2.2  yamt static int
    223  1.1.2.2  yamt adbbt_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
    224  1.1.2.2  yamt {
    225  1.1.2.2  yamt #ifdef WSDISPLAY_COMPAT_RAWKBD
    226  1.1.2.2  yamt 	struct adbbt_softc *sc = (struct adbbt_softc *) v;
    227  1.1.2.2  yamt #endif
    228  1.1.2.2  yamt 
    229  1.1.2.2  yamt 	switch (cmd) {
    230  1.1.2.2  yamt 
    231  1.1.2.2  yamt 	case WSKBDIO_GTYPE:
    232  1.1.2.2  yamt 		*(int *)data = WSKBD_TYPE_ADB;
    233  1.1.2.2  yamt 		return 0;
    234  1.1.2.2  yamt #ifdef WSDISPLAY_COMPAT_RAWKBD
    235  1.1.2.2  yamt 	case WSKBDIO_SETMODE:
    236  1.1.2.2  yamt 		sc->sc_rawkbd = *(int *)data == WSKBD_RAW;
    237  1.1.2.2  yamt 		return 0;
    238  1.1.2.2  yamt #endif
    239  1.1.2.2  yamt 	}
    240  1.1.2.2  yamt 
    241  1.1.2.2  yamt 	return EPASSTHROUGH;
    242  1.1.2.2  yamt }
    243