aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/tdmb/mtv318/raontv_internal.h
blob: 1e41350c978ec2d0f6769f8978adef52c07f02c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
/*
 *
 * File name: drivers/media/tdmb/mtv318/src/raontv_internal.h
 *
 * Description : RAONTECH TV internal header file.
 *
 * Copyright (C) (2011, RAONTECH)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation version 2.
 *
 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
 * kind, whether express or implied; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef __RAONTV_INTERNAL_H__
#define __RAONTV_INTERNAL_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "raontv.h"

/* Do not modify the order! */
enum E_RTV_TV_MODE_TYPE {
	RTV_TV_MODE_TDMB = 0, /* Band III  Korea */
	RTV_TV_MODE_DAB_B3 = 1, /* Band III*/
	RTV_TV_MODE_DAB_L = 2, /* L-Band*/
	RTV_TV_MODE_1SEG = 3, /* UHF*/
	RTV_TV_MODE_FM = 4, /* FM*/
	MAX_NUM_RTV_MODE
};

struct RTV_REG_INIT_INFO {
	U8 bReg;
	U8 bVal;
};

struct RTV_REG_MASK_INFO {
	U8 bReg;
	U8 bMask;
	U8 bVal;
};

#if defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)
#if defined(RTV_TSIF_CLK_SPEED_DIV_2) /* Host Clk/2*/
#define RTV_COMM_CON47_CLK_SEL	(0<<6)
#elif defined(RTV_TSIF_CLK_SPEED_DIV_4) /* Host Clk/4*/
#define RTV_COMM_CON47_CLK_SEL	(1<<6)
#elif defined(RTV_TSIF_CLK_SPEED_DIV_6) /* Host Clk/6*/
#define RTV_COMM_CON47_CLK_SEL	(2<<6)
#elif defined(RTV_TSIF_CLK_SPEED_DIV_8) /* Host Clk/8*/
#define RTV_COMM_CON47_CLK_SEL	(3<<6)
#else
#error "Code not present"
#endif
#endif

#define MSC1_E_OVER_FLOW       0x40
#define MSC1_E_UNDER_FLOW      0x20
#define MSC1_E_INT             0x10
#define MSC0_E_OVER_FLOW       0x08
#define MSC0_E_UNDER_FLOW      0x04
#define MSC0_E_INT             0x02
#define FIC_E_INT              0x01
#define RE_CONFIG_E_INT        0x04

#define MSC1_INTR_BITS	(MSC1_E_INT|MSC1_E_UNDER_FLOW|MSC1_E_OVER_FLOW)
#define MSC0_INTR_BITS	(MSC0_E_INT|MSC0_E_UNDER_FLOW|MSC0_E_OVER_FLOW)

/* [2]MSC1 int clear [1]MSC0 int clear [0]FIC int clear */
#define INT_E_UCLRL         (0x35)

/* [6]OFDM TII done clear */
#define INT_E_UCLRH         (0x36)

/* [7]OFDM Lock status [6]MSC1 overrun [5]MSC1 underrun
 * [4]MSC1 int [3]MSC0 overrun [2]MSC0 underrun [1]MSC0 int [0]FIC int */
#define INT_E_STATL         (0x33)

/* [7]OFDM NIS [6]OFDM TII [5]OFDM scan [4]OFDM window position
 * [3]OFDM unlock [2]FEC re-configuration [1]FEC CIF end [0]FEC soft reset*/
#define INT_E_STATH         (0x34)

/* [7]Buf_en [6]PKT_CRC_MODE:enable (stored) [5]MPEG_HEAD [4]MPEG-2TS_EN
 * [3]EPKT_MODE [2]CAS_MODE [1]FIDC_MODE [0]FIC_INIT_EN == 1:enable*/
#define DD_E_TOPCON         (0x45)

/* [4]FIC_CRC stored- 1:enable [3]FIC uclear-1
 * [2]FIC_Update - 1:dependent by user
 * [1]FIC_EN [0]FIG_EN - 1:only FIG 6 dump*/
#define FIC_E_DDCON         (0x46)

/* [3]MSC0 uclear-1
 * [2]MSC0_en
 * [1]MSC0 read length -1:user length, 0:interrupt length
 * [0]MSC0 interrupt sel-1:user th, 0:CIF end*/
#define MSC0_E_CON          (0x47)

/* [5]MSC1_length-0:subch+length [4]MSC1 header-0:disable [3]MSC1 uclear-1
 * [2]MSC1_en [1]MSC1 read length -1:user length, 0:interrupt length
 * [0]MSC1 interrupt sel-1:user th, 0:CIF end*/
#define MSC1_E_CON          (0x48)

/* [3]NIS uclear-1 [2]NIS_Update - 1:dependent by user
 * [1]TII status clear -1:user set only, 0:user set & internal event
 * [0]TII_Update - 1:dependent by user*/
#define OFDM_E_DDCON        (0x49)

/* [11:8] setting in MSC0 read length for interrupt clear*/
#define MSC0_E_RSIZE_H      (0x4E)

/* [7:0]*/
#define MSC0_E_RSIZE_L      (0x4F)

/* [11:8] MSC0 interrupt threshold*/
#define MSC0_E_INTTH_H      (0x50)

/* [7:0]*/
#define MSC0_E_INTTH_L      (0x51)

/* [11:8]*/
#define MSC0_E_TSIZE_L      (0x52)

/* [7:0] MSC0 total size which you can read*/
#define MSC0_E_TSIZE_H      (0x53)

/* [11:8] setting in MSC1 read length for interrupt clear*/
#define MSC1_E_RSIZE_H      (0x54)
#define MSC1_E_RSIZE_L      (0x55)  /* [7:0]*/
#define MSC1_E_INTTH_H      (0x56)  /* [11:8] MSC1 interrupt threshold*/
#define MSC1_E_INTTH_L      (0x57)  /* [7:0]*/
#define MSC1_E_TSIZE_L      (0x58)  /* [11:8]*/
#define MSC1_E_TSIZE_H      (0x59)  /* [7:0] MSC1 read length*/

#define MODE1 2
#define MODE2 1
#define MODE3 0

#define MAP_SEL_REG	0x03

#define OFDM_PAGE	0x02 /* for 1seg */
#define FEC_PAGE	0x03 /* for 1seg */
#define COMM_PAGE	0x04
#define FM_PAGE		0x06 /* T-DMB OFDM/FM */
#define HOST_PAGE	0x07
#define CAS_PAGE	0x08
#define DD_PAGE		0x09 /* FEC for TDMB, DAB, FM */
#define FIC_PAGE	0x0A
#define MSC0_PAGE	0x0B
#define MSC1_PAGE	0x0C
#define RF_PAGE		0x0F

#define DEMOD_0SC_DIV2_ON  0x80
#define DEMOD_0SC_DIV2_OFF 0x00

#if (RTV_SRC_CLK_FREQ_KHz >= 32000)
#define DEMOD_OSC_DIV2	DEMOD_0SC_DIV2_ON
#else
#define DEMOD_OSC_DIV2	DEMOD_0SC_DIV2_OFF
#endif

#define MAP_SEL_VAL(page)		(DEMOD_OSC_DIV2|page)
#define RTV_REG_MAP_SEL(page)	RTV_REG_SET(MAP_SEL_REG, MAP_SEL_VAL(page))

#define RTV_TS_STREAM_DISABLE_DELAY		20 /* ms */

/* ISDB-T Channel */
#define ISDBT_CH_NUM_START__JAPAN			13
#define ISDBT_CH_NUM_END__JAPAN				62
#define ISDBT_CH_FREQ_START__JAPAN			473143
#define ISDBT_CH_FREQ_STEP__JAPAN			6000

#define ISDBT_CH_NUM_START__BRAZIL			14
#define ISDBT_CH_NUM_END__BRAZIL			69
#define ISDBT_CH_FREQ_START__BRAZIL			473143
#define ISDBT_CH_FREQ_STEP__BRAZIL			6000

#define ISDBT_CH_NUM_START__ARGENTINA		14
#define ISDBT_CH_NUM_END__ARGENTINA			69
#define ISDBT_CH_FREQ_START__ARGENTINA		473143
#define ISDBT_CH_FREQ_STEP__ARGENTINA		6000

/* T-DMB Channel */
#define TDMB_CH_FREQ_START__KOREA		175280
#define TDMB_CH_FREQ_STEP__KOREA		1728 /* about... */
/* DAB Channel */
#define DAB_CH_BAND3_START_FREQ_KHz		174928
#define DAB_CH_BAND3_STEP_FREQ_KHz		1712 /* in KHz */
#define DAB_CH_LBAND_START_FREQ_KHz		1452960
#define DAB_CH_LBAND_STEP_STEP_FREQ_KHz	1712 /*in KHz */

extern enum E_RTV_ADC_CLK_FREQ_TYPE g_eRtvAdcClkFreqType;
extern enum E_RTV_COUNTRY_BAND_TYPE g_eRtvCountryBandType;

#ifdef RTV_DAB_ENABLE
extern enum E_RTV_TV_MODE_TYPE g_curDabSetType;
#endif

/* Use SPI/EBI2 interrupt handler to prevent the changing of register map. */
extern BOOL g_fRtvChannelChange;
extern BOOL g_fRtvStreamEnabled;

extern UINT g_nRtvMscThresholdSize;

#if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
extern U8 g_bRtvIntrMaskRegL;

#else
#if !defined(RTV_CIF_MODE_ENABLED) || !defined(RTV_FIC_POLLING_MODE)
/* T-DMB: Single sub channel and Serial TSIF */
extern U8 g_bRtvIntrMaskRegL;
#endif
#endif

/*See PLL table in raontv_rf_pll_data_fm.h */
#define FM_MIN_FREQ_KHz			75950
#define FM_MAX_FREQ_KHz			108050
#define FM_SCAN_STEP_FREQ_KHz		(RTV_FM_CH_STEP_FREQ_KHz/2)

#if (RTV_FM_CH_MIN_FREQ_KHz < FM_MIN_FREQ_KHz) \
	|| (RTV_FM_CH_MAX_FREQ_KHz > FM_MAX_FREQ_KHz)
#error "Invalid FM freq range"
#endif

/*============================================================================
 *
 * Common inline functions.
 *
 *===========================================================================*/

/* Forward prototype. */
static INLINE void rtv_SetupMemory_MSC1(U16 wThresholdSize);

static INLINE enum E_RTV_TV_MODE_TYPE rtv_GetDabTvMode(U32 dwChFreqKHz)
{
	if (dwChFreqKHz >= DAB_CH_LBAND_START_FREQ_KHz) {
		/*RTV_DBGMSG0("return RTV_TV_MODE_DAB_L;\n");*/
		return RTV_TV_MODE_DAB_L; /* L-Band */
	} else {
		switch (dwChFreqKHz) {
		case 175280/*7A*/: case 177008/*7B*/: case 178736/*7C*/:
		case 181280/*8A*/: case 183008/*8B*/: case 184736/*8C*/:
		case 187280/*9A*/: case 189008/*9B*/: case 190736/*9C*/:
		case 193280/*10A*/: case 195008/*10B*/: case 196736/*10C*/:
		case 199280/*11A*/: case 201008/*11B*/: case 202736/*11C*/:
		case 205280/*12A*/: case 207008/*12B*/: case 208736/*12C*/:
		case 211280/*13A*/: case 213008/*13B*/: case 214736/*13C*/:
			/*RTV_DBGMSG0("return RTV_TV_MODE_TDMB;\n");*/
			return RTV_TV_MODE_TDMB; /*Korea TDMB.*/

		default:
			/*RTV_DBGMSG0("return RTV_TV_MODE_DAB_B3;\n"); */
			return RTV_TV_MODE_DAB_B3; /* DAB Band-III */
		}
	}
}

/* Pause straem */
static INLINE void rtv_StreamDisable(enum E_RTV_TV_MODE_TYPE eTvMode)
{
#ifndef RTV_IF_MPEG2_PARALLEL_TSIF
	if (g_fRtvStreamEnabled == FALSE)
		return;

	switch (eTvMode) {
#ifdef RTV_ISDBT_ENABLE
	case RTV_TV_MODE_1SEG:
#if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
		RTV_REG_MAP_SEL(HOST_PAGE);
		/* FIC, MSC0, MSC1 */
		RTV_REG_SET(0x62,
			g_bRtvIntrMaskRegL|MSC0_INTR_BITS|MSC1_INTR_BITS);

#elif defined(RTV_IF_MPEG2_SERIAL_TSIF) \
	|| defined(RTV_IF_SPI_SLAVE)\
	|| defined(RTV_IF_QUALCOMM_TSIF)

		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x29, 0x08);
		RTV_DELAY_MS(RTV_TS_STREAM_DISABLE_DELAY);
#endif
		break;
#endif /* RTV_ISDBT_ENABLE */

#ifdef RTV_FM_ENABLE
	case RTV_TV_MODE_FM:
#if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
		RTV_REG_MAP_SEL(HOST_PAGE);
		/* FIC, MSC0, MSC1 */
		RTV_REG_SET(0x62,
			g_bRtvIntrMaskRegL|MSC0_INTR_BITS|MSC1_INTR_BITS);

#elif defined(RTV_IF_MPEG2_SERIAL_TSIF) \
	|| defined(RTV_IF_SPI_SLAVE) \
	|| defined(RTV_IF_QUALCOMM_TSIF)

		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x29, 0x08);
		RTV_DELAY_MS(RTV_TS_STREAM_DISABLE_DELAY);
#endif
		break;
#endif/* RTV_FM_ENABLE */

#ifdef RTV_TDMB_ENABLE
	case RTV_TV_MODE_TDMB:
#if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
		RTV_REG_MAP_SEL(HOST_PAGE);

		/* FIC, MSC0, MSC1 */
		RTV_REG_SET(0x62,
		g_bRtvIntrMaskRegL|MSC0_INTR_BITS|MSC1_INTR_BITS|FIC_E_INT);
#elif defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)
		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x29, 0x08);
		RTV_DELAY_MS(RTV_TS_STREAM_DISABLE_DELAY);

#ifndef RTV_CIF_MODE_ENABLED /* Individual Mode */
#ifndef RTV_FIC_POLLING_MODE
		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x62, g_bRtvIntrMaskRegL|FIC_E_INT);
#endif
#else /* CIF Mode. */

#endif
#endif
		break;
#endif	/* RTV_TDMB_ENABLE */

#ifdef RTV_DAB_ENABLE
	case RTV_TV_MODE_DAB_B3:
	case RTV_TV_MODE_DAB_L:
	case RTV_TV_MODE_TDMB:
#if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x62,
		g_bRtvIntrMaskRegL|MSC0_INTR_BITS|MSC1_INTR_BITS|FIC_E_INT);

#elif defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)
		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x29, 0x08);
		RTV_DELAY_MS(RTV_TS_STREAM_DISABLE_DELAY);

#ifndef RTV_CIF_MODE_ENABLED /* Individual Mode */
#ifndef RTV_FIC_POLLING_MODE
		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x62, g_bRtvIntrMaskRegL|FIC_E_INT);
#endif
#else /* Multi Sub Channel Mode. */

#endif
#endif
		break;
#endif	/* RTV_DAB_ENABLE */

	default:
		break;
	}

	g_fRtvStreamEnabled = FALSE;
#endif
}


static INLINE void rtv_StreamRestore(enum E_RTV_TV_MODE_TYPE eTvMode)
{
#ifndef RTV_IF_MPEG2_PARALLEL_TSIF
	if (g_fRtvStreamEnabled == TRUE)
		return;

	switch (eTvMode) {
#ifdef RTV_ISDBT_ENABLE
	case RTV_TV_MODE_1SEG:
#if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
		RTV_REG_MAP_SEL(DD_PAGE);
		RTV_REG_SET(0x35, 0x04); /* MSC1 Interrupt status clear. */

		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x62, g_bRtvIntrMaskRegL);
#endif
		break;
#endif

#ifdef RTV_FM_ENABLE
	case RTV_TV_MODE_FM:
#if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
		RTV_REG_MAP_SEL(DD_PAGE);
		RTV_REG_SET(0x35, 0x04);

		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x62, g_bRtvIntrMaskRegL);
#elif defined(RTV_IF_SERIAL_TSIF) || defined(RTV_IF_SPI_SLAVE)
		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x29, 0x00);
#endif
		break;
#endif

#ifdef RTV_TDMB_ENABLE
	case RTV_TV_MODE_TDMB:
#if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
		RTV_REG_MAP_SEL(DD_PAGE);
		RTV_REG_SET(0x35, 0x07);

		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x62, g_bRtvIntrMaskRegL);

#elif defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)
		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x29, 0x00);

#ifndef RTV_CIF_MODE_ENABLED /* Individual Mode */
#ifndef RTV_FIC_POLLING_MODE
		RTV_REG_MAP_SEL(DD_PAGE);
		RTV_REG_SET(0x35, 0x01);

		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x62, g_bRtvIntrMaskRegL);
#endif
#else /* Multi Sub Channel Mode. */
#endif
#endif
		break;
#endif

#ifdef RTV_DAB_ENABLE
	case RTV_TV_MODE_DAB_B3:
	case RTV_TV_MODE_DAB_L:
	case RTV_TV_MODE_TDMB:
#if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
		RTV_REG_MAP_SEL(DD_PAGE);
		RTV_REG_SET(0x35, 0x07);

		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x62, g_bRtvIntrMaskRegL);/* FIC, MSC0, MSC1 */

#elif defined(RTV_IF_TSIF) || defined(RTV_IF_SPI_SLAVE)
		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x29, 0x00);

#ifndef RTV_CIF_MODE_ENABLED /* Individual Mode */
#ifndef RTV_FIC_POLLING_MODE
		RTV_REG_MAP_SEL(DD_PAGE);
		RTV_REG_SET(0x35, 0x01); /* FIC Interrupt status clear. */

		RTV_REG_MAP_SEL(HOST_PAGE);
		RTV_REG_SET(0x62, g_bRtvIntrMaskRegL);
#endif
#else /* Multi Sub Channel Mode. */
#endif
#endif
		break;
#endif	/* RTV_DAB_ENABLE */
	default:
		/* RTV_DBGMSG0("[rtv_StreamRestore] Invalid TV mode.\n"); */
		break;
	}

	g_fRtvStreamEnabled = TRUE;
#endif
}

/* Enable the stream path forcely for ISDB-T and FM only! */
static INLINE void rtv_StreamEnable(void)
{
#ifndef RTV_IF_MPEG2_PARALLEL_TSIF
	if (g_fRtvStreamEnabled == TRUE)
		return;

#if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
	RTV_REG_MAP_SEL(DD_PAGE);
	RTV_REG_SET(0x35, 0x04); /* MSC1 Interrupt status clear. */

	RTV_REG_MAP_SEL(HOST_PAGE);

	/* [6] MSC1 over-run [5] MSC1 under-run [4] MSC1 interrupt */
	g_bRtvIntrMaskRegL = 0x8F;
	RTV_REG_SET(0x62, g_bRtvIntrMaskRegL);

#elif defined(RTV_IF_SERIAL_TSIF) || defined(RTV_IF_SPI_SLAVE)
	RTV_REG_MAP_SEL(HOST_PAGE);
	RTV_REG_SET(0x29, 0x00);
#endif

	/* Restore MSC1 memory. */
	rtv_SetupMemory_MSC1(g_nRtvMscThresholdSize);

	g_fRtvStreamEnabled = TRUE;
#endif /* #ifndef RTV_IF_MPEG2_PARALLEL_TSIF */
}

static INLINE void rtv_ConfigureTsifFormat(void)
{
	RTV_REG_MAP_SEL(COMM_PAGE);

#if defined(RTV_IF_MPEG2_SERIAL_TSIF) || defined(RTV_IF_SPI_SLAVE)
#if defined(RTV_TSIF_FORMAT_1)
	RTV_REG_SET(0x45, 0x00);
#elif defined(RTV_TSIF_FORMAT_2)
	RTV_REG_SET(0x45, 0x02);
#elif defined(RTV_TSIF_FORMAT_3)
	RTV_REG_SET(0x45, 0x21);
#elif defined(RTV_TSIF_FORMAT_4)
	RTV_REG_SET(0x45, 0x23);
#else
#error "Code not present"
#endif

#elif defined(RTV_IF_QUALCOMM_TSIF)
#if defined(RTV_TSIF_FORMAT_1)
	RTV_REG_SET(0x45, 0x00);
#elif defined(RTV_TSIF_FORMAT_2)
	RTV_REG_SET(0x45, 0xE9);

#elif defined(RTV_TSIF_FORMAT_3)
	RTV_REG_SET(0x45, 0xE1);
#elif defined(RTV_TSIF_FORMAT_4)
	RTV_REG_SET(0x45, 0x40);
#elif defined(RTV_TSIF_FORMAT_5)
	RTV_REG_SET(0x45, 0x21);
#else
#error "Code not present"
#endif
#endif

#if defined(RTV_IF_MPEG2_SERIAL_TSIF)
	RTV_REG_SET(0x46, 0x80);
#elif defined(RTV_IF_QUALCOMM_TSIF)
	RTV_REG_SET(0x46, 0xA0);
#elif defined(RTV_IF_SPI_SLAVE)
	RTV_REG_SET(0x46, 0x82);
#endif
}

static INLINE void rtv_ResetMemory_MSC0(void)
{
	RTV_REG_MAP_SEL(DD_PAGE);
	RTV_REG_SET(0x47, 0x00); /* MSC0 memory control register clear. */
}

static INLINE void rtv_ResetMemory_MSC1(void)
{
#ifndef RTV_IF_MPEG2_PARALLEL_TSIF
	RTV_REG_MAP_SEL(DD_PAGE);
	RTV_REG_SET(0x48, 0x00); /* MSC1 memory control register clear. */
#endif
}

/* Only for T-DMB and DAB. */
static INLINE void rtv_ClearAndSetupMemory_MSC0(void)
{
#ifndef RTV_IF_MPEG2_PARALLEL_TSIF

#if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
#ifdef RTV_MSC_INTR_ISTAUS_ACC_CLR_MODE
	U8 msc0_int_usel = 0; /* 0: auto&uclr, 1: user set only */
#else
	U8 msc0_int_usel = 1;
#endif
#else
	U8 msc0_int_usel = 0;
#endif

#ifndef RTV_CIF_MODE_ENABLED /* Individual Mode */
	U8 int_type = 1; /* 0: CIF end,  1: Threshold */
#else
	U8 int_type = 0;
#endif

	RTV_REG_SET(0x47, 0x00);
	RTV_REG_SET(0x47, (msc0_int_usel<<3) | (1/*msc0_en*/<<2) | int_type);
#endif /* #ifndef RTV_IF_MPEG2_PARALLEL_TSIF */
}

/* Only for T-DMB and DAB. */
static INLINE void rtv_SetupMemory_MSC0(U16 wThresholdSize)
{
#ifndef RTV_IF_MPEG2_PARALLEL_TSIF
	RTV_REG_MAP_SEL(DD_PAGE);

	RTV_REG_SET(0x50, ((wThresholdSize>>8) & 0x0F));
	RTV_REG_SET(0x51, (wThresholdSize & 0xFF));

	rtv_ClearAndSetupMemory_MSC0();

	RTV_REG_SET(0x35, 0x02); /* MSC0 Interrupt clear. */

#endif /* #ifndef RTV_IF_MPEG2_PARALLEL_TSIF */
}

/* For SPI interface ISR. */
static INLINE void rtv_ClearAndSetupMemory_MSC1(void)
{
#ifndef RTV_IF_MPEG2_PARALLEL_TSIF
#if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
#ifdef RTV_MSC_INTR_ISTAUS_ACC_CLR_MODE
	U8 msc1_int_usel = 0; /* 0: auto&uclr, 1: user set only */
#else
	U8 msc1_int_usel = 1;
#endif
#else
	/* TSIF */
	U8 msc1_int_usel = 0;
#endif

	U8 int_type = 1; /* 0: CIF end, 1: Threshold (for SPI, Header OFF) */

	RTV_REG_SET(0x48, 0x00);
	RTV_REG_SET(0x48,
	(0<<5) | (0<<4) | (msc1_int_usel<<3) | (1/*msc1_en*/<<2) | int_type);

#endif /* #ifndef RTV_IF_MPEG2_PARALLEL_TSIF */
}

static INLINE void rtv_SetupMemory_MSC1(U16 wThresholdSize)
{
#ifndef RTV_IF_MPEG2_PARALLEL_TSIF
	RTV_REG_MAP_SEL(DD_PAGE);

	/* The below settings are not applied to CIF of TDMB/DAB. */
	RTV_REG_SET(0x56, ((wThresholdSize>>8) & 0x0F));
	RTV_REG_SET(0x57, (wThresholdSize & 0xFF));

	rtv_ClearAndSetupMemory_MSC1();
#endif /* #ifndef RTV_IF_MPEG2_PARALLEL_TSIF */
}

/* Only this sub channel contains the RS decoder. */
static INLINE void rtv_Set_MSC1_SUBCH0(UINT nSubChID,
					BOOL fSubChEnable, BOOL fRsEnable)
{
	RTV_REG_MAP_SEL(DD_PAGE);

#if !defined(RTV_IF_MPEG2_PARALLEL_TSIF)
	RTV_REG_SET(0x3A, (fSubChEnable << 7) | (fRsEnable << 6) | nSubChID);
#else
	if (fRsEnable == TRUE) {
		RTV_REG_SET(0xFF, 0x00);
		RTV_REG_SET(0x3A,
			(fSubChEnable << 7) | (fRsEnable << 6) | nSubChID);

	} else {
		RTV_REG_SET(0x3A, 0x00);
		RTV_REG_SET(0xFF, (fSubChEnable << 7) | nSubChID);
	}
#endif
}

static INLINE void rtv_Set_MSC1_SUBCH1(UINT nSubChID, BOOL fSubChEnable)
{
	RTV_REG_MAP_SEL(DD_PAGE);
	RTV_REG_SET(0x3B, (fSubChEnable << 7) | nSubChID);
}

static INLINE void rtv_Set_MSC1_SUBCH2(UINT nSubChID, BOOL fSubChEnable)
{
	RTV_REG_MAP_SEL(DD_PAGE);
	RTV_REG_SET(0x3C, (fSubChEnable << 7) | nSubChID);
}

static INLINE void rtv_Set_MSC0_SUBCH3(UINT nSubChID, BOOL fSubChEnable)
{
	RTV_REG_MAP_SEL(DD_PAGE);
	RTV_REG_SET(0x3D, (fSubChEnable << 7) | nSubChID);
}

static INLINE void rtv_Set_MSC0_SUBCH4(UINT nSubChID, BOOL fSubChEnable)
{
	RTV_REG_MAP_SEL(DD_PAGE);
	RTV_REG_SET(0x3E, (fSubChEnable << 7) | nSubChID);
}

static INLINE void rtv_Set_MSC0_SUBCH5(UINT nSubChID, BOOL fSubChEnable)
{
	RTV_REG_MAP_SEL(DD_PAGE);
	RTV_REG_SET(0x3F, (fSubChEnable << 7) | nSubChID);
}

static INLINE void rtv_Set_MSC0_SUBCH6(UINT nSubChID, BOOL fSubChEnable)
{
	RTV_REG_MAP_SEL(DD_PAGE);
	RTV_REG_SET(0x42, (fSubChEnable << 7) | nSubChID);
}

/*=============================================================================
 *
 * T-DMB inline functions.
 *
 *===========================================================================*/
static INLINE void rtv_SetupMemory_FIC(void)
{
	RTV_REG_MAP_SEL(DD_PAGE);
	/* auto user clr, get fic  CRC 2byte including[4] */
	RTV_REG_SET(0x46, 0x10);
	RTV_REG_SET(0x46, 0x16); /* FIC enable */
}

static INLINE void rtv_ResetMemory_FIC(void)
{

	RTV_REG_MAP_SEL(DD_PAGE);
	RTV_REG_SET(0x46, 0x00);
}

/*==============================================================================
 *
 * Parallel TSIF inline functions.
 *
 *============================================================================*/
#ifdef RTV_IF_MPEG2_PARALLEL_TSIF
#if defined(RTV_ISDBT_ENABLE)
static INLINE void rtv_SetParallelTsif_1SEG_Only(void)
{
	RTV_REG_MAP_SEL(FEC_PAGE);

#if defined(RTV_TSIF_FORMAT_1)
	RTV_REG_SET(0x6E, 0x11);
#elif defined(RTV_TSIF_FORMAT_2)
	RTV_REG_SET(0x6E, 0x13);
#elif defined(RTV_TSIF_FORMAT_3)
	RTV_REG_SET(0x6E, 0x10);
#elif defined(RTV_TSIF_FORMAT_4)
	RTV_REG_SET(0x6E, 0x12);
#else
#error "Code not present"
#endif
	RTV_REG_SET(0x6F, 0x02);
	RTV_REG_SET(0x70, 0x88);
}

#elif defined(RTV_TDMB_ENABLE)
static INLINE void rtv_SetParallelTsif_TDMB_Only(void)
{
	RTV_REG_MAP_SEL(0x09);

#if defined(RTV_TSIF_FORMAT_1)
	RTV_REG_SET(0xDD, 0xD0);
#elif defined(RTV_TSIF_FORMAT_2)
	RTV_REG_SET(0xDD, 0xD2);
#elif defined(RTV_TSIF_FORMAT_3)
	RTV_REG_SET(0xDD, 0xD1);
#elif defined(RTV_TSIF_FORMAT_4)
	RTV_REG_SET(0xDD, 0xD3);
#else
#error "Code not present"
#endif
	RTV_REG_SET(0xDE, 0x12);
	RTV_REG_SET(0x45, 0xB0);
}
#else
#error "Code not present"
#endif
#endif

/*==============================================================================
 * External functions for RAONTV driver core.
 *============================================================================*/
void rtv_ConfigureHostIF(void);
INT rtv_InitSystem(enum E_RTV_TV_MODE_TYPE eTvMode,
		enum E_RTV_ADC_CLK_FREQ_TYPE eAdcClkFreqType);

#ifdef RTV_CIF_HEADER_INSERTED
void rtvCIFDEC_Init(void);
void rtvCIFDEC_Deinit(void);
void rtvCIFDEC_DeleteSubChannelID(UINT nSubChID);
void rtvCIFDEC_AddSubChannelID(UINT nSubChID);
#endif

#ifdef __cplusplus
}
#endif

#endif /* __RAONTV_INTERNAL_H__ */

/*
 WINDOWS
 #define INLINE __inline
 #define FORCE_INLINE __forceinline
 #define NAKED __declspec(naked)

 __GNUC__
 #define INLINE __inline__
 #define FORCE_INLINE __attribute__((always_inline)) __inline__
 #define NAKED __attribute__((naked))

 ARM RVDS compiler
 #define INLINE __inline
 #define FORCE_INLINE __forceinline
 #define NAKED __asm
 */