Home | History | Annotate | Line # | Download | only in adb
adb_bt.c revision 1.1.36.2
      1  1.1.36.1       mjf /*	$NetBSD: adb_bt.c,v 1.1.36.2 2008/06/02 13:23:13 mjf Exp $ */
      2       1.1  macallan 
      3       1.1  macallan /*-
      4       1.1  macallan  * Copyright (c) 2006 Michael Lorenz
      5       1.1  macallan  * All rights reserved.
      6       1.1  macallan  *
      7       1.1  macallan  * Redistribution and use in source and binary forms, with or without
      8       1.1  macallan  * modification, are permitted provided that the following conditions
      9       1.1  macallan  * are met:
     10       1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     11       1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     12       1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1  macallan  *    notice, this list of conditions and the following disclaimer in the
     14       1.1  macallan  *    documentation and/or other materials provided with the distribution.
     15       1.1  macallan  *
     16       1.1  macallan  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17       1.1  macallan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18       1.1  macallan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19       1.1  macallan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20       1.1  macallan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21       1.1  macallan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22       1.1  macallan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23       1.1  macallan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24       1.1  macallan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25       1.1  macallan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26       1.1  macallan  * POSSIBILITY OF SUCH DAMAGE.
     27       1.1  macallan  */
     28       1.1  macallan 
     29       1.1  macallan #include <sys/cdefs.h>
     30  1.1.36.1       mjf __KERNEL_RCSID(0, "$NetBSD: adb_bt.c,v 1.1.36.2 2008/06/02 13:23:13 mjf Exp $");
     31       1.1  macallan 
     32       1.1  macallan #include <sys/param.h>
     33       1.1  macallan #include <sys/systm.h>
     34       1.1  macallan #include <sys/kernel.h>
     35       1.1  macallan #include <sys/device.h>
     36       1.1  macallan #include <sys/proc.h>
     37       1.1  macallan 
     38       1.1  macallan #include <machine/autoconf.h>
     39       1.1  macallan #include <machine/adbsys.h>
     40  1.1.36.2       mjf #include <machine/keyboard.h>
     41       1.1  macallan 
     42       1.1  macallan #include <dev/adb/adbvar.h>
     43       1.1  macallan 
     44       1.1  macallan #include "opt_wsdisplay_compat.h"
     45       1.1  macallan #include "adbdebug.h"
     46       1.1  macallan 
     47       1.1  macallan #ifdef ADBBT_DEBUG
     48       1.1  macallan #define DPRINTF printf
     49       1.1  macallan #else
     50       1.1  macallan #define DPRINTF while (0) printf
     51       1.1  macallan #endif
     52       1.1  macallan 
     53       1.1  macallan #define BT_VOL_UP	0x06
     54       1.1  macallan #define BT_VOL_DOWN	0x07
     55       1.1  macallan #define BT_VOL_MUTE	0x08
     56       1.1  macallan #define BT_BRT_UP	0x09
     57       1.1  macallan #define BT_BRT_DOWN	0x0a
     58       1.1  macallan #define BT_EJECT	0x0b
     59       1.1  macallan #define BT_F7		0x0c
     60       1.1  macallan #define BT_NUMLOCK	0x7f
     61       1.1  macallan 
     62  1.1.36.1       mjf static int adbbt_match(device_t, cfdata_t, void *);
     63  1.1.36.1       mjf static void adbbt_attach(device_t, device_t, void *);
     64       1.1  macallan 
     65       1.1  macallan struct adbbt_softc {
     66  1.1.36.1       mjf 	device_t sc_dev;
     67       1.1  macallan 	struct adb_device *sc_adbdev;
     68       1.1  macallan 	struct adb_bus_accessops *sc_ops;
     69       1.1  macallan 	int sc_msg_len;
     70       1.1  macallan 	int sc_event;
     71       1.1  macallan 	uint8_t sc_buffer[16];
     72       1.1  macallan 	uint8_t sc_us;
     73       1.1  macallan };
     74       1.1  macallan 
     75       1.1  macallan /* Driver definition. */
     76  1.1.36.1       mjf CFATTACH_DECL_NEW(adbbt, sizeof(struct adbbt_softc),
     77       1.1  macallan     adbbt_match, adbbt_attach, NULL, NULL);
     78       1.1  macallan 
     79       1.1  macallan extern struct cfdriver adbbt_cd;
     80       1.1  macallan 
     81       1.1  macallan static void adbbt_handler(void *, int, uint8_t *);
     82       1.1  macallan 
     83       1.1  macallan static int
     84  1.1.36.1       mjf adbbt_match(device_t parent, cfdata_t cf, void *aux)
     85       1.1  macallan {
     86       1.1  macallan 	struct adb_attach_args *aaa = aux;
     87       1.1  macallan 
     88       1.1  macallan 	if ((aaa->dev->original_addr == ADBADDR_MISC) &&
     89       1.1  macallan 	    (aaa->dev->handler_id == 0x1f))
     90       1.1  macallan 		return 100;
     91       1.1  macallan 	else
     92       1.1  macallan 		return 0;
     93       1.1  macallan }
     94       1.1  macallan 
     95       1.1  macallan static void
     96  1.1.36.1       mjf adbbt_attach(device_t parent, device_t self, void *aux)
     97       1.1  macallan {
     98  1.1.36.1       mjf 	struct adbbt_softc *sc = device_private(self);
     99       1.1  macallan 	struct adb_attach_args *aaa = aux;
    100       1.1  macallan 
    101  1.1.36.1       mjf 	sc->sc_dev = self;
    102       1.1  macallan 	sc->sc_ops = aaa->ops;
    103       1.1  macallan 	sc->sc_adbdev = aaa->dev;
    104       1.1  macallan 	sc->sc_adbdev->cookie = sc;
    105       1.1  macallan 	sc->sc_adbdev->handler = adbbt_handler;
    106       1.1  macallan 	sc->sc_us = ADBTALK(sc->sc_adbdev->current_addr, 0);
    107       1.1  macallan 
    108       1.1  macallan 	sc->sc_msg_len = 0;
    109       1.1  macallan 
    110       1.1  macallan 	printf(" addr %d: button device\n", sc->sc_adbdev->current_addr);
    111       1.1  macallan }
    112       1.1  macallan 
    113       1.1  macallan static void
    114       1.1  macallan adbbt_handler(void *cookie, int len, uint8_t *data)
    115       1.1  macallan {
    116  1.1.36.2       mjf 	/* struct adbbt_softc *sc = cookie; */
    117  1.1.36.2       mjf 	uint8_t k, scancode;
    118       1.1  macallan 
    119       1.1  macallan #ifdef ADBBT_DEBUG
    120       1.1  macallan 	int i;
    121  1.1.36.2       mjf 	printf("%s: %02x - ", device_xname(&sc->sc_dev), sc->sc_us);
    122       1.1  macallan 	for (i = 0; i < len; i++) {
    123       1.1  macallan 		printf(" %02x", data[i]);
    124       1.1  macallan 	}
    125       1.1  macallan 	printf("\n");
    126       1.1  macallan #endif
    127       1.1  macallan 	k = data[2];
    128  1.1.36.2       mjf 	scancode = ADBK_KEYVAL(k);
    129  1.1.36.2       mjf 	if ((scancode < 6) || (scancode > 0x0c))
    130       1.1  macallan 		return;
    131       1.1  macallan 
    132  1.1.36.2       mjf 	if (ADBK_PRESS(k)) {
    133       1.1  macallan 
    134  1.1.36.2       mjf 		switch (scancode) {
    135  1.1.36.2       mjf 			case BT_VOL_UP:
    136  1.1.36.2       mjf 				pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_UP);
    137  1.1.36.2       mjf 				break;
    138  1.1.36.2       mjf 			case BT_VOL_DOWN:
    139  1.1.36.2       mjf 				pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_DOWN);
    140  1.1.36.2       mjf 				break;
    141  1.1.36.2       mjf 			case BT_VOL_MUTE:
    142  1.1.36.2       mjf 				pmf_event_inject(NULL,
    143  1.1.36.2       mjf 				    PMFE_AUDIO_VOLUME_TOGGLE);
    144  1.1.36.2       mjf 				break;
    145  1.1.36.2       mjf 			case BT_BRT_UP:
    146  1.1.36.2       mjf 				pmf_event_inject(NULL,
    147  1.1.36.2       mjf 				    PMFE_DISPLAY_BRIGHTNESS_UP);
    148  1.1.36.2       mjf 				break;
    149  1.1.36.2       mjf 			case BT_BRT_DOWN:
    150  1.1.36.2       mjf 				pmf_event_inject(NULL,
    151  1.1.36.2       mjf 				    PMFE_DISPLAY_BRIGHTNESS_DOWN);
    152  1.1.36.2       mjf 				break;
    153  1.1.36.2       mjf 		}
    154       1.1  macallan 	}
    155       1.1  macallan }
    156