1 /*******************************************************************************
3 * Copyright (C) 2017 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 *******************************************************************************/
32 /******************************************************************************/
37 * This file implements all the functions related to the Video Pipeline of the
38 * DisplayPort Subsystem. See xavbuf.h for the detailed description of the
44 * MODIFICATION HISTORY:
46 * Ver Who Date Changes
47 * ----- ---- -------- -----------------------------------------------
48 * 1.0 aad 06/24/17 Initial release.
49 * 2.0 aad 10/08/17 Some APIs to use enums instead of Macros.
53 *******************************************************************************/
54 /******************************* Include Files ********************************/
58 /**************************** Constant Definitions ****************************/
59 const XAVBuf_VideoAttribute XAVBuf_SupportedFormats[XAVBUF_NUM_SUPPORTED];
61 /******************************************************************************/
63 * This function sets the scaling factors depending on the source video stream.
65 * @param InstancePtr is a pointer to the XAVBuf instance.
66 * @param RegOffset is the register offset of the SF0 register from the
68 * @param Scaling Factors is a pointer to the scaling factors needed for
69 * scaling colors to 12 BPC.
75 *******************************************************************************/
76 static void XAVBuf_SetScalingFactors(XAVBuf *InstancePtr, u32 RegOffset,
80 for (Index = 0; Index < 3; Index++) {
81 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
82 RegOffset + (Index * 4), ScalingFactors[Index]);
87 /******************************************************************************/
89 * This function sets the Layer Control for Video and Graphics layers.
91 * @param InstancePtr is a pointer to the XAVBuf instance.
92 * @param RegOffset is the register offset of Video Layer or Graphics
93 * Layer from the base address
94 * @param Video is a pointer to the XAVBuf_VideoAttribute struct which
95 * has been configured for the particular layer
101 *******************************************************************************/
102 static void XAVBuf_SetLayerControl(XAVBuf *InstancePtr, u32 RegOffset,
103 XAVBuf_VideoAttribute *Video)
107 RegVal = (Video->IsRGB <<
108 XAVBUF_V_BLEND_LAYER0_CONTROL_RGB_MODE_SHIFT) |
111 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, RegOffset, RegVal);
114 /******************************************************************************/
116 * This function applies Attributes for Live source(Video/Graphics).
118 * @param InstancePtr is an pointer to the XAVBuf Instance.
119 * @param RegConfig is a register offset for Video or Graphics config
121 * @param Video is a pointer to the attributes of the video to be applied
125 * @note Live source can be live Video or Live Graphics.
126 ******************************************************************************/
127 static void XAVBuf_SetLiveVideoAttributes(XAVBuf *InstancePtr, u32 RegConfig,
128 XAVBuf_VideoAttribute *Video)
132 RegVal |= Video->Value << XAVBUF_BUF_LIVE_VID_CFG_FORMAT_SHIFT;
133 RegVal |= Video->BPP/6 - 3;
134 RegVal |= Video->Swap << XAVBUF_BUF_LIVE_VID_CFG_CB_FIRST_SHIFT;
135 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, RegConfig, RegVal);
138 /******************************************************************************/
140 * This function applies Attributes for Non - Live source(Video/Graphics).
142 * @param InstancePtr is an pointer to the XAVBuf Instance.
143 * @param VideoSrc is the source of the Non-Live Video
144 * @param Video is a pointer to the attributes of the video to be applied
148 * @note Non Live source can be Non Live Video or Non Live Graphics.
149 ******************************************************************************/
150 static void XAVBuf_SetNonLiveVideoAttributes(XAVBuf *InstancePtr, u32 VideoSrc,
151 XAVBuf_VideoAttribute *Video)
155 RegVal = XAVBuf_ReadReg(InstancePtr->Config.BaseAddr,
157 if(VideoSrc == XAVBUF_VIDSTREAM1_NONLIVE) {
158 RegVal &= ~XAVBUF_BUF_FORMAT_NL_VID_FORMAT_MASK;
159 RegVal |= Video->Value;
161 else if (VideoSrc == XAVBUF_VIDSTREAM2_NONLIVE_GFX) {
162 RegVal &= ~XAVBUF_BUF_FORMAT_NL_GRAPHX_FORMAT_MASK;
163 RegVal |= (Video->Value) <<
164 XAVBUF_BUF_FORMAT_NL_GRAPHX_FORMAT_SHIFT;
167 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_BUF_FORMAT,
171 /******************************************************************************/
173 * This function programs the coeffitients for Color Space Conversion.
175 * @param InstancePtr is an pointer to the XAVBuf Instance.
176 * @param RegOffset is a register offset for Video or Graphics config
178 * @param Video is a pointer to the XAVBuf_Attribute structure
183 ******************************************************************************/
184 static void XAVBuf_InConvertToRGB(XAVBuf *InstancePtr, u32 RegOffset,
185 XAVBuf_VideoAttribute *Video)
191 /* SDTV Coefficients */
192 u16 CSCCoeffs[] = { 0x1000, 0x0000, 0x166F,
193 0x1000, 0x7A7F, 0x7493,
194 0x1000, 0x1C5A, 0x0000 };
195 u16 CSCOffset[] = { 0x0000, 0x1800, 0x1800 };
196 u16 RGBCoeffs[] = { 0x1000, 0x0000, 0x0000,
197 0x0000, 0x1000, 0x0000,
198 0x0000, 0x0000, 0x1000 };
199 u16 RGBOffset[] = { 0x0000, 0x0000, 0x0000 };
201 CSCMatrix = RGBCoeffs;
202 OffsetMatrix = RGBOffset;
205 CSCMatrix = CSCCoeffs;
206 OffsetMatrix = CSCOffset;
208 /* Program Colorspace conversion coefficients */
209 for (Index = 9; Index < 12; Index++) {
210 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
211 RegOffset + (Index * 4),
212 OffsetMatrix[Index - 9]);
215 /* Program Colorspace conversion matrix */
216 for (Index = 0; Index < 9; Index++) {
217 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
218 RegOffset + (Index * 4), CSCMatrix[Index]);
223 /******************************************************************************/
225 * This function converts the Blender output to the desired output format.
227 * @param InstancePtr is an pointer to the XAVBuf Instance.
228 * @param RegConfig is a register offset for Video or Graphics config
230 * @param Video is a pointer to the XAVBuf_Attribute structure
235 ******************************************************************************/
236 static void XAVBuf_InConvertToOutputFormat(XAVBuf *InstancePtr,
237 XAVBuf_VideoAttribute *Video)
240 u32 RegOffset = XAVBUF_V_BLEND_RGB2YCBCR_COEFF0;
241 u32 ColorOffset = XAVBUF_V_BLEND_LUMA_OUTCSC_OFFSET;
242 u8 Value = Video->Value;
246 /* SDTV Coeffitients */
247 u16 CSCCoeffs[] = { 0x04C8, 0x0964, 0x01D3,
248 0x7D4C, 0x7AB4, 0x0800,
249 0x0800, 0x7945, 0x7EB5 };
250 u16 CSCOffset[] = { 0x0000, 0x800, 0x800 };
251 u16 RGBCoeffs[] = { 0x1000, 0x0000, 0x0000,
252 0x0000, 0x1000, 0x0000,
253 0x0000, 0x0000, 0x1000 };
254 u16 RGBOffset[] = { 0x0000, 0x0000, 0x0000 };
258 MatrixCoeff = CSCCoeffs;
259 MatrixOffset = CSCOffset;
263 MatrixCoeff = RGBCoeffs;
264 MatrixOffset = RGBOffset;
267 for (Index = 0; Index < 9; Index++) {
268 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
269 RegOffset + (Index * 4), MatrixCoeff[Index]);
271 for (Index = 0; Index < 3; Index++) {
272 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
273 ColorOffset + (Index * 4),
274 (MatrixOffset[Index] <<
275 XAVBUF_V_BLEND_LUMA_IN1CSC_OFFSET_POST_OFFSET_SHIFT));
278 /******************************************************************************/
280 * This function configures the Video Pipeline for the selected source
282 * @param InstancePtr is an pointer to the XAVBuf Instance.
283 * @param VideoSrc is a parameter which indicates which Video Source
289 ******************************************************************************/
290 static int XAVBuf_ConfigureVideo(XAVBuf *InstancePtr, u8 VideoSrc)
294 u32 ScalingOffset = 0;
297 XAVBuf_VideoAttribute *Video = NULL;
298 u32 *ScalingFactors = NULL;
300 Xil_AssertNonvoid(InstancePtr != NULL);
302 case XAVBUF_VIDSTREAM1_LIVE:
303 RegConfig = XAVBUF_BUF_LIVE_VID_CFG;
304 ScalingOffset = XAVBUF_BUF_LIVE_VID_COMP0_SF;
305 LayerOffset = XAVBUF_V_BLEND_LAYER0_CONTROL;
306 CSCOffset = XAVBUF_V_BLEND_IN1CSC_COEFF0;
307 Video = InstancePtr->AVMode.LiveVideo;
308 ScalingFactors = Video->SF;
310 /* Set the Video Attributes */
311 XAVBuf_SetLiveVideoAttributes(InstancePtr, RegConfig,
315 case XAVBUF_VIDSTREAM2_LIVE_GFX:
316 RegConfig = XAVBUF_BUF_LIVE_GFX_CFG;
317 ScalingOffset = XAVBUF_BUF_LIVE_GFX_COMP0_SF;
318 LayerOffset = XAVBUF_V_BLEND_LAYER1_CONTROL;
319 CSCOffset = XAVBUF_V_BLEND_IN2CSC_COEFF0;
320 Video = InstancePtr->AVMode.LiveGraphics;
321 ScalingFactors = Video->SF;
323 /* Set the Video Attributes */
324 XAVBuf_SetLiveVideoAttributes(InstancePtr, RegConfig,
328 case XAVBUF_VIDSTREAM1_NONLIVE:
329 RegConfig = XAVBUF_BUF_LIVE_GFX_CFG;
330 ScalingOffset = XAVBUF_BUF_VID_COMP0_SCALE_FACTOR;
331 LayerOffset = XAVBUF_V_BLEND_LAYER0_CONTROL;
332 CSCOffset = XAVBUF_V_BLEND_IN1CSC_COEFF0;
333 Video = InstancePtr->AVMode.NonLiveVideo;
334 ScalingFactors = Video->SF;
336 /* Set the Video Attributes */
337 XAVBuf_SetNonLiveVideoAttributes(InstancePtr, VideoSrc,
341 case XAVBUF_VIDSTREAM2_NONLIVE_GFX:
342 RegConfig = XAVBUF_BUF_LIVE_GFX_CFG;
343 ScalingOffset = XAVBUF_BUF_GRAPHICS_COMP0_SCALE_FACTOR;
344 LayerOffset = XAVBUF_V_BLEND_LAYER1_CONTROL;
345 CSCOffset = XAVBUF_V_BLEND_IN2CSC_COEFF0;
346 Video = InstancePtr->AVMode.NonLiveGraphics;
347 ScalingFactors = Video->SF;
349 /* Set the Video Attributes */
350 XAVBuf_SetNonLiveVideoAttributes(InstancePtr, VideoSrc,
353 case XAVBUF_VIDSTREAM1_TPG:
355 XAVBUF_V_BLEND_LAYER0_CONTROL_RGB_MODE_SHIFT;
357 XAVBUF_V_BLEND_LAYER0_CONTROL_BYPASS_SHIFT;
358 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
359 XAVBUF_V_BLEND_LAYER0_CONTROL,
365 /* Setting the scaling factors */
366 XAVBuf_SetScalingFactors(InstancePtr, ScalingOffset, ScalingFactors);
368 XAVBuf_SetLayerControl(InstancePtr, LayerOffset, Video);
369 /* Colorspace conversion */
370 XAVBuf_InConvertToRGB(InstancePtr, CSCOffset, Video);
374 /******************************************************************************/
376 * This function intializes the configuration for the AVBuf Instance.
378 * @param InstancePtr is a pointer to the XAVBuf instance.
379 * @param BaseAddr sets the base address of the AVBuf instance
380 * @param Deviceid is the id of the device from the design.
384 * @note Base address and DeviceId is same as the DP Core driver.
386 *******************************************************************************/
387 void XAVBuf_CfgInitialize(XAVBuf *InstancePtr, u32 BaseAddr, u16 DeviceId)
389 Xil_AssertVoid(InstancePtr != NULL);
391 InstancePtr->Config.DeviceId = DeviceId;
392 InstancePtr->Config.BaseAddr = BaseAddr;
395 /******************************************************************************/
397 * This function initializes all the data structures of the XAVBuf Instance.
399 * @param InstancePtr is a pointer to the XAVBuf instance.
405 *******************************************************************************/
406 void XAVBuf_Initialize(XAVBuf *InstancePtr)
408 Xil_AssertVoid(InstancePtr != NULL);
410 InstancePtr->AVMode.NonLiveVideo = NULL;
411 InstancePtr->AVMode.LiveVideo = NULL;
412 InstancePtr->AVMode.LiveGraphics = NULL;
413 InstancePtr->AVMode.NonLiveGraphics = NULL;
414 InstancePtr->AVMode.VideoSrc = XAVBUF_VIDSTREAM1_NONE;
415 InstancePtr->AVMode.GraphicsSrc = XAVBUF_VIDSTREAM2_NONE;
416 InstancePtr->AVMode.Audio = NULL;
417 InstancePtr->AVMode.GraphicsAudio = NULL;
418 InstancePtr->AVMode.AudioSrc1 = XAVBUF_AUDSTREAM1_NO_AUDIO;
419 InstancePtr->AVMode.AudioSrc2 = XAVBUF_AUDSTREAM2_NO_AUDIO;
421 InstancePtr->Blender.GlobalAlphaEn = 0;
422 InstancePtr->Blender.Alpha = 0;
423 InstancePtr->Blender.OutputVideo = NULL;
425 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_AUD_SOFT_RST, 0);
428 /******************************************************************************/
430 * This function selects the source for the Video and Graphics streams that are
431 * passed on to the blender block.
433 * @param InstancePtr is a pointer to the XAVBuf instance.
434 * @param VidStream selects the stream coming from the video sources
435 * @param GfxStream selects the stream coming from the graphics sources
441 *******************************************************************************/
442 void XAVBuf_InputVideoSelect(XAVBuf *InstancePtr, XAVBuf_VideoStream VidStream,
443 XAVBuf_GfxStream GfxStream)
447 Xil_AssertVoid(InstancePtr != NULL);
448 Xil_AssertVoid((VidStream != XAVBUF_VIDSTREAM1_LIVE) |
449 (VidStream != XAVBUF_VIDSTREAM1_NONLIVE) |
450 (VidStream != XAVBUF_VIDSTREAM1_TPG) |
451 (VidStream != XAVBUF_VIDSTREAM1_NONE));
452 Xil_AssertVoid((GfxStream != XAVBUF_VIDSTREAM2_DISABLEGFX) |
453 (GfxStream != XAVBUF_VIDSTREAM2_NONLIVE_GFX) |
454 (GfxStream != XAVBUF_VIDSTREAM2_LIVE_GFX) |
455 (GfxStream != XAVBUF_VIDSTREAM2_NONE));
457 InstancePtr->AVMode.VideoSrc = VidStream;
458 InstancePtr->AVMode.GraphicsSrc = GfxStream;
460 RegVal = XAVBuf_ReadReg(InstancePtr->Config.BaseAddr,
461 XAVBUF_BUF_OUTPUT_AUD_VID_SELECT);
462 RegVal &= ~(XAVBUF_BUF_OUTPUT_AUD_VID_SELECT_VID_STREAM2_SEL_MASK |
463 XAVBUF_BUF_OUTPUT_AUD_VID_SELECT_VID_STREAM1_SEL_MASK);
464 RegVal |= VidStream | GfxStream;
465 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
466 XAVBUF_BUF_OUTPUT_AUD_VID_SELECT, RegVal);
469 /******************************************************************************/
471 * This function sets the video format for the non-live video
473 * @param InstancePtr is a pointer to the XAVBuf instance.
474 * @param Format is the enum for the non-live video format
476 * @return XST_SUCCESS if the correct format has been set.
477 * XST_FAILURE if the format is invalid.
480 *******************************************************************************/
481 int XAVBuf_SetInputNonLiveVideoFormat(XAVBuf *InstancePtr,
482 XAVBuf_VideoFormat Format)
484 Xil_AssertNonvoid(InstancePtr != NULL);
485 Xil_AssertNonvoid((Format >= CbY0CrY1) | (Format <= YV16Ci2_420_10BPC));
487 InstancePtr->AVMode.NonLiveVideo =
488 XAVBuf_GetNLiveVideoAttribute(Format);
489 if(InstancePtr->AVMode.NonLiveVideo == NULL)
495 /******************************************************************************/
497 * This function sets the graphics format for the non-live video
499 * @param InstancePtr is a pointer to the XAVBuf instance.
500 * @param Format is the enum for the non-live video format
502 * @return XST_SUCCESS if the correct format has been set.
503 * XST_FAILURE if the format is invalid.
506 *******************************************************************************/
507 int XAVBuf_SetInputNonLiveGraphicsFormat(XAVBuf *InstancePtr,
508 XAVBuf_VideoFormat Format)
510 Xil_AssertNonvoid(InstancePtr != NULL);
511 Xil_AssertNonvoid((Format >= RGBA8888) |( Format <= YOnly));
513 InstancePtr->AVMode.NonLiveGraphics =
514 XAVBuf_GetNLGraphicsAttribute(Format);
515 if(InstancePtr->AVMode.NonLiveGraphics == NULL)
521 /******************************************************************************/
523 * This function sets the video format for the live video
525 * @param InstancePtr is a pointer to the XAVBuf instance.
526 * @param Format is the enum for the non-live video format
528 * @return XST_SUCCESS if the correct format has been set.
529 * XST_FAILURE if the format is invalid.
532 *******************************************************************************/
533 int XAVBuf_SetInputLiveVideoFormat(XAVBuf *InstancePtr,
534 XAVBuf_VideoFormat Format)
536 Xil_AssertNonvoid(InstancePtr != NULL);
537 Xil_AssertNonvoid((Format >= RGB_6BPC) | (Format <= YOnly_12BPC));
539 InstancePtr->AVMode.LiveVideo = XAVBuf_GetLiveVideoAttribute(Format);
540 if(InstancePtr->AVMode.LiveVideo == NULL)
546 /******************************************************************************/
548 * This function sets the graphics format for the live video
550 * @param InstancePtr is a pointer to the XAVBuf instance.
551 * @param Format is the enum for the non-live video format
553 * @return XST_SUCCESS if the correct format has been set.
554 * XST_FAILURE if the format is invalid.
557 *******************************************************************************/
558 int XAVBuf_SetInputLiveGraphicsFormat(XAVBuf *InstancePtr,
559 XAVBuf_VideoFormat Format)
561 Xil_AssertNonvoid(InstancePtr != NULL);
562 Xil_AssertNonvoid((Format >= RGB_6BPC) | (Format <= YOnly_12BPC));
564 InstancePtr->AVMode.LiveGraphics =
565 XAVBuf_GetLiveVideoAttribute(Format);
566 if(InstancePtr->AVMode.LiveGraphics == NULL)
572 /******************************************************************************/
574 * This function sets the Output Video Format
576 * @param InstancePtr is a pointer to the XAVBuf instance.
577 * @param Format is the enum for the non-live video format
579 * @return XST_SUCCESS if the correct format has been set.
580 * XST_FAILURE if the format is invalid.
583 *******************************************************************************/
584 int XAVBuf_SetOutputVideoFormat(XAVBuf *InstancePtr, XAVBuf_VideoFormat Format)
586 Xil_AssertNonvoid(InstancePtr != NULL);
587 Xil_AssertNonvoid((Format >= RGB_6BPC) | (Format <= YOnly_12BPC));
589 InstancePtr->Blender.OutputVideo =
590 XAVBuf_GetLiveVideoAttribute(Format);
591 if(InstancePtr->Blender.OutputVideo == NULL)
597 /******************************************************************************/
599 * This function sets the Audio and Video Clock Source and the video timing
602 * @param InstancePtr is a pointer to the XAVBuf instance.
603 * @param VideoClk selects the Video Clock Source
604 * @param AudioClk selects the Audio Clock Source
608 * @note System uses PL Clock for Video when Live source is in use.
610 *******************************************************************************/
611 void XAVBuf_SetAudioVideoClkSrc(XAVBuf *InstancePtr, u8 VideoClk, u8 AudioClk)
616 Xil_AssertVoid(InstancePtr != NULL);
617 Xil_AssertVoid((VideoClk != XAVBUF_PS_CLK) |
618 (VideoClk!= XAVBUF_PL_CLK));
619 Xil_AssertVoid((AudioClk != XAVBUF_PS_CLK) |
620 (AudioClk!= XAVBUF_PL_CLK));
622 if((InstancePtr->AVMode.VideoSrc != XAVBUF_VIDSTREAM1_LIVE) &&
623 (InstancePtr->AVMode.GraphicsSrc != XAVBUF_VIDSTREAM2_LIVE_GFX)) {
625 XAVBUF_BUF_AUD_VID_CLK_SOURCE_VID_TIMING_SRC_SHIFT;
627 else if((InstancePtr->AVMode.VideoSrc == XAVBUF_VIDSTREAM1_LIVE) ||
628 (InstancePtr->AVMode.GraphicsSrc ==
629 XAVBUF_VIDSTREAM2_LIVE_GFX)) {
630 VideoClk = XAVBUF_PL_CLK;
633 RegVal |= (VideoClk <<
634 XAVBUF_BUF_AUD_VID_CLK_SOURCE_VID_CLK_SRC_SHIFT) |
636 XAVBUF_BUF_AUD_VID_CLK_SOURCE_AUD_CLK_SRC_SHIFT);
637 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
638 XAVBUF_BUF_AUD_VID_CLK_SOURCE, RegVal);
639 /*Soft Reset VideoPipeline when changing the clock source*/
640 XAVBuf_SoftReset(InstancePtr);
643 /******************************************************************************/
645 * This function applies a soft reset to the Audio Video pipeline.
647 * @param InstancePtr is a pointer to the XAVBuf instance.
653 *******************************************************************************/
654 void XAVBuf_SoftReset(XAVBuf *InstancePtr)
656 Xil_AssertVoid(InstancePtr != NULL);
658 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_BUF_SRST_REG,
659 XAVBUF_BUF_SRST_REG_VID_RST_MASK);
660 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_BUF_SRST_REG, 0);
663 /******************************************************************************/
665 * This function looks up if the video format is valid or not for the non-live
666 * video datapath and returns a pointer to the attributes of the video.
668 * @param Format takes in the video format for which attributes are being
671 * @return A pointer to the structure XAVBuf_VideoAttribute if the video
672 * format is valid, else returns NULL.
674 *******************************************************************************/
675 XAVBuf_VideoAttribute *XAVBuf_GetLiveVideoAttribute(XAVBuf_VideoFormat Format)
678 XAVBuf_VideoAttribute *VideoAttribute;
679 Xil_AssertNonvoid((Format >= RGB_6BPC) | (Format <= YOnly_12BPC));
681 for (Index = RGB_6BPC; Index <= YOnly_12BPC; Index++) {
682 VideoAttribute = (XAVBuf_VideoAttribute *)
683 &XAVBuf_SupportedFormats[Index];
684 if(Format == VideoAttribute->VideoFormat) {
685 return VideoAttribute;
691 /******************************************************************************/
693 * This function looks up if the video format is valid or not and returns a
694 * pointer to the attributes of the video.
696 * @param Format takes in the video format for which attributes are being
699 * @return A pointer to the structure XAVBuf_VideoAttribute if the video
700 * format is valid, else returns NULL.
702 *******************************************************************************/
703 XAVBuf_VideoAttribute *XAVBuf_GetNLiveVideoAttribute(XAVBuf_VideoFormat Format)
706 XAVBuf_VideoAttribute *VideoAttribute;
708 Xil_AssertNonvoid((Format >= CbY0CrY1) | (Format <= YV16Ci2_420_10BPC));
710 for (Index = CbY0CrY1; Index <= YV16Ci2_420_10BPC; Index++) {
711 VideoAttribute = (XAVBuf_VideoAttribute *)
712 &XAVBuf_SupportedFormats[Index];
713 if(Format == VideoAttribute->VideoFormat) {
714 return VideoAttribute;
720 /******************************************************************************/
722 * This function looks up if the video format is valid or not and returns a
723 * pointer to the attributes of the video.
725 * @param Format takes in the video format for which attributes are being
728 * @return A pointer to the structure XAVBuf_VideoAttribute if the video
729 * format is valid, else returns NULL.
731 *******************************************************************************/
732 XAVBuf_VideoAttribute *XAVBuf_GetNLGraphicsAttribute(XAVBuf_VideoFormat Format)
735 XAVBuf_VideoAttribute *VideoAttribute;
737 Xil_AssertNonvoid((Format >= RGBA8888) | (Format <= YOnly));
739 for(Index = RGBA8888; Index <= YOnly; Index++) {
740 VideoAttribute = (XAVBuf_VideoAttribute *)
741 &XAVBuf_SupportedFormats[Index];
742 if(Format == VideoAttribute->VideoFormat) {
743 return VideoAttribute;
749 /******************************************************************************/
751 * This function configures the Video Pipeline
753 * @param InstancePtr is an pointer to the XAVBuf Instance.
758 ******************************************************************************/
759 void XAVBuf_ConfigureVideoPipeline(XAVBuf *InstancePtr)
761 Xil_AssertVoid(InstancePtr != NULL);
763 XAVBuf_ConfigureVideo(InstancePtr, InstancePtr->AVMode.VideoSrc);
766 /******************************************************************************/
768 * This function configures the Graphics Pipeline
770 * @param InstancePtr is an pointer to the XAVBuf Instance.
775 ******************************************************************************/
776 void XAVBuf_ConfigureGraphicsPipeline(XAVBuf *InstancePtr)
778 Xil_AssertVoid(InstancePtr != NULL);
779 XAVBuf_ConfigureVideo(InstancePtr, InstancePtr->AVMode.GraphicsSrc);
782 /******************************************************************************/
784 * This function sets the blender background color
786 * @param InstancePtr is an pointer to the XAVBuf Instance.
787 * @param Color is a pointer to the structure XAVBuf_BlenderBgClr
792 ******************************************************************************/
793 void XAVBuf_BlendSetBgColor(XAVBuf *InstancePtr, XAVBuf_BlenderBgClr *Color)
795 Xil_AssertVoid(InstancePtr != NULL);
796 Xil_AssertVoid(Color != NULL);
798 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_V_BLEND_BG_CLR_0,
800 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_V_BLEND_BG_CLR_1,
802 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_V_BLEND_BG_CLR_2,
806 /******************************************************************************/
808 * This function enables or disables global alpha
810 * @param InstancePtr is an pointer to the XAVBuf Instance.
811 * @param Enable sets a software flag for global alpha
812 * @param Alpha sets the value for the global alpha blending
816 * @note GlobalAlphaEn = 1, enables the global alpha.
817 * GlobalAlphaEn = 0, disables the global alpha.
818 * Alpha = 0, passes stream2
819 * Alpha = 255, passes stream1
820 ******************************************************************************/
821 void XAVBuf_SetBlenderAlpha(XAVBuf *InstancePtr, u8 Alpha, u8 Enable)
824 Xil_AssertVoid(InstancePtr != NULL);
825 Xil_AssertVoid((Enable !=0) | (Enable != 1));
827 InstancePtr->Blender.GlobalAlphaEn = Enable;
828 InstancePtr->Blender.Alpha = Alpha;
831 RegVal |= Alpha << XAVBUF_V_BLEND_SET_GLOBAL_ALPHA_REG_VALUE_SHIFT;
833 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
834 XAVBUF_V_BLEND_SET_GLOBAL_ALPHA_REG, RegVal);
837 /******************************************************************************/
839 * This function configures the Output of the Video Pipeline
841 * @param InstancePtr is an pointer to the XAVBuf Instance.
842 * @param OutputVideo is a pointer to the XAVBuf_VideoAttribute.
847 ******************************************************************************/
848 void XAVBuf_ConfigureOutputVideo(XAVBuf *InstancePtr)
851 XAVBuf_VideoAttribute *OutputVideo = InstancePtr->Blender.OutputVideo;
853 RegVal |= OutputVideo->SamplingEn <<
854 XAVBUF_V_BLEND_OUTPUT_VID_FORMAT_EN_DOWNSAMPLE_SHIFT;
855 RegVal |= OutputVideo->Value;
856 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
857 XAVBUF_V_BLEND_OUTPUT_VID_FORMAT, RegVal);
859 XAVBuf_InConvertToOutputFormat(InstancePtr, OutputVideo);
862 /******************************************************************************/
864 * This function selects the source for audio streams corresponding to the
865 * Video and Graphics streams that are passed on to the blender
867 * @param InstancePtr is a pointer to the XAVBuf instance.
868 * @param AudStream1 selects the audio stream source corresponding to
869 * the video source selected
870 * @param AudStream2 selects the audio stream source corresponding to
871 * the graphics source selected.
877 *******************************************************************************/
878 void XAVBuf_InputAudioSelect(XAVBuf *InstancePtr, XAVBuf_AudioStream1 AudStream1,
879 XAVBuf_AudioStream2 AudStream2)
881 Xil_AssertVoid(InstancePtr != NULL);
882 Xil_AssertVoid((AudStream1 != XAVBUF_AUDSTREAM1_NONLIVE) |
883 (AudStream1 != XAVBUF_AUDSTREAM1_LIVE) |
884 (AudStream1 != XAVBUF_AUDSTREAM1_TPG));
885 Xil_AssertVoid((AudStream2 != XAVBUF_AUDSTREAM2_NO_AUDIO) |
886 (AudStream2 != XAVBUF_AUDSTREAM2_AUDIOGFX));
889 RegVal = XAVBuf_ReadReg(InstancePtr->Config.BaseAddr,
890 XAVBUF_BUF_OUTPUT_AUD_VID_SELECT);
891 RegVal &= ~(XAVBUF_BUF_OUTPUT_AUD_VID_SELECT_AUD_STREAM2_SEL_MASK |
892 XAVBUF_BUF_OUTPUT_AUD_VID_SELECT_AUD_STREAM1_SEL_MASK);
893 RegVal |= AudStream1 | AudStream2;
895 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
896 XAVBUF_BUF_OUTPUT_AUD_VID_SELECT, RegVal);
899 /******************************************************************************/
901 * This function sets up the scaling factor for Audio Mixer Volume Control.
903 * @param InstancePtr is a pointer to the XAVBuf instance.
904 * @param Channel0Volume is the volume to be set for Audio from Channel0
905 * @param Channel1Volume is the volume to be set for Audio from Channel1
912 *******************************************************************************/
913 void XAVBuf_AudioMixerVolumeControl(XAVBuf *InstancePtr, u8 Channel0Volume,
917 Xil_AssertVoid(InstancePtr != NULL);
918 Val = Channel1Volume <<
919 XAVBUF_AUD_MIXER_VOLUME_CONTROL_VOL_CTRL_CH1_SHIFT;
920 Val |= Channel0Volume;
921 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
922 XAVBUF_AUD_MIXER_VOLUME_CONTROL, Val);
925 /******************************************************************************/
927 * This function resets the Audio Pipe.
929 * @param InstancePtr is a pointer to the XAVBuf Instance.
933 * @note Needed when non-live audio is disabled.
936 ******************************************************************************/
937 void XAVBuf_AudioSoftReset(XAVBuf *InstancePtr)
940 Xil_AssertVoid(InstancePtr != NULL);
941 RegVal = XAVBuf_ReadReg(InstancePtr->Config.BaseAddr,
942 XAVBUF_AUD_SOFT_RST);
943 RegVal |= XAVBUF_AUD_SOFT_RST_AUD_SRST_MASK;
944 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_AUD_SOFT_RST,
946 RegVal &= ~XAVBUF_AUD_SOFT_RST_AUD_SRST_MASK;
947 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_AUD_SOFT_RST, 0);
951 /******************************************************************************/
953 * This function enables End of Line Reset for reduced blanking resolutions.
955 * @param InstancePtr is a pointer to the XAVBuf Instance.
956 * @param Disable is to be set while using Reduced Blanking Resolutions.
962 ******************************************************************************/
963 void XABuf_LineResetDisable(XAVBuf *InstancePtr, u8 Disable)
966 Xil_AssertVoid(InstancePtr != NULL);
967 RegVal = XAVBuf_ReadReg(InstancePtr->Config.BaseAddr,
968 XAVBUF_AUD_SOFT_RST);
970 RegVal |= XAVBUF_AUD_SOFT_RST_LINE_RST_DISABLE_MASK;
972 RegVal &= ~XAVBUF_AUD_SOFT_RST_LINE_RST_DISABLE_MASK;
974 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_AUD_SOFT_RST,
978 /******************************************************************************/
980 * This function enables the video channel interface between the DPDMA and the
983 * @param InstancePtr is a pointer to the XAVBuf Instance.
984 * @param Enable sets the corresponding buffers.
990 ******************************************************************************/
991 void XAVBuf_EnableVideoBuffers(XAVBuf *InstancePtr, u8 Enable)
995 u8 NumPlanes = InstancePtr->AVMode.NonLiveVideo->Mode;
997 RegVal = (0xF << XAVBUF_CHBUF0_BURST_LEN_SHIFT) |
998 (XAVBUF_CHBUF0_FLUSH_MASK);
1000 for (Index = 0; Index <= NumPlanes; Index++) {
1001 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
1002 XAVBUF_CHBUF0 + (Index * 4), RegVal);
1005 RegVal = (0xF << XAVBUF_CHBUF0_BURST_LEN_SHIFT) |
1006 XAVBUF_CHBUF0_EN_MASK;
1007 for (Index = 0; Index <= NumPlanes; Index++) {
1008 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr,
1009 XAVBUF_CHBUF0 + (Index * 4), RegVal);
1013 /******************************************************************************/
1015 * This function enables the graphics interface between the DPDMA and the AVBuf.
1017 * @param InstancePtr is a pointer to the XAVBuf Instance.
1018 * @param Enable sets the corresponding buffers.
1024 ******************************************************************************/
1025 void XAVBuf_EnableGraphicsBuffers(XAVBuf *InstancePtr, u8 Enable)
1029 RegVal = (0xF << XAVBUF_CHBUF3_BURST_LEN_SHIFT) |
1030 XAVBUF_CHBUF3_FLUSH_MASK;
1031 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_CHBUF3, RegVal);
1033 RegVal = (0xF << XAVBUF_CHBUF3_BURST_LEN_SHIFT) |
1034 XAVBUF_CHBUF0_EN_MASK;
1035 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_CHBUF3,
1040 /******************************************************************************/
1042 * This function enables the audio interface between the DPDMA and the AVBuf
1044 * @param InstancePtr is a pointer to the XAVBuf Instance.
1045 * @param Enable sets the corresponding buffers.
1051 ******************************************************************************/
1052 void XAVBuf_EnableAudio0Buffers(XAVBuf *InstancePtr, u8 Enable)
1056 RegVal = (0x3 << XAVBUF_CHBUF4_BURST_LEN_SHIFT) |
1057 XAVBUF_CHBUF4_FLUSH_MASK;
1058 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_CHBUF4, RegVal);
1060 RegVal = (0x3 << XAVBUF_CHBUF4_BURST_LEN_SHIFT) |
1061 XAVBUF_CHBUF4_EN_MASK;
1062 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_CHBUF4,
1067 /******************************************************************************/
1069 * This function enables the audio interface between the DPDMA and the AVBuf
1071 * @param InstancePtr is a pointer to the XAVBuf Instance.
1072 * @param Enable sets the corresponding buffers.
1078 ******************************************************************************/
1079 void XAVBuf_EnableAudio1Buffers(XAVBuf *InstancePtr, u8 Enable)
1083 RegVal = (0x3 << XAVBUF_CHBUF5_BURST_LEN_SHIFT) |
1084 XAVBUF_CHBUF5_FLUSH_MASK;
1085 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_CHBUF5, RegVal);
1087 RegVal = (0x3 << XAVBUF_CHBUF5_BURST_LEN_SHIFT) |
1088 XAVBUF_CHBUF5_EN_MASK;
1089 XAVBuf_WriteReg(InstancePtr->Config.BaseAddr, XAVBUF_CHBUF5,