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

Annotation of sys/arch/vax/vax/led.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: led.c,v 1.4 2006/08/27 16:55:41 miod Exp $    */
        !             2: /*     $NetBSD: leds.c,v 1.4 2005/12/11 12:19:37 christos Exp $        */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1998 Jason L. Wright (jason@thought.net)
        !             6:  * 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:  *
        !            17:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
        !            18:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
        !            19:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        !            20:  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
        !            21:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
        !            22:  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        !            23:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            24:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
        !            25:  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
        !            26:  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        !            27:  * POSSIBILITY OF SUCH DAMAGE.
        !            28:  */
        !            29: /*-
        !            30:  * Copyright (c) 1997 The NetBSD Foundation, Inc.
        !            31:  * All rights reserved.
        !            32:  *
        !            33:  * This code is derived from software contributed to The NetBSD Foundation
        !            34:  * by Gordon W. Ross and der Mouse.
        !            35:  *
        !            36:  * Redistribution and use in source and binary forms, with or without
        !            37:  * modification, are permitted provided that the following conditions
        !            38:  * are met:
        !            39:  * 1. Redistributions of source code must retain the above copyright
        !            40:  *    notice, this list of conditions and the following disclaimer.
        !            41:  * 2. Redistributions in binary form must reproduce the above copyright
        !            42:  *    notice, this list of conditions and the following disclaimer in the
        !            43:  *    documentation and/or other materials provided with the distribution.
        !            44:  * 3. All advertising materials mentioning features or use of this software
        !            45:  *    must display the following acknowledgement:
        !            46:  *     This product includes software developed by the NetBSD
        !            47:  *     Foundation, Inc. and its contributors.
        !            48:  * 4. Neither the name of The NetBSD Foundation nor the names of its
        !            49:  *    contributors may be used to endorse or promote products derived
        !            50:  *    from this software without specific prior written permission.
        !            51:  *
        !            52:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
        !            53:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
        !            54:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
        !            55:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
        !            56:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        !            57:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        !            58:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        !            59:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        !            60:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        !            61:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        !            62:  * POSSIBILITY OF SUCH DAMAGE.
        !            63:  */
        !            64:
        !            65: /*
        !            66:  * Functions to flash the LEDs with some pattern.
        !            67:  */
        !            68:
        !            69: #include <sys/param.h>
        !            70: #include <sys/systm.h>
        !            71: #include <sys/kernel.h>
        !            72: #include <sys/device.h>
        !            73: #include <sys/conf.h>
        !            74: #include <sys/timeout.h>
        !            75:
        !            76: #include <machine/cpu.h>
        !            77: #include <machine/nexus.h>
        !            78: #include <machine/sid.h>
        !            79:
        !            80: struct led_softc {
        !            81:        struct device   sc_dev;
        !            82:        struct timeout  sc_tmo;
        !            83:        volatile u_short *sc_reg;
        !            84:        const u_int8_t  *sc_pat, *sc_patpos;
        !            85: };
        !            86:
        !            87: /*
        !            88:  * Patterns for 8 and 4 led displays.
        !            89:  */
        !            90: static const u_int8_t led_pattern8[] = {
        !            91:        0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f,
        !            92:        0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0x00
        !            93: };
        !            94: static const u_int8_t led_pattern4[] = {
        !            95:        0x0e, 0x0d, 0x0b, 0x07, 0x0b, 0x0d, 0x00
        !            96: };
        !            97:
        !            98: int    ledmatch(struct device *, void *, void *);
        !            99: void   ledattach(struct device *, struct device *, void *);
        !           100: void   led_blink(void *);
        !           101:
        !           102: struct cfattach led_ca = {
        !           103:        sizeof(struct led_softc), ledmatch, ledattach
        !           104: };
        !           105:
        !           106: struct cfdriver led_cd = {
        !           107:        NULL, "led", DV_DULL
        !           108: };
        !           109:
        !           110: int
        !           111: ledmatch(struct device *parent, void *cf, void *aux)
        !           112: {
        !           113:        struct mainbus_attach_args *maa = aux;
        !           114:
        !           115:        if (maa->maa_bustype != VAX_LEDS)
        !           116:                return (0);
        !           117:
        !           118:        switch (vax_boardtype) {
        !           119: #if VAX46 || VAX48 || VAX49 || VAX53 || VXT
        !           120: #if VAX46
        !           121:        case VAX_BTYP_46:
        !           122: #endif
        !           123: #if VAX48
        !           124:        case VAX_BTYP_48:
        !           125: #endif
        !           126: #if VAX49
        !           127:        case VAX_BTYP_49:
        !           128: #endif
        !           129: #if VAX53
        !           130:        case VAX_BTYP_1303:
        !           131: #endif
        !           132: #if VXT
        !           133:        case VAX_BTYP_VXT:
        !           134: #endif
        !           135:                return (1);
        !           136: #endif
        !           137:        default:
        !           138:                return (0);
        !           139:        }
        !           140: }
        !           141:
        !           142: void
        !           143: ledattach(struct device *parent, struct device *self, void *aux)
        !           144: {
        !           145:        struct led_softc *sc = (void *)self;
        !           146: #if VAX49 || VAX53 || VXT
        !           147:        vaddr_t pgva;
        !           148: #endif
        !           149:
        !           150:        printf("\n");
        !           151:
        !           152:        switch (vax_boardtype) {
        !           153: #if VAX46
        !           154:        case VAX_BTYP_46:
        !           155:        {
        !           156:                extern struct vs_cpu *ka46_cpu;
        !           157:                sc->sc_reg = (volatile u_short *)(&ka46_cpu->vc_diagdsp);
        !           158:                sc->sc_pat = led_pattern8;
        !           159:        }
        !           160:                break;
        !           161: #endif
        !           162: #if VAX48
        !           163:        case VAX_BTYP_48:
        !           164:        {
        !           165:                extern struct vs_cpu *ka48_cpu;
        !           166:                sc->sc_reg = (volatile u_short *)(&ka48_cpu->vc_diagdsp);
        !           167:                sc->sc_pat = led_pattern8;
        !           168:        }
        !           169:                break;
        !           170: #endif
        !           171: #if VAX49
        !           172:        case VAX_BTYP_49:
        !           173:                pgva = vax_map_physmem(0x25800000, 1);
        !           174:                sc->sc_reg = (volatile u_short *)(pgva + 4);
        !           175:                sc->sc_pat = led_pattern8;
        !           176:                break;
        !           177: #endif
        !           178: #if VAX53
        !           179:        case VAX_BTYP_1303:
        !           180:                pgva = vax_map_physmem(0x20140000, 1);
        !           181:                sc->sc_reg = (volatile u_short *)(pgva + 0x30);
        !           182:                sc->sc_pat = led_pattern4;
        !           183:                break;
        !           184: #endif
        !           185: #if VXT
        !           186:        case VAX_BTYP_VXT:
        !           187:                pgva = vax_map_physmem(0x200c1000, 1);
        !           188:                sc->sc_reg = (volatile u_short *)pgva;
        !           189:                sc->sc_pat = led_pattern8;
        !           190:                break;
        !           191: #endif
        !           192:        }
        !           193:
        !           194:        sc->sc_patpos = sc->sc_pat;
        !           195:        timeout_set(&sc->sc_tmo, led_blink, sc);
        !           196:        led_blink(sc);
        !           197: }
        !           198:
        !           199: void
        !           200: led_blink(void *v)
        !           201: {
        !           202:        struct led_softc *sc = v;
        !           203:        extern int vax_led_blink;
        !           204:
        !           205:        if (sc == NULL) {
        !           206:                /* find our softc if we come from cpu_sysctl */
        !           207:                if (led_cd.cd_ndevs != 0)
        !           208:                        sc = (struct led_softc *)led_cd.cd_devs[0];
        !           209:                if (sc == NULL)
        !           210:                        return;
        !           211:        }
        !           212:
        !           213:        if (vax_led_blink == 0) {
        !           214:                *sc->sc_reg = 0xff;
        !           215:                return;
        !           216:        }
        !           217:
        !           218:        *sc->sc_reg = *sc->sc_patpos++;
        !           219:        if (*sc->sc_patpos == 0)
        !           220:                sc->sc_patpos = sc->sc_pat;
        !           221:
        !           222:        timeout_add(&sc->sc_tmo,
        !           223:            (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 3)));
        !           224: }

CVSweb