in fbdev/kyro/STG4000OverlayDevice.c [317:600]
int SetOverlayViewPort(volatile STG4000REG __iomem *pSTGReg,
u32 left, u32 top,
u32 right, u32 bottom)
{
OVRL_SRC_DEST srcDest;
u32 ulSrcTop, ulSrcBottom;
u32 ulSrc, ulDest;
u32 ulFxScale, ulFxOffset;
u32 ulHeight, ulWidth;
u32 ulPattern;
u32 ulDecimate, ulDecimated;
u32 ulApplied;
u32 ulDacXScale, ulDacYScale;
u32 ulScale;
u32 ulLeft, ulRight;
u32 ulSrcLeft, ulSrcRight;
u32 ulScaleLeft;
u32 ulhDecim;
u32 ulsVal;
u32 ulVertDecFactor;
int bResult;
u32 ulClipOff = 0;
u32 ulBits = 0;
u32 ulsAdd = 0;
u32 tmp, ulStride;
u32 ulExcessPixels, ulClip, ulExtraLines;
srcDest.ulSrcX1 = 0;
srcDest.ulSrcY1 = 0;
srcDest.ulSrcX2 = ovlWidth - 1;
srcDest.ulSrcY2 = ovlHeight - 1;
srcDest.ulDstX1 = left;
srcDest.ulDstY1 = top;
srcDest.ulDstX2 = right;
srcDest.ulDstY2 = bottom;
srcDest.lDstX1 = srcDest.ulDstX1;
srcDest.lDstY1 = srcDest.ulDstY1;
srcDest.lDstX2 = srcDest.ulDstX2;
srcDest.lDstY2 = srcDest.ulDstY2;
/************* Vertical decimation/scaling ******************/
/* Get Src Top and Bottom */
ulSrcTop = srcDest.ulSrcY1;
ulSrcBottom = srcDest.ulSrcY2;
ulSrc = ulSrcBottom - ulSrcTop;
ulDest = srcDest.lDstY2 - srcDest.lDstY1; /* on-screen overlay */
if (ulSrc <= 1)
return -EINVAL;
/* First work out the position we are to display as offset from the
* source of the buffer
*/
ulFxScale = (ulDest << 11) / ulSrc; /* fixed point scale factor */
ulFxOffset = (srcDest.lDstY2 - srcDest.ulDstY2) << 11;
ulSrcBottom = ulSrcBottom - (ulFxOffset / ulFxScale);
ulSrc = ulSrcBottom - ulSrcTop;
ulHeight = ulSrc;
ulDest = srcDest.ulDstY2 - (srcDest.ulDstY1 - 1);
ulPattern = adwDecim8[ulBits];
/* At this point ulSrc represents the input decimator */
if (ulSrc > ulDest) {
ulDecimate = ulSrc - ulDest;
ulBits = 0;
ulApplied = ulSrc / 32;
while (((ulBits * ulApplied) +
Overlap((ulSrc % 32),
adwDecim8[ulBits])) < ulDecimate)
ulBits++;
ulPattern = adwDecim8[ulBits];
ulDecimated =
(ulBits * ulApplied) + Overlap((ulSrc % 32),
ulPattern);
ulSrc = ulSrc - ulDecimated; /* the number number of lines that will go into the scaler */
}
if (ulBits && (ulBits != 32)) {
ulVertDecFactor = (63 - ulBits) / (32 - ulBits); /* vertical decimation factor scaled up to nearest integer */
} else {
ulVertDecFactor = 1;
}
ulDacYScale = ((ulSrc - 1) * 2048) / (ulDest + 1);
tmp = STG_READ_REG(DACOverlayVtDec); /* Decimation */
CLEAR_BITS_FRM_TO(0, 31);
tmp = ulPattern;
STG_WRITE_REG(DACOverlayVtDec, tmp);
/***************** Horizontal decimation/scaling ***************************/
/*
* Now we handle the horizontal case, this is a simplified version of
* the vertical case in that we decimate by factors of 2. as we are
* working in words we should always be able to decimate by these
* factors. as we always have to have a buffer which is aligned to a
* whole number of 128 bit words, we must align the left side to the
* lowest to the next lowest 128 bit boundary, and the right hand edge
* to the next largets boundary, (in a similar way to how we didi it in
* PMX1) as the left and right hand edges are aligned to these
* boundaries normally this only becomes an issue when we are chopping
* of one of the sides We shall work out vertical stuff first
*/
ulSrc = srcDest.ulSrcX2 - srcDest.ulSrcX1;
ulDest = srcDest.lDstX2 - srcDest.lDstX1;
#ifdef _OLDCODE
ulLeft = srcDest.ulDstX1;
ulRight = srcDest.ulDstX2;
#else
if (srcDest.ulDstX1 > 2) {
ulLeft = srcDest.ulDstX1 + 2;
ulRight = srcDest.ulDstX2 + 1;
} else {
ulLeft = srcDest.ulDstX1;
ulRight = srcDest.ulDstX2 + 1;
}
#endif
/* first work out the position we are to display as offset from the source of the buffer */
bResult = 1;
do {
if (ulDest == 0)
return -EINVAL;
/* source pixels per dest pixel <<11 */
ulFxScale = ((ulSrc - 1) << 11) / (ulDest);
/* then number of destination pixels out we are */
ulFxOffset = ulFxScale * ((srcDest.ulDstX1 - srcDest.lDstX1) + ulClipOff);
ulFxOffset >>= 11;
/* this replaces the code which was making a decision as to use either ulFxOffset or ulSrcX1 */
ulSrcLeft = srcDest.ulSrcX1 + ulFxOffset;
/* then number of destination pixels out we are */
ulFxOffset = ulFxScale * (srcDest.lDstX2 - srcDest.ulDstX2);
ulFxOffset >>= 11;
ulSrcRight = srcDest.ulSrcX2 - ulFxOffset;
/*
* we must align these to our 128 bit boundaries. we shall
* round down the pixel pos to the nearest 8 pixels.
*/
ulScaleLeft = ulSrcLeft;
/* shift fxscale until it is in the range of the scaler */
ulhDecim = 0;
ulScale = (((ulSrcRight - ulSrcLeft) - 1) << (11 - ulhDecim)) / (ulRight - ulLeft + 2);
while (ulScale > 0x800) {
ulhDecim++;
ulScale = (((ulSrcRight - ulSrcLeft) - 1) << (11 - ulhDecim)) / (ulRight - ulLeft + 2);
}
/*
* to try and get the best values We first try and use
* src/dwdest for the scale factor, then we move onto src-1
*
* we want to check to see if we will need to clip data, if so
* then we should clip our source so that we don't need to
*/
if (!ovlLinear) {
ulSrcLeft &= ~0x1f;
/*
* we must align the right hand edge to the next 32
* pixel` boundary, must be on a 256 boundary so u, and
* v are 128 bit aligned
*/
ulSrcRight = (ulSrcRight + 0x1f) & ~0x1f;
} else {
ulSrcLeft &= ~0x7;
/*
* we must align the right hand edge to the next
* 8pixel` boundary
*/
ulSrcRight = (ulSrcRight + 0x7) & ~0x7;
}
/* this is the input size line store needs to cope with */
ulWidth = ulSrcRight - ulSrcLeft;
/*
* use unclipped value to work out scale factror this is the
* scale factor we want we shall now work out the horizonal
* decimation and scaling
*/
ulsVal = ((ulWidth / 8) >> ulhDecim);
if ((ulWidth != (ulsVal << ulhDecim) * 8))
ulsAdd = 1;
/* input pixels to scaler; */
ulSrc = ulWidth >> ulhDecim;
if (ulSrc <= 2)
return -EINVAL;
ulExcessPixels = ((((ulScaleLeft - ulSrcLeft)) << (11 - ulhDecim)) / ulScale);
ulClip = (ulSrc << 11) / ulScale;
ulClip -= (ulRight - ulLeft);
ulClip += ulExcessPixels;
if (ulClip)
ulClip--;
/* We may need to do more here if we really have a HW rev < 5 */
} while (!bResult);
ulExtraLines = (1 << ulhDecim) * ulVertDecFactor;
ulExtraLines += 64;
ulHeight += ulExtraLines;
ulDacXScale = ulScale;
tmp = STG_READ_REG(DACVerticalScal);
CLEAR_BITS_FRM_TO(0, 11);
CLEAR_BITS_FRM_TO(16, 22); /* Vertical Scaling */
/* Calculate new output line stride, this is always the number of 422
words in the line buffer, so it doesn't matter if the
mode is 420. Then set the vertical scale register.
*/
ulStride = (ulWidth >> (ulhDecim + 3)) + ulsAdd;
tmp |= ((ulStride << 16) | (ulDacYScale)); /* DAC_LS_CTRL = stride */
STG_WRITE_REG(DACVerticalScal, tmp);
/* Now set up the overlay size using the modified width and height
from decimate and scaling calculations
*/
tmp = STG_READ_REG(DACOverlaySize);
CLEAR_BITS_FRM_TO(0, 10);
CLEAR_BITS_FRM_TO(12, 31);
if (ovlLinear) {
tmp |=
(ovlStride | ((ulHeight + 1) << 12) |
(((ulWidth / 8) - 1) << 23));
} else {
tmp |=
(ovlStride | ((ulHeight + 1) << 12) |
(((ulWidth / 32) - 1) << 23));
}
STG_WRITE_REG(DACOverlaySize, tmp);
/* Set Video Window Start */
tmp = ((ulLeft << 16)) | (srcDest.ulDstY1);
STG_WRITE_REG(DACVidWinStart, tmp);
/* Set Video Window End */
tmp = ((ulRight) << 16) | (srcDest.ulDstY2);
STG_WRITE_REG(DACVidWinEnd, tmp);
/* Finally set up the rest of the overlay regs in the order
done in the IMG driver
*/
tmp = STG_READ_REG(DACPixelFormat);
tmp = ((ulExcessPixels << 16) | tmp) & 0x7fffffff;
STG_WRITE_REG(DACPixelFormat, tmp);
tmp = STG_READ_REG(DACHorizontalScal);
CLEAR_BITS_FRM_TO(0, 11);
CLEAR_BITS_FRM_TO(16, 17);
tmp |= ((ulhDecim << 16) | (ulDacXScale));
STG_WRITE_REG(DACHorizontalScal, tmp);
return 0;
}