1/*	$NetBSD: grf_tv.c,v 1.14 2009/01/18 02:40:05 isaki Exp $	*/
2
3/*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1990, 1993
6 *	The Regents of the University of California.  All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 *    may be used to endorse or promote products derived from this software
22 *    without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * from: Utah $Hdr: grf_tc.c 1.20 93/08/13$
37 *
38 *	@(#)grf_tc.c	8.4 (Berkeley) 1/12/94
39 */
40
41/*
42 * Graphics routines for the X68K native custom chip set.
43 */
44
45#include <sys/cdefs.h>
46__KERNEL_RCSID(0, "$NetBSD: grf_tv.c,v 1.14 2009/01/18 02:40:05 isaki Exp $");
47
48#include <sys/param.h>
49#include <sys/device.h>
50#include <sys/errno.h>
51
52#include <machine/cpu.h>
53#include <machine/grfioctl.h>
54
55#include <x68k/dev/grfvar.h>
56#include <x68k/x68k/iodevice.h>
57
58int cc_init(struct grf_softc *, void *);
59int cc_mode(struct grf_softc *, u_long, void *);
60
61/* Initialize hardware.
62 * Must fill in the grfinfo structure in g_softc.
63 * Returns 0 if hardware not present, non-zero ow.
64 */
65int
66cc_init(struct grf_softc *gp, void *addr)
67{
68	struct grfinfo *gi = &gp->g_display;
69
70	gi->gd_fbwidth  = 1024;	/* XXX */
71	gi->gd_fbheight = 1024;	/* XXX */
72	gi->gd_planes  = 4;	/* XXX */
73	gi->gd_regaddr = (void *)0x00e80000;	/* XXX */
74	gi->gd_regsize = 0x00004000;		/* XXX */
75	gi->gd_fbaddr  = (void *)0x00e00000;	/* XXX */
76	gi->gd_fbsize  = gi->gd_fbwidth / 8 * gi->gd_fbheight * gi->gd_planes;
77	gp->g_regkva   = addr;
78	gp->g_fbkva    = addr;
79	switch(IODEVbase->io_sram[0x1d]) {
80	case 18:
81		/*
82		 * mode 18, 24kHz
83		 */
84		gi->gd_dwidth  = 1024;
85		gi->gd_dheight =  848;
86		break;
87	case 19:
88		/*
89		 * mode 19, 31kHz VGA mode
90		 */
91		gi->gd_dwidth  = 640;
92		gi->gd_dheight = 480;
93		break;
94	default:
95		/*
96		 * mode 16, 31kHz (default)
97		 */
98		gi->gd_dwidth  = 768;
99		gi->gd_dheight = 512;
100		break;
101	}
102	gi->gd_colors  = 1 << gi->gd_planes;
103
104	return 1;
105}
106
107/*
108 * Change the mode of the display.
109 * Right now all we can do is grfon/grfoff.
110 * Return a UNIX error number or 0 for success.
111 */
112/*ARGSUSED*/
113int
114cc_mode(struct grf_softc *gp, u_long cmd, void *data)
115{
116	int error = 0;
117
118	switch (cmd) {
119	case GM_GRFON:
120	case GM_GRFOFF:
121		break;
122
123	/*
124	 * Remember UVA of mapping for GCDESCRIBE.
125	 * XXX this should be per-process.
126	 */
127	case GM_MAP:
128		gp->g_data = data;
129		break;
130
131	case GM_UNMAP:
132		gp->g_data = 0;
133		break;
134
135	case GM_GRFSETVMODE:
136		if (*(int *)data == 1) {
137			struct grfinfo *gi = &gp->g_display;
138			volatile struct crtc *crtc = &IODEVbase->io_crtc;
139			/* Reset CRTC, set dwidth and dheight accordingly */
140			crtc->r20 = (crtc->r20 & 0xFF00) | 0x1a;
141			crtc->r08 = 0x1b;
142			crtc->r07 = 0x19c;
143			crtc->r06 = 0x1c;
144			crtc->r05 = 0x02;
145			crtc->r04 = 0x019f;
146			crtc->r03 = 0x9a;
147			crtc->r02 = 0x1a;
148			crtc->r01 = 0x09;
149			crtc->r00 = 0xa4;
150			gi->gd_dwidth = 1024;
151			gi->gd_dheight = 768;
152		}
153		break;
154
155	default:
156		error = EINVAL;
157		break;
158	}
159	return error;
160}
161