1 /* $NetBSD: grf_cc.c,v 1.24 1998/01/12 10:39:30 thorpej 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 #include "grfcc.h" 33 #if NGRFCC > 0 34 /* 35 * currently this is a backward compat hack that interface to 36 * view.c 37 */ 38 39 #include <sys/param.h> 40 #include <sys/proc.h> 41 #include <sys/errno.h> 42 #include <sys/ioctl.h> 43 #include <sys/queue.h> 44 #include <sys/device.h> 45 #include <sys/systm.h> 46 #include <vm/vm_param.h> 47 #include <machine/cpu.h> 48 #include <amiga/amiga/color.h> /* DEBUG */ 49 #include <amiga/amiga/device.h> 50 #include <amiga/amiga/custom.h> 51 #include <amiga/amiga/cia.h> 52 #include <amiga/dev/grfioctl.h> 53 #include <amiga/dev/grfvar.h> 54 #include <amiga/dev/grf_ccreg.h> 55 #include <amiga/dev/grfabs_reg.h> 56 #include <amiga/dev/viewioctl.h> 57 58 #include <sys/conf.h> 59 #include <machine/conf.h> 60 61 #include "view.h" 62 63 int grfccmatch __P((struct device *, struct cfdata *, void *)); 64 int grfccprint __P((void *, const char *)); 65 void grfccattach __P((struct device *, struct device *, void *)); 66 void grf_cc_on __P((struct grf_softc *)); 67 68 struct cfattach grfcc_ca = { 69 sizeof(struct grf_softc), grfccmatch, grfccattach 70 }; 71 72 /* 73 * only used in console init 74 */ 75 static struct cfdata *cfdata; 76 77 /* 78 * we make sure to only init things once. this is somewhat 79 * tricky regarding the console. 80 */ 81 int 82 grfccmatch(pdp, cfp, auxp) 83 struct device *pdp; 84 struct cfdata *cfp; 85 void *auxp; 86 { 87 static int ccconunit = -1; 88 char *mainbus_name = auxp; 89 90 /* 91 * allow only one cc console 92 */ 93 if (amiga_realconfig == 0 && ccconunit != -1) 94 return(0); 95 if (matchname("grfcc", mainbus_name) == 0) 96 return(0); 97 if (amiga_realconfig == 0 || ccconunit != cfp->cf_unit) { 98 if (grfcc_probe() == 0) 99 return(0); 100 viewprobe(); 101 /* 102 * XXX nasty hack. opens view[0] and never closes. 103 */ 104 if (viewopen(0, 0, 0, NULL)) 105 return(0); 106 if (amiga_realconfig == 0) { 107 ccconunit = cfp->cf_unit; 108 cfdata = cfp; 109 } 110 } 111 return(1); 112 } 113 114 /* 115 * attach to the grfbus (mainbus) 116 */ 117 void 118 grfccattach(pdp, dp, auxp) 119 struct device *pdp, *dp; 120 void *auxp; 121 { 122 static struct grf_softc congrf; 123 struct grf_softc *gp; 124 125 if (dp == NULL) 126 gp = &congrf; 127 else 128 gp = (struct grf_softc *)dp; 129 130 if (dp != NULL && congrf.g_regkva != 0) { 131 /* 132 * we inited earlier just copy the info 133 * take care not to copy the device struct though. 134 */ 135 bcopy(&congrf.g_display, &gp->g_display, 136 (char *)&gp[1] - (char *)&gp->g_display); 137 } else { 138 gp->g_unit = GRF_CC_UNIT; 139 gp->g_flags = GF_ALIVE; 140 gp->g_mode = cc_mode; 141 gp->g_conpri = grfcc_cnprobe(); 142 grfcc_iteinit(gp); 143 grf_cc_on(gp); 144 } 145 if (dp != NULL) 146 printf("\n"); 147 /* 148 * attach grf 149 */ 150 amiga_config_found(cfdata, &gp->g_device, gp, grfccprint); 151 } 152 153 int 154 grfccprint(auxp, pnp) 155 void *auxp; 156 const char *pnp; 157 { 158 if (pnp) 159 printf("grf%d at %s", ((struct grf_softc *)auxp)->g_unit, 160 pnp); 161 return(UNCONF); 162 } 163 164 /* 165 * Change the mode of the display. 166 * Right now all we can do is grfon/grfoff. 167 * Return a UNIX error number or 0 for success. 168 */ 169 /*ARGSUSED*/ 170 int 171 cc_mode(gp, cmd, arg, a2, a3) 172 struct grf_softc *gp; 173 u_long cmd; 174 void *arg; 175 u_long a2; 176 int a3; 177 { 178 179 switch (cmd) { 180 case GM_GRFON: 181 grf_cc_on(gp); 182 return(0); 183 case GM_GRFOFF: 184 viewioctl(0, VIOCREMOVE, NULL, -1, NULL); 185 return(0); 186 case GM_GRFCONFIG: 187 default: 188 break; 189 } 190 return(EINVAL); 191 } 192 193 void 194 grf_cc_on(gp) 195 struct grf_softc *gp; 196 { 197 struct view_size vs; 198 bmap_t bm; 199 struct grfinfo *gi; 200 201 gi = &gp->g_display; 202 203 viewioctl(0, VIOCGBMAP, (caddr_t)&bm, -1, NULL); /* XXX type of bm ? */ 204 205 gp->g_data = (caddr_t) 0xDeadBeaf; /* not particularly clean.. */ 206 207 gi->gd_regaddr = (caddr_t) 0xdff000; /* depricated */ 208 gi->gd_regsize = round_page(sizeof (custom)); 209 gi->gd_fbaddr = bm.hardware_address; 210 gi->gd_fbsize = bm.depth*bm.bytes_per_row*bm.rows; 211 212 if (viewioctl (0, VIOCGSIZE, (caddr_t)&vs, -1, NULL)) { 213 /* XXX type of vs ? */ 214 /* fill in some default values... XXX */ 215 vs.width = 640; 216 vs.height = 400; 217 vs.depth = 2; 218 } 219 gi->gd_colors = 1 << vs.depth; 220 gi->gd_planes = vs.depth; 221 222 gi->gd_fbwidth = vs.width; 223 gi->gd_fbheight = vs.height; 224 gi->gd_fbx = 0; 225 gi->gd_fby = 0; 226 gi->gd_dwidth = vs.width; 227 gi->gd_dheight = vs.height; 228 gi->gd_dx = 0; 229 gi->gd_dy = 0; 230 231 gp->g_regkva = (void *)0xDeadBeaf; /* builtin */ 232 gp->g_fbkva = NULL; /* not needed, view internal */ 233 234 viewioctl(0, VIOCDISPLAY, NULL, -1, NULL); 235 } 236 #endif 237 238