2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2011, Justin Hibbits.
5 * Copyright (c) 2002, Miodrag Vallat.
6 * Copyright (C) 1999 Tsubai Masanari. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * OpenBSD: abtn.c,v 1.12 2009/01/10 18:00:59 robert Exp
31 * NetBSD: abtn.c,v 1.1 1999/07/12 17:48:26 tsubai Exp
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/module.h>
39 #include <sys/kernel.h>
42 #include <machine/bus.h>
44 #include <dev/ofw/openfirm.h>
45 #include <machine/ofw_machdep.h>
47 #include <dev/adb/adb.h>
49 #define ABTN_HANDLER_ID 31
57 static int abtn_probe(device_t dev);
58 static int abtn_attach(device_t dev);
59 static u_int abtn_receive_packet(device_t dev, u_char status,
60 u_char command, u_char reg, int len, u_char *data);
62 static device_method_t abtn_methods[] = {
63 /* Device interface */
64 DEVMETHOD(device_probe, abtn_probe),
65 DEVMETHOD(device_attach, abtn_attach),
66 DEVMETHOD(device_shutdown, bus_generic_shutdown),
67 DEVMETHOD(device_suspend, bus_generic_suspend),
68 DEVMETHOD(device_resume, bus_generic_resume),
71 DEVMETHOD(adb_receive_packet, abtn_receive_packet),
75 static driver_t abtn_driver = {
78 sizeof(struct abtn_softc),
81 static devclass_t abtn_devclass;
83 DRIVER_MODULE(abtn, adb, abtn_driver, abtn_devclass, 0, 0);
86 abtn_probe(device_t dev)
90 type = adb_get_device_type(dev);
92 if (type != ADB_DEVICE_MISC)
95 device_set_desc(dev, "ADB Brightness/Volume/Eject Buttons");
100 abtn_attach(device_t dev)
102 struct abtn_softc *sc;
104 sc = device_get_softc(dev);
107 sc->handler_id = adb_get_device_handler(dev);
113 abtn_receive_packet(device_t dev, u_char status,
114 u_char command, u_char reg, int len, u_char *data)
121 case 0x0a: /* decrease brightness */
122 devctl_notify("PMU", "keys", "brightness",
126 case 0x09: /* increase brightness */
127 devctl_notify("PMU", "keys", "brightness", "notify=up");
130 case 0x08: /* mute */
131 case 0x01: /* mute, AV hardware */
132 devctl_notify("PMU", "keys", "mute", NULL);
134 case 0x07: /* decrease volume */
135 case 0x02: /* decrease volume, AV hardware */
136 devctl_notify("PMU", "keys", "volume", "notify=down");
138 case 0x06: /* increase volume */
139 case 0x03: /* increase volume, AV hardware */
140 devctl_notify("PMU", "keys", "volume", "notify=up");
142 case 0x0c: /* mirror display key */
143 /* Need callback to do something with this */
145 case 0x0b: /* eject tray */
146 devctl_notify("PMU", "keys", "eject", NULL);
148 case 0x7f: /* numlock */
149 /* Need callback to do something with this */
154 if ((cmd & ~0x7f) == 0)
155 device_printf(dev, "unknown ADB button 0x%x\n", cmd);