pnozz_driver.c revision 20e46bc2
1a6b33934Smacallan/*
2a6b33934Smacallan * SBus Weitek P9100 driver
3a6b33934Smacallan *
4a6b33934Smacallan * Copyright (C) 2005, 2006 Michael Lorenz
5a6b33934Smacallan *
6a6b33934Smacallan * Permission is hereby granted, free of charge, to any person obtaining a copy
7a6b33934Smacallan * of this software and associated documentation files (the "Software"), to deal
8a6b33934Smacallan * in the Software without restriction, including without limitation the rights
9a6b33934Smacallan * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10a6b33934Smacallan * copies of the Software, and to permit persons to whom the Software is
11a6b33934Smacallan * furnished to do so, subject to the following conditions:
12a6b33934Smacallan *
13a6b33934Smacallan * The above copyright notice and this permission notice shall be included in
14a6b33934Smacallan * all copies or substantial portions of the Software.
15a6b33934Smacallan *
16a6b33934Smacallan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17a6b33934Smacallan * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18a6b33934Smacallan * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19a6b33934Smacallan * MICHAEL LORENZ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20a6b33934Smacallan * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21a6b33934Smacallan * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22a6b33934Smacallan */
2320e46bc2Smrg/* $NetBSD: pnozz_driver.c,v 1.4 2010/11/26 21:18:10 mrg Exp $ */
24a6b33934Smacallan
25a6b33934Smacallan/*
26a6b33934Smacallan * this driver has been tested on SPARCbook 3GX and 3TX, it supports full
27a6b33934Smacallan * acceleration in 8, 16 and 24 bit colour
28a6b33934Smacallan */
29a6b33934Smacallan
30a6b33934Smacallan#include <fcntl.h>
31a6b33934Smacallan#include <sys/time.h>
32a6b33934Smacallan#include <sys/types.h>
33a6b33934Smacallan#include <dev/sun/fbio.h>
34a6b33934Smacallan#include <dev/wscons/wsconsio.h>
35a6b33934Smacallan
36a6b33934Smacallan#include "xf86.h"
37a6b33934Smacallan#include "xf86_OSproc.h"
38a6b33934Smacallan
3920e46bc2Smrg#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
40a6b33934Smacallan#include "xf86Resources.h"
4120e46bc2Smrg#endif
42a6b33934Smacallan#include "xf86sbusBus.h"
43a6b33934Smacallan
44a6b33934Smacallan#include "mipointer.h"
45a6b33934Smacallan#include "mibstore.h"
46a6b33934Smacallan#include "micmap.h"
47a6b33934Smacallan
48a6b33934Smacallan#define DEBUG 0
49a6b33934Smacallan
50a6b33934Smacallan#include "fb.h"
51a6b33934Smacallan#include "xf86cmap.h"
52a6b33934Smacallan#include "pnozz.h"
53a6b33934Smacallan
54c59a3c9dSmrg#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) > 6
551b41fcf5Smrg#define xf86LoaderReqSymLists(...) do {} while (0)
561b41fcf5Smrg#define LoaderRefSymLists(...) do {} while (0)
571b41fcf5Smrg#endif
581b41fcf5Smrg
59a6b33934Smacallanstatic const OptionInfoRec * PnozzAvailableOptions(int chipid, int busid);
60a6b33934Smacallanstatic void	PnozzIdentify(int flags);
61a6b33934Smacallanstatic Bool	PnozzProbe(DriverPtr drv, int flags);
62a6b33934Smacallanstatic Bool	PnozzPreInit(ScrnInfoPtr pScrn, int flags);
63a6b33934Smacallanstatic Bool	PnozzScreenInit(int Index, ScreenPtr pScreen, int argc,
64a6b33934Smacallan			      char **argv);
65a6b33934Smacallanstatic Bool	PnozzEnterVT(int scrnIndex, int flags);
66a6b33934Smacallanstatic void	PnozzLeaveVT(int scrnIndex, int flags);
67a6b33934Smacallanstatic Bool	PnozzCloseScreen(int scrnIndex, ScreenPtr pScreen);
68a6b33934Smacallanstatic Bool	PnozzSaveScreen(ScreenPtr pScreen, int mode);
69a6b33934Smacallan
70a6b33934Smacallan/* Required if the driver supports mode switching */
71a6b33934Smacallanstatic Bool	PnozzSwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
72a6b33934Smacallan/* Required if the driver supports moving the viewport */
73a6b33934Smacallanstatic void	PnozzAdjustFrame(int scrnIndex, int x, int y, int flags);
74a6b33934Smacallan
75a6b33934Smacallan/* Optional functions */
76a6b33934Smacallanstatic void	PnozzFreeScreen(int scrnIndex, int flags);
77a6b33934Smacallanstatic ModeStatus PnozzValidMode(int scrnIndex, DisplayModePtr mode,
78a6b33934Smacallan			       Bool verbose, int flags);
79a6b33934Smacallan
80a6b33934Smacallanvoid PnozzSync(ScrnInfoPtr);
81a6b33934Smacallanvoid PnozzSave(PnozzPtr);
82a6b33934Smacallanvoid PnozzRestore(PnozzPtr);
83a6b33934Smacallanint PnozzSetDepth(PnozzPtr, int);	/* return true or false */
84a6b33934Smacallanvoid DumpSCR(unsigned int);
85a6b33934Smacallan
86a6b33934Smacallanstatic void PnozzLoadPalette(ScrnInfoPtr, int, int *, LOCO *, VisualPtr);
87a6b33934Smacallan
88a6b33934Smacallan#define VERSION 4000
89a6b33934Smacallan#define PNOZZ_NAME "p9100"
90a6b33934Smacallan#define PNOZZ_DRIVER_NAME "pnozz"
91a6b33934Smacallan#define PNOZZ_MAJOR_VERSION 1
92a6b33934Smacallan#define PNOZZ_MINOR_VERSION 0
93a6b33934Smacallan#define PNOZZ_PATCHLEVEL 0
94a6b33934Smacallan
95a6b33934Smacallan/*
96a6b33934Smacallan * This contains the functions needed by the server after loading the driver
97a6b33934Smacallan * module.  It must be supplied, and gets passed back by the SetupProc
98a6b33934Smacallan * function in the dynamic case.  In the static case, a reference to this
99a6b33934Smacallan * is compiled in, and this requires that the name of this DriverRec be
100a6b33934Smacallan * an upper-case version of the driver name.
101a6b33934Smacallan */
102a6b33934Smacallan
103a6b33934SmacallanDriverRec PNOZZ = {
104a6b33934Smacallan    VERSION,
105a6b33934Smacallan    PNOZZ_DRIVER_NAME,
106a6b33934Smacallan    PnozzIdentify,
107a6b33934Smacallan    PnozzProbe,
108a6b33934Smacallan    PnozzAvailableOptions,
109a6b33934Smacallan    NULL,
110a6b33934Smacallan    0
111a6b33934Smacallan};
112a6b33934Smacallan
113a6b33934Smacallantypedef enum {
114a6b33934Smacallan    OPTION_SW_CURSOR,
115a6b33934Smacallan    OPTION_HW_CURSOR,
116a6b33934Smacallan    OPTION_NOACCEL
117a6b33934Smacallan} PnozzOpts;
118a6b33934Smacallan
119a6b33934Smacallanstatic const OptionInfoRec PnozzOptions[] = {
120a6b33934Smacallan    { OPTION_SW_CURSOR,		"SWcursor",	OPTV_BOOLEAN,	{0}, FALSE },
121a6b33934Smacallan    { OPTION_HW_CURSOR,		"HWcursor",	OPTV_BOOLEAN,	{0}, FALSE },
122a6b33934Smacallan    { OPTION_NOACCEL,		"NoAccel",	OPTV_BOOLEAN,	{0}, FALSE },
123a6b33934Smacallan    { -1,			NULL,		OPTV_NONE,	{0}, FALSE }
124a6b33934Smacallan};
125a6b33934Smacallan
126a6b33934Smacallanstatic const char *ramdacSymbols[] = {
127a6b33934Smacallan    "xf86CreateCursorInfoRec",
128a6b33934Smacallan    "xf86DestroyCursorInfoRec",
129a6b33934Smacallan    "xf86InitCursor",
130a6b33934Smacallan    NULL
131a6b33934Smacallan};
132a6b33934Smacallan
133a6b33934Smacallanstatic const char *fbSymbols[] = {
134a6b33934Smacallan    "fbScreenInit",
135a6b33934Smacallan    "fbPictureInit",
136a6b33934Smacallan    NULL
137a6b33934Smacallan};
138a6b33934Smacallan
139a6b33934Smacallanstatic const char *xaaSymbols[] =
140a6b33934Smacallan{
141a6b33934Smacallan    "XAACreateInfoRec",
142a6b33934Smacallan    "XAADestroyInfoRec",
143a6b33934Smacallan    "XAAInit",
144a6b33934Smacallan    NULL
145a6b33934Smacallan};
146a6b33934Smacallan#ifdef XFree86LOADER
147a6b33934Smacallan
148a6b33934Smacallanstatic MODULESETUPPROTO(PnozzSetup);
149a6b33934Smacallan
150a6b33934Smacallanstatic XF86ModuleVersionInfo PnozzVersRec =
151a6b33934Smacallan{
152a6b33934Smacallan	"pnozz",
153a6b33934Smacallan	MODULEVENDORSTRING,
154a6b33934Smacallan	MODINFOSTRING1,
155a6b33934Smacallan	MODINFOSTRING2,
156a6b33934Smacallan	XORG_VERSION_CURRENT,
157a6b33934Smacallan	PNOZZ_MAJOR_VERSION, PNOZZ_MINOR_VERSION, PNOZZ_PATCHLEVEL,
158a6b33934Smacallan	ABI_CLASS_VIDEODRV,
159a6b33934Smacallan	ABI_VIDEODRV_VERSION,
160a6b33934Smacallan	MOD_CLASS_VIDEODRV,
161a6b33934Smacallan	{0,0,0,0}
162a6b33934Smacallan};
163a6b33934Smacallan
164a6b33934SmacallanXF86ModuleData pnozzModuleData = { &PnozzVersRec, PnozzSetup, NULL };
165a6b33934Smacallan
166a6b33934Smacallanpointer
167a6b33934SmacallanPnozzSetup(pointer module, pointer opts, int *errmaj, int *errmin)
168a6b33934Smacallan{
169a6b33934Smacallan    static Bool setupDone = FALSE;
170a6b33934Smacallan
171a6b33934Smacallan    if (!setupDone) {
172a6b33934Smacallan	setupDone = TRUE;
173a6b33934Smacallan	xf86AddDriver(&PNOZZ, module, 0);
174a6b33934Smacallan
175a6b33934Smacallan	LoaderRefSymLists(xaaSymbols, ramdacSymbols, fbSymbols, NULL);
176a6b33934Smacallan	/*
177a6b33934Smacallan	 * Modules that this driver always requires can be loaded here
178a6b33934Smacallan	 * by calling LoadSubModule().
179a6b33934Smacallan	 */
180a6b33934Smacallan
181a6b33934Smacallan	/*
182a6b33934Smacallan	 * The return value must be non-NULL on success even though there
183a6b33934Smacallan	 * is no TearDownProc.
184a6b33934Smacallan	 */
185a6b33934Smacallan	return (pointer)TRUE;
186a6b33934Smacallan    } else {
187a6b33934Smacallan	if (errmaj) *errmaj = LDR_ONCEONLY;
188a6b33934Smacallan	return NULL;
189a6b33934Smacallan    }
190a6b33934Smacallan}
191a6b33934Smacallan
192a6b33934Smacallan#endif /* XFree86LOADER */
193a6b33934Smacallan
194a6b33934Smacallanstatic volatile unsigned int scratch32;
195a6b33934Smacallan
196a6b33934Smacallanvoid pnozz_write_4(PnozzPtr p, int offset, unsigned int value)
197a6b33934Smacallan{
198a6b33934Smacallan	if ((offset & 0xffffff80) != p->offset_mask) {
199a6b33934Smacallan		p->offset_mask = offset & 0xffffff80;
200a6b33934Smacallan		scratch32 = *(volatile unsigned int *)(p->fb + offset);
201a6b33934Smacallan	}
202a6b33934Smacallan	*((volatile unsigned int *)(p->fbc + offset)) = value;
203a6b33934Smacallan}
204a6b33934Smacallan
205a6b33934Smacallanunsigned int pnozz_read_4(PnozzPtr p, int offset)
206a6b33934Smacallan{
207a6b33934Smacallan	if ((offset & 0xffffff80) != p->offset_mask) {
208a6b33934Smacallan		p->offset_mask = offset & 0xffffff80;
209a6b33934Smacallan		scratch32 = *(volatile unsigned int *)(p->fb + offset);
210a6b33934Smacallan	}
211a6b33934Smacallan	return *(volatile unsigned int *)(p->fbc + offset);
212a6b33934Smacallan}
213a6b33934Smacallan
214a6b33934Smacallanvoid pnozz_write_dac(PnozzPtr p, int offset, unsigned char value)
215a6b33934Smacallan{
216a6b33934Smacallan	CARD32 val = ((CARD32)value) << 16;
217a6b33934Smacallan
218a6b33934Smacallan	scratch32 = pnozz_read_4(p, PWRUP_CNFG);
219a6b33934Smacallan	if ((offset != DAC_INDX_DATA) && (offset != DAC_CMAP_DATA)) {
220a6b33934Smacallan		do {
221a6b33934Smacallan			pnozz_write_4(p, offset, val);
222a6b33934Smacallan		} while (pnozz_read_4(p, offset) != val);
223a6b33934Smacallan	} else {
224a6b33934Smacallan		pnozz_write_4(p, offset, val);
225a6b33934Smacallan	}
226a6b33934Smacallan}
227a6b33934Smacallan
228a6b33934Smacallanunsigned char pnozz_read_dac(PnozzPtr p, int offset)
229a6b33934Smacallan{
230a6b33934Smacallan	scratch32 = pnozz_read_4(p, PWRUP_CNFG);
231a6b33934Smacallan	return ((pnozz_read_4(p, offset) >> 16) & 0xff);
232a6b33934Smacallan}
233a6b33934Smacallan
234a6b33934Smacallanvoid pnozz_write_dac_ctl_reg(PnozzPtr p, int offset, unsigned char val)
235a6b33934Smacallan{
236a6b33934Smacallan
237a6b33934Smacallan	pnozz_write_dac(p, DAC_INDX_HI, (offset & 0xff00) >> 8);
238a6b33934Smacallan	pnozz_write_dac(p, DAC_INDX_LO, (offset & 0xff));
239a6b33934Smacallan	pnozz_write_dac(p, DAC_INDX_DATA, val);
240a6b33934Smacallan}
241a6b33934Smacallan
242a6b33934Smacallanvoid pnozz_write_dac_ctl_reg_2(PnozzPtr p, int offset, unsigned short val)
243a6b33934Smacallan{
244a6b33934Smacallan
245a6b33934Smacallan	pnozz_write_dac(p, DAC_INDX_HI, (offset & 0xff00) >> 8);
246a6b33934Smacallan	pnozz_write_dac(p, DAC_INDX_LO, (offset & 0xff));
247a6b33934Smacallan	pnozz_write_dac(p, DAC_INDX_CTL, DAC_INDX_AUTOINCR);
248a6b33934Smacallan	pnozz_write_dac(p, DAC_INDX_DATA, val & 0xff);
249a6b33934Smacallan	pnozz_write_dac(p, DAC_INDX_DATA, (val & 0xff00) >> 8);
250a6b33934Smacallan}
251a6b33934Smacallan
252a6b33934Smacallanunsigned char pnozz_read_dac_ctl_reg(PnozzPtr p, int offset)
253a6b33934Smacallan{
254a6b33934Smacallan	pnozz_write_dac(p, DAC_INDX_HI, (offset & 0xff00) >> 8);
255a6b33934Smacallan	pnozz_write_dac(p, DAC_INDX_LO, (offset & 0xff));
256a6b33934Smacallan	return pnozz_read_dac(p, DAC_INDX_DATA);
257a6b33934Smacallan}
258a6b33934Smacallan
259a6b33934Smacallanvoid pnozz_write_dac_cmap_reg(PnozzPtr p, int offset, unsigned int val)
260a6b33934Smacallan{
261a6b33934Smacallan	pnozz_write_dac(p, DAC_CMAP_WRIDX,(offset & 0xff));
262a6b33934Smacallan	pnozz_write_dac(p, DAC_CMAP_DATA,(val & 0xff));
263a6b33934Smacallan	pnozz_write_dac(p, DAC_CMAP_DATA,(val & 0xff00) >> 8);
264a6b33934Smacallan	pnozz_write_dac(p, DAC_CMAP_DATA,(val & 0xff0000) >> 16);
265a6b33934Smacallan}
266a6b33934Smacallan
267a6b33934Smacallanstatic void
268a6b33934SmacallanPnozzLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO *colors,
269a6b33934Smacallan    VisualPtr pVisual)
270a6b33934Smacallan{
271a6b33934Smacallan    PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn);
272a6b33934Smacallan    int i, index;
273a6b33934Smacallan
274a6b33934Smacallan    PnozzSync(pScrn);
275a6b33934Smacallan    pnozz_write_dac(pPnozz, DAC_INDX_CTL, DAC_INDX_AUTOINCR);
276a6b33934Smacallan
277a6b33934Smacallan    for (i = 0; i < numColors; i++)
278a6b33934Smacallan    {
279a6b33934Smacallan    	index = indices[i];
280a6b33934Smacallan	if (index >= 0) {
281a6b33934Smacallan    	    pnozz_write_dac(pPnozz, DAC_CMAP_WRIDX, index);
282a6b33934Smacallan	    pnozz_write_dac(pPnozz, DAC_CMAP_DATA, colors[index].red);
283a6b33934Smacallan	    pnozz_write_dac(pPnozz, DAC_CMAP_DATA, colors[index].green);
284a6b33934Smacallan	    pnozz_write_dac(pPnozz, DAC_CMAP_DATA, colors[index].blue);
285a6b33934Smacallan	}
286a6b33934Smacallan    }
287a6b33934Smacallan    PnozzSync(pScrn);
288a6b33934Smacallan}
289a6b33934Smacallan
290a6b33934Smacallanstatic Bool
291a6b33934SmacallanPnozzGetRec(ScrnInfoPtr pScrn)
292a6b33934Smacallan{
293a6b33934Smacallan    /*
294a6b33934Smacallan     * Allocate an PnozzRec, and hook it into pScrn->driverPrivate.
295a6b33934Smacallan     * pScrn->driverPrivate is initialised to NULL, so we can check if
296a6b33934Smacallan     * the allocation has already been done.
297a6b33934Smacallan     */
298a6b33934Smacallan    if (pScrn->driverPrivate != NULL)
299a6b33934Smacallan	return TRUE;
300a6b33934Smacallan
301a6b33934Smacallan    pScrn->driverPrivate = xnfcalloc(sizeof(PnozzRec), 1);
302a6b33934Smacallan    return TRUE;
303a6b33934Smacallan}
304a6b33934Smacallan
305a6b33934Smacallanstatic void
306a6b33934SmacallanPnozzFreeRec(ScrnInfoPtr pScrn)
307a6b33934Smacallan{
308a6b33934Smacallan    PnozzPtr pPnozz;
309a6b33934Smacallan
310a6b33934Smacallan    if (pScrn->driverPrivate == NULL)
311a6b33934Smacallan	return;
312a6b33934Smacallan
313a6b33934Smacallan    pPnozz = GET_PNOZZ_FROM_SCRN(pScrn);
314a6b33934Smacallan
315a6b33934Smacallan    xfree(pScrn->driverPrivate);
316a6b33934Smacallan    pScrn->driverPrivate = NULL;
317a6b33934Smacallan
318a6b33934Smacallan    return;
319a6b33934Smacallan}
320a6b33934Smacallan
321a6b33934Smacallanstatic const OptionInfoRec *
322a6b33934SmacallanPnozzAvailableOptions(int chipid, int busid)
323a6b33934Smacallan{
324a6b33934Smacallan    return PnozzOptions;
325a6b33934Smacallan}
326a6b33934Smacallan
327a6b33934Smacallan/* Mandatory */
328a6b33934Smacallanstatic void
329a6b33934SmacallanPnozzIdentify(int flags)
330a6b33934Smacallan{
331a6b33934Smacallan    xf86Msg(X_INFO, "%s: driver for Weitek P9100 found in Tadpole SPARCbook 3GX and others\n", PNOZZ_NAME);
332a6b33934Smacallan}
333a6b33934Smacallan
334a6b33934Smacallan
335a6b33934Smacallan/* Mandatory */
336a6b33934Smacallanstatic Bool
337a6b33934SmacallanPnozzProbe(DriverPtr drv, int flags)
338a6b33934Smacallan{
339a6b33934Smacallan    int i;
340a6b33934Smacallan    GDevPtr *devSections;
341a6b33934Smacallan    int *usedChips;
342a6b33934Smacallan    int numDevSections;
343a6b33934Smacallan    int numUsed;
344a6b33934Smacallan    Bool foundScreen = FALSE;
345a6b33934Smacallan    EntityInfoPtr pEnt;
346a6b33934Smacallan
347a6b33934Smacallan    /*
348a6b33934Smacallan     * The aim here is to find all cards that this driver can handle,
349a6b33934Smacallan     * and for the ones not already claimed by another driver, claim the
350a6b33934Smacallan     * slot, and allocate a ScrnInfoRec.
351a6b33934Smacallan     *
352a6b33934Smacallan     * This should be a minimal probe, and it should under no circumstances
353a6b33934Smacallan     * change the state of the hardware.  Because a device is found, don't
354a6b33934Smacallan     * assume that it will be used.  Don't do any initialisations other than
355a6b33934Smacallan     * the required ScrnInfoRec initialisations.  Don't allocate any new
356a6b33934Smacallan     * data structures.
357a6b33934Smacallan     */
358a6b33934Smacallan
359a6b33934Smacallan    /*
360a6b33934Smacallan     * Next we check, if there has been a chipset override in the config file.
361a6b33934Smacallan     * For this we must find out if there is an active device section which
362a6b33934Smacallan     * is relevant, i.e., which has no driver specified or has THIS driver
363a6b33934Smacallan     * specified.
364a6b33934Smacallan     */
365a6b33934Smacallan
366a6b33934Smacallan    if ((numDevSections = xf86MatchDevice(PNOZZ_DRIVER_NAME,
367a6b33934Smacallan					  &devSections)) <= 0) {
368a6b33934Smacallan	/*
369a6b33934Smacallan	 * There's no matching device section in the config file, so quit
370a6b33934Smacallan	 * now.
371a6b33934Smacallan	 */
372a6b33934Smacallan	return FALSE;
373a6b33934Smacallan    }
374a6b33934Smacallan
375a6b33934Smacallan    /*
376a6b33934Smacallan     * We need to probe the hardware first.  We then need to see how this
377a6b33934Smacallan     * fits in with what is given in the config file, and allow the config
378a6b33934Smacallan     * file info to override any contradictions.
379a6b33934Smacallan     */
380a6b33934Smacallan
381a6b33934Smacallan    numUsed = xf86MatchSbusInstances(PNOZZ_NAME, SBUS_DEVICE_P9100,
382a6b33934Smacallan		   devSections, numDevSections,
383a6b33934Smacallan		   drv, &usedChips);
384a6b33934Smacallan
385a6b33934Smacallan    xfree(devSections);
386a6b33934Smacallan    if (numUsed <= 0)
387a6b33934Smacallan	return FALSE;
388a6b33934Smacallan
389a6b33934Smacallan    if (flags & PROBE_DETECT)
390a6b33934Smacallan	foundScreen = TRUE;
391a6b33934Smacallan    else
392a6b33934Smacallan	for (i = 0; i < numUsed; i++) {
393a6b33934Smacallan	    pEnt = xf86GetEntityInfo(usedChips[i]);
394a6b33934Smacallan
395a6b33934Smacallan	    /*
396a6b33934Smacallan	     * Check that nothing else has claimed the slots.
397a6b33934Smacallan	     */
398a6b33934Smacallan	    if(pEnt->active) {
399a6b33934Smacallan		ScrnInfoPtr pScrn;
400a6b33934Smacallan
401a6b33934Smacallan		/* Allocate a ScrnInfoRec and claim the slot */
402a6b33934Smacallan		pScrn = xf86AllocateScreen(drv, 0);
403a6b33934Smacallan
404a6b33934Smacallan		/* Fill in what we can of the ScrnInfoRec */
405a6b33934Smacallan		pScrn->driverVersion = VERSION;
406a6b33934Smacallan		pScrn->driverName	 = PNOZZ_DRIVER_NAME;
407a6b33934Smacallan		pScrn->name		 = PNOZZ_NAME;
408a6b33934Smacallan		pScrn->Probe	 	 = PnozzProbe;
409a6b33934Smacallan		pScrn->PreInit	 	 = PnozzPreInit;
410a6b33934Smacallan		pScrn->ScreenInit	 = PnozzScreenInit;
411a6b33934Smacallan  		pScrn->SwitchMode	 = PnozzSwitchMode;
412a6b33934Smacallan  		pScrn->AdjustFrame	 = PnozzAdjustFrame;
413a6b33934Smacallan		pScrn->EnterVT		 = PnozzEnterVT;
414a6b33934Smacallan		pScrn->LeaveVT		 = PnozzLeaveVT;
415a6b33934Smacallan		pScrn->FreeScreen	 = PnozzFreeScreen;
416a6b33934Smacallan		pScrn->ValidMode	 = PnozzValidMode;
417a6b33934Smacallan		xf86AddEntityToScreen(pScrn, pEnt->index);
418a6b33934Smacallan		foundScreen = TRUE;
419a6b33934Smacallan	    }
420a6b33934Smacallan	    xfree(pEnt);
421a6b33934Smacallan    	}
422a6b33934Smacallan    xfree(usedChips);
423a6b33934Smacallan    return foundScreen;
424a6b33934Smacallan}
425a6b33934Smacallan
426a6b33934Smacallan/* Mandatory */
427a6b33934Smacallanstatic Bool
428a6b33934SmacallanPnozzPreInit(ScrnInfoPtr pScrn, int flags)
429a6b33934Smacallan{
430a6b33934Smacallan    PnozzPtr pPnozz;
431a6b33934Smacallan    sbusDevicePtr psdp;
432a6b33934Smacallan    MessageType from;
433a6b33934Smacallan    rgb defaultWeight = {0, 0, 0};
434a6b33934Smacallan    int i;
435a6b33934Smacallan
436a6b33934Smacallan    if (flags & PROBE_DETECT) return FALSE;
437a6b33934Smacallan
438a6b33934Smacallan    /*
439a6b33934Smacallan     * Note: This function is only called once at server startup, and
440a6b33934Smacallan     * not at the start of each server generation.  This means that
441a6b33934Smacallan     * only things that are persistent across server generations can
442a6b33934Smacallan     * be initialised here.  xf86Screens[] is (pScrn is a pointer to one
443a6b33934Smacallan     * of these).  Privates allocated using xf86AllocateScrnInfoPrivateIndex()
444a6b33934Smacallan     * are too, and should be used for data that must persist across
445a6b33934Smacallan     * server generations.
446a6b33934Smacallan     *
447a6b33934Smacallan     * Per-generation data should be allocated with
448a6b33934Smacallan     * AllocateScreenPrivateIndex() from the ScreenInit() function.
449a6b33934Smacallan     */
450a6b33934Smacallan
451a6b33934Smacallan    /* Allocate the PnozzRec driverPrivate */
452a6b33934Smacallan    if (!PnozzGetRec(pScrn)) {
453a6b33934Smacallan	return FALSE;
454a6b33934Smacallan    }
455a6b33934Smacallan    pPnozz = GET_PNOZZ_FROM_SCRN(pScrn);
456a6b33934Smacallan
457a6b33934Smacallan    /* always mismatch on first access */
458a6b33934Smacallan    pPnozz->offset_mask = 0xffffffff;
459a6b33934Smacallan
460a6b33934Smacallan    /* Set pScrn->monitor */
461a6b33934Smacallan    pScrn->monitor = pScrn->confScreen->monitor;
462a6b33934Smacallan
463a6b33934Smacallan    /* This driver doesn't expect more than one entity per screen */
464a6b33934Smacallan    if (pScrn->numEntities > 1)
465a6b33934Smacallan	return FALSE;
466a6b33934Smacallan    /* This is the general case */
467a6b33934Smacallan    for (i = 0; i < pScrn->numEntities; i++) {
468a6b33934Smacallan	EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[i]);
469a6b33934Smacallan
470a6b33934Smacallan	/* PNOZZ is purely SBUS */
471a6b33934Smacallan	if (pEnt->location.type == BUS_SBUS) {
472a6b33934Smacallan	    psdp = xf86GetSbusInfoForEntity(pEnt->index);
473a6b33934Smacallan	    pPnozz->psdp = psdp;
474a6b33934Smacallan	} else
475a6b33934Smacallan	    return FALSE;
476a6b33934Smacallan    }
477a6b33934Smacallan
478a6b33934Smacallan    /*********************
479a6b33934Smacallan    deal with depth
480a6b33934Smacallan    *********************/
481a6b33934Smacallan    if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support32bppFb)) {
482a6b33934Smacallan	return FALSE;
483a6b33934Smacallan    } else {
484a6b33934Smacallan	/* Check that the returned depth is one we support */
485a6b33934Smacallan#ifdef DEBUG
486a6b33934Smacallan	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
487a6b33934Smacallan	    "Depth requested: %d\n", pScrn->depth);
488a6b33934Smacallan#endif
489a6b33934Smacallan	switch (pScrn->depth) {
490a6b33934Smacallan	case 8:
491a6b33934Smacallan	case 16:
492a6b33934Smacallan	case 24:
493a6b33934Smacallan	    /* OK */
494a6b33934Smacallan	    break;
495a6b33934Smacallan	default:
496a6b33934Smacallan	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
497a6b33934Smacallan		       "Given depth (%d) is not supported by this driver\n",
498a6b33934Smacallan		       pScrn->depth);
499a6b33934Smacallan	    return FALSE;
500a6b33934Smacallan	}
501a6b33934Smacallan    }
502a6b33934Smacallan    xf86PrintDepthBpp(pScrn);
503a6b33934Smacallan
504a6b33934Smacallan    /* We use a programmable clock */
505a6b33934Smacallan    pScrn->progClock = TRUE;
506a6b33934Smacallan
507a6b33934Smacallan    /* Set the bits per RGB for 8bpp mode */
508a6b33934Smacallan    if (pScrn->depth == 8)
509a6b33934Smacallan	pScrn->rgbBits = 8;
510a6b33934Smacallan
511a6b33934Smacallan    if (pScrn->depth > 8) {
512a6b33934Smacallan      if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
513a6b33934Smacallan        return FALSE;
514a6b33934Smacallan    }
515a6b33934Smacallan
516a6b33934Smacallan    if (!xf86SetDefaultVisual(pScrn, -1)) {
517a6b33934Smacallan      return FALSE;
518a6b33934Smacallan    } else {
519a6b33934Smacallan      /* We don't currently support DirectColor at > 8bpp */
520a6b33934Smacallan      if (pScrn->depth > 8 && pScrn->defaultVisual != TrueColor) {
521a6b33934Smacallan        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given default visual"
522a6b33934Smacallan		 " (%s) is not supported at depth %d\n",
523a6b33934Smacallan		 xf86GetVisualName(pScrn->defaultVisual), pScrn->depth);
524a6b33934Smacallan        return FALSE;
525a6b33934Smacallan      }
526a6b33934Smacallan    }
527a6b33934Smacallan
528a6b33934Smacallan    /* Collect all of the relevant option flags (fill in pScrn->options) */
529a6b33934Smacallan    xf86CollectOptions(pScrn, NULL);
530a6b33934Smacallan
531a6b33934Smacallan    /* Process the options */
532a6b33934Smacallan    if (!(pPnozz->Options = xalloc(sizeof(PnozzOptions))))
533a6b33934Smacallan	return FALSE;
534a6b33934Smacallan
535a6b33934Smacallan    memcpy(pPnozz->Options, PnozzOptions, sizeof(PnozzOptions));
536a6b33934Smacallan    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pPnozz->Options);
537a6b33934Smacallan
538a6b33934Smacallan    /*
539a6b33934Smacallan     * The new cmap code requires this to be initialised.
540a6b33934Smacallan     */
541a6b33934Smacallan
542a6b33934Smacallan    {
543a6b33934Smacallan	Gamma zeros = {0.0, 0.0, 0.0};
544a6b33934Smacallan
545a6b33934Smacallan	if (!xf86SetGamma(pScrn, zeros)) {
546a6b33934Smacallan	    return FALSE;
547a6b33934Smacallan	}
548a6b33934Smacallan    }
549a6b33934Smacallan
550a6b33934Smacallan    /* Set the bits per RGB for 8bpp mode */
551a6b33934Smacallan    from = X_DEFAULT;
552a6b33934Smacallan
553a6b33934Smacallan    /* determine whether we use hardware or software cursor */
554a6b33934Smacallan    pPnozz->HWCursor = TRUE;
555a6b33934Smacallan    if (xf86GetOptValBool(pPnozz->Options, OPTION_HW_CURSOR, &pPnozz->HWCursor))
556a6b33934Smacallan	from = X_CONFIG;
557a6b33934Smacallan    if (xf86ReturnOptValBool(pPnozz->Options, OPTION_SW_CURSOR, FALSE)) {
558a6b33934Smacallan	from = X_CONFIG;
559a6b33934Smacallan	pPnozz->HWCursor = FALSE;
560a6b33934Smacallan    }
561a6b33934Smacallan
562a6b33934Smacallan    xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
563a6b33934Smacallan		pPnozz->HWCursor ? "HW" : "SW");
564a6b33934Smacallan
565a6b33934Smacallan    if (xf86ReturnOptValBool(pPnozz->Options, OPTION_NOACCEL, FALSE)) {
566a6b33934Smacallan	pPnozz->NoAccel = TRUE;
567a6b33934Smacallan	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n");
568a6b33934Smacallan    }
569a6b33934Smacallan
570a6b33934Smacallan    if (xf86LoadSubModule(pScrn, "fb") == NULL) {
571a6b33934Smacallan	PnozzFreeRec(pScrn);
572a6b33934Smacallan	return FALSE;
573a6b33934Smacallan    }
574a6b33934Smacallan
575a6b33934Smacallan    if (xf86LoadSubModule(pScrn, "ramdac") == NULL) {
576a6b33934Smacallan	PnozzFreeRec(pScrn);
577a6b33934Smacallan	return FALSE;
578a6b33934Smacallan    }
579a6b33934Smacallan    xf86LoaderReqSymLists(ramdacSymbols, NULL);
580a6b33934Smacallan
581a6b33934Smacallan    if (xf86LoadSubModule(pScrn, "xaa") == NULL) {
582a6b33934Smacallan	PnozzFreeRec(pScrn);
583a6b33934Smacallan	return FALSE;
584a6b33934Smacallan    }
585a6b33934Smacallan    xf86LoaderReqSymLists(xaaSymbols, NULL);
586a6b33934Smacallan
587a6b33934Smacallan    /*********************
588a6b33934Smacallan    set up clock and mode stuff
589a6b33934Smacallan    *********************/
590a6b33934Smacallan
591a6b33934Smacallan    pScrn->progClock = TRUE;
592a6b33934Smacallan
593a6b33934Smacallan    if(pScrn->display->virtualX || pScrn->display->virtualY) {
594a6b33934Smacallan	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
595a6b33934Smacallan		   "Pnozz does not support a virtual desktop\n");
596a6b33934Smacallan	pScrn->display->virtualX = 0;
597a6b33934Smacallan	pScrn->display->virtualY = 0;
598a6b33934Smacallan    }
599a6b33934Smacallan
600a6b33934Smacallan    xf86SbusUseBuiltinMode(pScrn, pPnozz->psdp);
601a6b33934Smacallan    pScrn->currentMode = pScrn->modes;
602a6b33934Smacallan    pScrn->displayWidth = pScrn->virtualX;
603a6b33934Smacallan
604a6b33934Smacallan    /* Set display resolution */
605a6b33934Smacallan    xf86SetDpi(pScrn, 0, 0);
606a6b33934Smacallan
607a6b33934Smacallan    return TRUE;
608a6b33934Smacallan}
609a6b33934Smacallan
610a6b33934Smacallan/* Mandatory */
611a6b33934Smacallan
612a6b33934Smacallan/* This gets called at the start of each server generation */
613a6b33934Smacallan
614a6b33934Smacallanstatic Bool
615a6b33934SmacallanPnozzScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
616a6b33934Smacallan{
617a6b33934Smacallan    ScrnInfoPtr pScrn;
618a6b33934Smacallan    PnozzPtr pPnozz;
619a6b33934Smacallan    VisualPtr visual;
620a6b33934Smacallan    int ret,len=0,i;
621a6b33934Smacallan    unsigned int *regs, pctl, pfb, *fb;
622a6b33934Smacallan
623a6b33934Smacallan    /*
624a6b33934Smacallan     * First get the ScrnInfoRec
625a6b33934Smacallan     */
626a6b33934Smacallan    pScrn = xf86Screens[pScreen->myNum];
627a6b33934Smacallan
628a6b33934Smacallan    pPnozz = GET_PNOZZ_FROM_SCRN(pScrn);
629a6b33934Smacallan
630a6b33934Smacallan    /*
631a6b33934Smacallan     * XXX
632a6b33934Smacallan     * figure out how much video RAM we really have - 2MB is just by far the
633a6b33934Smacallan     * most common size
634a6b33934Smacallan     */
635a6b33934Smacallan    pPnozz->fb =
636a6b33934Smacallan	xf86MapSbusMem (pPnozz->psdp, 0, 0x200000);	/* map 2MB */
637a6b33934Smacallan    fb=(unsigned int *)pPnozz->fb;
638a6b33934Smacallan
639a6b33934Smacallan    pPnozz->fbc =
640a6b33934Smacallan	xf86MapSbusMem (pPnozz->psdp, 0x200000,0x8000);	/* map registers */
641a6b33934Smacallan
642a6b33934Smacallan    if (! pPnozz->fbc)
643a6b33934Smacallan	return FALSE;
644a6b33934Smacallan
645a6b33934Smacallan    /*
646a6b33934Smacallan     * The next step is to setup the screen's visuals, and initialise the
647a6b33934Smacallan     * framebuffer code.  In cases where the framebuffer's default
648a6b33934Smacallan     * choices for things like visual layouts and bits per RGB are OK,
649a6b33934Smacallan     * this may be as simple as calling the framebuffer's ScreenInit()
650a6b33934Smacallan     * function.  If not, the visuals will need to be setup before calling
651a6b33934Smacallan     * a fb ScreenInit() function and fixed up after.
652a6b33934Smacallan     */
653a6b33934Smacallan
654a6b33934Smacallan    /*
655a6b33934Smacallan     * Reset visual list.
656a6b33934Smacallan     */
657a6b33934Smacallan    miClearVisualTypes();
658a6b33934Smacallan
659a6b33934Smacallan#ifdef DEBUG
660a6b33934Smacallan    xf86Msg(X_ERROR, "depth: %d, bpp: %d\n", pScrn->depth, pScrn->bitsPerPixel);
661a6b33934Smacallan#endif
662a6b33934Smacallan    switch (pScrn->bitsPerPixel) {
663a6b33934Smacallan    	case 8:
664a6b33934Smacallan	    pPnozz->depthshift = 0;
665a6b33934Smacallan	    break;
666a6b33934Smacallan    	case 16:
667a6b33934Smacallan	    pPnozz->depthshift = 1;
668a6b33934Smacallan	    break;
669a6b33934Smacallan    	case 32:
670a6b33934Smacallan	    pPnozz->depthshift = 2;
671a6b33934Smacallan	    break;
672a6b33934Smacallan	default:
673a6b33934Smacallan	    return FALSE;
674a6b33934Smacallan    }
675a6b33934Smacallan    pPnozz->width = pScrn->virtualX;
676a6b33934Smacallan    pPnozz->height = pScrn->virtualY;
677a6b33934Smacallan    pPnozz->scanlinesize = pScrn->virtualX << pPnozz->depthshift;
678a6b33934Smacallan
679a6b33934Smacallan    PnozzSave(pPnozz);
680a6b33934Smacallan
681a6b33934Smacallan    /*
682a6b33934Smacallan     * ok, let's switch to whatever depth That Guy Out There wants.
683a6b33934Smacallan     * We won't switch video mode, only colour depth -
684a6b33934Smacallan     */
685a6b33934Smacallan    if(!PnozzSetDepth(pPnozz, pScrn->bitsPerPixel))
686a6b33934Smacallan    	return FALSE;
687a6b33934Smacallan
688a6b33934Smacallan    /* Setup the visuals we support. */
689a6b33934Smacallan
690a6b33934Smacallan    if (!miSetVisualTypes(pScrn->depth, miGetDefaultVisualMask(pScrn->depth),
691a6b33934Smacallan			  pScrn->rgbBits, pScrn->defaultVisual))
692a6b33934Smacallan	return FALSE;
693a6b33934Smacallan
694a6b33934Smacallan    miSetPixmapDepths();
695a6b33934Smacallan
696a6b33934Smacallan    /*
697a6b33934Smacallan     * Call the framebuffer layer's ScreenInit function, and fill in other
698a6b33934Smacallan     * pScreen fields.
699a6b33934Smacallan     */
700a6b33934Smacallan#if DEBUG
701a6b33934Smacallan    xf86Msg(X_ERROR, "sls: %d\n", pPnozz->scanlinesize);
702a6b33934Smacallan#endif
703a6b33934Smacallan    ret = fbScreenInit(pScreen, pPnozz->fb, pScrn->virtualX,
704a6b33934Smacallan		       pScrn->virtualY, pScrn->xDpi, pScrn->yDpi,
705a6b33934Smacallan		       pScrn->displayWidth, pScrn->bitsPerPixel);
706a6b33934Smacallan
707a6b33934Smacallan    /* should be set by PnozzSetDepth() */
708a6b33934Smacallan    pPnozz->maxheight = (0x200000 / pPnozz->scanlinesize) & 0xffff;
709a6b33934Smacallan#if DEBUG
710a6b33934Smacallan    xf86Msg(X_ERROR, "max scanlines: %d\n", pPnozz->maxheight);
711a6b33934Smacallan#endif
712a6b33934Smacallan    if (!ret)
713a6b33934Smacallan	return FALSE;
714a6b33934Smacallan
715a6b33934Smacallan    if (pScrn->bitsPerPixel > 8) {
716a6b33934Smacallan      visual = pScreen->visuals + pScreen->numVisuals;
717a6b33934Smacallan      while (--visual >= pScreen->visuals) {
718a6b33934Smacallan        if ((visual->class | DynamicClass) == DirectColor) {
719a6b33934Smacallan	  visual->offsetRed = pScrn->offset.red;
720a6b33934Smacallan	  visual->offsetGreen = pScrn->offset.green;
721a6b33934Smacallan	  visual->offsetBlue = pScrn->offset.blue;
722a6b33934Smacallan	  visual->redMask = pScrn->mask.red;
723a6b33934Smacallan	  visual->greenMask = pScrn->mask.green;
724a6b33934Smacallan	  visual->blueMask = pScrn->mask.blue;
725a6b33934Smacallan        }
726a6b33934Smacallan      }
727a6b33934Smacallan    }
728a6b33934Smacallan
729a6b33934Smacallan    fbPictureInit(pScreen, 0, 0);
730a6b33934Smacallan
731a6b33934Smacallan    miInitializeBackingStore(pScreen);
732a6b33934Smacallan    xf86SetBackingStore(pScreen);
733a6b33934Smacallan    xf86SetSilkenMouse(pScreen);
734a6b33934Smacallan    xf86SetBlackWhitePixels(pScreen);
735a6b33934Smacallan
736a6b33934Smacallan    if (!pPnozz->NoAccel) {
737a6b33934Smacallan    	BoxRec bx;
738a6b33934Smacallan	pPnozz->pXAA = XAACreateInfoRec();
739a6b33934Smacallan	PnozzAccelInit(pScrn);
740a6b33934Smacallan	bx.x1 = bx.y1 = 0;
741a6b33934Smacallan	bx.x2 = pPnozz->width;
742a6b33934Smacallan	bx.y2 = pPnozz->maxheight;
743a6b33934Smacallan	xf86InitFBManager(pScreen, &bx);
744a6b33934Smacallan	if(!XAAInit(pScreen, pPnozz->pXAA))
745a6b33934Smacallan	    return FALSE;
746a6b33934Smacallan	xf86Msg(X_INFO, "%s: Using acceleration\n", pPnozz->psdp->device);
747a6b33934Smacallan    }
748a6b33934Smacallan
749a6b33934Smacallan    /* Initialise cursor functions */
750a6b33934Smacallan    miDCInitialize (pScreen, xf86GetPointerScreenFuncs());
751a6b33934Smacallan
752a6b33934Smacallan    /*
753a6b33934Smacallan     * Initialize HW cursor layer.
754a6b33934Smacallan     * Must follow software cursor initialization
755a6b33934Smacallan     */
756a6b33934Smacallan    xf86SbusHideOsHwCursor(pPnozz->psdp);
757a6b33934Smacallan    if (pPnozz->HWCursor) {
758a6b33934Smacallan	extern Bool PnozzHWCursorInit(ScreenPtr pScreen);
759a6b33934Smacallan
760a6b33934Smacallan	if(!PnozzHWCursorInit(pScreen)) {
761a6b33934Smacallan	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
762a6b33934Smacallan		       "Hardware cursor initialization failed\n");
763a6b33934Smacallan	    return(FALSE);
764a6b33934Smacallan	}
765a6b33934Smacallan    }
766a6b33934Smacallan
767a6b33934Smacallan    /* Initialise default colourmap */
768a6b33934Smacallan    if (!miCreateDefColormap(pScreen))
769a6b33934Smacallan	return FALSE;
770a6b33934Smacallan#if 1
771a6b33934Smacallan    if(!xf86SbusHandleColormaps(pScreen, pPnozz->psdp))
772a6b33934Smacallan#else
773a6b33934Smacallan    if(!xf86HandleColormaps(pScreen, 256, pScrn->rgbBits, PnozzLoadPalette, NULL,
774a6b33934Smacallan        /*CMAP_PALETTED_TRUECOLOR|*/CMAP_RELOAD_ON_MODE_SWITCH))
775a6b33934Smacallan#endif
776a6b33934Smacallan	return FALSE;
777a6b33934Smacallan    pPnozz->CloseScreen = pScreen->CloseScreen;
778a6b33934Smacallan    pScreen->CloseScreen = PnozzCloseScreen;
779a6b33934Smacallan    pScreen->SaveScreen = PnozzSaveScreen;
780a6b33934Smacallan
781a6b33934Smacallan    /* Report any unused options (only for the first generation) */
782a6b33934Smacallan    if (serverGeneration == 1) {
783a6b33934Smacallan	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
784a6b33934Smacallan    }
785a6b33934Smacallan
786a6b33934Smacallan    /* unblank the screen */
787a6b33934Smacallan    PnozzSaveScreen(pScreen, SCREEN_SAVER_OFF);
788a6b33934Smacallan
789a6b33934Smacallan    /* Done */
790a6b33934Smacallan    return TRUE;
791a6b33934Smacallan}
792a6b33934Smacallan
793a6b33934Smacallan
794a6b33934Smacallan/* Usually mandatory */
795a6b33934Smacallanstatic Bool
796a6b33934SmacallanPnozzSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
797a6b33934Smacallan{
798a6b33934Smacallan    xf86Msg(X_ERROR, "SwitchMode: %d %d %d %d\n", mode->CrtcHTotal,
799a6b33934Smacallan        mode->CrtcHSyncStart, mode->CrtcHSyncEnd, mode->CrtcHDisplay);
800a6b33934Smacallan    return TRUE;
801a6b33934Smacallan}
802a6b33934Smacallan
803a6b33934Smacallan
804a6b33934Smacallan/*
805a6b33934Smacallan * This function is used to initialize the Start Address - the first
806a6b33934Smacallan * displayed location in the video memory.
807a6b33934Smacallan */
808a6b33934Smacallan/* Usually mandatory */
809a6b33934Smacallanstatic void
810a6b33934SmacallanPnozzAdjustFrame(int scrnIndex, int x, int y, int flags)
811a6b33934Smacallan{
812a6b33934Smacallan    /* we don't support virtual desktops for now */
813a6b33934Smacallan    return;
814a6b33934Smacallan}
815a6b33934Smacallan
816a6b33934Smacallan/*
817a6b33934Smacallan * This is called when VT switching back to the X server.  Its job is
818a6b33934Smacallan * to reinitialise the video mode.
819a6b33934Smacallan */
820a6b33934Smacallan
821a6b33934Smacallan/* Mandatory */
822a6b33934Smacallanstatic Bool
823a6b33934SmacallanPnozzEnterVT(int scrnIndex, int flags)
824a6b33934Smacallan{
825a6b33934Smacallan    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
826a6b33934Smacallan    PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn);
827a6b33934Smacallan
828a6b33934Smacallan    xf86SbusHideOsHwCursor (pPnozz->psdp);
829a6b33934Smacallan    return TRUE;
830a6b33934Smacallan}
831a6b33934Smacallan
832a6b33934Smacallan
833a6b33934Smacallan/*
834a6b33934Smacallan * This is called when VT switching away from the X server.
835a6b33934Smacallan */
836a6b33934Smacallan
837a6b33934Smacallan/* Mandatory */
838a6b33934Smacallanstatic void
839a6b33934SmacallanPnozzLeaveVT(int scrnIndex, int flags)
840a6b33934Smacallan{
841a6b33934Smacallan    return;
842a6b33934Smacallan}
843a6b33934Smacallan
844a6b33934Smacallan
845a6b33934Smacallan/*
846a6b33934Smacallan * This is called at the end of each server generation.  It restores the
847a6b33934Smacallan * original (text) mode.  It should really also unmap the video memory too.
848a6b33934Smacallan */
849a6b33934Smacallan
850a6b33934Smacallan/* Mandatory */
851a6b33934Smacallanstatic Bool
852a6b33934SmacallanPnozzCloseScreen(int scrnIndex, ScreenPtr pScreen)
853a6b33934Smacallan{
854a6b33934Smacallan    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
855a6b33934Smacallan    PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn);
856a6b33934Smacallan    int state = 1;
857a6b33934Smacallan
858a6b33934Smacallan    pScrn->vtSema = FALSE;
859a6b33934Smacallan
860a6b33934Smacallan    if (pPnozz->HWCursor)
861a6b33934Smacallan    	PnozzHideCursor(pScrn);
862a6b33934Smacallan
863a6b33934Smacallan    PnozzRestore(pPnozz);	/* restore colour depth */
864a6b33934Smacallan
865a6b33934Smacallan    xf86UnmapSbusMem(pPnozz->psdp, pPnozz->fb,0x200000);
866a6b33934Smacallan    xf86UnmapSbusMem(pPnozz->psdp, pPnozz->fbc,0x8000);
867a6b33934Smacallan
868a6b33934Smacallan    /* make sure video is turned on */
869a6b33934Smacallan    ioctl(pPnozz->psdp->fd, FBIOSVIDEO, &state);
870a6b33934Smacallan
871a6b33934Smacallan    pScreen->CloseScreen = pPnozz->CloseScreen;
872a6b33934Smacallan    return (*pScreen->CloseScreen)(scrnIndex, pScreen);
873a6b33934Smacallan    return FALSE;
874a6b33934Smacallan}
875a6b33934Smacallan
876a6b33934Smacallan
877a6b33934Smacallan/* Free up any per-generation data structures */
878a6b33934Smacallan
879a6b33934Smacallan/* Optional */
880a6b33934Smacallanstatic void
881a6b33934SmacallanPnozzFreeScreen(int scrnIndex, int flags)
882a6b33934Smacallan{
883a6b33934Smacallan    PnozzFreeRec(xf86Screens[scrnIndex]);
884a6b33934Smacallan}
885a6b33934Smacallan
886a6b33934Smacallan
887a6b33934Smacallan/* Checks if a mode is suitable for the selected chipset. */
888a6b33934Smacallan
889a6b33934Smacallan/* Optional */
890a6b33934Smacallanstatic ModeStatus
891a6b33934SmacallanPnozzValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
892a6b33934Smacallan{
893a6b33934Smacallan    if (mode->Flags & V_INTERLACE)
894a6b33934Smacallan	return(MODE_BAD);
895a6b33934Smacallan
896a6b33934Smacallan    return(MODE_OK);
897a6b33934Smacallan}
898a6b33934Smacallan
899a6b33934Smacallan/* Do screen blanking */
900a6b33934Smacallan
901a6b33934Smacallan/* Mandatory */
902a6b33934Smacallanstatic Bool
903a6b33934SmacallanPnozzSaveScreen(ScreenPtr pScreen, int mode)
904a6b33934Smacallan{
905a6b33934Smacallan    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
906a6b33934Smacallan    PnozzPtr pPnozz = GET_PNOZZ_FROM_SCRN(pScrn);
907a6b33934Smacallan    int fd = pPnozz->psdp->fd, state;
908a6b33934Smacallan
909a6b33934Smacallan    /*
910a6b33934Smacallan     * we're using ioctl() instead of just whacking the DAC because the
911a6b33934Smacallan     * underlying driver will also turn off the backlight which we couldn't do
912a6b33934Smacallan     * from here without adding lots more hardware dependencies
913a6b33934Smacallan     */
914a6b33934Smacallan    switch(mode)
915a6b33934Smacallan    {
916a6b33934Smacallan	case SCREEN_SAVER_ON:
917a6b33934Smacallan	case SCREEN_SAVER_CYCLE:
918a6b33934Smacallan    		state = 0;
919a6b33934Smacallan		if(ioctl(fd, FBIOSVIDEO, &state) == -1)
920a6b33934Smacallan		{
921a6b33934Smacallan			/* complain */
922a6b33934Smacallan		}
923a6b33934Smacallan		break;
924a6b33934Smacallan	case SCREEN_SAVER_OFF:
925a6b33934Smacallan	case SCREEN_SAVER_FORCER:
926a6b33934Smacallan    		state = 1;
927a6b33934Smacallan		if(ioctl(fd, FBIOSVIDEO, &state) == -1)
928a6b33934Smacallan		{
929a6b33934Smacallan			/* complain */
930a6b33934Smacallan		}
931a6b33934Smacallan		break;
932a6b33934Smacallan	default:
933a6b33934Smacallan		return FALSE;
934a6b33934Smacallan    }
935a6b33934Smacallan    return TRUE;
936a6b33934Smacallan}
937a6b33934Smacallan
938a6b33934Smacallanint shift_1(int b)
939a6b33934Smacallan{
940a6b33934Smacallan    if (b > 0)
941a6b33934Smacallan	return (16 << b);
942a6b33934Smacallan    return 0;
943a6b33934Smacallan}
944a6b33934Smacallan
945a6b33934Smacallanint shift_2(int b)
946a6b33934Smacallan{
947a6b33934Smacallan    if (b > 0)
948a6b33934Smacallan	return (512 << b);
949a6b33934Smacallan    return 0;
950a6b33934Smacallan}
951a6b33934Smacallan
952a6b33934Smacallanvoid
953a6b33934SmacallanPnozzSave(PnozzPtr pPnozz)
954a6b33934Smacallan{
955a6b33934Smacallan	int i;
956a6b33934Smacallan	pPnozz->SvSysConf = pnozz_read_4(pPnozz, SYS_CONF);
957a6b33934Smacallan	pPnozz->SvDAC_MC3 = pnozz_read_dac_ctl_reg(pPnozz, DAC_MISC_3);
958a6b33934Smacallan	pPnozz->SvDAC_MCCR = pnozz_read_dac_ctl_reg(pPnozz, DAC_MISC_CLK);
959a6b33934Smacallan	pPnozz->SvDAC_PF = pnozz_read_dac_ctl_reg(pPnozz, DAC_PIXEL_FMT);
960a6b33934Smacallan	pPnozz->SvPLL = pnozz_read_dac_ctl_reg(pPnozz, DAC_PLL0);
961a6b33934Smacallan	pPnozz->SvVCO = pnozz_read_dac_ctl_reg(pPnozz, DAC_VCO_DIV);
962a6b33934Smacallan	pPnozz->SvMemCtl = pnozz_read_4(pPnozz, VID_MEM_CONFIG);
963a6b33934Smacallan	for (i = 0; i < 4; i++)
964a6b33934Smacallan		pPnozz->CRTC[i] = pnozz_read_4(pPnozz, VID_HTOTAL + (i << 2));
965a6b33934Smacallan	pPnozz->DidSave = 1;
966a6b33934Smacallan#if DEBUG
967a6b33934Smacallan	xf86Msg(X_ERROR, "Saved: %x %x %x %x\n", pPnozz->SvSysConf,
968a6b33934Smacallan	    pPnozz->SvDAC_MCCR, pPnozz->SvDAC_PF, pPnozz->SvDAC_MC3);
969a6b33934Smacallan	DumpSCR(pPnozz->SvSysConf);
970a6b33934Smacallan#endif
971a6b33934Smacallan}
972a6b33934Smacallan
973a6b33934Smacallanvoid DumpSCR(unsigned int scr)
974a6b33934Smacallan{
975a6b33934Smacallan#if DEBUG
976a6b33934Smacallan	int s0, s1, s2, s3, ps;
977a6b33934Smacallan	int width;
978a6b33934Smacallan	ps = (scr >> PIXEL_SHIFT) & 7;
979a6b33934Smacallan	s0 = (scr >> SHIFT_0) & 7;
980a6b33934Smacallan	s1 = (scr >> SHIFT_1) & 7;
981a6b33934Smacallan	s2 = (scr >> SHIFT_2) & 7;
982a6b33934Smacallan	s3 = (scr >> SHIFT_3) & 3;
983a6b33934Smacallan	width = shift_1(s0) + shift_1(s1) + shift_1(s2) + shift_2(s3);
984a6b33934Smacallan	xf86Msg(X_ERROR, "ps: %d wi: %d\n", ps, width);
985a6b33934Smacallan#endif
986a6b33934Smacallan}
987a6b33934Smacallan
988a6b33934Smacallanvoid DumpDAC(PnozzPtr pPnozz)
989a6b33934Smacallan{
990a6b33934Smacallan#if DEBUG
991a6b33934Smacallan    int addr, i, val;
992a6b33934Smacallan    char line[256], buffer[16];
993a6b33934Smacallan    pnozz_write_dac(pPnozz, DAC_INDX_LO, 0);
994a6b33934Smacallan    pnozz_write_dac(pPnozz, DAC_INDX_HI, 0);
995a6b33934Smacallan    for (addr = 0; addr < 0x100; addr += 16) {
996a6b33934Smacallan    	snprintf(line, 16, "%02x:", addr);
997a6b33934Smacallan	for (i=0;i<16;i++) {
998a6b33934Smacallan	    val = pnozz_read_dac(pPnozz, DAC_INDX_DATA);
999a6b33934Smacallan	    snprintf(buffer, 16, " %02x", val);
1000a6b33934Smacallan	    strcat(line, buffer);
1001a6b33934Smacallan	}
1002a6b33934Smacallan	xf86Msg(X_ERROR, "%s\n", line);
1003a6b33934Smacallan    }
1004a6b33934Smacallan#endif
1005a6b33934Smacallan}
1006a6b33934Smacallan
1007a6b33934Smacallanvoid DumpCRTC(PnozzPtr pPnozz)
1008a6b33934Smacallan{
1009a6b33934Smacallan#if DEBUG
1010a6b33934Smacallan    int i;
1011a6b33934Smacallan    unsigned int reg;
1012a6b33934Smacallan    for (i = 0x108; i<0x140; i += 4) {
1013a6b33934Smacallan        reg = pnozz_read_4(pPnozz, i);
1014a6b33934Smacallan	xf86Msg(X_ERROR, "%x / %d ", reg, reg);
1015a6b33934Smacallan    }
1016a6b33934Smacallan    reg = pnozz_read_4(pPnozz, VID_MEM_CONFIG);
1017a6b33934Smacallan    xf86Msg(X_ERROR, "memcfg: %08x\n", reg);
1018a6b33934Smacallan    xf86Msg(X_ERROR, "shiftclk:  %x\n", (reg >> 10) & 7);
1019a6b33934Smacallan    xf86Msg(X_ERROR, "shiftmode: %x\n", (reg >> 22) & 3);
1020a6b33934Smacallan    xf86Msg(X_ERROR, "crtc_clk:  %x\n", (reg >> 13) & 7);
1021a6b33934Smacallan#endif
1022a6b33934Smacallan}
1023a6b33934Smacallan
1024a6b33934Smacallanvoid
1025a6b33934SmacallanPnozzRestore(PnozzPtr pPnozz)
1026a6b33934Smacallan{
1027a6b33934Smacallan    int i;
1028a6b33934Smacallan    if(pPnozz->DidSave == 1) {
1029a6b33934Smacallan	pnozz_write_4(pPnozz, SYS_CONF, pPnozz->SvSysConf);
1030a6b33934Smacallan	pnozz_write_4(pPnozz, VID_MEM_CONFIG, pPnozz->SvMemCtl);
1031a6b33934Smacallan	for (i = 0; i < 4; i++)
1032a6b33934Smacallan	    pnozz_write_4(pPnozz, VID_HTOTAL + (i << 2), pPnozz->CRTC[i]);
1033a6b33934Smacallan
1034a6b33934Smacallan        pnozz_write_dac_ctl_reg(pPnozz, DAC_PLL0, pPnozz->SvPLL);
1035a6b33934Smacallan        pnozz_write_dac_ctl_reg(pPnozz, DAC_MISC_3, pPnozz->SvDAC_MC3);
1036a6b33934Smacallan        pnozz_write_dac_ctl_reg(pPnozz, DAC_MISC_CLK, pPnozz->SvDAC_MCCR);
1037a6b33934Smacallan	pnozz_write_dac_ctl_reg(pPnozz, DAC_PIXEL_FMT, pPnozz->SvDAC_PF);
1038a6b33934Smacallan	pnozz_write_dac_ctl_reg(pPnozz, DAC_VCO_DIV, pPnozz->SvVCO);
1039a6b33934Smacallan    }
1040a6b33934Smacallan}
1041a6b33934Smacallan
1042a6b33934Smacallanunsigned int upper_bit(unsigned int b)
1043a6b33934Smacallan{
1044a6b33934Smacallan	unsigned int mask=0x80000000;
1045a6b33934Smacallan	int cnt = 31;
1046a6b33934Smacallan	if (b == 0)
1047a6b33934Smacallan		return -1;
1048a6b33934Smacallan	while ((mask != 0) && ((b & mask) == 0)) {
1049a6b33934Smacallan		mask = mask >> 1;
1050a6b33934Smacallan		cnt--;
1051a6b33934Smacallan	}
1052a6b33934Smacallan	return cnt;
1053a6b33934Smacallan}
1054a6b33934Smacallan
1055a6b33934Smacallan/*
1056a6b33934Smacallan * To switch colour depth we need to:
1057a6b33934Smacallan * - double or quadruple both crtc and shift clock ( for 16 or 32 bit )
1058a6b33934Smacallan * - double or quadruple scanline length
1059a6b33934Smacallan * - switch the DAC to the appropriate pixel format
1060a6b33934Smacallan * - tell the drawing engine about new line length / pixel size
1061a6b33934Smacallan */
1062a6b33934Smacallan
1063a6b33934Smacallanint
1064a6b33934SmacallanPnozzSetDepth(PnozzPtr pPnozz, int depth)
1065a6b33934Smacallan{
1066a6b33934Smacallan    int new_sls;
1067a6b33934Smacallan    unsigned int bits, scr, sscr, memctl, mem;
1068a6b33934Smacallan    int s0, s1, s2, s3, ps, crtcline;
1069a6b33934Smacallan    unsigned char pf, mc3, es;
1070a6b33934Smacallan
1071a6b33934Smacallan#if DEBUG
1072a6b33934Smacallan    DumpDAC(pPnozz);
1073a6b33934Smacallan    DumpCRTC(pPnozz);
1074a6b33934Smacallan#endif
1075a6b33934Smacallan
1076a6b33934Smacallan    switch (depth) {
1077a6b33934Smacallan	case 8:
1078a6b33934Smacallan	    pPnozz->depthshift = 0;
1079a6b33934Smacallan	    ps = 2;
1080a6b33934Smacallan	    pf = 3;
1081a6b33934Smacallan	    mc3 = 0;
1082a6b33934Smacallan	    es = 0;	/* no swapping */
1083a6b33934Smacallan	    memctl = 3;
1084a6b33934Smacallan	    break;
1085a6b33934Smacallan	case 16:
1086a6b33934Smacallan	    pPnozz->depthshift = 1;
1087a6b33934Smacallan	    ps = 3;
1088a6b33934Smacallan	    pf = 4;
1089a6b33934Smacallan	    mc3 = 0;
1090a6b33934Smacallan	    es = 2;	/* swap bytes in 16bit words */
1091a6b33934Smacallan	    memctl = 2;
1092a6b33934Smacallan	    break;
1093a6b33934Smacallan	case 24:
1094a6b33934Smacallan	    /* boo */
1095a6b33934Smacallan	    xf86Msg(X_ERROR, "We don't DO 24bit pixels dammit!\n");
1096a6b33934Smacallan	    return 0;
1097a6b33934Smacallan	case 32:
1098a6b33934Smacallan	    pPnozz->depthshift = 2;
1099a6b33934Smacallan	    ps = 5;
1100a6b33934Smacallan	    pf = 6;
1101a6b33934Smacallan	    mc3 = 0;
1102a6b33934Smacallan	    es = 6;	/* swap both half-words and bytes */
1103a6b33934Smacallan	    memctl = 1;	/* 0 */
1104a6b33934Smacallan	    break;
1105a6b33934Smacallan    }
1106a6b33934Smacallan    /*
1107a6b33934Smacallan     * this could be done a lot shorter and faster but then nobody would
1108a6b33934Smacallan     * understand what the hell we're doing here without getting a major
1109a6b33934Smacallan     * headache. Scanline size is encoded as 4 shift values, 3 of them 3 bits
1110a6b33934Smacallan     * wide, 16 << n for n>0, one 2 bits, 512 << n for n>0. n==0 means 0
1111a6b33934Smacallan     */
1112a6b33934Smacallan    new_sls = pPnozz->width << pPnozz->depthshift;
1113a6b33934Smacallan    pPnozz->scanlinesize = new_sls;
1114a6b33934Smacallan    bits = new_sls;
1115a6b33934Smacallan    s3 = upper_bit(bits);
1116a6b33934Smacallan    if (s3 > 9) {
1117a6b33934Smacallan	bits &= ~(1 << s3);
1118a6b33934Smacallan	s3 -= 9;
1119a6b33934Smacallan    } else s3 = 0;
1120a6b33934Smacallan    s2 = upper_bit(bits);
1121a6b33934Smacallan    if (s2 > 0) {
1122a6b33934Smacallan	bits &= ~(1 << s2);
1123a6b33934Smacallan	s2 -= 4;
1124a6b33934Smacallan    } else s2 = 0;
1125a6b33934Smacallan    s1 = upper_bit(bits);
1126a6b33934Smacallan    if (s1 > 0) {
1127a6b33934Smacallan        bits &= ~(1 << s1);
1128a6b33934Smacallan        s1 -= 4;
1129a6b33934Smacallan    } else s1 = 0;
1130a6b33934Smacallan    s0 = upper_bit(bits);
1131a6b33934Smacallan    if (s0 > 0) {
1132a6b33934Smacallan        bits &= ~(1 << s0);
1133a6b33934Smacallan        s0 -= 4;
1134a6b33934Smacallan    } else s0 = 0;
1135a6b33934Smacallan
1136a6b33934Smacallan#if DEBUG
1137a6b33934Smacallan    xf86Msg(X_ERROR, "sls: %x sh: %d %d %d %d leftover: %x\n", new_sls, s0, s1,
1138a6b33934Smacallan        s2, s3, bits);
1139a6b33934Smacallan#endif
1140a6b33934Smacallan
1141a6b33934Smacallan    /*
1142a6b33934Smacallan     * now let's put these values into the System Config Register. No need to
1143a6b33934Smacallan     * read it here since we (hopefully) just saved the content
1144a6b33934Smacallan     */
1145a6b33934Smacallan    scr = pnozz_read_4(pPnozz, SYS_CONF);
1146a6b33934Smacallan    scr = (s0 << SHIFT_0) | (s1 << SHIFT_1) | (s2 << SHIFT_2) |
1147a6b33934Smacallan        (s3 << SHIFT_3) | (ps << PIXEL_SHIFT) | (es << SWAP_SHIFT);
1148a6b33934Smacallan#if DEBUG
1149a6b33934Smacallan    xf86Msg(X_ERROR, "new scr: %x DAC %x %x\n", scr, pf, mc3);
1150a6b33934Smacallan    DumpSCR(scr);
1151a6b33934Smacallan#endif
1152a6b33934Smacallan
1153a6b33934Smacallan    mem = pnozz_read_4(pPnozz, VID_MEM_CONFIG);
1154a6b33934Smacallan#if DEBUG
1155a6b33934Smacallan    xf86Msg(X_ERROR, "old memctl: %08x\n", mem);
1156a6b33934Smacallan#endif
1157a6b33934Smacallan    /* set shift and crtc clock */
1158a6b33934Smacallan    mem &= ~(0x0000fc00);
1159a6b33934Smacallan    mem |= (memctl << 10) | (memctl << 13);
1160a6b33934Smacallan    pnozz_write_4(pPnozz, VID_MEM_CONFIG, mem);
1161a6b33934Smacallan#if DEBUG
1162a6b33934Smacallan    xf86Msg(X_ERROR, "new memctl: %08x\n", mem);
1163a6b33934Smacallan#endif
1164a6b33934Smacallan    /* whack the engine... */
1165a6b33934Smacallan    pnozz_write_4(pPnozz, SYS_CONF, scr);
1166a6b33934Smacallan
1167a6b33934Smacallan    /* ok, whack the DAC */
1168a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, DAC_MISC_1, 0x11);
1169a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, DAC_MISC_2, 0x45);
1170a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, DAC_MISC_3, mc3);
1171a6b33934Smacallan    /*
1172a6b33934Smacallan     * despite the 3GX manual saying otherwise we don't need to mess with any
1173a6b33934Smacallan     * clock dividers here
1174a6b33934Smacallan     */
1175a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, DAC_MISC_CLK, 1);
1176a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, 3, 0);
1177a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, 4, 0);
1178a6b33934Smacallan
1179a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, DAC_POWER_MGT, 0);
1180a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, DAC_OPERATION, 0);
1181a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, DAC_PALETTE_CTRL, 0);
1182a6b33934Smacallan
1183a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, DAC_PIXEL_FMT, pf);
1184a6b33934Smacallan
1185a6b33934Smacallan    /* TODO: distinguish between 15 and 16 bit */
1186a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, DAC_8BIT_CTRL, 0);
1187a6b33934Smacallan    /* direct colour, linear, 565 */
1188a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, DAC_16BIT_CTRL, 0xc6);
1189a6b33934Smacallan    /* direct colour */
1190a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, DAC_32BIT_CTRL, 3);
1191a6b33934Smacallan
1192a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, 0x10, 2);
1193a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, 0x11, 0);
1194a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, 0x14, 5);
1195a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, 0x08, 1);
1196a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, 0x15, 5);
1197a6b33934Smacallan    pnozz_write_dac_ctl_reg(pPnozz, 0x16, 0x63);
1198a6b33934Smacallan
1199a6b33934Smacallan    /* whack the CRTC */
1200a6b33934Smacallan    /* we always transfer 64bit in one go */
1201a6b33934Smacallan    crtcline = pPnozz->scanlinesize >> 3;
1202a6b33934Smacallan#if DEBUG
1203a6b33934Smacallan    xf86Msg(X_ERROR, "crtcline: %d\n", crtcline);
1204a6b33934Smacallan#endif
1205a6b33934Smacallan    pnozz_write_4(pPnozz, VID_HTOTAL, (24 << pPnozz->depthshift) + crtcline);
1206a6b33934Smacallan    pnozz_write_4(pPnozz, VID_HSRE, 8 << pPnozz->depthshift);
1207a6b33934Smacallan    pnozz_write_4(pPnozz, VID_HBRE, 18 << pPnozz->depthshift);
1208a6b33934Smacallan    pnozz_write_4(pPnozz, VID_HBFE, (18 << pPnozz->depthshift) + crtcline);
1209a6b33934Smacallan
1210a6b33934Smacallan#if DEBUG
1211a6b33934Smacallan    sscr = pnozz_read_4(pPnozz, SYS_CONF);
1212a6b33934Smacallan    xf86Msg(X_ERROR, "scr: %x\n", sscr);
1213a6b33934Smacallan#endif
1214a6b33934Smacallan    return TRUE;
1215a6b33934Smacallan}
1216