aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/common/tuners/mt2063.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2011-07-21 15:40:03 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-01-04 19:21:43 -0500
commit54a4613fdb84786d71ef4b26ab59eed97cad0e7c (patch)
tree9031f297865a12f0d7f3bf13e9652ef395268681 /drivers/media/common/tuners/mt2063.c
parent99ac54125490f16f7434f82fcb73bbb88290b38e (diff)
[media] mt2063: Fix comments
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/common/tuners/mt2063.c')
-rw-r--r--drivers/media/common/tuners/mt2063.c959
1 files changed, 370 insertions, 589 deletions
diff --git a/drivers/media/common/tuners/mt2063.c b/drivers/media/common/tuners/mt2063.c
index 4f634ad24e14..181deac72008 100644
--- a/drivers/media/common/tuners/mt2063.c
+++ b/drivers/media/common/tuners/mt2063.c
@@ -1,3 +1,22 @@
1/*
2 * Driver for mt2063 Micronas tuner
3 *
4 * Copyright (c) 2011 Mauro Carvalho Chehab <mchehab@redhat.com>
5 *
6 * This driver came from a driver originally written by Henry, made available
7 * by Terratec, at:
8 * http://linux.terratec.de/files/TERRATEC_H7/20110323_TERRATEC_H7_Linux.tar.gz
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation under version 2 of the License.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
1#include <linux/init.h> 20#include <linux/init.h>
2#include <linux/kernel.h> 21#include <linux/kernel.h>
3#include <linux/module.h> 22#include <linux/module.h>
@@ -89,8 +108,8 @@ struct MT2063_AvoidSpursData_t {
89}; 108};
90 109
91/* 110/*
92 * Parameter for function MT2063_SetPowerMask that specifies the power down 111 * Parameter for function MT2063_SetPowerMask that specifies the power down
93 * of various sections of the MT2063. 112 * of various sections of the MT2063.
94 */ 113 */
95enum MT2063_Mask_Bits { 114enum MT2063_Mask_Bits {
96 MT2063_REG_SD = 0x0040, /* Shutdown regulator */ 115 MT2063_REG_SD = 0x0040, /* Shutdown regulator */
@@ -134,9 +153,9 @@ enum MT2063_DNC_Output_Enable {
134}; 153};
135 154
136/* 155/*
137** Two-wire serial bus subaddresses of the tuner registers. 156 * Two-wire serial bus subaddresses of the tuner registers.
138** Also known as the tuner's register addresses. 157 * Also known as the tuner's register addresses.
139*/ 158 */
140enum MT2063_Register_Offsets { 159enum MT2063_Register_Offsets {
141 MT2063_REG_PART_REV = 0, /* 0x00: Part/Rev Code */ 160 MT2063_REG_PART_REV = 0, /* 0x00: Part/Rev Code */
142 MT2063_REG_LO1CQ_1, /* 0x01: LO1C Queued Byte 1 */ 161 MT2063_REG_LO1CQ_1, /* 0x01: LO1C Queued Byte 1 */
@@ -320,8 +339,7 @@ static u32 mt2063_read(struct mt2063_state *state,
320static int MT2063_Sleep(struct dvb_frontend *fe) 339static int MT2063_Sleep(struct dvb_frontend *fe)
321{ 340{
322 /* 341 /*
323 ** ToDo: Add code here to implement a OS blocking 342 * ToDo: Add code here to implement a OS blocking
324 ** for a period of "nMinDelayTime" milliseconds.
325 */ 343 */
326 msleep(10); 344 msleep(10);
327 345
@@ -391,23 +409,14 @@ static struct MT2063_ExclZone_t *RemoveNode(struct MT2063_AvoidSpursData_t
391 return pNext; 409 return pNext;
392} 410}
393 411
394/***************************************************************************** 412/*
395** 413 * MT_AddExclZone()
396** Name: MT_AddExclZone 414 *
397** 415 * Add (and merge) an exclusion zone into the list.
398** Description: Add (and merge) an exclusion zone into the list. 416 * If the range (f_min, f_max) is totally outside the
399** If the range (f_min, f_max) is totally outside the 417 * 1st IF BW, ignore the entry.
400** 1st IF BW, ignore the entry. 418 * If the range (f_min, f_max) is negative, ignore the entry.
401** If the range (f_min, f_max) is negative, ignore the entry. 419 */
402**
403** Revision History:
404**
405** SCR Date Author Description
406** -------------------------------------------------------------------------
407** 103 01-31-2005 DAD Ver 1.14: In MT_AddExclZone(), if the range
408** (f_min, f_max) < 0, ignore the entry.
409**
410*****************************************************************************/
411static void MT2063_AddExclZone(struct MT2063_AvoidSpursData_t *pAS_Info, 420static void MT2063_AddExclZone(struct MT2063_AvoidSpursData_t *pAS_Info,
412 u32 f_min, u32 f_max) 421 u32 f_min, u32 f_max)
413{ 422{
@@ -420,11 +429,11 @@ static void MT2063_AddExclZone(struct MT2063_AvoidSpursData_t *pAS_Info,
420 && (f_min < (pAS_Info->f_if1_Center + (pAS_Info->f_if1_bw / 2))) 429 && (f_min < (pAS_Info->f_if1_Center + (pAS_Info->f_if1_bw / 2)))
421 && (f_min < f_max)) { 430 && (f_min < f_max)) {
422 /* 431 /*
423 ** 1 2 3 4 5 6 432 * 1 2 3 4 5 6
424 ** 433 *
425 ** New entry: |---| |--| |--| |-| |---| |--| 434 * New entry: |---| |--| |--| |-| |---| |--|
426 ** or or or or or 435 * or or or or or
427 ** Existing: |--| |--| |--| |---| |-| |--| 436 * Existing: |--| |--| |--| |---| |-| |--|
428 */ 437 */
429 438
430 /* Check for our place in the list */ 439 /* Check for our place in the list */
@@ -450,18 +459,16 @@ static void MT2063_AddExclZone(struct MT2063_AvoidSpursData_t *pAS_Info,
450 while ((pNext != NULL) && (pNext->min_ < pNode->max_)) { 459 while ((pNext != NULL) && (pNext->min_ < pNode->max_)) {
451 if (pNext->max_ > pNode->max_) 460 if (pNext->max_ > pNode->max_)
452 pNode->max_ = pNext->max_; 461 pNode->max_ = pNext->max_;
453 pNext = RemoveNode(pAS_Info, pNode, pNext); /* Remove pNext, return ptr to pNext->next */ 462 /* Remove pNext, return ptr to pNext->next */
463 pNext = RemoveNode(pAS_Info, pNode, pNext);
454 } 464 }
455 } 465 }
456} 466}
457 467
458/* 468/*
459** Reset all exclusion zones. 469 * Reset all exclusion zones.
460** Add zones to protect the PLL FracN regions near zero 470 * Add zones to protect the PLL FracN regions near zero
461** 471 */
462** N/A I 06-17-2008 RSK Ver 1.19: Refactoring avoidance of DECT
463** frequencies into MT_ResetExclZones().
464*/
465static void MT2063_ResetExclZones(struct MT2063_AvoidSpursData_t *pAS_Info) 472static void MT2063_ResetExclZones(struct MT2063_AvoidSpursData_t *pAS_Info)
466{ 473{
467 u32 center; 474 u32 center;
@@ -525,32 +532,21 @@ static void MT2063_ResetExclZones(struct MT2063_AvoidSpursData_t *pAS_Info)
525 } 532 }
526} 533}
527 534
528/***************************************************************************** 535/*
529** 536 * MT_ChooseFirstIF - Choose the best available 1st IF
530** Name: MT_ChooseFirstIF 537 * If f_Desired is not excluded, choose that first.
531** 538 * Otherwise, return the value closest to f_Center that is
532** Description: Choose the best available 1st IF 539 * not excluded
533** If f_Desired is not excluded, choose that first. 540 */
534** Otherwise, return the value closest to f_Center that is
535** not excluded
536**
537** Revision History:
538**
539** SCR Date Author Description
540** -------------------------------------------------------------------------
541** 117 03-29-2007 RSK Ver 1.15: Re-wrote to match search order from
542** tuner DLL.
543** 147 07-27-2007 RSK Ver 1.17: Corrected calculation (-) to (+)
544** Added logic to force f_Center within 1/2 f_Step.
545**
546*****************************************************************************/
547static u32 MT2063_ChooseFirstIF(struct MT2063_AvoidSpursData_t *pAS_Info) 541static u32 MT2063_ChooseFirstIF(struct MT2063_AvoidSpursData_t *pAS_Info)
548{ 542{
549 /* 543 /*
550 ** Update "f_Desired" to be the nearest "combinational-multiple" of "f_LO1_Step". 544 * Update "f_Desired" to be the nearest "combinational-multiple" of
551 ** The resulting number, F_LO1 must be a multiple of f_LO1_Step. And F_LO1 is the arithmetic sum 545 * "f_LO1_Step".
552 ** of f_in + f_Center. Neither f_in, nor f_Center must be a multiple of f_LO1_Step. 546 * The resulting number, F_LO1 must be a multiple of f_LO1_Step.
553 ** However, the sum must be. 547 * And F_LO1 is the arithmetic sum of f_in + f_Center.
548 * Neither f_in, nor f_Center must be a multiple of f_LO1_Step.
549 * However, the sum must be.
554 */ 550 */
555 const u32 f_Desired = 551 const u32 f_Desired =
556 pAS_Info->f_LO1_Step * 552 pAS_Info->f_LO1_Step *
@@ -575,7 +571,10 @@ static u32 MT2063_ChooseFirstIF(struct MT2063_AvoidSpursData_t *pAS_Info)
575 if (pAS_Info->nZones == 0) 571 if (pAS_Info->nZones == 0)
576 return f_Desired; 572 return f_Desired;
577 573
578 /* f_Center needs to be an integer multiple of f_Step away from f_Desired */ 574 /*
575 * f_Center needs to be an integer multiple of f_Step away
576 * from f_Desired
577 */
579 if (pAS_Info->f_if1_Center > f_Desired) 578 if (pAS_Info->f_if1_Center > f_Desired)
580 f_Center = 579 f_Center =
581 f_Desired + 580 f_Desired +
@@ -589,7 +588,10 @@ static u32 MT2063_ChooseFirstIF(struct MT2063_AvoidSpursData_t *pAS_Info)
589 ((f_Desired - pAS_Info->f_if1_Center + 588 ((f_Desired - pAS_Info->f_if1_Center +
590 f_Step / 2) / f_Step); 589 f_Step / 2) / f_Step);
591 590
592 /* Take MT_ExclZones, center around f_Center and change the resolution to f_Step */ 591 /*
592 * Take MT_ExclZones, center around f_Center and change the
593 * resolution to f_Step
594 */
593 while (pNode != NULL) { 595 while (pNode != NULL) {
594 /* floor function */ 596 /* floor function */
595 tmpMin = 597 tmpMin =
@@ -618,13 +620,13 @@ static u32 MT2063_ChooseFirstIF(struct MT2063_AvoidSpursData_t *pAS_Info)
618 } 620 }
619 621
620 /* 622 /*
621 ** If the desired is okay, return with it 623 * If the desired is okay, return with it
622 */ 624 */
623 if (bDesiredExcluded == 0) 625 if (bDesiredExcluded == 0)
624 return f_Desired; 626 return f_Desired;
625 627
626 /* 628 /*
627 ** If the desired is excluded and the center is okay, return with it 629 * If the desired is excluded and the center is okay, return with it
628 */ 630 */
629 if (bZeroExcluded == 0) 631 if (bZeroExcluded == 0)
630 return f_Center; 632 return f_Center;
@@ -644,30 +646,14 @@ static u32 MT2063_ChooseFirstIF(struct MT2063_AvoidSpursData_t *pAS_Info)
644 return f_Center + (bestDiff * f_Step); 646 return f_Center + (bestDiff * f_Step);
645} 647}
646 648
647/**************************************************************************** 649/**
648** 650 * gcd() - Uses Euclid's algorithm
649** Name: gcd 651 *
650** 652 * @u, @v: Unsigned values whose GCD is desired.
651** Description: Uses Euclid's algorithm 653 *
652** 654 * Returns THE greatest common divisor of u and v, if either value is 0,
653** Parameters: u, v - unsigned values whose GCD is desired. 655 * the other value is returned as the result.
654** 656 */
655** Global: None
656**
657** Returns: greatest common divisor of u and v, if either value
658** is 0, the other value is returned as the result.
659**
660** Dependencies: None.
661**
662** Revision History:
663**
664** SCR Date Author Description
665** -------------------------------------------------------------------------
666** N/A 06-01-2004 JWS Original
667** N/A 08-03-2004 DAD Changed to Euclid's since it can handle
668** unsigned numbers.
669**
670****************************************************************************/
671static u32 MT2063_gcd(u32 u, u32 v) 657static u32 MT2063_gcd(u32 u, u32 v)
672{ 658{
673 u32 r; 659 u32 r;
@@ -681,39 +667,25 @@ static u32 MT2063_gcd(u32 u, u32 v)
681 return u; 667 return u;
682} 668}
683 669
684/**************************************************************************** 670/**
685** 671 * IsSpurInBand() - Checks to see if a spur will be present within the IF's
686** Name: IsSpurInBand 672 * bandwidth. (fIFOut +/- fIFBW, -fIFOut +/- fIFBW)
687** 673 *
688** Description: Checks to see if a spur will be present within the IF's 674 * ma mb mc md
689** bandwidth. (fIFOut +/- fIFBW, -fIFOut +/- fIFBW) 675 * <--+-+-+-------------------+-------------------+-+-+-->
690** 676 * | ^ 0 ^ |
691** ma mb mc md 677 * ^ b=-fIFOut+fIFBW/2 -b=+fIFOut-fIFBW/2 ^
692** <--+-+-+-------------------+-------------------+-+-+--> 678 * a=-fIFOut-fIFBW/2 -a=+fIFOut+fIFBW/2
693** | ^ 0 ^ | 679 *
694** ^ b=-fIFOut+fIFBW/2 -b=+fIFOut-fIFBW/2 ^ 680 * Note that some equations are doubled to prevent round-off
695** a=-fIFOut-fIFBW/2 -a=+fIFOut+fIFBW/2 681 * problems when calculating fIFBW/2
696** 682 *
697** Note that some equations are doubled to prevent round-off 683 * @pAS_Info: Avoid Spurs information block
698** problems when calculating fIFBW/2 684 * @fm: If spur, amount f_IF1 has to move negative
699** 685 * @fp: If spur, amount f_IF1 has to move positive
700** Parameters: pAS_Info - Avoid Spurs information block 686 *
701** fm - If spur, amount f_IF1 has to move negative 687 * Returns 1 if an LO spur would be present, otherwise 0.
702** fp - If spur, amount f_IF1 has to move positive 688 */
703**
704** Global: None
705**
706** Returns: 1 if an LO spur would be present, otherwise 0.
707**
708** Dependencies: None.
709**
710** Revision History:
711**
712** SCR Date Author Description
713** -------------------------------------------------------------------------
714** N/A 11-28-2002 DAD Implemented algorithm from applied patent
715**
716****************************************************************************/
717static u32 IsSpurInBand(struct MT2063_AvoidSpursData_t *pAS_Info, 689static u32 IsSpurInBand(struct MT2063_AvoidSpursData_t *pAS_Info,
718 u32 *fm, u32 * fp) 690 u32 *fm, u32 * fp)
719{ 691{
@@ -814,22 +786,12 @@ static u32 IsSpurInBand(struct MT2063_AvoidSpursData_t *pAS_Info,
814 return 0; 786 return 0;
815} 787}
816 788
817/***************************************************************************** 789/*
818** 790 * MT_AvoidSpurs() - Main entry point to avoid spurs.
819** Name: MT_AvoidSpurs 791 * Checks for existing spurs in present LO1, LO2 freqs
820** 792 * and if present, chooses spur-free LO1, LO2 combination
821** Description: Main entry point to avoid spurs. 793 * that tunes the same input/output frequencies.
822** Checks for existing spurs in present LO1, LO2 freqs 794 */
823** and if present, chooses spur-free LO1, LO2 combination
824** that tunes the same input/output frequencies.
825**
826** Revision History:
827**
828** SCR Date Author Description
829** -------------------------------------------------------------------------
830** 096 04-06-2005 DAD Ver 1.11: Fix divide by 0 error if maxH==0.
831**
832*****************************************************************************/
833static u32 MT2063_AvoidSpurs(struct MT2063_AvoidSpursData_t *pAS_Info) 795static u32 MT2063_AvoidSpurs(struct MT2063_AvoidSpursData_t *pAS_Info)
834{ 796{
835 u32 status = 0; 797 u32 status = 0;
@@ -841,15 +803,15 @@ static u32 MT2063_AvoidSpurs(struct MT2063_AvoidSpursData_t *pAS_Info)
841 return 0; 803 return 0;
842 804
843 /* 805 /*
844 ** Avoid LO Generated Spurs 806 * Avoid LO Generated Spurs
845 ** 807 *
846 ** Make sure that have no LO-related spurs within the IF output 808 * Make sure that have no LO-related spurs within the IF output
847 ** bandwidth. 809 * bandwidth.
848 ** 810 *
849 ** If there is an LO spur in this band, start at the current IF1 frequency 811 * If there is an LO spur in this band, start at the current IF1 frequency
850 ** and work out until we find a spur-free frequency or run up against the 812 * and work out until we find a spur-free frequency or run up against the
851 ** 1st IF SAW band edge. Use temporary copies of fLO1 and fLO2 so that they 813 * 1st IF SAW band edge. Use temporary copies of fLO1 and fLO2 so that they
852 ** will be unchanged if a spur-free setting is not found. 814 * will be unchanged if a spur-free setting is not found.
853 */ 815 */
854 pAS_Info->bSpurPresent = IsSpurInBand(pAS_Info, &fm, &fp); 816 pAS_Info->bSpurPresent = IsSpurInBand(pAS_Info, &fm, &fp);
855 if (pAS_Info->bSpurPresent) { 817 if (pAS_Info->bSpurPresent) {
@@ -887,15 +849,15 @@ static u32 MT2063_AvoidSpurs(struct MT2063_AvoidSpursData_t *pAS_Info)
887 849
888 pAS_Info->bSpurPresent = IsSpurInBand(pAS_Info, &fm, &fp); 850 pAS_Info->bSpurPresent = IsSpurInBand(pAS_Info, &fm, &fp);
889 /* 851 /*
890 ** Continue while the new 1st IF is still within the 1st IF bandwidth 852 * Continue while the new 1st IF is still within the 1st IF bandwidth
891 ** and there is a spur in the band (again) 853 * and there is a spur in the band (again)
892 */ 854 */
893 } while ((2 * delta_IF1 + pAS_Info->f_out_bw <= pAS_Info->f_if1_bw) && pAS_Info->bSpurPresent); 855 } while ((2 * delta_IF1 + pAS_Info->f_out_bw <= pAS_Info->f_if1_bw) && pAS_Info->bSpurPresent);
894 856
895 /* 857 /*
896 ** Use the LO-spur free values found. If the search went all the way to 858 * Use the LO-spur free values found. If the search went all
897 ** the 1st IF band edge and always found spurs, just leave the original 859 * the way to the 1st IF band edge and always found spurs, just
898 ** choice. It's as "good" as any other. 860 * leave the original choice. It's as "good" as any other.
899 */ 861 */
900 if (pAS_Info->bSpurPresent == 1) { 862 if (pAS_Info->bSpurPresent == 1) {
901 status |= MT2063_SPUR_PRESENT_ERR; 863 status |= MT2063_SPUR_PRESENT_ERR;
@@ -912,7 +874,6 @@ static u32 MT2063_AvoidSpurs(struct MT2063_AvoidSpursData_t *pAS_Info)
912 return status; 874 return status;
913} 875}
914 876
915
916/* 877/*
917 * Constants used by the tuning algorithm 878 * Constants used by the tuning algorithm
918 */ 879 */
@@ -936,35 +897,29 @@ static u32 MT2063_AvoidSpurs(struct MT2063_AvoidSpursData_t *pAS_Info)
936#define MT2063_MAX_UPC_FREQ (2750000000UL) /* Maximum LO1 frequency (in Hz) */ 897#define MT2063_MAX_UPC_FREQ (2750000000UL) /* Maximum LO1 frequency (in Hz) */
937 898
938/* 899/*
939** Define the supported Part/Rev codes for the MT2063 900 * Define the supported Part/Rev codes for the MT2063
940*/ 901 */
941#define MT2063_B0 (0x9B) 902#define MT2063_B0 (0x9B)
942#define MT2063_B1 (0x9C) 903#define MT2063_B1 (0x9C)
943#define MT2063_B2 (0x9D) 904#define MT2063_B2 (0x9D)
944#define MT2063_B3 (0x9E) 905#define MT2063_B3 (0x9E)
945 906
946/* 907/*
947** Constants for setting receiver modes. 908 * Constants for setting receiver modes.
948** (6 modes defined at this time, enumerated by MT2063_RCVR_MODES) 909 * (6 modes defined at this time, enumerated by MT2063_RCVR_MODES)
949** (DNC1GC & DNC2GC are the values, which are used, when the specific 910 * (DNC1GC & DNC2GC are the values, which are used, when the specific
950** DNC Output is selected, the other is always off) 911 * DNC Output is selected, the other is always off)
951** 912 *
952** If PAL-L or L' is received, set: 913 * enum MT2063_RCVR_MODES
953** MT2063_SetParam(hMT2063,MT2063_TAGC,1); 914 * -------------+----------------------------------------------
954** 915 * Mode 0 : | MT2063_CABLE_QAM
955** --------------+---------------------------------------------- 916 * Mode 1 : | MT2063_CABLE_ANALOG
956** Mode 0 : | MT2063_CABLE_QAM 917 * Mode 2 : | MT2063_OFFAIR_COFDM
957** Mode 1 : | MT2063_CABLE_ANALOG 918 * Mode 3 : | MT2063_OFFAIR_COFDM_SAWLESS
958** Mode 2 : | MT2063_OFFAIR_COFDM 919 * Mode 4 : | MT2063_OFFAIR_ANALOG
959** Mode 3 : | MT2063_OFFAIR_COFDM_SAWLESS 920 * Mode 5 : | MT2063_OFFAIR_8VSB
960** Mode 4 : | MT2063_OFFAIR_ANALOG 921 * --------------+----------------------------------------------
961** Mode 5 : | MT2063_OFFAIR_8VSB 922 */
962** --------------+----+----+----+----+-----+-----+--------------
963** Mode | 0 | 1 | 2 | 3 | 4 | 5 |
964** --------------+----+----+----+----+-----+-----+
965**
966**
967*/
968static const u8 RFAGCEN[] = { 0, 0, 0, 0, 0, 0 }; 923static const u8 RFAGCEN[] = { 0, 0, 0, 0, 0, 0 };
969static const u8 LNARIN[] = { 0, 0, 3, 3, 3, 3 }; 924static const u8 LNARIN[] = { 0, 0, 3, 3, 3, 3 };
970static const u8 FIFFQEN[] = { 1, 1, 1, 1, 1, 1 }; 925static const u8 FIFFQEN[] = { 1, 1, 1, 1, 1, 1 };
@@ -1053,117 +1008,109 @@ static u32 mt2063_set_dnc_output_enable(struct mt2063_state *state,
1053 /* selects, which DNC output is used */ 1008 /* selects, which DNC output is used */
1054 switch (nValue) { 1009 switch (nValue) {
1055 case MT2063_DNC_NONE: 1010 case MT2063_DNC_NONE:
1056 { 1011 val = (state->reg[MT2063_REG_DNC_GAIN] & 0xFC) | 0x03; /* Set DNC1GC=3 */
1057 val = (state->reg[MT2063_REG_DNC_GAIN] & 0xFC) | 0x03; /* Set DNC1GC=3 */ 1012 if (state->reg[MT2063_REG_DNC_GAIN] !=
1058 if (state->reg[MT2063_REG_DNC_GAIN] != 1013 val)
1059 val) 1014 status |=
1060 status |= 1015 mt2063_setreg(state,
1061 mt2063_setreg(state, 1016 MT2063_REG_DNC_GAIN,
1062 MT2063_REG_DNC_GAIN, 1017 val);
1063 val);
1064 1018
1065 val = (state->reg[MT2063_REG_VGA_GAIN] & 0xFC) | 0x03; /* Set DNC2GC=3 */ 1019 val = (state->reg[MT2063_REG_VGA_GAIN] & 0xFC) | 0x03; /* Set DNC2GC=3 */
1066 if (state->reg[MT2063_REG_VGA_GAIN] != 1020 if (state->reg[MT2063_REG_VGA_GAIN] !=
1067 val) 1021 val)
1068 status |= 1022 status |=
1069 mt2063_setreg(state, 1023 mt2063_setreg(state,
1070 MT2063_REG_VGA_GAIN, 1024 MT2063_REG_VGA_GAIN,
1071 val); 1025 val);
1072 1026
1073 val = (state->reg[MT2063_REG_RSVD_20] & ~0x40); /* Set PD2MUX=0 */ 1027 val = (state->reg[MT2063_REG_RSVD_20] & ~0x40); /* Set PD2MUX=0 */
1074 if (state->reg[MT2063_REG_RSVD_20] != 1028 if (state->reg[MT2063_REG_RSVD_20] !=
1075 val) 1029 val)
1076 status |= 1030 status |=
1077 mt2063_setreg(state, 1031 mt2063_setreg(state,
1078 MT2063_REG_RSVD_20, 1032 MT2063_REG_RSVD_20,
1079 val); 1033 val);
1080 1034
1081 break; 1035 break;
1082 }
1083 case MT2063_DNC_1: 1036 case MT2063_DNC_1:
1084 { 1037 val = (state->reg[MT2063_REG_DNC_GAIN] & 0xFC) | (DNC1GC[state->rcvr_mode] & 0x03); /* Set DNC1GC=x */
1085 val = (state->reg[MT2063_REG_DNC_GAIN] & 0xFC) | (DNC1GC[state->rcvr_mode] & 0x03); /* Set DNC1GC=x */ 1038 if (state->reg[MT2063_REG_DNC_GAIN] !=
1086 if (state->reg[MT2063_REG_DNC_GAIN] != 1039 val)
1087 val) 1040 status |=
1088 status |= 1041 mt2063_setreg(state,
1089 mt2063_setreg(state, 1042 MT2063_REG_DNC_GAIN,
1090 MT2063_REG_DNC_GAIN, 1043 val);
1091 val);
1092 1044
1093 val = (state->reg[MT2063_REG_VGA_GAIN] & 0xFC) | 0x03; /* Set DNC2GC=3 */ 1045 val = (state->reg[MT2063_REG_VGA_GAIN] & 0xFC) | 0x03; /* Set DNC2GC=3 */
1094 if (state->reg[MT2063_REG_VGA_GAIN] != 1046 if (state->reg[MT2063_REG_VGA_GAIN] !=
1095 val) 1047 val)
1096 status |= 1048 status |=
1097 mt2063_setreg(state, 1049 mt2063_setreg(state,
1098 MT2063_REG_VGA_GAIN, 1050 MT2063_REG_VGA_GAIN,
1099 val); 1051 val);
1100 1052
1101 val = (state->reg[MT2063_REG_RSVD_20] & ~0x40); /* Set PD2MUX=0 */ 1053 val = (state->reg[MT2063_REG_RSVD_20] & ~0x40); /* Set PD2MUX=0 */
1102 if (state->reg[MT2063_REG_RSVD_20] != 1054 if (state->reg[MT2063_REG_RSVD_20] !=
1103 val) 1055 val)
1104 status |= 1056 status |=
1105 mt2063_setreg(state, 1057 mt2063_setreg(state,
1106 MT2063_REG_RSVD_20, 1058 MT2063_REG_RSVD_20,
1107 val); 1059 val);
1108 1060
1109 break; 1061 break;
1110 }
1111 case MT2063_DNC_2: 1062 case MT2063_DNC_2:
1112 { 1063 val = (state->reg[MT2063_REG_DNC_GAIN] & 0xFC) | 0x03; /* Set DNC1GC=3 */
1113 val = (state->reg[MT2063_REG_DNC_GAIN] & 0xFC) | 0x03; /* Set DNC1GC=3 */ 1064 if (state->reg[MT2063_REG_DNC_GAIN] !=
1114 if (state->reg[MT2063_REG_DNC_GAIN] != 1065 val)
1115 val) 1066 status |=
1116 status |= 1067 mt2063_setreg(state,
1117 mt2063_setreg(state, 1068 MT2063_REG_DNC_GAIN,
1118 MT2063_REG_DNC_GAIN, 1069 val);
1119 val);
1120 1070
1121 val = (state->reg[MT2063_REG_VGA_GAIN] & 0xFC) | (DNC2GC[state->rcvr_mode] & 0x03); /* Set DNC2GC=x */ 1071 val = (state->reg[MT2063_REG_VGA_GAIN] & 0xFC) | (DNC2GC[state->rcvr_mode] & 0x03); /* Set DNC2GC=x */
1122 if (state->reg[MT2063_REG_VGA_GAIN] != 1072 if (state->reg[MT2063_REG_VGA_GAIN] !=
1123 val) 1073 val)
1124 status |= 1074 status |=
1125 mt2063_setreg(state, 1075 mt2063_setreg(state,
1126 MT2063_REG_VGA_GAIN, 1076 MT2063_REG_VGA_GAIN,
1127 val); 1077 val);
1128 1078
1129 val = (state->reg[MT2063_REG_RSVD_20] | 0x40); /* Set PD2MUX=1 */ 1079 val = (state->reg[MT2063_REG_RSVD_20] | 0x40); /* Set PD2MUX=1 */
1130 if (state->reg[MT2063_REG_RSVD_20] != 1080 if (state->reg[MT2063_REG_RSVD_20] !=
1131 val) 1081 val)
1132 status |= 1082 status |=
1133 mt2063_setreg(state, 1083 mt2063_setreg(state,
1134 MT2063_REG_RSVD_20, 1084 MT2063_REG_RSVD_20,
1135 val); 1085 val);
1136 1086
1137 break; 1087 break;
1138 }
1139 case MT2063_DNC_BOTH: 1088 case MT2063_DNC_BOTH:
1140 { 1089 val = (state->reg[MT2063_REG_DNC_GAIN] & 0xFC) | (DNC1GC[state->rcvr_mode] & 0x03); /* Set DNC1GC=x */
1141 val = (state->reg[MT2063_REG_DNC_GAIN] & 0xFC) | (DNC1GC[state->rcvr_mode] & 0x03); /* Set DNC1GC=x */ 1090 if (state->reg[MT2063_REG_DNC_GAIN] !=
1142 if (state->reg[MT2063_REG_DNC_GAIN] != 1091 val)
1143 val) 1092 status |=
1144 status |= 1093 mt2063_setreg(state,
1145 mt2063_setreg(state, 1094 MT2063_REG_DNC_GAIN,
1146 MT2063_REG_DNC_GAIN, 1095 val);
1147 val);
1148 1096
1149 val = (state->reg[MT2063_REG_VGA_GAIN] & 0xFC) | (DNC2GC[state->rcvr_mode] & 0x03); /* Set DNC2GC=x */ 1097 val = (state->reg[MT2063_REG_VGA_GAIN] & 0xFC) | (DNC2GC[state->rcvr_mode] & 0x03); /* Set DNC2GC=x */
1150 if (state->reg[MT2063_REG_VGA_GAIN] != 1098 if (state->reg[MT2063_REG_VGA_GAIN] !=
1151 val) 1099 val)
1152 status |= 1100 status |=
1153 mt2063_setreg(state, 1101 mt2063_setreg(state,
1154 MT2063_REG_VGA_GAIN, 1102 MT2063_REG_VGA_GAIN,
1155 val); 1103 val);
1156 1104
1157 val = (state->reg[MT2063_REG_RSVD_20] | 0x40); /* Set PD2MUX=1 */ 1105 val = (state->reg[MT2063_REG_RSVD_20] | 0x40); /* Set PD2MUX=1 */
1158 if (state->reg[MT2063_REG_RSVD_20] != 1106 if (state->reg[MT2063_REG_RSVD_20] !=
1159 val) 1107 val)
1160 status |= 1108 status |=
1161 mt2063_setreg(state, 1109 mt2063_setreg(state,
1162 MT2063_REG_RSVD_20, 1110 MT2063_REG_RSVD_20,
1163 val); 1111 val);
1164 1112
1165 break; 1113 break;
1166 }
1167 default: 1114 default:
1168 break; 1115 break;
1169 } 1116 }
@@ -1171,89 +1118,47 @@ static u32 mt2063_set_dnc_output_enable(struct mt2063_state *state,
1171 return status; 1118 return status;
1172} 1119}
1173 1120
1174/****************************************************************************** 1121/*
1175** 1122 * MT2063_SetReceiverMode() - Set the MT2063 receiver mode
1176** Name: MT2063_SetReceiverMode 1123**
1177** 1124 * enum MT2063_RCVR_MODES
1178** Description: Set the MT2063 receiver mode 1125 * --------------+----------------------------------------------
1179** 1126 * Mode 0 : | MT2063_CABLE_QAM
1180** --------------+---------------------------------------------- 1127 * Mode 1 : | MT2063_CABLE_ANALOG
1181** Mode 0 : | MT2063_CABLE_QAM 1128 * Mode 2 : | MT2063_OFFAIR_COFDM
1182** Mode 1 : | MT2063_CABLE_ANALOG 1129 * Mode 3 : | MT2063_OFFAIR_COFDM_SAWLESS
1183** Mode 2 : | MT2063_OFFAIR_COFDM 1130 * Mode 4 : | MT2063_OFFAIR_ANALOG
1184** Mode 3 : | MT2063_OFFAIR_COFDM_SAWLESS 1131 * Mode 5 : | MT2063_OFFAIR_8VSB
1185** Mode 4 : | MT2063_OFFAIR_ANALOG 1132 * --------------+----------------------------------------------
1186** Mode 5 : | MT2063_OFFAIR_8VSB 1133 * (DNC1GC & DNC2GC are the values, which are used, when the specific
1187** --------------+----+----+----+----+-----+-------------------- 1134 * DNC Output is selected, the other is always off)
1188** (DNC1GC & DNC2GC are the values, which are used, when the specific 1135 *
1189** DNC Output is selected, the other is always off) 1136 * |<---------- Mode -------------->|
1190** 1137 * Reg Field | 0 | 1 | 2 | 3 | 4 | 5 |
1191** |<---------- Mode -------------->| 1138 * ------------+-----+-----+-----+-----+-----+-----+
1192** Reg Field | 0 | 1 | 2 | 3 | 4 | 5 | 1139 * RFAGCen | OFF | OFF | OFF | OFF | OFF | OFF
1193** ------------+-----+-----+-----+-----+-----+-----+ 1140 * LNARin | 0 | 0 | 3 | 3 | 3 | 3
1194** RFAGCen | OFF | OFF | OFF | OFF | OFF | OFF 1141 * FIFFQen | 1 | 1 | 1 | 1 | 1 | 1
1195** LNARin | 0 | 0 | 3 | 3 | 3 | 3 1142 * FIFFq | 0 | 0 | 0 | 0 | 0 | 0
1196** FIFFQen | 1 | 1 | 1 | 1 | 1 | 1 1143 * DNC1gc | 0 | 0 | 0 | 0 | 0 | 0
1197** FIFFq | 0 | 0 | 0 | 0 | 0 | 0 1144 * DNC2gc | 0 | 0 | 0 | 0 | 0 | 0
1198** DNC1gc | 0 | 0 | 0 | 0 | 0 | 0 1145 * GCU Auto | 1 | 1 | 1 | 1 | 1 | 1
1199** DNC2gc | 0 | 0 | 0 | 0 | 0 | 0 1146 * LNA max Atn | 31 | 31 | 31 | 31 | 31 | 31
1200** GCU Auto | 1 | 1 | 1 | 1 | 1 | 1 1147 * LNA Target | 44 | 43 | 43 | 43 | 43 | 43
1201** LNA max Atn | 31 | 31 | 31 | 31 | 31 | 31 1148 * ign RF Ovl | 0 | 0 | 0 | 0 | 0 | 0
1202** LNA Target | 44 | 43 | 43 | 43 | 43 | 43 1149 * RF max Atn | 31 | 31 | 31 | 31 | 31 | 31
1203** ign RF Ovl | 0 | 0 | 0 | 0 | 0 | 0 1150 * PD1 Target | 36 | 36 | 38 | 38 | 36 | 38
1204** RF max Atn | 31 | 31 | 31 | 31 | 31 | 31 1151 * ign FIF Ovl | 0 | 0 | 0 | 0 | 0 | 0
1205** PD1 Target | 36 | 36 | 38 | 38 | 36 | 38 1152 * FIF max Atn | 5 | 5 | 5 | 5 | 5 | 5
1206** ign FIF Ovl | 0 | 0 | 0 | 0 | 0 | 0 1153 * PD2 Target | 40 | 33 | 42 | 42 | 33 | 42
1207** FIF max Atn | 5 | 5 | 5 | 5 | 5 | 5 1154 *
1208** PD2 Target | 40 | 33 | 42 | 42 | 33 | 42 1155 *
1209** 1156 * @state: ptr to mt2063_state structure
1210** 1157 * @Mode: desired reciever mode
1211** Parameters: state - ptr to mt2063_state structure 1158 *
1212** Mode - desired reciever mode 1159 * Note: Register cache must be valid for it to work
1213** 1160 */
1214** Usage: status = MT2063_SetReceiverMode(hMT2063, Mode); 1161
1215**
1216** Returns: status:
1217** MT_OK - No errors
1218** MT_COMM_ERR - Serial bus communications error
1219**
1220** Dependencies: mt2063_setreg - Write a byte of data to a HW register.
1221** Assumes that the tuner cache is valid.
1222**
1223** Revision History:
1224**
1225** SCR Date Author Description
1226** -------------------------------------------------------------------------
1227** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
1228** N/A 01-10-2007 PINZ Added additional GCU Settings, FIFF Calib will be triggered
1229** 155 10-01-2007 DAD Ver 1.06: Add receiver mode for SECAM positive
1230** modulation
1231** (MT2063_ANALOG_TV_POS_NO_RFAGC_MODE)
1232** N/A 10-22-2007 PINZ Ver 1.07: Changed some Registers at init to have
1233** the same settings as with MT Launcher
1234** N/A 10-30-2007 PINZ Add SetParam VGAGC & VGAOI
1235** Add SetParam DNC_OUTPUT_ENABLE
1236** Removed VGAGC from receiver mode,
1237** default now 1
1238** N/A 10-31-2007 PINZ Ver 1.08: Add SetParam TAGC, removed from rcvr-mode
1239** Add SetParam AMPGC, removed from rcvr-mode
1240** Corrected names of GCU values
1241** reorganized receiver modes, removed,
1242** (MT2063_ANALOG_TV_POS_NO_RFAGC_MODE)
1243** Actualized Receiver-Mode values
1244** N/A 11-12-2007 PINZ Ver 1.09: Actualized Receiver-Mode values
1245** N/A 11-27-2007 PINZ Improved buffered writing
1246** 01-03-2008 PINZ Ver 1.10: Added a trigger of BYPATNUP for
1247** correct wakeup of the LNA after shutdown
1248** Set AFCsd = 1 as default
1249** Changed CAP1sel default
1250** 01-14-2008 PINZ Ver 1.11: Updated gain settings
1251** 04-18-2008 PINZ Ver 1.15: Add SetParam LNARIN & PDxTGT
1252** Split SetParam up to ACLNA / ACLNA_MAX
1253** removed ACLNA_INRC/DECR (+RF & FIF)
1254** removed GCUAUTO / BYPATNDN/UP
1255**
1256******************************************************************************/
1257static u32 MT2063_SetReceiverMode(struct mt2063_state *state, 1162static u32 MT2063_SetReceiverMode(struct mt2063_state *state,
1258 enum MT2063_RCVR_MODES Mode) 1163 enum MT2063_RCVR_MODES Mode)
1259{ 1164{
@@ -1382,37 +1287,19 @@ static u32 MT2063_SetReceiverMode(struct mt2063_state *state,
1382 return status; 1287 return status;
1383} 1288}
1384 1289
1385/**************************************************************************** 1290/*
1386** 1291 * MT2063_ClearPowerMaskBits () - Clears the power-down mask bits for various
1387** Name: MT2063_ClearPowerMaskBits 1292 * sections of the MT2063
1388** 1293 *
1389** Description: Clears the power-down mask bits for various sections of 1294 * @Bits: Mask bits to be cleared.
1390** the MT2063 1295 *
1391** 1296 * See definition of MT2063_Mask_Bits type for description
1392** Parameters: h - Tuner handle (returned by MT2063_Open) 1297 * of each of the power bits.
1393** Bits - Mask bits to be cleared. 1298 */
1394**
1395** See definition of MT2063_Mask_Bits type for description
1396** of each of the power bits.
1397**
1398** Returns: status:
1399** MT_OK - No errors
1400** MT_INV_HANDLE - Invalid tuner handle
1401** MT_COMM_ERR - Serial bus communications error
1402**
1403** Dependencies: USERS MUST CALL MT2063_Open() FIRST!
1404**
1405** Revision History:
1406**
1407** SCR Date Author Description
1408** -------------------------------------------------------------------------
1409** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
1410**
1411****************************************************************************/
1412static u32 MT2063_ClearPowerMaskBits(struct mt2063_state *state, 1299static u32 MT2063_ClearPowerMaskBits(struct mt2063_state *state,
1413 enum MT2063_Mask_Bits Bits) 1300 enum MT2063_Mask_Bits Bits)
1414{ 1301{
1415 u32 status = 0; /* Status to be returned */ 1302 u32 status = 0;
1416 1303
1417 Bits = (enum MT2063_Mask_Bits)(Bits & MT2063_ALL_SD); /* Only valid bits for this tuner */ 1304 Bits = (enum MT2063_Mask_Bits)(Bits & MT2063_ALL_SD); /* Only valid bits for this tuner */
1418 if ((Bits & 0xFF00) != 0) { 1305 if ((Bits & 0xFF00) != 0) {
@@ -1433,42 +1320,19 @@ static u32 MT2063_ClearPowerMaskBits(struct mt2063_state *state,
1433 return status; 1320 return status;
1434} 1321}
1435 1322
1436/**************************************************************************** 1323/*
1437** 1324 * MT2063_SoftwareShutdown() - Enables or disables software shutdown function.
1438** Name: MT2063_SoftwareShutdown 1325 * When Shutdown is 1, any section whose power
1439** 1326 * mask is set will be shutdown.
1440** Description: Enables or disables software shutdown function. When 1327 */
1441** Shutdown==1, any section whose power mask is set will be
1442** shutdown.
1443**
1444** Parameters: h - Tuner handle (returned by MT2063_Open)
1445** Shutdown - 1 = shutdown the masked sections, otherwise
1446** power all sections on
1447**
1448** Returns: status:
1449** MT_OK - No errors
1450** MT_INV_HANDLE - Invalid tuner handle
1451** MT_COMM_ERR - Serial bus communications error
1452**
1453** Dependencies: USERS MUST CALL MT2063_Open() FIRST!
1454**
1455** Revision History:
1456**
1457** SCR Date Author Description
1458** -------------------------------------------------------------------------
1459** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
1460** 01-03-2008 PINZ Ver 1.xx: Added a trigger of BYPATNUP for
1461** correct wakeup of the LNA
1462**
1463****************************************************************************/
1464static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown) 1328static u32 MT2063_SoftwareShutdown(struct mt2063_state *state, u8 Shutdown)
1465{ 1329{
1466 u32 status; /* Status to be returned */ 1330 u32 status;
1467 1331
1468 if (Shutdown == 1) 1332 if (Shutdown == 1)
1469 state->reg[MT2063_REG_PWR_1] |= 0x04; /* Turn the bit on */ 1333 state->reg[MT2063_REG_PWR_1] |= 0x04;
1470 else 1334 else
1471 state->reg[MT2063_REG_PWR_1] &= ~0x04; /* Turn off the bit */ 1335 state->reg[MT2063_REG_PWR_1] &= ~0x04;
1472 1336
1473 status = mt2063_write(state, 1337 status = mt2063_write(state,
1474 MT2063_REG_PWR_1, 1338 MT2063_REG_PWR_1,
@@ -1500,36 +1364,24 @@ static u32 MT2063_Round_fLO(u32 f_LO, u32 f_LO_Step, u32 f_ref)
1500 + f_LO_Step * (((f_LO % f_ref) + (f_LO_Step / 2)) / f_LO_Step); 1364 + f_LO_Step * (((f_LO % f_ref) + (f_LO_Step / 2)) / f_LO_Step);
1501} 1365}
1502 1366
1503/**************************************************************************** 1367/**
1504** 1368 * fLO_FractionalTerm() - Calculates the portion contributed by FracN / denom.
1505** Name: fLO_FractionalTerm 1369 * This function preserves maximum precision without
1506** 1370 * risk of overflow. It accurately calculates
1507** Description: Calculates the portion contributed by FracN / denom. 1371 * f_ref * num / denom to within 1 HZ with fixed math.
1508** 1372 *
1509** This function preserves maximum precision without 1373 * @num : Fractional portion of the multiplier
1510** risk of overflow. It accurately calculates 1374 * @denom: denominator portion of the ratio
1511** f_ref * num / denom to within 1 HZ with fixed math. 1375 * @f_Ref: SRO frequency.
1512** 1376 *
1513** Parameters: num - Fractional portion of the multiplier 1377 * This calculation handles f_ref as two separate 14-bit fields.
1514** denom - denominator portion of the ratio 1378 * Therefore, a maximum value of 2^28-1 may safely be used for f_ref.
1515** This routine successfully handles denom values 1379 * This is the genesis of the magic number "14" and the magic mask value of
1516** up to and including 2^18. 1380 * 0x03FFF.
1517** f_Ref - SRO frequency. This calculation handles 1381 *
1518** f_ref as two separate 14-bit fields. 1382 * This routine successfully handles denom values up to and including 2^18.
1519** Therefore, a maximum value of 2^28-1 1383 * Returns: f_ref * num / denom
1520** may safely be used for f_ref. This is 1384 */
1521** the genesis of the magic number "14" and the
1522** magic mask value of 0x03FFF.
1523**
1524** Returns: f_ref * num / denom
1525**
1526** Revision History:
1527**
1528** SCR Date Author Description
1529** -------------------------------------------------------------------------
1530** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
1531**
1532****************************************************************************/
1533static u32 MT2063_fLO_FractionalTerm(u32 f_ref, u32 num, u32 denom) 1385static u32 MT2063_fLO_FractionalTerm(u32 f_ref, u32 num, u32 denom)
1534{ 1386{
1535 u32 t1 = (f_ref >> 14) * num; 1387 u32 t1 = (f_ref >> 14) * num;
@@ -1540,33 +1392,23 @@ static u32 MT2063_fLO_FractionalTerm(u32 f_ref, u32 num, u32 denom)
1540 return (term1 << 14) + term2; 1392 return (term1 << 14) + term2;
1541} 1393}
1542 1394
1543/**************************************************************************** 1395/*
1544** 1396 * CalcLO1Mult()- Calculates Integer divider value and the numerator
1545** Name: CalcLO1Mult 1397 * value for a FracN PLL.
1546** 1398 *
1547** Description: Calculates Integer divider value and the numerator 1399 * This function assumes that the f_LO and f_Ref are
1548** value for a FracN PLL. 1400 * evenly divisible by f_LO_Step.
1549** 1401 *
1550** This function assumes that the f_LO and f_Ref are 1402 * @Div: OUTPUT: Whole number portion of the multiplier
1551** evenly divisible by f_LO_Step. 1403 * @FracN: OUTPUT: Fractional portion of the multiplier
1552** 1404 * @f_LO: desired LO frequency.
1553** Parameters: Div - OUTPUT: Whole number portion of the multiplier 1405 * @f_LO_Step: Minimum step size for the LO (in Hz).
1554** FracN - OUTPUT: Fractional portion of the multiplier 1406 * @f_Ref: SRO frequency.
1555** f_LO - desired LO frequency. 1407 * @f_Avoid: Range of PLL frequencies to avoid near integer multiples
1556** f_LO_Step - Minimum step size for the LO (in Hz). 1408 * of f_Ref (in Hz).
1557** f_Ref - SRO frequency. 1409 *
1558** f_Avoid - Range of PLL frequencies to avoid near 1410 * Returns: Recalculated LO frequency.
1559** integer multiples of f_Ref (in Hz). 1411 */
1560**
1561** Returns: Recalculated LO frequency.
1562**
1563** Revision History:
1564**
1565** SCR Date Author Description
1566** -------------------------------------------------------------------------
1567** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
1568**
1569****************************************************************************/
1570static u32 MT2063_CalcLO1Mult(u32 *Div, 1412static u32 MT2063_CalcLO1Mult(u32 *Div,
1571 u32 *FracN, 1413 u32 *FracN,
1572 u32 f_LO, 1414 u32 f_LO,
@@ -1583,33 +1425,23 @@ static u32 MT2063_CalcLO1Mult(u32 *Div,
1583 return (f_Ref * (*Div)) + MT2063_fLO_FractionalTerm(f_Ref, *FracN, 64); 1425 return (f_Ref * (*Div)) + MT2063_fLO_FractionalTerm(f_Ref, *FracN, 64);
1584} 1426}
1585 1427
1586/**************************************************************************** 1428/**
1587** 1429 * CalcLO2Mult() - Calculates Integer divider value and the numerator
1588** Name: CalcLO2Mult 1430 * value for a FracN PLL.
1589** 1431 *
1590** Description: Calculates Integer divider value and the numerator 1432 * This function assumes that the f_LO and f_Ref are
1591** value for a FracN PLL. 1433 * evenly divisible by f_LO_Step.
1592** 1434 *
1593** This function assumes that the f_LO and f_Ref are 1435 * @Div: OUTPUT: Whole number portion of the multiplier
1594** evenly divisible by f_LO_Step. 1436 * @FracN: OUTPUT: Fractional portion of the multiplier
1595** 1437 * @f_LO: desired LO frequency.
1596** Parameters: Div - OUTPUT: Whole number portion of the multiplier 1438 * @f_LO_Step: Minimum step size for the LO (in Hz).
1597** FracN - OUTPUT: Fractional portion of the multiplier 1439 * @f_Ref: SRO frequency.
1598** f_LO - desired LO frequency. 1440 * @f_Avoid: Range of PLL frequencies to avoid near
1599** f_LO_Step - Minimum step size for the LO (in Hz). 1441 * integer multiples of f_Ref (in Hz).
1600** f_Ref - SRO frequency. 1442 *
1601** f_Avoid - Range of PLL frequencies to avoid near 1443 * Returns: Recalculated LO frequency.
1602** integer multiples of f_Ref (in Hz). 1444 */
1603**
1604** Returns: Recalculated LO frequency.
1605**
1606** Revision History:
1607**
1608** SCR Date Author Description
1609** -------------------------------------------------------------------------
1610** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
1611**
1612****************************************************************************/
1613static u32 MT2063_CalcLO2Mult(u32 *Div, 1445static u32 MT2063_CalcLO2Mult(u32 *Div,
1614 u32 *FracN, 1446 u32 *FracN,
1615 u32 f_LO, 1447 u32 f_LO,
@@ -1627,28 +1459,15 @@ static u32 MT2063_CalcLO2Mult(u32 *Div,
1627 8191); 1459 8191);
1628} 1460}
1629 1461
1630/**************************************************************************** 1462/*
1631** 1463 * FindClearTuneFilter() - Calculate the corrrect ClearTune filter to be
1632** Name: FindClearTuneFilter 1464 * used for a given input frequency.
1633** 1465 *
1634** Description: Calculate the corrrect ClearTune filter to be used for 1466 * @state: ptr to tuner data structure
1635** a given input frequency. 1467 * @f_in: RF input center frequency (in Hz).
1636** 1468 *
1637** Parameters: state - ptr to tuner data structure 1469 * Returns: ClearTune filter number (0-31)
1638** f_in - RF input center frequency (in Hz). 1470 */
1639**
1640** Returns: ClearTune filter number (0-31)
1641**
1642** Dependencies: MUST CALL MT2064_Open BEFORE FindClearTuneFilter!
1643**
1644** Revision History:
1645**
1646** SCR Date Author Description
1647** -------------------------------------------------------------------------
1648** 04-10-2008 PINZ Ver 1.14: Use software-controlled ClearTune
1649** cross-over frequency values.
1650**
1651****************************************************************************/
1652static u32 FindClearTuneFilter(struct mt2063_state *state, u32 f_in) 1471static u32 FindClearTuneFilter(struct mt2063_state *state, u32 f_in)
1653{ 1472{
1654 u32 RFBand; 1473 u32 RFBand;
@@ -1667,51 +1486,13 @@ static u32 FindClearTuneFilter(struct mt2063_state *state, u32 f_in)
1667 return RFBand; 1486 return RFBand;
1668} 1487}
1669 1488
1670/**************************************************************************** 1489/*
1671** 1490 * MT2063_Tune() - Change the tuner's tuned frequency to RFin.
1672** Name: MT2063_Tune 1491 */
1673**
1674** Description: Change the tuner's tuned frequency to RFin.
1675**
1676** Parameters: h - Open handle to the tuner (from MT2063_Open).
1677** f_in - RF input center frequency (in Hz).
1678**
1679** Returns: status:
1680** MT_OK - No errors
1681** MT_INV_HANDLE - Invalid tuner handle
1682** MT_UPC_UNLOCK - Upconverter PLL unlocked
1683** MT_DNC_UNLOCK - Downconverter PLL unlocked
1684** MT_COMM_ERR - Serial bus communications error
1685** MT_SPUR_CNT_MASK - Count of avoided LO spurs
1686** MT_SPUR_PRESENT - LO spur possible in output
1687** MT_FIN_RANGE - Input freq out of range
1688** MT_FOUT_RANGE - Output freq out of range
1689** MT_UPC_RANGE - Upconverter freq out of range
1690** MT_DNC_RANGE - Downconverter freq out of range
1691**
1692** Dependencies: MUST CALL MT2063_Open BEFORE MT2063_Tune!
1693**
1694** MT_ReadSub - Read data from the two-wire serial bus
1695** MT_WriteSub - Write data to the two-wire serial bus
1696** MT_Sleep - Delay execution for x milliseconds
1697** MT2063_GetLocked - Checks to see if LO1 and LO2 are locked
1698**
1699** Revision History:
1700**
1701** SCR Date Author Description
1702** -------------------------------------------------------------------------
1703** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
1704** 04-10-2008 PINZ Ver 1.05: Use software-controlled ClearTune
1705** cross-over frequency values.
1706** 175 I 16-06-2008 PINZ Ver 1.16: Add control to avoid US DECT freqs.
1707** 175 I 06-19-2008 RSK Ver 1.17: Refactor DECT control to SpurAvoid.
1708** 06-24-2008 PINZ Ver 1.18: Add Get/SetParam CTFILT_SW
1709**
1710****************************************************************************/
1711static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in) 1492static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
1712{ /* RF input center frequency */ 1493{ /* RF input center frequency */
1713 1494
1714 u32 status = 0; /* status of operation */ 1495 u32 status = 0;
1715 u32 LO1; /* 1st LO register value */ 1496 u32 LO1; /* 1st LO register value */
1716 u32 Num1; /* Numerator for LO1 reg. value */ 1497 u32 Num1; /* Numerator for LO1 reg. value */
1717 u32 f_IF1; /* 1st IF requested */ 1498 u32 f_IF1; /* 1st IF requested */
@@ -1735,7 +1516,7 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
1735 return -EINVAL; 1516 return -EINVAL;
1736 1517
1737 /* 1518 /*
1738 ** Save original LO1 and LO2 register values 1519 * Save original LO1 and LO2 register values
1739 */ 1520 */
1740 ofLO1 = state->AS_Data.f_LO1; 1521 ofLO1 = state->AS_Data.f_LO1;
1741 ofLO2 = state->AS_Data.f_LO2; 1522 ofLO2 = state->AS_Data.f_LO2;
@@ -1743,7 +1524,7 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
1743 ofout = state->AS_Data.f_out; 1524 ofout = state->AS_Data.f_out;
1744 1525
1745 /* 1526 /*
1746 ** Find and set RF Band setting 1527 * Find and set RF Band setting
1747 */ 1528 */
1748 if (state->ctfilt_sw == 1) { 1529 if (state->ctfilt_sw == 1) {
1749 val = (state->reg[MT2063_REG_CTUNE_CTRL] | 0x08); 1530 val = (state->reg[MT2063_REG_CTUNE_CTRL] | 0x08);
@@ -1763,7 +1544,7 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
1763 } 1544 }
1764 1545
1765 /* 1546 /*
1766 ** Read the FIFF Center Frequency from the tuner 1547 * Read the FIFF Center Frequency from the tuner
1767 */ 1548 */
1768 if (status >= 0) { 1549 if (status >= 0) {
1769 status |= 1550 status |=
@@ -1773,7 +1554,7 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
1773 fiffc = state->reg[MT2063_REG_FIFFC]; 1554 fiffc = state->reg[MT2063_REG_FIFFC];
1774 } 1555 }
1775 /* 1556 /*
1776 ** Assign in the requested values 1557 * Assign in the requested values
1777 */ 1558 */
1778 state->AS_Data.f_in = f_in; 1559 state->AS_Data.f_in = f_in;
1779 /* Request a 1st IF such that LO1 is on a step size */ 1560 /* Request a 1st IF such that LO1 is on a step size */
@@ -1783,8 +1564,8 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
1783 state->AS_Data.f_ref) - f_in; 1564 state->AS_Data.f_ref) - f_in;
1784 1565
1785 /* 1566 /*
1786 ** Calculate frequency settings. f_IF1_FREQ + f_in is the 1567 * Calculate frequency settings. f_IF1_FREQ + f_in is the
1787 ** desired LO1 frequency 1568 * desired LO1 frequency
1788 */ 1569 */
1789 MT2063_ResetExclZones(&state->AS_Data); 1570 MT2063_ResetExclZones(&state->AS_Data);
1790 1571
@@ -1799,14 +1580,14 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
1799 state->AS_Data.f_LO2_Step, state->AS_Data.f_ref); 1580 state->AS_Data.f_LO2_Step, state->AS_Data.f_ref);
1800 1581
1801 /* 1582 /*
1802 ** Check for any LO spurs in the output bandwidth and adjust 1583 * Check for any LO spurs in the output bandwidth and adjust
1803 ** the LO settings to avoid them if needed 1584 * the LO settings to avoid them if needed
1804 */ 1585 */
1805 status |= MT2063_AvoidSpurs(&state->AS_Data); 1586 status |= MT2063_AvoidSpurs(&state->AS_Data);
1806 /* 1587 /*
1807 ** MT_AvoidSpurs spurs may have changed the LO1 & LO2 values. 1588 * MT_AvoidSpurs spurs may have changed the LO1 & LO2 values.
1808 ** Recalculate the LO frequencies and the values to be placed 1589 * Recalculate the LO frequencies and the values to be placed
1809 ** in the tuning registers. 1590 * in the tuning registers.
1810 */ 1591 */
1811 state->AS_Data.f_LO1 = 1592 state->AS_Data.f_LO1 =
1812 MT2063_CalcLO1Mult(&LO1, &Num1, state->AS_Data.f_LO1, 1593 MT2063_CalcLO1Mult(&LO1, &Num1, state->AS_Data.f_LO1,
@@ -1819,7 +1600,7 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
1819 state->AS_Data.f_LO2_Step, state->AS_Data.f_ref); 1600 state->AS_Data.f_LO2_Step, state->AS_Data.f_ref);
1820 1601
1821 /* 1602 /*
1822 ** Check the upconverter and downconverter frequency ranges 1603 * Check the upconverter and downconverter frequency ranges
1823 */ 1604 */
1824 if ((state->AS_Data.f_LO1 < MT2063_MIN_UPC_FREQ) 1605 if ((state->AS_Data.f_LO1 < MT2063_MIN_UPC_FREQ)
1825 || (state->AS_Data.f_LO1 > MT2063_MAX_UPC_FREQ)) 1606 || (state->AS_Data.f_LO1 > MT2063_MAX_UPC_FREQ))
@@ -1832,19 +1613,19 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
1832 LO2LK = 0x40; 1613 LO2LK = 0x40;
1833 1614
1834 /* 1615 /*
1835 ** If we have the same LO frequencies and we're already locked, 1616 * If we have the same LO frequencies and we're already locked,
1836 ** then skip re-programming the LO registers. 1617 * then skip re-programming the LO registers.
1837 */ 1618 */
1838 if ((ofLO1 != state->AS_Data.f_LO1) 1619 if ((ofLO1 != state->AS_Data.f_LO1)
1839 || (ofLO2 != state->AS_Data.f_LO2) 1620 || (ofLO2 != state->AS_Data.f_LO2)
1840 || ((state->reg[MT2063_REG_LO_STATUS] & (LO1LK | LO2LK)) != 1621 || ((state->reg[MT2063_REG_LO_STATUS] & (LO1LK | LO2LK)) !=
1841 (LO1LK | LO2LK))) { 1622 (LO1LK | LO2LK))) {
1842 /* 1623 /*
1843 ** Calculate the FIFFOF register value 1624 * Calculate the FIFFOF register value
1844 ** 1625 *
1845 ** IF1_Actual 1626 * IF1_Actual
1846 ** FIFFOF = ------------ - 8 * FIFFC - 4992 1627 * FIFFOF = ------------ - 8 * FIFFC - 4992
1847 ** f_ref/64 1628 * f_ref/64
1848 */ 1629 */
1849 fiffof = 1630 fiffof =
1850 (state->AS_Data.f_LO1 - 1631 (state->AS_Data.f_LO1 -
@@ -1854,8 +1635,8 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
1854 fiffof = 0xFF; 1635 fiffof = 0xFF;
1855 1636
1856 /* 1637 /*
1857 ** Place all of the calculated values into the local tuner 1638 * Place all of the calculated values into the local tuner
1858 ** register fields. 1639 * register fields.
1859 */ 1640 */
1860 if (status >= 0) { 1641 if (status >= 0) {
1861 state->reg[MT2063_REG_LO1CQ_1] = (u8) (LO1 & 0xFF); /* DIV1q */ 1642 state->reg[MT2063_REG_LO1CQ_1] = (u8) (LO1 & 0xFF); /* DIV1q */
@@ -1866,9 +1647,9 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
1866 state->reg[MT2063_REG_LO2CQ_3] = (u8) (0xE0 | (Num2 & 0x000F)); /* NUM2q (lo) */ 1647 state->reg[MT2063_REG_LO2CQ_3] = (u8) (0xE0 | (Num2 & 0x000F)); /* NUM2q (lo) */
1867 1648
1868 /* 1649 /*
1869 ** Now write out the computed register values 1650 * Now write out the computed register values
1870 ** IMPORTANT: There is a required order for writing 1651 * IMPORTANT: There is a required order for writing
1871 ** (0x05 must follow all the others). 1652 * (0x05 must follow all the others).
1872 */ 1653 */
1873 status |= mt2063_write(state, MT2063_REG_LO1CQ_1, &state->reg[MT2063_REG_LO1CQ_1], 5); /* 0x01 - 0x05 */ 1654 status |= mt2063_write(state, MT2063_REG_LO1CQ_1, &state->reg[MT2063_REG_LO1CQ_1], 5); /* 0x01 - 0x05 */
1874 if (state->tuner_id == MT2063_B0) { 1655 if (state->tuner_id == MT2063_B0) {
@@ -1890,7 +1671,7 @@ static u32 MT2063_Tune(struct mt2063_state *state, u32 f_in)
1890 } 1671 }
1891 1672
1892 /* 1673 /*
1893 ** Check for LO's locking 1674 * Check for LO's locking
1894 */ 1675 */
1895 1676
1896 if (status < 0) 1677 if (status < 0)
@@ -2173,7 +1954,7 @@ static int mt2063_get_status(struct dvb_frontend *fe, u32 *tuner_status)
2173 if (status < 0) 1954 if (status < 0)
2174 return status; 1955 return status;
2175 if (status) 1956 if (status)
2176 *tuner_status = TUNER_STATUS_LOCKED; 1957 *tuner_status = TUNER_STATUS_LOCKED;
2177 1958
2178 return 0; 1959 return 0;
2179} 1960}
@@ -2273,7 +2054,7 @@ static int mt2063_set_analog_params(struct dvb_frontend *fe,
2273/* 2054/*
2274 * As defined on EN 300 429, the DVB-C roll-off factor is 0.15. 2055 * As defined on EN 300 429, the DVB-C roll-off factor is 0.15.
2275 * So, the amount of the needed bandwith is given by: 2056 * So, the amount of the needed bandwith is given by:
2276 * Bw = Symbol_rate * (1 + 0.15) 2057 * Bw = Symbol_rate * (1 + 0.15)
2277 * As such, the maximum symbol rate supported by 6 MHz is given by: 2058 * As such, the maximum symbol rate supported by 6 MHz is given by:
2278 * max_symbol_rate = 6 MHz / 1.15 = 5217391 Bauds 2059 * max_symbol_rate = 6 MHz / 1.15 = 5217391 Bauds
2279 */ 2060 */
@@ -2346,7 +2127,7 @@ static int mt2063_set_params(struct dvb_frontend *fe,
2346 status = MT2063_Tune(state, (params->frequency + (pict2chanb_vsb + (ch_bw / 2)))); 2127 status = MT2063_Tune(state, (params->frequency + (pict2chanb_vsb + (ch_bw / 2))));
2347 2128
2348 if (status < 0) 2129 if (status < 0)
2349 return status; 2130 return status;
2350 2131
2351 state->frequency = params->frequency; 2132 state->frequency = params->frequency;
2352 return 0; 2133 return 0;
@@ -2445,6 +2226,6 @@ EXPORT_SYMBOL_GPL(tuner_MT2063_ClearPowerMaskBits);
2445 2226
2446MODULE_PARM_DESC(verbose, "Set Verbosity level"); 2227MODULE_PARM_DESC(verbose, "Set Verbosity level");
2447 2228
2448MODULE_AUTHOR("Henry"); 2229MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
2449MODULE_DESCRIPTION("MT2063 Silicon tuner"); 2230MODULE_DESCRIPTION("MT2063 Silicon tuner");
2450MODULE_LICENSE("GPL"); 2231MODULE_LICENSE("GPL");