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

Annotation of sys/arch/sparc/dev/led.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: led.c,v 1.12 2006/08/01 18:09:40 deraadt Exp $        */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 1998 Jason L. Wright (jason@thought.net)
        !             5:  * All rights reserved.
        !             6:  *
        !             7:  * Redistribution and use in source and binary forms, with or without
        !             8:  * modification, are permitted provided that the following conditions
        !             9:  * are met:
        !            10:  * 1. Redistributions of source code must retain the above copyright
        !            11:  *    notice, this list of conditions and the following disclaimer.
        !            12:  * 2. Redistributions in binary form must reproduce the above copyright
        !            13:  *    notice, this list of conditions and the following disclaimer in the
        !            14:  *    documentation and/or other materials provided with the distribution.
        !            15:  *
        !            16:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
        !            17:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
        !            18:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        !            19:  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
        !            20:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
        !            21:  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        !            22:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            23:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
        !            24:  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
        !            25:  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        !            26:  * POSSIBILITY OF SUCH DAMAGE.
        !            27:  */
        !            28:
        !            29: /*
        !            30:  * Driver for leds on the 4/100, 4/200, 4/300, and 4/600. (sun4 & sun4m)
        !            31:  */
        !            32:
        !            33: #include <sys/param.h>
        !            34: #include <sys/systm.h>
        !            35: #include <sys/kernel.h>
        !            36: #include <sys/errno.h>
        !            37: #include <sys/socket.h>
        !            38: #include <sys/syslog.h>
        !            39: #include <sys/device.h>
        !            40: #include <sys/malloc.h>
        !            41: #include <sys/timeout.h>
        !            42:
        !            43: #include <machine/autoconf.h>
        !            44: #include <machine/ctlreg.h>
        !            45: #include <sparc/sparc/asm.h>
        !            46: #include <sparc/cpu.h>
        !            47: #include <sparc/sparc/cpuvar.h>
        !            48: #include <sparc/dev/led.h>
        !            49:
        !            50: int    ledmatch(struct device *, void *, void *);
        !            51: void   ledattach(struct device *, struct device *, void *);
        !            52: void   led_cycle(void *);
        !            53:
        !            54: struct cfattach led_ca = {
        !            55:        sizeof (struct led_softc), ledmatch, ledattach
        !            56: };
        !            57:
        !            58: struct cfdriver led_cd = {
        !            59:        NULL, "led", DV_DULL
        !            60: };
        !            61:
        !            62: static u_int8_t led_pattern[] = {
        !            63:        0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f,
        !            64:        0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd,
        !            65: };
        !            66:
        !            67: struct led_softc *led_sc = NULL;
        !            68: extern int sparc_led_blink;    /* from machdep */
        !            69:
        !            70: int
        !            71: ledmatch(parent, vcf, aux)
        !            72:        struct device *parent;
        !            73:        void *vcf, *aux;
        !            74: {
        !            75: #if defined(SUN4)
        !            76:        struct cfdata *cf = vcf;
        !            77: #endif
        !            78: #if defined(SUN4) || defined(SUN4M)
        !            79:        struct confargs *ca = aux;
        !            80:        register struct romaux *ra = &ca->ca_ra;
        !            81:
        !            82: #if defined(SUN4M)
        !            83:        if (ca->ca_bustype == BUS_OBIO) {
        !            84:                if (strcmp("leds", ra->ra_name))
        !            85:                        return (0);
        !            86:                return (1);
        !            87:        }
        !            88: #endif /* SUN4M */
        !            89:
        !            90: #if defined(SUN4)
        !            91:        if (ca->ca_bustype == BUS_MAIN) {
        !            92:                if (strcmp(cf->cf_driver->cd_name, ra->ra_name))
        !            93:                        return (0);
        !            94:                if (CPU_ISSUN4)
        !            95:                        return (1);
        !            96:                return (0);
        !            97:        }
        !            98: #endif /* SUN4 */
        !            99: #endif /* SUN4 || SUN4M */
        !           100:
        !           101:        return (0);
        !           102: }
        !           103:
        !           104: void
        !           105: ledattach(parent, self, aux)
        !           106:        struct device *parent, *self;
        !           107:        void *aux;
        !           108: {
        !           109:        struct confargs *ca = aux;
        !           110:        struct led_softc *sc = (struct led_softc *)self;
        !           111:
        !           112:        sc->sc_node = ca->ca_ra.ra_node;
        !           113:
        !           114:        timeout_set(&sc->sc_to, led_cycle, sc);
        !           115:
        !           116:        if (CPU_ISSUN4M)
        !           117:                sc->sc_reg = mapiodev(&(ca->ca_ra.ra_reg[0]), 0,
        !           118:                    ca->ca_ra.ra_reg[0].rr_len);
        !           119:
        !           120:        led_sc = sc;
        !           121:        if (sparc_led_blink)
        !           122:                led_cycle(sc);
        !           123:        printf("\n");
        !           124: }
        !           125:
        !           126: void
        !           127: led_cycle(v)
        !           128:        void *v;
        !           129: {
        !           130:        struct led_softc *sc = v;
        !           131:        int s;
        !           132:
        !           133:        if (sc == NULL)
        !           134:                return;
        !           135:
        !           136:        sc->sc_index = (sc->sc_index + 1) %
        !           137:                        (sizeof(led_pattern)/sizeof(led_pattern[0]));
        !           138:
        !           139:        if (sparc_led_blink == 0)
        !           140:                sc->sc_index = 0;
        !           141:
        !           142: #if defined(SUN4M)
        !           143:        if (CPU_ISSUN4M) {
        !           144:                s = splhigh();
        !           145:                (*sc->sc_reg) = led_pattern[sc->sc_index] | 0xff00;
        !           146:                splx(s);
        !           147:        }
        !           148: #endif
        !           149:
        !           150: #if defined(SUN4)
        !           151:        if (CPU_ISSUN4) {
        !           152:                s = splhigh();
        !           153:                stba(AC_DIAG_REG, ASI_CONTROL, led_pattern[sc->sc_index]);
        !           154:                splx(s);
        !           155:        }
        !           156: #endif
        !           157:
        !           158:        if (sparc_led_blink != 0) {
        !           159:                s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 3));
        !           160:                timeout_add(&sc->sc_to, s);
        !           161:        }
        !           162: }

CVSweb