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

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

1.1       nbrk        1: /*     $OpenBSD: cgeight.c,v 1.28 2006/12/03 22:13:05 miod Exp $       */
                      2: /*     $NetBSD: cgeight.c,v 1.13 1997/05/24 20:16:04 pk Exp $  */
                      3:
                      4: /*
                      5:  * Copyright (c) 2002 Miodrag Vallat.  All rights reserved.
                      6:  * Copyright (c) 1996 Jason R. Thorpe.  All rights reserved.
                      7:  * Copyright (c) 1995 Theo de Raadt
                      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 (cgeight) driver.
                     49:  *
                     50:  * For performance reasons, we run the emulation mode in the (monochrome)
                     51:  * overlay plane, but X11 in the 24-bit color plane.
                     52:  *
                     53:  * Does not handle interrupts, even though they can occur.
                     54:  */
                     55:
                     56: #include <sys/param.h>
                     57: #include <sys/systm.h>
                     58: #include <sys/buf.h>
                     59: #include <sys/device.h>
                     60: #include <sys/ioctl.h>
                     61: #include <sys/malloc.h>
                     62: #include <sys/mman.h>
                     63: #include <sys/tty.h>
                     64: #include <sys/conf.h>
                     65:
                     66: #include <uvm/uvm_extern.h>
                     67:
                     68: #include <machine/autoconf.h>
                     69: #include <machine/pmap.h>
                     70: #include <machine/eeprom.h>
                     71: #include <machine/conf.h>
                     72:
                     73: #include <dev/wscons/wsconsio.h>
                     74: #include <dev/wscons/wsdisplayvar.h>
                     75: #include <dev/rasops/rasops.h>
                     76: #include <machine/fbvar.h>
                     77:
                     78: #include <sparc/dev/btreg.h>
                     79: #include <sparc/dev/btvar.h>
                     80: #include <sparc/dev/pfourreg.h>
                     81:
                     82: /* per-display variables */
                     83: struct cgeight_softc {
                     84:        struct  sunfb sc_sunfb;                 /* common base device */
                     85:        struct  rom_reg sc_phys;
                     86:        volatile struct fbcontrol *sc_fbc;      /* Brooktree registers */
                     87:        volatile u_char *sc_enable;             /* enable plane */
                     88: };
                     89:
                     90: int    cgeight_ioctl(void *, u_long, caddr_t, int, struct proc *);
                     91: paddr_t        cgeight_mmap(void *, off_t, int);
                     92: void   cgeight_reset(struct cgeight_softc *, int);
                     93:
                     94: struct wsdisplay_accessops cgeight_accessops = {
                     95:        cgeight_ioctl,
                     96:        cgeight_mmap,
                     97:        NULL,   /* alloc_screen */
                     98:        NULL,   /* free_screen */
                     99:        NULL,   /* show_screen */
                    100:        NULL,   /* load_font */
                    101:        NULL,   /* scrollback */
                    102:        NULL,   /* getchar */
                    103:        fb_pfour_burner,
                    104:        NULL    /* pollc */
                    105: };
                    106:
                    107: void   cgeightattach(struct device *, struct device *, void *);
                    108: int    cgeightmatch(struct device *, void *, void *);
                    109:
                    110: struct cfattach cgeight_ca = {
                    111:        sizeof(struct cgeight_softc), cgeightmatch, cgeightattach
                    112: };
                    113:
                    114: struct cfdriver cgeight_cd = {
                    115:        NULL, "cgeight", DV_DULL
                    116: };
                    117:
                    118: int
                    119: cgeightmatch(struct device *parent, void *vcf, void *aux)
                    120: {
                    121:        struct cfdata *cf = vcf;
                    122:        struct confargs *ca = aux;
                    123:        struct romaux *ra = &ca->ca_ra;
                    124:
                    125:        if (strcmp(cf->cf_driver->cd_name, ra->ra_name))
                    126:                return (0);
                    127:
                    128:        if (!CPU_ISSUN4 || ca->ca_bustype != BUS_OBIO)
                    129:                return (0);
                    130:
                    131:        /*
                    132:         * Make sure there's hardware there.
                    133:         */
                    134:        if (probeget(ra->ra_vaddr, 4) == -1)
                    135:                return (0);
                    136:
                    137:        /*
                    138:         * Check the pfour register.
                    139:         */
                    140:        if (fb_pfour_id(ra->ra_vaddr) == PFOUR_ID_COLOR24)
                    141:                return (1);
                    142:
                    143:        return (0);
                    144: }
                    145:
                    146: void
                    147: cgeightattach(struct device *parent, struct device *self, void *args)
                    148: {
                    149:        struct cgeight_softc *sc = (struct cgeight_softc *)self;
                    150:        struct confargs *ca = args;
                    151:        int node = 0;
                    152:        volatile struct bt_regs *bt;
                    153:        int isconsole = 0;
                    154:
                    155:        /* Map the pfour register. */
                    156:        SET(sc->sc_sunfb.sf_flags, FB_PFOUR);
                    157:        sc->sc_sunfb.sf_pfour = (volatile u_int32_t *)
                    158:            mapiodev(ca->ca_ra.ra_reg, 0, sizeof(u_int32_t));
                    159:
                    160:        if (cputyp == CPU_SUN4) {
                    161:                struct eeprom *eep = (struct eeprom *)eeprom_va;
                    162:
                    163:                /*
                    164:                 * Assume this is the console if there's no eeprom info
                    165:                 * to be found.
                    166:                 */
                    167:                if (eep == NULL || eep->eeConsole == EE_CONS_P4OPT)
                    168:                        isconsole = 1;
                    169:        }
                    170:
                    171:        /* Map the Brooktree. */
                    172:        sc->sc_fbc = (volatile struct fbcontrol *)
                    173:            mapiodev(ca->ca_ra.ra_reg,
                    174:                     PFOUR_COLOR_OFF_CMAP, sizeof(struct fbcontrol));
                    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, 0);
                    182:
                    183:        fb_setsize(&sc->sc_sunfb, 1, 1152, 900, node, ca->ca_bustype);
                    184:        sc->sc_sunfb.sf_ro.ri_hw = sc;
                    185:
                    186:        /*
                    187:         * Map the overlay and overlay enable planes.
                    188:         */
                    189:        sc->sc_enable = (volatile u_char *)mapiodev(ca->ca_ra.ra_reg,
                    190:            PFOUR_COLOR_OFF_ENABLE, round_page(sc->sc_sunfb.sf_fbsize));
                    191:        sc->sc_sunfb.sf_ro.ri_bits =  mapiodev(ca->ca_ra.ra_reg,
                    192:            PFOUR_COLOR_OFF_OVERLAY, round_page(sc->sc_sunfb.sf_fbsize));
                    193:
                    194:        cgeight_reset(sc, WSDISPLAYIO_MODE_EMUL);
                    195:        fbwscons_init(&sc->sc_sunfb, isconsole ? 0 : RI_CLEAR);
                    196:        printf(": p4, %dx%d", sc->sc_sunfb.sf_width,
                    197:            sc->sc_sunfb.sf_height);
                    198:
                    199:        if (isconsole) {
                    200:                fbwscons_console_init(&sc->sc_sunfb, -1);
                    201:        }
                    202:
                    203:        fbwscons_attach(&sc->sc_sunfb, &cgeight_accessops, isconsole);
                    204: }
                    205:
                    206: void
                    207: cgeight_reset(struct cgeight_softc *sc, int mode)
                    208: {
                    209:        volatile struct bt_regs *bt;
                    210:        union bt_cmap cm;
                    211:        u_int c;
                    212:
                    213:        bt = &sc->sc_fbc->fbc_dac;
                    214:
                    215:        /*
                    216:         * Depending on the mode requested, disable or enable
                    217:         * the overlay plane.
                    218:         */
                    219:        if (mode == WSDISPLAYIO_MODE_EMUL) {
                    220:                memset((void *)sc->sc_enable, 0xff,
                    221:                    round_page(sc->sc_sunfb.sf_fbsize));
                    222:
                    223:                /* Setup a strict mono colormap */
                    224:                cm.cm_map[0][0] = cm.cm_map[0][1] = cm.cm_map[0][2] = 0x00;
                    225:                for (c = 1; c < 256; c++) {
                    226:                        cm.cm_map[c][0] = cm.cm_map[c][1] = cm.cm_map[c][2] =
                    227:                            0xff;
                    228:                }
                    229:        } else {
                    230:                memset((void *)sc->sc_enable, 0x00,
                    231:                    round_page(sc->sc_sunfb.sf_fbsize));
                    232:
                    233:                /* Setup a ramp colormap (direct color) */
                    234:                for (c = 0; c < 256; c++) {
                    235:                        cm.cm_map[c][0] = cm.cm_map[c][1] = cm.cm_map[c][2] = c;
                    236:                }
                    237:        }
                    238:
                    239:        /* Upload the colormap into the DAC */
                    240:        bt_loadcmap(&cm, bt, 0, 256, 0);
                    241: }
                    242:
                    243: int
                    244: cgeight_ioctl(void *v, u_long cmd, caddr_t data, int flags, struct proc *p)
                    245: {
                    246:        struct cgeight_softc *sc = v;
                    247:        struct wsdisplay_fbinfo *wdf;
                    248:
                    249:        switch (cmd) {
                    250:        case WSDISPLAYIO_GTYPE:
                    251:                *(u_int *)data = WSDISPLAY_TYPE_SUNCG8;
                    252:                break;
                    253:        case WSDISPLAYIO_GINFO:
                    254:                wdf = (struct wsdisplay_fbinfo *)data;
                    255:                wdf->height = sc->sc_sunfb.sf_height;
                    256:                wdf->width = sc->sc_sunfb.sf_width;
                    257:                wdf->depth = 24;
                    258:                wdf->cmsize = 0;
                    259:                break;
                    260:        case WSDISPLAYIO_SMODE:
                    261:                cgeight_reset(sc, *(int *)data);
                    262:                break;
                    263:        case WSDISPLAYIO_SVIDEO:
                    264:        case WSDISPLAYIO_GVIDEO:
                    265:                break;
                    266:
                    267:        case WSDISPLAYIO_GETCMAP:       /* nothing to do */
                    268:        case WSDISPLAYIO_PUTCMAP:       /* nothing to do */
                    269:        case WSDISPLAYIO_GCURPOS:       /* not supported */
                    270:        case WSDISPLAYIO_SCURPOS:       /* not supported */
                    271:        case WSDISPLAYIO_GCURMAX:       /* not supported */
                    272:        case WSDISPLAYIO_GCURSOR:       /* not supported */
                    273:        case WSDISPLAYIO_SCURSOR:       /* not supported */
                    274:        default:
                    275:                return (-1);
                    276:        }
                    277:
                    278:        return (0);
                    279: }
                    280:
                    281: paddr_t
                    282: cgeight_mmap(void *v, off_t offset, int prot)
                    283: {
                    284:        struct cgeight_softc *sc = v;
                    285:
                    286:        if (offset & PGOFSET)
                    287:                return (-1);
                    288:
                    289:        /* Allow mapping of the 24-bit color planes */
                    290:        if (offset >= 0 && offset < round_page(24 * sc->sc_sunfb.sf_fbsize)) {
                    291:                return (REG2PHYS(&sc->sc_phys,
                    292:                    offset + PFOUR_COLOR_OFF_COLOR) | PMAP_NC);
                    293:        }
                    294:
                    295:        return (-1);
                    296: }

CVSweb