1/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nsc/gfx/vid_5530.c,v 1.2 2003/02/21 16:51:10 alanh Exp $ */ 2/* 3 * $Workfile: vid_5530.c $ 4 * 5 * This file contains routines to control the CS5530 video overlay hardware. 6 * 7 * NSC_LIC_ALTERNATIVE_PREAMBLE 8 * 9 * Revision 1.0 10 * 11 * National Semiconductor Alternative GPL-BSD License 12 * 13 * National Semiconductor Corporation licenses this software 14 * ("Software"): 15 * 16 * Durango 17 * 18 * under one of the two following licenses, depending on how the 19 * Software is received by the Licensee. 20 * 21 * If this Software is received as part of the Linux Framebuffer or 22 * other GPL licensed software, then the GPL license designated 23 * NSC_LIC_GPL applies to this Software; in all other circumstances 24 * then the BSD-style license designated NSC_LIC_BSD shall apply. 25 * 26 * END_NSC_LIC_ALTERNATIVE_PREAMBLE */ 27 28/* NSC_LIC_BSD 29 * 30 * National Semiconductor Corporation Open Source License for Durango 31 * 32 * (BSD License with Export Notice) 33 * 34 * Copyright (c) 1999-2001 35 * National Semiconductor Corporation. 36 * All rights reserved. 37 * 38 * Redistribution and use in source and binary forms, with or without 39 * modification, are permitted provided that the following conditions 40 * are met: 41 * 42 * * Redistributions of source code must retain the above copyright 43 * notice, this list of conditions and the following disclaimer. 44 * 45 * * Redistributions in binary form must reproduce the above 46 * copyright notice, this list of conditions and the following 47 * disclaimer in the documentation and/or other materials provided 48 * with the distribution. 49 * 50 * * Neither the name of the National Semiconductor Corporation nor 51 * the names of its contributors may be used to endorse or promote 52 * products derived from this software without specific prior 53 * written permission. 54 * 55 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 56 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 57 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 58 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 59 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY 60 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 62 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 63 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 64 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE, 65 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY 66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 67 * OF SUCH DAMAGE. 68 * 69 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF 70 * YOUR JURISDICTION. It is licensee's responsibility to comply with 71 * any export regulations applicable in licensee's jurisdiction. Under 72 * CURRENT (2001) U.S. export regulations this software 73 * is eligible for export from the U.S. and can be downloaded by or 74 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed 75 * destinations which include Cuba, Iraq, Libya, North Korea, Iran, 76 * Syria, Sudan, Afghanistan and any other country to which the U.S. 77 * has embargoed goods and services. 78 * 79 * END_NSC_LIC_BSD */ 80 81/* NSC_LIC_GPL 82 * 83 * National Semiconductor Corporation Gnu General Public License for Durango 84 * 85 * (GPL License with Export Notice) 86 * 87 * Copyright (c) 1999-2001 88 * National Semiconductor Corporation. 89 * All rights reserved. 90 * 91 * Redistribution and use in source and binary forms, with or without 92 * modification, are permitted under the terms of the GNU General 93 * Public License as published by the Free Software Foundation; either 94 * version 2 of the License, or (at your option) any later version 95 * 96 * In addition to the terms of the GNU General Public License, neither 97 * the name of the National Semiconductor Corporation nor the names of 98 * its contributors may be used to endorse or promote products derived 99 * from this software without specific prior written permission. 100 * 101 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 102 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 103 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 104 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 105 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY 106 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 107 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 108 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 109 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 110 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE, 111 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY 112 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 113 * OF SUCH DAMAGE. See the GNU General Public License for more details. 114 * 115 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF 116 * YOUR JURISDICTION. It is licensee's responsibility to comply with 117 * any export regulations applicable in licensee's jurisdiction. Under 118 * CURRENT (2001) U.S. export regulations this software 119 * is eligible for export from the U.S. and can be downloaded by or 120 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed 121 * destinations which include Cuba, Iraq, Libya, North Korea, Iran, 122 * Syria, Sudan, Afghanistan and any other country to which the U.S. 123 * has embargoed goods and services. 124 * 125 * You should have received a copy of the GNU General Public License 126 * along with this file; if not, write to the Free Software Foundation, 127 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 128 * 129 * END_NSC_LIC_GPL */ 130 131/*---------------------------------------------------------------------------- 132 * CS5530 PLL TABLE 133 *---------------------------------------------------------------------------- 134 */ 135typedef struct tagCS5530PLLENTRY 136{ 137 long frequency; /* 16.16 fixed point frequency */ 138 unsigned long pll_value; /* associated register value */ 139} 140CS5530PLLENTRY; 141 142CS5530PLLENTRY CS5530_PLLtable[] = { 143 {0x00192CCC, 0x31C45801,}, /* 25.1750 */ 144 {0x001C526E, 0x20E36802,}, /* 28.3220 */ 145 {0x001F8000, 0x33915801,}, /* 31.5000 */ 146 {0x00240000, 0x31EC4801,}, /* 36.0000 */ 147 {0x00258000, 0x21E22801,}, /* 37.5000 */ 148 {0x00280000, 0x33088801,}, /* 40.0000 */ 149 {0x002CE666, 0x33E22801,}, /* 44.9000 */ 150 {0x00318000, 0x336C4801,}, /* 49.5000 */ 151 {0x00320000, 0x23088801,}, /* 50.0000 */ 152 {0x00325999, 0x23088801,}, /* 50.3500 */ 153 {0x00360000, 0x3708A801,}, /* 54.0000 */ 154 {0x00384000, 0x23E36802,}, /* 56.2500 */ 155 {0x0038643F, 0x23E36802,}, /* 56.3916 */ 156 {0x0038A4DD, 0x23E36802,}, /* 56.6444 */ 157 {0x003B0000, 0x37C45801,}, /* 59.0000 */ 158 {0x003F0000, 0x23EC4801,}, /* 63.0000 */ 159 {0x00410000, 0x37911801,}, /* 65.0000 */ 160 {0x00438000, 0x37963803,}, /* 67.5000 */ 161 {0x0046CCCC, 0x37058803,}, /* 70.8000 */ 162 {0x00480000, 0x3710C805,}, /* 72.0000 */ 163 {0x004B0000, 0x37E22801,}, /* 75.0000 */ 164 {0x004EC000, 0x27915801,}, /* 78.7500 */ 165 {0x00500000, 0x37D8D802,}, /* 80.0000 */ 166 {0x0059CCCC, 0x27588802,}, /* 89.8000 */ 167 {0x005E8000, 0x27EC4802,}, /* 94.5000 */ 168 {0x00630000, 0x27AC6803,}, /* 99.0000 */ 169 {0x00640000, 0x27088801,}, /* 100.0000 */ 170 {0x006C0000, 0x2710C805,}, /* 108.0000 */ 171 {0x00708000, 0x27E36802,}, /* 112.5000 */ 172 {0x00820000, 0x27C58803,}, /* 130.0000 */ 173 {0x00870000, 0x27316803,}, /* 135.0000 */ 174 {0x009D8000, 0x2F915801,}, /* 157.5000 */ 175 {0x00A20000, 0x2F08A801,}, /* 162.0000 */ 176 {0x00AF0000, 0x2FB11802,}, /* 175.0000 */ 177 {0x00BD0000, 0x2FEC4802,}, /* 189.0000 */ 178 {0x00CA0000, 0x2F963803,}, /* 202.0000 */ 179 {0x00E80000, 0x2FB1B802,}, /* 232.0000 */ 180}; 181 182#define NUM_CS5530_FREQUENCIES sizeof(CS5530_PLLtable)/sizeof(CS5530PLLENTRY) 183 184int cs5530_set_video_enable(int enable); 185int cs5530_set_video_format(unsigned long format); 186int cs5530_set_video_size(unsigned short width, unsigned short height); 187int cs5530_set_video_yuv_pitch(unsigned long ypitch, unsigned long uvpitch); 188int cs5530_set_video_offset(unsigned long offset); 189int cs5530_set_video_yuv_offsets(unsigned long yoffset, unsigned long uoffset, 190 unsigned long voffset); 191int cs5530_set_video_window(short x, short y, unsigned short w, 192 unsigned short h); 193int cs5530_set_video_left_crop(unsigned short x); 194int cs5530_set_video_upscale(unsigned short srcw, unsigned short srch, 195 unsigned short dstw, unsigned short dsth); 196int cs5530_set_video_scale(unsigned short srcw, unsigned short srch, 197 unsigned short dstw, unsigned short dsth); 198int cs5530_set_video_vertical_downscale(unsigned short srch, 199 unsigned short dsth); 200void cs5530_set_video_vertical_downscale_enable(int enable); 201int cs5530_set_video_downscale_config(unsigned short type, unsigned short m); 202int cs5530_set_video_color_key(unsigned long key, unsigned long mask, 203 int bluescreen); 204int cs5530_set_video_filter(int xfilter, int yfilter); 205int cs5530_set_video_palette(unsigned long *palette); 206int cs5530_set_video_palette_entry(unsigned long index, unsigned long color); 207int cs5530_set_video_downscale_coefficients(unsigned short coef1, 208 unsigned short coef2, 209 unsigned short coef3, 210 unsigned short coef4); 211int cs5530_set_video_downscale_enable(int enable); 212int cs5530_set_video_source(VideoSourceType source); 213int cs5530_set_vbi_source(VbiSourceType source); 214int cs5530_set_vbi_lines(unsigned long even, unsigned long odd); 215int cs5530_set_vbi_total(unsigned long even, unsigned long odd); 216int cs5530_set_video_interlaced(int enable); 217int cs5530_set_color_space_YUV(int enable); 218int cs5530_set_vertical_scaler_offset(char offset); 219int cs5530_set_top_line_in_odd(int enable); 220int cs5530_set_genlock_delay(unsigned long delay); 221int cs5530_set_genlock_enable(int flags); 222int cs5530_set_video_cursor(unsigned long key, unsigned long mask, 223 unsigned short select_color2, 224 unsigned long color1, unsigned long color2); 225int cs5530_set_video_cursor_enable(int enable); 226int cs5530_set_video_request(short x, short y); 227 228int cs5530_select_alpha_region(int region); 229int cs5530_set_alpha_enable(int enable); 230int cs5530_set_alpha_window(short x, short y, 231 unsigned short width, unsigned short height); 232int cs5530_set_alpha_value(unsigned char alpha, char delta); 233int cs5530_set_alpha_priority(int priority); 234int cs5530_set_alpha_color(unsigned long color); 235int cs5530_set_alpha_color_enable(int enable); 236int cs5530_set_no_ck_outside_alpha(int enable); 237int cs5530_disable_softvga(void); 238int cs5530_enable_softvga(void); 239int cs5530_set_macrovision_enable(int enable); 240int cs5530_set_crt_enable(int enable); 241void cs5530_reset_video(void); 242int cs5530_set_display_control(int sync_polarities); 243void cs5530_set_clock_frequency(unsigned long frequency); 244 245/* READ ROUTINES IN GFX_VID.C */ 246 247int cs5530_get_video_enable(void); 248int cs5530_get_video_format(void); 249unsigned long cs5530_get_video_src_size(void); 250unsigned long cs5530_get_video_line_size(void); 251unsigned long cs5530_get_video_xclip(void); 252unsigned long cs5530_get_video_offset(void); 253void cs5530_get_video_yuv_offsets(unsigned long *yoffset, 254 unsigned long *uoffset, 255 unsigned long *voffset); 256void cs5530_get_video_yuv_pitch(unsigned long *ypitch, 257 unsigned long *uvpitch); 258unsigned long cs5530_get_video_upscale(void); 259unsigned long cs5530_get_video_scale(void); 260unsigned long cs5530_get_video_downscale_delta(void); 261int cs5530_get_video_vertical_downscale_enable(void); 262int cs5530_get_video_downscale_config(unsigned short *type, 263 unsigned short *m); 264void cs5530_get_video_downscale_coefficients(unsigned short *coef1, 265 unsigned short *coef2, 266 unsigned short *coef3, 267 unsigned short *coef4); 268void cs5530_get_video_downscale_enable(int *enable); 269unsigned long cs5530_get_video_dst_size(void); 270unsigned long cs5530_get_video_position(void); 271unsigned long cs5530_get_video_color_key(void); 272unsigned long cs5530_get_video_color_key_mask(void); 273int cs5530_get_video_palette_entry(unsigned long index, 274 unsigned long *palette); 275int cs5530_get_video_color_key_src(void); 276int cs5530_get_video_filter(void); 277int cs5530_get_video_request(short *x, short *y); 278int cs5530_get_video_source(VideoSourceType * source); 279int cs5530_get_vbi_source(VbiSourceType * source); 280unsigned long cs5530_get_vbi_lines(int odd); 281unsigned long cs5530_get_vbi_total(int odd); 282int cs5530_get_video_interlaced(void); 283int cs5530_get_color_space_YUV(void); 284int cs5530_get_vertical_scaler_offset(char *offset); 285unsigned long cs5530_get_genlock_delay(void); 286int cs5530_get_genlock_enable(void); 287int cs5530_get_video_cursor(unsigned long *key, unsigned long *mask, 288 unsigned short *select_color2, 289 unsigned long *color1, unsigned short *color2); 290unsigned long cs5530_read_crc(void); 291unsigned long cs5530_read_crc32(void); 292unsigned long cs5530_read_window_crc(int source, unsigned short x, 293 unsigned short y, unsigned short width, 294 unsigned short height, int crc32); 295int cs5530_get_macrovision_enable(void); 296 297void cs5530_get_alpha_enable(int *enable); 298void cs5530_get_alpha_size(unsigned short *x, unsigned short *y, 299 unsigned short *width, unsigned short *height); 300void cs5530_get_alpha_value(unsigned char *alpha, char *delta); 301void cs5530_get_alpha_priority(int *priority); 302void cs5530_get_alpha_color(unsigned long *color); 303unsigned long cs5530_get_clock_frequency(void); 304int cs5530_get_vsa2_softvga_enable(void); 305int cs5530_get_sync_polarities(void); 306 307/*--------------------------------------------------------------------------- 308 * gfx_set_crt_enable 309 * 310 * This routine enables or disables the CRT output from the video processor. 311 *--------------------------------------------------------------------------- 312 */ 313#if GFX_VIDEO_DYNAMIC 314int 315cs5530_set_crt_enable(int enable) 316#else 317int 318gfx_set_crt_enable(int enable) 319#endif 320{ 321 unsigned long config; 322 323 config = READ_VID32(CS5530_DISPLAY_CONFIG); 324 325 switch (enable) { 326 case CRT_DISABLE: /* Disable everything */ 327 328 WRITE_VID32(CS5530_DISPLAY_CONFIG, 329 config & ~(CS5530_DCFG_DIS_EN | CS5530_DCFG_HSYNC_EN | 330 CS5530_DCFG_VSYNC_EN | CS5530_DCFG_DAC_BL_EN | 331 CS5530_DCFG_DAC_PWDNX)); 332 break; 333 334 case CRT_ENABLE: /* Enable CRT display, including display logic */ 335 336 WRITE_VID32(CS5530_DISPLAY_CONFIG, 337 config | CS5530_DCFG_DIS_EN | CS5530_DCFG_HSYNC_EN | 338 CS5530_DCFG_VSYNC_EN | CS5530_DCFG_DAC_BL_EN | 339 CS5530_DCFG_DAC_PWDNX); 340 break; 341 342 case CRT_STANDBY: /* HSync:Off VSync:On */ 343 344 WRITE_VID32(CS5530_DISPLAY_CONFIG, 345 (config & 346 ~(CS5530_DCFG_DIS_EN | CS5530_DCFG_HSYNC_EN | 347 CS5530_DCFG_DAC_BL_EN | CS5530_DCFG_DAC_PWDNX)) 348 | CS5530_DCFG_VSYNC_EN); 349 break; 350 351 case CRT_SUSPEND: /* HSync:On VSync:Off */ 352 353 WRITE_VID32(CS5530_DISPLAY_CONFIG, 354 (config & 355 ~(CS5530_DCFG_DIS_EN | CS5530_DCFG_VSYNC_EN | 356 CS5530_DCFG_DAC_BL_EN | CS5530_DCFG_DAC_PWDNX)) 357 | CS5530_DCFG_HSYNC_EN); 358 break; 359 360 default: 361 return (GFX_STATUS_BAD_PARAMETER); 362 } 363 return (GFX_STATUS_OK); 364} 365 366/*--------------------------------------------------------------------------- 367 * gfx_reset_video (PRIVATE ROUTINE: NOT PART OF DURANGO API) 368 * 369 * This routine is used to disable all components of video overlay before 370 * performing a mode switch. 371 *--------------------------------------------------------------------------- 372 */ 373#if GFX_VIDEO_DYNAMIC 374void 375cs5530_reset_video(void) 376#else 377void 378gfx_reset_video(void) 379#endif 380{ 381 gfx_set_video_enable(0); 382} 383 384/*----------------------------------------------------------------------------- 385 * gfx_set_display_control (PRIVATE ROUTINE: NOT PART OF DURANGO API) 386 * 387 * This routine configures the display output. 388 * 389 * "sync_polarities" is used to set the polarities of the sync pulses according 390 * to the following mask: 391 * 392 * Bit 0: If set to 1, negative horizontal polarity is programmed, 393 * otherwise positive horizontal polarity is programmed. 394 * Bit 1: If set to 1, negative vertical polarity is programmed, 395 * otherwise positive vertical polarity is programmed. 396 * 397 *----------------------------------------------------------------------------- 398 */ 399#if GFX_VIDEO_DYNAMIC 400int 401cs5530_set_display_control(int sync_polarities) 402#else 403int 404gfx_set_display_control(int sync_polarities) 405#endif 406{ 407 unsigned long dcfg; 408 409 /* ENABLE DISPLAY OUTPUT FROM CX5530 */ 410 411 dcfg = READ_VID32(CS5530_DISPLAY_CONFIG); 412 413 /* CLEAR RELEVANT FIELDS */ 414 415 dcfg &= ~(CS5530_DCFG_CRT_SYNC_SKW_MASK | CS5530_DCFG_PWR_SEQ_DLY_MASK | 416 CS5530_DCFG_CRT_HSYNC_POL | CS5530_DCFG_CRT_VSYNC_POL | 417 CS5530_DCFG_FP_PWR_EN | CS5530_DCFG_FP_DATA_EN); 418 419 /* INITIALIZATION */ 420 421 dcfg |= (CS5530_DCFG_CRT_SYNC_SKW_INIT | 422 CS5530_DCFG_PWR_SEQ_DLY_INIT | CS5530_DCFG_GV_PAL_BYP); 423 424 if (PanelEnable) { 425 dcfg |= CS5530_DCFG_FP_PWR_EN; 426 dcfg |= CS5530_DCFG_FP_DATA_EN; 427 } 428 429 /* SET APPROPRIATE SYNC POLARITIES */ 430 431 if (sync_polarities & 1) 432 dcfg |= CS5530_DCFG_CRT_HSYNC_POL; 433 if (sync_polarities & 2) 434 dcfg |= CS5530_DCFG_CRT_VSYNC_POL; 435 436 WRITE_VID32(CS5530_DISPLAY_CONFIG, dcfg); 437 return (0); 438} 439 440/*--------------------------------------------------------------------------- 441 * gfx_set_clock_frequency 442 * 443 * This routine sets the clock frequency, specified as a 16.16 fixed point 444 * value (0x00318000 = 49.5 MHz). It will set the closest frequency found 445 * in the lookup table. 446 *--------------------------------------------------------------------------- 447 */ 448#if GFX_VIDEO_DYNAMIC 449void 450cs5530_set_clock_frequency(unsigned long frequency) 451#else 452void 453gfx_set_clock_frequency(unsigned long frequency) 454#endif 455{ 456 unsigned int index; 457 unsigned long value; 458 long min, diff; 459 460 /* FIND THE REGISTER VALUES FOR THE DESIRED FREQUENCY */ 461 /* Search the table for the closest frequency (16.16 format). */ 462 463 value = CS5530_PLLtable[0].pll_value; 464 min = (long)CS5530_PLLtable[0].frequency - frequency; 465 if (min < 0L) 466 min = -min; 467 for (index = 1; index < NUM_CS5530_FREQUENCIES; index++) { 468 diff = (long)CS5530_PLLtable[index].frequency - frequency; 469 if (diff < 0L) 470 diff = -diff; 471 if (diff < min) { 472 min = diff; 473 value = CS5530_PLLtable[index].pll_value; 474 } 475 } 476 477 /* SET THE DOT CLOCK REGISTER */ 478 479 WRITE_VID32(CS5530_DOT_CLK_CONFIG, value); 480 WRITE_VID32(CS5530_DOT_CLK_CONFIG, value | 0x80000100); /* set reset/bypass */ 481 gfx_delay_milliseconds(1); /* wait for PLL to settle */ 482 WRITE_VID32(CS5530_DOT_CLK_CONFIG, value & 0x7FFFFFFF); /* clear reset */ 483 WRITE_VID32(CS5530_DOT_CLK_CONFIG, value & 0x7FFFFEFF); /* clear bypass */ 484 return; 485} 486 487/*----------------------------------------------------------------------------- 488 * gfx_set_video_enable 489 * 490 * This routine enables or disables the video overlay functionality. 491 *----------------------------------------------------------------------------- 492 */ 493#if GFX_VIDEO_DYNAMIC 494int 495cs5530_set_video_enable(int enable) 496#else 497int 498gfx_set_video_enable(int enable) 499#endif 500{ 501 unsigned long vcfg; 502 503 /* WAIT FOR VERTICAL BLANK TO START */ 504 /* Otherwise a glitch can be observed. */ 505 506 if (gfx_test_timing_active()) { 507 if (!gfx_test_vertical_active()) { 508 while (!gfx_test_vertical_active()) ; 509 } 510 while (gfx_test_vertical_active()) ; 511 } 512 vcfg = READ_VID32(CS5530_VIDEO_CONFIG); 513 if (enable) { 514 /* ENABLE VIDEO OVERLAY FROM DISPLAY CONTROLLER */ 515 /* Use private routine to abstract the display controller. */ 516 517 gfx_set_display_video_enable(1); 518 519 /* SET CS5530 BUS CONTROL PARAMETERS */ 520 /* Currently always high speed, 8-bit interface. */ 521 522 vcfg |= CS5530_VCFG_HIGH_SPD_INT; 523 vcfg &= ~(CS5530_VCFG_EARLY_VID_RDY | CS5530_VCFG_16_BIT_EN); 524 525 /* ENABLE CS5530 VIDEO OVERLAY */ 526 527 vcfg |= CS5530_VCFG_VID_EN; 528 WRITE_VID32(CS5530_VIDEO_CONFIG, vcfg); 529 } else { 530 /* DISABLE CS5530 VIDEO OVERLAY */ 531 532 vcfg &= ~CS5530_VCFG_VID_EN; 533 WRITE_VID32(CS5530_VIDEO_CONFIG, vcfg); 534 535 /* DISABLE VIDEO OVERLAY FROM DISPLAY CONTROLLER */ 536 /* Use private routine to abstract the display controller. */ 537 538 gfx_set_display_video_enable(0); 539 } 540 return (0); 541} 542 543/*----------------------------------------------------------------------------- 544 * gfx_set_video_format 545 * 546 * Currently only sets 4:2:0 format, Y1 V Y0 U. 547 *----------------------------------------------------------------------------- 548 */ 549#if GFX_VIDEO_DYNAMIC 550int 551cs5530_set_video_format(unsigned long format) 552#else 553int 554gfx_set_video_format(unsigned long format) 555#endif 556{ 557 unsigned long vcfg = 0; 558 559 /* SET THE CS5530 VIDEO INPUT FORMAT */ 560 561 vcfg = READ_VID32(CS5530_VIDEO_CONFIG); 562 vcfg &= ~(CS5530_VCFG_VID_INP_FORMAT | CS5530_VCFG_4_2_0_MODE); 563 vcfg &= ~(CS5530_VCFG_CSC_BYPASS); 564 vcfg &= ~(CS5530_VCFG_GV_SEL); 565 566 if (format < 4) 567 vcfg |= (format << 2); 568 else { 569 if (format == VIDEO_FORMAT_Y0Y1Y2Y3) { 570 vcfg |= CS5530_VCFG_4_2_0_MODE; 571 vcfg |= 1 << 2; 572 } 573 if (format == VIDEO_FORMAT_RGB) { 574 vcfg |= CS5530_VCFG_CSC_BYPASS; 575 vcfg |= CS5530_VCFG_GV_SEL; 576 } 577 } 578 579 WRITE_VID32(CS5530_VIDEO_CONFIG, vcfg); 580 return (0); 581} 582 583/*----------------------------------------------------------------------------- 584 * gfx_set_video_size 585 * 586 * This routine specifies the size of the source data. It is used only 587 * to determine how much data to transfer per frame, and is not used to 588 * calculate the scaling value (that is handled by a separate routine). 589 *----------------------------------------------------------------------------- 590 */ 591#if GFX_VIDEO_DYNAMIC 592int 593cs5530_set_video_size(unsigned short width, unsigned short height) 594#else 595int 596gfx_set_video_size(unsigned short width, unsigned short height) 597#endif 598{ 599 unsigned long size, vcfg; 600 601 /* SET THE CS5530 VIDEO LINE SIZE */ 602 603 vcfg = READ_VID32(CS5530_VIDEO_CONFIG); 604 vcfg &= ~(CS5530_VCFG_LINE_SIZE_LOWER_MASK | CS5530_VCFG_LINE_SIZE_UPPER); 605 size = (width >> 1); 606 vcfg |= (size & 0x00FF) << 8; 607 if (size & 0x0100) 608 vcfg |= CS5530_VCFG_LINE_SIZE_UPPER; 609 WRITE_VID32(CS5530_VIDEO_CONFIG, vcfg); 610 611 /* SET TOTAL VIDEO BUFFER SIZE IN DISPLAY CONTROLLER */ 612 /* Use private routine to abstract the display controller. */ 613 614 gfx_set_display_video_size(width, height); 615 return (0); 616} 617 618/*----------------------------------------------------------------------------- 619 * gfx_set_video_offset 620 * 621 * This routine sets the starting offset for the video buffer when only 622 * one offset needs to be specified. 623 *----------------------------------------------------------------------------- 624 */ 625#if GFX_VIDEO_DYNAMIC 626int 627cs5530_set_video_offset(unsigned long offset) 628#else 629int 630gfx_set_video_offset(unsigned long offset) 631#endif 632{ 633 /* SAVE VALUE FOR FUTURE CLIPPING OF THE TOP OF THE VIDEO WINDOW */ 634 635 gfx_vid_offset = offset; 636 637 /* SET VIDEO BUFFER OFFSET IN DISPLAY CONTROLLER */ 638 /* Use private routine to abstract the display controller. */ 639 640 gfx_set_display_video_offset(offset); 641 return (0); 642} 643 644/*--------------------------------------------------------------------------- 645 * gfx_set_video_scale 646 * 647 * This routine sets the scale factor for the video overlay window. The 648 * size of the source and destination regions are specified in pixels. 649 *--------------------------------------------------------------------------- 650 */ 651#if GFX_VIDEO_DYNAMIC 652int 653cs5530_set_video_scale(unsigned short srcw, unsigned short srch, 654 unsigned short dstw, unsigned short dsth) 655#else 656int 657gfx_set_video_scale(unsigned short srcw, unsigned short srch, 658 unsigned short dstw, unsigned short dsth) 659#endif 660{ 661 unsigned long xscale, yscale; 662 663 /* SAVE PARAMETERS */ 664 /* These are needed for clipping the video window later. */ 665 666 gfx_vid_srcw = srcw; 667 gfx_vid_srch = srch; 668 gfx_vid_dstw = dstw; 669 gfx_vid_dsth = dsth; 670 671 /* CALCULATE CS5530 SCALE FACTORS */ 672 /* No downscaling in CS5530 so force to 1x if attempted. */ 673 674 if (dstw <= srcw) 675 xscale = 0x1FFF; 676 else if (dstw == 1 || srcw == 1) 677 return GFX_STATUS_BAD_PARAMETER; 678 else 679 xscale = (0x2000l * (srcw - 1l)) / (dstw - 1l); 680 if (dsth <= srch) 681 yscale = 0x1FFF; 682 else if (dsth == 1 || srch == 1) 683 return GFX_STATUS_BAD_PARAMETER; 684 else 685 yscale = (0x2000l * (srch - 1l)) / (dsth - 1l); 686 WRITE_VID32(CS5530_VIDEO_SCALE, (yscale << 16) | xscale); 687 688 /* CALL ROUTINE TO UPDATE WINDOW POSITION */ 689 /* This is required because the scale values effect the number of */ 690 /* source data pixels that need to be clipped, as well as the */ 691 /* amount of data that needs to be transferred. */ 692 693 gfx_set_video_window(gfx_vid_xpos, gfx_vid_ypos, gfx_vid_width, 694 gfx_vid_height); 695 return (0); 696} 697 698/*--------------------------------------------------------------------------- 699 * gfx_set_video_window 700 * 701 * This routine sets the position and size of the video overlay window. The 702 * position is specified in screen relative coordinates, and may be negative. 703 * The size of destination region is specified in pixels. The line size 704 * indicates the number of bytes of source data per scanline. 705 *--------------------------------------------------------------------------- 706 */ 707#if GFX_VIDEO_DYNAMIC 708int 709cs5530_set_video_window(short x, short y, unsigned short w, unsigned short h) 710#else 711int 712gfx_set_video_window(short x, short y, unsigned short w, unsigned short h) 713#endif 714{ 715 unsigned long vcfg = 0; 716 unsigned long hadjust, vadjust; 717 unsigned long xstart, ystart, xend, yend; 718 719 /* SAVE PARAMETERS */ 720 /* These are needed to call this routine if the scale value changes. */ 721 722 gfx_vid_xpos = x; 723 gfx_vid_ypos = y; 724 gfx_vid_width = w; 725 gfx_vid_height = h; 726 727 /* GET ADJUSTMENT VALUES */ 728 /* Use routines to abstract version of display controller. */ 729 730 hadjust = gfx_get_htotal() - gfx_get_hsync_end() - 13l; 731 vadjust = gfx_get_vtotal() - gfx_get_vsync_end() + 1l; 732 733 /* HORIZONTAL START */ 734 xstart = (unsigned long)x + hadjust; 735 736 /* HORIZONTAL END */ 737 /* End positions in register are non-inclusive (one more than the actual end) */ 738 739 if ((x + w) < gfx_get_hactive()) 740 xend = (unsigned long)x + (unsigned long)w + hadjust; 741 else /* right clipping needed */ 742 xend = (unsigned long)gfx_get_hactive() + hadjust; 743 744 /* VERTICAL START */ 745 746 ystart = (unsigned long)y + vadjust; 747 748 /* VERTICAL END */ 749 750 if ((y + h) < gfx_get_vactive()) 751 yend = (unsigned long)y + (unsigned long)h + vadjust; 752 else /* bottom clipping needed */ 753 yend = (unsigned long)gfx_get_vactive() + vadjust; 754 755 /* DISABLE REGISTER UPDATES */ 756 757 vcfg = READ_VID32(CS5530_VIDEO_CONFIG); 758 vcfg &= ~CS5530_VCFG_VID_REG_UPDATE; 759 WRITE_VID32(CS5530_VIDEO_CONFIG, vcfg); 760 761 /* SET VIDEO POSITION */ 762 763 WRITE_VID32(CS5530_VIDEO_X_POS, (xend << 16) | xstart); 764 WRITE_VID32(CS5530_VIDEO_Y_POS, (yend << 16) | ystart); 765 766 vcfg |= CS5530_VCFG_VID_REG_UPDATE; 767 WRITE_VID32(CS5530_VIDEO_CONFIG, vcfg); 768 769 return (0); 770} 771 772/*--------------------------------------------------------------------------- 773 * gfx_set_video_left_crop 774 * 775 * This routine sets the number of pixels which will be cropped from the 776 * beginning of each video line. The video window will begin to display only 777 * from the pixel following the cropped pixels, and the cropped pixels 778 * will be ignored. 779 *--------------------------------------------------------------------------- 780 */ 781#if GFX_VIDEO_DYNAMIC 782int 783cs5530_set_video_left_crop(unsigned short x) 784#else 785int 786gfx_set_video_left_crop(unsigned short x) 787#endif 788{ 789 unsigned long vcfg, initread; 790 791 /* CLIPPING ON LEFT */ 792 /* Adjust initial read for scale, checking for divide by zero */ 793 794 if (gfx_vid_dstw) 795 initread = (unsigned long)x *gfx_vid_srcw / gfx_vid_dstw; 796 797 else 798 initread = 0; 799 800 /* SET INITIAL READ ADDRESS AND ENABLE REGISTER UPDATES */ 801 802 vcfg = READ_VID32(CS5530_VIDEO_CONFIG); 803 vcfg &= ~CS5530_VCFG_INIT_READ_MASK; 804 vcfg |= (initread << 15) & CS5530_VCFG_INIT_READ_MASK; 805 vcfg |= CS5530_VCFG_VID_REG_UPDATE; 806 WRITE_VID32(CS5530_VIDEO_CONFIG, vcfg); 807 return (0); 808} 809 810/*--------------------------------------------------------------------------- 811 * gfx_set_video_color_key 812 * 813 * This routine specifies the color key value and mask for the video overlay 814 * hardware. To disable color key, the color and mask should both be set to 815 * zero. The hardware uses the color key in the following equation: 816 * 817 * ((source data) & (color key mask)) == ((color key) & (color key mask)) 818 * 819 * The source data can be either graphics data or video data. The bluescreen 820 * parameter is set to have the hardware compare video data and clear to 821 * comapare graphics data. 822 *--------------------------------------------------------------------------- 823 */ 824#if GFX_VIDEO_DYNAMIC 825int 826cs5530_set_video_color_key(unsigned long key, unsigned long mask, 827 int graphics) 828#else 829int 830gfx_set_video_color_key(unsigned long key, unsigned long mask, int graphics) 831#endif 832{ 833 unsigned long dcfg = 0; 834 835 /* SET CS5530 COLOR KEY VALUE */ 836 837 WRITE_VID32(CS5530_VIDEO_COLOR_KEY, key); 838 WRITE_VID32(CS5530_VIDEO_COLOR_MASK, mask); 839 840 /* SELECT GRAPHICS OR VIDEO DATA TO COMPARE TO THE COLOR KEY */ 841 842 dcfg = READ_VID32(CS5530_DISPLAY_CONFIG); 843 if (graphics & 0x01) 844 dcfg &= ~CS5530_DCFG_VG_CK; 845 else 846 dcfg |= CS5530_DCFG_VG_CK; 847 WRITE_VID32(CS5530_DISPLAY_CONFIG, dcfg); 848 return (0); 849} 850 851/*--------------------------------------------------------------------------- 852 * gfx_set_video_filter 853 * 854 * This routine enables or disables the video overlay filters. 855 *--------------------------------------------------------------------------- 856 */ 857#if GFX_VIDEO_DYNAMIC 858int 859cs5530_set_video_filter(int xfilter, int yfilter) 860#else 861int 862gfx_set_video_filter(int xfilter, int yfilter) 863#endif 864{ 865 unsigned long vcfg = 0; 866 867 /* ENABLE OR DISABLE CS5530 VIDEO OVERLAY FILTERS */ 868 869 vcfg = READ_VID32(CS5530_VIDEO_CONFIG); 870 vcfg &= ~(CS5530_VCFG_X_FILTER_EN | CS5530_VCFG_Y_FILTER_EN); 871 if (xfilter) 872 vcfg |= CS5530_VCFG_X_FILTER_EN; 873 if (yfilter) 874 vcfg |= CS5530_VCFG_Y_FILTER_EN; 875 WRITE_VID32(CS5530_VIDEO_CONFIG, vcfg); 876 877 return (0); 878} 879 880/*--------------------------------------------------------------------------- 881 * gfx_set_video_palette 882 * 883 * This routine loads the video hardware palette. If a NULL pointer is 884 * specified, the palette is bypassed (for CS5530, this means loading the 885 * palette with identity values). 886 *--------------------------------------------------------------------------- 887 */ 888#if GFX_VIDEO_DYNAMIC 889int 890cs5530_set_video_palette(unsigned long *palette) 891#else 892int 893gfx_set_video_palette(unsigned long *palette) 894#endif 895{ 896 unsigned long i, entry; 897 898 /* LOAD CS5530 VIDEO PALETTE */ 899 900 WRITE_VID32(CS5530_PALETTE_ADDRESS, 0); 901 for (i = 0; i < 256; i++) { 902 if (palette) 903 entry = palette[i]; 904 else 905 entry = i | (i << 8) | (i << 16); 906 WRITE_VID32(CS5530_PALETTE_DATA, entry); 907 } 908 return (0); 909} 910 911/*--------------------------------------------------------------------------- 912 * gfx_set_video_palette_entry 913 * 914 * This routine loads a single entry of the video hardware palette. 915 *--------------------------------------------------------------------------- 916 */ 917#if GFX_VIDEO_DYNAMIC 918int 919cs5530_set_video_palette_entry(unsigned long index, unsigned long palette) 920#else 921int 922gfx_set_video_palette_entry(unsigned long index, unsigned long palette) 923#endif 924{ 925 if (index > 0xFF) 926 return GFX_STATUS_BAD_PARAMETER; 927 928 /* SET A SINGLE ENTRY */ 929 930 WRITE_VID32(CS5530_PALETTE_ADDRESS, index); 931 WRITE_VID32(CS5530_PALETTE_DATA, palette); 932 933 return (0); 934} 935 936#define CX55xx_VIDEO_PCI_44 0x80009444 937 938/*--------------------------------------------------------------------------- 939 * gfx_disable_softvga 940 * 941 * Disables SoftVga. This function is only valid with VSA2, Returns 1 if 942 * SoftVga can be disabled; 0 if not. 943 *--------------------------------------------------------------------------- 944 */ 945#if GFX_VIDEO_DYNAMIC 946int 947cs5530_disable_softvga(void) 948#else 949int 950gfx_disable_softvga(void) 951#endif 952{ 953 unsigned long reg_val; 954 955 /* get the current value */ 956 reg_val = gfx_pci_config_read(CX55xx_VIDEO_PCI_44); 957 /* setting video PCI register 44 bit 0 to 1 disables SoftVga */ 958 reg_val |= 0x1; 959 gfx_pci_config_write(CX55xx_VIDEO_PCI_44, reg_val); 960 961 /* see if we set the bit and return the appropriate value */ 962 reg_val = gfx_pci_config_read(CX55xx_VIDEO_PCI_44); 963 if ((reg_val & 0x1) == 0x1) 964 return (1); 965 else 966 return (0); 967 968} 969 970/*--------------------------------------------------------------------------- 971 * gfx_enable_softvga 972 * 973 * Enables SoftVga. This function is only valid with VSA2, Returns 1 if 974 * SoftVga can be enbled; 0 if not. 975 *--------------------------------------------------------------------------- 976 */ 977#if GFX_VIDEO_DYNAMIC 978int 979cs5530_enable_softvga(void) 980#else 981int 982gfx_enable_softvga(void) 983#endif 984{ 985 unsigned long reg_val; 986 987 /* get the current value */ 988 reg_val = gfx_pci_config_read(CX55xx_VIDEO_PCI_44); 989 /* clearing video PCI register 44 bit 0 enables SoftVga */ 990 gfx_pci_config_write(CX55xx_VIDEO_PCI_44, reg_val & 0xfffffffe); 991 992 /* see if we cleared the bit and return the appropriate value */ 993 reg_val = gfx_pci_config_read(CX55xx_VIDEO_PCI_44); 994 if ((reg_val & 0x1) == 0) 995 return (1); 996 else 997 return (0); 998 999} 1000 1001/*--------------------------------------------------------------------------- 1002 * gfx_get_clock_frequency 1003 * 1004 * This routine returns the current clock frequency in 16.16 format. 1005 * It reads the current register value and finds the match in the table. 1006 * If no match is found, this routine returns 0. 1007 *--------------------------------------------------------------------------- 1008 */ 1009#if GFX_VIDEO_DYNAMIC 1010unsigned long 1011cs5530_get_clock_frequency(void) 1012#else 1013unsigned long 1014gfx_get_clock_frequency(void) 1015#endif 1016{ 1017 unsigned int index; 1018 unsigned long value, mask; 1019 1020 mask = 0x7FFFFEDC; 1021 value = READ_VID32(CS5530_DOT_CLK_CONFIG) & mask; 1022 for (index = 0; index < NUM_CS5530_FREQUENCIES; index++) { 1023 if ((CS5530_PLLtable[index].pll_value & mask) == value) 1024 return (CS5530_PLLtable[index].frequency); 1025 } 1026 return (0); 1027} 1028 1029/*************************************************************/ 1030/* READ ROUTINES | INCLUDED FOR DIAGNOSTIC PURPOSES ONLY */ 1031/*************************************************************/ 1032 1033#if GFX_READ_ROUTINES 1034 1035/*--------------------------------------------------------------------------- 1036 * gfx_get_vsa2_softvga_enable 1037 * 1038 * This function returns the enable status of SoftVGA. It is valid 1039 * only if VSAII is present. 1040 *--------------------------------------------------------------------------- 1041 */ 1042#if GFX_VIDEO_DYNAMIC 1043int 1044cs5530_get_vsa2_softvga_enable(void) 1045#else 1046int 1047gfx_get_vsa2_softvga_enable(void) 1048#endif 1049{ 1050 unsigned long reg_val; 1051 1052 reg_val = gfx_pci_config_read(CX55xx_VIDEO_PCI_44); 1053 if ((reg_val & 0x1) == 0) 1054 return (1); 1055 else 1056 return (0); 1057 1058} 1059 1060/*--------------------------------------------------------------------------- 1061 * gfx_get_sync_polarities 1062 * 1063 * This routine returns the polarities of the sync pulses: 1064 * Bit 0: Set if negative horizontal polarity. 1065 * Bit 1: Set if negative vertical polarity. 1066 *--------------------------------------------------------------------------- 1067 */ 1068#if GFX_VIDEO_DYNAMIC 1069int 1070cs5530_get_sync_polarities(void) 1071#else 1072int 1073gfx_get_sync_polarities(void) 1074#endif 1075{ 1076 int polarities = 0; 1077 1078 if (READ_VID32(CS5530_DISPLAY_CONFIG) & 0x00000100) 1079 polarities |= 1; 1080 if (READ_VID32(CS5530_DISPLAY_CONFIG) & 0x00000200) 1081 polarities |= 2; 1082 return (polarities); 1083} 1084 1085/*--------------------------------------------------------------------------- 1086 * gfx_get_video_palette_entry 1087 * 1088 * This routine returns a single palette entry. 1089 *--------------------------------------------------------------------------- 1090 */ 1091#if GFX_VIDEO_DYNAMIC 1092int 1093cs5530_get_video_palette_entry(unsigned long index, unsigned long *palette) 1094#else 1095int 1096gfx_get_video_palette_entry(unsigned long index, unsigned long *palette) 1097#endif 1098{ 1099 if (index > 0xFF) 1100 return GFX_STATUS_BAD_PARAMETER; 1101 1102 /* READ A SINGLE ENTRY */ 1103 1104 WRITE_VID32(CS5530_PALETTE_ADDRESS, index); 1105 *palette = READ_VID32(CS5530_PALETTE_DATA); 1106 1107 return (GFX_STATUS_OK); 1108} 1109 1110/*----------------------------------------------------------------------------- 1111 * gfx_get_video_enable 1112 * 1113 * This routine returns the value "one" if video overlay is currently enabled, 1114 * otherwise it returns the value "zero". 1115 *----------------------------------------------------------------------------- 1116 */ 1117#if GFX_VIDEO_DYNAMIC 1118int 1119cs5530_get_video_enable(void) 1120#else 1121int 1122gfx_get_video_enable(void) 1123#endif 1124{ 1125 if (READ_VID32(CS5530_VIDEO_CONFIG) & CS5530_VCFG_VID_EN) 1126 return (1); 1127 return (0); 1128} 1129 1130/*----------------------------------------------------------------------------- 1131 * gfx_get_video_format 1132 * 1133 * This routine returns the current video overlay format. 1134 *----------------------------------------------------------------------------- 1135 */ 1136#if GFX_VIDEO_DYNAMIC 1137int 1138cs5530_get_video_format(void) 1139#else 1140int 1141gfx_get_video_format(void) 1142#endif 1143{ 1144 unsigned long vcfg; 1145 1146 vcfg = READ_VID32(CS5530_VIDEO_CONFIG); 1147 if (vcfg & CS5530_VCFG_CSC_BYPASS) 1148 return (VIDEO_FORMAT_RGB); 1149 if (vcfg & CS5530_VCFG_4_2_0_MODE) 1150 return (VIDEO_FORMAT_Y0Y1Y2Y3); 1151 1152 return ((int)((vcfg >> 2) & 3)); 1153} 1154 1155/*----------------------------------------------------------------------------- 1156 * gfx_get_video_src_size 1157 * 1158 * This routine returns the size of the source video overlay buffer. The 1159 * return value is (height << 16) | width. 1160 *----------------------------------------------------------------------------- 1161 */ 1162#if GFX_VIDEO_DYNAMIC 1163unsigned long 1164cs5530_get_video_src_size(void) 1165#else 1166unsigned long 1167gfx_get_video_src_size(void) 1168#endif 1169{ 1170 unsigned long width = 0, height = 0; 1171 1172 /* DETERMINE SOURCE WIDTH FROM THE CS5530 VIDEO LINE SIZE */ 1173 1174 width = (READ_VID32(CS5530_VIDEO_CONFIG) >> 7) & 0x000001FE; 1175 if (READ_VID32(CS5530_VIDEO_CONFIG) & CS5530_VCFG_LINE_SIZE_UPPER) 1176 width += 512l; 1177 1178 if (width) { 1179 /* DETERMINE HEIGHT BY DIVIDING TOTAL SIZE BY WIDTH */ 1180 /* Get total size from display controller - abtracted. */ 1181 1182 height = gfx_get_display_video_size() / (width << 1); 1183 } 1184 return ((height << 16) | width); 1185} 1186 1187/*----------------------------------------------------------------------------- 1188 * gfx_get_video_line_size 1189 * 1190 * This routine returns the line size of the source video overlay buffer, in 1191 * pixels. 1192 *----------------------------------------------------------------------------- 1193 */ 1194#if GFX_VIDEO_DYNAMIC 1195unsigned long 1196cs5530_get_video_line_size(void) 1197#else 1198unsigned long 1199gfx_get_video_line_size(void) 1200#endif 1201{ 1202 unsigned long width = 0; 1203 1204 /* DETERMINE SOURCE WIDTH FROM THE CS5530 VIDEO LINE SIZE */ 1205 1206 width = (READ_VID32(CS5530_VIDEO_CONFIG) >> 7) & 0x000001FE; 1207 if (READ_VID32(CS5530_VIDEO_CONFIG) & CS5530_VCFG_LINE_SIZE_UPPER) 1208 width += 512l; 1209 return (width); 1210} 1211 1212/*----------------------------------------------------------------------------- 1213 * gfx_get_video_xclip 1214 * 1215 * This routine returns the number of bytes clipped on the left side of a 1216 * video overlay line (skipped at beginning). 1217 *----------------------------------------------------------------------------- 1218 */ 1219#if GFX_VIDEO_DYNAMIC 1220unsigned long 1221cs5530_get_video_xclip(void) 1222#else 1223unsigned long 1224gfx_get_video_xclip(void) 1225#endif 1226{ 1227 unsigned long clip = 0; 1228 1229 /* DETERMINE SOURCE WIDTH FROM THE CS5530 VIDEO LINE SIZE */ 1230 1231 clip = (READ_VID32(CS5530_VIDEO_CONFIG) >> 14) & 0x000007FC; 1232 return (clip); 1233} 1234 1235/*----------------------------------------------------------------------------- 1236 * gfx_get_video_offset 1237 * 1238 * This routine returns the current offset for the video overlay buffer. 1239 *----------------------------------------------------------------------------- 1240 */ 1241#if GFX_VIDEO_DYNAMIC 1242unsigned long 1243cs5530_get_video_offset(void) 1244#else 1245unsigned long 1246gfx_get_video_offset(void) 1247#endif 1248{ 1249 return (gfx_get_display_video_offset()); 1250} 1251 1252/*--------------------------------------------------------------------------- 1253 * gfx_get_video_scale 1254 * 1255 * This routine returns the scale factor for the video overlay window. 1256 *--------------------------------------------------------------------------- 1257 */ 1258#if GFX_VIDEO_DYNAMIC 1259unsigned long 1260cs5530_get_video_scale(void) 1261#else 1262unsigned long 1263gfx_get_video_scale(void) 1264#endif 1265{ 1266 return (READ_VID32(CS5530_VIDEO_SCALE)); 1267} 1268 1269/*--------------------------------------------------------------------------- 1270 * gfx_get_video_dst_size 1271 * 1272 * This routine returns the size of the displayed video overlay window. 1273 * NOTE: This is the displayed window size, which may be different from 1274 * the real window size if clipped. 1275 *--------------------------------------------------------------------------- 1276 */ 1277#if GFX_VIDEO_DYNAMIC 1278unsigned long 1279cs5530_get_video_dst_size(void) 1280#else 1281unsigned long 1282gfx_get_video_dst_size(void) 1283#endif 1284{ 1285 unsigned long xsize, ysize; 1286 1287 xsize = READ_VID32(CS5530_VIDEO_X_POS); 1288 xsize = ((xsize >> 16) & 0x7FF) - (xsize & 0x07FF); 1289 ysize = READ_VID32(CS5530_VIDEO_Y_POS); 1290 ysize = ((ysize >> 16) & 0x7FF) - (ysize & 0x07FF); 1291 return ((ysize << 16) | xsize); 1292} 1293 1294/*--------------------------------------------------------------------------- 1295 * gfx_get_video_position 1296 * 1297 * This routine returns the position of the video overlay window. The 1298 * return value is (ypos << 16) | xpos. 1299 * NOTE: This is the displayed window position, which may be different from 1300 * the real window position if clipped. 1301 *--------------------------------------------------------------------------- 1302 */ 1303#if GFX_VIDEO_DYNAMIC 1304unsigned long 1305cs5530_get_video_position(void) 1306#else 1307unsigned long 1308gfx_get_video_position(void) 1309#endif 1310{ 1311 unsigned long hadjust, vadjust; 1312 unsigned long xpos, ypos; 1313 1314 /* READ HARDWARE POSITION */ 1315 1316 xpos = READ_VID32(CS5530_VIDEO_X_POS) & 0x000007FF; 1317 ypos = READ_VID32(CS5530_VIDEO_Y_POS) & 0x000007FF; 1318 1319 /* GET ADJUSTMENT VALUES */ 1320 /* Use routines to abstract version of display controller. */ 1321 1322 hadjust = gfx_get_htotal() - gfx_get_hsync_end() - 13l; 1323 vadjust = gfx_get_vtotal() - gfx_get_vsync_end() + 1l; 1324 xpos -= hadjust; 1325 ypos -= vadjust; 1326 return ((ypos << 16) | (xpos & 0x0000FFFF)); 1327} 1328 1329/*--------------------------------------------------------------------------- 1330 * gfx_get_video_color_key 1331 * 1332 * This routine returns the current video color key value. 1333 *--------------------------------------------------------------------------- 1334 */ 1335#if GFX_VIDEO_DYNAMIC 1336unsigned long 1337cs5530_get_video_color_key(void) 1338#else 1339unsigned long 1340gfx_get_video_color_key(void) 1341#endif 1342{ 1343 return (READ_VID32(CS5530_VIDEO_COLOR_KEY)); 1344} 1345 1346/*--------------------------------------------------------------------------- 1347 * gfx_get_video_color_key_mask 1348 * 1349 * This routine returns the current video color mask value. 1350 *--------------------------------------------------------------------------- 1351 */ 1352#if GFX_VIDEO_DYNAMIC 1353unsigned long 1354cs5530_get_video_color_key_mask(void) 1355#else 1356unsigned long 1357gfx_get_video_color_key_mask(void) 1358#endif 1359{ 1360 return (READ_VID32(CS5530_VIDEO_COLOR_MASK)); 1361} 1362 1363/*--------------------------------------------------------------------------- 1364 * gfx_get_video_color_key_src 1365 * 1366 * This routine returns 0 for video data compare, 1 for graphics data. 1367 *--------------------------------------------------------------------------- 1368 */ 1369#if GFX_VIDEO_DYNAMIC 1370int 1371cs5530_get_video_color_key_src(void) 1372#else 1373int 1374gfx_get_video_color_key_src(void) 1375#endif 1376{ 1377 if (READ_VID32(CS5530_DISPLAY_CONFIG) & CS5530_DCFG_VG_CK) 1378 return (0); 1379 return (1); 1380} 1381 1382/*--------------------------------------------------------------------------- 1383 * gfx_get_video_filter 1384 * 1385 * This routine returns if the filters are currently enabled. 1386 *--------------------------------------------------------------------------- 1387 */ 1388#if GFX_VIDEO_DYNAMIC 1389int 1390cs5530_get_video_filter(void) 1391#else 1392int 1393gfx_get_video_filter(void) 1394#endif 1395{ 1396 int retval = 0; 1397 1398 if (READ_VID32(CS5530_VIDEO_CONFIG) & CS5530_VCFG_X_FILTER_EN) 1399 retval |= 1; 1400 if (READ_VID32(CS5530_VIDEO_CONFIG) & CS5530_VCFG_Y_FILTER_EN) 1401 retval |= 2; 1402 return (retval); 1403} 1404 1405/*--------------------------------------------------------------------------- 1406 * gfx_read_crc 1407 * 1408 * This routine returns the hardware CRC value, which is used for automated 1409 * testing. The value is like a checksum, but will change if pixels move 1410 * locations. 1411 *--------------------------------------------------------------------------- 1412 */ 1413#if GFX_VIDEO_DYNAMIC 1414unsigned long 1415cs5530_read_crc(void) 1416#else 1417unsigned long 1418gfx_read_crc(void) 1419#endif 1420{ 1421 unsigned long crc = 0xFFFFFFFF; 1422 1423 if (gfx_test_timing_active()) { 1424 /* WAIT UNTIL ACTIVE DISPLAY */ 1425 1426 while (!gfx_test_vertical_active()) ; 1427 1428 /* RESET CRC DURING ACTIVE DISPLAY */ 1429 1430 WRITE_VID32(CS5530_CRCSIG_TFT_TV, 0); 1431 WRITE_VID32(CS5530_CRCSIG_TFT_TV, 1); 1432 1433 /* WAIT UNTIL NOT ACTIVE, THEN ACTIVE, NOT ACTIVE, THEN ACTIVE */ 1434 1435 while (gfx_test_vertical_active()) ; 1436 while (!gfx_test_vertical_active()) ; 1437 while (gfx_test_vertical_active()) ; 1438 while (!gfx_test_vertical_active()) ; 1439 crc = READ_VID32(CS5530_CRCSIG_TFT_TV) >> 8; 1440 } 1441 return (crc); 1442} 1443 1444#endif /* GFX_READ_ROUTINES */ 1445 1446/* END OF FILE */ 1447