abtn.c revision 1.1.2.2 1 1.1.2.2 thorpej /* $NetBSD: abtn.c,v 1.1.2.2 1999/08/02 19:55:12 thorpej Exp $ */
2 1.1.2.2 thorpej
3 1.1.2.2 thorpej /*-
4 1.1.2.2 thorpej * Copyright (C) 1999 Tsubai Masanari. All rights reserved.
5 1.1.2.2 thorpej *
6 1.1.2.2 thorpej * Redistribution and use in source and binary forms, with or without
7 1.1.2.2 thorpej * modification, are permitted provided that the following conditions
8 1.1.2.2 thorpej * are met:
9 1.1.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
10 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer.
11 1.1.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
12 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
13 1.1.2.2 thorpej * documentation and/or other materials provided with the distribution.
14 1.1.2.2 thorpej * 3. The name of the author may not be used to endorse or promote products
15 1.1.2.2 thorpej * derived from this software without specific prior written permission.
16 1.1.2.2 thorpej *
17 1.1.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1.2.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1.2.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1.2.2 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1.2.2 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1.2.2 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1.2.2 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1.2.2 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1.2.2 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 1.1.2.2 thorpej * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1.2.2 thorpej */
28 1.1.2.2 thorpej
29 1.1.2.2 thorpej #include <sys/param.h>
30 1.1.2.2 thorpej #include <sys/device.h>
31 1.1.2.2 thorpej #include <sys/systm.h>
32 1.1.2.2 thorpej
33 1.1.2.2 thorpej #include <macppc/dev/adbvar.h>
34 1.1.2.2 thorpej
35 1.1.2.2 thorpej #define NVRAM_BRIGHTNESS 0x140e
36 1.1.2.2 thorpej #define ABTN_HANDLER_ID 31
37 1.1.2.2 thorpej
38 1.1.2.2 thorpej struct abtn_softc {
39 1.1.2.2 thorpej struct device sc_dev;
40 1.1.2.2 thorpej
41 1.1.2.2 thorpej int origaddr; /* ADB device type */
42 1.1.2.2 thorpej int adbaddr; /* current ADB address */
43 1.1.2.2 thorpej int handler_id;
44 1.1.2.2 thorpej
45 1.1.2.2 thorpej int brightness; /* backlight brightness */
46 1.1.2.2 thorpej int volume; /* speaker volume (not yet) */
47 1.1.2.2 thorpej };
48 1.1.2.2 thorpej
49 1.1.2.2 thorpej static int abtn_match __P((struct device *, struct cfdata *, void *));
50 1.1.2.2 thorpej static void abtn_attach __P((struct device *, struct device *, void *));
51 1.1.2.2 thorpej static void abtn_adbcomplete __P((caddr_t, caddr_t, int));
52 1.1.2.2 thorpej
53 1.1.2.2 thorpej struct cfattach abtn_ca = {
54 1.1.2.2 thorpej sizeof(struct abtn_softc), abtn_match, abtn_attach
55 1.1.2.2 thorpej };
56 1.1.2.2 thorpej
57 1.1.2.2 thorpej int
58 1.1.2.2 thorpej abtn_match(parent, cf, aux)
59 1.1.2.2 thorpej struct device *parent;
60 1.1.2.2 thorpej struct cfdata *cf;
61 1.1.2.2 thorpej void *aux;
62 1.1.2.2 thorpej {
63 1.1.2.2 thorpej struct adb_attach_args *aa = aux;
64 1.1.2.2 thorpej
65 1.1.2.2 thorpej if (aa->origaddr == ADBADDR_MISC &&
66 1.1.2.2 thorpej aa->handler_id == ABTN_HANDLER_ID)
67 1.1.2.2 thorpej return 1;
68 1.1.2.2 thorpej
69 1.1.2.2 thorpej return 0;
70 1.1.2.2 thorpej }
71 1.1.2.2 thorpej
72 1.1.2.2 thorpej void
73 1.1.2.2 thorpej abtn_attach(parent, self, aux)
74 1.1.2.2 thorpej struct device *parent, *self;
75 1.1.2.2 thorpej void *aux;
76 1.1.2.2 thorpej {
77 1.1.2.2 thorpej struct abtn_softc *sc = (struct abtn_softc *)self;
78 1.1.2.2 thorpej struct adb_attach_args *aa = aux;
79 1.1.2.2 thorpej ADBSetInfoBlock adbinfo;
80 1.1.2.2 thorpej int bright;
81 1.1.2.2 thorpej
82 1.1.2.2 thorpej printf("brightness/volume button\n");
83 1.1.2.2 thorpej
84 1.1.2.2 thorpej bright = pm_read_nvram(NVRAM_BRIGHTNESS);
85 1.1.2.2 thorpej pm_set_brightness(bright);
86 1.1.2.2 thorpej sc->brightness = bright;
87 1.1.2.2 thorpej
88 1.1.2.2 thorpej sc->origaddr = aa->origaddr;
89 1.1.2.2 thorpej sc->adbaddr = aa->adbaddr;
90 1.1.2.2 thorpej sc->handler_id = aa->handler_id;
91 1.1.2.2 thorpej
92 1.1.2.2 thorpej adbinfo.siServiceRtPtr = (Ptr)abtn_adbcomplete;
93 1.1.2.2 thorpej adbinfo.siDataAreaAddr = (caddr_t)sc;
94 1.1.2.2 thorpej
95 1.1.2.2 thorpej SetADBInfo(&adbinfo, sc->adbaddr);
96 1.1.2.2 thorpej }
97 1.1.2.2 thorpej
98 1.1.2.2 thorpej void
99 1.1.2.2 thorpej abtn_adbcomplete(buffer, data, adb_command)
100 1.1.2.2 thorpej caddr_t buffer, data;
101 1.1.2.2 thorpej int adb_command;
102 1.1.2.2 thorpej {
103 1.1.2.2 thorpej struct abtn_softc *sc = (struct abtn_softc *)data;
104 1.1.2.2 thorpej u_int cmd;
105 1.1.2.2 thorpej
106 1.1.2.2 thorpej cmd = buffer[1];
107 1.1.2.2 thorpej
108 1.1.2.2 thorpej switch (cmd) {
109 1.1.2.2 thorpej case 0x0a:
110 1.1.2.2 thorpej sc->brightness -= 8;
111 1.1.2.2 thorpej if (sc->brightness < 8)
112 1.1.2.2 thorpej sc->brightness = 8;
113 1.1.2.2 thorpej pm_set_brightness(sc->brightness);
114 1.1.2.2 thorpej pm_write_nvram(NVRAM_BRIGHTNESS, sc->brightness);
115 1.1.2.2 thorpej break;
116 1.1.2.2 thorpej
117 1.1.2.2 thorpej case 0x09:
118 1.1.2.2 thorpej sc->brightness += 8;
119 1.1.2.2 thorpej if (sc->brightness > 0x78)
120 1.1.2.2 thorpej sc->brightness = 0x78;
121 1.1.2.2 thorpej pm_set_brightness(sc->brightness);
122 1.1.2.2 thorpej pm_write_nvram(NVRAM_BRIGHTNESS, sc->brightness);
123 1.1.2.2 thorpej break;
124 1.1.2.2 thorpej }
125 1.1.2.2 thorpej }
126