source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/hdm/7552/bhdm_packet.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 49.7 KB
Line 
1/***************************************************************************
2*         (c)2004-2010 Broadcom Corporation
3*
4*  This program is the proprietary software of Broadcom Corporation and/or its licensors,
5*  and may only be used, duplicated, modified or distributed pursuant to the terms and
6*  conditions of a separate, written license agreement executed between you and Broadcom
7*  (an "Authorized License").  Except as set forth in an Authorized License, Broadcom grants
8*  no license (express or implied), right to use, or waiver of any kind with respect to the
9*  Software, and Broadcom expressly reserves all rights in and to the Software and all
10*  intellectual property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU
11*  HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY
12*  NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
13*
14*  Except as expressly set forth in the Authorized License,
15*
16*  1.     This program, including its structure, sequence and organization, constitutes the valuable trade
17*  secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof,
18*  and to use this information only in connection with your use of Broadcom integrated circuit products.
19*
20*  2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
21*  AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
22*  WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
23*  THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES
24*  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE,
25*  LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION
26*  OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF
27*  USE OR PERFORMANCE OF THE SOFTWARE.
28*
29*  3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
30*  LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR
31*  EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR
32*  USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF
33*  THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT
34*  ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
35*  LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF
36*  ANY LIMITED REMEDY.
37 *
38 * $brcm_Workfile: bhdm_packet.c $
39 * $brcm_Revision: Hydra_Software_Devel/25 $
40 * $brcm_Date: 3/6/12 6:37p $
41 *
42 * Module Description:
43 *
44 * Revision History:
45 *
46 * $brcm_Log: /magnum/portinginterface/hdm/7038/bhdm_packet.c $
47 *
48 * Hydra_Software_Devel/25   3/6/12 6:37p rgreen
49 * SW7425-2572: Set AVI Infoframe to <No Data> when unknown aspect ratio
50 * is Set.  Do not report uncompatible with HDMI message
51 *
52 * Hydra_Software_Devel/24   3/2/12 10:07a rgreen
53 * SW7408-320: Fix bug introduced by clearing AudioInfoFrame argument in
54 * BHDM_SetAudioInfoFrame.  Argument can be same as internally stored
55 * AudioInfoFrame.  See  BHDM_EnableDisplay.  Fix same issue for VSI
56 * packet.
57 *
58 * Hydra_Software_Devel/23   2/21/12 10:20a rgreen
59 * SW7408-320: Merge Changes
60 *
61 * Hydra_Software_Devel/SW7408-320/3   2/21/12 9:53a rgreen
62 * SW7408-320: Bound extended colorimetry feature with HDMI 1.3 macro
63 *
64 * Hydra_Software_Devel/SW7408-320/2   2/20/12 3:34p rgreen
65 * SW7408-320: Clear bOverrideDefaults flag after each use;  Caller must
66 * specify each instance that settings must be overrwritten
67 *
68 * Hydra_Software_Devel/SW7408-320/1   2/20/12 1:20p rgreen
69 * SW7408-320:  Fix Set AVI InfoFrame to correctly update/keep all fields;
70 * Ensure Get/Set calls initalize packets to 0.
71 *
72 * Hydra_Software_Devel/21   1/4/12 3:31p rgreen
73 * SW7405-5004: Use BAVC_HDMI_xxx macros when copying InfoFrame contents.;
74 * Add debug info packet transmission.
75 *
76 * Hydra_Software_Devel/20   11/2/11 1:18p vle
77 * SW7420-2117: Save VSI settings in all cases.
78 *
79 * Hydra_Software_Devel/19   10/21/11 4:49p rgreen
80 * SW7125-1128,SW7422-114: Initialize all RAM Packets to NULL Packets
81 *
82 * Hydra_Software_Devel/18   9/15/11 4:27p rgreen
83 * SW7425-1296: Fix bug with SPD Infoframe description length
84 *
85 * Hydra_Software_Devel/17   8/4/11 2:36p vle
86 * SW7422-464: fix typo
87 *
88 * Hydra_Software_Devel/16   8/4/11 12:19p vle
89 * SW7422-464: Save the VendorSpecificInfoFrame when setting it.
90 *
91 * Hydra_Software_Devel/15   8/3/11 1:06p rgreen
92 * SW7422-461:   Add packet type, version, and length to the printed debug
93 * information
94 *
95 * Hydra_Software_Devel/14   7/20/11 12:30p vle
96 * SW7422-461: Fix incorrect VendorSpecificInfoFrame generated for non-3D
97 * formats
98 *
99 * Hydra_Software_Devel/13   4/11/11 3:37p rgreen
100 * SW7420-579: Remove warnings when dEBUG_AVI_INFOFRAME is set.
101 *
102 * Hydra_Software_Devel/12   2/17/11 5:53p vle
103 * SW7420-1289: Merge to mainline
104 *
105 * Hydra_Software_Devel/SW7420-1289/2   2/17/11 10:02a vle
106 * SW7420-1289: Add NEXUS APIs to get/set HDMI AVI InfoFrame, HDMI Audio
107 * Infoframe. Share structures for hdmi_input and hdmi_output
108 *
109 * Hydra_Software_Devel/SW7420-1289/1   1/27/11 2:35p vle
110 * SW7420-1289: Add NEXUS APIs to get/set HDMI AVI InfoFrame, HDMI Audio
111 * Infoframe
112 *
113 * Hydra_Software_Devel/11   1/17/11 7:12p vle
114 * SW7405-5094: Fix error in forming Vendor Specific InfoFrame which
115 * causes HDMI compliance test failure on test 7-38
116 *
117 * Hydra_Software_Devel/10   10/7/10 7:36p jtna
118 * SW7420-972: BHDM_P_WritePacket requires BHCP_PWR_Acquire/Release
119 *
120 * Hydra_Software_Devel/9   9/21/10 7:28p rgreen
121 * SW7420-737,SW7125-537: Fix Audio InfoFrame Channel Count  Update debug
122 * messages for Audio InfoFrame
123 *
124 * Hydra_Software_Devel/8   5/13/10 5:18p vle
125 * SW7420-579: Fix build error if enable DEBUG_AVI_INFOFRAME debug build.
126 *
127 * Hydra_Software_Devel/7   4/15/10 6:59p rgreen
128 * SW7405-3997:: Update debug display info for VSI
129 *
130 * Hydra_Software_Devel/6   4/14/10 7:19p rgreen
131 * SW7405-3997: Fix creation of IEEE RegID for VSI transmission: SW7405-
132 * 3997:
133 *
134 * Hydra_Software_Devel/5   4/5/10 4:58p rgreen
135 * SW7405-3997:Merge changes for debug messages
136 *
137 * Hydra_Software_Devel/SW7401-4363/1   4/5/10 4:56p rgreen
138 * SW7405-3997:Use debug messages in addition to enums to indicate the VSI
139 * information sent
140 *
141 * Hydra_Software_Devel/4   4/2/10 6:40p vle
142 * SW7601-172: Rename to clearly indicate SetGamutMetadataPacket is a
143 * private API.
144 *
145 * Hydra_Software_Devel/3   4/2/10 5:31p rgreen
146 * SW7405-3994,SW7405-3997: Report required 3D Structure vs 3D optional
147 * Ext Data when sending 3D info
148 *
149 * Hydra_Software_Devel/2   3/26/10 4:34p vle
150 * SW7601-172: Merge xvYCC support with Gamut Metadata Packet transmission
151 * from bdvd branch
152 *
153 * Hydra_Software_Devel/1   2/23/10 12:41a vle
154 * SW7420-579: Refactor HDMI PI code.
155 *
156 ***************************************************************************/
157
158#include "bstd.h"
159#include "bhdm.h"
160#include "bhdm_priv.h"
161#include "bavc_hdmi.h"
162
163#if BCHP_PWR_SUPPORT
164#include "bchp_pwr.h"
165#endif
166
167BDBG_MODULE(BHDM_PACKET) ;
168
169#define BHDM_CHECK_RC( rc, func )                         \
170do                                                                                                \
171{                                                                                                 \
172        if( (rc = BERR_TRACE(func)) != BERR_SUCCESS ) \
173        {                                                                                         \
174                goto done;                                                                \
175        }                                                                                         \
176} while(0)
177
178
179#define BHDM_P_WORDS_PER_RAM_PACKET 9
180#define BHDM_P_NUM_CONFIGURABLE_RAM_PACKETS 14
181       
182#define BHDM_REFER_TO_STREAM_HEADER 0
183       
184static const uint16_t BHDM_Packet_AVIFrameType    = 0x82 ; 
185static const uint8_t  BHDM_Packet_AVIFrameVersion = 0x02 ;
186static const uint8_t  BHDM_Packet_AVIFrameLength  = 0x0D ;
187
188static const uint16_t BHDM_Packet_SPDFrameType    = 0x83 ;
189static const uint8_t  BHDM_Packet_SPDFrameVersion = 0x01 ;
190static const uint8_t  BHDM_Packet_SPDFrameLength  = 25  ;
191
192static const uint16_t BHDM_Packet_AudioFrameType        = 0x84 ; 
193static const uint8_t  BHDM_Packet_AudioFrameVersion = 0x01 ;
194static const uint8_t  BHDM_Packet_AudioFrameLength      = 0x0A ;
195
196
197#if BHDM_CONFIG_HDMI_1_3_SUPPORT
198/*
199 * As per Chris Pasqualino:
200 * ========================
201 * This GBD specification based on GBD format 1, 12-bit data, defined as an RGB expression
202 * of xvYCC709 coordinates.  This profile provides the min/max non-gamma corrected limited
203 * range RGB values in the transmitted stream.   
204 *
205 * Header Byte 1 = 0x81 = 1_000_0001b:
206 *      Affected_Gamut_Seq_Num = 1      This is the first gamut provided
207 *      GBD_profile = 0                 P0 Profile
208 *      Next_Field = 1                  This GBD data applies to the next field
209 *
210 * Header Byte 2 = 0x31 = 0_0_11_0001b:
211 *      Current_Gamut_Seq_Num = 1       This gamut number being transmitted.
212 *      Packet_Seq = 3                  The only packet in the sequence
213 *      No_Current_GBD = 0              A GBD is applicable to next video field.
214 *
215 * From the header, we know this is a profile 0 GBD.  This is important because it means
216 * that there are no length parameters stored in the subpacket data. Thus, the MSB of the
217 * first byte in subpacket 0 indicates the format of the remainder of the packet.
218 *
219 * Subpacket 0, Byte 0 = 0x92 = 1_0_0_10_010b:
220 *      Format_Flag = 1                 GBD data is a range description
221 *      GBD_Color_Precision = 2         12-bit precision on GBD data
222 *      GBD_Color_Space = 2     RGB Expression of xvYCC709 coordinates
223 *
224 * The HDMI spec states in section E.4 that for Format_Flag = 1, the Packet_Range_Data
225 * shall be stored in the following order:
226 *      Min_Red_Data
227 *      Max_Red_Data
228 *      Min_Green_Data
229 *      Max_Green_Data
230 *      Min_Blue_Data
231 *      Max_Blue_Data
232 */
233static const uint8_t BHDM_Packet_GamutMetadataType = 0x0A ; 
234static const uint8_t BHDM_Packet_GamutMetadataHB1  = 0x81 ;
235static const uint8_t BHDM_Packet_GamutMetadataHB2  = 0x31 ;
236static const uint8_t BHDM_Packet_GamutMetadataSubPkt[] = {
237                0x92, 0x9B, 0x52, 0xF4, 0x8D, 
238                0x72, 0x96, 0x8C, 0xC2, 0x92
239};
240#endif
241
242/***************************************************************************
243BHDM_P_InitializePacketRAM
244Summary: Configure/Initialize the Packet RAM with NULL Packets
245****************************************************************************/
246BERR_Code BHDM_InitializePacketRAM(
247   BHDM_Handle hHDMI              /* [in] HDMI handle */
248) 
249{
250        BERR_Code       rc = BERR_SUCCESS;
251        uint32_t        Register ;
252        uint32_t RegAddr ;
253        uint8_t Packet ;
254       
255        /*CP*  13 Enable/Configure RAM Packets - HDMI_TODO Add PUBLIC FUNCTION(s)??? */ 
256       
257        /* This will configure a NULL packet for sending. 
258           This is just to get things up and running. */
259
260        /* set   RAM_ENABLE  */
261        /* set   ACTIVE_RAM_PACKETS = 14'd1   - Enable RAM Packet 0 */
262
263
264        /* Zero (NULL) out all RAM Packets */
265        for (Packet = 0 ; Packet < BHDM_P_NUM_CONFIGURABLE_RAM_PACKETS; Packet++)
266        {
267                for (Register = 0 ; Register < BHDM_P_WORDS_PER_RAM_PACKET ; Register++)
268                {
269                        RegAddr = BCHP_HDMI_RAM_GCP_0
270                                + Packet * BHDM_P_WORDS_PER_RAM_PACKET * 4 
271                                + Register * 4 ;
272                       
273                        BREG_Write32(hHDMI->hRegister, RegAddr, (uint32_t) 0) ;
274                }
275        }
276
277        /* Enable the Packet Ram */
278        Register = BREG_Read32(hHDMI->hRegister, BCHP_HDMI_RAM_PACKET_CONFIG) ;
279        Register |= BCHP_FIELD_DATA(HDMI_RAM_PACKET_CONFIG, RAM_ENABLE, 1) ;
280        BREG_Write32(hHDMI->hRegister, BCHP_HDMI_RAM_PACKET_CONFIG,  Register) ;
281
282        return rc ;
283}
284
285
286BERR_Code BHDM_EnablePacketTransmission(
287   BHDM_Handle hHDMI,              /* [in] HDMI handle */
288   BHDM_Packet PacketId)
289{
290        BERR_Code          rc = BERR_SUCCESS ;
291        uint32_t Register ;
292        uint32_t XmitPacketN ;
293        uint8_t timeoutMs ;
294       
295        /* set the transmission bit */
296        Register = BREG_Read32(hHDMI->hRegister, BCHP_HDMI_RAM_PACKET_CONFIG) ;
297        Register |= 1 << (uint8_t) PacketId ;
298        BREG_Write32(hHDMI->hRegister, BCHP_HDMI_RAM_PACKET_CONFIG, Register) ;
299       
300        /* wait until RAM Packet Status starts transmitting (RAM_PACKET_X = 0) */
301        timeoutMs = 10 ;
302        do
303        {
304                Register = BREG_Read32(hHDMI->hRegister, BCHP_HDMI_RAM_PACKET_STATUS) ;
305                XmitPacketN = Register & (1 << (uint8_t) PacketId) ;
306                if (XmitPacketN)
307                        break ;
308
309                BDBG_MSG(("Attempting start of RAM PACKET %d transmission", (uint8_t) PacketId)) ;
310                BKNI_Sleep(1) ;
311        } while ( timeoutMs-- ) ;
312
313        if (!XmitPacketN)
314        {
315                BDBG_ERR(("Timeout Error starting RAM PACKET %d transmission", (uint8_t) PacketId)) ;
316                rc = BERR_TIMEOUT ;
317                goto done ;
318        }
319
320done:
321        return rc ;
322}       
323
324
325
326BERR_Code BHDM_DisablePacketTransmission(
327   BHDM_Handle hHDMI,              /* [in] HDMI handle */
328   BHDM_Packet PacketId)
329{
330        BERR_Code          rc = BERR_SUCCESS ;
331        uint32_t Register ;
332        uint32_t XmitPacketN ;
333        uint8_t timeoutMs ;
334
335        /* clear the transmission bit */
336        Register = BREG_Read32(hHDMI->hRegister, BCHP_HDMI_RAM_PACKET_CONFIG) ;
337        Register &= ~(1 << (uint8_t) PacketId) ;
338        BREG_Write32(hHDMI->hRegister, BCHP_HDMI_RAM_PACKET_CONFIG, Register) ;
339       
340        /* wait until RAM Packet Status stops transmitting (RAM_PACKET_X = 0) */
341        timeoutMs = 10 ;
342        do
343        {
344                Register = BREG_Read32(hHDMI->hRegister, BCHP_HDMI_RAM_PACKET_STATUS) ;
345                XmitPacketN = Register & (1 << (uint8_t) PacketId) ;
346                if (!XmitPacketN)
347                        break ;
348
349                BDBG_MSG(("Attempting stop of RAM PACKET %d transmission", (uint8_t) PacketId)) ;
350                BKNI_Sleep(1) ;
351        } while ( timeoutMs-- ) ;
352
353        if (XmitPacketN)
354        {
355                BDBG_ERR(("Timeout Error stopping RAM PACKET %d transmission", (uint8_t) PacketId)) ;
356                rc = BERR_TIMEOUT ;
357                goto done ;
358        }
359       
360done:
361        return rc ;
362}       
363
364
365
366BERR_Code BHDM_P_WritePacket(
367        BHDM_Handle hHDMI, BHDM_Packet PhysicalHdmiRamPacketId,
368        uint8_t PacketType, uint8_t PacketVersion, uint8_t PacketLength, 
369        uint8_t *PacketBytes) 
370{
371        BERR_Code          rc = BERR_SUCCESS ;
372        uint32_t Register ; 
373       
374        uint32_t PacketRegisterOffset ;
375        uint32_t checksum ;
376        uint8_t i ;
377
378
379        /* zero out the unused packet bytes */
380        for (i = PacketLength + 1 ; i < BHDM_NUM_PACKET_BYTES; i++)
381                PacketBytes[i] = 0 ;
382
383        /* calculate Packet Checksum only on CEA-861 InfoFrame Packets */
384        if (PacketType > BHDM_INFOFRAME_PACKET_TYPE)
385        {
386                /* calculate checksum */                       
387                checksum = 0 ;
388                checksum = PacketType + PacketVersion + PacketLength ;
389                for (i = 1 ; i <= PacketLength ; i++)
390                        checksum = checksum + PacketBytes[i] ;
391       
392                PacketBytes[0] = 256 - (uint8_t) (checksum % 256)  ;
393#if BHDM_CONFIG_DEBUG_HDMI_PACKETS             
394                BDBG_MSG(("Infoframe Checksum Byte: %#X", PacketBytes[0])) ;
395#endif 
396        }
397        else
398        {
399                /* do not modify PB0; may be used for some other purpose */
400                BDBG_WRN(("Writing non-Infoframe Packet Type %#x", PacketType)) ;
401        }
402
403#ifdef BCHP_PWR_RESOURCE_HDMI_TX
404        BCHP_PWR_AcquireResource(hHDMI->hChip, BCHP_PWR_RESOURCE_HDMI_TX);
405#endif
406        /* disable transmission of the RAM Packet */
407        BHDM_CHECK_RC(rc, BHDM_DisablePacketTransmission(hHDMI, PhysicalHdmiRamPacketId)) ;
408
409       
410        /* calculate the offset of where the RAM for Packet ID begins */               
411        PacketRegisterOffset = 
412                   BCHP_HDMI_RAM_GCP_0
413                + BHDM_P_WORDS_PER_RAM_PACKET * 4 * PhysicalHdmiRamPacketId ;
414       
415        /* create/write the header use HDMI_RAM_PACKET_1_0 for Register field names */
416        Register = BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_0, HEADER_BYTE_0, PacketType) 
417                         | BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_0, HEADER_BYTE_1, PacketVersion)
418                         | BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_0, HEADER_BYTE_2, PacketLength) ;
419        BREG_Write32(hHDMI->hRegister, PacketRegisterOffset, Register) ;
420       
421#if BHDM_CONFIG_DEBUG_HDMI_PACKETS             
422        BDBG_MSG(("Packet Type %#X Packet %d Loading...", 
423                PacketType, PhysicalHdmiRamPacketId)) ;
424        BDBG_MSG(("Addr [%#x] = %x", PacketRegisterOffset, Register)) ;
425#endif 
426       
427        /* load the Packet Bytes */
428        for (i = 0 ; i < BHDM_NUM_PACKET_BYTES; i = i + 7)
429        {
430                PacketRegisterOffset += 4 ;
431               
432                /* create/write the subpacket data use HDMI_RAM_PACKET_1_1 for Register field names */
433                Register = 
434                          BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_1, SUBPACKET_1_BYTE_0, PacketBytes[i]) 
435                        | BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_1, SUBPACKET_1_BYTE_1, PacketBytes[i+1]) 
436                        | BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_1, SUBPACKET_1_BYTE_2, PacketBytes[i+2]) 
437                        | BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_1, SUBPACKET_1_BYTE_3, PacketBytes[i+3]) ;
438                BREG_Write32(hHDMI->hRegister, PacketRegisterOffset, Register) ;
439#if BHDM_CONFIG_DEBUG_HDMI_PACKETS             
440                BDBG_MSG(("Addr [%#x] = %#x", PacketRegisterOffset, Register)) ;
441#endif         
442               
443                PacketRegisterOffset += 4 ;
444               
445                /* create/write the subpacket data use HDMI_RAM_PACKET_1_1 for Register field names */
446                Register = 
447                          BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_2, SUBPACKET_1_BYTE_4, PacketBytes[i+4]) 
448                        | BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_2, SUBPACKET_1_BYTE_5, PacketBytes[i+5]) 
449                        | BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_2, SUBPACKET_1_BYTE_6, PacketBytes[i+6]) ;
450                BREG_Write32(hHDMI->hRegister, PacketRegisterOffset, Register) ;
451#if BHDM_CONFIG_DEBUG_HDMI_PACKETS                             
452                BDBG_MSG(("Addr [%#x] = %#x", PacketRegisterOffset, Register)) ;
453#endif         
454        }
455       
456        /* reenable the packet transmission */
457        BHDM_CHECK_RC(rc, BHDM_EnablePacketTransmission(hHDMI, PhysicalHdmiRamPacketId)) ;
458#ifdef BCHP_PWR_RESOURCE_HDMI_TX
459        BCHP_PWR_ReleaseResource(hHDMI->hChip, BCHP_PWR_RESOURCE_HDMI_TX);
460#endif
461done:
462        return rc ; 
463}
464
465
466/******************************************************************************
467Summary:
468Set/Enable the Auxillary Video Information Info frame to be sent to the HDMI Rx
469*******************************************************************************/
470BERR_Code BHDM_SetAVIInfoFramePacket(
471   BHDM_Handle hHDMI,              /* [in] HDMI handle */
472   BAVC_HDMI_AviInfoFrame *stAviInfoFrame
473)
474{
475        BERR_Code          rc = BERR_SUCCESS ;
476       
477        BHDM_Packet PhysicalHdmiRamPacketId ;
478        BAVC_HDMI_AviInfoFrame newAviInfoFrame ;
479        uint8_t PacketType ;
480        uint8_t PacketVersion ;
481        uint8_t PacketLength ;
482        uint8_t M1M0 ;
483        uint8_t VideoID = 1 ;
484        uint8_t PixelRepeat ;
485        uint8_t C1C0 ;
486        uint8_t Y1Y0 ;
487        uint8_t EC2EC1EC0 = 0 ;
488
489        /* make a local copy of AVI  */
490        BKNI_Memset(&newAviInfoFrame, 0, sizeof(BAVC_HDMI_AviInfoFrame)) ;
491        BKNI_Memcpy(&newAviInfoFrame, stAviInfoFrame,
492                sizeof(BAVC_HDMI_AviInfoFrame)) ;
493
494        /* initialize packet information to zero */ 
495        BKNI_Memset(hHDMI->PacketBytes, 0, BHDM_NUM_PACKET_BYTES) ;
496
497        PhysicalHdmiRamPacketId = BHDM_PACKET_eAVI_ID  ;
498       
499        PacketType        = BHDM_Packet_AVIFrameType ;
500        PacketVersion = BHDM_Packet_AVIFrameVersion ;
501        PacketLength  = BHDM_Packet_AVIFrameLength ;
502
503
504        /* Override AVI infoFrame info. Use settings from the AVI InfoFrame passed in */
505        if (stAviInfoFrame->bOverrideDefaults)
506        {
507                /* Set RGB or YCrCb Colorspace */       
508                Y1Y0 = stAviInfoFrame->ePixelEncoding; 
509               
510                /* Set Colorimetry */   
511                C1C0 = stAviInfoFrame->eColorimetry;
512               
513#if BHDM_CONFIG_HDMI_1_3_SUPPORT
514                if (stAviInfoFrame->eColorimetry == BAVC_HDMI_AviInfoFrame_Colorimetry_eExtended) 
515                        EC2EC1EC0 = stAviInfoFrame->eExtendedColorimetry ;
516#endif                 
517                /* Picture Aspect Ratio*/
518                M1M0 = stAviInfoFrame->ePictureAspectRatio;     
519
520                /* Video ID Code & Pixel Repetition */
521                VideoID = stAviInfoFrame->VideoIdCode;
522                PixelRepeat = stAviInfoFrame->PixelRepeat;             
523        }
524        else
525        {
526                /* Set RGB or YCrCb Colorspace */       
527                switch (hHDMI->DeviceSettings.eColorimetry)
528                {
529                default :
530                case BAVC_MatrixCoefficients_eHdmi_RGB :
531                        Y1Y0 =  BAVC_HDMI_AviInfoFrame_Colorspace_eRGB ;
532                        break ;
533                       
534                /* YCbCr output is always YCbCr 4:4:4 */               
535                case BAVC_MatrixCoefficients_eItu_R_BT_709 :
536                case BAVC_MatrixCoefficients_eSmpte_170M :
537                case BAVC_MatrixCoefficients_eXvYCC_601 :
538                case BAVC_MatrixCoefficients_eXvYCC_709 :               
539                        Y1Y0 =  BAVC_HDMI_AviInfoFrame_Colorspace_eYCbCr444 ; 
540                        break ;
541                }
542
543               
544                /* Set Colorimetry */   
545                switch (hHDMI->DeviceSettings.eColorimetry)
546                {
547                default :
548                        C1C0 = BAVC_HDMI_AviInfoFrame_Colorimetry_eNoData ;
549                        break ;
550                       
551                case BAVC_MatrixCoefficients_eItu_R_BT_709 :
552                        C1C0 = BAVC_HDMI_AviInfoFrame_Colorimetry_eItu709 ;
553                        break ;
554               
555                case BAVC_MatrixCoefficients_eSmpte_170M :
556                        C1C0 = BAVC_HDMI_AviInfoFrame_Colorimetry_eSmpte170 ;
557                        break ;
558                       
559                case BAVC_MatrixCoefficients_eXvYCC_601 :
560                        C1C0 = BAVC_HDMI_AviInfoFrame_Colorimetry_eExtended ;
561                        EC2EC1EC0 = BAVC_HDMI_AviInfoFrame_ExtendedColorimetry_exvYCC601 ;
562                        break ;
563
564                case BAVC_MatrixCoefficients_eXvYCC_709 :
565                        C1C0 = BAVC_HDMI_AviInfoFrame_Colorimetry_eExtended ;
566                        EC2EC1EC0 = BAVC_HDMI_AviInfoFrame_ExtendedColorimetry_exvYCC709 ;
567                        break ;         
568                }
569
570                       
571                /* convert specified Aspect Ratio to use for AVI Infoframe values */
572                switch (hHDMI->DeviceSettings.eAspectRatio)
573                {
574                default :
575                case BFMT_AspectRatio_eUnknown   : /* Unknown/Reserved */
576                        BDBG_WRN(("Unknown AspectRatio <%d> passed in AVI Frame",
577                                (uint8_t) hHDMI->DeviceSettings.eAspectRatio)) ;
578                        M1M0 = BAVC_HDMI_AviInfoFrame_PictureAspectRatio_eNoData ;
579                        break ;
580
581                case BFMT_AspectRatio_eSquarePxl : /* square pixel */
582                case BFMT_AspectRatio_e221_1     :         /* 2.21:1 */
583                        BDBG_WRN(("Specified BAVC Aspect Ratio %d, not compatible with HDMI" ,
584                                (uint8_t) hHDMI->DeviceSettings.eAspectRatio)) ;
585                        M1M0 = BAVC_HDMI_AviInfoFrame_PictureAspectRatio_eNoData ;
586                        break ;
587               
588                case BFMT_AspectRatio_e4_3               :     
589                        M1M0 = BAVC_HDMI_AviInfoFrame_PictureAspectRatio_e4_3 ;
590                        break ;
591                       
592                case BFMT_AspectRatio_e16_9      :     
593                        M1M0 = BAVC_HDMI_AviInfoFrame_PictureAspectRatio_e16_9 ;
594                        break ;
595                }
596
597                /* Video Id Code & pixel repetitions */
598                BHDM_P_VideoFmt2CEA861Code(hHDMI->DeviceSettings.eInputVideoFmt, 
599                        hHDMI->DeviceSettings.eAspectRatio, hHDMI->DeviceSettings.ePixelRepetition, 
600                        &VideoID) ;
601               
602                switch (VideoID) 
603                {
604                case  6 :       case  7 : 
605                case 14 :       case 15 : 
606                case 21 :       case 22 : 
607                case 29 :       case 30 : 
608                        PixelRepeat = BAVC_HDMI_PixelRepetition_e2x;
609                        break;
610                       
611                case 10 :       case 11 : 
612                case 25 :       case 26 : 
613                case 35 :       case 36 : 
614                case 37 :       case 38 : 
615                        PixelRepeat = BAVC_HDMI_PixelRepetition_e4x;
616                        break;
617                       
618                default:
619                        PixelRepeat = BAVC_HDMI_PixelRepetition_eNone;
620                        break;
621                }       
622        }       
623
624        /* Update derived or overridden AVI fields */
625
626        /* Pixel Encoding  */
627        newAviInfoFrame.ePixelEncoding = Y1Y0 ;
628       
629        /* Update AVI Colorimetry */
630        newAviInfoFrame.eColorimetry = C1C0;
631#if BHDM_CONFIG_HDMI_1_3_SUPPORT
632        if (C1C0 == BAVC_HDMI_AviInfoFrame_Colorimetry_eExtended)
633                newAviInfoFrame.eExtendedColorimetry = EC2EC1EC0;
634#endif
635
636        /* Picture Aspect Ratio */
637        newAviInfoFrame.ePictureAspectRatio = M1M0 ;
638       
639       
640        /* Video ID and Pixel Repeat */
641        newAviInfoFrame.VideoIdCode = VideoID;
642        newAviInfoFrame.PixelRepeat = PixelRepeat;
643
644        /* always set the bOverrideDefaults to false */
645        /* so subsequent calls to Get/Set AVI do not force override of settings */
646        /* all overrides must be explicitly forced by the caller */
647        newAviInfoFrame.bOverrideDefaults = false ;
648
649       
650        /* Construct AVI InfoFrame pay loads */
651        hHDMI->PacketBytes[1] =                 
652                  newAviInfoFrame.ePixelEncoding << 5 /* Y1Y0 Colorspace */
653                | newAviInfoFrame.eActiveInfo << 4   /*    A0 Active Information Valid */
654                | newAviInfoFrame.eBarInfo << 2      /* B1B0 Bar Info Valid */
655                | newAviInfoFrame.eScanInfo ;         /* S1S0 Scan Information */
656
657        hHDMI->PacketBytes[2] =
658                  newAviInfoFrame.eColorimetry << 6   /* C1C0 Colorimetry */
659                | newAviInfoFrame.ePictureAspectRatio << 4     /* M1M0 */
660                | newAviInfoFrame.eActiveFormatAspectRatio ;  /* R3..R0 */
661
662        hHDMI->PacketBytes[3] = newAviInfoFrame.eScaling ;
663        if (newAviInfoFrame.eColorimetry == BAVC_HDMI_AviInfoFrame_Colorimetry_eExtended)
664        {
665#if BHDM_CONFIG_HDMI_1_3_SUPPORT
666                hHDMI->PacketBytes[3] |= 
667                        newAviInfoFrame.eExtendedColorimetry << 4;  /* EC2EC1EC0 */
668#endif
669        }
670       
671#if BHDM_CONFIG_HDMI_1_3_SUPPORT
672        hHDMI->PacketBytes[3] |= 
673                  newAviInfoFrame.eITContent << 7  /* ITC */
674                | newAviInfoFrame.eRGBQuantizationRange << 2;  /* Q1Q0 */
675#endif
676
677
678        if (PacketVersion >= 2) {
679                hHDMI->PacketBytes[4] = VideoID ;
680                hHDMI->PacketBytes[5] = PixelRepeat;
681#if BHDM_CONFIG_HDMI_1_3_SUPPORT
682                hHDMI->PacketBytes[5] |= 
683                          newAviInfoFrame.eContentType << 4  /* CN1CN0 */
684                        | newAviInfoFrame.eYccQuantizationRange << 6; /* YQ1YQ0 */
685#endif
686        }
687        else /* AVI Version 1 bytes 4,5 are reserved */
688                hHDMI->PacketBytes[4] = hHDMI->PacketBytes[5] = 0 ;
689
690
691        hHDMI->PacketBytes[6]  = (uint8_t) (newAviInfoFrame.TopBarEndLineNumber & 0x00FF) ; 
692        hHDMI->PacketBytes[7]  = (uint8_t) (newAviInfoFrame.TopBarEndLineNumber >> 8) ;   
693       
694        hHDMI->PacketBytes[8]  = (uint8_t) (newAviInfoFrame.BottomBarStartLineNumber & 0x00FF) ;                 
695        hHDMI->PacketBytes[9]  = (uint8_t) (newAviInfoFrame.BottomBarStartLineNumber >> 8) ;   
696       
697        hHDMI->PacketBytes[10] = (uint8_t) (newAviInfoFrame.LeftBarEndPixelNumber & 0x00FF) ;             
698        hHDMI->PacketBytes[11] = (uint8_t) (newAviInfoFrame.LeftBarEndPixelNumber >> 8) ;       
699       
700        hHDMI->PacketBytes[12] = (uint8_t) (newAviInfoFrame.RightBarEndPixelNumber & 0x00FF) ;             
701        hHDMI->PacketBytes[13] = (uint8_t) (newAviInfoFrame.RightBarEndPixelNumber >> 8) ;       
702       
703        BHDM_P_WritePacket(
704                hHDMI, PhysicalHdmiRamPacketId,
705                PacketType, PacketVersion, PacketLength, hHDMI->PacketBytes) ;
706               
707        /* update current device settings with new AviInfoFrame settings */
708        BKNI_Memcpy(&(hHDMI->DeviceSettings.stAviInfoFrame), &newAviInfoFrame, 
709                sizeof(BAVC_HDMI_AviInfoFrame)) ;
710
711
712#if BHDM_CONFIG_DEBUG_AVI_INFOFRAME
713/*
714                Y0, Y1         
715                        RGB or YCBCR indicator. See EIA/CEA-861B table 8 for details.
716                A0                     
717                        Active Information Present. Indicates whether field R0..R3 is valid.
718                        See EIA/CEA-861B table 8 for details.
719                B0, B1         
720                        Bar Info data valid. See EIA/CEA-861B table 8 for details.       
721                S0, S1         
722                        Scan Information (i.e. overscan, underscan). See EIA/CEA-861B table 8
723                C0, C1         
724                        Colorimetry (ITU BT.601, BT.709 etc.). See EIA/CEA-861B table 9
725                M0, M1         
726                        Picture Aspect Ratio (4:3, 16:9). See EIA/CEA-861B table 9
727                R0.R3           
728                        Active Format Aspect Ratio. See EIA/CEA-861B table 10 and Annex H
729                VIC0..VIC6     
730                        Video Format Identification Code. See EIA/CEA-861B table 13
731                PR0..PR3       
732                        Pixel Repetition factor. See EIA/CEA-861B table 14
733                SC1, SC0
734                        Non-uniform Picture Scaling. See EIA/CEA-861B table 11
735                EC2..EC0
736                        Extended Colorimetry. See EIA/CEA-861D tables 7 & 11
737*/                                       
738
739        BDBG_WRN(("-------------------- NEW  AVI INFOFRAME -------------------")) ;
740        BDBG_WRN(("Packet Type: 0x%02x  Version %d  Length: %d", 
741                PacketType, PacketVersion, PacketLength)) ;
742
743        /* display original bOverrideDefaults setting */
744        BDBG_WRN(("Override Default: %d", stAviInfoFrame->bOverrideDefaults));
745
746        BDBG_WRN(("ColorSpace (%d): %s", 
747                newAviInfoFrame.ePixelEncoding, 
748                BAVC_HDMI_AviInfoFrame_ColorspaceToStr(newAviInfoFrame.ePixelEncoding)));
749        BDBG_WRN(("Active Info (%d): %s ", 
750                newAviInfoFrame.eActiveInfo, BAVC_HDMI_AviInfoFrame_ActiveFormatToStr(newAviInfoFrame.eActiveInfo)));
751        BDBG_WRN(("Bar Info (%d): %s ", 
752                newAviInfoFrame.eBarInfo, BAVC_HDMI_AviInfoFrame_BarInfoToStr(newAviInfoFrame.eBarInfo)));
753        BDBG_WRN(("Scan Info (%d): %s", newAviInfoFrame.eScanInfo, BAVC_HDMI_AviInfoFrame_ScanInfoToStr(newAviInfoFrame.eScanInfo))) ;
754
755        BDBG_WRN(("Colorimetry (%d): %s", 
756                newAviInfoFrame.eColorimetry, 
757                BAVC_HDMI_AviInfoFrame_ColorimetryToStr(newAviInfoFrame.eColorimetry))) ; 
758
759#if BHDM_CONFIG_HDMI_1_3_SUPPORT
760        BDBG_WRN(("Extended Colorimetry (%d): %s", 
761                newAviInfoFrame.eExtendedColorimetry, 
762                BAVC_HDMI_AviInfoFrame_ExtendedColorimetryToStr(newAviInfoFrame.eExtendedColorimetry))) ;
763#endif
764
765        BDBG_WRN(("Picture AR (%d): %s", 
766                newAviInfoFrame.ePictureAspectRatio, 
767                BAVC_HDMI_AviInfoFrame_PictureAspectRatioToStr(newAviInfoFrame.ePictureAspectRatio))) ;
768       
769        if ((newAviInfoFrame.eActiveFormatAspectRatio >= 8) 
770        &&      (newAviInfoFrame.eActiveFormatAspectRatio <= 11))
771                BDBG_WRN(("Active Format AR (%d): %s", 
772                        newAviInfoFrame.eActiveFormatAspectRatio,
773                        BAVC_HDMI_AviInfoFrame_ActiveFormatAspectRatioToStr(newAviInfoFrame.eActiveFormatAspectRatio - 8))) ;
774        else
775                BDBG_WRN(("Active Format AR (%d): Other", 
776                        newAviInfoFrame.eActiveFormatAspectRatio)) ;
777                       
778        BDBG_WRN(("Picture Scaling (%d): %s ", 
779                newAviInfoFrame.eScaling, BAVC_HDMI_AviInfoFrame_ScalingToStr(newAviInfoFrame.eScaling))) ;
780               
781        BDBG_WRN(("Video ID Code = %d", newAviInfoFrame.VideoIdCode )) ;
782        BDBG_WRN(("Pixel Repeat: %d", newAviInfoFrame.PixelRepeat)) ;
783
784#if BHDM_CONFIG_HDMI_1_3_SUPPORT
785        BDBG_WRN(("IT Content (%d): %s", newAviInfoFrame.eITContent, 
786                BAVC_HDMI_AviInfoFrame_ITContentToStr(newAviInfoFrame.eITContent)));
787        BDBG_WRN(("IT Content Type (%d): %s", newAviInfoFrame.eContentType,
788                BAVC_HDMI_AviInfoFrame_ContentTypeToStr(newAviInfoFrame.eContentType)));
789        BDBG_WRN(("RGB Quantization Range (%d): %s", newAviInfoFrame.eRGBQuantizationRange,
790                BAVC_HDMI_AviInfoFrame_RGBQuantizationRangeToStr(newAviInfoFrame.eRGBQuantizationRange)));
791        BDBG_WRN(("Ycc Quantization Range (%d): %s", newAviInfoFrame.eYccQuantizationRange,
792                BAVC_HDMI_AviInfoFrame_YccQuantizationRangeToStr(newAviInfoFrame.eYccQuantizationRange)));
793#endif
794       
795        BDBG_WRN(("Top Bar End Line Number: %d", newAviInfoFrame.TopBarEndLineNumber)) ;
796        BDBG_WRN(("Bottom Bar Stop Line Number: %d", newAviInfoFrame.BottomBarStartLineNumber)) ;
797       
798        BDBG_WRN(("Left Bar End Pixel Number: %d", newAviInfoFrame.LeftBarEndPixelNumber )) ; 
799        BDBG_WRN(("Right Bar End Pixel Number: %d", newAviInfoFrame.RightBarEndPixelNumber )) ;
800        BDBG_WRN(("--------------------- END AVI INFOFRAME ---------------------")) ;
801#endif         
802               
803               
804        return rc ;
805}       
806
807
808/******************************************************************************
809Summary:
810Get the Auxillary Video Information Info frame sent to the HDMI Rx
811*******************************************************************************/
812BERR_Code BHDM_GetAVIInfoFramePacket(
813   BHDM_Handle hHDMI,              /* [in] HDMI handle */
814   BAVC_HDMI_AviInfoFrame *stAviInfoFrame
815)
816{
817        BERR_Code          rc = BERR_SUCCESS ;
818#if BHDM_CONFIG_DEBUG_AVI_INFOFRAME     
819        uint8_t 
820                Y1Y0, C1C0, M1M0, 
821                EC2EC1EC0=2,
822                VideoID,
823                PixelRepeat;
824#endif 
825
826        BKNI_Memset(stAviInfoFrame, 0, sizeof(BAVC_HDMI_AviInfoFrame)) ;
827        BKNI_Memcpy(stAviInfoFrame, &(hHDMI->DeviceSettings.stAviInfoFrame), 
828                sizeof(BAVC_HDMI_AviInfoFrame)) ;
829
830
831/* translate to AVI Data for debug/display purposes */         
832#if BHDM_CONFIG_DEBUG_AVI_INFOFRAME     
833
834        if (stAviInfoFrame->bOverrideDefaults)
835        {
836                /* RGB or YCrCb Colorspace */   
837                Y1Y0 = stAviInfoFrame->ePixelEncoding; 
838               
839                /* Colorimetry */       
840                C1C0 = stAviInfoFrame->eColorimetry;
841               
842#if BHDM_CONFIG_HDMI_1_3_SUPPORT
843                if (stAviInfoFrame->eColorimetry == BAVC_HDMI_AviInfoFrame_Colorimetry_eExtended) {
844                        EC2EC1EC0 = stAviInfoFrame->eExtendedColorimetry;
845                }
846#endif 
847
848                /* Picture Aspect Ratio*/
849                M1M0 = stAviInfoFrame->ePictureAspectRatio;     
850               
851                /* Video ID Code & Pixel Repetition */
852                VideoID = stAviInfoFrame->VideoIdCode;
853                PixelRepeat = stAviInfoFrame->PixelRepeat;
854        }
855        else 
856        {       
857                /* Set RGB or YCrCb Colorspace */       
858                switch (hHDMI->DeviceSettings.eColorimetry)
859                {
860                default :
861                case BAVC_MatrixCoefficients_eHdmi_RGB :
862                        Y1Y0 =  BAVC_HDMI_AviInfoFrame_Colorspace_eRGB ;
863                        break ;
864                       
865                /* YCbCr output is always YCbCr 4:4:4 */               
866                case BAVC_MatrixCoefficients_eItu_R_BT_709 :
867                case BAVC_MatrixCoefficients_eSmpte_170M :
868                case BAVC_MatrixCoefficients_eXvYCC_601 :
869                case BAVC_MatrixCoefficients_eXvYCC_709 :               
870                        Y1Y0 =  BAVC_HDMI_AviInfoFrame_Colorspace_eYCbCr444 ; 
871                        break ;
872                }
873               
874                /* Set Colorimetry */   
875                switch (hHDMI->DeviceSettings.eColorimetry)
876                {
877                default :
878                        C1C0 = BAVC_HDMI_AviInfoFrame_Colorimetry_eNoData ;
879                        break ;
880                       
881                case BAVC_MatrixCoefficients_eItu_R_BT_709 :
882                        C1C0 = BAVC_HDMI_AviInfoFrame_Colorimetry_eItu709 ;
883                        break ;
884               
885                case BAVC_MatrixCoefficients_eSmpte_170M :
886                        C1C0 = BAVC_HDMI_AviInfoFrame_Colorimetry_eSmpte170 ;
887                        break ;
888
889                case BAVC_MatrixCoefficients_eXvYCC_601 :
890                        C1C0 = BAVC_HDMI_AviInfoFrame_Colorimetry_eExtended ;
891                        EC2EC1EC0 = BAVC_HDMI_AviInfoFrame_ExtendedColorimetry_exvYCC601;
892                        break ;
893
894                case BAVC_MatrixCoefficients_eXvYCC_709 :
895                        C1C0 = BAVC_HDMI_AviInfoFrame_Colorimetry_eExtended ;
896                        EC2EC1EC0 = BAVC_HDMI_AviInfoFrame_ExtendedColorimetry_exvYCC709;
897                }
898               
899
900                /* convert specified Aspect Ratio to use for AVI Infoframe values */
901                switch (hHDMI->DeviceSettings.eAspectRatio)
902                {
903                default :
904                case BFMT_AspectRatio_eUnknown   : /* Unknown/Reserved */
905                        BDBG_WRN(("Unknown AspectRatio passed in AVI Frame")) ;
906                        /* fall through */
907                       
908                case BFMT_AspectRatio_eSquarePxl : /* square pixel */
909                case BFMT_AspectRatio_e221_1     :         /* 2.21:1 */
910                        BDBG_WRN(("Specified BAVC Aspect Ratio %d, not compatible with HDMI" ,
911                                hHDMI->DeviceSettings.eAspectRatio)) ;
912                        M1M0 = BAVC_HDMI_AviInfoFrame_PictureAspectRatio_eNoData ;
913                        break ;
914               
915                case BFMT_AspectRatio_e4_3               :     
916                        M1M0 = BAVC_HDMI_AviInfoFrame_PictureAspectRatio_e4_3 ;
917                        break ;
918                       
919                case BFMT_AspectRatio_e16_9      :     
920                        M1M0 = BAVC_HDMI_AviInfoFrame_PictureAspectRatio_e16_9 ;
921                        break ;
922                }
923
924                BHDM_P_VideoFmt2CEA861Code(hHDMI->DeviceSettings.eInputVideoFmt, 
925                        hHDMI->DeviceSettings.eAspectRatio, hHDMI->DeviceSettings.ePixelRepetition, 
926                        &VideoID) ;             
927
928                PixelRepeat = (uint8_t) hHDMI->DeviceSettings.ePixelRepetition;
929        }
930       
931        BDBG_WRN(("*** Current AVI Info Frame Settings ***")) ;
932        BDBG_WRN(("ColorSpace (%d): %s", Y1Y0, BAVC_HDMI_AviInfoFrame_ColorspaceToStr(Y1Y0))) ;
933        BDBG_WRN(("Active Info (%d): %s ", stAviInfoFrame->eActiveInfo, 
934                BAVC_HDMI_AviInfoFrame_ActiveFormatToStr(stAviInfoFrame->eActiveInfo))) ;
935        BDBG_WRN(("Bar Info (%d): %s ", stAviInfoFrame->eBarInfo, 
936                BAVC_HDMI_AviInfoFrame_BarInfoToStr(stAviInfoFrame->eBarInfo))) ;
937        BDBG_WRN(("Scan Info (%d): %s", stAviInfoFrame->eScanInfo, 
938                BAVC_HDMI_AviInfoFrame_ScanInfoToStr(stAviInfoFrame->eScanInfo))) ;     
939        BDBG_WRN(("Colorimetry (%d): %s", C1C0, BAVC_HDMI_AviInfoFrame_ColorimetryToStr(C1C0))) ;
940        BDBG_WRN(("Extended Colorimetry (%d): %s", EC2EC1EC0, 
941                BAVC_HDMI_AviInfoFrame_ExtendedColorimetryToStr(EC2EC1EC0))) ; 
942        BDBG_WRN(("Picture AR (%d): %s", M1M0, 
943                BAVC_HDMI_AviInfoFrame_PictureAspectRatioToStr(M1M0))) ;
944       
945        if ((stAviInfoFrame->eActiveFormatAspectRatio >= 8) 
946        &&      (stAviInfoFrame->eActiveFormatAspectRatio <= 11))
947                BDBG_WRN(("Active Format AR (%d): %s", stAviInfoFrame->eActiveFormatAspectRatio,
948                        BAVC_HDMI_AviInfoFrame_ActiveFormatAspectRatioToStr(stAviInfoFrame->eActiveFormatAspectRatio - 8))) ;
949        else
950                BDBG_WRN(("Active Format AR (%d): Other", 
951                        stAviInfoFrame->eActiveFormatAspectRatio)) ;
952                       
953        BDBG_WRN(("Picture Scaling (%d): %s ", stAviInfoFrame->eScaling, 
954                BAVC_HDMI_AviInfoFrame_ScalingToStr(stAviInfoFrame->eScaling))) ;
955       
956        BDBG_WRN(("Video ID Code = %d", VideoID)) ;
957        BDBG_WRN(("Pixel Repeat: %d", PixelRepeat)) ;
958
959#if BHDM_CONFIG_HDMI_1_3_SUPPORT
960        BDBG_WRN(("IT Content (%d): %s", stAviInfoFrame->eITContent, 
961                BAVC_HDMI_AviInfoFrame_ITContentToStr(stAviInfoFrame->eITContent)));
962        BDBG_WRN(("IT Content Type (%d): %s", stAviInfoFrame->eContentType,
963                BAVC_HDMI_AviInfoFrame_ContentTypeToStr(stAviInfoFrame->eContentType)));
964        BDBG_WRN(("RGB Quantization Range (%d): %s", stAviInfoFrame->eRGBQuantizationRange,
965                BAVC_HDMI_AviInfoFrame_RGBQuantizationRangeToStr(stAviInfoFrame->eRGBQuantizationRange)));
966        BDBG_WRN(("YCC Quantization Range (%d): %s", stAviInfoFrame->eYccQuantizationRange,
967                BAVC_HDMI_AviInfoFrame_YccQuantizationRangeToStr(stAviInfoFrame->eYccQuantizationRange)));
968#endif
969               
970        BDBG_WRN(("Top Bar End Line Number: %d", stAviInfoFrame->TopBarEndLineNumber)) ;
971        BDBG_WRN(("Bottom Bar Stop Line Number: %d", stAviInfoFrame->BottomBarStartLineNumber)) ;
972       
973        BDBG_WRN(("Left Bar End Pixel Number: %d", stAviInfoFrame->LeftBarEndPixelNumber )) ; 
974        BDBG_WRN(("Right Bar End Pixel Number: %d\n", stAviInfoFrame->RightBarEndPixelNumber )) ;
975       
976#endif         
977
978        return rc ;
979}
980
981
982/******************************************************************************
983Summary:
984Set/Enable the Audio Info Frame packet to be sent to the HDMI Rx
985*******************************************************************************/
986BERR_Code BHDM_SetAudioInfoFramePacket(
987   BHDM_Handle hHDMI,             /* [in] HDMI handle */
988   BAVC_HDMI_AudioInfoFrame *pstAudioInfoFrame
989)
990{
991        BERR_Code          rc = BERR_SUCCESS ;
992
993        BHDM_Packet PhysicalHdmiRamPacketId ;
994       
995        uint8_t PacketType ;
996        uint8_t PacketVersion ;
997        uint8_t PacketLength ;
998       
999        /* BHDM_SetAudioInfoFramePacket also called from BHDM_EnableDisplay
1000            using the AudioInfoFrame stored in the HDMI handle
1001        */
1002
1003        /* initialize packet information to zero */ 
1004        BKNI_Memset(hHDMI->PacketBytes, 0, BHDM_NUM_PACKET_BYTES) ;
1005
1006        PhysicalHdmiRamPacketId = BHDM_PACKET_eAudioFrame_ID ;
1007       
1008        PacketType        = BHDM_Packet_AudioFrameType ;
1009        PacketVersion = BHDM_Packet_AudioFrameVersion ;
1010        PacketLength  = BHDM_Packet_AudioFrameLength ;
1011
1012        if ((!pstAudioInfoFrame->bOverrideDefaults) 
1013        && ((pstAudioInfoFrame->CodingType)
1014        ||  (pstAudioInfoFrame->SampleFrequency) 
1015        ||  (pstAudioInfoFrame->SampleSize)))
1016        {
1017                BDBG_WRN(("Audio Coding Type, Sample Size, and Frequency are obtained from stream header")) ;
1018               
1019                /* set the audio coding type, sample frequency, and sample size ALL to 0 */
1020                pstAudioInfoFrame->CodingType =
1021                pstAudioInfoFrame->SampleFrequency =
1022                pstAudioInfoFrame->SampleSize
1023                        =  BHDM_REFER_TO_STREAM_HEADER ;
1024        }
1025       
1026
1027        hHDMI->PacketBytes[1] = 
1028                   pstAudioInfoFrame->CodingType << 4 
1029                | (pstAudioInfoFrame->ChannelCount) ; 
1030        hHDMI->PacketBytes[2] = 
1031                   pstAudioInfoFrame->SampleFrequency << 2 
1032                | pstAudioInfoFrame->SampleSize ;
1033       
1034       
1035        hHDMI->PacketBytes[3] = 0 ; /* Per HDMI Spec... Set to 0  */
1036       
1037        hHDMI->PacketBytes[4] = 
1038                pstAudioInfoFrame->SpeakerAllocation ;
1039       
1040        hHDMI->PacketBytes[5] = 
1041                pstAudioInfoFrame->DownMixInhibit << 7 
1042                | pstAudioInfoFrame->LevelShift << 3 ;
1043
1044        /* adjust the Audio Input Configuration to reflect any changes */
1045        BHDM_P_ConfigureInputAudioFmt(hHDMI, pstAudioInfoFrame) ;
1046
1047        BHDM_CHECK_RC(rc, BHDM_P_WritePacket(
1048                hHDMI, PhysicalHdmiRamPacketId,
1049                PacketType, PacketVersion, PacketLength, hHDMI->PacketBytes)) ;
1050
1051        /* update current device settings with new information on AudioInfoFrame */
1052        BKNI_Memcpy(&hHDMI->DeviceSettings.stAudioInfoFrame, pstAudioInfoFrame, 
1053                sizeof(BAVC_HDMI_AudioInfoFrame)) ;
1054
1055#if BHDM_CONFIG_DEBUG_AUDIO_INFOFRAME           
1056        BDBG_WRN(("------------------- NEW  AUDIO INFOFRAME ------------------")) ;
1057        BDBG_WRN(("Packet Type: 0x%02x  Version %d  Length: %d", 
1058                PacketType, PacketVersion, PacketLength)) ;
1059        BDBG_WRN(("Checksum            %#02x", hHDMI->PacketBytes[0])) ;
1060
1061        BDBG_WRN(("Audio Coding Type     %s", 
1062                BAVC_HDMI_AudioInfoFrame_CodingTypeToStr(pstAudioInfoFrame->CodingType))) ;
1063
1064        BDBG_WRN(("Audio Channel Count   %s", 
1065                BAVC_HDMI_AudioInfoFrame_ChannelCountToStr(pstAudioInfoFrame->ChannelCount))) ;
1066       
1067        BDBG_WRN(("Sampling Frequency    %s", 
1068                BAVC_HDMI_AudioInfoFrame_SampleFrequencyToStr(pstAudioInfoFrame->SampleFrequency))) ;
1069
1070        BDBG_WRN(("Sample Size           %s", 
1071                BAVC_HDMI_AudioInfoFrame_SampleSizeToStr(pstAudioInfoFrame->SampleSize))) ;
1072
1073        BDBG_WRN(("Speaker Allocation    %02x", pstAudioInfoFrame->SpeakerAllocation)) ;
1074
1075        BDBG_WRN(("Level Shift           %s",
1076                BAVC_HDMI_AudioInfoFrame_LevelShiftToStr(pstAudioInfoFrame->LevelShift))) ;
1077
1078        BDBG_WRN(("Down-mix Inhibit Flag %s", 
1079                BAVC_HDMI_AudioInfoFrame_DownMixInhibitToStr(pstAudioInfoFrame->DownMixInhibit))) ;
1080       
1081        {
1082                uint8_t i ;
1083
1084                for (i = 1 ; i <= 10 ; i++)
1085                {
1086                        BDBG_WRN(("Data Byte %02d = %#02x h", i, hHDMI->PacketBytes[i])) ;
1087                }
1088        }       
1089        BDBG_WRN(("-------------------- END AUDIO INFOFRAME --------------------")) ;
1090#endif
1091       
1092done:
1093        return rc ; 
1094}
1095
1096
1097
1098/******************************************************************************
1099Summary:
1100Get the Audio Information Info frame sent to the HDMI Rx
1101*******************************************************************************/
1102BERR_Code BHDM_GetAudioInfoFramePacket(
1103   BHDM_Handle hHDMI,              /* [in] HDMI handle */
1104   BAVC_HDMI_AudioInfoFrame *stAudioInfoFrame
1105)
1106{
1107        BERR_Code          rc = BERR_SUCCESS ;
1108
1109        BKNI_Memset(stAudioInfoFrame, 0, sizeof(BAVC_HDMI_AudioInfoFrame)) ;
1110
1111        BKNI_Memcpy(stAudioInfoFrame, &(hHDMI->DeviceSettings.stAudioInfoFrame), 
1112                sizeof(BAVC_HDMI_AudioInfoFrame)) ;
1113
1114        return rc ;
1115}
1116
1117
1118
1119/******************************************************************************
1120Summary:
1121Get the length of  a string
1122*******************************************************************************/
1123static int _strlen(const unsigned char *s) {
1124        int i=0;
1125        while (*s++) i++;
1126        return i;
1127}
1128
1129
1130
1131/******************************************************************************
1132Summary:
1133Set/Enable the Source Product Description Info Frame packet to be sent to the HDMI Rx
1134*******************************************************************************/
1135BERR_Code BHDM_SetSPDInfoFramePacket(
1136   BHDM_Handle hHDMI              /* [in] HDMI handle */
1137)
1138{
1139        BERR_Code          rc = BERR_SUCCESS ;
1140
1141        BHDM_Packet PhysicalHdmiRamPacketId ;
1142       
1143        uint8_t PacketType ;
1144        uint8_t PacketVersion ;
1145        uint8_t PacketLength ;
1146
1147
1148        /* check length of vendor and description */
1149        PacketLength = _strlen(hHDMI->DeviceSettings.SpdVendorName) ;
1150        if (PacketLength > BAVC_HDMI_SPD_IF_VENDOR_LEN)
1151        {
1152                BDBG_ERR(("SPD Vendor Name Length %d larger than MAX: %d", 
1153                        PacketLength, BAVC_HDMI_SPD_IF_VENDOR_LEN)) ;
1154                return BERR_INVALID_PARAMETER ;
1155        }
1156       
1157        PacketLength = _strlen(hHDMI->DeviceSettings.SpdDescription) ;
1158        if (PacketLength > BAVC_HDMI_SPD_IF_DESC_LEN)
1159        {
1160                BDBG_ERR(("SPD Description Length %d larger than MAX: %d", 
1161                        PacketLength, BAVC_HDMI_SPD_IF_DESC_LEN)) ;
1162                return BERR_INVALID_PARAMETER ;
1163        }
1164       
1165       
1166        /* initialize packet information to zero */ 
1167        BKNI_Memset(hHDMI->PacketBytes, 0, BHDM_NUM_PACKET_BYTES) ;
1168
1169        PhysicalHdmiRamPacketId = BHDM_PACKET_eSPD_ID ;
1170       
1171        PacketType        = BHDM_Packet_SPDFrameType    ;
1172        PacketVersion = BHDM_Packet_SPDFrameVersion ;
1173        PacketLength  = BHDM_Packet_SPDFrameLength      ;
1174       
1175        BKNI_Memcpy(hHDMI->PacketBytes+1, hHDMI->DeviceSettings.SpdVendorName, 
1176                BAVC_HDMI_SPD_IF_VENDOR_LEN) ;
1177        BKNI_Memcpy(hHDMI->PacketBytes+9, hHDMI->DeviceSettings.SpdDescription, 
1178                BAVC_HDMI_SPD_IF_DESC_LEN) ;
1179        hHDMI->PacketBytes[25] = hHDMI->DeviceSettings.eSpdSourceDevice ;
1180                                                                                                                                                                                           
1181                       
1182        BHDM_CHECK_RC(rc, BHDM_P_WritePacket(
1183                hHDMI, PhysicalHdmiRamPacketId,
1184                PacketType, PacketVersion, PacketLength, hHDMI->PacketBytes)) ;
1185       
1186done:
1187#if BHDM_CONFIG_DEBUG_SPD_INFOFRAME
1188        BDBG_WRN(("-------------------- NEW  SPD INFOFRAME -------------------")) ;
1189        BDBG_WRN(("Packet Type: 0x%02x  Version %d  Length: %d", 
1190                PacketType, PacketVersion, PacketLength)) ;
1191
1192        BDBG_WRN(("Vendor Name: %s",
1193                hHDMI->DeviceSettings.SpdVendorName)) ;
1194
1195        BDBG_WRN(("Vendor Description: %s",
1196                hHDMI->DeviceSettings.SpdDescription)) ;
1197               
1198        BDBG_WRN(("Device Type: %s",
1199                BAVC_HDMI_SpdInfoFrame_SourceTypeToStr(
1200                        hHDMI->DeviceSettings.eSpdSourceDevice))) ;
1201        BDBG_WRN(("--------------------- END SPD INFOFRAME ---------------------")) ;
1202               
1203#endif 
1204        return rc ; 
1205}
1206
1207
1208/******************************************************************************
1209Summary:
1210        Get currently transmitted Vendor Specific Info Frame
1211*******************************************************************************/
1212void  BHDM_GetVendorSpecificInfoFrame(
1213        BHDM_Handle hHDMI,                      /* [in] HDMI handle */
1214        BAVC_HDMI_VendorSpecificInfoFrame *pVendorSpecficInfoFrame)
1215{
1216        BKNI_Memset(pVendorSpecficInfoFrame, 
1217                0, sizeof(BAVC_HDMI_VendorSpecificInfoFrame)) ;
1218
1219        BKNI_Memcpy(pVendorSpecficInfoFrame, &(hHDMI->DeviceSettings.stVendorSpecificInfoFrame), 
1220                sizeof(BAVC_HDMI_VendorSpecificInfoFrame)) ;
1221}
1222
1223/******************************************************************************
1224Summary:
1225        Create/Set a Vendor Specific Info Frame
1226*******************************************************************************/
1227BERR_Code BHDM_SetVendorSpecificInfoFrame(
1228        BHDM_Handle hHDMI,                      /* [in] HDMI handle */
1229        const BAVC_HDMI_VendorSpecificInfoFrame *pVendorSpecificInfoFrame)
1230{
1231        BERR_Code          rc = BERR_SUCCESS ;
1232        uint8_t packetByte5 ;
1233
1234        BHDM_Packet PhysicalHdmiRamPacketId = BHDM_Packet_eVendorSpecific_ID ;
1235       
1236        uint8_t PacketType = BAVC_HDMI_PacketType_eVendorSpecificInfoframe ;
1237        uint8_t PacketVersion = 0x01 ; 
1238        uint8_t PacketLength = 0 ;
1239
1240        /* BHDM_SetVendorSpecificInfoFrame packet also called from BHDM_EnableDisplay
1241            using the VSI stored in the HDMI handle
1242        */
1243       
1244        /* initialize packet information to zero */ 
1245        BKNI_Memset(hHDMI->PacketBytes, 0, BHDM_NUM_PACKET_BYTES) ;
1246
1247
1248        /* ready the Packet Data structure used for transmissIon of the Vendor Specific Data */
1249        /* Copy the IEEE Reg ID; skip over the checksum byte */
1250        BKNI_Memcpy(hHDMI->PacketBytes + 1, 
1251                &pVendorSpecificInfoFrame->uIEEE_RegId, BAVC_HDMI_IEEE_REGID_LEN) ;
1252        PacketLength = BAVC_HDMI_IEEE_REGID_LEN;
1253
1254        /* Set the HDMI Video Format */
1255        hHDMI->PacketBytes[4] = pVendorSpecificInfoFrame->eHdmiVideoFormat << 5 ;
1256        PacketLength++ ;
1257
1258        /* Set the Extended Resolution or 3D Format */
1259        switch (pVendorSpecificInfoFrame->eHdmiVideoFormat)
1260        {
1261        default :
1262        case BAVC_HDMI_VSInfoFrame_HDMIVideoFormat_eNone :
1263                goto done;
1264               
1265        case BAVC_HDMI_VSInfoFrame_HDMIVideoFormat_eExtendedResolution :
1266                packetByte5 = pVendorSpecificInfoFrame->eHdmiVic ;
1267                break ;
1268               
1269        case BAVC_HDMI_VSInfoFrame_HDMIVideoFormat_e3DFormat :
1270                packetByte5 = pVendorSpecificInfoFrame->e3DStructure << 4 ;
1271                break ;
1272        }
1273        hHDMI->PacketBytes[5] = packetByte5 ;
1274        PacketLength++ ;
1275
1276        /* if 3D_Structure = sidebysideHalf, 3D_Ext_Data is added to HDMI VSI for additional info */
1277        if ((pVendorSpecificInfoFrame->eHdmiVideoFormat == BAVC_HDMI_VSInfoFrame_HDMIVideoFormat_e3DFormat)
1278                && (pVendorSpecificInfoFrame->e3DStructure == BAVC_HDMI_VSInfoFrame_3DStructure_eSidexSideHalf))
1279        {
1280                hHDMI->PacketBytes[6] = pVendorSpecificInfoFrame->e3DExtData << 4;
1281                PacketLength++;
1282        }
1283
1284
1285done:
1286       
1287#if BHDM_CONFIG_DEBUG_VENDOR_SPECIFIC_INFOFRAME
1288
1289        BDBG_WRN(("-------------------- NEW  VS  INFOFRAME -------------------")) ;
1290        BDBG_WRN(("Packet Type: 0x%02x  Version %d  Length: %d", 
1291                PacketType, PacketVersion, PacketLength)) ;
1292
1293        BDBG_WRN(("IEEE Registration ID 0x%02x%02x%02x",
1294                pVendorSpecificInfoFrame->uIEEE_RegId[2],
1295                pVendorSpecificInfoFrame->uIEEE_RegId[1],
1296                pVendorSpecificInfoFrame->uIEEE_RegId[0])) ; 
1297       
1298   
1299        BDBG_WRN(("HDMI VideoFormat: %s   (PB4: %#x)", 
1300                BAVC_HDMI_VsInfoFrame_HdmiVideoFormatToStr(pVendorSpecificInfoFrame->eHdmiVideoFormat),
1301                pVendorSpecificInfoFrame->eHdmiVideoFormat)) ;
1302
1303        if (pVendorSpecificInfoFrame->eHdmiVideoFormat == BAVC_HDMI_VSInfoFrame_HDMIVideoFormat_eExtendedResolution)
1304        {
1305                BDBG_WRN(("HDMI_VIC: %d (PB5: %#x)",
1306                                pVendorSpecificInfoFrame->eHdmiVic, pVendorSpecificInfoFrame->eHdmiVic));
1307        }
1308        else if (pVendorSpecificInfoFrame->eHdmiVideoFormat == BAVC_HDMI_VSInfoFrame_HDMIVideoFormat_e3DFormat)
1309        {
1310                BDBG_WRN(("HDMI 2D/3D Structure: %s (PB5: %#x)",
1311                        BAVC_HDMI_VsInfoFrame_3DStructureToStr(pVendorSpecificInfoFrame->e3DStructure),
1312                        pVendorSpecificInfoFrame->e3DStructure));
1313
1314                if (pVendorSpecificInfoFrame->e3DStructure == BAVC_HDMI_VSInfoFrame_3DStructure_eSidexSideHalf)
1315                {               
1316                        BDBG_WRN(("HDMI 3D_Ext_Data: %s (PB6: %#x)",
1317                                BAVC_HDMI_VsInfoFrame_3DExtDataToStr(pVendorSpecificInfoFrame->e3DExtData),
1318                                pVendorSpecificInfoFrame->e3DExtData));
1319                }
1320        }
1321        BDBG_WRN(("--------------------- END VS  INFOFRAME ---------------------")) ;
1322       
1323#endif 
1324
1325        /* update current device settings with new information on VendorSpecificInfoFrame */
1326        BKNI_Memcpy(&hHDMI->DeviceSettings.stVendorSpecificInfoFrame, pVendorSpecificInfoFrame, 
1327                sizeof(BAVC_HDMI_VendorSpecificInfoFrame)) ;
1328
1329        BHDM_P_WritePacket(
1330                hHDMI, PhysicalHdmiRamPacketId,
1331                PacketType, PacketVersion, PacketLength, hHDMI->PacketBytes) ;
1332
1333        return rc ; 
1334}
1335
1336
1337/******************************************************************************
1338Summary:
1339        Create/Set a user defined packet
1340*******************************************************************************/
1341BERR_Code BHDM_SetUserDefinedPacket(
1342        BHDM_Handle hHDMI,                      /* [in] HDMI handle */
1343        BHDM_Packet PhysicalHdmiRamPacketId,
1344       
1345        uint8_t PacketType,
1346        uint8_t PacketVersion, 
1347        uint8_t PacketLength,
1348       
1349        uint8_t *PacketData
1350)
1351{
1352        BERR_Code          rc = BERR_SUCCESS ;
1353        uint8_t i ;
1354
1355       
1356        if (PacketLength > BHDM_NUM_PACKET_BYTES)
1357        {
1358                rc = BERR_INVALID_PARAMETER ;
1359                BDBG_ERR(("User Defined Packet Length larger than HDMI Packet Size %d", 
1360                        BHDM_NUM_PACKET_BYTES)) ;
1361                goto done ;
1362        }
1363       
1364        if (PhysicalHdmiRamPacketId < BHDM_Packet_eUser1)
1365        {
1366                rc = BERR_INVALID_PARAMETER ;
1367                BDBG_ERR(("Pre-defined Packets cannot be modified; use BHDM_Packet_eUserX")) ;
1368                goto done ;
1369               
1370        }
1371       
1372        for (i = 0 ; i < BHDM_Packet_eUser1;  i++)
1373        {
1374                if (PacketType == (BHDM_Packet) i)
1375                {
1376                        BDBG_ERR(("User Packet Type cannot be pre-defined Packet Type: %d", i)) ;
1377                        rc = BERR_INVALID_PARAMETER ;
1378                }
1379        }
1380       
1381       
1382        /* initialize packet information to zero */ 
1383        BKNI_Memset(hHDMI->PacketBytes, 0, BHDM_NUM_PACKET_BYTES) ;
1384       
1385       
1386        /* copy the user defined data */
1387        for (i = 0 ; i < PacketLength;  i++)
1388                hHDMI->PacketBytes[i] = PacketData[i] ;
1389               
1390        BDBG_MSG(("Packet Bytes: %s", hHDMI->PacketBytes)) ;
1391       
1392        BHDM_P_WritePacket(
1393                hHDMI, PhysicalHdmiRamPacketId,
1394                PacketType, PacketVersion, PacketLength, hHDMI->PacketBytes) ;
1395       
1396done:           
1397        return rc ; 
1398}
1399
1400
1401#if BHDM_CONFIG_HDMI_1_3_SUPPORT
1402/******************************************************************************
1403Summary:
1404Set/Enable the Gamut Metadata packet to be sent to the HDMI Rx
1405*******************************************************************************/
1406BERR_Code BHDM_P_SetGamutMetadataPacket(
1407        BHDM_Handle hHDMI                 /* [in] HDMI handle */
1408)
1409{
1410        BERR_Code rc = BERR_SUCCESS ;
1411
1412        BHDM_Packet PhysicalHdmiRamPacketId ;
1413        uint32_t PacketRegisterOffset ;
1414        uint32_t Register;
1415        uint32_t i;
1416
1417        /* initialize packet information to zero */ 
1418        BKNI_Memset(hHDMI->PacketBytes, 0, BHDM_NUM_PACKET_BYTES) ;
1419
1420        PhysicalHdmiRamPacketId = BHDM_PACKET_eGamutMetadata_ID;
1421
1422        hHDMI->PacketBytes[0] = BHDM_Packet_GamutMetadataType;
1423        hHDMI->PacketBytes[1] = BHDM_Packet_GamutMetadataHB1;
1424        hHDMI->PacketBytes[2] = BHDM_Packet_GamutMetadataHB2;
1425
1426        for (i=0; i<sizeof(BHDM_Packet_GamutMetadataSubPkt); i++) {
1427                hHDMI->PacketBytes[i+3] = BHDM_Packet_GamutMetadataSubPkt[i];
1428        }
1429
1430        /* disable transmission of the RAM Packet */
1431        BHDM_CHECK_RC(rc, BHDM_DisablePacketTransmission(hHDMI, PhysicalHdmiRamPacketId)) ;
1432
1433        /* calculate the offset of where the RAM for Packet ID begins */               
1434        PacketRegisterOffset = 
1435                  BCHP_HDMI_RAM_GCP_0
1436                + BHDM_P_WORDS_PER_RAM_PACKET * 4 * PhysicalHdmiRamPacketId ;
1437
1438        /* load the Packet Bytes */
1439        for (i = 0 ; i < BHDM_NUM_PACKET_BYTES; i = i + 7)
1440        {
1441                /* create/write the subpacket data use HDMI_RAM_PACKET_1_0 for Register field names */
1442                Register = 
1443                          BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_0, HEADER_BYTE_0, hHDMI->PacketBytes[i+0]) 
1444                        | BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_0, HEADER_BYTE_1, hHDMI->PacketBytes[i+1]) 
1445                        | BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_0, HEADER_BYTE_2, hHDMI->PacketBytes[i+2]) ;
1446                BREG_Write32(hHDMI->hRegister, PacketRegisterOffset, Register) ;
1447               
1448#if BHDM_CONFIG_DEBUG_HDMI_PACKETS                             
1449                BDBG_MSG(("Addr [%#x] = %#x", PacketRegisterOffset, Register)) ;
1450#endif                         
1451                PacketRegisterOffset += 4 ;
1452
1453                /* create/write the subpacket data use HDMI_RAM_PACKET_1_1 for Register field names */
1454                Register = 
1455                          BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_1, SUBPACKET_1_BYTE_0, hHDMI->PacketBytes[i+3]) 
1456                        | BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_1, SUBPACKET_1_BYTE_1, hHDMI->PacketBytes[i+4]) 
1457                        | BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_1, SUBPACKET_1_BYTE_2, hHDMI->PacketBytes[i+5]) 
1458                        | BCHP_FIELD_DATA(HDMI_RAM_PACKET_1_1, SUBPACKET_1_BYTE_3, hHDMI->PacketBytes[i+6]) ;
1459                BREG_Write32(hHDMI->hRegister, PacketRegisterOffset, Register) ;
1460
1461#if BHDM_CONFIG_DEBUG_HDMI_PACKETS             
1462                BDBG_MSG(("Addr [%#x] = %#x", PacketRegisterOffset, Register)) ;
1463#endif                         
1464                PacketRegisterOffset += 4 ;     
1465        }
1466       
1467        /* reenable the packet transmission */
1468        BHDM_CHECK_RC(rc, BHDM_EnablePacketTransmission(hHDMI, PhysicalHdmiRamPacketId)) ;
1469       
1470done:
1471        return rc ; 
1472}
1473
1474#endif
1475
1476
Note: See TracBrowser for help on using the repository browser.