NetBSD/sys/arch/x68k/dev/grf_machdep.c

270 lines
7.6 KiB
C
Raw Normal View History

/* $NetBSD: grf_machdep.c,v 1.22 2005/06/13 00:07:39 he Exp $ */
1996-05-05 16:17:03 +04:00
/*
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Science Department.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Utah $Hdr: grf_machdep.c 1.1 92/01/21
*
* @(#)grf_machdep.c 8.2 (Berkeley) 1/12/94
*/
/*
* Copyright (c) 1991 University of Utah.
*
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Science Department.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
1996-05-05 16:17:03 +04:00
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Utah $Hdr: grf_machdep.c 1.1 92/01/21
*
* @(#)grf_machdep.c 8.2 (Berkeley) 1/12/94
*/
/*
* Graphics display driver for the HP300/400 DIO/DIO-II based machines.
* This is the hardware-dependent configuration portion of the driver.
*/
2003-07-15 05:44:50 +04:00
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: grf_machdep.c,v 1.22 2005/06/13 00:07:39 he Exp $");
#include "locators.h"
2003-07-15 05:44:50 +04:00
1996-05-05 16:17:03 +04:00
#include <sys/param.h>
#include <sys/systm.h>
1996-05-05 16:17:03 +04:00
#include <sys/device.h>
#include <machine/grfioctl.h>
1996-05-05 16:17:03 +04:00
#include <x68k/dev/grfvar.h>
#include <x68k/x68k/iodevice.h>
/*
* false when initing for the console.
*/
extern int x68k_realconfig;
extern int x68k_config_found(struct cfdata *, struct device *,
void *, cfprint_t);
1996-05-05 16:17:03 +04:00
/* grfbus: is this necessary? */
int grfbusprint(void *auxp, const char *);
int grfbusmatch(struct device *, struct cfdata *, void *);
void grfbusattach(struct device *, struct device *, void *);
int grfbussearch(struct device *, struct cfdata *, void *);
1996-05-05 16:17:03 +04:00
/* grf itself */
void grfattach(struct device *, struct device *, void *);
int grfmatch(struct device *, struct cfdata *, void *);
int grfprint(void *, const char *);
1996-05-05 16:17:03 +04:00
static int grfinit(void *, int);
1997-10-12 18:44:12 +04:00
2002-10-01 08:43:01 +04:00
CFATTACH_DECL(grfbus, sizeof(struct device),
2002-10-02 20:02:08 +04:00
grfbusmatch, grfbusattach, NULL, NULL);
1996-05-05 16:17:03 +04:00
2002-10-01 08:43:01 +04:00
CFATTACH_DECL(grf, sizeof(struct grf_softc),
2002-10-02 20:02:08 +04:00
grfmatch, grfattach, NULL, NULL);
1996-05-05 16:17:03 +04:00
/*
* only used in console init.
*/
static struct cfdata *cfdata_gbus;
static struct cfdata *cfdata_grf;
1996-05-05 16:17:03 +04:00
1998-01-12 23:52:29 +03:00
extern struct cfdriver grfbus_cd;
1996-05-05 16:17:03 +04:00
int
2005-01-18 10:12:15 +03:00
grfbusmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
1996-05-05 16:17:03 +04:00
{
if (strcmp(auxp, grfbus_cd.cd_name))
return (0);
1996-05-05 16:17:03 +04:00
2005-01-18 10:12:15 +03:00
if ((x68k_realconfig == 0) || (cfdata_gbus == NULL)) {
1996-05-05 16:17:03 +04:00
/*
* Probe layers we depend on
*/
2005-01-18 10:12:15 +03:00
if (x68k_realconfig == 0) {
1996-05-05 16:17:03 +04:00
cfdata_gbus = cfp;
}
}
return (1);
1996-05-05 16:17:03 +04:00
}
void
2005-01-18 10:12:15 +03:00
grfbusattach(struct device *pdp, struct device *dp, void *auxp)
1996-05-05 16:17:03 +04:00
{
int i;
if (dp == NULL) {
i = 0;
x68k_config_found(cfdata_gbus, NULL, &i, grfbusprint);
1996-05-05 16:17:03 +04:00
} else {
1996-10-13 07:29:05 +04:00
printf("\n");
config_search(grfbussearch, dp, NULL);
1996-05-05 16:17:03 +04:00
}
}
int
2005-01-18 10:12:15 +03:00
grfbussearch(struct device *dp, struct cfdata *match, void *aux)
1996-05-05 16:17:03 +04:00
{
2005-01-18 10:12:15 +03:00
config_found(dp, &match->cf_loc[GRFBCF_ADDR], grfbusprint);
return (0);
1996-05-05 16:17:03 +04:00
}
int
2005-01-18 10:12:15 +03:00
grfbusprint(void *auxp, const char *name)
1996-05-05 16:17:03 +04:00
{
2005-01-18 10:12:15 +03:00
if (name == NULL)
return (UNCONF);
return (QUIET);
1996-05-05 16:17:03 +04:00
}
/*
* Normal init routine called by configure() code
*/
int
2005-01-18 10:12:15 +03:00
grfmatch(struct device *parent, struct cfdata *cfp, void *aux)
1996-05-05 16:17:03 +04:00
{
int addr;
addr = cfp->cf_loc[GRFBCF_ADDR];
1996-05-05 16:17:03 +04:00
if (x68k_realconfig == 0) {
if (addr != 0)
return 0;
1996-05-05 16:17:03 +04:00
cfdata_grf = cfp;
}
if (addr < 0 || addr > ngrfsw)
return 0;
return 1;
1996-05-05 16:17:03 +04:00
}
static struct grf_softc congrf;
1996-05-05 16:17:03 +04:00
void
2005-01-18 10:12:15 +03:00
grfattach(struct device *parent, struct device *dp, void *aux)
1996-05-05 16:17:03 +04:00
{
struct grf_softc *gp;
struct cfdata *cf;
int addr;
1996-05-05 16:17:03 +04:00
/*
* Handle exeption case: early console init
*/
if (dp == NULL) {
1996-05-05 16:17:03 +04:00
/* Attach console ite */
grfinit(&congrf, 0);
1996-05-05 16:17:03 +04:00
x68k_config_found(cfdata_grf, NULL, &congrf, grfprint);
return;
}
cf = dp->dv_cfdata;
addr = cf->cf_loc[GRFBCF_ADDR];
grfinit(dp, addr);
1996-05-05 16:17:03 +04:00
gp = (struct grf_softc *)dp;
gp->g_cfaddr = addr;
printf(": %d x %d ", gp->g_display.gd_dwidth, gp->g_display.gd_dheight);
1996-05-05 16:17:03 +04:00
if (gp->g_display.gd_colors == 2)
1996-10-13 07:29:05 +04:00
printf("monochrome");
1996-05-05 16:17:03 +04:00
else
1996-10-13 07:29:05 +04:00
printf("%d colors", gp->g_display.gd_colors);
printf(" %s display\n", gp->g_sw->gd_desc);
1996-05-05 16:17:03 +04:00
/*
* try and attach an ite
*/
config_found(dp, gp, grfprint);
}
int
2005-01-18 10:12:15 +03:00
grfprint(void *auxp, const char *pnp)
1996-05-05 16:17:03 +04:00
{
if (pnp)
aprint_normal("ite at %s", pnp);
return UNCONF;
1996-05-05 16:17:03 +04:00
}
int
grfinit(void *dp, int cfaddr)
1996-05-05 16:17:03 +04:00
{
struct grf_softc *gp = dp;
2005-01-18 10:12:15 +03:00
struct grfsw *gsw;
caddr_t addr;
if (cfaddr == 0)
addr = (caddr_t)__UNVOLATILE(IODEVbase->tvram);
else
addr = (caddr_t)__UNVOLATILE(IODEVbase->gvram);
1996-05-05 16:17:03 +04:00
gsw = &grfsw[cfaddr];
1996-05-05 16:17:03 +04:00
if (gsw < &grfsw[ngrfsw] && (*gsw->gd_init)(gp, addr)) {
gp->g_sw = gsw;
gp->g_display.gd_id = gsw->gd_swid;
gp->g_flags = GF_ALIVE;
return 1;
1996-05-05 16:17:03 +04:00
}
return 0;
1996-05-05 16:17:03 +04:00
}