adb_bt.c revision 1.3.4.3 1 1.3.4.3 yamt /* $NetBSD: adb_bt.c,v 1.3.4.3 2010/10/09 03:32:04 yamt 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.3.4.3 yamt __KERNEL_RCSID(0, "$NetBSD: adb_bt.c,v 1.3.4.3 2010/10/09 03:32:04 yamt 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.3.4.2 yamt #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.2 matt static int adbbt_match(device_t, cfdata_t, void *);
63 1.2 matt static void adbbt_attach(device_t, device_t, void *);
64 1.1 macallan
65 1.1 macallan struct adbbt_softc {
66 1.2 matt 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.2 matt 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.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.3.4.2 yamt /* struct adbbt_softc *sc = cookie; */
117 1.3.4.2 yamt uint8_t k, scancode;
118 1.1 macallan
119 1.1 macallan #ifdef ADBBT_DEBUG
120 1.3.4.3 yamt struct adbbt_softc *sc = cookie;
121 1.1 macallan int i;
122 1.3.4.3 yamt 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.3.4.2 yamt scancode = ADBK_KEYVAL(k);
130 1.3.4.2 yamt if ((scancode < 6) || (scancode > 0x0c))
131 1.1 macallan return;
132 1.1 macallan
133 1.3.4.2 yamt if (ADBK_PRESS(k)) {
134 1.1 macallan
135 1.3.4.2 yamt switch (scancode) {
136 1.3.4.2 yamt case BT_VOL_UP:
137 1.3.4.2 yamt pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_UP);
138 1.3.4.2 yamt break;
139 1.3.4.2 yamt case BT_VOL_DOWN:
140 1.3.4.2 yamt pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_DOWN);
141 1.3.4.2 yamt break;
142 1.3.4.2 yamt case BT_VOL_MUTE:
143 1.3.4.2 yamt pmf_event_inject(NULL,
144 1.3.4.2 yamt PMFE_AUDIO_VOLUME_TOGGLE);
145 1.3.4.2 yamt break;
146 1.3.4.2 yamt case BT_BRT_UP:
147 1.3.4.2 yamt pmf_event_inject(NULL,
148 1.3.4.2 yamt PMFE_DISPLAY_BRIGHTNESS_UP);
149 1.3.4.2 yamt break;
150 1.3.4.2 yamt case BT_BRT_DOWN:
151 1.3.4.2 yamt pmf_event_inject(NULL,
152 1.3.4.2 yamt PMFE_DISPLAY_BRIGHTNESS_DOWN);
153 1.3.4.2 yamt break;
154 1.3.4.2 yamt }
155 1.1 macallan }
156 1.1 macallan }
157