#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: grf_cc.c,v 1.45 2025/12/13 05:40:16 andvar Exp $");
#include "grfcc.h"
#include "ite.h"
#if NGRFCC > 0
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/queue.h>
#include <sys/device.h>
#include <sys/device_impl.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <machine/cpu.h>
#include <amiga/amiga/color.h>
#include <amiga/amiga/device.h>
#include <amiga/amiga/custom.h>
#include <amiga/amiga/cia.h>
#include <amiga/dev/grfioctl.h>
#include <amiga/dev/grfvar.h>
#include <amiga/dev/grf_ccreg.h>
#include <amiga/dev/grfabs_reg.h>
#include <amiga/dev/viewioctl.h>
#include "view.h"
int grfccmatch(device_t, cfdata_t, void *);
int grfccprint(void *, const char *);
void grfccattach(device_t, device_t, void *);
void grf_cc_on(struct grf_softc *);
CFATTACH_DECL_NEW(grfcc, sizeof(struct grf_softc),
grfccmatch, grfccattach, NULL, NULL);
static cfdata_t cfdata;
int
grfccmatch(device_t parent, cfdata_t cf, void *aux)
{
static int ccconunit = -1;
char *mainbus_name = aux;
extern const struct cdevsw view_cdevsw;
if (amiga_realconfig == 0 && ccconunit != -1)
return(0);
if (matchname("grfcc", mainbus_name) == 0)
return(0);
if (amiga_realconfig == 0 || ccconunit != cf->cf_unit) {
if (grfcc_probe() == 0)
return(0);
viewprobe();
if ((*view_cdevsw.d_open)(0, 0, 0, NULL))
return(0);
if (amiga_realconfig == 0) {
ccconunit = cf->cf_unit;
cfdata = cf;
}
}
return(1);
}
void
grfccattach(device_t parent, device_t self, void *aux)
{
static struct grf_softc congrf;
struct device temp;
struct grf_softc *gp;
if (self == NULL) {
gp = &congrf;
gp->g_device = &temp;
temp.dv_private = gp;
} else {
gp = device_private(self);
gp->g_device = self;
}
if (self != NULL && congrf.g_regkva != 0) {
memcpy(&gp->g_display, &congrf.g_display,
(char *)&gp[1] - (char *)&gp->g_display);
} else {
gp->g_unit = GRF_CC_UNIT;
gp->g_flags = GF_ALIVE;
gp->g_mode = cc_mode;
#if NITE > 0
gp->g_conpri = grfcc_cnprobe();
grfcc_iteinit(gp);
#endif
grf_cc_on(gp);
}
if (self != NULL)
printf("\n");
amiga_config_found(cfdata, gp->g_device, gp, grfccprint, CFARGS_NONE);
}
int
grfccprint(void *aux, const char *pnp)
{
if (pnp)
aprint_normal("grf%d at %s", ((struct grf_softc *)aux)->g_unit,
pnp);
return(UNCONF);
}
int
cc_mode(struct grf_softc *gp, u_long cmd, void *arg, u_long a2, int a3)
{
extern const struct cdevsw view_cdevsw;
switch (cmd) {
case GM_GRFON:
grf_cc_on(gp);
return(0);
case GM_GRFOFF:
(*view_cdevsw.d_ioctl)(0, VIOCREMOVE, NULL, -1, NULL);
return(0);
case GM_GRFCONFIG:
default:
break;
}
return(EPASSTHROUGH);
}
void
grf_cc_on(struct grf_softc *gp)
{
struct view_size vs;
bmap_t bm;
struct grfinfo *gi;
extern const struct cdevsw view_cdevsw;
gi = &gp->g_display;
(*view_cdevsw.d_ioctl)(0, VIOCGBMAP, (void *)&bm, -1, NULL);
gp->g_data = (void *) 0xDeadBeaf;
gi->gd_regaddr = (void *) 0xdff000;
gi->gd_regsize = round_page(sizeof (custom));
gi->gd_fbaddr = bm.hardware_address;
gi->gd_fbsize = bm.depth*bm.bytes_per_row*bm.rows;
if ((*view_cdevsw.d_ioctl)(0, VIOCGSIZE, (void *)&vs, -1, NULL)) {
vs.width = 640;
vs.height = 400;
vs.depth = 2;
}
gi->gd_colors = 1 << vs.depth;
gi->gd_planes = vs.depth;
gi->gd_fbwidth = vs.width;
gi->gd_fbheight = vs.height;
gi->gd_fbx = 0;
gi->gd_fby = 0;
gi->gd_dwidth = vs.width;
gi->gd_dheight = vs.height;
gi->gd_dx = 0;
gi->gd_dy = 0;
gp->g_regkva = (void *)0xDeadBeaf;
gp->g_fbkva = NULL;
(*view_cdevsw.d_ioctl)(0, VIOCDISPLAY, NULL, -1, NULL);
}
#endif