/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roland C. Dowdeswell of Ponte, Inc.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
/*
* This function exists solely to provide a means to init
* the RAMDAC without first registering. It is useful for
* initializing the console early on.
*/
/* XXXrcd: bunch of magic of which I have no current clue */
ibm561_regwr(data, IBM561_CONFIG_REG1, 0x2a);
ibm561_regwr(data, IBM561_CONFIG_REG3, 0x41);
ibm561_regwr(data, IBM561_CONFIG_REG4, 0x20);
/* initialize the card a bit */
ibm561_regwr(data, IBM561_SYNC_CNTL, 0x1);
ibm561_regwr(data, IBM561_CONFIG_REG2, 0x19);
/*
* XXX:
* I am leaving these functions returning EINVAL, as they are
* not strictly necessary for the correct functioning of the
* card and in fact are not used on the other TGA variants, except
* they are exported via ioctl(2) to userland, which does not in
* fact use them.
*/
/* XXX see comment above ibm561_cninit() */
if (!data)
data = &saved_console_data;
if (data->changed & CHANGED_WTYPE) {
ibm561_regbegin(data, IBM561_FB_WINTYPE);
for (i=0; i < IBM561_NWTYPES; i++)
ibm561_regcont10bit(data, IBM561_CMD_FB_WAT, data->wtype[i]);
/* XXXrcd: quick hack here for AUX FB table */
ibm561_regbegin(data, IBM561_AUXFB_WINTYPE);
for (i=0; i < IBM561_NWTYPES; i++)
ibm561_regcont(data, IBM561_CMD, 0x04);
/* XXXrcd: quick hack here for OL WAT table */
ibm561_regbegin(data, IBM561_OL_WINTYPE);
for (i=0; i < IBM561_NWTYPES; i++)
ibm561_regcont10bit(data, IBM561_CMD_FB_WAT, 0x0231);
/* XXXrcd: quick hack here for AUX OL WAT table */
ibm561_regbegin(data, IBM561_AUXOL_WINTYPE);
for (i=0; i < IBM561_NWTYPES; i++)
ibm561_regcont(data, IBM561_CMD, 0x0c);
}
if (data->changed & CHANGED_CMAP)
ibm561_load_cmap(data);
/* XXX: I am not sure in what situations it is safe to
* change the dotclock---hope this is good.
*/
if (data->changed & CHANGED_DOTCLOCK)
ibm561_load_dotclock(data);
}
static void
ibm561_load_cmap(struct ibm561data *data)
{
int i;
ibm561_regbegin(data, IBM561_CMAP_TABLE);
for (i=0; i < IBM561_NCMAP_ENTRIES; i++) {
ibm561_regcont(data, IBM561_CMD_CMAP, data->cmap_r[i]);
ibm561_regcont(data, IBM561_CMD_CMAP, data->cmap_g[i]);
ibm561_regcont(data, IBM561_CMD_CMAP, data->cmap_b[i]);
}
ibm561_regbegin(data, IBM561_RED_GAMMA_TABLE);
for (i=0; i < 256; i++)
ibm561_regcont10bit(data, IBM561_CMD_GAMMA, data->gamma_r[i]);
ibm561_regbegin(data, IBM561_GREEN_GAMMA_TABLE);
for (i=1; i < 256; i++)
ibm561_regcont10bit(data, IBM561_CMD_GAMMA, data->gamma_g[i]);
ibm561_regbegin(data, IBM561_BLUE_GAMMA_TABLE);
for (i=1; i < 256; i++)
ibm561_regcont10bit(data, IBM561_CMD_GAMMA, data->gamma_b[i]);
}
static void
ibm561_load_dotclock(struct ibm561data *data)
{
/* XXX
* we should probably be more pro-active here, but it shouldn't
* actually happen...
*/
if (!data->vco_div || !data->pll_ref || ! data->div_dotclock) {
panic("ibm561_load_dotclock: called uninitialized");
}