1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 // File Name: mhal_CEC.c
94 // Description: For CEC functions.
95 ////////////////////////////////////////////////////////////////////////////////
96
97
98 #define _MHAL_CEC_C_
99
100 #ifdef MSOS_TYPE_LINUX_KERNEL
101 #include <linux/string.h>
102 #else
103 #include "string.h"
104 #endif
105 #include "MsCommon.h"
106 #include "cec_hwreg_utility2.h"
107 #include "cec_Analog_Reg.h"
108 #include "MsOS.h"
109 #include "apiCEC.h"
110 #include "MsIRQ.h"
111 #include "mhal_CEC.h"
112 #include "asmCPU.h"
113
114 MS_VIRT CEC_RIU_BASE;
115
116 #define PM_REG_WRITE MDrv_WriteByte
117 #define PM_REG_READ MDrv_ReadByte
118
119
120 #define MST_XTAL_CLOCK_HZ (12000000UL) /* Temp define */
121
122 #define _NOP_ MAsm_CPU_Nop();
123
124 #if(defined(CONFIG_MLOG))
125 #include "ULog.h"
126
127 #define MHAL_CEC_MSG_INFO(format, args...) //ULOGI("CEC", format, ##args)
128 #define MHAL_CEC_MSG_WARNING(format, args...) ULOGW("CEC", format, ##args)
129 #define MHAL_CEC_MSG_DEBUG(format, args...) ULOGD("CEC", format, ##args)
130 #define MHAL_CEC_MSG_ERROR(format, args...) ULOGE("CEC", format, ##args)
131 #define MHAL_CEC_MSG_FATAL(format, args...) ULOGF("CEC", format, ##args)
132
133 #else
134 #define MHAL_CEC_MSG_INFO(format, args...) //printf(format, ##args)
135 #define MHAL_CEC_MSG_WARNING(format, args...) printf(format, ##args)
136 #define MHAL_CEC_MSG_DEBUG(format, args...) printf(format, ##args)
137 #define MHAL_CEC_MSG_ERROR(format, args...) printf(format, ##args)
138 #define MHAL_CEC_MSG_FATAL(format, args...) printf(format, ##args)
139
140 #endif
141
mhal_CEC_PortSelect(MsCEC_INPUT_PORT InputPort)142 void mhal_CEC_PortSelect(MsCEC_INPUT_PORT InputPort)
143 {
144
145 }
146
mhal_CEC_init_riu_base(MS_VIRT u32riu_base,MS_VIRT u32PMriu_base)147 void mhal_CEC_init_riu_base(MS_VIRT u32riu_base, MS_VIRT u32PMriu_base)
148 {
149 CEC_RIU_BASE = u32PMriu_base;
150 }
151
152
mhal_CEC_HeaderSwap(MS_U8 value)153 MS_U8 mhal_CEC_HeaderSwap(MS_U8 value)
154 {
155 return(((value&0x0f)<<4)+((value&0xf0)>>4));
156 }
157
mhal_CEC_SendFrame(MS_U8 header,MS_U8 opcode,MS_U8 * operand,MS_U8 len)158 MS_U8 mhal_CEC_SendFrame(MS_U8 header, MS_U8 opcode, MS_U8* operand, MS_U8 len)
159 {
160 MS_U8 i, cnt, *ptr, res;
161 MS_U8 u8waitcnt;
162
163 // clear CEC TX INT status
164 PM_REG_WRITE(H_BK_CEC(0x12), 0x0E);
165 PM_REG_WRITE(H_BK_CEC(0x12), 0x00);
166 PM_REG_WRITE( L_BK_CEC(0x18), header );
167 PM_REG_WRITE( H_BK_CEC(0x18), opcode );
168
169 MHAL_CEC_MSG_INFO("\r\n/******** CEC Tx **********/\r\n");
170 MHAL_CEC_MSG_INFO("CEC Tx FIFO= 0x%x", (MS_U8)header);
171 MHAL_CEC_MSG_INFO(" 0x%x", (MS_U8)opcode);
172
173 if(len > 0)
174 {
175 ptr=operand;
176 for(i=0;i<len;i++)
177 {
178 PM_REG_WRITE( L_BK_CEC(0x19)+i , *(ptr+i) );
179 MHAL_CEC_MSG_INFO(" 0x%x", *(operand+i));
180 }
181 MHAL_CEC_MSG_INFO("\r\n/**************************/\r\n");
182 }
183
184 if((PM_REG_READ(L_BK_CEC(0x05))== 1) && (PM_REG_READ(H_BK_CEC(0x05))== 0)) // CEC idle
185 {
186 MHAL_CEC_MSG_INFO("*** CEC idle!!! ***\n");
187
188 // CEC transmit length
189 //if((opcode==0x00)&&(operand==NULL)&&(len==0))
190 if((opcode==0x00)&&(len==0))
191 {
192 PM_REG_WRITE(L_BK_CEC(0x00), 0); //polling message
193 u8waitcnt = 5;
194 }
195 else
196 {
197 PM_REG_WRITE(L_BK_CEC(0x00), (len+1));
198 u8waitcnt = 4 * (len+2);
199 }
200
201 //The total time,
202 //(1). successful, 4.5 ms + 10 * 2.4 ms * N = 4.5 ms + 24 * N
203 // = 28.5 ms (1), or 52.5 ms (2), ....
204 //(2). NAK, (4.5 ms + 10 * 2.4 ms) * 1 + (4.5 ms + 10 * 2.4 ms +7.2 ms(3 bit time)) * retry (3)
205 // = 28.5 + 35.2 * 3 = 133.6 ms
206
207 cnt=0;
208 MsOS_DelayTask(20);
209
210 do
211 {
212 MsOS_DelayTask(10);
213 if(cnt++>=u8waitcnt)
214 break;
215 } while((PM_REG_READ(H_BK_CEC(0x11))&0x0E)==0);
216 res = (PM_REG_READ(H_BK_CEC(0x11))&0x0E);
217
218 if(cnt>=u8waitcnt)
219 res |= E_CEC_SYSTEM_BUSY;
220
221 // clear CEC TX INT status
222 PM_REG_WRITE(H_BK_CEC(0x12), 0x0E);
223 PM_REG_WRITE(H_BK_CEC(0x12), 0x00);
224 }
225 else
226 {
227 MHAL_CEC_MSG_INFO("*** system busy!!! ***\n");
228
229 res = E_CEC_SYSTEM_BUSY;
230 }
231
232 return res;
233 }
234
mhal_CEC_SendFramex(MS_U8 header,MS_U8 opcode,MS_U8 * operand,MS_U8 len)235 MS_U8 mhal_CEC_SendFramex(MS_U8 header, MS_U8 opcode, MS_U8* operand, MS_U8 len)
236 {
237 MS_U8 i, cnt, *ptr, res;
238 MS_U8 u8waitcnt;
239 volatile MS_U16 k, m;
240 // clear CEC TX INT status
241 PM_REG_WRITE(H_BK_CEC(0x12), 0x0E);
242 PM_REG_WRITE(H_BK_CEC(0x12), 0x00);
243 PM_REG_WRITE( L_BK_CEC(0x18), header );
244 PM_REG_WRITE( H_BK_CEC(0x18), opcode );
245
246 MHAL_CEC_MSG_INFO("\r\n/******** CEC Tx **********/\r\n");
247 MHAL_CEC_MSG_INFO("CEC Tx FIFO= 0x%x", (MS_U8)header);
248 MHAL_CEC_MSG_INFO(" 0x%x", (MS_U8)opcode);
249
250 if(len > 0)
251 {
252 ptr=operand;
253 for(i=0;i<len;i++)
254 {
255 PM_REG_WRITE( L_BK_CEC(0x19)+i , *(ptr+i) );
256 MHAL_CEC_MSG_INFO(" 0x%x", *(operand+i));
257 }
258 MHAL_CEC_MSG_INFO("\r\n/**************************/\r\n");
259 }
260
261 if((PM_REG_READ(L_BK_CEC(0x05))== 1) && (PM_REG_READ(H_BK_CEC(0x05))== 0)) // CEC idle
262 {
263 MHAL_CEC_MSG_INFO("*** CEC idle!!! ***\n");
264
265 // CEC transmit length
266 //if((opcode==0x00)&&(operand==NULL)&&(len==0))
267 if((opcode==0x00)&&(len==0))
268 {
269 PM_REG_WRITE(L_BK_CEC(0x00), 0); //polling message
270 u8waitcnt = 5;
271 }
272 else
273 {
274 PM_REG_WRITE(L_BK_CEC(0x00), (len+1));
275 u8waitcnt = 30;
276 }
277
278 //The total time,
279 //(1). successful, 4.5 ms + 10 * 2.4 ms * N = 4.5 ms + 24 * N
280 // = 28.5 ms (1), or 52.5 ms (2), ....
281 //(2). NAK, (4.5 ms + 10 * 2.4 ms) * 1 + (4.5 ms + 10 * 2.4 ms +7.2 ms(3 bit time)) * retry (3)
282 // = 28.5 + 35.2 * 3 = 133.6 ms
283
284
285 cnt=0;
286 //MsOS_DelayTask(20);
287 for(k = 0; k< 20000; k++)
288 {
289 _NOP_
290 _NOP_
291 _NOP_
292 }
293
294
295 do
296 {
297 //MsOS_DelayTask(10);
298 for(k = 0; k< 20000; k++)
299 {
300 for(m=0;m<50;m++)
301 {
302 _NOP_
303 _NOP_
304 _NOP_
305 _NOP_
306 _NOP_
307 }
308 }
309 if(cnt++>=u8waitcnt)
310 break;
311 } while((PM_REG_READ(H_BK_CEC(0x11))&0x0E)==0);
312
313 res = (PM_REG_READ(H_BK_CEC(0x11))&0x0E);
314
315 if(cnt>=u8waitcnt)
316 res |= E_CEC_SYSTEM_BUSY;
317
318 // clear CEC TX INT status
319 PM_REG_WRITE(H_BK_CEC(0x12), 0x0E);
320 PM_REG_WRITE(H_BK_CEC(0x12), 0x00);
321 }
322 else
323 {
324 MHAL_CEC_MSG_INFO("*** system busy!!! ***\n");
325
326 res = E_CEC_SYSTEM_BUSY;
327 }
328
329 return res;
330 }
331
332
mhal_CEC_SetMyAddress(MS_U8 mylogicaladdress)333 void mhal_CEC_SetMyAddress(MS_U8 mylogicaladdress)
334 {
335 PM_REG_WRITE(L_BK_CEC(0x02), (PM_REG_READ(L_BK_CEC(0x02)) & 0x0F) |(mylogicaladdress<<4));
336 }
337
mhal_CEC_INTEn(MS_BOOL bflag)338 void mhal_CEC_INTEn(MS_BOOL bflag)
339 {
340 if(bflag) // unmask
341 PM_REG_WRITE(L_BK_CEC(0x13), 0x1E); //REG_HDMI_INT_MASK
342
343 else // Mask CEC interrupt
344 #if ENABLE_CEC_MULTIPLE
345 PM_REG_WRITE(L_BK_CEC(0x13), 0x7F); //REG_HDMI_INT_MASK
346 #else
347 PM_REG_WRITE(L_BK_CEC(0x13), 0x1F); //REG_HDMI_INT_MASK
348 #endif
349
350 }
351
352
mhal_CEC_Init(MS_U32 u32XTAL_CLK_Hz,MsCEC_DEVICELA DeviceLA,MS_U8 ucRetryCnt)353 void mhal_CEC_Init(MS_U32 u32XTAL_CLK_Hz, MsCEC_DEVICELA DeviceLA, MS_U8 ucRetryCnt)
354 {
355 MS_U16 reg_val0, reg_val1;
356
357 #if ENABLE_CEC_INT
358
359 // CEC irq clear
360 PM_REG_WRITE(H_BK_CEC(0x12), 0x1F);
361 PM_REG_WRITE(H_BK_CEC(0x12), 0x00);
362 // CEC irq mask control -only enable CEC rx irq
363 PM_REG_WRITE(L_BK_CEC(0x13), 0x1E);
364 // CEC interrupt mask for PM/normal function
365 PM_REG_WRITE(L_BK_CEC(0x30), 0x08); // 11_30[3] = 1 Interrupt clear type select (Level), clear by itself
366
367 #endif
368
369 PM_REG_WRITE(L_BK_CEC(0x14),0x01); // [1]: clock source from Xtal;[0]: Power down CEC controller select
370 PM_REG_WRITE(H_BK_CEC(0x03),PM_REG_READ(H_BK_CEC(0x03))&(~ BIT(4))); // [4]: Standby mode;
371 PM_REG_WRITE(H_BK_CEC(0x00),0x10|ucRetryCnt); // retry times
372 PM_REG_WRITE(L_BK_CEC(0x01),0x80); // [5]:CEC clock no gate; [7]: Enable CEC controller
373 PM_REG_WRITE(H_BK_CEC(0x01),(BusFreeTime<<4)|(ReTxInterval)); // CNT1=ReTxInterval; CNT2=BusFreeTime;
374 PM_REG_WRITE(L_BK_CEC(0x02),(DeviceLA<<4)|(FrameInterval)); // CNT3=FrameInterval; [7:4]=logical address: TV
375 #if ENABLE_CEC_MULTIPLE
376 PM_REG_WRITE(L_BK_CEC(0x30),PM_REG_READ(L_BK_CEC(0x30))|BIT(0)); // enable CEC multiple function
377 #endif
378 //reg_val0=(u32XTAL_CLK_Hz%100000l)*0.00016+0.5;
379 reg_val0=((u32XTAL_CLK_Hz%100000UL)*160+500000UL)/1000000UL;
380
381 PM_REG_WRITE(H_BK_CEC(0x02),(u32XTAL_CLK_Hz/100000UL)); // CEC time unit by Xtal(integer)
382 reg_val1 = PM_REG_READ(L_BK_CEC(0x03));
383 PM_REG_WRITE(L_BK_CEC(0x03), ((reg_val1 & 0xF0) | reg_val0)); // CEC time unit by Xtal(fractional)
384
385 PM_REG_WRITE(L_BK_CEC(0x11), 0xFF); // clear CEC status
386
387
388 }
389
mhal_CEC_IsMessageReceived(void)390 MS_BOOL mhal_CEC_IsMessageReceived(void)
391 {
392 return (PM_REG_READ(H_BK_CEC(0x11))& 0x01 ? TRUE : FALSE);
393 }
394
mhal_CEC_ReceivedMessageLen(void)395 MS_U8 mhal_CEC_ReceivedMessageLen(void)
396 {
397 return ((PM_REG_READ(L_BK_CEC(0x04)) & 0x1F) + 1);
398 }
399
mhal_CEC_GetMessageByte(MS_U8 idx)400 MS_U8 mhal_CEC_GetMessageByte(MS_U8 idx)
401 {
402 return (PM_REG_READ(L_BK_CEC(0x20) + idx));
403 }
404
mhal_CEC_ClearRxStatus(void)405 void mhal_CEC_ClearRxStatus(void)
406 {
407 // clear RX INT status
408 PM_REG_WRITE(H_BK_CEC(0x12), 0x11);
409 PM_REG_WRITE(H_BK_CEC(0x12), 0x00);
410 // clear RX NACK status
411 PM_REG_WRITE(L_BK_CEC(0x11), 0xFF);
412 }
413
414 /***************************************************************************************/
415 /// config cec wake up
416 /***************************************************************************************/
417
mhal_CEC_ConfigWakeUp(MS_U8 ucRetryCount,MS_U8 * ucVendorID,MS_U32 u32XTAL_CLK_Hz,MS_U8 * ucPA,MsCEC_DEVICE_TYPE eType,MS_BOOL bIsSrc)418 void mhal_CEC_ConfigWakeUp(MS_U8 ucRetryCount, MS_U8* ucVendorID, MS_U32 u32XTAL_CLK_Hz, MS_U8* ucPA, MsCEC_DEVICE_TYPE eType, MS_BOOL bIsSrc)
419 {
420 MS_U16 reg_val0, reg_val1;
421 MHAL_CEC_MSG_INFO("\r\n Here do the PM config cec wakeup \r\n");
422
423 //XBYTE[0x250C] &= ~BIT0;
424 MDrv_WriteByte( REG_COMBO_PHY0_P0_0C_H, MDrv_ReadByte(REG_COMBO_PHY0_P0_0C_H) &(~ BIT(4)));
425
426
427 //(1) enable chiptop clk_mcu & clk_pram
428 #if 0
429 XBYTE[0x0E00] = 0x03;
430 //enable PM_Sleep's clk_mcu and _pram
431 Drv_WriteByte(L_BK_PMSLP(0x00), 0x03);
432 XBYTE[0x0E01] = 0x0F;
433 //0x0C; Ken 20080916 for calibration to 1Mz
434 MDrv_WriteByte(H_BK_PMSLP(0x00), 0x0F);
435 #endif
436
437
438 //(2) HDMI CEC settings
439 PM_REG_WRITE(H_BK_CEC(0x00),0x10|ucRetryCount); // retry times
440 PM_REG_WRITE(L_BK_CEC(0x01),0x80); // [5]:CEC clock no gate; [7]: Enable CEC controller
441 PM_REG_WRITE(H_BK_CEC(0x01),(BusFreeTime<<4)|(ReTxInterval)); // CNT1=ReTxInterval; CNT2=BusFreeTime;
442 //PM_REG_WRITE(L_BK_CEC(0x02),0x07); // CNT3=7; logical address: TV
443
444 //reg_val0=(MST_XTAL_CLOCK_HZ%100000l)*0.00016+0.5;
445 reg_val0=((u32XTAL_CLK_Hz%100000UL)*160+500000UL)/1000000UL;
446
447 PM_REG_WRITE(H_BK_CEC(0x02),(u32XTAL_CLK_Hz/100000l)); // CEC time unit by Xtal(integer)
448
449 reg_val1 = PM_REG_READ(L_BK_CEC(0x03));
450 PM_REG_WRITE(L_BK_CEC(0x03), ((reg_val1 & 0xF0) | reg_val0)); // CEC time unit by Xtal(fractional)
451
452
453 //(3) PM Sleep: wakeup enable sources
454 //PM_REG_WRITE(L_BK_PMMCU(0x00),0x01); // reg_cec_enw
455
456
457 //(4) PM CEC power down controller settings
458 // Mask CEC interrupt in standby mode
459 PM_REG_WRITE(L_BK_CEC(0x13),0xFF);
460 // select power down SW CEC controller
461 PM_REG_WRITE(L_BK_CEC(0x14),0x01); // [1]: clock source from Xtal;[0]: Power down CEC controller select
462 PM_REG_WRITE(L_BK_CEC(0x01),0x00); // [5]:CEC clock no gate; [7]: Disable CEC controller
463 PM_REG_WRITE(L_BK_CEC(0x01),0x80); // [5]:CEC clock no gate; [7]: Enable CEC controller
464 #if 0//ENABLE_SW_CEC_WAKEUP
465 PM_REG_WRITE(H_BK_CEC(0x03),PM_REG_READ(H_BK_CEC(0x03))&(~ BIT(4))); // [4]: Standby mode;
466 #else
467 PM_REG_WRITE(H_BK_CEC(0x03),PM_REG_READ(H_BK_CEC(0x03))|(BIT(4))); // [4]: sleep mode;
468 #endif
469
470
471 //(5) PM CEC wakeup opcode settings
472 // OPCODE0: N/A
473 // OPCODE1: N/A
474 // OPCODE2: 0x44 0x40(Power)
475 // 0x44 0x6D(Power ON Function)
476 // OPCODE3: N/A
477 // OPCODE4: 0x86(Set stream path)
478 PM_REG_WRITE(L_BK_CEC(0x07), 0x34); // Enable OP2 and OP4
479 PM_REG_WRITE(H_BK_CEC(0x07), 0x24); // Eanble OPCODE2's operand
480
481 PM_REG_WRITE(L_BK_CEC(0x09), E_MSG_UI_PRESS); // OPCODE2: User Control Pressed
482 PM_REG_WRITE(H_BK_CEC(0x0B), E_MSG_UI_POWER); // OPCODE2 operand: Power
483 PM_REG_WRITE(L_BK_CEC(0x0C), E_MSG_UI_POWER_ON_FUN); // OPCODE2 operand: Power ON Function
484
485 PM_REG_WRITE(L_BK_CEC(0x0A), E_MSG_RC_SET_STREM_PATH); // OPCODE4: Set stream path
486
487 // [2:0]: CEC version 1.4; [7]: OP4 is broadcast message
488 PM_REG_WRITE(H_BK_CEC(0x0D), 0x80 | HDMI_CEC_VERSION);
489
490
491 //(6) Device(TV) Vendor ID for customer (Big Endian)
492 // It depends end-customer's vendor ID
493 MHAL_CEC_MSG_INFO("!!!!!!!!!!!!!!!!!!!Change this Vendor ID according to customer!!!!!!!!!!!!!!!!\n");
494 PM_REG_WRITE(L_BK_CEC(0x0F), ucVendorID[0]); // Device Vendor ID
495 PM_REG_WRITE(H_BK_CEC(0x0F), ucVendorID[1]); // Device Vendor ID
496 PM_REG_WRITE(L_BK_CEC(0x10), ucVendorID[2]); // Device Vendor ID
497
498 // [2:0]: Feature abort reason - "Not in correct mode to respond"
499 PM_REG_WRITE(H_BK_CEC(0x10), E_MSG_AR_CANNOTRESPOND );
500
501
502 //(7) Device Physical address: default is 0x00 0x00 0x00
503 /*PM_REG_WRITE(L_BK_CEC(0x0E), 0x00); // Physical address 0.0
504 PM_REG_WRITE(H_BK_CEC(0x0E), 0x00); // Physical address 0.0
505 PM_REG_WRITE(H_BK_CEC(0x14), 0x00); // Device type: TV*/
506 PM_REG_WRITE(L_BK_CEC(0x0E), ucPA[0]); // Physical address 0.0
507 PM_REG_WRITE(H_BK_CEC(0x0E), ucPA[1]); // Physical address 0.0
508 PM_REG_WRITE(H_BK_CEC(0x14), eType & 0xFF); // Device type: TV*/
509
510
511 //(8) Clear CEC status
512 PM_REG_WRITE(L_BK_CEC(0x11), 0x7F); // Clear CEC wakeup status
513 PM_REG_WRITE(H_BK_CEC(0x12), 0x1F); // Clear RX/TX/RF/LA/NACK status status
514 PM_REG_WRITE(H_BK_CEC(0x12), 0x00);
515 }
516
mhal_CEC_Enabled(MS_BOOL bEnableFlag)517 void mhal_CEC_Enabled(MS_BOOL bEnableFlag)
518 {
519 if(bEnableFlag)
520 PM_REG_WRITE(L_BK_CEC(0x01),0x80); //Enable PM CEC controller
521 else
522 PM_REG_WRITE(L_BK_CEC(0x01),0x00); //Disable PM CEC controller
523 }
524
mhal_CEC_TxStatus(void)525 MS_U8 mhal_CEC_TxStatus(void)
526 {
527 return (PM_REG_READ(H_BK_CEC(0x11))&0x0E);
528 }
529
mhal_CEC_Device_Is_Tx(void)530 MS_BOOL mhal_CEC_Device_Is_Tx(void)
531 {
532 return CEC_DEVICE_IS_SOURCE;
533 }
mhal_CEC_SetRetryCount(MS_U8 ucRetryCount)534 void mhal_CEC_SetRetryCount(MS_U8 ucRetryCount)
535 {
536 PM_REG_WRITE(H_BK_CEC(0x00),ucRetryCount|(PM_REG_READ(H_BK_CEC(0x00))& 0xF8)); // retry times
537 }
538
539 #if ENABLE_CEC_MULTIPLE
mhal_CEC_SetMyAddress2(MS_U8 mylogicaladdress)540 void mhal_CEC_SetMyAddress2(MS_U8 mylogicaladdress)
541 {
542 PM_REG_WRITE(H_BK_CEC(0x30), (PM_REG_READ(H_BK_CEC(0x30)) & 0xF0) |(mylogicaladdress));
543 }
544
mhal_CEC_IsMessageReceived2(void)545 MS_BOOL mhal_CEC_IsMessageReceived2(void)
546 {
547 return (PM_REG_READ(H_BK_CEC(0x11))& 0x20 ? TRUE : FALSE);
548 }
549
mhal_CEC_ReceivedMessageLen2(void)550 MS_U8 mhal_CEC_ReceivedMessageLen2(void)
551 {
552 return ((PM_REG_READ(L_BK_CEC(0x31)) & 0x1F) + 1);
553 }
554
mhal_CEC_GetMessageByte2(MS_U8 idx)555 MS_U8 mhal_CEC_GetMessageByte2(MS_U8 idx)
556 {
557 return (PM_REG_READ(L_BK_CEC(0x28) + idx));
558 }
559
mhal_CEC_ClearRxStatus2(void)560 void mhal_CEC_ClearRxStatus2(void)
561 {
562 // clear RX INT status
563 PM_REG_WRITE(H_BK_CEC(0x12), 0x60);
564 PM_REG_WRITE(H_BK_CEC(0x12), 0x00);
565 // clear RX NACK status
566 PM_REG_WRITE(L_BK_CEC(0x11), 0xFF);
567 }
568 #endif
569
570
571