[BACK]Return to abtn.c CVS log [TXT][DIR] Up to [local] / sys / arch / macppc / dev

Annotation of sys/arch/macppc/dev/abtn.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: abtn.c,v 1.11 2006/01/18 23:21:17 miod Exp $  */
                      2: /*     $NetBSD: abtn.c,v 1.1 1999/07/12 17:48:26 tsubai Exp $  */
                      3:
                      4: /*-
                      5:  * Copyright (c) 2002, Miodrag Vallat.
                      6:  * Copyright (C) 1999 Tsubai Masanari.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     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.
                     18:  *
                     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.
                     29:  */
                     30:
                     31: #include <sys/param.h>
                     32: #include <sys/device.h>
                     33: #include <sys/systm.h>
                     34:
                     35: #include <machine/bus.h>
                     36:
                     37: #include <dev/ofw/openfirm.h>
                     38: #include <macppc/macppc/ofw_machdep.h>
                     39:
                     40: #include <dev/adb/adb.h>
                     41:
                     42: #define ABTN_HANDLER_ID 31
                     43:
                     44: struct abtn_softc {
                     45:        struct device sc_dev;
                     46:
                     47:        int origaddr;           /* ADB device type */
                     48:        int adbaddr;            /* current ADB address */
                     49:        int handler_id;
                     50: };
                     51:
                     52: int abtn_match(struct device *, void *, void *);
                     53: void abtn_attach(struct device *, struct device *, void *);
                     54: void abtn_adbcomplete(caddr_t, caddr_t, int);
                     55:
                     56: struct cfattach abtn_ca = {
                     57:        sizeof(struct abtn_softc), abtn_match, abtn_attach
                     58: };
                     59: struct cfdriver abtn_cd = {
                     60:        NULL, "abtn", DV_DULL
                     61: };
                     62:
                     63: int
                     64: abtn_match(struct device *parent, void *cf, void *aux)
                     65: {
                     66:        struct adb_attach_args *aa = aux;
                     67:
                     68:        if (aa->origaddr == ADBADDR_MISC &&
                     69:            aa->handler_id == ABTN_HANDLER_ID)
                     70:                return 1;
                     71:
                     72:        return 0;
                     73: }
                     74:
                     75: void
                     76: abtn_attach(struct device *parent, struct device *self, void *aux)
                     77: {
                     78:        struct abtn_softc *sc = (struct abtn_softc *)self;
                     79:        struct adb_attach_args *aa = aux;
                     80:        ADBSetInfoBlock adbinfo;
                     81:
                     82:        printf(": brightness/volume/eject buttons\n");
                     83:
                     84:        sc->origaddr = aa->origaddr;
                     85:        sc->adbaddr = aa->adbaddr;
                     86:        sc->handler_id = aa->handler_id;
                     87:
                     88:        adbinfo.siServiceRtPtr = (Ptr)abtn_adbcomplete;
                     89:        adbinfo.siDataAreaAddr = (caddr_t)sc;
                     90:
                     91:        set_adb_info(&adbinfo, sc->adbaddr);
                     92: }
                     93:
                     94: void
                     95: abtn_adbcomplete(caddr_t buffer, caddr_t data, int adb_command)
                     96: {
                     97:        u_int cmd, brightness;
                     98:
                     99:        cmd = buffer[1];
                    100:
                    101:        switch (cmd) {
                    102:        case 0x0a:      /* decrease brightness */
                    103:                brightness = cons_brightness;
                    104:                if (brightness == MAX_BRIGHTNESS)
                    105:                        brightness++;           /* get round values */
                    106:                brightness -= STEP_BRIGHTNESS;
                    107:                of_setbrightness(brightness);
                    108:                break;
                    109:
                    110:        case 0x09:      /* increase brightness */
                    111:                brightness = cons_brightness + STEP_BRIGHTNESS;
                    112:                of_setbrightness(brightness);
                    113:                break;
                    114:
                    115: #ifdef DEBUG
                    116:        case 0x08:      /* mute */
                    117:        case 0x01:      /* mute, AV hardware */
                    118:        case 0x07:      /* decrease volume */
                    119:        case 0x02:      /* decrease volume, AV hardware */
                    120:        case 0x06:      /* increase volume */
                    121:        case 0x03:      /* increase volume, AV hardware */
                    122:                /* Need callback to do something with these */
                    123:                break;
                    124:
                    125:        case 0x0c:      /* mirror display key */
                    126:                /* Need callback to do something with this */
                    127:                break;
                    128:
                    129:        case 0x0b:      /* eject tray */
                    130:                /* Need callback to do something with this */
                    131:                break;
                    132:
                    133:        case 0x7f:      /* numlock */
                    134:                /* Need callback to do something with this */
                    135:                break;
                    136:
                    137:        default:
                    138:                if ((cmd & ~0x7f) == 0)
                    139:                        printf("unknown ADB button 0x%x\n", cmd);
                    140:                break;
                    141: #endif
                    142:        }
                    143: }

CVSweb