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

Annotation of sys/arch/sparc64/dev/clkbrd.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: clkbrd.c,v 1.5 2004/10/01 18:18:49 jason Exp $        */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 2004 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: #include <sys/types.h>
        !            30: #include <sys/param.h>
        !            31: #include <sys/systm.h>
        !            32: #include <sys/kernel.h>
        !            33: #include <sys/device.h>
        !            34: #include <sys/conf.h>
        !            35: #include <sys/timeout.h>
        !            36: #include <sys/malloc.h>
        !            37:
        !            38: #include <machine/bus.h>
        !            39: #include <machine/autoconf.h>
        !            40: #include <machine/openfirm.h>
        !            41:
        !            42: #include <sparc64/dev/fhcvar.h>
        !            43: #include <sparc64/dev/clkbrdreg.h>
        !            44: #include <sparc64/dev/clkbrdvar.h>
        !            45:
        !            46: int clkbrd_match(struct device *, void *, void *);
        !            47: void clkbrd_attach(struct device *, struct device *, void *);
        !            48: void clkbrd_led_blink(void *, int);
        !            49:
        !            50: struct cfattach clkbrd_ca = {
        !            51:        sizeof(struct clkbrd_softc), clkbrd_match, clkbrd_attach
        !            52: };
        !            53:
        !            54: struct cfdriver clkbrd_cd = {
        !            55:        NULL, "clkbrd", DV_DULL
        !            56: };
        !            57:
        !            58: int
        !            59: clkbrd_match(parent, match, aux)
        !            60:        struct device *parent;
        !            61:        void *match, *aux;
        !            62: {
        !            63:        struct fhc_attach_args *fa = aux;
        !            64:
        !            65:        if (strcmp(fa->fa_name, "clock-board") == 0)
        !            66:                return (1);
        !            67:        return (0);
        !            68: }
        !            69:
        !            70: void
        !            71: clkbrd_attach(parent, self, aux)
        !            72:        struct device *parent, *self;
        !            73:        void *aux;
        !            74: {
        !            75:        struct clkbrd_softc *sc = (struct clkbrd_softc *)self;
        !            76:        struct fhc_attach_args *fa = aux;
        !            77:        int slots;
        !            78:        u_int8_t r;
        !            79:
        !            80:        sc->sc_bt = fa->fa_bustag;
        !            81:
        !            82:        if (fa->fa_nreg < 2) {
        !            83:                printf(": no registers\n");
        !            84:                return;
        !            85:        }
        !            86:
        !            87:        if (fhc_bus_map(sc->sc_bt, fa->fa_reg[1].fbr_slot,
        !            88:            fa->fa_reg[1].fbr_offset, fa->fa_reg[1].fbr_size, 0,
        !            89:            &sc->sc_creg)) {
        !            90:                printf(": can't map ctrl regs\n");
        !            91:                return;
        !            92:        }
        !            93:
        !            94:        if (fa->fa_nreg > 2) {
        !            95:                if (fhc_bus_map(sc->sc_bt, fa->fa_reg[2].fbr_slot,
        !            96:                    fa->fa_reg[2].fbr_offset, fa->fa_reg[2].fbr_size, 0,
        !            97:                    &sc->sc_vreg)) {
        !            98:                        printf(": can't map vreg\n");
        !            99:                        return;
        !           100:                }
        !           101:                sc->sc_has_vreg = 1;
        !           102:        }
        !           103:
        !           104:        slots = 4;
        !           105:        r = bus_space_read_1(sc->sc_bt, sc->sc_creg, CLK_STS1);
        !           106:        switch (r & 0xc0) {
        !           107:        case 0x40:
        !           108:                slots = 16;
        !           109:                break;
        !           110:        case 0xc0:
        !           111:                slots = 8;
        !           112:                break;
        !           113:        case 0x80:
        !           114:                if (sc->sc_has_vreg) {
        !           115:                        r = bus_space_read_1(sc->sc_bt, sc->sc_vreg, 0);
        !           116:                        if (r != 0 && (r & 0x80) == 0)
        !           117:                                        slots = 5;
        !           118:                }
        !           119:        }
        !           120:
        !           121:        printf(": %d slots\n", slots);
        !           122:
        !           123:        sc->sc_blink.bl_func = clkbrd_led_blink;
        !           124:        sc->sc_blink.bl_arg = sc;
        !           125:        blink_led_register(&sc->sc_blink);
        !           126: }
        !           127:
        !           128: void
        !           129: clkbrd_led_blink(void *vsc, int on)
        !           130: {
        !           131:        struct clkbrd_softc *sc = vsc;
        !           132:        int s;
        !           133:        u_int8_t r;
        !           134:
        !           135:        s = splhigh();
        !           136:        r = bus_space_read_1(sc->sc_bt, sc->sc_creg, CLK_CTRL);
        !           137:        if (on)
        !           138:                r |= CLK_CTRL_RLED;
        !           139:        else
        !           140:                r &= ~CLK_CTRL_RLED;
        !           141:        bus_space_write_1(sc->sc_bt, sc->sc_creg, CLK_CTRL, r);
        !           142:        bus_space_read_1(sc->sc_bt, sc->sc_creg, CLK_CTRL);
        !           143:        splx(s);
        !           144: }

CVSweb