Home | History | Annotate | Line # | Download | only in dev
grf_cc.c revision 1.39.8.2
      1 /*	$NetBSD: grf_cc.c,v 1.39.8.2 2012/10/30 17:18:48 yamt Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1994 Christian E. Hopps
      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  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Christian E. Hopps.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: grf_cc.c,v 1.39.8.2 2012/10/30 17:18:48 yamt Exp $");
     35 
     36 #include "grfcc.h"
     37 #include "ite.h"
     38 #if NGRFCC > 0
     39 /*
     40  * currently this is a backward compat hack that interface to
     41  * view.c
     42  */
     43 
     44 #include <sys/param.h>
     45 #include <sys/proc.h>
     46 #include <sys/errno.h>
     47 #include <sys/ioctl.h>
     48 #include <sys/queue.h>
     49 #include <sys/device.h>
     50 #include <sys/systm.h>
     51 #include <sys/conf.h>
     52 #include <machine/cpu.h>
     53 #include <amiga/amiga/color.h>	/* DEBUG */
     54 #include <amiga/amiga/device.h>
     55 #include <amiga/amiga/custom.h>
     56 #include <amiga/amiga/cia.h>
     57 #include <amiga/dev/grfioctl.h>
     58 #include <amiga/dev/grfvar.h>
     59 #include <amiga/dev/grf_ccreg.h>
     60 #include <amiga/dev/grfabs_reg.h>
     61 #include <amiga/dev/viewioctl.h>
     62 
     63 #include "view.h"
     64 
     65 int grfccmatch(device_t, cfdata_t, void *);
     66 int grfccprint(void *, const char *);
     67 void grfccattach(device_t, device_t, void *);
     68 void grf_cc_on(struct grf_softc *);
     69 
     70 CFATTACH_DECL_NEW(grfcc, sizeof(struct grf_softc),
     71     grfccmatch, grfccattach, NULL, NULL);
     72 
     73 /*
     74  * only used in console init
     75  */
     76 static cfdata_t cfdata;
     77 
     78 /*
     79  * we make sure to only init things once.  this is somewhat
     80  * tricky regarding the console.
     81  */
     82 int
     83 grfccmatch(device_t parent, cfdata_t cf, void *aux)
     84 {
     85 	static int ccconunit = -1;
     86 	char *mainbus_name = aux;
     87 	extern const struct cdevsw view_cdevsw;
     88 
     89 	/*
     90 	 * allow only one cc console
     91 	 */
     92 	if (amiga_realconfig == 0 && ccconunit != -1)
     93 		return(0);
     94 	if (matchname("grfcc", mainbus_name) == 0)
     95 		return(0);
     96 	if (amiga_realconfig == 0 || ccconunit != cf->cf_unit) {
     97 		if (grfcc_probe() == 0)
     98 			return(0);
     99 		viewprobe();
    100 		/*
    101 		 * XXX nasty hack. opens view[0] and never closes.
    102 		 */
    103 		if ((*view_cdevsw.d_open)(0, 0, 0, NULL))
    104 			return(0);
    105 		if (amiga_realconfig == 0) {
    106 			ccconunit = cf->cf_unit;
    107 			cfdata = cf;
    108 		}
    109 	}
    110 	return(1);
    111 }
    112 
    113 /*
    114  * attach to the grfbus (mainbus)
    115  */
    116 void
    117 grfccattach(device_t parent, device_t self, void *aux)
    118 {
    119 	static struct grf_softc congrf;
    120 	struct device temp;
    121 	struct grf_softc *gp;
    122 
    123 	if (self == NULL) {
    124 		gp = &congrf;
    125 		gp->g_device = &temp;
    126 		temp.dv_private = gp;
    127 	} else {
    128 		gp = device_private(self);
    129 		gp->g_device = self;
    130 	}
    131 
    132 	if (self != NULL && congrf.g_regkva != 0) {
    133 		/*
    134 		 * we inited earlier just copy the info
    135 		 * take care not to copy the device struct though.
    136 		 */
    137 		memcpy(&gp->g_display, &congrf.g_display,
    138 		    (char *)&gp[1] - (char *)&gp->g_display);
    139 	} else {
    140 		gp->g_unit = GRF_CC_UNIT;
    141 		gp->g_flags = GF_ALIVE;
    142 		gp->g_mode = cc_mode;
    143 #if NITE > 0
    144 		gp->g_conpri = grfcc_cnprobe();
    145 		grfcc_iteinit(gp);
    146 #endif
    147 		grf_cc_on(gp);
    148 	}
    149 	if (self != NULL)
    150 		printf("\n");
    151 	/*
    152 	 * attach grf
    153 	 */
    154 	amiga_config_found(cfdata, gp->g_device, gp, grfccprint);
    155 }
    156 
    157 int
    158 grfccprint(void *aux, const char *pnp)
    159 {
    160 	if (pnp)
    161 		aprint_normal("grf%d at %s", ((struct grf_softc *)aux)->g_unit,
    162 			pnp);
    163 	return(UNCONF);
    164 }
    165 
    166 /*
    167  * Change the mode of the display.
    168  * Right now all we can do is grfon/grfoff.
    169  * Return a UNIX error number or 0 for success.
    170  */
    171 /*ARGSUSED*/
    172 int
    173 cc_mode(struct grf_softc *gp, u_long cmd, void *arg, u_long a2, int a3)
    174 {
    175 	extern const struct cdevsw view_cdevsw;
    176 
    177 	switch (cmd) {
    178 	case GM_GRFON:
    179 		grf_cc_on(gp);
    180 		return(0);
    181 	case GM_GRFOFF:
    182 		(*view_cdevsw.d_ioctl)(0, VIOCREMOVE, NULL, -1, NULL);
    183 		return(0);
    184 	case GM_GRFCONFIG:
    185 	default:
    186 		break;
    187 	}
    188 	return(EPASSTHROUGH);
    189 }
    190 
    191 void
    192 grf_cc_on(struct grf_softc *gp)
    193 {
    194 	struct view_size vs;
    195 	bmap_t bm;
    196 	struct grfinfo *gi;
    197 	extern const struct cdevsw view_cdevsw;
    198 
    199 	gi = &gp->g_display;
    200 
    201 	/* XXX type of bm ? */
    202 	(*view_cdevsw.d_ioctl)(0, VIOCGBMAP, (void *)&bm, -1, NULL);
    203 
    204 	gp->g_data = (void *) 0xDeadBeaf; /* not particularly clean.. */
    205 
    206 	gi->gd_regaddr = (void *) 0xdff000;	/* depricated */
    207 	gi->gd_regsize = round_page(sizeof (custom));
    208 	gi->gd_fbaddr  = bm.hardware_address;
    209 	gi->gd_fbsize  = bm.depth*bm.bytes_per_row*bm.rows;
    210 
    211 	if ((*view_cdevsw.d_ioctl)(0, VIOCGSIZE, (void *)&vs, -1, NULL)) {
    212 		/* XXX type of vs ? */
    213 		/* fill in some default values... XXX */
    214 		vs.width = 640;
    215 		vs.height = 400;
    216 		vs.depth = 2;
    217 	}
    218 	gi->gd_colors = 1 << vs.depth;
    219 	gi->gd_planes = vs.depth;
    220 
    221 	gi->gd_fbwidth = vs.width;
    222 	gi->gd_fbheight = vs.height;
    223 	gi->gd_fbx = 0;
    224 	gi->gd_fby = 0;
    225 	gi->gd_dwidth = vs.width;
    226 	gi->gd_dheight = vs.height;
    227 	gi->gd_dx = 0;
    228 	gi->gd_dy = 0;
    229 
    230 	gp->g_regkva = (void *)0xDeadBeaf;	/* builtin */
    231 	gp->g_fbkva = NULL;		/* not needed, view internal */
    232 
    233 	(*view_cdevsw.d_ioctl)(0, VIOCDISPLAY, NULL, -1, NULL);
    234 }
    235 #endif
    236