| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2011, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: common routines for certification |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | * |
|---|
| 21 | ***************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | #include "bstd.h" |
|---|
| 24 | #include "bkni.h" |
|---|
| 25 | #include "bdbg.h" |
|---|
| 26 | #include "bavc.h" |
|---|
| 27 | #include "bchp_sun_top_ctrl.h" |
|---|
| 28 | |
|---|
| 29 | #include "gist.h" |
|---|
| 30 | #include "cert_common.h" |
|---|
| 31 | #include "ts_psi.h" |
|---|
| 32 | |
|---|
| 33 | BDBG_MODULE(common); |
|---|
| 34 | |
|---|
| 35 | struct comm_state_t commstate; |
|---|
| 36 | |
|---|
| 37 | #define TUNE_FREQ 411000000 |
|---|
| 38 | //#define TUNE_FREQ 723000000 |
|---|
| 39 | #define TUNE_FEC eFEC_ANNEX_B |
|---|
| 40 | #define TUNE_QAM eQAM_Scan |
|---|
| 41 | |
|---|
| 42 | #define VIDEO_PID 2176 |
|---|
| 43 | #define AUDIO_PID 2177 |
|---|
| 44 | #define PCR_PID 2176 |
|---|
| 45 | |
|---|
| 46 | #define ReadReg32(reg) BREG_Read32(GetREG(),reg) |
|---|
| 47 | #define WriteReg32(reg,val) BREG_Write32(GetREG(),reg,val) |
|---|
| 48 | |
|---|
| 49 | extern unsigned int menu_read_number(void); |
|---|
| 50 | |
|---|
| 51 | int comm_decode_init(void); |
|---|
| 52 | |
|---|
| 53 | void comm_init_tuner(void) |
|---|
| 54 | { |
|---|
| 55 | if(NULL == commstate.tuner){ |
|---|
| 56 | bsettop_init(0); |
|---|
| 57 | commstate.tuner = btuner_open(B_ID(0)); |
|---|
| 58 | BDBG_ASSERT(commstate.tuner); |
|---|
| 59 | smessage_init(NULL); |
|---|
| 60 | commstate.display = bdisplay_open(B_ID(0)); |
|---|
| 61 | #if (BCHP_VER>=BCHP_VER_B0) |
|---|
| 62 | commstate.rfm = brfm_open(0); |
|---|
| 63 | #endif |
|---|
| 64 | commstate.freq = TUNE_FREQ; |
|---|
| 65 | commstate.qam = TUNE_QAM; |
|---|
| 66 | /* new settop api access the status register (500ms after ds_task is started) |
|---|
| 67 | even though tuner lock evenrt was not generated it causes system crash by accessing status register */ |
|---|
| 68 | comm_tune(); |
|---|
| 69 | } |
|---|
| 70 | BKNI_Printf("Enter numbers in decimal (1234) or hex (0x1234) format.\n"); |
|---|
| 71 | BKNI_Printf("Enter Frequency in KHz: "); |
|---|
| 72 | commstate.freq = menu_read_number(); |
|---|
| 73 | commstate.freq = commstate.freq * 1000; |
|---|
| 74 | BKNI_Printf("\n"); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | void comm_init_tuner_default(void) |
|---|
| 78 | { |
|---|
| 79 | if(NULL == commstate.tuner){ |
|---|
| 80 | bsettop_init(0); |
|---|
| 81 | commstate.tuner = btuner_open(B_ID(0)); |
|---|
| 82 | BDBG_ASSERT(commstate.tuner); |
|---|
| 83 | smessage_init(NULL); |
|---|
| 84 | commstate.display = bdisplay_open(B_ID(0)); |
|---|
| 85 | #if (BCHP_VER>=BCHP_VER_B0) |
|---|
| 86 | commstate.rfm = brfm_open(0); |
|---|
| 87 | #endif |
|---|
| 88 | } |
|---|
| 89 | commstate.freq = TUNE_FREQ; |
|---|
| 90 | commstate.qam = TUNE_QAM; |
|---|
| 91 | BKNI_Printf("Default tuner frequency is %d\n", commstate.freq); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | int comm_tune(void) |
|---|
| 95 | { |
|---|
| 96 | btuner_params params; |
|---|
| 97 | bband_t tune_result; |
|---|
| 98 | |
|---|
| 99 | if(NULL == commstate.tuner){ |
|---|
| 100 | BDBG_ERR(("Tuner not initialized. Set tuner frequency first.")); |
|---|
| 101 | tune_result = -1; |
|---|
| 102 | goto ExitFunc; |
|---|
| 103 | } |
|---|
| 104 | btuner_params_init(¶ms,commstate.tuner); |
|---|
| 105 | params.qamMode = commstate.qam; |
|---|
| 106 | params.fecMode = TUNE_FEC; |
|---|
| 107 | params.wait_for_lock = 1; |
|---|
| 108 | tune_result = btuner_tune(commstate.tuner,commstate.freq,¶ms); |
|---|
| 109 | if(0 > tune_result){ |
|---|
| 110 | BDBG_ERR(("Tune to %dHz failed\n",commstate.freq)); |
|---|
| 111 | }else{ |
|---|
| 112 | BDBG_ERR(("Tune to %dHz success\n",commstate.freq)); |
|---|
| 113 | } |
|---|
| 114 | ExitFunc: |
|---|
| 115 | return tune_result; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | /* dump memory in hex */ |
|---|
| 119 | void comm_dump_mem(unsigned char * buff, size_t size) |
|---|
| 120 | { |
|---|
| 121 | size_t i; |
|---|
| 122 | |
|---|
| 123 | for(i = 0; i < size; i++){ |
|---|
| 124 | BKNI_Printf(" %02x", buff[i]); |
|---|
| 125 | if(0 == ((i+1)%16)){ |
|---|
| 126 | BKNI_Printf("\n"); |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | BKNI_Printf("\n"); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | /* dump memory in hex */ |
|---|
| 133 | void comm_dump_mem32(unsigned int * buff, size_t size) |
|---|
| 134 | { |
|---|
| 135 | size_t i; |
|---|
| 136 | |
|---|
| 137 | for(i = 0; i < size; i++){ |
|---|
| 138 | BKNI_Printf(" %08x", buff[i]); |
|---|
| 139 | if(0 == ((i+1)%8)){ |
|---|
| 140 | BKNI_Printf("\n"); |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | BKNI_Printf("\n"); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | void comm_decode_params(void) |
|---|
| 147 | { |
|---|
| 148 | BKNI_Printf("Enter numbers in decimal (1234) or hex (0x1234) format.\n"); |
|---|
| 149 | BKNI_Printf("Video pid: "); |
|---|
| 150 | commstate.vpid = menu_read_number(); |
|---|
| 151 | BKNI_Printf("\nAudio pid: "); |
|---|
| 152 | commstate.apid = menu_read_number(); |
|---|
| 153 | BKNI_Printf("\nPcr pid: "); |
|---|
| 154 | commstate.ppid = menu_read_number(); |
|---|
| 155 | BKNI_Printf("\n"); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | void comm_decode_start(void) |
|---|
| 159 | { |
|---|
| 160 | bstream_mpeg mpeg; |
|---|
| 161 | bresult bres; |
|---|
| 162 | bdecode_config cfg; |
|---|
| 163 | bstream_t stream; |
|---|
| 164 | |
|---|
| 165 | bres = comm_decode_init(); |
|---|
| 166 | if(0 != bres){ |
|---|
| 167 | goto ExitFunc; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | mpeg.video[0].pid = commstate.vpid; |
|---|
| 171 | mpeg.video[0].format = BAVC_VideoCompressionStd_eMPEG2; |
|---|
| 172 | mpeg.audio[0].pid = commstate.apid; |
|---|
| 173 | mpeg.audio[0].format = BAVC_AudioCompressionStd_eAc3; |
|---|
| 174 | mpeg.pcr_pid = commstate.ppid; |
|---|
| 175 | stream = bstream_open(TUNER_BAND,&mpeg); |
|---|
| 176 | if(NULL == stream){ |
|---|
| 177 | BDBG_ERR(("Unable to start decode. Already decoding?")); |
|---|
| 178 | goto ExitFunc; |
|---|
| 179 | } |
|---|
| 180 | commstate.stream = stream; |
|---|
| 181 | bres = bdecode_start(commstate.decode, commstate.stream, commstate.decode_w); |
|---|
| 182 | bres = baudio_decode_start(commstate.audio, commstate.display, commstate.stream); |
|---|
| 183 | |
|---|
| 184 | bdecode_get_config(commstate.decode,&cfg); |
|---|
| 185 | cfg.mute = 0; |
|---|
| 186 | bdecode_set_config(commstate.decode,&cfg); |
|---|
| 187 | ExitFunc: |
|---|
| 188 | return; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | void comm_decode_start_ex(uint16_t vpid, uint16_t apid, uint16_t ppid, uint8_t vtype, uint8_t atype) |
|---|
| 192 | { |
|---|
| 193 | bstream_mpeg mpeg; |
|---|
| 194 | bresult bres; |
|---|
| 195 | bdecode_config cfg; |
|---|
| 196 | bstream_t stream; |
|---|
| 197 | |
|---|
| 198 | bres = comm_decode_init(); |
|---|
| 199 | if(0 != bres){ |
|---|
| 200 | goto ExitFunc; |
|---|
| 201 | } |
|---|
| 202 | mpeg.video[0].pid = vpid; |
|---|
| 203 | mpeg.audio[0].pid = apid; |
|---|
| 204 | mpeg.pcr_pid = ppid; |
|---|
| 205 | |
|---|
| 206 | switch (vtype) |
|---|
| 207 | { |
|---|
| 208 | case TS_PSI_ST_AVS_Video: |
|---|
| 209 | mpeg.video[0].format = BAVC_VideoCompressionStd_eAVS; |
|---|
| 210 | break; |
|---|
| 211 | case TS_PSI_ST_14496_10_Video: |
|---|
| 212 | mpeg.video[0].format = BAVC_VideoCompressionStd_eH264; |
|---|
| 213 | break; |
|---|
| 214 | case TS_PSI_ST_SMPTE_VC1: |
|---|
| 215 | mpeg.video[0].format = BAVC_VideoCompressionStd_eVC1; |
|---|
| 216 | break; |
|---|
| 217 | case TS_PSI_ST_14496_2_Video: |
|---|
| 218 | mpeg.video[0].format = BAVC_VideoCompressionStd_eMPEG4Part2; |
|---|
| 219 | break; |
|---|
| 220 | case TS_PSI_ST_13818_2_Video: |
|---|
| 221 | case TS_PSI_ST_ATSC_Video: |
|---|
| 222 | default: |
|---|
| 223 | mpeg.video[0].format = BAVC_VideoCompressionStd_eMPEG2; |
|---|
| 224 | break; |
|---|
| 225 | } |
|---|
| 226 | switch (atype) |
|---|
| 227 | { |
|---|
| 228 | case TS_PSI_ST_11172_3_Audio: |
|---|
| 229 | case TS_PSI_ST_13818_3_Audio: |
|---|
| 230 | mpeg.audio[0].format = BAVC_AudioCompressionStd_eMpegL1; |
|---|
| 231 | break; |
|---|
| 232 | case TS_PSI_ST_ATSC_EAC3: |
|---|
| 233 | mpeg.audio[0].format = BAVC_AudioCompressionStd_eAc3Plus; |
|---|
| 234 | break; |
|---|
| 235 | case TS_PSI_ST_ATSC_AC3: |
|---|
| 236 | default: |
|---|
| 237 | mpeg.audio[0].format = BAVC_AudioCompressionStd_eAc3; |
|---|
| 238 | break; |
|---|
| 239 | } |
|---|
| 240 | stream = bstream_open(TUNER_BAND, &mpeg); |
|---|
| 241 | if (NULL == stream) { |
|---|
| 242 | BDBG_ERR(("Unable to start decode. Already decoding?")); |
|---|
| 243 | goto ExitFunc; |
|---|
| 244 | } |
|---|
| 245 | commstate.stream = stream; |
|---|
| 246 | bres = bdecode_start(commstate.decode, commstate.stream, commstate.decode_w); |
|---|
| 247 | bres = baudio_decode_start(commstate.audio, commstate.display, commstate.stream); |
|---|
| 248 | |
|---|
| 249 | bdecode_get_config(commstate.decode,&cfg); |
|---|
| 250 | cfg.mute = 0; |
|---|
| 251 | bdecode_set_config(commstate.decode,&cfg); |
|---|
| 252 | ExitFunc: |
|---|
| 253 | return; |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | void comm_decode_stop(void) |
|---|
| 257 | { |
|---|
| 258 | if(NULL != commstate.stream){ |
|---|
| 259 | bdecode_stop(commstate.decode); |
|---|
| 260 | baudio_decode_stop(commstate.audio); |
|---|
| 261 | bstream_close(commstate.stream); |
|---|
| 262 | commstate.stream = NULL; |
|---|
| 263 | } |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | void comm_decode_status() |
|---|
| 267 | { |
|---|
| 268 | bdecode_status status; |
|---|
| 269 | |
|---|
| 270 | if (commstate.decode != NULL) { |
|---|
| 271 | bdecode_get_status(commstate.decode, &status); |
|---|
| 272 | BDBG_WRN(("width:%d height:%d", status.source_width, status.source_height)); |
|---|
| 273 | } |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | void comm_hdcp_callback(bool auth_valid) |
|---|
| 277 | { |
|---|
| 278 | return; |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | int comm_decode_init(void) |
|---|
| 282 | { |
|---|
| 283 | int res; |
|---|
| 284 | res = 1; /* failure */ |
|---|
| 285 | if(NULL == commstate.display){ |
|---|
| 286 | BKNI_Printf("Error: did you forget to tune?\n"); |
|---|
| 287 | goto ExitFunc; |
|---|
| 288 | } |
|---|
| 289 | if(NULL == commstate.decode){ |
|---|
| 290 | commstate.decode = bdecode_open(0); |
|---|
| 291 | BDBG_ASSERT(commstate.decode); |
|---|
| 292 | |
|---|
| 293 | /* this function returns NULL do no check result */ |
|---|
| 294 | commstate.decode_w = bdecode_window_open(0, commstate.display); |
|---|
| 295 | |
|---|
| 296 | commstate.audio = baudio_decode_open(B_ID(0)); |
|---|
| 297 | /* open hdmi output */ |
|---|
| 298 | bsettop_hdmi_open(&commstate.hdmi, commstate.display, commstate.audio, comm_hdcp_callback); |
|---|
| 299 | } |
|---|
| 300 | res = 0; |
|---|
| 301 | ExitFunc: |
|---|
| 302 | return res; |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | void comm_decode_params_default(void) |
|---|
| 306 | { |
|---|
| 307 | commstate.vpid = VIDEO_PID; |
|---|
| 308 | BKNI_Printf("Video pid: %8d", commstate.vpid); |
|---|
| 309 | commstate.apid = AUDIO_PID; |
|---|
| 310 | BKNI_Printf("\nAudio pid: %8d", commstate.apid); |
|---|
| 311 | commstate.ppid = PCR_PID; |
|---|
| 312 | BKNI_Printf("\nPcr pid: %8d", commstate.ppid); |
|---|
| 313 | BKNI_Printf("\n"); |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | void comm_reset(void) |
|---|
| 317 | { |
|---|
| 318 | uint32_t value; |
|---|
| 319 | |
|---|
| 320 | value = ReadReg32(BCHP_SUN_TOP_CTRL_RESET_SOURCE_ENABLE); |
|---|
| 321 | value |= BCHP_SUN_TOP_CTRL_RESET_SOURCE_ENABLE_sw_master_reset_enable_MASK; |
|---|
| 322 | WriteReg32(BCHP_SUN_TOP_CTRL_RESET_SOURCE_ENABLE, value); |
|---|
| 323 | value = ReadReg32(BCHP_SUN_TOP_CTRL_SW_MASTER_RESET); |
|---|
| 324 | value |= BCHP_SUN_TOP_CTRL_SW_MASTER_RESET_chip_master_reset_MASK; |
|---|
| 325 | WriteReg32(BCHP_SUN_TOP_CTRL_SW_MASTER_RESET, value); |
|---|
| 326 | } |
|---|