source: svn/newcon3bcm2_21bu/dst/dhl/src/DHL_FE_Platform_lg3305.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: 12.1 KB
Line 
1
2/********************************************************************
3        DHL_FE_Platform_lg3305.c
4
5        write by yhkim
6       
7        LG3305 µå¶óÀ̹ö¸¦ Áö¿øÇϱâ À§ÇÑ È®Àå¿ë API
8       
9********************************************************************/
10
11#include "DHL_OSAL.h"
12#include "DHL_DBG.h"
13#include "DHL_SYS.h"
14#include "DHL_SYS_Config.h"
15
16#include "DHL_FE_Priv.h"
17
18
19
20// FE Driver header ¼±¾ð..
21#include "LG3305.h"
22
23
24
25
26#if COMMENT
27____DBG____(){}
28#endif
29
30//DHL_MODULE("*fe", 0);
31
32
33
34#if COMMENT
35____Global____(){}
36#endif
37
38
39#define LG3305_VENDOR_NAME "LG"
40#define LG3305_MODEL_NAME "LG3305"
41
42
43static tDHL_Demod g_last_demod_type[DHL_CFG_NUM_TUNER];
44
45
46static DHL_RESULT dhl_LG3305_check_lock(tDHL_TunerID id, UINT32 *pValue);
47static DHL_RESULT dhl_LG3305_check_snr1000(tDHL_TunerID id, UINT32 *pValue);
48static DHL_RESULT dhl_LG3305_check_ser(tDHL_TunerID id, UINT32 *pValue);
49
50
51
52#if COMMENT
53___Local_Func__() {}
54#endif
55
56
57struct curv_pt {
58        int x;
59        int y;
60};
61
62static struct curv_pt c_linear[] = // ¼±Çü ¸ÅÇÎ.
63{
64        { 0, 0 },
65        { 1000,1000 },
66};
67
68static struct curv_pt c_s_soft[] = // s curve ¸ÅÇÎ.
69{ 
70        { 0, 0 },
71        { 400, 300, },
72        { 600, 700, },
73        { 1000, 1000 },
74};
75
76static struct curv_pt c_s_strong[] = // s curve ¸ÅÇÎ 2
77{ 
78        { 0, 0 },
79        { 400, 200, },
80        { 600, 800, },
81        { 1000, 1000 },
82};
83
84static struct curv_pt c_snr_2_strength[] = 
85{
86        {   0,    0 },
87        {  60,   60 }, // x1.0
88        { 120,  180 }, // x1.5
89        { 180,  360 }, // x2.0
90        { 240,  600 }, // x2.5
91        { 300,  900 }, // x3.0
92        { 400, 1000 },
93};
94
95#define N_ELEM(a) (sizeof(a)/sizeof(a[0]))
96
97static struct {
98        struct curv_pt* tbl;
99        int size;
100} tables[] = {
101        // Á¦°ø °¡´ÉÇÑ curve µéÀ» ¿©±â¿¡ ³ª¿­.
102        {c_linear, N_ELEM(c_linear)},   // 0
103        {c_s_soft, N_ELEM(c_s_soft)},   // 1
104        {c_s_strong, N_ELEM(c_s_strong)}, // 2
105        {c_snr_2_strength, N_ELEM(c_snr_2_strength)}, // 3
106};
107       
108       
109
110static float p_interpolate(int x1, int y1, int x2, int y2, int xi)
111{
112        if (x1 == x2)
113                return (y1 + y2)/2.;
114       
115        return ((y2)-(y1)) * ((xi)-(x1)) / (float)((x2)-(x1)) + (y1);
116}
117
118static float p_apply_curve(UINT32 type, int x)
119{
120        int i;
121       
122       
123
124        struct curv_pt *tbl;
125        int size;
126        float fy;
127       
128        if (type > N_ELEM(tables)) {
129                printf("!! invalid curve type %d\n", type);
130                type = 0;
131        }
132
133        tbl = tables[type].tbl;
134        size = tables[type].size;
135
136        if (x <= tbl[0].x) { // ÁÂÃø °æ°è ¹þ¾î³². ù¹øÂ° boundary °ª »ç¿ë.
137                fy = tbl[0].y;
138                goto label_end;
139        }
140
141        //printf(" tble : (%d %d) (%d %d)\n", tbl[0].x, tbl[0].y, tbl[1].x, tbl[1].y);
142       
143        for (i=1; i<size; i++)
144        {
145                // x°¡ tbl[i-1] tbl[i] »çÀÌ °ªÀ̸é
146                if (tbl[i-1].x <= x && x <= tbl[i].x)
147                {
148                        // ±× Áß°£ °ªÀ» °è»ê.
149                        fy = p_interpolate(tbl[i-1].x, tbl[i-1].y, tbl[i].x, tbl[i].y, x);
150                        //printf(" -> %d, size %d, %d<%d<%d \n", (int)fy, size, tbl[i-1].x, x, tbl[i].x);
151
152                        goto label_end;
153                }
154        }
155        fy = tbl[size-1].y; // ¿ìÃø °æ°è ¹þ¾î³². ¸¶Áö¸· boundary °ªÀ» »ç¿ë.
156        //printf(" x:%d -> fy:%d, right limit\n", x, (int)fy);
157
158label_end:
159
160        return fy;
161       
162}
163
164
165
166static int p_get_sig_strength(int snr10)
167{
168        int strength;
169       
170        strength=(int)p_apply_curve(3, snr10)/10;
171       
172        return strength;
173}
174
175
176
177#if COMMENT
178____API____(){}
179#endif
180
181
182
183/* LG3305 ÃʱâÈ­ Driver API ÇÔ¼ö
184
185        ÀÎÀÚ : I2C Ch.No , Device Addr
186       
187        Driver API ·Î ²À! FE_ID, I2C_ID, I2C_Addr À» ³Ñ°ÜÁØ´Ù..
188
189*/
190DHL_RESULT dhl_LG3305_init(tDHL_TunerID id, DHL_BOARD_REV rev, 
191        tDHL_DEV_I2C_ID hI2c, UINT8 i2cAddr)
192{
193
194        DHL_RESULT dhr = DHL_OK;
195        LgdtReturn_t nRet = LGDT_ERR_NO;
196       
197
198        if(id == 0)
199        {
200                dprint(1, "id : %d, Rev : 0x%04x, I2C_ID : %d, I2C_Addr : 0x%02x, LG3305 \r\n",
201                                        id, rev, hI2c, i2cAddr);
202
203                // Demod Reset Active low (> 1ms)
204                DHL_SYS_ResetGPIO(GPIO_DEMOD_RST);                     
205                DHL_OS_Delay(1);
206                DHL_SYS_SetGPIO(GPIO_DEMOD_RST);
207
208                nRet = LG3305_init(id, hI2c, i2cAddr);
209                if(nRet != LGDT_ERR_NO)
210                {
211                        dprint(0, " FE_ID : %d, LG3305 in-band init Error!!! \r\n", id);
212                        dhr = DHL_FAIL;
213                }
214                else
215                {
216                        dprint(0, " FE_ID : %d, LG3305 in-band init OK!!! \r\n", id);
217                }
218               
219#ifdef _FE_LGH952F
220#else
221                LgdtAlterRegi(0x030C, 0x38);
222                LgdtAlterRegi(0x0300, 0x05);
223                LgdtAlterRegi(0x0301, 0x00);
224#endif
225
226                LG3305_RepeaterI2C(id, PASS_OFF); // Tuner Control À» À§ÇØ Pass ¸¦ On ÇØÁÜ..                   
227        }
228       
229
230        return dhr;
231
232}
233
234
235
236DHL_RESULT dhl_LG3305_open(tDHL_TunerID id, DHL_BOARD_REV rev)
237{
238
239        DHL_RESULT dhr = DHL_OK;
240       
241
242        if(id == 0)
243        {
244        }
245       
246
247        return dhr;
248
249}
250
251
252DHL_RESULT dhl_LG3305_close(tDHL_TunerID id, DHL_BOARD_REV rev)
253{
254
255        DHL_RESULT dhr = DHL_OK;
256       
257
258        if(id == 0)
259        {
260        }
261       
262
263        return dhr;
264
265}
266
267
268/* LG3305 tune Driver API ÇÔ¼ö
269
270        ÁÖ¾îÁø Á֯ļö(KHz) ¹× demod(ÇöÀç ... ¸¸ Áö¿ø..) ·Î Æ©´×ÇÑ´Ù.
271        In-band ¿Í OOB Demod type À» ±¸ºÐÇÏ¿© ó¸®..
272       
273*/
274DHL_RESULT dhl_LG3305_start(tDHL_TunerID id, DHL_BOARD_REV rev, 
275        UINT32 freqKHz, tDHL_Demod demod, tDHL_DemodExtSettings *settings)
276{
277
278        DHL_RESULT dhr = DHL_OK;
279        LgdtReturn_t nRet = LGDT_ERR_NO;
280
281        LgdtOperMode_t demod_LGDT;
282        double if_freq = 0;
283
284        if(id == 0)
285        {
286                if_freq = 44.0;
287
288                if(demod == eDHL_DEMOD_8VSB)
289                        demod_LGDT = LGDT_VSB;
290                else if(demod == eDHL_DEMOD_64QAM)
291                        demod_LGDT = LGDT_QAM64;
292                else if(demod == eDHL_DEMOD_256QAM)
293                        demod_LGDT = LGDT_QAM256;
294                else
295                {                               
296                        dprint(0, " FE_ID : %d, LG3305 demod type out of range !!! \r\n", id);
297                        dhr = DHL_FAIL;
298                        goto err_exit;                 
299                }                                               
300
301                g_last_demod_type[id] = demod;  // Demod ¼³Á¤°ªÀ» ÀúÀå.. Â÷ÈÄ ºñ±³ ¹× ¹ÝȯÀ» À§ÇØ..
302
303                nRet = LG3305_tune(id, demod_LGDT, if_freq);
304                if(nRet != LGDT_ERR_NO)
305                {
306                        dprint(0, " FE_ID : %d, LG3305 in-band tune Fail!!! \r\n", id);
307                        dhr = DHL_FAIL;
308                }
309                else
310                {
311                        dprint(0, " FE_ID : %d, LG3305 in-band tune OK!!! \r\n", id);
312                }
313               
314#ifdef _FE_LGH952F
315#else
316                LgdtAlterRegi(0x030C, 0x38);
317                LgdtAlterRegi(0x0300, 0x05);
318                LgdtAlterRegi(0x0301, 0x00);
319#endif
320        }// id : 0
321       
322
323err_exit:
324
325        return dhr;
326
327}
328
329
330/*      tune stop Driver API ÇÔ¼ö
331
332        FE ¿¡ Çѹø tune ¸í·ÉÀ» ³»·Á tune ÀÌ µÇ¸é tune »óŰ¡ À¯ÁöµÈ´Ù.
333        FE ¿¡¼­ Lock üũ¸¦ ÇÏ¿© snr, Lock »óŵîÀ» °¡Áö°í Decoder ´Ü¿¡¼­ È­¸é Ãâ·ÂÀ» ÆÇ´Ü...
334        µû¶ó¼­ stop À» À§ÇØ tune ¼³Á¤°ªÀ» ¹Ù²ÙÁö ¾Ê°í Lock üũ ºÎºÐÀ» disable ÇÏ¿© tune ¾ÈµÈ°Í ó·³
335        º¸À̰ÔÇÔ..
336        ÀÌÀü Lock »óŰªÀº ÃʱâÈ­ ½ÃÅ´..
337       
338       
339*/
340DHL_RESULT dhl_LG3305_stop(tDHL_TunerID id, DHL_BOARD_REV rev)
341{
342
343        DHL_RESULT dhr = DHL_OK;
344
345
346        if(id == 0)
347        {
348        }
349       
350
351        return dhr;
352
353}
354
355
356
357DHL_RESULT dhl_LG3305_get_sig_info(tDHL_TunerID id, DHL_BOARD_REV rev, 
358        tDHL_SignalStatus selector, UINT32 *pValue)
359{
360
361        DHL_RESULT dhr = DHL_OK;
362
363
364        if(id == 0)
365        {
366                switch(selector) 
367                {
368                        case eDHL_SIGNAL_LOCK :
369                                dhr = dhl_LG3305_check_lock(id, pValue);
370                                //dprint(2, "    lock status: %d\n", *pValue);
371                                break;
372                               
373                        // UDCPÀÇ direct 3114 controlÀ» À§ÇÑ Àü¿ë ÄÚµå.
374                        // bcm firmware°¡ »ç¿ëµÉ °æ¿ì ÇÊ¿ä ¾øÀ½. ³ªÁß¿¡ »èÁ¦.
375                        case eDHL_SIGNAL_LOCK_PROGRESS:
376                               
377                                break;
378
379                        case eDHL_SIGNAL_SER:
380                        case eDHL_SIGNAL_SER_1SEC:
381                        case eDHL_SIGNAL_SER_10SEC:
382                        case eDHL_SIGNAL_PER:
383                        case eDHL_SIGNAL_BER:
384                                dhr = dhl_LG3305_check_ser(id, pValue);
385                                break;
386               
387                        case eDHL_SIGNAL_STRENGTH :
388                        case eDHL_SIGNAL_METER :
389                                dhr = dhl_LG3305_check_snr1000(id, pValue);
390                                if(dhr==DHL_OK)
391                                        *pValue=(int)p_get_sig_strength(*pValue/100);
392                                else
393                                        pValue=0;
394                                break;
395                       
396                        case eDHL_SIGNAL_SNR :
397                        case eDHL_SIGNAL_SNR2 :
398                                dhr = dhl_LG3305_check_snr1000(id, pValue); // snr À» ´ã´Â º¯¼ö´Â INT ÇüÀε¥..pValue º¯¼ö´Â UINT.. - Àϰæ¿ì´Â..??
399                                break;
400                       
401                        default :
402                                //dprint(0, "!! %s : not supported signal status type\n", __FUNCTION__);
403                                dhr = DHL_FAIL_NOT_IMPLEMENTED;
404                                break;
405                       
406                } /* switch */ 
407        }// id : 0
408       
409
410        return dhr;
411
412}
413
414
415
416DHL_RESULT dhl_LG3305_control(tDHL_TunerID id, DHL_BOARD_REV rev, 
417        tDHL_FeControlType selector, UINT32 arg)
418{
419
420        DHL_RESULT dhr = DHL_OK;
421
422
423        if(id == 0)
424        {
425                switch(selector) {
426                        default :
427                                //dprint(0, "!! %s : not supported control type\n", __FUNCTION__);
428                                dhr = DHL_FAIL_NOT_IMPLEMENTED;
429                                break;
430               
431                } /* switch */
432        } // id : 0
433       
434
435        return dhr;
436
437}
438
439
440/*
441        ¼³Á¤µÈ Demod type À» °¡Á®¿È..
442        Lock üũ¸¦ ¼öÇàÇϸé Lock üũ ¾È¿¡ Demod type À» üũÇÏ´Â ºÎºÐÀÌ ÀÖÀ¸¸ç
443        Lock ÀÌ µÇ¸é Demod type ÀÌ app ¼³Á¤°ª°ú reg ¼ÂÆÃ°ªÀÌ °°´Ù´Â Àǹ̰¡ µÇ¸ç
444        À̶§ App ¼³Á¤°ªÀ» ¹ÝÈ¯ÇØ ÁØ´Ù.
445       
446*/
447DHL_RESULT dhl_LG3305_get_demod_type(tDHL_TunerID id, DHL_BOARD_REV rev, 
448        tDHL_Demod *pDemod)
449{
450
451        DHL_RESULT dhr = DHL_OK;
452
453
454        if(id == 0)
455        {
456                UINT32 pValue;
457       
458                if(pDemod != NULL) {
459                        dhl_LG3305_check_lock(id, &pValue);
460                        if (pValue)
461                                *pDemod = g_last_demod_type[id];
462                        else
463                                *pDemod = eDHL_DEMOD_INVALID;
464                }
465        } // id : 0
466       
467
468        return dhr;
469
470}
471
472
473/*
474        ÀÏ´Ü ±âÁ¸ API ¿Í ȣȯÀ» À§ÇØ Demod ÀÇ °æ¿ì Capability ¸¸ ¹ÝÈ¯ÇØÁÜ..
475
476*/
477DHL_RESULT dhl_LG3305_get_device_info(tDHL_TunerID id, DHL_BOARD_REV rev, 
478        tDHL_TunerDeviceInfo selector, void *pValue)
479{
480
481        DHL_RESULT dhr = DHL_OK;
482
483        if(id == 0)
484        {
485                if(selector==eDHL_FE_DEV_VENDOR_NAME) {
486                        strcat((char *)pValue,"LG");
487                }
488                else if(selector==eDHL_FE_DEV_CAPABILITY_1) {
489                        UINT32 value = 0;
490                        value |= eDHL_TUCAP_VSB;
491                        value |= eDHL_TUCAP_QAM;
492                        //value |= eDHL_TUCAP_OOB;
493                        *(UINT32 *)pValue = value;
494                }
495                else {
496                        return DHL_FAIL_INVALID_PARAM;
497                }       
498        }
499
500        return dhr;
501
502}
503
504
505
506#if COMMENT
507____Function____(){}
508#endif
509
510
511/*
512        Æ©´× lock ¿©ºÎ¸¦ ¸®ÅÏ.
513        lock µÇ¾úÀ¸¸é 0¸¦ ¸®ÅÏÇÑ´Ù.
514
515        Lock ¿©ºÎ¿¡´Â modulation ÀÇ App¼³Á¤°ª°ú device ÀÇ reg ¼³Á¤°ªÀÌ °°ÀºÁö üũÈÄ Lock üũ
516       
517*/
518static DHL_RESULT dhl_LG3305_check_lock(tDHL_TunerID id, UINT32 *pValue)
519{
520
521        DHL_RESULT dhr = DHL_OK;
522        LgdtReturn_t nRet = LGDT_ERR_NO;
523        BOOL lock = 0;
524        LgdtOperMode_t demod_LGDT;
525               
526
527
528        if(g_last_demod_type[id] == eDHL_DEMOD_8VSB)
529                demod_LGDT = LGDT_VSB;
530        else if(g_last_demod_type[id] == eDHL_DEMOD_64QAM)
531                demod_LGDT = LGDT_QAM64;
532        else if(g_last_demod_type[id] == eDHL_DEMOD_256QAM)
533                demod_LGDT = LGDT_QAM256;
534        else
535        {                                               
536                dhr = DHL_FAIL;
537                goto err_exit;                 
538        }
539
540        nRet = LG3305_get_LockStatus(id, demod_LGDT, &lock);   
541        if(nRet != LGDT_ERR_NO)
542        {               
543                dprint(0, " FE_ID : %d, LG3305 Lock Check Error!!! \r\n", id);
544                dhr = DHL_FAIL;
545                goto err_exit;
546        }
547
548
549err_exit:
550
551        *pValue = lock;
552
553        return dhr;
554}
555
556
557/* ser °ª »êÃâ ¹× ¹Ýȯ
558
559        Errcount °ªÀ» ÀÐÀº ÈÄ XX scaling ¼öÇà ÈÄ ¹Ýȯ.
560
561        ¿¡·¯ Ä«¿îÆ® °ª°ú È­¸é »óŸ¦ ºñ±³ÈÄ Àû´çÇÑ Scaling À» ¼öÇàÇÏ¿© Ser °ª ¹Ýȯ..
562        ÇöÀç´Â reg ¿¡¼­ ÀÐÀº ¿¡·¯ Ä«¿îÆ® °ªÀ» ±×´ë·Î ¹Ýȯ..
563
564*/
565static DHL_RESULT dhl_LG3305_check_ser(tDHL_TunerID id, UINT32 *pValue)
566{
567        DHL_RESULT dhr = DHL_OK;
568        LgdtReturn_t nRet = LGDT_ERR_NO;
569        LgdtOperMode_t demod_LGDT;
570        UINT16 ser = 255;
571        int lock;
572
573
574        if(g_last_demod_type[id] == eDHL_DEMOD_8VSB)
575                demod_LGDT = LGDT_VSB;
576        else if(g_last_demod_type[id] == eDHL_DEMOD_64QAM)
577                demod_LGDT = LGDT_QAM64;
578        else if(g_last_demod_type[id] == eDHL_DEMOD_256QAM)
579                demod_LGDT = LGDT_QAM256;
580        else
581        {                                               
582                dhr = DHL_FAIL;
583                goto err_exit;                 
584        }
585
586        nRet = LG3305_get_FECerr(id, demod_LGDT, &ser);
587        if(nRet != LGDT_ERR_NO)
588        {               
589                dprint(0, " FE_ID : %d, LG3305 SER Check Error!!! \r\n", id);
590                dhr = DHL_FAIL;
591                goto err_exit;
592        }       
593       
594#if 0   
595
596        if (!lock) return 255; // maximum err!
597
598        // sigmon ¿¡¼­ threshold¸¦ 50 Á¤µµ·Î Àâ°í ÀÖÀ¸¹Ç·Î 1000->50 scaling ¼öÇà.
599        ser = ser*50/1000;
600        if (ser > 255) ser = 255;
601
602#endif
603       
604
605err_exit:
606
607        *pValue = ser;
608       
609        return dhr;
610}
611
612
613/* ¼Ò¼öÁ¡ 3ÀÚ¸®±îÁö Á¤¼ö·Î ȯ»êÇÑ 1000SNR Á¤¼ö°ª ¹Ýȯ..*/
614static DHL_RESULT dhl_LG3305_check_snr1000(tDHL_TunerID id, UINT32 *pValue)
615{
616
617        DHL_RESULT dhr = DHL_OK;
618        double snrEst = 0;
619        LgdtOperMode_t demod_LGDT;
620        LgdtReturn_t nRet = LGDT_ERR_NO;
621       
622
623        if(g_last_demod_type[id] == eDHL_DEMOD_8VSB)
624                demod_LGDT = LGDT_VSB;
625        else if(g_last_demod_type[id] == eDHL_DEMOD_64QAM)
626                demod_LGDT = LGDT_QAM64;
627        else if(g_last_demod_type[id] == eDHL_DEMOD_256QAM)
628                demod_LGDT = LGDT_QAM256;
629        else
630        {                                               
631                dhr = DHL_FAIL;
632                goto err_exit;                 
633        }
634
635
636        nRet = LG3305_get_Snr(id, demod_LGDT, &snrEst);
637        if(nRet != LGDT_ERR_NO)
638        {               
639                dprint(0, " FE_ID : %d, LG3305 SNR Check Error!!! \r\n", id);
640                dhr = DHL_FAIL;
641                goto err_exit;
642        }       
643
644       
645err_exit:
646//      DHL_OS_Printf("\n\n\n ***** %f ***** \n\n\n",snrEst);
647       
648        *pValue = snrEst * 1000;
649
650        return dhr;
651}
652
653
654
655
656
657
658
659#if COMMENT
660____Test_Code____(){}
661#endif
662
663
664
665
666
Note: See TracBrowser for help on using the repository browser.