1 /* $NetBSD: abtn.c,v 1.16 2009/03/14 15:36:09 dsl Exp $ */
4 * Copyright (C) 1999 Tsubai Masanari. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: abtn.c,v 1.16 2009/03/14 15:36:09 dsl Exp $");
32 #include <sys/param.h>
33 #include <sys/device.h>
34 #include <sys/systm.h>
36 #include <macppc/dev/akbdvar.h>
37 #include <macppc/dev/adbvar.h>
38 #include <macppc/dev/pm_direct.h>
40 #define NVRAM_BRIGHTNESS 0x140e
41 #define ABTN_HANDLER_ID 31
43 #define BUTTON_LOUDER 0x06
44 #define BUTTON_SOFTER 0x07
45 #define BUTTON_MUTE 0x08
46 #define BUTTON_BRIGHTER 0x09
47 #define BUTTON_DIMMER 0x0a
48 #define BUTTON_EJECT 0x0b
49 #define BUTTON_DISPLAY 0x0c
50 #define BUTTON_KEYPAD 0x7f
51 #define BUTTON_DEPRESS 0x80
56 int origaddr
; /* ADB device type */
57 int adbaddr
; /* current ADB address */
60 int brightness
; /* backlight brightness */
61 int volume
; /* speaker volume (not yet) */
64 static int abtn_match(struct device
*, struct cfdata
*, void *);
65 static void abtn_attach(struct device
*, struct device
*, void *);
66 static void abtn_adbcomplete(uint8_t *, uint8_t *, int);
68 CFATTACH_DECL(abtn
, sizeof(struct abtn_softc
),
69 abtn_match
, abtn_attach
, NULL
, NULL
);
72 abtn_match(struct device
*parent
, struct cfdata
*cf
, void *aux
)
74 struct adb_attach_args
*aa
= aux
;
76 if (aa
->origaddr
== ADBADDR_MISC
&&
77 aa
->handler_id
== ABTN_HANDLER_ID
)
84 abtn_attach(struct device
*parent
, struct device
*self
, void *aux
)
86 struct abtn_softc
*sc
= (struct abtn_softc
*)self
;
87 struct adb_attach_args
*aa
= aux
;
88 ADBSetInfoBlock adbinfo
;
93 bright
= pm_read_nvram(NVRAM_BRIGHTNESS
);
95 pm_set_brightness(bright
);
96 sc
->brightness
= bright
;
98 sc
->origaddr
= aa
->origaddr
;
99 sc
->adbaddr
= aa
->adbaddr
;
100 sc
->handler_id
= aa
->handler_id
;
102 adbinfo
.siServiceRtPtr
= (Ptr
)abtn_adbcomplete
;
103 adbinfo
.siDataAreaAddr
= (void *)sc
;
105 SetADBInfo(&adbinfo
, sc
->adbaddr
);
108 extern struct cfdriver akbd_cd
;
111 abtn_adbcomplete(uint8_t *buffer
, uint8_t *data
, int adb_command
)
113 struct abtn_softc
*sc
= (struct abtn_softc
*)data
;
115 #ifdef FORCE_FUNCTION_KEYS
121 #ifdef FORCE_FUNCTION_KEYS
122 switch (cmd
& 0x7f) {
147 kbd_passup(device_lookup_private(&akbd_cd
, 0),key
);
152 if (cmd
>= BUTTON_DEPRESS
)
158 if (sc
->brightness
< 8)
160 pm_set_brightness(sc
->brightness
);
161 pm_write_nvram(NVRAM_BRIGHTNESS
, sc
->brightness
);
164 case BUTTON_BRIGHTER
:
166 if (sc
->brightness
> 0x78)
167 sc
->brightness
= 0x78;
168 pm_set_brightness(sc
->brightness
);
169 pm_write_nvram(NVRAM_BRIGHTNESS
, sc
->brightness
);
175 printf("%s: volume setting not implemented\n",
176 sc
->sc_dev
.dv_xname
);
179 printf("%s: display selection not implemented\n",
180 sc
->sc_dev
.dv_xname
);
183 printf("%s: eject not implemented\n",
184 sc
->sc_dev
.dv_xname
);
187 /* The keyboard gets wacky when in keypad mode. */
192 printf("%s: unknown button 0x%x\n",
193 sc
->sc_dev
.dv_xname
, cmd
);