source: svn/newcon3bcm2_21bu/nexus/platforms/97552/src/nexus_platform.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 82.5 KB
Line 
1/***************************************************************************
2*     (c)2004-2011 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: nexus_platform.c $
39* $brcm_Revision: 203 $
40* $brcm_Date: 12/15/11 4:26p $
41*
42* API Description:
43*   API name: Platform
44*    Specific APIs to initialize the a board.
45*
46* Revision History:
47*
48* $brcm_Log: /nexus/platforms/97400/src/nexus_platform.c $
49*
50* 203   12/15/11 4:26p vsilyaev
51* SW7425-1140: Merge NEXUS_Cec module support into main-line
52*
53* SW7425-1140/1   12/9/11 5:11p vle
54* SW7425-1140: add NEXUS Cec module
55*
56* 202   12/2/11 6:32p jtna
57* SW7425-1708: add i2c s3 standby power management
58*
59* 201   11/23/11 4:03p jtna
60* SW7425-1708: add s3 power management for security
61*
62* 200   11/22/11 5:51p jtna
63* SW7425-1708: add s3 power management for rfm
64*
65* 199   11/18/11 4:23p jtna
66* SW7425-1708: add s3 power management for pwm
67*
68* 198   11/15/11 4:04p erickson
69* SW7425-1747: remove old code
70*
71* 197   11/11/11 7:07p jtna
72* SW7425-1708: added NEXUS_UartModule_Standby_priv
73*
74* 196   11/11/11 10:55a erickson
75* SW7231-317: fix NEXUS_BASE_ONLY, clean up warnings, simplify
76*  NEXUS_PlatformConfiguration if no inputs/outputs are defined
77*
78* 195   11/10/11 6:00p jtna
79* SW7425-1709: move NEXUS_DmaModule_Standby_priv prototype to separate,
80*  private header file
81*
82* 194   11/8/11 6:00p jtna
83* SW7425-1709: make use of BMMD_Standby/Resume
84*
85* 193   11/1/11 2:51p erickson
86* SW7231-391: fix naming, warnings
87*
88* 192   11/1/11 11:21a erickson
89* SW7231-391: add macro to test if nexus class exists
90*
91* 191   10/31/11 7:49p bandrews
92* SW7231-391: merge to main
93*
94* SW7420-2078/5   10/31/11 7:35p bandrews
95* SW7231-391: added dependency from display to transport for timebase
96*  calls
97*
98* 190   10/31/11 5:54p bandrews
99* SW7420-2078: merge to main
100*
101* SW7420-2078/4   10/18/11 7:02p bandrews
102* SW7231-391: remove mention of global_handle attribute
103*
104* SW7420-2078/3   10/11/11 8:23p bandrews
105* SW7420-2078: must untune when releasing platform
106*
107* SW7420-2078/2   10/3/11 7:30p bandrews
108* SW7420-2078: forgot to include class verification header
109*
110* SW7420-2078/1   9/30/11 7:32p bandrews
111* SW7420-2078: added
112*
113* 189   10/24/11 9:47a erickson
114* SW7420-1992: fix warning
115*
116* 188   10/20/11 1:56p erickson
117* SW7420-1992: embed NEXUS_VideoWindowSettings in
118*  NEXUS_SurfaceCompositorDisplaySettings
119*
120* 187   10/19/11 1:11p gmohile
121* SW7420-2103 : Uhf module should ont be locks in active standby
122*
123* 184   9/14/11 2:31p erickson
124* SW7405-5478: add MSG to identify each module as it uninits
125*
126* 183   9/7/11 4:04p gmohile
127* SW7425-533 : Add VCE standby support
128*
129* 182   9/6/11 2:43p erickson
130* SWNOOS-482: pass through file module settings in user mode
131*
132* 181   8/24/11 9:13a erickson
133* SW7420-1993: add input_router
134*
135* 180   8/23/11 4:33p erickson
136* SW7420-1992: rename to surface_compositor
137*
138* 179   8/12/11 3:23p gmohile
139* SW7425-533 : add hdmi out standby
140*
141* 178   8/12/11 11:13a gmohile
142* SW7125-1014 : Ir input should use the active scheduler
143*
144* 177   8/10/11 1:38p erickson
145* SWSECURITY-28: add nsk2hdi module option
146*
147* 176   8/4/11 10:20a gmohile
148* SW7425-692 : Add hdmi input standby
149*
150* 175   7/26/11 1:33p erickson
151* SW7420-1992: add surface_compositor module and examples
152*
153* 174   7/21/11 5:02p gmohile
154* SW7125-1014 : Fix graphics standby include file
155*
156* 173   7/21/11 4:14p gmohile
157* SW7125-1014 : Rework power management
158*
159*
160* 169   6/20/11 5:41p jgarrett
161* SW7425-409: Merging VP6 support to main branch
162*
163* SW7425-409/2   6/13/11 7:21p jgarrett
164* SW7425-409: Changing module startup order to handle video decoder being
165*  dependent on audio
166*
167* SW7425-409/1   6/6/11 7:16p jgarrett
168* SW7425-409: Adding DSP video decoder extensions for VDE
169*
170* 168   5/25/11 9:54a erickson
171* SW7346-214: add security module settings to NEXUS_PlatformSettings
172*
173* 167   5/17/11 2:15p jhaberf
174* SWDTV-6928: Merge of 35233 platform code to the main
175*
176* SWDTV-6928/1   5/4/11 6:25p mstefan
177* SWDTV-6928: merge to main
178*
179* 164   4/16/11 2:14p nickh
180* SW7425-313: Enable MTSIF for platforms that support it
181*
182* 163   4/14/11 4:05p hongtaoz
183* SW7425-344, SW7125-769: clean uninit platform frontend; frontend uninit
184*  is unconditional since power management might opened some resources
185*  independent of frontend open or not;
186*
187* 162   4/13/11 11:30a hongtaoz
188* SW7425-344: uninit frontend module only if it's opened at platform
189*  init;
190*
191* 161   4/8/11 11:02a erickson
192* SW7420-1671: always call NEXUS_Platform_P_InitServer
193*
194* 160   4/7/11 6:15p vsilyaev
195* SW7425-232: Updated file mux module
196*
197* 159   4/7/11 5:25p erickson
198* SW7420-1671: try to exit failed NEXUS_Platform_Init cleanly
199*
200* 158   4/7/11 1:56p gmohile
201* SW7420-1773 : Resume nexus to full power before uninit
202*
203* 157   4/6/11 3:09p erickson
204* SW7420-1671: try to exit failed NEXUS_Platform_Init cleanly
205*
206* 156   4/4/11 6:18p vsilyaev
207* SW7405-5221: Added option to forward debug output to FIFO
208*
209* 155   4/1/11 4:23p jtna
210* SW7346-119: add 40nm allpass support
211*
212* 154   3/16/11 10:27a erickson
213* SW7420-1642: use NEXUS_Base_Settings.driverModuleInit instead of
214*  NEXUS_Platform_P_InitDone
215*
216* 153   3/9/11 1:19p erickson
217* SW7405-3282: reduce NEXUS_Platform_Init stack usage
218*
219* 152   3/8/11 9:15a jrubio
220* SW7325-843: make sure pwm var is not defined unless NEXUS_HAS_PWM is
221*  support, fixes NEXUS_BASE_ONLY
222*
223* 151   2/28/11 3:11p erickson
224* SW7420-1123: refactor server init/uninit for simpler, cleaner app
225*  init/uninit
226*
227* 150   2/28/11 2:37p erickson
228* SW7420-1123: fix indenting & whitespace
229*
230* 149   2/28/11 12:32p erickson
231* SW7335-1188: use NEXUS_HAS_<MODULE> for deciding to init/uninit a
232*  module
233*
234* 148   2/25/11 2:52p gmohile
235* SW7408-210 : Deprecate use of NEXUS_POWER_STANDBY
236*
237* 147   2/17/11 4:24p gmohile
238* SW7408-210 : Merge PM 2.0 support to mainline
239*
240* 146   2/17/11 11:53a hongtaoz
241* SW7425-9: add security support for hdmi_input;
242*
243* 146   2/17/11 11:51a hongtaoz
244* SW7425-9: add security support for hdmi_input;
245*
246* 145   2/16/11 4:39p randyjew
247* SW7344-25:Add 7344 spi frontpanel support using Aon gpios
248*
249* 144   1/21/11 11:33a mphillip
250* SW7420-1403: Error out if Graphics3D fails to initialize
251*
252* 143   1/17/11 4:46p vsilyaev
253* SW7425-65: Added StcChannel to the videoEncoder
254*
255* 142   1/4/11 1:53p erickson
256* SW7422-2: improve NEXUS_Platform_Init error recovery
257*
258* 141   12/26/10 4:17p vsilyaev
259* SW7425-40: Fixed shutdown sequence
260*
261* 140   12/20/10 4:29p erickson
262* SW7422-2: rework nexus_platform_core, add board-specific file and API,
263*  mmap after determining heaps
264*
265* 139   12/17/10 4:39p jtna
266* SW7422-155: init picture decoder
267*
268* 138   12/13/10 7:02p vsilyaev
269* SW7425-40: Added system initialization for the StreamMux and
270*  VideoEncoder modules
271*
272* 137   12/7/10 5:47p erickson
273* SW7420-1148: refactor kernel mode proxy for process isolation
274*
275* 136   12/2/10 7:41p spothana
276* SW7420-1177: Adding nexus hdmi dvo module.
277*
278* SW7420-1177/2   11/5/10 3:23p spothana
279* SW7420-1177: Update nexus hdmi dvo.
280*
281* SW7420-1177/1   11/1/10 8:36p spothana
282* SW7420-1177: Adding nexus hdmi dvo module.
283*
284* 135   11/12/10 10:30a rgreen
285* SW7422-10: Merge Changes
286*
287* SW7422-10/1   11/10/10 2:13p rgreen
288* SW7422-10: Add nexus platform support for hdmiInput
289*
290* 134   10/26/10 11:33a jtna
291* SW7420-887: added temp_monitor
292*
293* SW7420-887/2   10/21/10 7:23p spothana
294* SW7420-887: Correct the coding conventions
295*
296* SW7420-887/1   10/20/10 7:50p spothana
297* SW7420-887: Add temperature module.
298*
299* 133   10/13/10 1:37p vsilyaev
300* SW7550-496: Initialiaze surface prior to the audio module
301*
302* 132   10/12/10 3:25p spothana
303* SW7420-1157 : Match the VDC memory usage in the reference software to
304*  memory worksheet
305*
306* 131   10/12/10 3:13p erickson
307* SW7420-1135: add simple decoder
308*
309* 130   9/29/10 9:48a erickson
310* SW7420-1123: consolidate IPC server header file for now
311*
312* 129   9/29/10 9:33a erickson
313* SW7420-1123: add linux usermode IPC
314*
315* 128   9/24/10 3:31p jtna
316* SW7420-887: added touchpad module
317*
318* 127   9/24/10 1:07p nickh
319* SW7422-10: Add main and PIP memory settings for 7422
320*
321* 126   9/23/10 2:14p erickson
322* SW7420-943: add NFE reverse jump wrappers
323*
324* 125   9/8/10 11:53a vsilyaev
325* SW7468-129: Added video decoder on ZSP
326*
327* 124   8/26/10 4:23p jgarrett
328* SW7408-52: Fixing up 7405 soft audio support
329*
330* 123   8/20/10 12:35p erickson
331* SW7405-3832: add support for non-numeric NEXUS_PLATFORM defines.
332*
333* 122   8/5/10 8:32p VISHK
334* SW7335-813: Add smartcard module settings to the Platform settings.
335*
336* 121   8/4/10 5:01p spothana
337* SW7420-886: Add support for 97410 UMA mode using MEMC0 only.
338*
339* 120   8/4/10 10:55a VISHK
340* SW7335-813: Add smartcard module settings to the Platform settings.
341*
342* 119   8/3/10 5:45p gskerl
343* SW7125-237: Fixed compile error; moved NEXUS_Platform_JoinStandby()
344*  from nexus_platform.c to nexus_platform_standby.c
345*
346* 118   8/3/10 2:46p gskerl
347* SW7125-237: Fixed compile error; only declare
348*  NEXUS_Platform_JoinStandby() if NEXUS_POWER_STANDBY is true
349*
350* 117   8/2/10 6:44p gskerl
351* SW7125-237: Added NEXUS_PlatformJoinStandby API for multiprocess Nexus
352*  in Active Standby mode
353*
354* 116   7/19/10 4:17p jgarrett
355* SW7550-496: Adding surface module handle to audio initialization for
356*  ZSP graphics.
357*
358* SW7550-496/1   7/16/10 5:50p nitinb
359* SW7550-496: For ZSP graphics extension, surface module need to be
360*  initialized before audio module
361*
362* 115   6/24/10 11:52a erickson
363* SW7400-2806: add NEXUS_Platform_GetStatus
364*
365* 114   4/21/10 9:30a erickson
366* SW7420-703: pass NEXUS_SurfaceModuleSettings through
367*  NEXUS_PlatformSettings
368*
369* 113   4/19/10 3:44p nickh
370* SW7420-709: Add 7420DBS support and remove BCHP_CHIP
371*
372* 112   4/14/10 6:40p jtna
373* SW7125-322: Coverity Defect ID:21269 DEADCODE. videoDecoderThread is
374*  not null if MULTITHREADED_INIT=1
375*
376* 111   4/9/10 4:47p katrep
377* SW7405-4089:Fixed segfault in 32UMA mode
378*
379* 110   4/1/10 2:48p rjain
380* SW7550-309: merging back to main
381*
382* SW7550-74/1   1/14/10 11:17a chengli
383* SW7550-74 : smart card freq should be 24MHz for ARIB
384*
385* 109   3/19/10 10:12a erickson
386* SW7405-3832: create standard method for specific
387*  NEXUS_PLATFORM_VERSION. use tagged NEXUS_Platform_Init to enforce
388*  binary compatibility. consolidate NEXUS_Platform_GetReleaseVersion
389*  using standard macros.
390*
391* 108   2/4/10 5:37p jgarrett
392* SW7408-57: Refactoring soft audio startup of TP1
393*
394* 107   2/4/10 3:02p gmohile
395* SW7408-1 : Disable DMA L1 interrupt for 7408 during shutdown
396*
397* 106   1/21/10 6:35p garetht
398* SW7420-553: Add platform for 93380vms
399*
400* 105   1/15/10 6:02p jgarrett
401* SW7408-17: Adding backtrace support for TP1
402*
403* 104   12/30/09 2:53p nitinb
404* SW7550-146: Correcting the conditions for
405*  NEXUS_TRANSPORT_BEFORE_SECURITY
406*
407* 103   12/29/09 12:51p erickson
408* SW7550-146: allow security module to be initialized after the transport
409*  module if HW requires it
410*
411* 102   12/23/09 1:10p rjain
412* SW7550-146: For 7550, first init transport module, then security
413*
414* 101   12/15/09 4:30p erickson
415* SW7400-2629: add NEXUS_Platform_ReadRegister and
416*  NEXUS_Platform_WriteRegister
417*
418* 100   12/1/09 5:37p katrep
419* SW7335-627:user proper defines for conditional code for NEXUS_BASE_ONLY
420*
421* 99   11/30/09 3:13p jrubio
422* SW7335-627: fixed for NEXUS_BASE_ONLY
423*
424* 98   11/18/09 1:31p gmohile
425* SW7408-1 : Fix warning
426*
427* 97   11/12/09 3:37p gmohile
428* SW7408-1 : Update 7408 support
429*
430* 96   11/12/09 2:26p gmohile
431* SW7405-3395 : Fix use of NEXUS_FPGA_SUPPORT
432*
433* 95   11/6/09 9:50a erickson
434* SW7405-3350: move surface module handle to NEXUS_PlatformHandles
435*
436* 94   11/6/09 9:48a erickson
437* SWDEPRECATED-3881: fix code for platforms with < 3 displays
438*
439* 93   11/4/09 1:59p mward
440* SWDEPRECATED-3881: Support 3 display operation.
441*
442* 92   10/22/09 2:00p erickson
443* SW7405-3267: move NEXUS_KEYPAD_GPIO to nexus_platform_features.h
444*
445* 91   10/16/09 1:42p erickson
446* SWDEPRECATED-3881: default NEXUS_PlatformConfiguration values based on
447*  #defines
448*
449* 90   9/17/09 5:20p mward
450* SW7400-2529: Coverity Defect ID:18807 DEADCODE audioThread is only used
451*  if MULTITHREADED_INIT.
452*
453* 89   8/28/09 4:00p jgarrett
454* SW7405-2928: Adding multichannel capture support
455*
456* 88   8/25/09 6:44p jrubio
457* SW7340-10: fix GPIO setting for SPI Frontpanel
458*
459* 87   8/19/09 1:34p jrubio
460* PR55882: add 7340/7342
461*
462* 86   8/5/09 4:39p katrep
463* PR56569: add nexus platfrom get sw version api
464*
465* 85   8/5/09 12:04p katrep
466* PR56569: platfrom sofftware release version
467*
468* 84   7/29/09 4:23p nickh
469* PR56017: Add 7420B0 support for display heap settings
470*
471* 83   7/10/09 4:34p erickson
472* PR56558: use NEXUS_DisplayModule_SetVideoDecoderModule to speed up init
473*
474* 82   7/9/09 10:00a erickson
475* PR56558: no multi-threaded module init for linux kernel mode
476*
477* 81   7/2/09 10:46a erickson
478* PR56558: multithreaded module initialization
479*
480* 80   7/2/09 10:43a erickson
481* PR56558: make NEXUS_Platform_InitFrontend a public function, callable
482*  after NEXUS_Platform_Init if NEXUS_PlatformSettings.openFrontend =
483*  false.
484*
485* 79   6/23/09 11:59p mphillip
486* PR54926: Add a hook to allow customization at the end of
487*  NEXUS_Platform_Init
488*
489* 78   6/15/09 12:08a nickh
490* PR55967: Fix compile error
491*
492* 77   6/12/09 10:51a erickson
493* PR55967: convert NEXUS_DisplayModuleSettings heap settings to integers.
494*  This makes them settable in the application.
495*
496* 76   6/5/09 7:29p rjlewis
497* PR55287: missing initializer.
498*
499* 75   5/22/09 11:39a vishk
500* PR 54842: rockford/unittests/nexus/general/boot should test
501*  NEXUS_PlatformSettings options
502*
503* 74   5/22/09 11:33a vishk
504* PR 54842: rockford/unittests/nexus/general/boot should test
505*  NEXUS_PlatformSettings options
506*
507* 73   5/13/09 4:52p jtna
508* PR54809: guard against unpaired init and uninits
509*
510* 72   5/12/09 4:33p erickson
511* PR52109: added call to NEXUS_Platform_P_UninitInterrupts
512*
513* 71   5/12/09 4:18p erickson
514* PR52109: move g_NEXUS_platformModule for more general use
515*
516* 70   5/11/09 4:02p jtna
517* PR54515: make transport module handle available globally
518*
519* 69   4/27/09 6:18p jrubio
520* PR44849: fix splash, add NEXUS_BASE_ONLY support
521*
522* 68   4/21/09 11:46a vishk
523* PR 54381: Nexus smartcard module setting not configurable
524*
525* 67   4/20/09 3:22p vishk
526* PR 54381: Nexus smartcard module setting not configurable
527*
528* 66   4/9/09 11:46a jrubio
529* PR52188: add support for 2nd Receiver
530*
531* 65   4/8/09 4:31p vsilyaev
532* PR 54016: Added support for precompiled header
533*
534* 64   3/30/09 10:36a erickson
535* PR50748: support the secure heap using module settings handle
536*
537* 63   3/27/09 10:33a erickson
538* PR48963: set 7420 heaps for main and pip
539*
540* 62   3/20/09 2:54p katrep
541* PR53323: Fixed typo for NEXUS_HAS_IR_INPUT
542*
543* 61   3/19/09 4:59p erickson
544* PR53323: add more #if so that more modules can be optionally removed
545*
546* 60   3/9/09 2:33p erickson
547* PR50748: add multi-heap support
548*
549* 59   1/30/09 3:52p katrep
550* PR50567: Disabled UHF input for 97466
551*
552* 58   1/28/09 6:27p vsilyaev
553* PR 51392: Moved magnum initialization from Nexus base to the platform.
554*  Initialize only magnum layer inside of
555*  NEXUS_Platform_GetDefaultSettings
556*
557* 57   1/26/09 12:35p erickson
558* PR51468: global variable naming convention
559*
560* 56   1/22/09 3:40p shyam
561* PR50142 : Add Transcoder Uninit to the platform uninit function
562*
563* 55   12/30/08 2:34p jgarrett
564* PR 50409: Adding DVB-CI for 97325
565*
566* 54   12/24/08 12:40p jgarrett
567* PR 50703: Allowing build without security module
568*
569* 53   12/21/08 6:25p nickh
570* PR50605: Fix compile errors when running without Security
571*
572* 52   12/19/08 11:07a erickson
573* PR35457: give stronger ERR message when NEXUS_Platform_Init fails
574*
575* 51   12/17/08 1:48p katrep
576* PR49875: Add support for 7466
577*
578* 50   12/3/08 3:06p erickson
579* PR48963: remove stripeWidth setting. no longer needed for Graphics2D
580*  init.
581*
582* 49   11/3/08 4:49p katrep
583* PR48628: Add PWM to 7405 build
584*
585* 48   10/9/08 10:15a erickson
586* PR47328: moved NEXUS_Platform_GetStreamerInputBand to frontend.c
587*
588* 47   10/3/08 11:41a shyam
589* PR 40732 : Remove nexus_platform.c warnings
590*
591* 46   9/24/08 6:58p shyam
592* PR40732 : First working transcoder DMA version
593*
594* 45   9/23/08 9:16a jgarrett
595* PR 46513: Merging 97459 support to mainline
596*
597* 44   9/8/08 7:34p shyam
598* PR40732 : Reorganize 97043 platform specific into seperate files
599* PR40732 : Add PCI interrupt support
600*
601* 43   9/2/08 10:27p katrep
602* PR46457: Configure nexus features at the run time based on board strap
603*  options
604*
605* 42   9/2/08 4:45p erickson
606* PR46457: added NEXUS_Platform_GetSettings
607*
608* 41   8/22/08 7:23p erickson
609* PR45795: remove maxOutputFormat from config
610*
611* 40   8/5/08 9:06a erickson
612* PR45422: transport requires security for DivX DRM
613*
614* 39   7/31/08 5:19p vsilyaev
615* PR 45137: Initial support for multi application mode
616*
617* 38   7/23/08 2:16p erickson
618* PR44598: NEXUS_Platform_GetDefaultSettings must call NEXUS_Base_Init so
619*  that GetDefaultSettings can use Magnum
620*
621* 37   7/22/08 3:03p erickson
622* PR44598: move some module settings into NEXUS_PlatformSettings to allow
623*  app to customize init.
624*
625* 36   7/18/08 10:21a erickson
626* PR44919: move VideoDecoder heap customization into
627*  nexus_platform_features.h
628*
629* PR44830/2   9/17/08 4:41p anilmm
630* PR44830:  Replaced BCM_BOARD macro
631*
632* PR44830/1   7/18/08 11:05a anilmm
633* PR44830: Add support for 97459
634*
635* 35   7/11/08 5:10p jtna
636* PR42924: Add channel change measurements functionality
637*
638* 34   7/11/08 12:45p mphillip
639* PR40869: Initialize Graphics3D module
640*
641* 33   7/7/08 10:20a jrubio
642* PR42353: change secure heap size for 7325/7335 same as 7405
643*
644* 32   7/3/08 4:50p erickson
645* PR44586: NEXUS_DmaModule_Init must require the security module handle
646*
647* 31   7/3/08 1:14p mphillip
648* PR40869: 97400 decoder heap values
649*
650* 30   7/2/08 10:23a vsilyaev
651* PR 44452: Added file to keep NEXUS_Platform_GetDefaultSettings
652*
653* 29   5/16/08 7:40p vishk
654* PR 40034: Develop Nexus Smartcard Interface/Module.
655* PR 40016: bsettop_smartcard: Develop SettopAPI-to-Nexus shim layer
656*
657* 28   5/5/08 4:55p jrubio
658* PR42439: you must calculate your heap sizes for video decoder, each
659*  platform is different
660*
661* 27   5/2/08 2:02p jrubio
662* PR42353: update features for 7335
663*
664* 26   5/1/08 3:31p jrubio
665* PR42353: add 7335 support
666*
667* 25   4/29/08 6:01p jrubio
668* PR42336: add 7325 conditional for vdc heap allocation
669*
670* 24   4/24/08 12:59p erickson
671* PR42113: add InputCapture
672*
673* 23   4/18/08 4:55p vsilyaev
674* PR 41868: Added security API to playpump and recpump
675*
676* 22   4/11/08 12:36p erickson
677* PR41695: added Graphics2D stripeWidth setting
678*
679* 21   4/8/08 10:40a vsilyaev
680* PR 41083: Added bprofile support
681*
682* 20   4/2/08 5:51p shyam
683* PR39899: Add 7043 Transcoder support
684*
685* 19   3/27/08 8:25p bandrews
686* PR40090: corrected astm display module to video decoder module
687*
688* 18   3/27/08 2:43p vsilyaev
689* PR 40818: Added settings to allocate shared heap
690*
691* 17   3/25/08 7:41p vsilyaev
692* PR 40862: Added supported video output formats
693*
694* 16   3/24/08 10:27p bandrews
695* PR40090: astm integration
696*
697* 15   3/24/08 9:59a erickson
698* PR40788: don't fail Platform Init if frontend init fails
699*
700* 13   3/4/08 5:43p jrubio
701* PR40169: add n 7325
702*
703* 12   3/4/08 4:30p jgarrett
704* PR 39405: Adding RFM audio support
705*
706* PR39899/3   3/14/08 6:19p shyam
707* PR 39899 : Fix compiler warnings
708*
709* PR39899/2   3/12/08 6:21p shyam
710* PR39899 : Merge in good nodes from main
711*
712* PR39899/1   2/27/08 5:53p shyam
713* PR 39899 : Integrate 7043 XCD into Nexus
714*
715* 11   2/26/08 5:42p jgarrett
716* PR 39017: Adding security handle to hdmi
717*
718* 10   2/20/08 1:45p erickson
719* PR39405: added RFM
720*
721* 9   2/7/08 11:02a jgarrett
722* PR 39270: Specifying per-chip heap sizes
723*
724* 8   2/5/08 2:30p jgarrett
725* PR 39017: Adding HdmiOutput to Audio connection
726*
727* 7   2/4/08 11:42a erickson
728* PR36808: added SyncChannel
729*
730* 6   2/1/08 5:34p jgarrett
731* PR 39017: Adding HdmiOutput
732*
733* 6   2/1/08 5:25p jgarrett
734* PR 39017: Adding HdmiOutput
735*
736* 5   1/30/08 4:25p vsilyaev
737* PR 38682: Fixed warnings in release build
738*
739* 4   1/24/08 4:38p vsilyaev
740* PR 38682: Improved kernel/proxy environment
741*
742* 3   1/23/08 9:21p vobadm
743* PR35457: update docs
744*
745* 2   1/23/08 3:11p vsilyaev
746* PR 38682: Changed NEXUS_Platform_GetStreamerInputBand to follow nexus
747*  rules on return types
748*
749* 1   1/18/08 2:17p jgarrett
750* PR 38808: Merging to main branch
751*
752* Nexus_Devel/38   1/16/08 3:26p vsilyaev
753* PR 38682: Fixed condition initialization of PVR modules
754*
755* Nexus_Devel/37   12/18/07 1:49p jgarrett
756* PR 37837: Fixing DMA shutdown
757*
758* Nexus_Devel/36   12/7/07 11:54a jgarrett
759* PR 37837: Removing security-dma linkage
760*
761* Nexus_Devel/35   12/6/07 11:37a jgarrett
762* PR 37931: Making UART conditional
763*
764* Nexus_Devel/34   12/3/07 9:28p jgarrett
765* PR 37837: Adding DMA
766*
767* Nexus_Devel/33   11/29/07 2:54p erickson
768* PR35457: pass transport handle in Audio module Settings
769*
770* Nexus_Devel/32   11/21/07 11:05a erickson
771* PR37423: add io modules
772*
773* Nexus_Devel/31   11/15/07 5:28p erickson
774* PR37137: added security module
775*
776* Nexus_Devel/30   11/15/07 12:34p rrlee
777* PR37125: Add calls to UninitCore and UninitOS in shutdown
778*
779* Nexus_Devel/29   11/8/07 6:30p jgarrett
780* PR 36774: Setting streamer input band to 5 for 7405
781*
782* Nexus_Devel/28   11/8/07 2:47p vsilyaev
783* PR 36788: PVR record module
784*
785* Nexus_Devel/27   11/8/07 9:17a erickson
786* PR36802: use standard NEXUS_HAS_MODULE defines, impl Platform_Uninit
787*
788* Nexus_Devel/26   11/5/07 2:12p erickson
789* PR36725: add NEXUS_PlatformConfiguration, share more code with 97401
790*
791* Nexus_Devel/25   10/19/07 9:39a erickson
792* PR36275: added graphics2d
793*
794* Nexus_Devel/24   10/18/07 10:39a erickson
795* PR36152: added NEXUS_Platform_GetStreamerInputBand
796*
797* Nexus_Devel/23   10/15/07 5:11p vsilyaev
798* PR 35824: Added playback module
799*
800* Nexus_Devel/22   10/10/07 5:14p vsilyaev
801* PR 35824: Really added file module
802*
803* Nexus_Devel/21   10/10/07 5:11p vsilyaev
804* PR 35824: Added file module
805*
806* Nexus_Devel/20   10/10/07 11:34a jgarrett
807* PR 35551: Adding platform handles
808*
809* Nexus_Devel/19   10/8/07 10:24a erickson
810* PR35551: adding Uninit
811*
812* Nexus_Devel/18   10/5/07 5:51p jgarrett
813* PR 35551: Adding frontend
814*
815* Nexus_Devel/17   10/5/07 1:42p jgarrett
816* PR 35744: Adding i2c module
817*
818* Nexus_Devel/16   9/28/07 4:24p jgarrett
819* PR 35002: Adding debug
820*
821* Nexus_Devel/15   9/28/07 11:57a vsilyaev
822* PR 34662: Fixed API after review
823*
824* Nexus_Devel/14   9/28/07 11:32a erickson
825* PR34926: rename videodecoder to video_decoder
826*
827* Nexus_Devel/13   9/28/07 11:06a erickson
828* PR34926: move transport handle to videoDecoderSettings.transport
829*
830* Nexus_Devel/12   9/28/07 10:05a erickson
831* PR34925: updated module settings structure names
832*
833* Nexus_Devel/11   9/27/07 7:51p jgarrett
834* PR 34954: Adding audio
835*
836* Nexus_Devel/10   9/26/07 5:36p vsilyaev
837* PR 34662: Added platform configuration
838*
839* Nexus_Devel/9   9/26/07 1:45p vsilyaev
840* PR 34662: Implementation of display framebuffer
841*
842* Nexus_Devel/8   9/25/07 1:31p vsilyaev
843* PR 34662: Added display module
844*
845* Nexus_Devel/7   9/25/07 12:31p erickson
846* PR34926: fix Unint
847*
848* Nexus_Devel/6   9/25/07 12:27p erickson
849* PR34926: added VideoDecoder
850*
851* Nexus_Devel/5   9/25/07 9:55a erickson
852* PR34925: return 0 on successful Init
853*
854* Nexus_Devel/4   9/24/07 3:21p erickson
855* PR34925: added Transport init
856*
857* Nexus_Devel/3   9/24/07 1:00p jgarrett
858* PR 35002: Migrating core code for better 97401/97400 sharing
859*
860* Nexus_Devel/2   9/21/07 6:26p jgarrett
861* PR 35002: Successful 97400 build
862*
863* Nexus_Devel/1   9/19/07 6:32p jgarrett
864* PR 35002: Adding initial 97400 platform
865*
866***************************************************************************/
867
868#include "nexus_base.h"
869#include "nexus_types.h"
870#include "priv/nexus_core.h"
871#include "nexus_platform.h"
872#include "nexus_platform_priv.h"
873#include "nexus_power_management.h"
874#ifndef NEXUS_BASE_ONLY
875#include "nexus_class_verification.h"
876#endif
877
878#ifdef NEXUS_FPGA_SUPPORT
879#include "nexus_platform_fpga.h"
880#endif
881#if NEXUS_HAS_I2C
882#include "nexus_i2c_init.h"
883#include "priv/nexus_i2c_standby_priv.h"
884#endif
885#if NEXUS_HAS_TRANSPORT
886#include "nexus_transport_init.h"
887#include "nexus_input_band.h"
888#include "priv/nexus_transport_standby_priv.h"
889#endif
890#if NEXUS_HAS_VIDEO_DECODER
891#include "nexus_video_decoder_init.h"
892#include "priv/nexus_video_decoder_standby_priv.h"
893#endif
894#if NEXUS_HAS_DISPLAY
895#include "nexus_display_init.h"
896#include "nexus_video_input.h"
897#include "nexus_video_output.h"
898#include "priv/nexus_display_standby_priv.h"
899#endif
900#if NEXUS_HAS_SURFACE
901#include "nexus_surface_init.h"
902#endif
903#if NEXUS_HAS_GRAPHICS2D
904#include "nexus_graphics2d_init.h"
905#include "priv/nexus_graphics2d_standby_priv.h"
906#endif
907#ifdef NEXUS_HAS_GRAPHICS3D
908#include "nexus_graphics3d_init.h"
909#endif
910#if NEXUS_HAS_FRONTEND
911#include "nexus_frontend_init.h"
912#endif
913#if NEXUS_HAS_SECURITY
914#include "nexus_security_init.h"
915#include "priv/nexus_security_standby_priv.h"
916#endif
917#if NEXUS_HAS_AUDIO
918#include "nexus_audio_init.h"
919#include "nexus_audio_input.h"
920#include "nexus_audio_output.h"
921#include "priv/nexus_audio_standby_priv.h"
922#endif
923#if NEXUS_HAS_FILE
924#include "nexus_file_init.h"
925#endif
926#if NEXUS_HAS_PLAYBACK
927#include "nexus_playback_init.h"
928#endif
929#if NEXUS_HAS_RECORD
930#include "nexus_record_init.h"
931#endif
932#if NEXUS_HAS_DVB_CI
933#include "nexus_dvb_ci_init.h"
934#endif
935#if NEXUS_HAS_PCMCIA
936#include "nexus_pcmcia_init.h"
937#endif
938#if NEXUS_HAS_IR_INPUT
939#include "nexus_ir_input_init.h"
940#endif
941#if NEXUS_HAS_LED
942#include "nexus_led_init.h"
943#endif
944#if NEXUS_HAS_KEYPAD
945#include "nexus_keypad_init.h"
946#endif
947#if NEXUS_HAS_IR_BLASTER
948#include "nexus_ir_blaster_init.h"
949#endif
950#if NEXUS_HAS_INPUT_CAPTURE
951#include "nexus_input_capture_init.h"
952#endif
953#if NEXUS_HAS_UHF_INPUT
954#include "nexus_uhf_input_init.h"
955#include "priv/nexus_uhf_input_standby_priv.h"
956#endif
957#if NEXUS_HAS_GPIO
958#include "nexus_gpio_init.h"
959#endif
960#if NEXUS_HAS_SPI
961#include "nexus_spi_init.h"
962#endif
963#if NEXUS_HAS_SPI_FRONTPANEL
964#include "nexus_spi.h"
965#include "nexus_gpio.h"
966#endif
967#ifdef NEXUS_HAS_TRANSCODER
968#include "nexus_transcoder_init.h"
969#include "nexus_platform_transcoder.h"
970#endif
971#if NEXUS_HAS_UART
972#include "nexus_uart_init.h"
973#include "priv/nexus_uart_standby_priv.h"
974#endif
975#if NEXUS_HAS_SMARTCARD
976#include "nexus_smartcard_init.h"
977#include "priv/nexus_smartcard_standby_priv.h"
978#endif
979#if NEXUS_HAS_DMA
980#include "nexus_dma_init.h"
981#include "priv/nexus_dma_standby_priv.h"
982#endif
983#if NEXUS_HAS_HDMI_OUTPUT
984#include "nexus_hdmi_output_init.h"
985#include "priv/nexus_hdmi_output_standby_priv.h"
986#endif
987#if NEXUS_HAS_CEC
988#include "nexus_cec_init.h"
989#endif
990#if NEXUS_HAS_HDMI_DVO
991#include "nexus_hdmi_dvo_init.h"
992#endif
993#if NEXUS_HAS_HDMI_INPUT
994#include "nexus_hdmi_input_init.h"
995#include "priv/nexus_hdmi_input_standby_priv.h"
996#endif
997#if NEXUS_HAS_PICTURE_DECODER
998#include "nexus_picture_decoder_init.h"
999#endif
1000#if NEXUS_HAS_SYNC_CHANNEL
1001#include "nexus_sync_channel_init.h"
1002#endif
1003#if NEXUS_HAS_ASTM
1004#include "nexus_astm_init.h"
1005#endif
1006#if NEXUS_HAS_RFM
1007#include "nexus_rfm_init.h"
1008#include "priv/nexus_rfm_standby_priv.h"
1009#endif
1010#include "nexus_core_utils.h"
1011#if NEXUS_HAS_PWM
1012#include "nexus_pwm_init.h"
1013#include "nexus_pwm.h"
1014#include "priv/nexus_pwm_standby_priv.h"
1015#endif
1016#ifdef NEXUS_HAS_TOUCHPAD
1017#include "nexus_touchpad_init.h"
1018#endif
1019#if NEXUS_HAS_SIMPLE_DECODER
1020#include "nexus_simple_decoder_init.h"
1021#endif
1022#if NEXUS_HAS_SURFACE_COMPOSITOR
1023#include "nexus_surface_compositor_init.h"
1024#endif
1025#if NEXUS_HAS_INPUT_ROUTER
1026#include "nexus_input_router_init.h"
1027#endif
1028#if NEXUS_HAS_TEMP_MONITOR
1029#include "nexus_temp_monitor_init.h"
1030#include "priv/nexus_temp_monitor_standby_priv.h"
1031#endif
1032#if NEXUS_HAS_VIDEO_ENCODER
1033#include "nexus_video_encoder_init.h"
1034#include "priv/nexus_video_encoder_standby_priv.h"
1035#endif
1036#if NEXUS_HAS_STREAM_MUX
1037#include "nexus_stream_mux_init.h"
1038#endif
1039#if NEXUS_HAS_FILE_MUX
1040#include "nexus_file_mux_init.h"
1041#endif
1042#if NEXUS_HAS_NSK2HDI
1043#include "nexus_nsk2hdi_init.h"
1044#endif
1045
1046BDBG_MODULE(nexus_platform);
1047
1048
1049/* runtime WXGA/FHD support. extern to bfmt_custom.c */
1050void BFMT_P_SetFhd(void);
1051
1052
1053NEXUS_PlatformHandles g_NEXUS_platformHandles;
1054NEXUS_PlatformSettings g_NEXUS_platformSettings;   /* saved platfrom settings */
1055NEXUS_ModuleHandle g_NEXUS_platformModule = NULL;
1056static NEXUS_HeapHandle g_secureHeap = NULL;
1057static char g_platformSwVersion[100]; /* keep off the static to prevent blowout */
1058
1059#ifdef NEXUS_BASE_OS_linuxuser
1060/* We can speed up init slightly by loading FW from multiple threads. */
1061#define MULTITHREADED_INIT 1
1062#endif
1063
1064#ifndef NEXUS_BASE_ONLY
1065static NEXUS_Platform_P_ModuleInfo * NEXUS_Platform_P_AddModule(NEXUS_ModuleHandle module_handle, 
1066                                NEXUS_PlatformStandbyLockMode lock_mode, 
1067                                void (*uninit)(void), 
1068                                NEXUS_Error (*standby)(bool, const NEXUS_StandbySettings *))
1069{
1070    NEXUS_Platform_P_ModuleInfo *module_info;
1071   
1072    if(!module_handle) 
1073    return NULL;
1074   
1075    module_info = BKNI_Malloc(sizeof(*module_info));
1076    if(!module_info) 
1077    return NULL;
1078
1079    BKNI_Memset(module_info, 0, sizeof(*module_info));
1080    module_info->module = module_handle;
1081    module_info->lock_mode = lock_mode;
1082    module_info->locked = false;   
1083    module_info->powerdown = false;
1084    module_info->uninit = uninit;
1085    module_info->standby = standby;
1086    BLST_Q_INSERT_HEAD(&g_NEXUS_platformHandles.handles, module_info, link);
1087   
1088    return module_info;
1089}
1090#endif
1091
1092#if NEXUS_HAS_SPI_FRONTPANEL
1093void NEXUS_Platform_P_SpiClose(void *cntx)
1094{
1095    NEXUS_Spi_Close((NEXUS_SpiHandle)cntx);
1096}
1097
1098void NEXUS_Platform_P_GpioClose(void *cntx)
1099{
1100    NEXUS_Gpio_Close((NEXUS_GpioHandle)cntx);
1101}
1102#endif
1103
1104#if NEXUS_HAS_VIDEO_DECODER
1105static void NEXUS_Platform_P_InitVideoDecoder(void *context)
1106{
1107    NEXUS_VideoDecoderModuleSettings videoDecoderSettings;   
1108    BSTD_UNUSED(context);
1109    BDBG_MSG((">VIDEO_DECODER"));
1110    videoDecoderSettings = g_NEXUS_platformSettings.videoDecoderModuleSettings;
1111    BDBG_ASSERT(g_NEXUS_platformHandles.transport);
1112    videoDecoderSettings.transport = g_NEXUS_platformHandles.transport;
1113    videoDecoderSettings.secureHeap = g_secureHeap;
1114#if NEXUS_NUM_ZSP_VIDEO_DECODERS || NEXUS_NUM_DSP_VIDEO_DECODERS
1115    BDBG_ASSERT(g_NEXUS_platformHandles.audio);
1116    videoDecoderSettings.audio = g_NEXUS_platformHandles.audio;
1117#endif
1118    g_NEXUS_platformHandles.videoDecoder = NEXUS_VideoDecoderModule_Init(&videoDecoderSettings);
1119    if (!g_NEXUS_platformHandles.videoDecoder) {
1120        BDBG_ERR(("Unable to init VideoDecoder"));
1121    } 
1122}
1123#endif
1124
1125#if NEXUS_HAS_AUDIO
1126#if NEXUS_HAS_SOFT_AUDIO
1127static uint32_t NEXUS_Platform_P_AudioReadReserved(
1128    void *pUnused1,
1129    int unused2,
1130    uint32_t physicalAddress)
1131{
1132    BSTD_UNUSED(pUnused1);
1133    BSTD_UNUSED(unused2);
1134    return NEXUS_Platform_P_ReadReserved(physicalAddress);
1135}
1136static void NEXUS_Platform_P_AudioWriteReserved(
1137    void *pUnused1,
1138    int unused2,
1139    uint32_t physicalAddress,
1140    uint32_t value)
1141{
1142    BSTD_UNUSED(pUnused1);
1143    BSTD_UNUSED(unused2);
1144    NEXUS_Platform_P_WriteReserved(physicalAddress, value);
1145}
1146static uint32_t NEXUS_Platform_P_AudioReadCoreReg(
1147    void *pUnused1,
1148    int unused2,
1149    uint32_t physicalAddress)
1150{
1151    BSTD_UNUSED(pUnused1);
1152    BSTD_UNUSED(unused2);
1153    return NEXUS_Platform_P_ReadCoreReg(physicalAddress);
1154}
1155static void NEXUS_Platform_P_AudioWriteCoreReg(
1156    void *pUnused1,
1157    int unused2,
1158    uint32_t physicalAddress,
1159    uint32_t value)
1160{
1161    BSTD_UNUSED(pUnused1);
1162    BSTD_UNUSED(unused2);
1163    NEXUS_Platform_P_WriteCoreReg(physicalAddress, value);
1164}
1165static uint32_t NEXUS_Platform_P_AudioReadCmtControl(
1166    void *pUnused1,
1167    int unused2)
1168{
1169    BSTD_UNUSED(pUnused1);
1170    BSTD_UNUSED(unused2);
1171    return NEXUS_Platform_P_ReadCmtControl();
1172}
1173static void NEXUS_Platform_P_AudioWriteCmtControl(
1174    void *pUnused1,
1175    int unused2,
1176    uint32_t value)
1177{
1178    BSTD_UNUSED(pUnused1);
1179    BSTD_UNUSED(unused2);
1180    NEXUS_Platform_P_WriteCmtControl(value);
1181}
1182#endif
1183
1184void NEXUS_Platform_P_InitAudio(void *context)
1185{
1186    NEXUS_AudioModuleSettings audioSettings;
1187
1188    BSTD_UNUSED(context);
1189    BDBG_MSG((">AUDIO"));
1190    audioSettings = g_NEXUS_platformSettings.audioModuleSettings;
1191    BDBG_ASSERT(g_NEXUS_platformHandles.transport);
1192    audioSettings.modules.transport = g_NEXUS_platformHandles.transport;
1193    BDBG_ASSERT(g_NEXUS_platformHandles.surface);
1194    audioSettings.modules.surface = g_NEXUS_platformHandles.surface;
1195    #if NEXUS_HAS_HDMI_OUTPUT
1196    BDBG_ASSERT(g_NEXUS_platformHandles.hdmiOutput);
1197    audioSettings.modules.hdmiOutput = g_NEXUS_platformHandles.hdmiOutput;
1198    #endif
1199    #if NEXUS_HAS_HDMI_INPUT
1200    BDBG_ASSERT(g_NEXUS_platformHandles.hdmiInput);
1201    audioSettings.modules.hdmiInput = g_NEXUS_platformHandles.hdmiInput;
1202    #endif
1203    #if NEXUS_HAS_RFM
1204    BDBG_ASSERT(g_NEXUS_platformHandles.rfm);
1205    audioSettings.modules.rfm = g_NEXUS_platformHandles.rfm;
1206    #endif
1207    #if NEXUS_HAS_SOFT_AUDIO
1208    audioSettings.readReserved = NEXUS_Platform_P_AudioReadReserved;
1209    audioSettings.writeReserved = NEXUS_Platform_P_AudioWriteReserved;
1210    audioSettings.readCoreRegister = NEXUS_Platform_P_AudioReadCoreReg;
1211    audioSettings.writeCoreRegister = NEXUS_Platform_P_AudioWriteCoreReg;
1212    audioSettings.readCmtControl = NEXUS_Platform_P_AudioReadCmtControl;
1213    audioSettings.writeCmtControl = NEXUS_Platform_P_AudioWriteCmtControl;
1214    #endif
1215    /* this is something used by the DTV... for now ignore the "DTV centric guarding schema" */
1216    #if NEXUS_HAS_FRONTEND
1217        audioSettings.modules.frontend = g_NEXUS_platformHandles.frontend;
1218    #endif
1219    g_NEXUS_platformHandles.audio = NEXUS_AudioModule_Init(&audioSettings);
1220    if ( !g_NEXUS_platformHandles.audio )
1221    {
1222        BDBG_ERR(("Unable to init audio"));
1223    } else {   
1224    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.audio, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_AudioModule_Uninit, NEXUS_AudioModule_Standby_priv);
1225    }
1226}
1227#endif
1228
1229/***************************************************************************
1230Summary:
1231    Initialize Nexus
1232Description:
1233    This will initialize all board-specifics and then proceed to
1234    initialize the nexus modules above it.  This is the main entry point
1235    for all applications to start Nexus.
1236See Also:
1237    NEXUS_Platform_Uninit
1238 ***************************************************************************/
1239NEXUS_Error NEXUS_Platform_Init_tagged( const NEXUS_PlatformSettings *pSettings, unsigned platformCheck, unsigned versionCheck, unsigned structSizeCheck )
1240{
1241    NEXUS_Error errCode;
1242    NEXUS_Base_Settings baseSettings;
1243    NEXUS_ThreadHandle videoDecoderThread = NULL;
1244#if MULTITHREADED_INIT
1245    NEXUS_ThreadHandle audioThread = NULL;
1246#endif
1247#if NEXUS_HAS_TRANSPORT
1248    NEXUS_TransportModuleSettings transportSettings;
1249#endif
1250#if NEXUS_HAS_FRONTEND
1251    NEXUS_FrontendModuleSettings frontendSettings;
1252#endif
1253#if NEXUS_HAS_PLAYBACK
1254    NEXUS_PlaybackModuleSettings playbackSettings;
1255#endif
1256#if NEXUS_HAS_RECORD
1257    NEXUS_RecordModuleSettings recordSettings;
1258#endif
1259#if NEXUS_HAS_GRAPHICS2D
1260    NEXUS_Graphics2DModuleSettings graphics2DSettings;
1261#endif
1262#if NEXUS_HAS_TRANSCODER
1263    NEXUS_TranscoderModuleSettings transcoderSettings;
1264    NEXUS_Platform_TranscoderSettings platTranscoderSettings;
1265    NEXUS_Platform_TranscoderPciInfo transcoderPciInfo;
1266#endif
1267#if NEXUS_HAS_DMA
1268    NEXUS_DmaModuleSettings dmaSettings;
1269#endif
1270#if NEXUS_HAS_HDMI_OUTPUT
1271    NEXUS_HdmiOutputModuleSettings hdmiSettings;
1272#endif
1273#if NEXUS_HAS_HDMI_INPUT
1274    NEXUS_HdmiInputModuleSettings hdmiInputSettings;
1275#endif
1276#if NEXUS_HAS_CEC
1277    NEXUS_CecModuleSettings cecSettings;
1278#endif
1279#if NEXUS_HAS_PICTURE_DECODER
1280    NEXUS_PictureDecoderModuleSettings pictureDecoderSettings;
1281#endif
1282#if NEXUS_HAS_SYNC_CHANNEL
1283    NEXUS_SyncChannelModuleSettings syncChannelSettings;
1284#endif
1285#if NEXUS_HAS_ASTM
1286    NEXUS_AstmModuleSettings astmSettings;
1287#endif
1288#if NEXUS_HAS_DVB_CI
1289    NEXUS_DvbCiModuleSettings dvbCiSettings;
1290#endif
1291#if NEXUS_HAS_PCMCIA
1292    NEXUS_PcmCiaModuleSettings pcmCiaSettings;
1293#endif
1294#if NEXUS_HAS_SPI_FRONTPANEL
1295    NEXUS_LedModuleSettings ledSpiSettings;
1296    NEXUS_SpiSettings spiSettings;
1297    NEXUS_KeypadModuleSettings keypadSpiSettings;
1298    NEXUS_GpioSettings keypadGpioSettings;
1299    NEXUS_GpioHandle keypadGpio;
1300    NEXUS_SpiHandle keypadSpi,ledSpi;
1301#endif
1302#if NEXUS_HAS_SMARTCARD
1303    NEXUS_SmartcardModuleSettings smartCardSettings;
1304#endif
1305#if NEXUS_HAS_STREAM_MUX
1306    NEXUS_StreamMuxModuleSettings streamMuxModuleSettings;   
1307#endif
1308#if NEXUS_HAS_NSK2HDI
1309    NEXUS_Nsk2hdiModuleSettings nsk2hdiSettings;   
1310#endif
1311    NEXUS_ModuleHandle handle;
1312    unsigned i;
1313
1314    BSTD_UNUSED(handle); /* in case it is unused */
1315    NEXUS_Platform_GetReleaseVersion(g_platformSwVersion,100);
1316    BDBG_WRN(("Release %s",g_platformSwVersion));
1317
1318#if !NEXUS_PLATFORM_NON_NUMERIC
1319    if (platformCheck != NEXUS_PLATFORM) {
1320        /* This code also ensures that NEXUS_PLATFORM is numeric, not alpha-numeric */
1321        BDBG_ERR(("NEXUS_Platform_Init failed with platform mismatch (nexus=%d, caller=%d). The application must be recompiled for this platform.",
1322            NEXUS_PLATFORM, platformCheck));
1323        return BERR_TRACE(NEXUS_INVALID_PARAMETER);
1324    }
1325#else
1326    BSTD_UNUSED(platformCheck);
1327#endif
1328
1329    if (versionCheck != NEXUS_P_GET_VERSION(NEXUS_PLATFORM)) {
1330        BDBG_ERR(("NEXUS_Platform_Init failed with version mismatch (nexus=%d.%d, caller=%d.%d). Please recompile application and/or nexus.",
1331            NEXUS_P_GET_VERSION(NEXUS_PLATFORM) / NEXUS_PLATFORM_VERSION_UNITS,
1332            NEXUS_P_GET_VERSION(NEXUS_PLATFORM) % NEXUS_PLATFORM_VERSION_UNITS,
1333            versionCheck / NEXUS_PLATFORM_VERSION_UNITS,
1334            versionCheck % NEXUS_PLATFORM_VERSION_UNITS));
1335        return BERR_TRACE(NEXUS_INVALID_PARAMETER);
1336    }
1337
1338    if (structSizeCheck != NEXUS_P_GET_STRUCT_SIZES()) {
1339        BDBG_ERR(("NEXUS_Platform failed with struct size mismatch (nexus=%d, caller=%d). Please recompile application and/or nexus.",
1340            NEXUS_P_GET_STRUCT_SIZES(), structSizeCheck));
1341        return BERR_TRACE(NEXUS_INVALID_PARAMETER);
1342    }
1343
1344    if (g_NEXUS_platformModule != NULL) {
1345        BDBG_ERR(("Already initialized"));
1346        return BERR_TRACE(NEXUS_UNKNOWN);
1347    }
1348
1349    /* Create defaults if no settings were provided */
1350    if ( NULL == pSettings )
1351    {
1352        NEXUS_Platform_GetDefaultSettings(&g_NEXUS_platformSettings);
1353    }
1354    else
1355    {
1356        g_NEXUS_platformSettings=*pSettings;
1357    }
1358
1359    BKNI_Memset(&g_NEXUS_platformHandles, 0, sizeof(g_NEXUS_platformHandles));
1360    BLST_Q_INIT(&g_NEXUS_platformHandles.handles);
1361
1362#if NEXUS_HAS_DISPLAY
1363    for (i=0;i<NEXUS_NUM_DISPLAYS;i++) {
1364        g_NEXUS_platformHandles.config.supportedDisplay[i] = NEXUS_NUM_DISPLAYS>i;
1365    }
1366    g_NEXUS_platformHandles.config.numWindowsPerDisplay = NEXUS_NUM_VIDEO_WINDOWS;
1367#endif
1368
1369#if NEXUS_HAS_VIDEO_DECODER
1370    for (i=0;i<NEXUS_NUM_VIDEO_DECODERS;i++) {
1371        g_NEXUS_platformHandles.config.supportedDecoder[i] = NEXUS_NUM_VIDEO_DECODERS>i;
1372    }
1373#endif
1374
1375    errCode = NEXUS_Platform_P_Magnum_Init();
1376    if ( errCode!=BERR_SUCCESS ) { errCode=BERR_TRACE(errCode); goto err_magnum; }
1377
1378    BDBG_MSG((">BASE"));
1379    NEXUS_Base_GetDefaultSettings(&baseSettings);
1380#if NEXUS_DEBUG_PROCFS
1381    baseSettings.driverModuleInit = nexus_driver_module_init_enum_cb;
1382    baseSettings.driverModuleUninit = nexus_driver_module_uninit_enum_cb;
1383#endif
1384
1385    errCode = NEXUS_Base_Init(&baseSettings);
1386    if ( errCode!=BERR_SUCCESS ) { errCode=BERR_TRACE(errCode); goto err_base; }
1387
1388    g_NEXUS_platformModule = NEXUS_Module_Create("platform", NULL);
1389    if ( !g_NEXUS_platformModule ) { errCode=BERR_TRACE(errCode); goto err_plaform_module; }
1390
1391    BDBG_MSG((">OS"));
1392    errCode = NEXUS_Platform_P_InitOS();
1393    if ( errCode!=BERR_SUCCESS ) { errCode=BERR_TRACE(errCode); goto err_os; }
1394
1395    /* Init the core modules */
1396    BDBG_MSG((">CORE"));
1397    errCode = NEXUS_Platform_P_InitCore(&g_NEXUS_platformSettings);
1398    if ( errCode!=BERR_SUCCESS ) { errCode=BERR_TRACE(errCode); goto err_core; }
1399
1400    for (i=0;i<NEXUS_MAX_HEAPS;i++) {
1401        if (g_pCoreHandles->nexusHeap[i]) {
1402            NEXUS_MemoryStatus status;
1403            NEXUS_Error rc;
1404            rc = NEXUS_Heap_GetStatus(g_pCoreHandles->nexusHeap[i], &status);
1405            if (!rc && status.memoryType == NEXUS_MemoryType_eSecure) {
1406                BDBG_WRN(("Heap %d has been marked as the secure heap", i));
1407                g_secureHeap = g_pCoreHandles->nexusHeap[i];
1408                break;
1409            }
1410        }
1411    }
1412
1413    if(NEXUS_GetEnv("profile_init")) {
1414        NEXUS_Profile_Start();
1415    }
1416
1417    /* do board-specific configuration after Core is brought up */
1418    BDBG_MSG((">INIT_BOARD"));
1419    errCode = NEXUS_Platform_P_InitBoard();
1420    if (errCode) {errCode = BERR_TRACE(errCode); goto err_initboard;}
1421
1422    BDBG_MSG((">PINMUX"));
1423    /* Init pinmuxes and vcxo control */
1424    errCode = NEXUS_Platform_P_InitPinmux();
1425    if ( errCode!=BERR_SUCCESS ) { errCode=BERR_TRACE(errCode); goto err_postboard; }
1426
1427    BDBG_MSG((">VCXO"));
1428    errCode = NEXUS_Platform_P_InitVcxo();
1429    if ( errCode!=BERR_SUCCESS ) { errCode=BERR_TRACE(errCode); goto err_postboard; }
1430
1431    /* Start Interrupts */
1432    BDBG_MSG((">InitInterrupts"));
1433    errCode = NEXUS_Platform_P_InitInterrupts();
1434    if ( errCode!=BERR_SUCCESS ) { errCode=BERR_TRACE(errCode); goto err_postboard; }
1435
1436
1437
1438    /* First bring up the minimum modules necessary to launch the module-init threads. */
1439
1440/* NEXUS_TRANSPORT_BEFORE_SECURITY is defined in nexus_transport_init.h for some chips. */
1441#if !NEXUS_TRANSPORT_BEFORE_SECURITY
1442#if NEXUS_HAS_SECURITY
1443    BDBG_MSG((">SECURITY"));
1444    g_NEXUS_platformHandles.security = NEXUS_SecurityModule_Init(&g_NEXUS_platformSettings.securitySettings);
1445    if (!g_NEXUS_platformHandles.security) {
1446        BDBG_ERR(("Unable to init security"));
1447        errCode = BERR_TRACE(BERR_NOT_SUPPORTED);
1448        goto err;
1449    } 
1450    else {   
1451        NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.security, NEXUS_PlatformStandbyLockMode_ePassiveOnly, NEXUS_SecurityModule_Uninit, NEXUS_SecurityModule_Standby_priv);
1452    }
1453#endif
1454#if NEXUS_HAS_DMA
1455    BDBG_MSG((">DMA"));
1456    NEXUS_DmaModule_GetDefaultSettings(&dmaSettings);
1457    dmaSettings.modules.security = g_NEXUS_platformHandles.security;
1458    g_NEXUS_platformHandles.dma = NEXUS_DmaModule_Init(&dmaSettings);
1459    if (!g_NEXUS_platformHandles.dma) {
1460        BDBG_ERR(("Unable to init Dma"));
1461        errCode = BERR_TRACE(BERR_NOT_SUPPORTED);
1462        goto err;
1463    } 
1464    else {   
1465        NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.dma, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_DmaModule_Uninit, NEXUS_DmaModule_Standby_priv);
1466    }
1467#endif
1468#endif /* NEXUS_TRANSPORT_BEFORE_SECURITY */
1469
1470#if NEXUS_HAS_TRANSPORT
1471    BDBG_MSG((">TRANSPORT"));
1472    NEXUS_TransportModule_GetDefaultSettings(&transportSettings);
1473    transportSettings = g_NEXUS_platformSettings.transportModuleSettings;
1474    transportSettings.dma = g_NEXUS_platformHandles.dma;
1475    transportSettings.security = g_NEXUS_platformHandles.security;
1476    transportSettings.secureHeap = g_secureHeap;
1477#if NEXUS_NUM_MTSIF
1478    for (i=0;i<NEXUS_NUM_MTSIF;i++)
1479        transportSettings.mtsif[i].enabled = true;
1480#endif
1481    g_NEXUS_platformHandles.transport = NEXUS_TransportModule_Init(&transportSettings);
1482    if (!g_NEXUS_platformHandles.transport) {
1483        BDBG_ERR(("Unable to init Transport"));
1484        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
1485        goto err;
1486    } else {   
1487    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.transport, NEXUS_PlatformStandbyLockMode_ePassiveOnly, NEXUS_TransportModule_Uninit, NEXUS_TransportModule_Standby_priv);
1488    }
1489#endif
1490
1491#if NEXUS_TRANSPORT_BEFORE_SECURITY
1492#if NEXUS_HAS_SECURITY
1493    BDBG_MSG((">SECURITY"));
1494    g_NEXUS_platformHandles.security = NEXUS_SecurityModule_Init(&g_NEXUS_platformSettings.securitySettings);
1495    if (!g_NEXUS_platformHandles.security) {
1496        BDBG_ERR(("Unable to init security"));
1497        errCode = BERR_TRACE(BERR_NOT_SUPPORTED);
1498        goto err;
1499    } 
1500    else {   
1501        NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.security, NEXUS_PlatformStandbyLockMode_ePassiveOnly, NEXUS_SecurityModule_Uninit, NEXUS_SecurityModule_Standby_priv);
1502    }
1503#endif
1504#if NEXUS_HAS_DMA
1505    BDBG_MSG((">DMA"));
1506    NEXUS_DmaModule_GetDefaultSettings(&dmaSettings);
1507    dmaSettings.modules.security = g_NEXUS_platformHandles.security;
1508    g_NEXUS_platformHandles.dma = NEXUS_DmaModule_Init(&dmaSettings);
1509    if (!g_NEXUS_platformHandles.dma) {
1510        BDBG_ERR(("Unable to init Dma"));
1511        errCode = BERR_TRACE(BERR_NOT_SUPPORTED);
1512        goto err;
1513    } 
1514    else {   
1515        NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.dma, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_DmaModule_Uninit, NEXUS_DmaModule_Standby_priv);
1516    }
1517#endif
1518#if NEXUS_HAS_TRANSPORT
1519    NEXUS_TransportModule_SetDmaModule(g_NEXUS_platformHandles.dma);
1520    NEXUS_TransportModule_SetSecurityModule(g_NEXUS_platformHandles.security);
1521#endif
1522#endif /* NEXUS_TRANSPORT_BEFORE_SECURITY */
1523
1524#if NEXUS_HAS_NSK2HDI
1525    BDBG_MSG((">NSK2HDI"));
1526    NEXUS_Nsk2hdiModule_GetDefaultSettings(&nsk2hdiSettings);
1527    nsk2hdiSettings.securityModule = g_NEXUS_platformHandles.security;
1528    nsk2hdiSettings.transportModule = g_NEXUS_platformHandles.transport;
1529    handle = NEXUS_Nsk2hdiModule_Init(&nsk2hdiSettings);
1530    if ( !handle )
1531    {
1532        BDBG_ERR(("Unable to init nsk2hdi"));
1533        errCode = BERR_TRACE(BERR_NOT_SUPPORTED);
1534        goto err;
1535    }
1536    else {
1537        NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_ePassiveOnly, NEXUS_Nsk2hdiModule_Uninit, NULL);
1538    }
1539#endif
1540
1541#if NEXUS_HAS_HDMI_OUTPUT
1542    BDBG_MSG((">HDMI_OUTPUT"));
1543    NEXUS_HdmiOutputModule_GetDefaultSettings(&hdmiSettings);
1544#if NEXUS_HAS_SECURITY
1545    hdmiSettings.modules.security = g_NEXUS_platformHandles.security;
1546#endif
1547    g_NEXUS_platformHandles.hdmiOutput = NEXUS_HdmiOutputModule_Init(&hdmiSettings);
1548    if ( !g_NEXUS_platformHandles.hdmiOutput) {
1549        BDBG_ERR(("Unable to init HdmiOutput"));
1550        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
1551        goto err;
1552    } else {   
1553    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.hdmiOutput, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_HdmiOutputModule_Uninit, NEXUS_HdmiOutputModule_Standby_priv);   
1554    }
1555#endif
1556
1557#if NEXUS_HAS_CEC
1558    BDBG_MSG((">CEC"));
1559    NEXUS_CecModule_GetDefaultSettings(&cecSettings);
1560    g_NEXUS_platformHandles.cec = NEXUS_CecModule_Init(&cecSettings);
1561    if ( !g_NEXUS_platformHandles.cec) {
1562        BDBG_ERR(("Unable to init CEC"));
1563        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
1564        goto err;
1565    } else {   
1566    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.cec, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_CecModule_Uninit, NULL);     
1567    }
1568#endif
1569
1570
1571#if NEXUS_HAS_HDMI_DVO
1572    BDBG_MSG((">HDMI_DVO"));
1573    g_NEXUS_platformHandles.hdmiDvo = NEXUS_HdmiDvoModule_Init(NULL);
1574    if (!g_NEXUS_platformHandles.hdmiDvo) {
1575        BDBG_ERR(("Unable to init HdmiDvo"));
1576        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
1577        goto err;
1578    } else {   
1579    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.hdmiDvo, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_HdmiDvoModule_Uninit, NULL);
1580    }
1581#endif
1582
1583#if NEXUS_HAS_HDMI_INPUT
1584    BDBG_MSG((">HDMI_INPUT"));
1585    NEXUS_HdmiInputModule_GetDefaultSettings(&hdmiInputSettings);
1586#if NEXUS_HAS_SECURITY
1587    hdmiInputSettings.modules.security = g_NEXUS_platformHandles.security;
1588#endif
1589    g_NEXUS_platformHandles.hdmiInput = NEXUS_HdmiInputModule_Init(&hdmiInputSettings);
1590    if (!g_NEXUS_platformHandles.hdmiInput)
1591    {
1592        BDBG_ERR(("Unable to init hdmiInput"));
1593        errCode = BERR_TRACE(BERR_NOT_SUPPORTED);
1594        goto err;
1595    } else {   
1596    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.hdmiInput, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_HdmiInputModule_Uninit, NEXUS_HdmiInputModule_Standby_priv);
1597    }
1598#endif
1599
1600
1601
1602#if NEXUS_HAS_RFM
1603    BDBG_MSG((">RFM"));
1604    g_NEXUS_platformHandles.rfm = NEXUS_RfmModule_Init(NULL);
1605    if (!g_NEXUS_platformHandles.rfm) {
1606        BDBG_ERR(("Unable to init Rfm"));
1607        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
1608        goto err;
1609    } else {   
1610        NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.rfm, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_RfmModule_Uninit, NEXUS_RfmModule_Standby_priv);
1611    }
1612#endif
1613
1614#if NEXUS_HAS_SURFACE
1615    BDBG_MSG((">SURFACE"));
1616    g_NEXUS_platformHandles.surface = NEXUS_SurfaceModule_Init(&g_NEXUS_platformSettings.surfacePlatformSettings);
1617    if (!g_NEXUS_platformHandles.surface) {
1618        BDBG_ERR(("Unable to init Surface"));
1619        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
1620        goto err;
1621    } else {   
1622    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.surface, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_SurfaceModule_Uninit, NULL);
1623    }
1624#endif
1625
1626
1627    /* Now that our init threads are launched, we can bring up modules in any order. */
1628#if NEXUS_HAS_I2C
1629    /* Init I2C */
1630    BDBG_MSG((">I2C"));
1631    g_NEXUS_platformHandles.i2c = NEXUS_I2cModule_Init(NULL);
1632    if ( !g_NEXUS_platformHandles.i2c ) {
1633    BDBG_ERR(("Unable to init I2C"));
1634        errCode=BERR_TRACE(errCode);
1635        goto err;
1636        } 
1637        else {   
1638                NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.i2c, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_I2cModule_Uninit, NEXUS_I2cModule_Standby_priv);
1639    }
1640#endif
1641
1642#if NEXUS_HAS_SPI
1643    BDBG_MSG((">SPI"));
1644    handle = NEXUS_SpiModule_Init(NULL);
1645    if ( !handle ) {
1646    BDBG_ERR(("Unable to init Spi"));
1647        errCode=BERR_TRACE(errCode);
1648        goto err;
1649    } else {   
1650    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_SpiModule_Uninit, NULL);
1651    }
1652#endif
1653
1654    /* Other IO modules */
1655#if NEXUS_HAS_IR_INPUT
1656    BDBG_MSG((">IR_INPUT"));
1657    handle = NEXUS_IrInputModule_Init(NULL);
1658    if ( !handle ) {
1659    BDBG_ERR(("Unable to init Ir Input"));
1660        errCode=BERR_TRACE(errCode);
1661        goto err;
1662    } else {   
1663    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_IrInputModule_Uninit, NULL);
1664    }
1665#endif
1666
1667#if NEXUS_HAS_INPUT_CAPTURE
1668    BDBG_MSG((">INPUT_CAPTURE"));
1669    handle = NEXUS_InputCaptureModule_Init(NULL);
1670    if ( !handle ) {
1671    BDBG_ERR(("Unable to init Input Capture"));
1672        errCode=BERR_TRACE(errCode);
1673        goto err;
1674    } else {   
1675    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_InputCaptureModule_Uninit, NULL);
1676    }
1677#endif
1678
1679#if NEXUS_HAS_IR_BLASTER
1680    BDBG_MSG((">IR_BLASTER"));
1681    handle = NEXUS_IrBlasterModule_Init(NULL);
1682    if ( !handle ) {
1683    BDBG_ERR(("Unable to init Ir Blaster"));
1684        errCode=BERR_TRACE(errCode);
1685        goto err;
1686    } else {   
1687    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_IrBlasterModule_Uninit, NULL);
1688    }
1689#endif
1690
1691#if NEXUS_HAS_UHF_INPUT
1692    BDBG_MSG((">UHF_INPUT"));
1693    handle = NEXUS_UhfInputModule_Init(NULL);
1694    if ( !handle ) {
1695    BDBG_ERR(("Unable to init Uhf Input"));
1696        errCode=BERR_TRACE(errCode);
1697        goto err;
1698    } else {   
1699    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_ePassiveOnly, NEXUS_UhfInputModule_Uninit, NEXUS_UhfInputModule_Standby_priv);
1700    }
1701#endif
1702
1703#if NEXUS_HAS_GPIO
1704    BDBG_MSG((">GPIO"));
1705    g_NEXUS_platformHandles.gpio = NEXUS_GpioModule_Init(NULL);
1706    if ( !g_NEXUS_platformHandles.gpio ) {
1707    BDBG_ERR(("Unable to init Gpio"));
1708        errCode=BERR_TRACE(errCode);
1709        goto err;
1710    } else {   
1711    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.gpio, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_GpioModule_Uninit, NULL);
1712    }
1713#endif
1714
1715#if NEXUS_HAS_SPI_FRONTPANEL
1716    /* FrontPanel SPI LED use Spi Channel 0 */
1717    NEXUS_Spi_GetDefaultSettings(&spiSettings);
1718    spiSettings.clockActiveLow = true;
1719    ledSpi = NEXUS_Spi_Open(0, &spiSettings);
1720    if (!ledSpi)
1721    {
1722        BDBG_ERR(("Unable to Open SPI For SPI_LED"));
1723        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
1724        goto err;
1725    }
1726
1727    BDBG_MSG((">LED (SPI)"));
1728    NEXUS_LedModule_GetDefaultSettings(&ledSpiSettings);
1729    ledSpiSettings.spi = ledSpi;
1730    handle = NEXUS_LedModule_Init(&ledSpiSettings);
1731    if ( !handle ) {
1732    BDBG_ERR(("Unable to init LED"));
1733        errCode=BERR_TRACE(errCode);
1734        goto err;
1735    } else { 
1736    NEXUS_Platform_P_ModuleInfo *module_info = NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_LedModule_Uninit, NULL);
1737    NEXUS_Platfor_P_CloseCallback *callback_handle;
1738    if(!module_info) {
1739        errCode=BERR_TRACE(errCode);
1740        goto err;
1741    }
1742    BLST_S_INIT(&module_info->list);
1743    callback_handle = BKNI_Malloc(sizeof(*callback_handle));
1744    if(!callback_handle) {
1745        errCode=BERR_TRACE(errCode);
1746        goto err;
1747    }
1748    callback_handle->close = NEXUS_Platform_P_SpiClose;
1749    callback_handle->cntx = (void*) ledSpi;
1750    BLST_S_INSERT_HEAD(&module_info->list, callback_handle, link);
1751    }
1752#elif NEXUS_HAS_LED
1753    BDBG_MSG((">LED"));
1754    handle = NEXUS_LedModule_Init(NULL);
1755    if ( !handle ) {
1756    BDBG_ERR(("Unable to init LED"));
1757        errCode=BERR_TRACE(errCode);
1758        goto err;
1759    } else {   
1760    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_LedModule_Uninit, NULL);
1761    }
1762#endif
1763
1764#if NEXUS_HAS_SPI_FRONTPANEL
1765
1766/* NEXUS_HAS_SPI_FRONTPANEL may be defined in build/Makefile */
1767#if  !defined(NEXUS_KEYPAD_GPIO) && !defined(NEXUS_KEYPAD_AON_GPIO)
1768#error If NEXUS_HAS_SPI_FRONTPANEL is defined, you must define NEXUS_KEYPAD_GPIO or NEXUS_KEYPAD_AON_GPIO in nexus_platform_features.h
1769#endif
1770
1771    /* FrontPanel SPI KEYPAD use Spi channel 1 */
1772    NEXUS_Spi_GetDefaultSettings(&spiSettings);
1773    spiSettings.clockActiveLow = true;
1774    keypadSpi = NEXUS_Spi_Open(1, &spiSettings);
1775    if (!keypadSpi)
1776    {
1777        BDBG_ERR(("Unable to Open SPI For SPI_KEYPAD"));
1778        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
1779        goto err;
1780    }
1781
1782    BDBG_ASSERT(g_NEXUS_platformHandles.gpio); /* GPIO module must have initialized first */
1783#ifdef NEXUS_KEYPAD_AON_GPIO
1784    NEXUS_Gpio_GetDefaultSettings(NEXUS_GpioType_eAonStandard, &keypadGpioSettings);
1785    keypadGpio = NEXUS_Gpio_Open(NEXUS_GpioType_eAonStandard, NEXUS_KEYPAD_AON_GPIO, &keypadGpioSettings);
1786    if (!keypadGpio)
1787    {
1788        BDBG_ERR(("Unable to open GPIO %d for keypad SPI interrupt", NEXUS_KEYPAD_AON_GPIO));
1789        goto err;
1790    }
1791#else
1792    NEXUS_Gpio_GetDefaultSettings(NEXUS_GpioType_eStandard, &keypadGpioSettings);
1793    keypadGpio = NEXUS_Gpio_Open(NEXUS_GpioType_eStandard, NEXUS_KEYPAD_GPIO, &keypadGpioSettings);
1794    if (!keypadGpio)
1795    {
1796        BDBG_ERR(("Unable to open GPIO %d for keypad SPI interrupt", NEXUS_KEYPAD_GPIO));
1797        goto err;
1798    }
1799#endif
1800
1801    BDBG_MSG((">KEYPAD (SPI)"));
1802    NEXUS_KeypadModule_GetDefaultSettings(&keypadSpiSettings);
1803    keypadSpiSettings.spi = keypadSpi;
1804    keypadSpiSettings.gpio = keypadGpio;
1805    handle = NEXUS_KeypadModule_Init(&keypadSpiSettings);
1806    if ( !handle ) {
1807    BDBG_ERR(("Unable to init Keypad"));
1808        errCode=BERR_TRACE(errCode);
1809        goto err;
1810    } else {   
1811    NEXUS_Platform_P_ModuleInfo *module_info = NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_KeypadModule_Uninit, NULL);
1812    NEXUS_Platfor_P_CloseCallback *callback_handle;
1813    if(!module_info) {
1814        errCode=BERR_TRACE(errCode);
1815        goto err;
1816    }
1817    BLST_S_INIT(&module_info->list);
1818    callback_handle = BKNI_Malloc(sizeof(*callback_handle));
1819    if(!callback_handle) {
1820        errCode=BERR_TRACE(errCode);
1821        goto err;
1822    }
1823    callback_handle->close = NEXUS_Platform_P_SpiClose;
1824    callback_handle->cntx = (void*) keypadSpi;
1825    BLST_S_INSERT_HEAD(&module_info->list, callback_handle, link);
1826
1827    callback_handle = BKNI_Malloc(sizeof(*callback_handle));
1828    if(!callback_handle) {
1829        errCode=BERR_TRACE(errCode);
1830        goto err;
1831    }
1832    callback_handle->close = NEXUS_Platform_P_GpioClose;
1833    callback_handle->cntx = (void*) keypadGpio;
1834    BLST_S_INSERT_HEAD(&module_info->list, callback_handle, link);
1835    }
1836#elif NEXUS_HAS_KEYPAD
1837    BDBG_MSG((">KEYPAD"));
1838    handle = NEXUS_KeypadModule_Init(NULL);
1839    if ( !handle ) {
1840    BDBG_ERR(("Unable to init Keypad"));
1841        errCode=BERR_TRACE(errCode);
1842        goto err;
1843    } else {   
1844    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_KeypadModule_Uninit, NULL);
1845    }
1846#endif
1847
1848#if NEXUS_HAS_UART
1849    BDBG_MSG((">UART"));
1850    handle = NEXUS_UartModule_Init(NULL);
1851    if (!handle) {
1852        BDBG_ERR(("Unable to init Uart"));
1853        errCode=BERR_TRACE(errCode);
1854        goto err;
1855    } else {
1856        NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_UartModule_Uninit, NEXUS_UartModule_Standby_priv);
1857    }
1858#endif
1859
1860#if NEXUS_HAS_TOUCHPAD
1861    BDBG_ERR((">NEXUS_TOUCHPAD_SUPPORT"));
1862    handle = NEXUS_TouchpadModule_Init(NULL);
1863    if ( !handle ) {
1864    BDBG_ERR(("Unable to init Touchpad"));
1865        errCode=BERR_TRACE(errCode);
1866        goto err;
1867    } else {   
1868    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_TouchpadModule_Uninit, NULL);
1869    }
1870#endif
1871#if NEXUS_HAS_FRONTEND
1872    BDBG_MSG((">FRONTEND"));
1873    NEXUS_FrontendModule_GetDefaultSettings(&frontendSettings);
1874    frontendSettings.i2cModule = g_NEXUS_platformHandles.i2c;
1875    g_NEXUS_platformHandles.frontend = NEXUS_FrontendModule_Init(&frontendSettings);
1876    if ( !g_NEXUS_platformHandles.frontend )
1877    {
1878        BDBG_ERR(("Unable to init frontend"));
1879        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
1880        goto err;
1881    } else {
1882    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.frontend, NEXUS_PlatformStandbyLockMode_ePassiveOnly, NEXUS_FrontendModule_Uninit, NULL);
1883    }
1884#endif
1885
1886
1887#if NEXUS_HAS_AUDIO
1888    /* audio requires transport, hdmiOutput and rfm. so we can launch as early as here. */
1889#if MULTITHREADED_INIT && !NEXUS_NUM_ZSP_VIDEO_DECODERS && !NEXUS_NUM_DSP_VIDEO_DECODERS
1890    audioThread = NEXUS_Thread_Create("audio_init", NEXUS_Platform_P_InitAudio, NULL, NULL);
1891#else
1892    NEXUS_Platform_P_InitAudio(NULL);
1893    if (!g_NEXUS_platformHandles.audio) {
1894        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
1895        goto err;
1896    }
1897#endif
1898#endif
1899
1900#if NEXUS_HAS_VIDEO_DECODER
1901    /* video decoder requires transport and secure heap. so we can launch as early as here. */
1902#if MULTITHREADED_INIT
1903    videoDecoderThread = NEXUS_Thread_Create("video_decoder_init", NEXUS_Platform_P_InitVideoDecoder, NULL, NULL);
1904#else
1905    NEXUS_Platform_P_InitVideoDecoder(NULL);
1906    if (!g_NEXUS_platformHandles.videoDecoder) {
1907        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
1908        goto err;
1909    }
1910#endif
1911#endif
1912
1913#if NEXUS_HAS_DVB_CI
1914    BDBG_MSG((">DVB-CI"));
1915    NEXUS_DvbCiModule_GetDefaultSettings(&dvbCiSettings);
1916    dvbCiSettings.modules.gpio = g_NEXUS_platformHandles.gpio;
1917    handle = NEXUS_DvbCiModule_Init(&dvbCiSettings);
1918    if ( !handle )
1919    {
1920        BDBG_ERR(("Unable to init DVB-CI module"));
1921        errCode = BERR_TRACE(BERR_NOT_SUPPORTED);
1922        goto err;
1923    } else {
1924    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_ePassiveOnly, NEXUS_DvbCiModule_Uninit, NULL);
1925    }
1926#endif
1927
1928#if NEXUS_HAS_PCMCIA
1929    BDBG_MSG(("PCMCIA"));
1930    NEXUS_PcmCiaModule_GetDefaultSettings(&pcmCiaSettings);
1931    pcmCiaSettings.modules.gpio = g_NEXUS_platformHandles.gpio;
1932    handle = NEXUS_PcmCiaModule_Init(&pcmCiaSettings);
1933    if ( !handle )
1934    {
1935        BDBG_ERR(("Unable to init PCMCIA module"));
1936        errCode = BERR_TRACE(BERR_NOT_SUPPORTED);
1937        goto err;
1938    } else {
1939    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_PcmCiaModule_Uninit, NULL); 
1940    }
1941#else
1942    BSTD_UNUSED(g_NEXUS_platformHandles.gpio);
1943#endif
1944
1945
1946#if NEXUS_HAS_GRAPHICS2D
1947    BDBG_MSG((">GRAPHICS2D"));
1948    NEXUS_Graphics2DModule_GetDefaultSettings(&graphics2DSettings);
1949    graphics2DSettings.surface = g_NEXUS_platformHandles.surface;
1950    handle = NEXUS_Graphics2DModule_Init(&graphics2DSettings);
1951    if (!handle) {
1952        BDBG_ERR(("Unable to init Graphics2D"));
1953        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
1954        goto err;
1955    } else {
1956    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_Graphics2DModule_Uninit, NEXUS_Graphics2DModule_Standby_priv);
1957    }
1958#endif
1959
1960#if NEXUS_HAS_SMARTCARD
1961    BDBG_MSG((">SMARTCARD"));
1962    if(!pSettings) {
1963        NEXUS_SmartcardModule_GetDefaultSettings(&smartCardSettings);
1964        smartCardSettings.clockSource= NEXUS_SmartcardClockSource_eInternalClock;
1965#if NEXUS_BOARD_7530_CRB
1966        smartCardSettings.clockFrequency = 24000000;
1967#else
1968        smartCardSettings.clockFrequency = 27000000;
1969#endif
1970        handle = NEXUS_SmartcardModule_Init(&smartCardSettings);
1971    }
1972    else {
1973        handle = NEXUS_SmartcardModule_Init(&g_NEXUS_platformSettings.smartCardSettings);
1974    }
1975    if (!handle) {
1976        BDBG_ERR(("Unable to init SmartCard"));
1977        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
1978        goto err;
1979    } else {
1980    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_ePassiveOnly, NEXUS_SmartcardModule_Uninit, NEXUS_SmartcardModule_Standby_priv);
1981    }
1982#endif
1983
1984#if NEXUS_HAS_PWM
1985    BDBG_MSG((">PWM"));
1986    g_NEXUS_platformHandles.pwm = NEXUS_PwmModule_Init(NULL);
1987    if (!g_NEXUS_platformHandles.pwm) {
1988        BDBG_ERR(("NEXUS_PwmModule_Init failed\n"));
1989        errCode = BERR_TRACE(BERR_NOT_SUPPORTED);
1990        goto err;
1991    } 
1992    else {
1993        NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.pwm, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_PwmModule_Uninit, NEXUS_PwmModule_Standby_priv);
1994    }
1995#endif
1996
1997#if NEXUS_HAS_TEMP_MONITOR
1998    BDBG_MSG((">TEMP_MONITOR"));
1999    handle = NEXUS_TempMonitorModule_Init(NULL);
2000    if (!handle) {
2001        BDBG_ERR(("NEXUS_TempMonitorModule_Init failed\n"));
2002        errCode = BERR_TRACE(BERR_NOT_SUPPORTED);
2003        goto err;
2004    } else {
2005    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_TempMonitorModule_Uninit, NULL);
2006    }
2007#endif
2008
2009#if NEXUS_HAS_FILE
2010    BDBG_MSG((">FILE"));
2011    {
2012        NEXUS_FileModuleSettings fileModuleSettings;
2013        NEXUS_FileModule_GetDefaultSettings(&fileModuleSettings);
2014        fileModuleSettings.workerThreads = g_NEXUS_platformSettings.fileModuleSettings.workerThreads;
2015        BKNI_Memcpy(fileModuleSettings.schedulerSettings, g_NEXUS_platformSettings.fileModuleSettings.schedulerSettings, sizeof(fileModuleSettings.schedulerSettings));
2016        g_NEXUS_platformHandles.file = NEXUS_FileModule_Init(&fileModuleSettings);
2017    }
2018    if (!g_NEXUS_platformHandles.file) {
2019        BDBG_ERR(("Unable to init File"));
2020        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2021        goto err;
2022    } else {
2023    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.file, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_FileModule_Uninit, NULL);
2024    }
2025#endif
2026
2027#if NEXUS_HAS_TRANSCODER
2028    BDBG_MSG((">TRANSCODE"));
2029    NEXUS_TranscoderModule_GetDefaultSettings(&transcoderSettings);
2030    errCode = NEXUS_Platform_DetectTranscoder(&platTranscoderSettings, &transcoderPciInfo);
2031    if(NEXUS_SUCCESS==errCode)
2032    {
2033        BDBG_MSG(("Detected Transcoder device ... Initializing the device"));
2034        transcoderSettings.pciRegPhysBase = transcoderPciInfo.pciRegPhysBase;
2035        transcoderSettings.pciMemPhysBase = transcoderPciInfo.pciMemPhysBase;
2036        transcoderSettings.pPciRegAddress = transcoderPciInfo.pPciRegAddress;
2037        transcoderSettings.pPciMemAddress = transcoderPciInfo.pPciMemAddress;
2038        transcoderSettings.regSpaceSize = transcoderPciInfo.regSpaceSize;
2039        transcoderSettings.memSpaceSize = transcoderPciInfo.memSpaceSize;
2040        transcoderSettings.pInstallPciInterrupt = transcoderPciInfo.pInstallPciInterrupt;
2041        handle = NEXUS_TranscoderModule_Init(&transcoderSettings);
2042        if ( NULL == handle ) {
2043            BDBG_ERR(("Error initializing the Transcoder device"));
2044        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2045        goto err;
2046        } else {
2047        NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_TranscoderModule_Uninit, NULL);
2048    } 
2049    }
2050    else {
2051            BDBG_ERR(("No 7043 transcoder device found on PCI"));
2052    }   
2053#endif
2054
2055#if NEXUS_HAS_GRAPHICS3D
2056    BDBG_MSG((">GRAPHICS3D"));
2057    handle = NEXUS_Graphics3dModule_Init(NULL);
2058    if ( !handle ) {
2059        BDBG_ERR(("Unable to initialize 3D graphics"));
2060    errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2061        goto err;
2062    } else {
2063    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_Graphics3dModule_Uninit, NULL);
2064    }   
2065#endif
2066
2067#if NEXUS_HAS_DISPLAY
2068    BDBG_MSG((">DISPLAY"));
2069    {
2070        /* NEXUS_DisplayModuleSettings is large (600+ bytes) so we malloc to avoid stack blowout */
2071        NEXUS_DisplayModuleSettings *pDisplaySettings = BKNI_Malloc(sizeof(*pDisplaySettings));
2072        if (!pDisplaySettings) {
2073            errCode = BERR_TRACE(NEXUS_OUT_OF_SYSTEM_MEMORY);
2074            goto err;
2075        }
2076        *pDisplaySettings = g_NEXUS_platformSettings.displayModuleSettings;
2077        pDisplaySettings->modules.surface = g_NEXUS_platformHandles.surface;
2078        /* don't set pDisplaySettings->modules.videoDecoder here */
2079    #if NEXUS_HAS_HDMI_OUTPUT
2080        pDisplaySettings->modules.hdmiOutput = g_NEXUS_platformHandles.hdmiOutput;
2081    #endif
2082    #if NEXUS_HAS_HDMI_DVO
2083        pDisplaySettings->modules.hdmiDvo = g_NEXUS_platformHandles.hdmiDvo;
2084    #endif
2085    #if NEXUS_HAS_HDMI_INPUT
2086        pDisplaySettings->modules.hdmiInput = g_NEXUS_platformHandles.hdmiInput;
2087    #endif
2088    #if NEXUS_HAS_RFM
2089        pDisplaySettings->modules.rfm = g_NEXUS_platformHandles.rfm;
2090    #endif
2091    #if NEXUS_HAS_PWM
2092        pDisplaySettings->modules.pwm = g_NEXUS_platformHandles.pwm;
2093    #endif
2094        pDisplaySettings->modules.transport = g_NEXUS_platformHandles.transport;
2095        g_NEXUS_platformHandles.display = NEXUS_DisplayModule_Init(pDisplaySettings);
2096        BKNI_Free(pDisplaySettings);
2097        if (!g_NEXUS_platformHandles.display) {
2098            BDBG_ERR(("Unable to init Display"));
2099            errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2100            goto err;
2101        } 
2102    }
2103#endif
2104
2105#if NEXUS_HAS_PICTURE_DECODER
2106    BDBG_MSG((">PICTURE_DECODER"));
2107    NEXUS_PictureDecoderModule_GetDefaultSettings(&pictureDecoderSettings);
2108    pictureDecoderSettings.surface = g_NEXUS_platformHandles.surface;
2109    handle = NEXUS_PictureDecoderModule_Init(&pictureDecoderSettings);
2110    if (!handle) {
2111        BDBG_ERR(("Unable to init PictureDecoder"));
2112        errCode = BERR_TRACE(BERR_NOT_SUPPORTED);
2113        goto err;
2114    } else {
2115    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_PictureDecoderModule_Uninit, NULL);
2116    }
2117#endif
2118
2119#if MULTITHREADED_INIT
2120    /* audio is needed for sync, so join here */
2121    if (audioThread) {
2122        NEXUS_Thread_Destroy(audioThread);
2123        audioThread = NULL;
2124    if (!g_NEXUS_platformHandles.audio) {
2125        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2126        goto err;
2127    }
2128    }
2129#endif
2130
2131#if NEXUS_HAS_SYNC_CHANNEL
2132    BDBG_MSG((">SYNC_CHANNEL"));
2133    NEXUS_SyncChannelModule_GetDefaultSettings(&syncChannelSettings);
2134    syncChannelSettings.modules.display = g_NEXUS_platformHandles.display;
2135    syncChannelSettings.modules.audio = g_NEXUS_platformHandles.audio;
2136    handle = NEXUS_SyncChannelModule_Init(&syncChannelSettings);
2137    if (!handle) {
2138        BDBG_ERR(("Unable to init SyncChannel"));
2139        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2140        goto err;
2141    } else {
2142    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_SyncChannelModule_Uninit, NULL);
2143    }
2144#endif
2145
2146    /* videoDecoder is needed for astm, so join here */
2147    /* coverity[dead_error_condition] */
2148    if (videoDecoderThread) {
2149        NEXUS_Thread_Destroy(videoDecoderThread);
2150        videoDecoderThread = NULL;
2151    if (!g_NEXUS_platformHandles.videoDecoder) {
2152        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2153        goto err;
2154    }
2155    }
2156
2157#if NEXUS_HAS_VIDEO_DECODER && NEXUS_HAS_DISPLAY
2158    NEXUS_DisplayModule_SetVideoDecoderModule(g_NEXUS_platformHandles.videoDecoder);
2159    /* Video Decoder and Display need to go in this order */
2160    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.videoDecoder, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_VideoDecoderModule_Uninit, NEXUS_VideoDecoderModule_Standby_priv);
2161    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.display, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_DisplayModule_Uninit, NEXUS_DisplayModule_Standby_priv);
2162#endif
2163
2164#if NEXUS_HAS_VIDEO_ENCODER
2165    BDBG_MSG((">VIDEO_ENCODER"));
2166    g_NEXUS_platformSettings.videoEncoderSettings.display = g_NEXUS_platformHandles.display;
2167    g_NEXUS_platformSettings.videoEncoderSettings.transport = g_NEXUS_platformHandles.transport;
2168    g_NEXUS_platformHandles.videoEncoder = NEXUS_VideoEncoderModule_Init(&g_NEXUS_platformSettings.videoEncoderSettings);
2169    if(!g_NEXUS_platformHandles.videoEncoder) {
2170        BDBG_ERR(("NEXUS_VideoEncoderModule_Init failed\n"));
2171        errCode = BERR_TRACE(BERR_NOT_SUPPORTED);
2172        goto err;
2173    } else {
2174    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.videoEncoder, NEXUS_PlatformStandbyLockMode_eAlways, NEXUS_VideoEncoderModule_Uninit, NEXUS_VideoEncoderModule_Standby_priv);
2175    }
2176#endif
2177
2178#if NEXUS_HAS_STREAM_MUX
2179    BDBG_MSG((">STREAM_MUX"));
2180    NEXUS_StreamMuxModule_GetDefaultSettings(&streamMuxModuleSettings);
2181    streamMuxModuleSettings.transport = g_NEXUS_platformHandles.transport;
2182    streamMuxModuleSettings.audio = g_NEXUS_platformHandles.audio;
2183    streamMuxModuleSettings.videoEncoder = g_NEXUS_platformHandles.videoEncoder;
2184    handle = NEXUS_StreamMuxModule_Init(&streamMuxModuleSettings);
2185    if(!handle) {
2186        BDBG_ERR(("NEXUS_StreamMuxModule_Init: failed\n"));
2187        errCode = BERR_TRACE(BERR_NOT_SUPPORTED);
2188        goto err;
2189    } else {
2190    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_StreamMuxModule_Uninit, NULL);
2191    }
2192#endif
2193
2194#if NEXUS_HAS_ASTM
2195    BDBG_MSG((">ASTM"));
2196    NEXUS_AstmModule_GetDefaultSettings(&astmSettings);
2197    astmSettings.modules.videoDecoder = g_NEXUS_platformHandles.videoDecoder;
2198    astmSettings.modules.audio = g_NEXUS_platformHandles.audio;
2199    astmSettings.modules.transport = g_NEXUS_platformHandles.transport;
2200    handle = NEXUS_AstmModule_Init(&astmSettings);
2201    if (!handle) {
2202        BDBG_ERR(("Unable to init Astm"));
2203        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2204        goto err;
2205    } else {
2206    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_AstmModule_Uninit, NULL);
2207    }
2208#endif
2209
2210#if NEXUS_HAS_PLAYBACK
2211    BDBG_MSG((">PLAYBACK"));
2212    NEXUS_PlaybackModule_GetDefaultSettings(&playbackSettings);
2213    playbackSettings.modules.file = g_NEXUS_platformHandles.file;
2214    playbackSettings.modules.audioDecoder = g_NEXUS_platformHandles.audio;
2215    playbackSettings.modules.videoDecoder = g_NEXUS_platformHandles.videoDecoder;
2216    playbackSettings.modules.playpump = g_NEXUS_platformHandles.transport;
2217    g_NEXUS_platformHandles.playback = NEXUS_PlaybackModule_Init(&playbackSettings);
2218    if (!g_NEXUS_platformHandles.playback) {
2219        BDBG_ERR(("Unable to init playback"));
2220        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2221        goto err;
2222    } else {
2223    NEXUS_Platform_P_AddModule(g_NEXUS_platformHandles.playback, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_PlaybackModule_Uninit, NULL);
2224    }
2225#endif
2226
2227#if NEXUS_HAS_RECORD
2228    BDBG_MSG((">RECORD"));
2229    NEXUS_RecordModule_GetDefaultSettings(&recordSettings);
2230    recordSettings.modules.file = g_NEXUS_platformHandles.file;
2231    recordSettings.modules.recpump = g_NEXUS_platformHandles.transport;
2232#if NEXUS_HAS_PLAYBACK
2233    recordSettings.modules.playback = g_NEXUS_platformHandles.playback;
2234#endif
2235    handle = NEXUS_RecordModule_Init(&recordSettings);
2236    if (!handle) {
2237        BDBG_ERR(("Unable to init record"));
2238        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2239        goto err;
2240    } else {
2241    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_RecordModule_Uninit, NULL);
2242    }
2243#endif
2244
2245#if NEXUS_HAS_FILE_MUX
2246    BDBG_MSG((">FILE_MUX"));
2247    handle = NEXUS_FileMuxModule_Init(NULL);
2248    if (!handle) {
2249        BDBG_ERR(("Unable to init File Mux"));
2250        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2251        goto err;
2252    } else {
2253    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_FileMuxModule_Uninit, NULL);
2254    }
2255#endif
2256
2257#if NEXUS_HAS_SIMPLE_DECODER
2258    BDBG_MSG((">SIMPLE_DECODER"));
2259    handle = NEXUS_SimpleDecoderModule_Init(NULL);
2260    if (!handle) {
2261        BDBG_ERR(("Unable to init Simple Decoder"));
2262        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2263        goto err;
2264    } else {
2265    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_SimpleDecoderModule_Uninit, NULL);
2266    }
2267#endif
2268
2269#if NEXUS_HAS_SURFACE_COMPOSITOR
2270    {
2271    NEXUS_SurfaceCompositorModuleSettings settings;
2272    BDBG_MSG((">SURFACE_COMPOSITOR"));
2273    settings.modules.display = g_NEXUS_platformHandles.display;
2274    handle = NEXUS_SurfaceCompositorModule_Init(&settings);
2275    }
2276    if (!handle) {
2277        BDBG_ERR(("Unable to init SurfaceCompositor"));
2278        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2279        goto err;
2280    } else {
2281    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_SurfaceCompositorModule_Uninit, NULL);
2282    }
2283#endif
2284
2285#if NEXUS_HAS_INPUT_ROUTER
2286    BDBG_MSG((">INPUT_ROUTER"));
2287    handle = NEXUS_InputRouterModule_Init(NULL);
2288    if (!handle) {
2289        BDBG_ERR(("Unable to init InputRouter"));
2290        errCode = BERR_TRACE(NEXUS_NOT_SUPPORTED);
2291        goto err;
2292    } else {
2293    NEXUS_Platform_P_AddModule(handle, NEXUS_PlatformStandbyLockMode_eNone, NEXUS_InputRouterModule_Uninit, NULL);
2294    }
2295#endif
2296
2297    BDBG_MSG((">CONFIG"));
2298    errCode = NEXUS_Platform_P_Config(&g_NEXUS_platformSettings);
2299    if ( errCode!=BERR_SUCCESS ) { errCode = BERR_TRACE(errCode); goto err_init; }
2300
2301
2302#if NEXUS_HAS_FRONTEND
2303    if (g_NEXUS_platformSettings.openFrontend) {
2304        BDBG_MSG((">FRONTEND CONFIG"));
2305        errCode = NEXUS_Platform_InitFrontend();
2306        if ( errCode!=BERR_SUCCESS ) {
2307            BDBG_ERR(("Unable to init frontend. Allowing Nexus to still come up."));
2308        }
2309    }
2310#endif
2311
2312#if NEXUS_POWER_MANAGEMENT
2313    NEXUS_Platform_SetStandbySettings(&g_NEXUS_platformSettings.standbySettings);
2314#endif
2315    NEXUS_Platform_P_InitServer();
2316
2317    /* Success */
2318    if(NEXUS_GetEnv("profile_init")) {
2319        NEXUS_Profile_Stop("NEXUS_Platform_Init");
2320    }
2321
2322    BDBG_WRN(("initialized"));
2323    return NEXUS_SUCCESS;
2324
2325err_init:
2326    NEXUS_Platform_Uninit();
2327    return errCode;
2328
2329err:
2330    BDBG_ERR(("Unable to init all platform modules. Unable to recover from this point."));
2331err_postboard:
2332    NEXUS_Platform_P_UninitBoard();
2333err_initboard:
2334    NEXUS_Platform_P_UninitCore();
2335err_core:
2336    NEXUS_Platform_P_UninitOS();
2337err_os:
2338    NEXUS_Module_Destroy(g_NEXUS_platformModule);
2339    g_NEXUS_platformModule = NULL;
2340err_plaform_module:
2341    NEXUS_Base_Uninit();
2342err_base:
2343    NEXUS_Platform_P_Magnum_Uninit();
2344err_magnum:
2345    BDBG_ASSERT(errCode); /* if we've taken this path, it's only because of failure */
2346    BDBG_ERR(("NEXUS_Platform_Init has failed. The system is not usable. Handles returned by NEXUS_Platform_GetConfiguration are likely to be invalid."));
2347    return errCode;
2348}
2349
2350/***************************************************************************
2351Summary:
2352    Uninitialize Nexus
2353See Also:
2354    NEXUS_Platform_Init
2355 ***************************************************************************/
2356void NEXUS_Platform_Uninit(void)
2357{
2358    NEXUS_Platform_P_ModuleInfo *module_info; 
2359
2360    if (g_NEXUS_platformModule == NULL) {
2361        BDBG_ERR(("Already uninitialized"));
2362        BERR_TRACE(NEXUS_UNKNOWN);
2363        return;
2364    }
2365
2366    NEXUS_Platform_P_UninitServer();
2367   
2368#if NEXUS_POWER_MANAGEMENT
2369    g_NEXUS_platformSettings.standbySettings.mode = NEXUS_PlatformStandbyMode_eOn;
2370    NEXUS_Platform_SetStandbySettings(&g_NEXUS_platformSettings.standbySettings);
2371#endif
2372#if NEXUS_HAS_FRONTEND
2373    /* shutdown whatever platform opened */
2374    NEXUS_Platform_UninitFrontend();
2375#endif
2376
2377    NEXUS_Platform_P_Shutdown();
2378
2379    /**
2380    Uninit modules
2381    **/
2382    while(NULL != (module_info=BLST_Q_FIRST(&g_NEXUS_platformHandles.handles))) {
2383        NEXUS_Platfor_P_CloseCallback *close_cb;
2384        BDBG_MSG(("uninit %s", NEXUS_Module_GetName(module_info->module)));
2385        if( module_info->uninit )
2386            module_info->uninit();
2387        else 
2388            BDBG_WRN(("Uninit function not provided for module %s", NEXUS_Module_GetName(module_info->module)));
2389   
2390        while(NULL != (close_cb=BLST_S_FIRST(&module_info->list))) {
2391            close_cb->close(close_cb->cntx);
2392            BLST_S_REMOVE_HEAD(&module_info->list, link);
2393            BKNI_Free(close_cb);
2394        }
2395        BLST_Q_REMOVE_HEAD(&g_NEXUS_platformHandles.handles, link);
2396        BKNI_Free(module_info);
2397    }       
2398
2399    NEXUS_Platform_P_UninitInterrupts();
2400
2401    BDBG_MSG(("<UNINIT_BOARD"));
2402    NEXUS_Platform_P_UninitBoard();
2403    BDBG_MSG(("<CORE"));
2404    NEXUS_Platform_P_UninitCore();
2405    BDBG_MSG(("<OS"));
2406    NEXUS_Platform_P_UninitOS();
2407    BDBG_MSG(("<BASE"));
2408    if (g_NEXUS_platformModule) {
2409        NEXUS_Module_Destroy(g_NEXUS_platformModule);
2410        g_NEXUS_platformModule = NULL;
2411    }
2412    NEXUS_Base_Uninit();
2413    BDBG_MSG(("<MAGNUM"));
2414    NEXUS_Platform_P_Magnum_Uninit();
2415
2416    return;
2417}
2418
2419void NEXUS_Platform_GetConfiguration(NEXUS_PlatformConfiguration *pConfiguration)
2420{
2421    *pConfiguration = g_NEXUS_platformHandles.config;
2422
2423    BDBG_ASSERT(sizeof(pConfiguration->heap) == sizeof(g_pCoreHandles->nexusHeap));
2424    BKNI_Memcpy(pConfiguration->heap, g_pCoreHandles->nexusHeap, sizeof(pConfiguration->heap));
2425}
2426
2427NEXUS_Error NEXUS_Platform_ReadRegister( uint32_t address, uint32_t *pValue )
2428{
2429    *pValue = BREG_Read32(g_pCoreHandles->reg, address);
2430    return 0;
2431}
2432
2433void NEXUS_Platform_WriteRegister( uint32_t address, uint32_t value )
2434{
2435    BREG_Write32(g_pCoreHandles->reg, address, value);
2436}
2437
2438NEXUS_Error NEXUS_Platform_GetStatus( NEXUS_PlatformStatus *pStatus )
2439{
2440    BERR_Code rc;
2441
2442    BDBG_ASSERT(g_NEXUS_platformModule); /* make sure NEXUS_Platform_Init was called */
2443
2444    BKNI_Memset(pStatus, 0, sizeof(*pStatus));
2445    rc = BCHP_GetChipInfo(g_pCoreHandles->chp, &pStatus->chipId, &pStatus->chipRevision);
2446    if (rc) return BERR_TRACE(rc);
2447
2448    return 0;
2449}
2450
2451#if B_REFSW_FIRMWARE
2452/* The following mappings simplify the rev jump */
2453NEXUS_Error
2454NEXUS_Platform_P_EnableInterrupt( unsigned irqNum)
2455{
2456    NEXUS_Error rc;
2457    BKNI_EnterCriticalSection();
2458    rc = NEXUS_Platform_P_EnableInterrupt_isr(irqNum);
2459    BKNI_LeaveCriticalSection();
2460    return rc;
2461}
2462void
2463NEXUS_Platform_P_DisableInterrupt( unsigned irqNum)
2464{
2465    BKNI_EnterCriticalSection();
2466    NEXUS_Platform_P_DisableInterrupt_isr(irqNum);
2467    BKNI_LeaveCriticalSection();
2468    return;
2469}
2470NEXUS_Error
2471NEXUS_Platform_P_Magnum_Init(void)
2472{
2473    /* nothing to do here, magnum already initialized when driver loaded */
2474    return BERR_SUCCESS;
2475}
2476void
2477NEXUS_Platform_P_Magnum_Uninit(void)
2478{
2479    return;
2480}
2481#endif
2482
2483#ifndef NEXUS_BASE_ONLY
2484/* implementation of attr{shutdown=NEXUS_VideoInput_Shutdown} */
2485void nexus_driver_shutdown_NEXUS_VideoInput_Shutdown(void *object)
2486{
2487#if NEXUS_HAS_DISPLAY
2488    NEXUS_VideoInput_Shutdown(object);
2489#endif
2490}
2491
2492/* implementation of attr{shutdown=NEXUS_VideoOutput_Shutdown} */
2493void nexus_driver_shutdown_NEXUS_VideoOutput_Shutdown(void *object)
2494{
2495#if NEXUS_HAS_DISPLAY
2496    NEXUS_VideoOutput_Shutdown(object);
2497#endif
2498}
2499
2500/* implementation of attr{shutdown=NEXUS_AudioInput_Shutdown} */
2501void nexus_driver_shutdown_NEXUS_AudioInput_Shutdown(void *object)
2502{
2503#if NEXUS_HAS_AUDIO
2504    NEXUS_AudioInput_Shutdown(object);
2505#endif
2506}
2507
2508/* implementation of attr{shutdown=NEXUS_AudioOutput_Shutdown} */
2509void nexus_driver_shutdown_NEXUS_AudioOutput_Shutdown(void *object)
2510{
2511#if NEXUS_HAS_AUDIO
2512    NEXUS_AudioOutput_Shutdown(object);
2513#endif
2514}
2515#endif
2516
2517#if NEXUS_I2cHandle_CLASS
2518static bool NEXUS_Platform_P_WasI2cOpened(NEXUS_I2cHandle handle)
2519{
2520    int i;
2521    NEXUS_PlatformConfiguration * pConfig = &g_NEXUS_platformHandles.config;
2522
2523    for (i = 0; i < NEXUS_NUM_I2C_CHANNELS; i++)
2524    {
2525        if (handle == pConfig->i2c[i])
2526        {
2527            return true;
2528        }
2529    }
2530
2531    return false;
2532}
2533#endif
2534
2535NEXUS_Error NEXUS_Platform_AcquireI2c(
2536    NEXUS_I2cHandle handle
2537    )
2538{
2539    NEXUS_Error rc = NEXUS_SUCCESS;
2540
2541#if NEXUS_I2cHandle_CLASS && NEXUS_NUM_I2C_CHANNELS
2542    if (NEXUS_Platform_P_WasI2cOpened(handle))
2543    {
2544        rc = nexus_register_NEXUS_I2cHandle(nexus_platform_client(), handle, false);
2545        if (rc) BERR_TRACE(rc);
2546    }
2547    else
2548#else
2549    BSTD_UNUSED(handle);
2550#endif
2551    {
2552        rc = NEXUS_INVALID_PARAMETER;
2553    }
2554
2555    return rc;
2556}
2557
2558void NEXUS_Platform_ReleaseI2c(NEXUS_I2cHandle handle)
2559{
2560#if NEXUS_I2cHandle_CLASS && NEXUS_NUM_I2C_CHANNELS
2561    nexus_unregister_NEXUS_I2cHandle(nexus_platform_client(), handle, false);
2562#else
2563    BSTD_UNUSED(handle);
2564#endif
2565}
2566
2567#if NEXUS_FrontendHandle_CLASS
2568static bool NEXUS_Platform_P_WasFrontendOpened(NEXUS_FrontendHandle handle)
2569{
2570    int i;
2571    NEXUS_PlatformConfiguration * pConfig = &g_NEXUS_platformHandles.config;
2572   
2573    for (i = 0; i < NEXUS_MAX_FRONTENDS; i++)
2574    {
2575        if (handle == pConfig->frontend[i])
2576        {
2577            return true;
2578        }
2579    }
2580
2581    return false;
2582}
2583#endif
2584
2585NEXUS_Error NEXUS_Platform_AcquireFrontend(
2586    NEXUS_FrontendHandle handle
2587    )
2588{
2589    NEXUS_Error rc = NEXUS_SUCCESS;
2590
2591#if NEXUS_FrontendHandle_CLASS
2592    if (NEXUS_Platform_P_WasFrontendOpened(handle))
2593    {
2594        rc = nexus_register_NEXUS_FrontendHandle(nexus_platform_client(), handle, false);
2595        if (rc) BERR_TRACE(rc);
2596    }
2597    else
2598#else
2599    BSTD_UNUSED(handle);
2600#endif
2601    {
2602        rc = NEXUS_INVALID_PARAMETER;
2603    }
2604
2605    return rc;
2606}
2607
2608void NEXUS_Platform_ReleaseFrontend(NEXUS_FrontendHandle handle)
2609{
2610#if NEXUS_FrontendHandle_CLASS
2611    nexus_unregister_NEXUS_FrontendHandle(nexus_platform_client(), handle, false);
2612    NEXUS_Frontend_Untune(handle);
2613#else
2614    BSTD_UNUSED(handle);
2615#endif
2616}
2617
Note: See TracBrowser for help on using the repository browser.