Home | History | Annotate | Line # | Download | only in adb
adb_bt.c revision 1.6.18.1
      1  1.6.18.1  jdolecek /*	$NetBSD: adb_bt.c,v 1.6.18.1 2017/12/03 11:36:59 jdolecek 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.6.18.1  jdolecek __KERNEL_RCSID(0, "$NetBSD: adb_bt.c,v 1.6.18.1 2017/12/03 11:36:59 jdolecek 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.5  macallan #include <machine/adbsys.h>
     40       1.1  macallan #include <machine/keyboard.h>
     41       1.1  macallan 
     42       1.1  macallan #include <dev/adb/adbvar.h>
     43       1.1  macallan 
     44  1.6.18.1  jdolecek #include "ioconf.h"
     45  1.6.18.1  jdolecek 
     46       1.1  macallan #include "opt_wsdisplay_compat.h"
     47       1.1  macallan #include "adbdebug.h"
     48       1.1  macallan 
     49       1.1  macallan #ifdef ADBBT_DEBUG
     50       1.1  macallan #define DPRINTF printf
     51       1.1  macallan #else
     52       1.1  macallan #define DPRINTF while (0) printf
     53       1.1  macallan #endif
     54       1.1  macallan 
     55       1.1  macallan #define BT_VOL_UP	0x06
     56       1.1  macallan #define BT_VOL_DOWN	0x07
     57       1.1  macallan #define BT_VOL_MUTE	0x08
     58       1.1  macallan #define BT_BRT_UP	0x09
     59       1.1  macallan #define BT_BRT_DOWN	0x0a
     60       1.1  macallan #define BT_EJECT	0x0b
     61       1.1  macallan #define BT_F7		0x0c
     62       1.1  macallan #define BT_NUMLOCK	0x7f
     63       1.1  macallan 
     64       1.2      matt static int adbbt_match(device_t, cfdata_t, void *);
     65       1.2      matt static void adbbt_attach(device_t, device_t, void *);
     66       1.1  macallan 
     67       1.1  macallan struct adbbt_softc {
     68       1.2      matt 	device_t sc_dev;
     69       1.1  macallan 	struct adb_device *sc_adbdev;
     70       1.1  macallan 	struct adb_bus_accessops *sc_ops;
     71       1.1  macallan 	int sc_msg_len;
     72       1.1  macallan 	int sc_event;
     73       1.1  macallan 	uint8_t sc_buffer[16];
     74       1.1  macallan 	uint8_t sc_us;
     75       1.1  macallan };
     76       1.1  macallan 
     77       1.1  macallan /* Driver definition. */
     78       1.2      matt CFATTACH_DECL_NEW(adbbt, sizeof(struct adbbt_softc),
     79       1.1  macallan     adbbt_match, adbbt_attach, NULL, NULL);
     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.2      matt 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.2      matt adbbt_attach(device_t parent, device_t self, void *aux)
     97       1.1  macallan {
     98       1.2      matt 	struct adbbt_softc *sc = device_private(self);
     99       1.1  macallan 	struct adb_attach_args *aaa = aux;
    100       1.1  macallan 
    101       1.2      matt 	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.5  macallan 	/* struct adbbt_softc *sc = cookie; */
    117       1.5  macallan 	uint8_t k, scancode;
    118       1.1  macallan 
    119       1.1  macallan #ifdef ADBBT_DEBUG
    120       1.6  macallan 	struct adbbt_softc *sc = cookie;
    121       1.1  macallan 	int i;
    122       1.6  macallan 	printf("%s: %02x - ", device_xname(sc->sc_dev), sc->sc_us);
    123       1.1  macallan 	for (i = 0; i < len; i++) {
    124       1.1  macallan 		printf(" %02x", data[i]);
    125       1.1  macallan 	}
    126       1.1  macallan 	printf("\n");
    127       1.1  macallan #endif
    128       1.1  macallan 	k = data[2];
    129       1.5  macallan 	scancode = ADBK_KEYVAL(k);
    130       1.5  macallan 	if ((scancode < 6) || (scancode > 0x0c))
    131       1.1  macallan 		return;
    132       1.1  macallan 
    133       1.5  macallan 	if (ADBK_PRESS(k)) {
    134       1.1  macallan 
    135       1.5  macallan 		switch (scancode) {
    136       1.5  macallan 			case BT_VOL_UP:
    137       1.5  macallan 				pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_UP);
    138       1.5  macallan 				break;
    139       1.5  macallan 			case BT_VOL_DOWN:
    140       1.5  macallan 				pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_DOWN);
    141       1.5  macallan 				break;
    142       1.5  macallan 			case BT_VOL_MUTE:
    143       1.5  macallan 				pmf_event_inject(NULL,
    144       1.5  macallan 				    PMFE_AUDIO_VOLUME_TOGGLE);
    145       1.5  macallan 				break;
    146       1.5  macallan 			case BT_BRT_UP:
    147       1.5  macallan 				pmf_event_inject(NULL,
    148       1.5  macallan 				    PMFE_DISPLAY_BRIGHTNESS_UP);
    149       1.5  macallan 				break;
    150       1.5  macallan 			case BT_BRT_DOWN:
    151       1.5  macallan 				pmf_event_inject(NULL,
    152       1.5  macallan 				    PMFE_DISPLAY_BRIGHTNESS_DOWN);
    153       1.5  macallan 				break;
    154       1.5  macallan 		}
    155       1.1  macallan 	}
    156       1.1  macallan }
    157