/*-
* Copyright (c) 2001 TAKEMURA Shin
* All rights reserved.
*
* 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. The name of the author may not 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.
*
*/
struct mq200_crt_param mq200_crt_params[] = {
[MQ200_CRT_640x480_60Hz] =
{ 640, 480, 25175, /* width, height, dot clock */
800, /* HD Total */
525, /* VD Total */
656, 752, /* HS Start, HS End */
490, 492, /* VS Start, VS End */
(MQ200_GC1CRTC_HSYNC_ACTVLOW |
MQ200_GC1CRTC_VSYNC_ACTVLOW |
MQ200_GC1CRTC_BLANK_PEDESTAL_EN),
},
[MQ200_CRT_800x600_60Hz] =
{ 800, 600, 40000, /* width, height, dot clock */
1054, /* HD Total */
628, /* VD Total */
839, 967, /* HS Start, HS End */
601, 605, /* VS Start, VS End */
MQ200_GC1CRTC_BLANK_PEDESTAL_EN,
},
[MQ200_CRT_1024x768_60Hz] =
{ 1024, 768, 65000, /* width, height, dot clock */
1344, /* HD Total */
806, /* VD Total */
1048, 1184, /* HS Start, HS End */
771, 777, /* VS Start, VS End */
(MQ200_GC1CRTC_HSYNC_ACTVLOW |
MQ200_GC1CRTC_VSYNC_ACTVLOW |
MQ200_GC1CRTC_BLANK_PEDESTAL_EN),
},
};
int mq200_crt_nparams = sizeof(mq200_crt_params)/sizeof(*mq200_crt_params);
/*
* get PLL setting register value for given frequency
*/
int
mq200_pllparam(int reqout, u_int32_t *res)
{
int n, m, p, out;
int ref = 12288;
int bn, bm, bp, e;
e = ref;
bn = 0; bp = 0; bm = 0;
for (p = 0; p <= 4; p++) {
for (n = 0; n < (1<<5); n++) {
m = (reqout * ((n + 1) << p)) / ref - 1;
out = ref * (m + 1) / ((n + 1) << p);
if (0xff < m)
break;
if (40 <= m &&
1000 <= ref/(n + 1) &&
170000 <= ref*(m+1)/(n+1) &&
ref*(m+1)/(n+1) <= 340000 &&
ABS(reqout - out) <= e) {
e = ABS(reqout - out);
bn = n;
bm = m;
bp = p;
}
}
}
if (ref <= e)
return (-1);
for (i = 0; i < sizeof(offsets)/sizeof(*offsets); i++) {
if (offsets[i] == 0)
#ifdef MQ200_DEBUG
if (i != MQ200_I_PMC)
panic("%s(%d): register context %d is empty",
__FILE__, __LINE__, i);
#endif
sc->sc_regctxs[i].offset = offsets[i];
}
}