Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / macppc / dev / abtn.c
blobc72fdae7922c207371870718a5b39b880710e245
1 /* $NetBSD: abtn.c,v 1.16 2009/03/14 15:36:09 dsl Exp $ */
3 /*-
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
8 * are met:
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
53 struct abtn_softc {
54 struct device sc_dev;
56 int origaddr; /* ADB device type */
57 int adbaddr; /* current ADB address */
58 int handler_id;
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);
71 int
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)
78 return 1;
80 return 0;
83 void
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;
89 int bright;
91 printf("buttons\n");
93 bright = pm_read_nvram(NVRAM_BRIGHTNESS);
94 if (bright != 0)
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;
110 void
111 abtn_adbcomplete(uint8_t *buffer, uint8_t *data, int adb_command)
113 struct abtn_softc *sc = (struct abtn_softc *)data;
114 u_int cmd;
115 #ifdef FORCE_FUNCTION_KEYS
116 int key = 0;
117 #endif
119 cmd = buffer[1];
121 #ifdef FORCE_FUNCTION_KEYS
122 switch (cmd & 0x7f) {
123 case 0x0a: /* f1 */
124 key = 122;
125 break;
126 case 0x09: /* f2 */
127 key = 120;
128 break;
129 case 0x08: /* f3 */
130 key = 99;
131 break;
132 case 0x07: /* f4 */
133 key = 118;
134 break;
135 case 0x06: /* f5 */
136 key = 96;
137 break;
138 case 0x7f: /* f6 */
139 key = 97;
140 break;
141 case 0x0b: /* f12 */
142 key = 111;
143 break;
145 if (key != 0) {
146 key |= cmd & 0x80;
147 kbd_passup(device_lookup_private(&akbd_cd, 0),key);
148 return;
150 #endif
152 if (cmd >= BUTTON_DEPRESS)
153 return;
155 switch (cmd) {
156 case BUTTON_DIMMER:
157 sc->brightness -= 8;
158 if (sc->brightness < 8)
159 sc->brightness = 8;
160 pm_set_brightness(sc->brightness);
161 pm_write_nvram(NVRAM_BRIGHTNESS, sc->brightness);
162 break;
164 case BUTTON_BRIGHTER:
165 sc->brightness += 8;
166 if (sc->brightness > 0x78)
167 sc->brightness = 0x78;
168 pm_set_brightness(sc->brightness);
169 pm_write_nvram(NVRAM_BRIGHTNESS, sc->brightness);
170 break;
172 case BUTTON_MUTE:
173 case BUTTON_SOFTER:
174 case BUTTON_LOUDER:
175 printf("%s: volume setting not implemented\n",
176 sc->sc_dev.dv_xname);
177 break;
178 case BUTTON_DISPLAY:
179 printf("%s: display selection not implemented\n",
180 sc->sc_dev.dv_xname);
181 break;
182 case BUTTON_EJECT:
183 printf("%s: eject not implemented\n",
184 sc->sc_dev.dv_xname);
185 break;
187 /* The keyboard gets wacky when in keypad mode. */
188 case BUTTON_KEYPAD:
189 break;
191 default:
192 printf("%s: unknown button 0x%x\n",
193 sc->sc_dev.dv_xname, cmd);