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

Annotation of sys/arch/sparc/dev/cgfour.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: cgfour.c,v 1.27 2006/12/03 16:38:12 miod Exp $        */
                      2: /*     $NetBSD: cgfour.c,v 1.13 1997/05/24 20:16:06 pk Exp $   */
                      3:
                      4: /*
                      5:  * Coyrpight (c) 2002 Miodrag Vallat.  All rights reserved.
                      6:  * Copyright (c) 1996 Jason R. Thorpe.  All rights reserved.
                      7:  * Copyright (c) 1995 Theo de Raadt.  All rights reserved.
                      8:  * Copyright (c) 1992, 1993
                      9:  *     The Regents of the University of California.  All rights reserved.
                     10:  *
                     11:  * This software was developed by the Computer Systems Engineering group
                     12:  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
                     13:  * contributed to Berkeley.
                     14:  *
                     15:  * All advertising materials mentioning features or use of this software
                     16:  * must display the following acknowledgement:
                     17:  *     This product includes software developed by the University of
                     18:  *     California, Lawrence Berkeley Laboratory.
                     19:  *
                     20:  * Redistribution and use in source and binary forms, with or without
                     21:  * modification, are permitted provided that the following conditions
                     22:  * are met:
                     23:  * 1. Redistributions of source code must retain the above copyright
                     24:  *    notice, this list of conditions and the following disclaimer.
                     25:  * 2. Redistributions in binary form must reproduce the above copyright
                     26:  *    notice, this list of conditions and the following disclaimer in the
                     27:  *    documentation and/or other materials provided with the distribution.
                     28:  * 3. Neither the name of the University nor the names of its contributors
                     29:  *    may be used to endorse or promote products derived from this software
                     30:  *    without specific prior written permission.
                     31:  *
                     32:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     33:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     34:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     35:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     36:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     37:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     38:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     39:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     40:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     41:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     42:  * SUCH DAMAGE.
                     43:  *
                     44:  *     from @(#)cgthree.c      8.2 (Berkeley) 10/30/93
                     45:  */
                     46:
                     47: /*
                     48:  * color display (cgfour) driver.
                     49:  *
                     50:  * Does not handle interrupts, even though they can occur.
                     51:  *
                     52:  * XXX should defer colormap updates to vertical retrace interrupts
                     53:  */
                     54:
                     55: #include <sys/param.h>
                     56: #include <sys/systm.h>
                     57: #include <sys/buf.h>
                     58: #include <sys/device.h>
                     59: #include <sys/ioctl.h>
                     60: #include <sys/malloc.h>
                     61: #include <sys/mman.h>
                     62: #include <sys/tty.h>
                     63: #include <sys/conf.h>
                     64:
                     65: #include <uvm/uvm_extern.h>            /* NBPG */
                     66:
                     67: #include <machine/autoconf.h>
                     68: #include <machine/pmap.h>
                     69: #include <machine/eeprom.h>
                     70: #include <machine/conf.h>
                     71:
                     72: #include <dev/wscons/wsconsio.h>
                     73: #include <dev/wscons/wsdisplayvar.h>
                     74: #include <dev/rasops/rasops.h>
                     75: #include <machine/fbvar.h>
                     76:
                     77: #include <sparc/dev/btreg.h>
                     78: #include <sparc/dev/btvar.h>
                     79: #include <sparc/dev/pfourreg.h>
                     80:
                     81: /* per-display variables */
                     82: struct cgfour_softc {
                     83:        struct  sunfb sc_sunfb;         /* common base part */
                     84:        struct rom_reg  sc_phys;        /* display RAM (phys addr) */
                     85:        volatile struct fbcontrol *sc_fbc;      /* Brooktree registers */
                     86:        union   bt_cmap sc_cmap;        /* Brooktree color map */
                     87: };
                     88:
                     89: int    cgfour_ioctl(void *, u_long, caddr_t, int, struct proc *);
                     90: paddr_t        cgfour_mmap(void *, off_t, int);
                     91: void   cgfour_setcolor(void *, u_int, u_int8_t, u_int8_t, u_int8_t);
                     92:
                     93: struct wsdisplay_accessops cgfour_accessops = {
                     94:        cgfour_ioctl,
                     95:        cgfour_mmap,
                     96:        NULL,   /* alloc_screen */
                     97:        NULL,   /* free_screen */
                     98:        NULL,   /* show_screen */
                     99:        NULL,   /* load_font */
                    100:        NULL,   /* scrollback */
                    101:        NULL,   /* getchar */
                    102:        fb_pfour_burner,
                    103:        NULL    /* pollc */
                    104: };
                    105:
                    106: void   cgfourattach(struct device *, struct device *, void *);
                    107: int    cgfourmatch(struct device *, void *, void *);
                    108:
                    109: struct cfattach cgfour_ca = {
                    110:        sizeof(struct cgfour_softc), cgfourmatch, cgfourattach
                    111: };
                    112:
                    113: struct cfdriver cgfour_cd = {
                    114:        NULL, "cgfour", DV_DULL
                    115: };
                    116:
                    117: int
                    118: cgfourmatch(struct device *parent, void *vcf, void *aux)
                    119: {
                    120:        struct cfdata *cf = vcf;
                    121:        struct confargs *ca = aux;
                    122:        struct romaux *ra = &ca->ca_ra;
                    123:
                    124:        if (strcmp(cf->cf_driver->cd_name, ra->ra_name))
                    125:                return (0);
                    126:
                    127:        if (!CPU_ISSUN4 || ca->ca_bustype != BUS_OBIO)
                    128:                return (0);
                    129:
                    130:        if (probeget(ra->ra_vaddr, 4) == -1)
                    131:                return (0);
                    132:
                    133:        /*
                    134:         * Check the pfour register.
                    135:         */
                    136:        if (fb_pfour_id(ra->ra_vaddr) == PFOUR_ID_COLOR8P1)
                    137:                return (1);
                    138:
                    139:        return (0);
                    140: }
                    141:
                    142: void
                    143: cgfourattach(struct device *parent, struct device *self, void *args)
                    144: {
                    145:        struct cgfour_softc *sc = (struct cgfour_softc *)self;
                    146:        struct confargs *ca = args;
                    147:        int node = 0;
                    148:        volatile struct bt_regs *bt;
                    149:        int isconsole = 0;
                    150:
                    151:        printf(": p4");
                    152:
                    153:        /* Map the pfour register. */
                    154:        SET(sc->sc_sunfb.sf_flags, FB_PFOUR);
                    155:        sc->sc_sunfb.sf_pfour = (volatile u_int32_t *)
                    156:                mapiodev(ca->ca_ra.ra_reg, 0, sizeof(u_int32_t));
                    157:
                    158:        if (cputyp == CPU_SUN4) {
                    159:                struct eeprom *eep = (struct eeprom *)eeprom_va;
                    160:
                    161:                /*
                    162:                 * Assume this is the console if there's no eeprom info
                    163:                 * to be found.
                    164:                 */
                    165:                if (eep == NULL || eep->eeConsole == EE_CONS_P4OPT)
                    166:                        isconsole = 1;
                    167:        }
                    168:
                    169:        /*
                    170:         * When the ROM has mapped in a cgfour display, the address
                    171:         * maps only the video RAM, so in any case we have to map the
                    172:         * registers ourselves.  We only need the video RAM if we are
                    173:         * going to print characters via rconsole.
                    174:         */
                    175:
                    176:        sc->sc_phys = ca->ca_ra.ra_reg[0];
                    177:
                    178:        /* enable video */
                    179:        fb_pfour_burner(sc, 1, 0);
                    180:        bt = &sc->sc_fbc->fbc_dac;
                    181:        BT_INIT(bt, 24);
                    182:
                    183:        /*
                    184:         * XXX should initialize the enable plane, instead of expecting the
                    185:         * PROM to do so for us
                    186:         */
                    187:
                    188:        fb_setsize(&sc->sc_sunfb, 8, 1152, 900, node, ca->ca_bustype);
                    189:        /*
                    190:         * XXX this only maps the color plane, not the overlay or the enable
                    191:         * planes
                    192:         */
                    193:        sc->sc_sunfb.sf_ro.ri_bits = mapiodev(ca->ca_ra.ra_reg,
                    194:            PFOUR_COLOR_OFF_COLOR, round_page(sc->sc_sunfb.sf_fbsize));
                    195:        sc->sc_sunfb.sf_ro.ri_hw = sc;
                    196:        fbwscons_init(&sc->sc_sunfb, isconsole ? 0 : RI_CLEAR);
                    197:        fbwscons_setcolormap(&sc->sc_sunfb, cgfour_setcolor);
                    198:
                    199:        printf(", %dx%d\n", sc->sc_sunfb.sf_width, sc->sc_sunfb.sf_height);
                    200:
                    201:        if (isconsole) {
                    202:                fbwscons_console_init(&sc->sc_sunfb, -1);
                    203:        }
                    204:
                    205:        fbwscons_attach(&sc->sc_sunfb, &cgfour_accessops, isconsole);
                    206: }
                    207:
                    208: int
                    209: cgfour_ioctl(void *v, u_long cmd, caddr_t data, int flags, struct proc *p)
                    210: {
                    211:        struct cgfour_softc *sc = v;
                    212:        struct wsdisplay_fbinfo *wdf;
                    213:        struct wsdisplay_cmap *cm;
                    214:        int error;
                    215:
                    216:        switch (cmd) {
                    217:        case WSDISPLAYIO_GTYPE:
                    218:                *(u_int *)data = WSDISPLAY_TYPE_SUNCG4;
                    219:                break;
                    220:        case WSDISPLAYIO_GINFO:
                    221:                wdf = (struct wsdisplay_fbinfo *)data;
                    222:                wdf->height = sc->sc_sunfb.sf_height;
                    223:                wdf->width  = sc->sc_sunfb.sf_width;
                    224:                wdf->depth  = sc->sc_sunfb.sf_depth;
                    225:                wdf->cmsize = 256;
                    226:                break;
                    227:        case WSDISPLAYIO_LINEBYTES:
                    228:                *(u_int *)data = sc->sc_sunfb.sf_linebytes;
                    229:                break;
                    230:
                    231:        case WSDISPLAYIO_GETCMAP:
                    232:                cm = (struct wsdisplay_cmap *)data;
                    233:                error = bt_getcmap(&sc->sc_cmap, cm);
                    234:                if (error)
                    235:                        return (error);
                    236:                break;
                    237:
                    238:        case WSDISPLAYIO_PUTCMAP:
                    239:                cm = (struct wsdisplay_cmap *)data;
                    240:                error = bt_putcmap(&sc->sc_cmap, cm);
                    241:                if (error)
                    242:                        return (error);
                    243:                bt_loadcmap(&sc->sc_cmap, &sc->sc_fbc->fbc_dac,
                    244:                    cm->index, cm->count, 1);
                    245:                break;
                    246:
                    247:        case WSDISPLAYIO_SVIDEO:
                    248:        case WSDISPLAYIO_GVIDEO:
                    249:                break;
                    250:
                    251:        case WSDISPLAYIO_GCURPOS:
                    252:        case WSDISPLAYIO_SCURPOS:
                    253:        case WSDISPLAYIO_GCURMAX:
                    254:        case WSDISPLAYIO_GCURSOR:
                    255:        case WSDISPLAYIO_SCURSOR:
                    256:        default:
                    257:                return (-1);    /* not supported yet */
                    258:         }
                    259:
                    260:        return (0);
                    261: }
                    262:
                    263: paddr_t
                    264: cgfour_mmap(void *v, off_t offset, int prot)
                    265: {
                    266:        struct cgfour_softc *sc = v;
                    267:
                    268:        if (offset & PGOFSET)
                    269:                return (-1);
                    270:
                    271:        if (offset >= 0 && offset < sc->sc_sunfb.sf_fbsize) {
                    272:                return (REG2PHYS(&sc->sc_phys,
                    273:                    PFOUR_COLOR_OFF_COLOR + offset) | PMAP_NC);
                    274:        }
                    275:
                    276:        return (-1);
                    277: }
                    278:
                    279: void
                    280: cgfour_setcolor(void *v, u_int index, u_int8_t r, u_int8_t g, u_int8_t b)
                    281: {
                    282:        struct cgfour_softc *sc = v;
                    283:
                    284:        bt_setcolor(&sc->sc_cmap, &sc->sc_fbc->fbc_dac, index, r, g, b, 1);
                    285: }

CVSweb