mt2063.c 151 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767
  1. #include <linux/init.h>
  2. #include <linux/kernel.h>
  3. #include <linux/module.h>
  4. #include <linux/string.h>
  5. #include "mt2063.h"
  6. static unsigned int verbose;
  7. module_param(verbose, int, 0644);
  8. /* Internal structures and types */
  9. /* FIXME: we probably don't need these new FE get/set property types for tuner */
  10. #define DVBFE_TUNER_OPEN 99
  11. #define DVBFE_TUNER_SOFTWARE_SHUTDOWN 100
  12. #define DVBFE_TUNER_CLEAR_POWER_MASKBITS 101
  13. #define MT2063_ERROR (1 << 31)
  14. #define MT2063_USER_ERROR (1 << 30)
  15. /* Macro to be used to check for errors */
  16. #define MT2063_IS_ERROR(s) (((s) >> 30) != 0)
  17. #define MT2063_NO_ERROR(s) (((s) >> 30) == 0)
  18. #define MT2063_OK (0x00000000)
  19. /* Unknown error */
  20. #define MT2063_UNKNOWN (0x80000001)
  21. /* Error: Upconverter PLL is not locked */
  22. #define MT2063_UPC_UNLOCK (0x80000002)
  23. /* Error: Downconverter PLL is not locked */
  24. #define MT2063_DNC_UNLOCK (0x80000004)
  25. /* Error: Two-wire serial bus communications error */
  26. #define MT2063_COMM_ERR (0x80000008)
  27. /* Error: Tuner handle passed to function was invalid */
  28. #define MT2063_INV_HANDLE (0x80000010)
  29. /* Error: Function argument is invalid (out of range) */
  30. #define MT2063_ARG_RANGE (0x80000020)
  31. /* Error: Function argument (ptr to return value) was NULL */
  32. #define MT2063_ARG_NULL (0x80000040)
  33. /* Error: Attempt to open more than MT_TUNER_CNT tuners */
  34. #define MT2063_TUNER_CNT_ERR (0x80000080)
  35. /* Error: Tuner Part Code / Rev Code mismatches expected value */
  36. #define MT2063_TUNER_ID_ERR (0x80000100)
  37. /* Error: Tuner Initialization failure */
  38. #define MT2063_TUNER_INIT_ERR (0x80000200)
  39. #define MT2063_TUNER_OPEN_ERR (0x80000400)
  40. /* User-definable fields (see mt_userdef.h) */
  41. #define MT2063_USER_DEFINED1 (0x00001000)
  42. #define MT2063_USER_DEFINED2 (0x00002000)
  43. #define MT2063_USER_DEFINED3 (0x00004000)
  44. #define MT2063_USER_DEFINED4 (0x00008000)
  45. #define MT2063_USER_MASK (0x4000f000)
  46. #define MT2063_USER_SHIFT (12)
  47. /* Info: Mask of bits used for # of LO-related spurs that were avoided during tuning */
  48. #define MT2063_SPUR_CNT_MASK (0x001f0000)
  49. #define MT2063_SPUR_SHIFT (16)
  50. /* Info: Tuner timeout waiting for condition */
  51. #define MT2063_TUNER_TIMEOUT (0x00400000)
  52. /* Info: Unavoidable LO-related spur may be present in the output */
  53. #define MT2063_SPUR_PRESENT_ERR (0x00800000)
  54. /* Info: Tuner input frequency is out of range */
  55. #define MT2063_FIN_RANGE (0x01000000)
  56. /* Info: Tuner output frequency is out of range */
  57. #define MT2063_FOUT_RANGE (0x02000000)
  58. /* Info: Upconverter frequency is out of range (may be reason for MT_UPC_UNLOCK) */
  59. #define MT2063_UPC_RANGE (0x04000000)
  60. /* Info: Downconverter frequency is out of range (may be reason for MT_DPC_UNLOCK) */
  61. #define MT2063_DNC_RANGE (0x08000000)
  62. /*
  63. * Data Types
  64. */
  65. #define MAX_UDATA (4294967295) /* max value storable in u32 */
  66. /*
  67. * Define an MTxxxx_CNT macro for each type of tuner that will be built
  68. * into your application (e.g., MT2121, MT2060). MT_TUNER_CNT
  69. * must be set to the SUM of all of the MTxxxx_CNT macros.
  70. *
  71. * #define MT2050_CNT (1)
  72. * #define MT2060_CNT (1)
  73. * #define MT2111_CNT (1)
  74. * #define MT2121_CNT (3)
  75. */
  76. #define MT2063_TUNER_CNT (1) /* total num of MicroTuner tuners */
  77. #define MT2063_I2C (0xC0)
  78. /*
  79. * Constant defining the version of the following structure
  80. * and therefore the API for this code.
  81. *
  82. * When compiling the tuner driver, the preprocessor will
  83. * check against this version number to make sure that
  84. * it matches the version that the tuner driver knows about.
  85. */
  86. /* DECT Frequency Avoidance */
  87. #define MT2063_DECT_AVOID_US_FREQS 0x00000001
  88. #define MT2063_DECT_AVOID_EURO_FREQS 0x00000002
  89. #define MT2063_EXCLUDE_US_DECT_FREQUENCIES(s) (((s) & MT2063_DECT_AVOID_US_FREQS) != 0)
  90. #define MT2063_EXCLUDE_EURO_DECT_FREQUENCIES(s) (((s) & MT2063_DECT_AVOID_EURO_FREQS) != 0)
  91. enum MT2063_DECT_Avoid_Type {
  92. MT2063_NO_DECT_AVOIDANCE = 0, /* Do not create DECT exclusion zones. */
  93. MT2063_AVOID_US_DECT = MT2063_DECT_AVOID_US_FREQS, /* Avoid US DECT frequencies. */
  94. MT2063_AVOID_EURO_DECT = MT2063_DECT_AVOID_EURO_FREQS, /* Avoid European DECT frequencies. */
  95. MT2063_AVOID_BOTH /* Avoid both regions. Not typically used. */
  96. };
  97. #define MT2063_MAX_ZONES 48
  98. struct MT2063_ExclZone_t;
  99. struct MT2063_ExclZone_t {
  100. u32 min_;
  101. u32 max_;
  102. struct MT2063_ExclZone_t *next_;
  103. };
  104. /*
  105. * Structure of data needed for Spur Avoidance
  106. */
  107. struct MT2063_AvoidSpursData_t {
  108. u32 nAS_Algorithm;
  109. u32 f_ref;
  110. u32 f_in;
  111. u32 f_LO1;
  112. u32 f_if1_Center;
  113. u32 f_if1_Request;
  114. u32 f_if1_bw;
  115. u32 f_LO2;
  116. u32 f_out;
  117. u32 f_out_bw;
  118. u32 f_LO1_Step;
  119. u32 f_LO2_Step;
  120. u32 f_LO1_FracN_Avoid;
  121. u32 f_LO2_FracN_Avoid;
  122. u32 f_zif_bw;
  123. u32 f_min_LO_Separation;
  124. u32 maxH1;
  125. u32 maxH2;
  126. enum MT2063_DECT_Avoid_Type avoidDECT;
  127. u32 bSpurPresent;
  128. u32 bSpurAvoided;
  129. u32 nSpursFound;
  130. u32 nZones;
  131. struct MT2063_ExclZone_t *freeZones;
  132. struct MT2063_ExclZone_t *usedZones;
  133. struct MT2063_ExclZone_t MT2063_ExclZones[MT2063_MAX_ZONES];
  134. };
  135. /*
  136. * Values returned by the MT2063's on-chip temperature sensor
  137. * to be read/written.
  138. */
  139. enum MT2063_Temperature {
  140. MT2063_T_0C = 0, /* Temperature approx 0C */
  141. MT2063_T_10C, /* Temperature approx 10C */
  142. MT2063_T_20C, /* Temperature approx 20C */
  143. MT2063_T_30C, /* Temperature approx 30C */
  144. MT2063_T_40C, /* Temperature approx 40C */
  145. MT2063_T_50C, /* Temperature approx 50C */
  146. MT2063_T_60C, /* Temperature approx 60C */
  147. MT2063_T_70C, /* Temperature approx 70C */
  148. MT2063_T_80C, /* Temperature approx 80C */
  149. MT2063_T_90C, /* Temperature approx 90C */
  150. MT2063_T_100C, /* Temperature approx 100C */
  151. MT2063_T_110C, /* Temperature approx 110C */
  152. MT2063_T_120C, /* Temperature approx 120C */
  153. MT2063_T_130C, /* Temperature approx 130C */
  154. MT2063_T_140C, /* Temperature approx 140C */
  155. MT2063_T_150C, /* Temperature approx 150C */
  156. };
  157. /*
  158. * Parameters for selecting GPIO bits
  159. */
  160. enum MT2063_GPIO_Attr {
  161. MT2063_GPIO_IN,
  162. MT2063_GPIO_DIR,
  163. MT2063_GPIO_OUT,
  164. };
  165. enum MT2063_GPIO_ID {
  166. MT2063_GPIO0,
  167. MT2063_GPIO1,
  168. MT2063_GPIO2,
  169. };
  170. /*
  171. * Parameter for function MT2063_SetExtSRO that specifies the external
  172. * SRO drive frequency.
  173. *
  174. * MT2063_EXT_SRO_OFF is the power-up default value.
  175. */
  176. enum MT2063_Ext_SRO {
  177. MT2063_EXT_SRO_OFF, /* External SRO drive off */
  178. MT2063_EXT_SRO_BY_4, /* External SRO drive divide by 4 */
  179. MT2063_EXT_SRO_BY_2, /* External SRO drive divide by 2 */
  180. MT2063_EXT_SRO_BY_1 /* External SRO drive divide by 1 */
  181. };
  182. /*
  183. * Parameter for function MT2063_SetPowerMask that specifies the power down
  184. * of various sections of the MT2063.
  185. */
  186. enum MT2063_Mask_Bits {
  187. MT2063_REG_SD = 0x0040, /* Shutdown regulator */
  188. MT2063_SRO_SD = 0x0020, /* Shutdown SRO */
  189. MT2063_AFC_SD = 0x0010, /* Shutdown AFC A/D */
  190. MT2063_PD_SD = 0x0002, /* Enable power detector shutdown */
  191. MT2063_PDADC_SD = 0x0001, /* Enable power detector A/D shutdown */
  192. MT2063_VCO_SD = 0x8000, /* Enable VCO shutdown */
  193. MT2063_LTX_SD = 0x4000, /* Enable LTX shutdown */
  194. MT2063_LT1_SD = 0x2000, /* Enable LT1 shutdown */
  195. MT2063_LNA_SD = 0x1000, /* Enable LNA shutdown */
  196. MT2063_UPC_SD = 0x0800, /* Enable upconverter shutdown */
  197. MT2063_DNC_SD = 0x0400, /* Enable downconverter shutdown */
  198. MT2063_VGA_SD = 0x0200, /* Enable VGA shutdown */
  199. MT2063_AMP_SD = 0x0100, /* Enable AMP shutdown */
  200. MT2063_ALL_SD = 0xFF73, /* All shutdown bits for this tuner */
  201. MT2063_NONE_SD = 0x0000 /* No shutdown bits */
  202. };
  203. /*
  204. * Parameter for function MT2063_GetParam & MT2063_SetParam that
  205. * specifies the tuning algorithm parameter to be read/written.
  206. */
  207. enum MT2063_Param {
  208. /* tuner address set by MT2063_Open() */
  209. MT2063_IC_ADDR,
  210. /* max number of MT2063 tuners set by MT_TUNER_CNT in mt_userdef.h */
  211. MT2063_MAX_OPEN,
  212. /* current number of open MT2063 tuners set by MT2063_Open() */
  213. MT2063_NUM_OPEN,
  214. /* crystal frequency (default: 16000000 Hz) */
  215. MT2063_SRO_FREQ,
  216. /* min tuning step size (default: 50000 Hz) */
  217. MT2063_STEPSIZE,
  218. /* input center frequency set by MT2063_Tune() */
  219. MT2063_INPUT_FREQ,
  220. /* LO1 Frequency set by MT2063_Tune() */
  221. MT2063_LO1_FREQ,
  222. /* LO1 minimum step size (default: 250000 Hz) */
  223. MT2063_LO1_STEPSIZE,
  224. /* LO1 FracN keep-out region (default: 999999 Hz) */
  225. MT2063_LO1_FRACN_AVOID_PARAM,
  226. /* Current 1st IF in use set by MT2063_Tune() */
  227. MT2063_IF1_ACTUAL,
  228. /* Requested 1st IF set by MT2063_Tune() */
  229. MT2063_IF1_REQUEST,
  230. /* Center of 1st IF SAW filter (default: 1218000000 Hz) */
  231. MT2063_IF1_CENTER,
  232. /* Bandwidth of 1st IF SAW filter (default: 20000000 Hz) */
  233. MT2063_IF1_BW,
  234. /* zero-IF bandwidth (default: 2000000 Hz) */
  235. MT2063_ZIF_BW,
  236. /* LO2 Frequency set by MT2063_Tune() */
  237. MT2063_LO2_FREQ,
  238. /* LO2 minimum step size (default: 50000 Hz) */
  239. MT2063_LO2_STEPSIZE,
  240. /* LO2 FracN keep-out region (default: 374999 Hz) */
  241. MT2063_LO2_FRACN_AVOID,
  242. /* output center frequency set by MT2063_Tune() */
  243. MT2063_OUTPUT_FREQ,
  244. /* output bandwidth set by MT2063_Tune() */
  245. MT2063_OUTPUT_BW,
  246. /* min inter-tuner LO separation (default: 1000000 Hz) */
  247. MT2063_LO_SEPARATION,
  248. /* ID of avoid-spurs algorithm in use compile-time constant */
  249. MT2063_AS_ALG,
  250. /* max # of intra-tuner harmonics (default: 15) */
  251. MT2063_MAX_HARM1,
  252. /* max # of inter-tuner harmonics (default: 7) */
  253. MT2063_MAX_HARM2,
  254. /* # of 1st IF exclusion zones used set by MT2063_Tune() */
  255. MT2063_EXCL_ZONES,
  256. /* # of spurs found/avoided set by MT2063_Tune() */
  257. MT2063_NUM_SPURS,
  258. /* >0 spurs avoided set by MT2063_Tune() */
  259. MT2063_SPUR_AVOIDED,
  260. /* >0 spurs in output (mathematically) set by MT2063_Tune() */
  261. MT2063_SPUR_PRESENT,
  262. /* Receiver Mode for some parameters. 1 is DVB-T */
  263. MT2063_RCVR_MODE,
  264. /* directly set LNA attenuation, parameter is value to set */
  265. MT2063_ACLNA,
  266. /* maximum LNA attenuation, parameter is value to set */
  267. MT2063_ACLNA_MAX,
  268. /* directly set ATN attenuation. Paremeter is value to set. */
  269. MT2063_ACRF,
  270. /* maxium ATN attenuation. Paremeter is value to set. */
  271. MT2063_ACRF_MAX,
  272. /* directly set FIF attenuation. Paremeter is value to set. */
  273. MT2063_ACFIF,
  274. /* maxium FIF attenuation. Paremeter is value to set. */
  275. MT2063_ACFIF_MAX,
  276. /* LNA Rin */
  277. MT2063_LNA_RIN,
  278. /* Power Detector LNA level target */
  279. MT2063_LNA_TGT,
  280. /* Power Detector 1 level */
  281. MT2063_PD1,
  282. /* Power Detector 1 level target */
  283. MT2063_PD1_TGT,
  284. /* Power Detector 2 level */
  285. MT2063_PD2,
  286. /* Power Detector 2 level target */
  287. MT2063_PD2_TGT,
  288. /* Selects, which DNC is activ */
  289. MT2063_DNC_OUTPUT_ENABLE,
  290. /* VGA gain code */
  291. MT2063_VGAGC,
  292. /* VGA bias current */
  293. MT2063_VGAOI,
  294. /* TAGC, determins the speed of the AGC */
  295. MT2063_TAGC,
  296. /* AMP gain code */
  297. MT2063_AMPGC,
  298. /* Control setting to avoid DECT freqs (default: MT_AVOID_BOTH) */
  299. MT2063_AVOID_DECT,
  300. /* Cleartune filter selection: 0 - by IC (default), 1 - by software */
  301. MT2063_CTFILT_SW,
  302. MT2063_EOP /* last entry in enumerated list */
  303. };
  304. /*
  305. * Parameter for selecting tuner mode
  306. */
  307. enum MT2063_RCVR_MODES {
  308. MT2063_CABLE_QAM = 0, /* Digital cable */
  309. MT2063_CABLE_ANALOG, /* Analog cable */
  310. MT2063_OFFAIR_COFDM, /* Digital offair */
  311. MT2063_OFFAIR_COFDM_SAWLESS, /* Digital offair without SAW */
  312. MT2063_OFFAIR_ANALOG, /* Analog offair */
  313. MT2063_OFFAIR_8VSB, /* Analog offair */
  314. MT2063_NUM_RCVR_MODES
  315. };
  316. /*
  317. * Possible values for MT2063_DNC_OUTPUT
  318. */
  319. enum MT2063_DNC_Output_Enable {
  320. MT2063_DNC_NONE = 0,
  321. MT2063_DNC_1,
  322. MT2063_DNC_2,
  323. MT2063_DNC_BOTH
  324. };
  325. /*
  326. ** Two-wire serial bus subaddresses of the tuner registers.
  327. ** Also known as the tuner's register addresses.
  328. */
  329. enum MT2063_Register_Offsets {
  330. MT2063_REG_PART_REV = 0, /* 0x00: Part/Rev Code */
  331. MT2063_REG_LO1CQ_1, /* 0x01: LO1C Queued Byte 1 */
  332. MT2063_REG_LO1CQ_2, /* 0x02: LO1C Queued Byte 2 */
  333. MT2063_REG_LO2CQ_1, /* 0x03: LO2C Queued Byte 1 */
  334. MT2063_REG_LO2CQ_2, /* 0x04: LO2C Queued Byte 2 */
  335. MT2063_REG_LO2CQ_3, /* 0x05: LO2C Queued Byte 3 */
  336. MT2063_REG_RSVD_06, /* 0x06: Reserved */
  337. MT2063_REG_LO_STATUS, /* 0x07: LO Status */
  338. MT2063_REG_FIFFC, /* 0x08: FIFF Center */
  339. MT2063_REG_CLEARTUNE, /* 0x09: ClearTune Filter */
  340. MT2063_REG_ADC_OUT, /* 0x0A: ADC_OUT */
  341. MT2063_REG_LO1C_1, /* 0x0B: LO1C Byte 1 */
  342. MT2063_REG_LO1C_2, /* 0x0C: LO1C Byte 2 */
  343. MT2063_REG_LO2C_1, /* 0x0D: LO2C Byte 1 */
  344. MT2063_REG_LO2C_2, /* 0x0E: LO2C Byte 2 */
  345. MT2063_REG_LO2C_3, /* 0x0F: LO2C Byte 3 */
  346. MT2063_REG_RSVD_10, /* 0x10: Reserved */
  347. MT2063_REG_PWR_1, /* 0x11: PWR Byte 1 */
  348. MT2063_REG_PWR_2, /* 0x12: PWR Byte 2 */
  349. MT2063_REG_TEMP_STATUS, /* 0x13: Temp Status */
  350. MT2063_REG_XO_STATUS, /* 0x14: Crystal Status */
  351. MT2063_REG_RF_STATUS, /* 0x15: RF Attn Status */
  352. MT2063_REG_FIF_STATUS, /* 0x16: FIF Attn Status */
  353. MT2063_REG_LNA_OV, /* 0x17: LNA Attn Override */
  354. MT2063_REG_RF_OV, /* 0x18: RF Attn Override */
  355. MT2063_REG_FIF_OV, /* 0x19: FIF Attn Override */
  356. MT2063_REG_LNA_TGT, /* 0x1A: Reserved */
  357. MT2063_REG_PD1_TGT, /* 0x1B: Pwr Det 1 Target */
  358. MT2063_REG_PD2_TGT, /* 0x1C: Pwr Det 2 Target */
  359. MT2063_REG_RSVD_1D, /* 0x1D: Reserved */
  360. MT2063_REG_RSVD_1E, /* 0x1E: Reserved */
  361. MT2063_REG_RSVD_1F, /* 0x1F: Reserved */
  362. MT2063_REG_RSVD_20, /* 0x20: Reserved */
  363. MT2063_REG_BYP_CTRL, /* 0x21: Bypass Control */
  364. MT2063_REG_RSVD_22, /* 0x22: Reserved */
  365. MT2063_REG_RSVD_23, /* 0x23: Reserved */
  366. MT2063_REG_RSVD_24, /* 0x24: Reserved */
  367. MT2063_REG_RSVD_25, /* 0x25: Reserved */
  368. MT2063_REG_RSVD_26, /* 0x26: Reserved */
  369. MT2063_REG_RSVD_27, /* 0x27: Reserved */
  370. MT2063_REG_FIFF_CTRL, /* 0x28: FIFF Control */
  371. MT2063_REG_FIFF_OFFSET, /* 0x29: FIFF Offset */
  372. MT2063_REG_CTUNE_CTRL, /* 0x2A: Reserved */
  373. MT2063_REG_CTUNE_OV, /* 0x2B: Reserved */
  374. MT2063_REG_CTRL_2C, /* 0x2C: Reserved */
  375. MT2063_REG_FIFF_CTRL2, /* 0x2D: Fiff Control */
  376. MT2063_REG_RSVD_2E, /* 0x2E: Reserved */
  377. MT2063_REG_DNC_GAIN, /* 0x2F: DNC Control */
  378. MT2063_REG_VGA_GAIN, /* 0x30: VGA Gain Ctrl */
  379. MT2063_REG_RSVD_31, /* 0x31: Reserved */
  380. MT2063_REG_TEMP_SEL, /* 0x32: Temperature Selection */
  381. MT2063_REG_RSVD_33, /* 0x33: Reserved */
  382. MT2063_REG_RSVD_34, /* 0x34: Reserved */
  383. MT2063_REG_RSVD_35, /* 0x35: Reserved */
  384. MT2063_REG_RSVD_36, /* 0x36: Reserved */
  385. MT2063_REG_RSVD_37, /* 0x37: Reserved */
  386. MT2063_REG_RSVD_38, /* 0x38: Reserved */
  387. MT2063_REG_RSVD_39, /* 0x39: Reserved */
  388. MT2063_REG_RSVD_3A, /* 0x3A: Reserved */
  389. MT2063_REG_RSVD_3B, /* 0x3B: Reserved */
  390. MT2063_REG_RSVD_3C, /* 0x3C: Reserved */
  391. MT2063_REG_END_REGS
  392. };
  393. struct MT2063_Info_t {
  394. void *handle;
  395. void *hUserData;
  396. u32 address;
  397. u32 tuner_id;
  398. struct MT2063_AvoidSpursData_t AS_Data;
  399. u32 f_IF1_actual;
  400. u32 rcvr_mode;
  401. u32 ctfilt_sw;
  402. u32 CTFiltMax[31];
  403. u32 num_regs;
  404. u8 reg[MT2063_REG_END_REGS];
  405. };
  406. typedef struct MT2063_Info_t *pMT2063_Info_t;
  407. enum MTTune_atv_standard {
  408. MTTUNEA_UNKNOWN = 0,
  409. MTTUNEA_PAL_B,
  410. MTTUNEA_PAL_G,
  411. MTTUNEA_PAL_I,
  412. MTTUNEA_PAL_L,
  413. MTTUNEA_PAL_MN,
  414. MTTUNEA_PAL_DK,
  415. MTTUNEA_DIGITAL,
  416. MTTUNEA_FMRADIO,
  417. MTTUNEA_DVBC,
  418. MTTUNEA_DVBT
  419. };
  420. struct mt2063_state {
  421. struct i2c_adapter *i2c;
  422. const struct mt2063_config *config;
  423. struct dvb_tuner_ops ops;
  424. struct dvb_frontend *frontend;
  425. struct tuner_state status;
  426. struct MT2063_Info_t *MT2063_ht;
  427. bool MT2063_init;
  428. enum MTTune_atv_standard tv_type;
  429. u32 frequency;
  430. u32 srate;
  431. u32 bandwidth;
  432. u32 reference;
  433. };
  434. /* Prototypes */
  435. static void MT2063_AddExclZone(struct MT2063_AvoidSpursData_t *pAS_Info,
  436. u32 f_min, u32 f_max);
  437. static u32 MT2063_ReInit(void *h);
  438. static u32 MT2063_Close(void *hMT2063);
  439. static u32 MT2063_GetReg(void *h, u8 reg, u8 * val);
  440. static u32 MT2063_GetParam(void *h, enum MT2063_Param param, u32 * pValue);
  441. static u32 MT2063_SetReg(void *h, u8 reg, u8 val);
  442. static u32 MT2063_SetParam(void *h, enum MT2063_Param param, u32 nValue);
  443. /*****************/
  444. /* From drivers/media/common/tuners/mt2063_cfg.h */
  445. unsigned int mt2063_setTune(struct dvb_frontend *fe, u32 f_in,
  446. u32 bw_in,
  447. enum MTTune_atv_standard tv_type)
  448. {
  449. //return (int)MT_Tune_atv(h, f_in, bw_in, tv_type);
  450. struct dvb_frontend_ops *frontend_ops = NULL;
  451. struct dvb_tuner_ops *tuner_ops = NULL;
  452. struct tuner_state t_state;
  453. struct mt2063_state *mt2063State = fe->tuner_priv;
  454. int err = 0;
  455. t_state.frequency = f_in;
  456. t_state.bandwidth = bw_in;
  457. mt2063State->tv_type = tv_type;
  458. if (&fe->ops)
  459. frontend_ops = &fe->ops;
  460. if (&frontend_ops->tuner_ops)
  461. tuner_ops = &frontend_ops->tuner_ops;
  462. if (tuner_ops->set_state) {
  463. if ((err =
  464. tuner_ops->set_state(fe, DVBFE_TUNER_FREQUENCY,
  465. &t_state)) < 0) {
  466. printk("%s: Invalid parameter\n", __func__);
  467. return err;
  468. }
  469. }
  470. return err;
  471. }
  472. unsigned int mt2063_lockStatus(struct dvb_frontend *fe)
  473. {
  474. struct dvb_frontend_ops *frontend_ops = &fe->ops;
  475. struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
  476. struct tuner_state t_state;
  477. int err = 0;
  478. if (&fe->ops)
  479. frontend_ops = &fe->ops;
  480. if (&frontend_ops->tuner_ops)
  481. tuner_ops = &frontend_ops->tuner_ops;
  482. if (tuner_ops->get_state) {
  483. if ((err =
  484. tuner_ops->get_state(fe, DVBFE_TUNER_REFCLOCK,
  485. &t_state)) < 0) {
  486. printk("%s: Invalid parameter\n", __func__);
  487. return err;
  488. }
  489. }
  490. return err;
  491. }
  492. unsigned int tuner_MT2063_Open(struct dvb_frontend *fe)
  493. {
  494. struct dvb_frontend_ops *frontend_ops = &fe->ops;
  495. struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
  496. struct tuner_state t_state;
  497. int err = 0;
  498. if (&fe->ops)
  499. frontend_ops = &fe->ops;
  500. if (&frontend_ops->tuner_ops)
  501. tuner_ops = &frontend_ops->tuner_ops;
  502. if (tuner_ops->set_state) {
  503. if ((err =
  504. tuner_ops->set_state(fe, DVBFE_TUNER_OPEN,
  505. &t_state)) < 0) {
  506. printk("%s: Invalid parameter\n", __func__);
  507. return err;
  508. }
  509. }
  510. return err;
  511. }
  512. unsigned int tuner_MT2063_SoftwareShutdown(struct dvb_frontend *fe)
  513. {
  514. struct dvb_frontend_ops *frontend_ops = &fe->ops;
  515. struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
  516. struct tuner_state t_state;
  517. int err = 0;
  518. if (&fe->ops)
  519. frontend_ops = &fe->ops;
  520. if (&frontend_ops->tuner_ops)
  521. tuner_ops = &frontend_ops->tuner_ops;
  522. if (tuner_ops->set_state) {
  523. if ((err =
  524. tuner_ops->set_state(fe, DVBFE_TUNER_SOFTWARE_SHUTDOWN,
  525. &t_state)) < 0) {
  526. printk("%s: Invalid parameter\n", __func__);
  527. return err;
  528. }
  529. }
  530. return err;
  531. }
  532. unsigned int tuner_MT2063_ClearPowerMaskBits(struct dvb_frontend *fe)
  533. {
  534. struct dvb_frontend_ops *frontend_ops = &fe->ops;
  535. struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
  536. struct tuner_state t_state;
  537. int err = 0;
  538. if (&fe->ops)
  539. frontend_ops = &fe->ops;
  540. if (&frontend_ops->tuner_ops)
  541. tuner_ops = &frontend_ops->tuner_ops;
  542. if (tuner_ops->set_state) {
  543. if ((err =
  544. tuner_ops->set_state(fe, DVBFE_TUNER_CLEAR_POWER_MASKBITS,
  545. &t_state)) < 0) {
  546. printk("%s: Invalid parameter\n", __func__);
  547. return err;
  548. }
  549. }
  550. return err;
  551. }
  552. /*****************/
  553. //i2c operation
  554. static int mt2063_writeregs(struct mt2063_state *state, u8 reg1,
  555. u8 * data, int len)
  556. {
  557. int ret;
  558. u8 buf[60]; /* = { reg1, data }; */
  559. struct i2c_msg msg = {
  560. .addr = state->config->tuner_address,
  561. .flags = 0,
  562. .buf = buf,
  563. .len = len + 1
  564. };
  565. msg.buf[0] = reg1;
  566. memcpy(msg.buf + 1, data, len);
  567. //printk("mt2063_writeregs state->i2c=%p\n", state->i2c);
  568. ret = i2c_transfer(state->i2c, &msg, 1);
  569. if (ret < 0)
  570. printk("mt2063_writeregs error ret=%d\n", ret);
  571. return ret;
  572. }
  573. static int mt2063_read_regs(struct mt2063_state *state, u8 reg1, u8 * b, u8 len)
  574. {
  575. int ret;
  576. u8 b0[] = { reg1 };
  577. struct i2c_msg msg[] = {
  578. {
  579. .addr = state->config->tuner_address,
  580. .flags = I2C_M_RD,
  581. .buf = b0,
  582. .len = 1}, {
  583. .addr = state->config->tuner_address,
  584. .flags = I2C_M_RD,
  585. .buf = b,
  586. .len = len}
  587. };
  588. //printk("mt2063_read_regs state->i2c=%p\n", state->i2c);
  589. ret = i2c_transfer(state->i2c, msg, 2);
  590. if (ret < 0)
  591. printk("mt2063_readregs error ret=%d\n", ret);
  592. return ret;
  593. }
  594. //context of mt2063_userdef.c <Henry> ======================================
  595. //#################################################################
  596. //=================================================================
  597. /*****************************************************************************
  598. **
  599. ** Name: MT_WriteSub
  600. **
  601. ** Description: Write values to device using a two-wire serial bus.
  602. **
  603. ** Parameters: hUserData - User-specific I/O parameter that was
  604. ** passed to tuner's Open function.
  605. ** addr - device serial bus address (value passed
  606. ** as parameter to MTxxxx_Open)
  607. ** subAddress - serial bus sub-address (Register Address)
  608. ** pData - pointer to the Data to be written to the
  609. ** device
  610. ** cnt - number of bytes/registers to be written
  611. **
  612. ** Returns: status:
  613. ** MT_OK - No errors
  614. ** MT_COMM_ERR - Serial bus communications error
  615. ** user-defined
  616. **
  617. ** Notes: This is a callback function that is called from the
  618. ** the tuning algorithm. You MUST provide code for this
  619. ** function to write data using the tuner's 2-wire serial
  620. ** bus.
  621. **
  622. ** The hUserData parameter is a user-specific argument.
  623. ** If additional arguments are needed for the user's
  624. ** serial bus read/write functions, this argument can be
  625. ** used to supply the necessary information.
  626. ** The hUserData parameter is initialized in the tuner's Open
  627. ** function.
  628. **
  629. ** Revision History:
  630. **
  631. ** SCR Date Author Description
  632. ** -------------------------------------------------------------------------
  633. ** N/A 03-25-2004 DAD Original
  634. **
  635. *****************************************************************************/
  636. static u32 MT2063_WriteSub(void *hUserData,
  637. u32 addr,
  638. u8 subAddress, u8 * pData, u32 cnt)
  639. {
  640. u32 status = MT2063_OK; /* Status to be returned */
  641. struct dvb_frontend *fe = hUserData;
  642. struct mt2063_state *state = fe->tuner_priv;
  643. /*
  644. ** ToDo: Add code here to implement a serial-bus write
  645. ** operation to the MTxxxx tuner. If successful,
  646. ** return MT_OK.
  647. */
  648. /* return status; */
  649. fe->ops.i2c_gate_ctrl(fe, 1); //I2C bypass drxk3926 close i2c bridge
  650. if (mt2063_writeregs(state, subAddress, pData, cnt) < 0) {
  651. status = MT2063_ERROR;
  652. }
  653. fe->ops.i2c_gate_ctrl(fe, 0); //I2C bypass drxk3926 close i2c bridge
  654. return (status);
  655. }
  656. /*****************************************************************************
  657. **
  658. ** Name: MT_ReadSub
  659. **
  660. ** Description: Read values from device using a two-wire serial bus.
  661. **
  662. ** Parameters: hUserData - User-specific I/O parameter that was
  663. ** passed to tuner's Open function.
  664. ** addr - device serial bus address (value passed
  665. ** as parameter to MTxxxx_Open)
  666. ** subAddress - serial bus sub-address (Register Address)
  667. ** pData - pointer to the Data to be written to the
  668. ** device
  669. ** cnt - number of bytes/registers to be written
  670. **
  671. ** Returns: status:
  672. ** MT_OK - No errors
  673. ** MT_COMM_ERR - Serial bus communications error
  674. ** user-defined
  675. **
  676. ** Notes: This is a callback function that is called from the
  677. ** the tuning algorithm. You MUST provide code for this
  678. ** function to read data using the tuner's 2-wire serial
  679. ** bus.
  680. **
  681. ** The hUserData parameter is a user-specific argument.
  682. ** If additional arguments are needed for the user's
  683. ** serial bus read/write functions, this argument can be
  684. ** used to supply the necessary information.
  685. ** The hUserData parameter is initialized in the tuner's Open
  686. ** function.
  687. **
  688. ** Revision History:
  689. **
  690. ** SCR Date Author Description
  691. ** -------------------------------------------------------------------------
  692. ** N/A 03-25-2004 DAD Original
  693. **
  694. *****************************************************************************/
  695. static u32 MT2063_ReadSub(void *hUserData,
  696. u32 addr,
  697. u8 subAddress, u8 * pData, u32 cnt)
  698. {
  699. /*
  700. ** ToDo: Add code here to implement a serial-bus read
  701. ** operation to the MTxxxx tuner. If successful,
  702. ** return MT_OK.
  703. */
  704. /* return status; */
  705. u32 status = MT2063_OK; /* Status to be returned */
  706. struct dvb_frontend *fe = hUserData;
  707. struct mt2063_state *state = fe->tuner_priv;
  708. u32 i = 0;
  709. fe->ops.i2c_gate_ctrl(fe, 1); //I2C bypass drxk3926 close i2c bridge
  710. for (i = 0; i < cnt; i++) {
  711. if (mt2063_read_regs(state, subAddress + i, pData + i, 1) < 0) {
  712. status = MT2063_ERROR;
  713. break;
  714. }
  715. }
  716. fe->ops.i2c_gate_ctrl(fe, 0); //I2C bypass drxk3926 close i2c bridge
  717. return (status);
  718. }
  719. /*****************************************************************************
  720. **
  721. ** Name: MT_Sleep
  722. **
  723. ** Description: Delay execution for "nMinDelayTime" milliseconds
  724. **
  725. ** Parameters: hUserData - User-specific I/O parameter that was
  726. ** passed to tuner's Open function.
  727. ** nMinDelayTime - Delay time in milliseconds
  728. **
  729. ** Returns: None.
  730. **
  731. ** Notes: This is a callback function that is called from the
  732. ** the tuning algorithm. You MUST provide code that
  733. ** blocks execution for the specified period of time.
  734. **
  735. ** Revision History:
  736. **
  737. ** SCR Date Author Description
  738. ** -------------------------------------------------------------------------
  739. ** N/A 03-25-2004 DAD Original
  740. **
  741. *****************************************************************************/
  742. static int MT2063_Sleep(struct dvb_frontend *fe)
  743. {
  744. /*
  745. ** ToDo: Add code here to implement a OS blocking
  746. ** for a period of "nMinDelayTime" milliseconds.
  747. */
  748. msleep(10);
  749. return 0;
  750. }
  751. //end of mt2063_userdef.c
  752. //=================================================================
  753. //#################################################################
  754. //=================================================================
  755. //context of mt2063_spuravoid.c <Henry> ======================================
  756. //#################################################################
  757. //=================================================================
  758. /*****************************************************************************
  759. **
  760. ** Name: mt_spuravoid.c
  761. **
  762. ** Description: Microtune spur avoidance software module.
  763. ** Supports Microtune tuner drivers.
  764. **
  765. ** CVS ID: $Id: mt_spuravoid.c,v 1.3 2008/06/26 15:39:52 software Exp $
  766. ** CVS Source: $Source: /export/home/cvsroot/software/tuners/MT2063/mt_spuravoid.c,v $
  767. **
  768. ** Revision History:
  769. **
  770. ** SCR Date Author Description
  771. ** -------------------------------------------------------------------------
  772. ** 082 03-25-2005 JWS Original multi-tuner support - requires
  773. ** MTxxxx_CNT declarations
  774. ** 096 04-06-2005 DAD Ver 1.11: Fix divide by 0 error if maxH==0.
  775. ** 094 04-06-2005 JWS Ver 1.11 Added uceil and ufloor to get rid
  776. ** of compiler warnings
  777. ** N/A 04-07-2005 DAD Ver 1.13: Merged single- and multi-tuner spur
  778. ** avoidance into a single module.
  779. ** 103 01-31-2005 DAD Ver 1.14: In MT_AddExclZone(), if the range
  780. ** (f_min, f_max) < 0, ignore the entry.
  781. ** 115 03-23-2007 DAD Fix declaration of spur due to truncation
  782. ** errors.
  783. ** 117 03-29-2007 RSK Ver 1.15: Re-wrote to match search order from
  784. ** tuner DLL.
  785. ** 137 06-18-2007 DAD Ver 1.16: Fix possible divide-by-0 error for
  786. ** multi-tuners that have
  787. ** (delta IF1) > (f_out-f_outbw/2).
  788. ** 147 07-27-2007 RSK Ver 1.17: Corrected calculation (-) to (+)
  789. ** Added logic to force f_Center within 1/2 f_Step.
  790. ** 177 S 02-26-2008 RSK Ver 1.18: Corrected calculation using LO1 > MAX/2
  791. ** Type casts added to preserve correct sign.
  792. ** N/A I 06-17-2008 RSK Ver 1.19: Refactoring avoidance of DECT
  793. ** frequencies into MT_ResetExclZones().
  794. ** N/A I 06-20-2008 RSK Ver 1.21: New VERSION number for ver checking.
  795. **
  796. *****************************************************************************/
  797. /* Version of this module */
  798. #define MT2063_SPUR_VERSION 10201 /* Version 01.21 */
  799. /* Implement ceiling, floor functions. */
  800. #define ceil(n, d) (((n) < 0) ? (-((-(n))/(d))) : (n)/(d) + ((n)%(d) != 0))
  801. #define uceil(n, d) ((n)/(d) + ((n)%(d) != 0))
  802. #define floor(n, d) (((n) < 0) ? (-((-(n))/(d))) - ((n)%(d) != 0) : (n)/(d))
  803. #define ufloor(n, d) ((n)/(d))
  804. struct MT2063_FIFZone_t {
  805. s32 min_;
  806. s32 max_;
  807. };
  808. #if MT2063_TUNER_CNT > 1
  809. static struct MT2063_AvoidSpursData_t *TunerList[MT2063_TUNER_CNT];
  810. static u32 TunerCount = 0;
  811. #endif
  812. static u32 MT2063_RegisterTuner(struct MT2063_AvoidSpursData_t *pAS_Info)
  813. {
  814. #if MT2063_TUNER_CNT == 1
  815. pAS_Info->nAS_Algorithm = 1;
  816. return MT2063_OK;
  817. #else
  818. u32 index;
  819. pAS_Info->nAS_Algorithm = 2;
  820. /*
  821. ** Check to see if tuner is already registered
  822. */
  823. for (index = 0; index < TunerCount; index++) {
  824. if (TunerList[index] == pAS_Info) {
  825. return MT2063_OK; /* Already here - no problem */
  826. }
  827. }
  828. /*
  829. ** Add tuner to list - if there is room.
  830. */
  831. if (TunerCount < MT2063_TUNER_CNT) {
  832. TunerList[TunerCount] = pAS_Info;
  833. TunerCount++;
  834. return MT2063_OK;
  835. } else
  836. return MT2063_TUNER_CNT_ERR;
  837. #endif
  838. }
  839. static void MT2063_UnRegisterTuner(struct MT2063_AvoidSpursData_t *pAS_Info)
  840. {
  841. #if MT2063_TUNER_CNT > 1
  842. u32 index;
  843. for (index = 0; index < TunerCount; index++) {
  844. if (TunerList[index] == pAS_Info) {
  845. TunerList[index] = TunerList[--TunerCount];
  846. }
  847. }
  848. #endif
  849. }
  850. /*
  851. ** Reset all exclusion zones.
  852. ** Add zones to protect the PLL FracN regions near zero
  853. **
  854. ** N/A I 06-17-2008 RSK Ver 1.19: Refactoring avoidance of DECT
  855. ** frequencies into MT_ResetExclZones().
  856. */
  857. static void MT2063_ResetExclZones(struct MT2063_AvoidSpursData_t *pAS_Info)
  858. {
  859. u32 center;
  860. #if MT2063_TUNER_CNT > 1
  861. u32 index;
  862. struct MT2063_AvoidSpursData_t *adj;
  863. #endif
  864. pAS_Info->nZones = 0; /* this clears the used list */
  865. pAS_Info->usedZones = NULL; /* reset ptr */
  866. pAS_Info->freeZones = NULL; /* reset ptr */
  867. center =
  868. pAS_Info->f_ref *
  869. ((pAS_Info->f_if1_Center - pAS_Info->f_if1_bw / 2 +
  870. pAS_Info->f_in) / pAS_Info->f_ref) - pAS_Info->f_in;
  871. while (center <
  872. pAS_Info->f_if1_Center + pAS_Info->f_if1_bw / 2 +
  873. pAS_Info->f_LO1_FracN_Avoid) {
  874. /* Exclude LO1 FracN */
  875. MT2063_AddExclZone(pAS_Info,
  876. center - pAS_Info->f_LO1_FracN_Avoid,
  877. center - 1);
  878. MT2063_AddExclZone(pAS_Info, center + 1,
  879. center + pAS_Info->f_LO1_FracN_Avoid);
  880. center += pAS_Info->f_ref;
  881. }
  882. center =
  883. pAS_Info->f_ref *
  884. ((pAS_Info->f_if1_Center - pAS_Info->f_if1_bw / 2 -
  885. pAS_Info->f_out) / pAS_Info->f_ref) + pAS_Info->f_out;
  886. while (center <
  887. pAS_Info->f_if1_Center + pAS_Info->f_if1_bw / 2 +
  888. pAS_Info->f_LO2_FracN_Avoid) {
  889. /* Exclude LO2 FracN */
  890. MT2063_AddExclZone(pAS_Info,
  891. center - pAS_Info->f_LO2_FracN_Avoid,
  892. center - 1);
  893. MT2063_AddExclZone(pAS_Info, center + 1,
  894. center + pAS_Info->f_LO2_FracN_Avoid);
  895. center += pAS_Info->f_ref;
  896. }
  897. if (MT2063_EXCLUDE_US_DECT_FREQUENCIES(pAS_Info->avoidDECT)) {
  898. /* Exclude LO1 values that conflict with DECT channels */
  899. MT2063_AddExclZone(pAS_Info, 1920836000 - pAS_Info->f_in, 1922236000 - pAS_Info->f_in); /* Ctr = 1921.536 */
  900. MT2063_AddExclZone(pAS_Info, 1922564000 - pAS_Info->f_in, 1923964000 - pAS_Info->f_in); /* Ctr = 1923.264 */
  901. MT2063_AddExclZone(pAS_Info, 1924292000 - pAS_Info->f_in, 1925692000 - pAS_Info->f_in); /* Ctr = 1924.992 */
  902. MT2063_AddExclZone(pAS_Info, 1926020000 - pAS_Info->f_in, 1927420000 - pAS_Info->f_in); /* Ctr = 1926.720 */
  903. MT2063_AddExclZone(pAS_Info, 1927748000 - pAS_Info->f_in, 1929148000 - pAS_Info->f_in); /* Ctr = 1928.448 */
  904. }
  905. if (MT2063_EXCLUDE_EURO_DECT_FREQUENCIES(pAS_Info->avoidDECT)) {
  906. MT2063_AddExclZone(pAS_Info, 1896644000 - pAS_Info->f_in, 1898044000 - pAS_Info->f_in); /* Ctr = 1897.344 */
  907. MT2063_AddExclZone(pAS_Info, 1894916000 - pAS_Info->f_in, 1896316000 - pAS_Info->f_in); /* Ctr = 1895.616 */
  908. MT2063_AddExclZone(pAS_Info, 1893188000 - pAS_Info->f_in, 1894588000 - pAS_Info->f_in); /* Ctr = 1893.888 */
  909. MT2063_AddExclZone(pAS_Info, 1891460000 - pAS_Info->f_in, 1892860000 - pAS_Info->f_in); /* Ctr = 1892.16 */
  910. MT2063_AddExclZone(pAS_Info, 1889732000 - pAS_Info->f_in, 1891132000 - pAS_Info->f_in); /* Ctr = 1890.432 */
  911. MT2063_AddExclZone(pAS_Info, 1888004000 - pAS_Info->f_in, 1889404000 - pAS_Info->f_in); /* Ctr = 1888.704 */
  912. MT2063_AddExclZone(pAS_Info, 1886276000 - pAS_Info->f_in, 1887676000 - pAS_Info->f_in); /* Ctr = 1886.976 */
  913. MT2063_AddExclZone(pAS_Info, 1884548000 - pAS_Info->f_in, 1885948000 - pAS_Info->f_in); /* Ctr = 1885.248 */
  914. MT2063_AddExclZone(pAS_Info, 1882820000 - pAS_Info->f_in, 1884220000 - pAS_Info->f_in); /* Ctr = 1883.52 */
  915. MT2063_AddExclZone(pAS_Info, 1881092000 - pAS_Info->f_in, 1882492000 - pAS_Info->f_in); /* Ctr = 1881.792 */
  916. }
  917. #if MT2063_TUNER_CNT > 1
  918. /*
  919. ** Iterate through all adjacent tuners and exclude frequencies related to them
  920. */
  921. for (index = 0; index < TunerCount; ++index) {
  922. adj = TunerList[index];
  923. if (pAS_Info == adj) /* skip over our own data, don't process it */
  924. continue;
  925. /*
  926. ** Add 1st IF exclusion zone covering adjacent tuner's LO2
  927. ** at "adjfLO2 + f_out" +/- m_MinLOSpacing
  928. */
  929. if (adj->f_LO2 != 0)
  930. MT2063_AddExclZone(pAS_Info,
  931. (adj->f_LO2 + pAS_Info->f_out) -
  932. pAS_Info->f_min_LO_Separation,
  933. (adj->f_LO2 + pAS_Info->f_out) +
  934. pAS_Info->f_min_LO_Separation);
  935. /*
  936. ** Add 1st IF exclusion zone covering adjacent tuner's LO1
  937. ** at "adjfLO1 - f_in" +/- m_MinLOSpacing
  938. */
  939. if (adj->f_LO1 != 0)
  940. MT2063_AddExclZone(pAS_Info,
  941. (adj->f_LO1 - pAS_Info->f_in) -
  942. pAS_Info->f_min_LO_Separation,
  943. (adj->f_LO1 - pAS_Info->f_in) +
  944. pAS_Info->f_min_LO_Separation);
  945. }
  946. #endif
  947. }
  948. static struct MT2063_ExclZone_t *InsertNode(struct MT2063_AvoidSpursData_t
  949. *pAS_Info,
  950. struct MT2063_ExclZone_t *pPrevNode)
  951. {
  952. struct MT2063_ExclZone_t *pNode;
  953. /* Check for a node in the free list */
  954. if (pAS_Info->freeZones != NULL) {
  955. /* Use one from the free list */
  956. pNode = pAS_Info->freeZones;
  957. pAS_Info->freeZones = pNode->next_;
  958. } else {
  959. /* Grab a node from the array */
  960. pNode = &pAS_Info->MT2063_ExclZones[pAS_Info->nZones];
  961. }
  962. if (pPrevNode != NULL) {
  963. pNode->next_ = pPrevNode->next_;
  964. pPrevNode->next_ = pNode;
  965. } else { /* insert at the beginning of the list */
  966. pNode->next_ = pAS_Info->usedZones;
  967. pAS_Info->usedZones = pNode;
  968. }
  969. pAS_Info->nZones++;
  970. return pNode;
  971. }
  972. static struct MT2063_ExclZone_t *RemoveNode(struct MT2063_AvoidSpursData_t
  973. *pAS_Info,
  974. struct MT2063_ExclZone_t *pPrevNode,
  975. struct MT2063_ExclZone_t
  976. *pNodeToRemove)
  977. {
  978. struct MT2063_ExclZone_t *pNext = pNodeToRemove->next_;
  979. /* Make previous node point to the subsequent node */
  980. if (pPrevNode != NULL)
  981. pPrevNode->next_ = pNext;
  982. /* Add pNodeToRemove to the beginning of the freeZones */
  983. pNodeToRemove->next_ = pAS_Info->freeZones;
  984. pAS_Info->freeZones = pNodeToRemove;
  985. /* Decrement node count */
  986. pAS_Info->nZones--;
  987. return pNext;
  988. }
  989. /*****************************************************************************
  990. **
  991. ** Name: MT_AddExclZone
  992. **
  993. ** Description: Add (and merge) an exclusion zone into the list.
  994. ** If the range (f_min, f_max) is totally outside the
  995. ** 1st IF BW, ignore the entry.
  996. ** If the range (f_min, f_max) is negative, ignore the entry.
  997. **
  998. ** Revision History:
  999. **
  1000. ** SCR Date Author Description
  1001. ** -------------------------------------------------------------------------
  1002. ** 103 01-31-2005 DAD Ver 1.14: In MT_AddExclZone(), if the range
  1003. ** (f_min, f_max) < 0, ignore the entry.
  1004. **
  1005. *****************************************************************************/
  1006. static void MT2063_AddExclZone(struct MT2063_AvoidSpursData_t *pAS_Info,
  1007. u32 f_min, u32 f_max)
  1008. {
  1009. struct MT2063_ExclZone_t *pNode = pAS_Info->usedZones;
  1010. struct MT2063_ExclZone_t *pPrev = NULL;
  1011. struct MT2063_ExclZone_t *pNext = NULL;
  1012. /* Check to see if this overlaps the 1st IF filter */
  1013. if ((f_max > (pAS_Info->f_if1_Center - (pAS_Info->f_if1_bw / 2)))
  1014. && (f_min < (pAS_Info->f_if1_Center + (pAS_Info->f_if1_bw / 2)))
  1015. && (f_min < f_max)) {
  1016. /*
  1017. ** 1 2 3 4 5 6
  1018. **
  1019. ** New entry: |---| |--| |--| |-| |---| |--|
  1020. ** or or or or or
  1021. ** Existing: |--| |--| |--| |---| |-| |--|
  1022. */
  1023. /* Check for our place in the list */
  1024. while ((pNode != NULL) && (pNode->max_ < f_min)) {
  1025. pPrev = pNode;
  1026. pNode = pNode->next_;
  1027. }
  1028. if ((pNode != NULL) && (pNode->min_ < f_max)) {
  1029. /* Combine me with pNode */
  1030. if (f_min < pNode->min_)
  1031. pNode->min_ = f_min;
  1032. if (f_max > pNode->max_)
  1033. pNode->max_ = f_max;
  1034. } else {
  1035. pNode = InsertNode(pAS_Info, pPrev);
  1036. pNode->min_ = f_min;
  1037. pNode->max_ = f_max;
  1038. }
  1039. /* Look for merging possibilities */
  1040. pNext = pNode->next_;
  1041. while ((pNext != NULL) && (pNext->min_ < pNode->max_)) {
  1042. if (pNext->max_ > pNode->max_)
  1043. pNode->max_ = pNext->max_;
  1044. pNext = RemoveNode(pAS_Info, pNode, pNext); /* Remove pNext, return ptr to pNext->next */
  1045. }
  1046. }
  1047. }
  1048. /*****************************************************************************
  1049. **
  1050. ** Name: MT_ChooseFirstIF
  1051. **
  1052. ** Description: Choose the best available 1st IF
  1053. ** If f_Desired is not excluded, choose that first.
  1054. ** Otherwise, return the value closest to f_Center that is
  1055. ** not excluded
  1056. **
  1057. ** Revision History:
  1058. **
  1059. ** SCR Date Author Description
  1060. ** -------------------------------------------------------------------------
  1061. ** 117 03-29-2007 RSK Ver 1.15: Re-wrote to match search order from
  1062. ** tuner DLL.
  1063. ** 147 07-27-2007 RSK Ver 1.17: Corrected calculation (-) to (+)
  1064. ** Added logic to force f_Center within 1/2 f_Step.
  1065. **
  1066. *****************************************************************************/
  1067. static u32 MT2063_ChooseFirstIF(struct MT2063_AvoidSpursData_t *pAS_Info)
  1068. {
  1069. /*
  1070. ** Update "f_Desired" to be the nearest "combinational-multiple" of "f_LO1_Step".
  1071. ** The resulting number, F_LO1 must be a multiple of f_LO1_Step. And F_LO1 is the arithmetic sum
  1072. ** of f_in + f_Center. Neither f_in, nor f_Center must be a multiple of f_LO1_Step.
  1073. ** However, the sum must be.
  1074. */
  1075. const u32 f_Desired =
  1076. pAS_Info->f_LO1_Step *
  1077. ((pAS_Info->f_if1_Request + pAS_Info->f_in +
  1078. pAS_Info->f_LO1_Step / 2) / pAS_Info->f_LO1_Step) -
  1079. pAS_Info->f_in;
  1080. const u32 f_Step =
  1081. (pAS_Info->f_LO1_Step >
  1082. pAS_Info->f_LO2_Step) ? pAS_Info->f_LO1_Step : pAS_Info->
  1083. f_LO2_Step;
  1084. u32 f_Center;
  1085. s32 i;
  1086. s32 j = 0;
  1087. u32 bDesiredExcluded = 0;
  1088. u32 bZeroExcluded = 0;
  1089. s32 tmpMin, tmpMax;
  1090. s32 bestDiff;
  1091. struct MT2063_ExclZone_t *pNode = pAS_Info->usedZones;
  1092. struct MT2063_FIFZone_t zones[MT2063_MAX_ZONES];
  1093. if (pAS_Info->nZones == 0)
  1094. return f_Desired;
  1095. /* f_Center needs to be an integer multiple of f_Step away from f_Desired */
  1096. if (pAS_Info->f_if1_Center > f_Desired)
  1097. f_Center =
  1098. f_Desired +
  1099. f_Step *
  1100. ((pAS_Info->f_if1_Center - f_Desired +
  1101. f_Step / 2) / f_Step);
  1102. else
  1103. f_Center =
  1104. f_Desired -
  1105. f_Step *
  1106. ((f_Desired - pAS_Info->f_if1_Center +
  1107. f_Step / 2) / f_Step);
  1108. //assert;
  1109. //if (!abs((s32) f_Center - (s32) pAS_Info->f_if1_Center) <= (s32) (f_Step/2))
  1110. // return 0;
  1111. /* Take MT_ExclZones, center around f_Center and change the resolution to f_Step */
  1112. while (pNode != NULL) {
  1113. /* floor function */
  1114. tmpMin =
  1115. floor((s32) (pNode->min_ - f_Center), (s32) f_Step);
  1116. /* ceil function */
  1117. tmpMax =
  1118. ceil((s32) (pNode->max_ - f_Center), (s32) f_Step);
  1119. if ((pNode->min_ < f_Desired) && (pNode->max_ > f_Desired))
  1120. bDesiredExcluded = 1;
  1121. if ((tmpMin < 0) && (tmpMax > 0))
  1122. bZeroExcluded = 1;
  1123. /* See if this zone overlaps the previous */
  1124. if ((j > 0) && (tmpMin < zones[j - 1].max_))
  1125. zones[j - 1].max_ = tmpMax;
  1126. else {
  1127. /* Add new zone */
  1128. //assert(j<MT2063_MAX_ZONES);
  1129. //if (j>=MT2063_MAX_ZONES)
  1130. //break;
  1131. zones[j].min_ = tmpMin;
  1132. zones[j].max_ = tmpMax;
  1133. j++;
  1134. }
  1135. pNode = pNode->next_;
  1136. }
  1137. /*
  1138. ** If the desired is okay, return with it
  1139. */
  1140. if (bDesiredExcluded == 0)
  1141. return f_Desired;
  1142. /*
  1143. ** If the desired is excluded and the center is okay, return with it
  1144. */
  1145. if (bZeroExcluded == 0)
  1146. return f_Center;
  1147. /* Find the value closest to 0 (f_Center) */
  1148. bestDiff = zones[0].min_;
  1149. for (i = 0; i < j; i++) {
  1150. if (abs(zones[i].min_) < abs(bestDiff))
  1151. bestDiff = zones[i].min_;
  1152. if (abs(zones[i].max_) < abs(bestDiff))
  1153. bestDiff = zones[i].max_;
  1154. }
  1155. if (bestDiff < 0)
  1156. return f_Center - ((u32) (-bestDiff) * f_Step);
  1157. return f_Center + (bestDiff * f_Step);
  1158. }
  1159. /****************************************************************************
  1160. **
  1161. ** Name: gcd
  1162. **
  1163. ** Description: Uses Euclid's algorithm
  1164. **
  1165. ** Parameters: u, v - unsigned values whose GCD is desired.
  1166. **
  1167. ** Global: None
  1168. **
  1169. ** Returns: greatest common divisor of u and v, if either value
  1170. ** is 0, the other value is returned as the result.
  1171. **
  1172. ** Dependencies: None.
  1173. **
  1174. ** Revision History:
  1175. **
  1176. ** SCR Date Author Description
  1177. ** -------------------------------------------------------------------------
  1178. ** N/A 06-01-2004 JWS Original
  1179. ** N/A 08-03-2004 DAD Changed to Euclid's since it can handle
  1180. ** unsigned numbers.
  1181. **
  1182. ****************************************************************************/
  1183. static u32 MT2063_gcd(u32 u, u32 v)
  1184. {
  1185. u32 r;
  1186. while (v != 0) {
  1187. r = u % v;
  1188. u = v;
  1189. v = r;
  1190. }
  1191. return u;
  1192. }
  1193. /****************************************************************************
  1194. **
  1195. ** Name: umax
  1196. **
  1197. ** Description: Implements a simple maximum function for unsigned numbers.
  1198. ** Implemented as a function rather than a macro to avoid
  1199. ** multiple evaluation of the calling parameters.
  1200. **
  1201. ** Parameters: a, b - Values to be compared
  1202. **
  1203. ** Global: None
  1204. **
  1205. ** Returns: larger of the input values.
  1206. **
  1207. ** Dependencies: None.
  1208. **
  1209. ** Revision History:
  1210. **
  1211. ** SCR Date Author Description
  1212. ** -------------------------------------------------------------------------
  1213. ** N/A 06-02-2004 JWS Original
  1214. **
  1215. ****************************************************************************/
  1216. static u32 MT2063_umax(u32 a, u32 b)
  1217. {
  1218. return (a >= b) ? a : b;
  1219. }
  1220. #if MT2063_TUNER_CNT > 1
  1221. static s32 RoundAwayFromZero(s32 n, s32 d)
  1222. {
  1223. return (n < 0) ? floor(n, d) : ceil(n, d);
  1224. }
  1225. /****************************************************************************
  1226. **
  1227. ** Name: IsSpurInAdjTunerBand
  1228. **
  1229. ** Description: Checks to see if a spur will be present within the IF's
  1230. ** bandwidth or near the zero IF.
  1231. ** (fIFOut +/- fIFBW/2, -fIFOut +/- fIFBW/2)
  1232. ** and
  1233. ** (0 +/- fZIFBW/2)
  1234. **
  1235. ** ma mb me mf mc md
  1236. ** <--+-+-+-----------------+-+-+-----------------+-+-+-->
  1237. ** | ^ 0 ^ |
  1238. ** ^ b=-fIFOut+fIFBW/2 -b=+fIFOut-fIFBW/2 ^
  1239. ** a=-fIFOut-fIFBW/2 -a=+fIFOut+fIFBW/2
  1240. **
  1241. ** Note that some equations are doubled to prevent round-off
  1242. ** problems when calculating fIFBW/2
  1243. **
  1244. ** The spur frequencies are computed as:
  1245. **
  1246. ** fSpur = n * f1 - m * f2 - fOffset
  1247. **
  1248. ** Parameters: f1 - The 1st local oscillator (LO) frequency
  1249. ** of the tuner whose output we are examining
  1250. ** f2 - The 1st local oscillator (LO) frequency
  1251. ** of the adjacent tuner
  1252. ** fOffset - The 2nd local oscillator of the tuner whose
  1253. ** output we are examining
  1254. ** fIFOut - Output IF center frequency
  1255. ** fIFBW - Output IF Bandwidth
  1256. ** nMaxH - max # of LO harmonics to search
  1257. ** fp - If spur, positive distance to spur-free band edge (returned)
  1258. ** fm - If spur, negative distance to spur-free band edge (returned)
  1259. **
  1260. ** Returns: 1 if an LO spur would be present, otherwise 0.
  1261. **
  1262. ** Dependencies: None.
  1263. **
  1264. ** Revision History:
  1265. **
  1266. ** SCR Date Author Description
  1267. ** -------------------------------------------------------------------------
  1268. ** N/A 01-21-2005 JWS Original, adapted from MT_DoubleConversion.
  1269. ** 115 03-23-2007 DAD Fix declaration of spur due to truncation
  1270. ** errors.
  1271. ** 137 06-18-2007 DAD Ver 1.16: Fix possible divide-by-0 error for
  1272. ** multi-tuners that have
  1273. ** (delta IF1) > (f_out-f_outbw/2).
  1274. ** 177 S 02-26-2008 RSK Ver 1.18: Corrected calculation using LO1 > MAX/2
  1275. ** Type casts added to preserve correct sign.
  1276. **
  1277. ****************************************************************************/
  1278. static u32 IsSpurInAdjTunerBand(u32 bIsMyOutput,
  1279. u32 f1,
  1280. u32 f2,
  1281. u32 fOffset,
  1282. u32 fIFOut,
  1283. u32 fIFBW,
  1284. u32 fZIFBW,
  1285. u32 nMaxH, u32 * fp, u32 * fm)
  1286. {
  1287. u32 bSpurFound = 0;
  1288. const u32 fHalf_IFBW = fIFBW / 2;
  1289. const u32 fHalf_ZIFBW = fZIFBW / 2;
  1290. /* Calculate a scale factor for all frequencies, so that our
  1291. calculations all stay within 31 bits */
  1292. const u32 f_Scale =
  1293. ((f1 +
  1294. (fOffset + fIFOut +
  1295. fHalf_IFBW) / nMaxH) / (MAX_UDATA / 2 / nMaxH)) + 1;
  1296. /*
  1297. ** After this scaling, _f1, _f2, and _f3 are guaranteed to fit into
  1298. ** signed data types (smaller than MAX_UDATA/2)
  1299. */
  1300. const s32 _f1 = (s32) (f1 / f_Scale);
  1301. const s32 _f2 = (s32) (f2 / f_Scale);
  1302. const s32 _f3 = (s32) (fOffset / f_Scale);
  1303. const s32 c = (s32) (fIFOut - fHalf_IFBW) / (s32) f_Scale;
  1304. const s32 d = (s32) ((fIFOut + fHalf_IFBW) / f_Scale);
  1305. const s32 f = (s32) (fHalf_ZIFBW / f_Scale);
  1306. s32 ma, mb, mc, md, me, mf;
  1307. s32 fp_ = 0;
  1308. s32 fm_ = 0;
  1309. s32 n;
  1310. /*
  1311. ** If the other tuner does not have an LO frequency defined,
  1312. ** assume that we cannot interfere with it
  1313. */
  1314. if (f2 == 0)
  1315. return 0;
  1316. /* Check out all multiples of f1 from -nMaxH to +nMaxH */
  1317. for (n = -(s32) nMaxH; n <= (s32) nMaxH; ++n) {
  1318. const s32 nf1 = n * _f1;
  1319. md = (_f3 + d - nf1) / _f2;
  1320. /* If # f2 harmonics > nMaxH, then no spurs present */
  1321. if (md <= -(s32) nMaxH)
  1322. break;
  1323. ma = (_f3 - d - nf1) / _f2;
  1324. if ((ma == md) || (ma >= (s32) (nMaxH)))
  1325. continue;
  1326. mc = (_f3 + c - nf1) / _f2;
  1327. if (mc != md) {
  1328. const s32 m = (n < 0) ? md : mc;
  1329. const s32 fspur = (nf1 + m * _f2 - _f3);
  1330. const s32 den = (bIsMyOutput ? n - 1 : n);
  1331. if (den == 0) {
  1332. fp_ = (d - fspur) * f_Scale;
  1333. fm_ = (fspur - c) * f_Scale;
  1334. } else {
  1335. fp_ =
  1336. (s32) RoundAwayFromZero((d - fspur) *
  1337. f_Scale, den);
  1338. fm_ =
  1339. (s32) RoundAwayFromZero((fspur - c) *
  1340. f_Scale, den);
  1341. }
  1342. if (((u32) abs(fm_) >= f_Scale)
  1343. && ((u32) abs(fp_) >= f_Scale)) {
  1344. bSpurFound = 1;
  1345. break;
  1346. }
  1347. }
  1348. /* Location of Zero-IF-spur to be checked */
  1349. mf = (_f3 + f - nf1) / _f2;
  1350. me = (_f3 - f - nf1) / _f2;
  1351. if (me != mf) {
  1352. const s32 m = (n < 0) ? mf : me;
  1353. const s32 fspur = (nf1 + m * _f2 - _f3);
  1354. const s32 den = (bIsMyOutput ? n - 1 : n);
  1355. if (den == 0) {
  1356. fp_ = (d - fspur) * f_Scale;
  1357. fm_ = (fspur - c) * f_Scale;
  1358. } else {
  1359. fp_ =
  1360. (s32) RoundAwayFromZero((f - fspur) *
  1361. f_Scale, den);
  1362. fm_ =
  1363. (s32) RoundAwayFromZero((fspur + f) *
  1364. f_Scale, den);
  1365. }
  1366. if (((u32) abs(fm_) >= f_Scale)
  1367. && ((u32) abs(fp_) >= f_Scale)) {
  1368. bSpurFound = 1;
  1369. break;
  1370. }
  1371. }
  1372. mb = (_f3 - c - nf1) / _f2;
  1373. if (ma != mb) {
  1374. const s32 m = (n < 0) ? mb : ma;
  1375. const s32 fspur = (nf1 + m * _f2 - _f3);
  1376. const s32 den = (bIsMyOutput ? n - 1 : n);
  1377. if (den == 0) {
  1378. fp_ = (d - fspur) * f_Scale;
  1379. fm_ = (fspur - c) * f_Scale;
  1380. } else {
  1381. fp_ =
  1382. (s32) RoundAwayFromZero((-c - fspur) *
  1383. f_Scale, den);
  1384. fm_ =
  1385. (s32) RoundAwayFromZero((fspur + d) *
  1386. f_Scale, den);
  1387. }
  1388. if (((u32) abs(fm_) >= f_Scale)
  1389. && ((u32) abs(fp_) >= f_Scale)) {
  1390. bSpurFound = 1;
  1391. break;
  1392. }
  1393. }
  1394. }
  1395. /*
  1396. ** Verify that fm & fp are both positive
  1397. ** Add one to ensure next 1st IF choice is not right on the edge
  1398. */
  1399. if (fp_ < 0) {
  1400. *fp = -fm_ + 1;
  1401. *fm = -fp_ + 1;
  1402. } else if (fp_ > 0) {
  1403. *fp = fp_ + 1;
  1404. *fm = fm_ + 1;
  1405. } else {
  1406. *fp = 1;
  1407. *fm = abs(fm_) + 1;
  1408. }
  1409. return bSpurFound;
  1410. }
  1411. #endif
  1412. /****************************************************************************
  1413. **
  1414. ** Name: IsSpurInBand
  1415. **
  1416. ** Description: Checks to see if a spur will be present within the IF's
  1417. ** bandwidth. (fIFOut +/- fIFBW, -fIFOut +/- fIFBW)
  1418. **
  1419. ** ma mb mc md
  1420. ** <--+-+-+-------------------+-------------------+-+-+-->
  1421. ** | ^ 0 ^ |
  1422. ** ^ b=-fIFOut+fIFBW/2 -b=+fIFOut-fIFBW/2 ^
  1423. ** a=-fIFOut-fIFBW/2 -a=+fIFOut+fIFBW/2
  1424. **
  1425. ** Note that some equations are doubled to prevent round-off
  1426. ** problems when calculating fIFBW/2
  1427. **
  1428. ** Parameters: pAS_Info - Avoid Spurs information block
  1429. ** fm - If spur, amount f_IF1 has to move negative
  1430. ** fp - If spur, amount f_IF1 has to move positive
  1431. **
  1432. ** Global: None
  1433. **
  1434. ** Returns: 1 if an LO spur would be present, otherwise 0.
  1435. **
  1436. ** Dependencies: None.
  1437. **
  1438. ** Revision History:
  1439. **
  1440. ** SCR Date Author Description
  1441. ** -------------------------------------------------------------------------
  1442. ** N/A 11-28-2002 DAD Implemented algorithm from applied patent
  1443. **
  1444. ****************************************************************************/
  1445. static u32 IsSpurInBand(struct MT2063_AvoidSpursData_t *pAS_Info,
  1446. u32 * fm, u32 * fp)
  1447. {
  1448. /*
  1449. ** Calculate LO frequency settings.
  1450. */
  1451. u32 n, n0;
  1452. const u32 f_LO1 = pAS_Info->f_LO1;
  1453. const u32 f_LO2 = pAS_Info->f_LO2;
  1454. const u32 d = pAS_Info->f_out + pAS_Info->f_out_bw / 2;
  1455. const u32 c = d - pAS_Info->f_out_bw;
  1456. const u32 f = pAS_Info->f_zif_bw / 2;
  1457. const u32 f_Scale = (f_LO1 / (MAX_UDATA / 2 / pAS_Info->maxH1)) + 1;
  1458. s32 f_nsLO1, f_nsLO2;
  1459. s32 f_Spur;
  1460. u32 ma, mb, mc, md, me, mf;
  1461. u32 lo_gcd, gd_Scale, gc_Scale, gf_Scale, hgds, hgfs, hgcs;
  1462. #if MT2063_TUNER_CNT > 1
  1463. u32 index;
  1464. struct MT2063_AvoidSpursData_t *adj;
  1465. #endif
  1466. *fm = 0;
  1467. /*
  1468. ** For each edge (d, c & f), calculate a scale, based on the gcd
  1469. ** of f_LO1, f_LO2 and the edge value. Use the larger of this
  1470. ** gcd-based scale factor or f_Scale.
  1471. */
  1472. lo_gcd = MT2063_gcd(f_LO1, f_LO2);
  1473. gd_Scale = MT2063_umax((u32) MT2063_gcd(lo_gcd, d), f_Scale);
  1474. hgds = gd_Scale / 2;
  1475. gc_Scale = MT2063_umax((u32) MT2063_gcd(lo_gcd, c), f_Scale);
  1476. hgcs = gc_Scale / 2;
  1477. gf_Scale = MT2063_umax((u32) MT2063_gcd(lo_gcd, f), f_Scale);
  1478. hgfs = gf_Scale / 2;
  1479. n0 = uceil(f_LO2 - d, f_LO1 - f_LO2);
  1480. /* Check out all multiples of LO1 from n0 to m_maxLOSpurHarmonic */
  1481. for (n = n0; n <= pAS_Info->maxH1; ++n) {
  1482. md = (n * ((f_LO1 + hgds) / gd_Scale) -
  1483. ((d + hgds) / gd_Scale)) / ((f_LO2 + hgds) / gd_Scale);
  1484. /* If # fLO2 harmonics > m_maxLOSpurHarmonic, then no spurs present */
  1485. if (md >= pAS_Info->maxH1)
  1486. break;
  1487. ma = (n * ((f_LO1 + hgds) / gd_Scale) +
  1488. ((d + hgds) / gd_Scale)) / ((f_LO2 + hgds) / gd_Scale);
  1489. /* If no spurs between +/- (f_out + f_IFBW/2), then try next harmonic */
  1490. if (md == ma)
  1491. continue;
  1492. mc = (n * ((f_LO1 + hgcs) / gc_Scale) -
  1493. ((c + hgcs) / gc_Scale)) / ((f_LO2 + hgcs) / gc_Scale);
  1494. if (mc != md) {
  1495. f_nsLO1 = (s32) (n * (f_LO1 / gc_Scale));
  1496. f_nsLO2 = (s32) (mc * (f_LO2 / gc_Scale));
  1497. f_Spur =
  1498. (gc_Scale * (f_nsLO1 - f_nsLO2)) +
  1499. n * (f_LO1 % gc_Scale) - mc * (f_LO2 % gc_Scale);
  1500. *fp = ((f_Spur - (s32) c) / (mc - n)) + 1;
  1501. *fm = (((s32) d - f_Spur) / (mc - n)) + 1;
  1502. return 1;
  1503. }
  1504. /* Location of Zero-IF-spur to be checked */
  1505. me = (n * ((f_LO1 + hgfs) / gf_Scale) +
  1506. ((f + hgfs) / gf_Scale)) / ((f_LO2 + hgfs) / gf_Scale);
  1507. mf = (n * ((f_LO1 + hgfs) / gf_Scale) -
  1508. ((f + hgfs) / gf_Scale)) / ((f_LO2 + hgfs) / gf_Scale);
  1509. if (me != mf) {
  1510. f_nsLO1 = n * (f_LO1 / gf_Scale);
  1511. f_nsLO2 = me * (f_LO2 / gf_Scale);
  1512. f_Spur =
  1513. (gf_Scale * (f_nsLO1 - f_nsLO2)) +
  1514. n * (f_LO1 % gf_Scale) - me * (f_LO2 % gf_Scale);
  1515. *fp = ((f_Spur + (s32) f) / (me - n)) + 1;
  1516. *fm = (((s32) f - f_Spur) / (me - n)) + 1;
  1517. return 1;
  1518. }
  1519. mb = (n * ((f_LO1 + hgcs) / gc_Scale) +
  1520. ((c + hgcs) / gc_Scale)) / ((f_LO2 + hgcs) / gc_Scale);
  1521. if (ma != mb) {
  1522. f_nsLO1 = n * (f_LO1 / gc_Scale);
  1523. f_nsLO2 = ma * (f_LO2 / gc_Scale);
  1524. f_Spur =
  1525. (gc_Scale * (f_nsLO1 - f_nsLO2)) +
  1526. n * (f_LO1 % gc_Scale) - ma * (f_LO2 % gc_Scale);
  1527. *fp = (((s32) d + f_Spur) / (ma - n)) + 1;
  1528. *fm = (-(f_Spur + (s32) c) / (ma - n)) + 1;
  1529. return 1;
  1530. }
  1531. }
  1532. #if MT2063_TUNER_CNT > 1
  1533. /* If no spur found, see if there are more tuners on the same board */
  1534. for (index = 0; index < TunerCount; ++index) {
  1535. adj = TunerList[index];
  1536. if (pAS_Info == adj) /* skip over our own data, don't process it */
  1537. continue;
  1538. /* Look for LO-related spurs from the adjacent tuner generated into my IF output */
  1539. if (IsSpurInAdjTunerBand(1, /* check my IF output */
  1540. pAS_Info->f_LO1, /* my fLO1 */
  1541. adj->f_LO1, /* the other tuner's fLO1 */
  1542. pAS_Info->f_LO2, /* my fLO2 */
  1543. pAS_Info->f_out, /* my fOut */
  1544. pAS_Info->f_out_bw, /* my output IF bandwidth */
  1545. pAS_Info->f_zif_bw, /* my Zero-IF bandwidth */
  1546. pAS_Info->maxH2, fp, /* minimum amount to move LO's positive */
  1547. fm)) /* miminum amount to move LO's negative */
  1548. return 1;
  1549. /* Look for LO-related spurs from my tuner generated into the adjacent tuner's IF output */
  1550. if (IsSpurInAdjTunerBand(0, /* check his IF output */
  1551. pAS_Info->f_LO1, /* my fLO1 */
  1552. adj->f_LO1, /* the other tuner's fLO1 */
  1553. adj->f_LO2, /* the other tuner's fLO2 */
  1554. adj->f_out, /* the other tuner's fOut */
  1555. adj->f_out_bw, /* the other tuner's output IF bandwidth */
  1556. pAS_Info->f_zif_bw, /* the other tuner's Zero-IF bandwidth */
  1557. adj->maxH2, fp, /* minimum amount to move LO's positive */
  1558. fm)) /* miminum amount to move LO's negative */
  1559. return 1;
  1560. }
  1561. #endif
  1562. /* No spurs found */
  1563. return 0;
  1564. }
  1565. /*****************************************************************************
  1566. **
  1567. ** Name: MT_AvoidSpurs
  1568. **
  1569. ** Description: Main entry point to avoid spurs.
  1570. ** Checks for existing spurs in present LO1, LO2 freqs
  1571. ** and if present, chooses spur-free LO1, LO2 combination
  1572. ** that tunes the same input/output frequencies.
  1573. **
  1574. ** Revision History:
  1575. **
  1576. ** SCR Date Author Description
  1577. ** -------------------------------------------------------------------------
  1578. ** 096 04-06-2005 DAD Ver 1.11: Fix divide by 0 error if maxH==0.
  1579. **
  1580. *****************************************************************************/
  1581. static u32 MT2063_AvoidSpurs(void *h, struct MT2063_AvoidSpursData_t * pAS_Info)
  1582. {
  1583. u32 status = MT2063_OK;
  1584. u32 fm, fp; /* restricted range on LO's */
  1585. pAS_Info->bSpurAvoided = 0;
  1586. pAS_Info->nSpursFound = 0;
  1587. if (pAS_Info->maxH1 == 0)
  1588. return MT2063_OK;
  1589. /*
  1590. ** Avoid LO Generated Spurs
  1591. **
  1592. ** Make sure that have no LO-related spurs within the IF output
  1593. ** bandwidth.
  1594. **
  1595. ** If there is an LO spur in this band, start at the current IF1 frequency
  1596. ** and work out until we find a spur-free frequency or run up against the
  1597. ** 1st IF SAW band edge. Use temporary copies of fLO1 and fLO2 so that they
  1598. ** will be unchanged if a spur-free setting is not found.
  1599. */
  1600. pAS_Info->bSpurPresent = IsSpurInBand(pAS_Info, &fm, &fp);
  1601. if (pAS_Info->bSpurPresent) {
  1602. u32 zfIF1 = pAS_Info->f_LO1 - pAS_Info->f_in; /* current attempt at a 1st IF */
  1603. u32 zfLO1 = pAS_Info->f_LO1; /* current attempt at an LO1 freq */
  1604. u32 zfLO2 = pAS_Info->f_LO2; /* current attempt at an LO2 freq */
  1605. u32 delta_IF1;
  1606. u32 new_IF1;
  1607. /*
  1608. ** Spur was found, attempt to find a spur-free 1st IF
  1609. */
  1610. do {
  1611. pAS_Info->nSpursFound++;
  1612. /* Raise f_IF1_upper, if needed */
  1613. MT2063_AddExclZone(pAS_Info, zfIF1 - fm, zfIF1 + fp);
  1614. /* Choose next IF1 that is closest to f_IF1_CENTER */
  1615. new_IF1 = MT2063_ChooseFirstIF(pAS_Info);
  1616. if (new_IF1 > zfIF1) {
  1617. pAS_Info->f_LO1 += (new_IF1 - zfIF1);
  1618. pAS_Info->f_LO2 += (new_IF1 - zfIF1);
  1619. } else {
  1620. pAS_Info->f_LO1 -= (zfIF1 - new_IF1);
  1621. pAS_Info->f_LO2 -= (zfIF1 - new_IF1);
  1622. }
  1623. zfIF1 = new_IF1;
  1624. if (zfIF1 > pAS_Info->f_if1_Center)
  1625. delta_IF1 = zfIF1 - pAS_Info->f_if1_Center;
  1626. else
  1627. delta_IF1 = pAS_Info->f_if1_Center - zfIF1;
  1628. }
  1629. /*
  1630. ** Continue while the new 1st IF is still within the 1st IF bandwidth
  1631. ** and there is a spur in the band (again)
  1632. */
  1633. while ((2 * delta_IF1 + pAS_Info->f_out_bw <=
  1634. pAS_Info->f_if1_bw)
  1635. && (pAS_Info->bSpurPresent =
  1636. IsSpurInBand(pAS_Info, &fm, &fp)));
  1637. /*
  1638. ** Use the LO-spur free values found. If the search went all the way to
  1639. ** the 1st IF band edge and always found spurs, just leave the original
  1640. ** choice. It's as "good" as any other.
  1641. */
  1642. if (pAS_Info->bSpurPresent == 1) {
  1643. status |= MT2063_SPUR_PRESENT_ERR;
  1644. pAS_Info->f_LO1 = zfLO1;
  1645. pAS_Info->f_LO2 = zfLO2;
  1646. } else
  1647. pAS_Info->bSpurAvoided = 1;
  1648. }
  1649. status |=
  1650. ((pAS_Info->
  1651. nSpursFound << MT2063_SPUR_SHIFT) & MT2063_SPUR_CNT_MASK);
  1652. return (status);
  1653. }
  1654. //end of mt2063_spuravoid.c
  1655. //=================================================================
  1656. //#################################################################
  1657. //=================================================================
  1658. /*
  1659. ** The expected version of MT_AvoidSpursData_t
  1660. ** If the version is different, an updated file is needed from Microtune
  1661. */
  1662. /* Expecting version 1.21 of the Spur Avoidance API */
  1663. typedef enum {
  1664. MT2063_SET_ATTEN,
  1665. MT2063_INCR_ATTEN,
  1666. MT2063_DECR_ATTEN
  1667. } MT2063_ATTEN_CNTL_MODE;
  1668. //#define TUNER_MT2063_OPTIMIZATION
  1669. /*
  1670. ** Constants used by the tuning algorithm
  1671. */
  1672. #define MT2063_REF_FREQ (16000000UL) /* Reference oscillator Frequency (in Hz) */
  1673. #define MT2063_IF1_BW (22000000UL) /* The IF1 filter bandwidth (in Hz) */
  1674. #define MT2063_TUNE_STEP_SIZE (50000UL) /* Tune in steps of 50 kHz */
  1675. #define MT2063_SPUR_STEP_HZ (250000UL) /* Step size (in Hz) to move IF1 when avoiding spurs */
  1676. #define MT2063_ZIF_BW (2000000UL) /* Zero-IF spur-free bandwidth (in Hz) */
  1677. #define MT2063_MAX_HARMONICS_1 (15UL) /* Highest intra-tuner LO Spur Harmonic to be avoided */
  1678. #define MT2063_MAX_HARMONICS_2 (5UL) /* Highest inter-tuner LO Spur Harmonic to be avoided */
  1679. #define MT2063_MIN_LO_SEP (1000000UL) /* Minimum inter-tuner LO frequency separation */
  1680. #define MT2063_LO1_FRACN_AVOID (0UL) /* LO1 FracN numerator avoid region (in Hz) */
  1681. #define MT2063_LO2_FRACN_AVOID (199999UL) /* LO2 FracN numerator avoid region (in Hz) */
  1682. #define MT2063_MIN_FIN_FREQ (44000000UL) /* Minimum input frequency (in Hz) */
  1683. #define MT2063_MAX_FIN_FREQ (1100000000UL) /* Maximum input frequency (in Hz) */
  1684. #define MT2063_MIN_FOUT_FREQ (36000000UL) /* Minimum output frequency (in Hz) */
  1685. #define MT2063_MAX_FOUT_FREQ (57000000UL) /* Maximum output frequency (in Hz) */
  1686. #define MT2063_MIN_DNC_FREQ (1293000000UL) /* Minimum LO2 frequency (in Hz) */
  1687. #define MT2063_MAX_DNC_FREQ (1614000000UL) /* Maximum LO2 frequency (in Hz) */
  1688. #define MT2063_MIN_UPC_FREQ (1396000000UL) /* Minimum LO1 frequency (in Hz) */
  1689. #define MT2063_MAX_UPC_FREQ (2750000000UL) /* Maximum LO1 frequency (in Hz) */
  1690. /*
  1691. ** Define the supported Part/Rev codes for the MT2063
  1692. */
  1693. #define MT2063_B0 (0x9B)
  1694. #define MT2063_B1 (0x9C)
  1695. #define MT2063_B2 (0x9D)
  1696. #define MT2063_B3 (0x9E)
  1697. /*
  1698. ** The number of Tuner Registers
  1699. */
  1700. static const u32 MT2063_Num_Registers = MT2063_REG_END_REGS;
  1701. #define USE_GLOBAL_TUNER 0
  1702. static u32 nMT2063MaxTuners = 1;
  1703. static u32 nMT2063OpenTuners = 0;
  1704. /*
  1705. ** Constants for setting receiver modes.
  1706. ** (6 modes defined at this time, enumerated by MT2063_RCVR_MODES)
  1707. ** (DNC1GC & DNC2GC are the values, which are used, when the specific
  1708. ** DNC Output is selected, the other is always off)
  1709. **
  1710. ** If PAL-L or L' is received, set:
  1711. ** MT2063_SetParam(hMT2063,MT2063_TAGC,1);
  1712. **
  1713. ** --------------+----------------------------------------------
  1714. ** Mode 0 : | MT2063_CABLE_QAM
  1715. ** Mode 1 : | MT2063_CABLE_ANALOG
  1716. ** Mode 2 : | MT2063_OFFAIR_COFDM
  1717. ** Mode 3 : | MT2063_OFFAIR_COFDM_SAWLESS
  1718. ** Mode 4 : | MT2063_OFFAIR_ANALOG
  1719. ** Mode 5 : | MT2063_OFFAIR_8VSB
  1720. ** --------------+----+----+----+----+-----+-----+--------------
  1721. ** Mode | 0 | 1 | 2 | 3 | 4 | 5 |
  1722. ** --------------+----+----+----+----+-----+-----+
  1723. **
  1724. **
  1725. */
  1726. static const u8 RFAGCEN[] = { 0, 0, 0, 0, 0, 0 };
  1727. static const u8 LNARIN[] = { 0, 0, 3, 3, 3, 3 };
  1728. static const u8 FIFFQEN[] = { 1, 1, 1, 1, 1, 1 };
  1729. static const u8 FIFFQ[] = { 0, 0, 0, 0, 0, 0 };
  1730. static const u8 DNC1GC[] = { 0, 0, 0, 0, 0, 0 };
  1731. static const u8 DNC2GC[] = { 0, 0, 0, 0, 0, 0 };
  1732. static const u8 ACLNAMAX[] = { 31, 31, 31, 31, 31, 31 };
  1733. static const u8 LNATGT[] = { 44, 43, 43, 43, 43, 43 };
  1734. static const u8 RFOVDIS[] = { 0, 0, 0, 0, 0, 0 };
  1735. static const u8 ACRFMAX[] = { 31, 31, 31, 31, 31, 31 };
  1736. static const u8 PD1TGT[] = { 36, 36, 38, 38, 36, 38 };
  1737. static const u8 FIFOVDIS[] = { 0, 0, 0, 0, 0, 0 };
  1738. static const u8 ACFIFMAX[] = { 29, 29, 29, 29, 29, 29 };
  1739. static const u8 PD2TGT[] = { 40, 33, 38, 42, 30, 38 };
  1740. /*
  1741. ** Local Function Prototypes - not available for external access.
  1742. */
  1743. /* Forward declaration(s): */
  1744. static u32 MT2063_CalcLO1Mult(u32 * Div, u32 * FracN, u32 f_LO,
  1745. u32 f_LO_Step, u32 f_Ref);
  1746. static u32 MT2063_CalcLO2Mult(u32 * Div, u32 * FracN, u32 f_LO,
  1747. u32 f_LO_Step, u32 f_Ref);
  1748. static u32 MT2063_fLO_FractionalTerm(u32 f_ref, u32 num,
  1749. u32 denom);
  1750. /******************************************************************************
  1751. **
  1752. ** Name: MT2063_Open
  1753. **
  1754. ** Description: Initialize the tuner's register values.
  1755. **
  1756. ** Parameters: MT2063_Addr - Serial bus address of the tuner.
  1757. ** hMT2063 - Tuner handle passed back.
  1758. ** hUserData - User-defined data, if needed for the
  1759. ** MT_ReadSub() & MT_WriteSub functions.
  1760. **
  1761. ** Returns: status:
  1762. ** MT_OK - No errors
  1763. ** MT_TUNER_ID_ERR - Tuner Part/Rev code mismatch
  1764. ** MT_TUNER_INIT_ERR - Tuner initialization failed
  1765. ** MT_COMM_ERR - Serial bus communications error
  1766. ** MT_ARG_NULL - Null pointer argument passed
  1767. ** MT_TUNER_CNT_ERR - Too many tuners open
  1768. **
  1769. ** Dependencies: MT_ReadSub - Read byte(s) of data from the two-wire bus
  1770. ** MT_WriteSub - Write byte(s) of data to the two-wire bus
  1771. **
  1772. ** Revision History:
  1773. **
  1774. ** SCR Date Author Description
  1775. ** -------------------------------------------------------------------------
  1776. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  1777. **
  1778. ******************************************************************************/
  1779. static u32 MT2063_Open(u32 MT2063_Addr, struct MT2063_Info_t **hMT2063, void *hUserData)
  1780. {
  1781. u32 status = MT2063_OK; /* Status to be returned. */
  1782. struct MT2063_Info_t *pInfo = NULL;
  1783. struct dvb_frontend *fe = (struct dvb_frontend *)hUserData;
  1784. struct mt2063_state *state = fe->tuner_priv;
  1785. /* Check the argument before using */
  1786. if (hMT2063 == NULL) {
  1787. return MT2063_ARG_NULL;
  1788. }
  1789. /* Default tuner handle to NULL. If successful, it will be reassigned */
  1790. if (state->MT2063_init == false) {
  1791. pInfo = kzalloc(sizeof(struct MT2063_Info_t), GFP_KERNEL);
  1792. if (pInfo == NULL) {
  1793. return MT2063_TUNER_OPEN_ERR;
  1794. }
  1795. pInfo->handle = NULL;
  1796. pInfo->address = MAX_UDATA;
  1797. pInfo->rcvr_mode = MT2063_CABLE_QAM;
  1798. pInfo->hUserData = NULL;
  1799. } else {
  1800. pInfo = *hMT2063;
  1801. }
  1802. if (MT2063_NO_ERROR(status)) {
  1803. status |= MT2063_RegisterTuner(&pInfo->AS_Data);
  1804. }
  1805. if (MT2063_NO_ERROR(status)) {
  1806. pInfo->handle = (void *) pInfo;
  1807. pInfo->hUserData = hUserData;
  1808. pInfo->address = MT2063_Addr;
  1809. pInfo->rcvr_mode = MT2063_CABLE_QAM;
  1810. status |= MT2063_ReInit((void *) pInfo);
  1811. }
  1812. if (MT2063_IS_ERROR(status))
  1813. /* MT2063_Close handles the un-registration of the tuner */
  1814. MT2063_Close((void *) pInfo);
  1815. else {
  1816. state->MT2063_init = true;
  1817. *hMT2063 = pInfo->handle;
  1818. }
  1819. return (status);
  1820. }
  1821. static u32 MT2063_IsValidHandle(struct MT2063_Info_t *handle)
  1822. {
  1823. return ((handle != NULL) && (handle->handle == handle)) ? 1 : 0;
  1824. }
  1825. /******************************************************************************
  1826. **
  1827. ** Name: MT2063_Close
  1828. **
  1829. ** Description: Release the handle to the tuner.
  1830. **
  1831. ** Parameters: hMT2063 - Handle to the MT2063 tuner
  1832. **
  1833. ** Returns: status:
  1834. ** MT_OK - No errors
  1835. ** MT_INV_HANDLE - Invalid tuner handle
  1836. **
  1837. ** Dependencies: mt_errordef.h - definition of error codes
  1838. **
  1839. ** Revision History:
  1840. **
  1841. ** SCR Date Author Description
  1842. ** -------------------------------------------------------------------------
  1843. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  1844. **
  1845. ******************************************************************************/
  1846. static u32 MT2063_Close(void *hMT2063)
  1847. {
  1848. struct MT2063_Info_t *pInfo = (struct MT2063_Info_t *)hMT2063;
  1849. if (!MT2063_IsValidHandle(pInfo))
  1850. return MT2063_INV_HANDLE;
  1851. /* Unregister tuner with SpurAvoidance routines (if needed) */
  1852. MT2063_UnRegisterTuner(&pInfo->AS_Data);
  1853. /* Now remove the tuner from our own list of tuners */
  1854. pInfo->handle = NULL;
  1855. pInfo->address = MAX_UDATA;
  1856. pInfo->hUserData = NULL;
  1857. //kfree(pInfo);
  1858. //pInfo = NULL;
  1859. return MT2063_OK;
  1860. }
  1861. /****************************************************************************
  1862. **
  1863. ** Name: MT2063_GetLocked
  1864. **
  1865. ** Description: Checks to see if LO1 and LO2 are locked.
  1866. **
  1867. ** Parameters: h - Open handle to the tuner (from MT2063_Open).
  1868. **
  1869. ** Returns: status:
  1870. ** MT_OK - No errors
  1871. ** MT_UPC_UNLOCK - Upconverter PLL unlocked
  1872. ** MT_DNC_UNLOCK - Downconverter PLL unlocked
  1873. ** MT_COMM_ERR - Serial bus communications error
  1874. ** MT_INV_HANDLE - Invalid tuner handle
  1875. **
  1876. ** Dependencies: MT_ReadSub - Read byte(s) of data from the serial bus
  1877. ** MT_Sleep - Delay execution for x milliseconds
  1878. **
  1879. ** Revision History:
  1880. **
  1881. ** SCR Date Author Description
  1882. ** -------------------------------------------------------------------------
  1883. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  1884. **
  1885. ****************************************************************************/
  1886. static u32 MT2063_GetLocked(void *h)
  1887. {
  1888. const u32 nMaxWait = 100; /* wait a maximum of 100 msec */
  1889. const u32 nPollRate = 2; /* poll status bits every 2 ms */
  1890. const u32 nMaxLoops = nMaxWait / nPollRate;
  1891. const u8 LO1LK = 0x80;
  1892. u8 LO2LK = 0x08;
  1893. u32 status = MT2063_OK; /* Status to be returned */
  1894. u32 nDelays = 0;
  1895. struct MT2063_Info_t *pInfo = (struct MT2063_Info_t *)h;
  1896. if (MT2063_IsValidHandle(pInfo) == 0)
  1897. return MT2063_INV_HANDLE;
  1898. /* LO2 Lock bit was in a different place for B0 version */
  1899. if (pInfo->tuner_id == MT2063_B0)
  1900. LO2LK = 0x40;
  1901. do {
  1902. status |=
  1903. MT2063_ReadSub(pInfo->hUserData, pInfo->address,
  1904. MT2063_REG_LO_STATUS,
  1905. &pInfo->reg[MT2063_REG_LO_STATUS], 1);
  1906. if (MT2063_IS_ERROR(status))
  1907. return (status);
  1908. if ((pInfo->reg[MT2063_REG_LO_STATUS] & (LO1LK | LO2LK)) ==
  1909. (LO1LK | LO2LK)) {
  1910. return (status);
  1911. }
  1912. msleep(nPollRate); /* Wait between retries */
  1913. }
  1914. while (++nDelays < nMaxLoops);
  1915. if ((pInfo->reg[MT2063_REG_LO_STATUS] & LO1LK) == 0x00)
  1916. status |= MT2063_UPC_UNLOCK;
  1917. if ((pInfo->reg[MT2063_REG_LO_STATUS] & LO2LK) == 0x00)
  1918. status |= MT2063_DNC_UNLOCK;
  1919. return (status);
  1920. }
  1921. /****************************************************************************
  1922. **
  1923. ** Name: MT2063_GetParam
  1924. **
  1925. ** Description: Gets a tuning algorithm parameter.
  1926. **
  1927. ** This function provides access to the internals of the
  1928. ** tuning algorithm - mostly for testing purposes.
  1929. **
  1930. ** Parameters: h - Tuner handle (returned by MT2063_Open)
  1931. ** param - Tuning algorithm parameter
  1932. ** (see enum MT2063_Param)
  1933. ** pValue - ptr to returned value
  1934. **
  1935. ** param Description
  1936. ** ---------------------- --------------------------------
  1937. ** MT2063_IC_ADDR Serial Bus address of this tuner
  1938. ** MT2063_MAX_OPEN Max # of MT2063's allowed open
  1939. ** MT2063_NUM_OPEN # of MT2063's open
  1940. ** MT2063_SRO_FREQ crystal frequency
  1941. ** MT2063_STEPSIZE minimum tuning step size
  1942. ** MT2063_INPUT_FREQ input center frequency
  1943. ** MT2063_LO1_FREQ LO1 Frequency
  1944. ** MT2063_LO1_STEPSIZE LO1 minimum step size
  1945. ** MT2063_LO1_FRACN_AVOID LO1 FracN keep-out region
  1946. ** MT2063_IF1_ACTUAL Current 1st IF in use
  1947. ** MT2063_IF1_REQUEST Requested 1st IF
  1948. ** MT2063_IF1_CENTER Center of 1st IF SAW filter
  1949. ** MT2063_IF1_BW Bandwidth of 1st IF SAW filter
  1950. ** MT2063_ZIF_BW zero-IF bandwidth
  1951. ** MT2063_LO2_FREQ LO2 Frequency
  1952. ** MT2063_LO2_STEPSIZE LO2 minimum step size
  1953. ** MT2063_LO2_FRACN_AVOID LO2 FracN keep-out region
  1954. ** MT2063_OUTPUT_FREQ output center frequency
  1955. ** MT2063_OUTPUT_BW output bandwidth
  1956. ** MT2063_LO_SEPARATION min inter-tuner LO separation
  1957. ** MT2063_AS_ALG ID of avoid-spurs algorithm in use
  1958. ** MT2063_MAX_HARM1 max # of intra-tuner harmonics
  1959. ** MT2063_MAX_HARM2 max # of inter-tuner harmonics
  1960. ** MT2063_EXCL_ZONES # of 1st IF exclusion zones
  1961. ** MT2063_NUM_SPURS # of spurs found/avoided
  1962. ** MT2063_SPUR_AVOIDED >0 spurs avoided
  1963. ** MT2063_SPUR_PRESENT >0 spurs in output (mathematically)
  1964. ** MT2063_RCVR_MODE Predefined modes.
  1965. ** MT2063_ACLNA LNA attenuator gain code
  1966. ** MT2063_ACRF RF attenuator gain code
  1967. ** MT2063_ACFIF FIF attenuator gain code
  1968. ** MT2063_ACLNA_MAX LNA attenuator limit
  1969. ** MT2063_ACRF_MAX RF attenuator limit
  1970. ** MT2063_ACFIF_MAX FIF attenuator limit
  1971. ** MT2063_PD1 Actual value of PD1
  1972. ** MT2063_PD2 Actual value of PD2
  1973. ** MT2063_DNC_OUTPUT_ENABLE DNC output selection
  1974. ** MT2063_VGAGC VGA gain code
  1975. ** MT2063_VGAOI VGA output current
  1976. ** MT2063_TAGC TAGC setting
  1977. ** MT2063_AMPGC AMP gain code
  1978. ** MT2063_AVOID_DECT Avoid DECT Frequencies
  1979. ** MT2063_CTFILT_SW Cleartune filter selection
  1980. **
  1981. ** Usage: status |= MT2063_GetParam(hMT2063,
  1982. ** MT2063_IF1_ACTUAL,
  1983. ** &f_IF1_Actual);
  1984. **
  1985. ** Returns: status:
  1986. ** MT_OK - No errors
  1987. ** MT_INV_HANDLE - Invalid tuner handle
  1988. ** MT_ARG_NULL - Null pointer argument passed
  1989. ** MT_ARG_RANGE - Invalid parameter requested
  1990. **
  1991. ** Dependencies: USERS MUST CALL MT2063_Open() FIRST!
  1992. **
  1993. ** See Also: MT2063_SetParam, MT2063_Open
  1994. **
  1995. ** Revision History:
  1996. **
  1997. ** SCR Date Author Description
  1998. ** -------------------------------------------------------------------------
  1999. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  2000. ** 154 09-13-2007 RSK Ver 1.05: Get/SetParam changes for LOx_FREQ
  2001. ** 10-31-2007 PINZ Ver 1.08: Get/SetParam add VGAGC, VGAOI, AMPGC, TAGC
  2002. ** 173 M 01-23-2008 RSK Ver 1.12: Read LO1C and LO2C registers from HW
  2003. ** in GetParam.
  2004. ** 04-18-2008 PINZ Ver 1.15: Add SetParam LNARIN & PDxTGT
  2005. ** Split SetParam up to ACLNA / ACLNA_MAX
  2006. ** removed ACLNA_INRC/DECR (+RF & FIF)
  2007. ** removed GCUAUTO / BYPATNDN/UP
  2008. ** 175 I 16-06-2008 PINZ Ver 1.16: Add control to avoid US DECT freqs.
  2009. ** 175 I 06-19-2008 RSK Ver 1.17: Refactor DECT control to SpurAvoid.
  2010. ** 06-24-2008 PINZ Ver 1.18: Add Get/SetParam CTFILT_SW
  2011. **
  2012. ****************************************************************************/
  2013. static u32 MT2063_GetParam(void *h, enum MT2063_Param param, u32 * pValue)
  2014. {
  2015. u32 status = MT2063_OK; /* Status to be returned */
  2016. struct MT2063_Info_t *pInfo = (struct MT2063_Info_t *)h;
  2017. u32 Div;
  2018. u32 Num;
  2019. if (pValue == NULL)
  2020. status |= MT2063_ARG_NULL;
  2021. /* Verify that the handle passed points to a valid tuner */
  2022. if (MT2063_IsValidHandle(pInfo) == 0)
  2023. status |= MT2063_INV_HANDLE;
  2024. if (MT2063_NO_ERROR(status)) {
  2025. switch (param) {
  2026. /* Serial Bus address of this tuner */
  2027. case MT2063_IC_ADDR:
  2028. *pValue = pInfo->address;
  2029. break;
  2030. /* Max # of MT2063's allowed to be open */
  2031. case MT2063_MAX_OPEN:
  2032. *pValue = nMT2063MaxTuners;
  2033. break;
  2034. /* # of MT2063's open */
  2035. case MT2063_NUM_OPEN:
  2036. *pValue = nMT2063OpenTuners;
  2037. break;
  2038. /* crystal frequency */
  2039. case MT2063_SRO_FREQ:
  2040. *pValue = pInfo->AS_Data.f_ref;
  2041. break;
  2042. /* minimum tuning step size */
  2043. case MT2063_STEPSIZE:
  2044. *pValue = pInfo->AS_Data.f_LO2_Step;
  2045. break;
  2046. /* input center frequency */
  2047. case MT2063_INPUT_FREQ:
  2048. *pValue = pInfo->AS_Data.f_in;
  2049. break;
  2050. /* LO1 Frequency */
  2051. case MT2063_LO1_FREQ:
  2052. {
  2053. /* read the actual tuner register values for LO1C_1 and LO1C_2 */
  2054. status |=
  2055. MT2063_ReadSub(pInfo->hUserData,
  2056. pInfo->address,
  2057. MT2063_REG_LO1C_1,
  2058. &pInfo->
  2059. reg[MT2063_REG_LO1C_1], 2);
  2060. Div = pInfo->reg[MT2063_REG_LO1C_1];
  2061. Num = pInfo->reg[MT2063_REG_LO1C_2] & 0x3F;
  2062. pInfo->AS_Data.f_LO1 =
  2063. (pInfo->AS_Data.f_ref * Div) +
  2064. MT2063_fLO_FractionalTerm(pInfo->AS_Data.
  2065. f_ref, Num, 64);
  2066. }
  2067. *pValue = pInfo->AS_Data.f_LO1;
  2068. break;
  2069. /* LO1 minimum step size */
  2070. case MT2063_LO1_STEPSIZE:
  2071. *pValue = pInfo->AS_Data.f_LO1_Step;
  2072. break;
  2073. /* LO1 FracN keep-out region */
  2074. case MT2063_LO1_FRACN_AVOID_PARAM:
  2075. *pValue = pInfo->AS_Data.f_LO1_FracN_Avoid;
  2076. break;
  2077. /* Current 1st IF in use */
  2078. case MT2063_IF1_ACTUAL:
  2079. *pValue = pInfo->f_IF1_actual;
  2080. break;
  2081. /* Requested 1st IF */
  2082. case MT2063_IF1_REQUEST:
  2083. *pValue = pInfo->AS_Data.f_if1_Request;
  2084. break;
  2085. /* Center of 1st IF SAW filter */
  2086. case MT2063_IF1_CENTER:
  2087. *pValue = pInfo->AS_Data.f_if1_Center;
  2088. break;
  2089. /* Bandwidth of 1st IF SAW filter */
  2090. case MT2063_IF1_BW:
  2091. *pValue = pInfo->AS_Data.f_if1_bw;
  2092. break;
  2093. /* zero-IF bandwidth */
  2094. case MT2063_ZIF_BW:
  2095. *pValue = pInfo->AS_Data.f_zif_bw;
  2096. break;
  2097. /* LO2 Frequency */
  2098. case MT2063_LO2_FREQ:
  2099. {
  2100. /* Read the actual tuner register values for LO2C_1, LO2C_2 and LO2C_3 */
  2101. status |=
  2102. MT2063_ReadSub(pInfo->hUserData,
  2103. pInfo->address,
  2104. MT2063_REG_LO2C_1,
  2105. &pInfo->
  2106. reg[MT2063_REG_LO2C_1], 3);
  2107. Div =
  2108. (pInfo->reg[MT2063_REG_LO2C_1] & 0xFE) >> 1;
  2109. Num =
  2110. ((pInfo->
  2111. reg[MT2063_REG_LO2C_1] & 0x01) << 12) |
  2112. (pInfo->
  2113. reg[MT2063_REG_LO2C_2] << 4) | (pInfo->
  2114. reg
  2115. [MT2063_REG_LO2C_3]
  2116. & 0x00F);
  2117. pInfo->AS_Data.f_LO2 =
  2118. (pInfo->AS_Data.f_ref * Div) +
  2119. MT2063_fLO_FractionalTerm(pInfo->AS_Data.
  2120. f_ref, Num, 8191);
  2121. }
  2122. *pValue = pInfo->AS_Data.f_LO2;
  2123. break;
  2124. /* LO2 minimum step size */
  2125. case MT2063_LO2_STEPSIZE:
  2126. *pValue = pInfo->AS_Data.f_LO2_Step;
  2127. break;
  2128. /* LO2 FracN keep-out region */
  2129. case MT2063_LO2_FRACN_AVOID:
  2130. *pValue = pInfo->AS_Data.f_LO2_FracN_Avoid;
  2131. break;
  2132. /* output center frequency */
  2133. case MT2063_OUTPUT_FREQ:
  2134. *pValue = pInfo->AS_Data.f_out;
  2135. break;
  2136. /* output bandwidth */
  2137. case MT2063_OUTPUT_BW:
  2138. *pValue = pInfo->AS_Data.f_out_bw - 750000;
  2139. break;
  2140. /* min inter-tuner LO separation */
  2141. case MT2063_LO_SEPARATION:
  2142. *pValue = pInfo->AS_Data.f_min_LO_Separation;
  2143. break;
  2144. /* ID of avoid-spurs algorithm in use */
  2145. case MT2063_AS_ALG:
  2146. *pValue = pInfo->AS_Data.nAS_Algorithm;
  2147. break;
  2148. /* max # of intra-tuner harmonics */
  2149. case MT2063_MAX_HARM1:
  2150. *pValue = pInfo->AS_Data.maxH1;
  2151. break;
  2152. /* max # of inter-tuner harmonics */
  2153. case MT2063_MAX_HARM2:
  2154. *pValue = pInfo->AS_Data.maxH2;
  2155. break;
  2156. /* # of 1st IF exclusion zones */
  2157. case MT2063_EXCL_ZONES:
  2158. *pValue = pInfo->AS_Data.nZones;
  2159. break;
  2160. /* # of spurs found/avoided */
  2161. case MT2063_NUM_SPURS:
  2162. *pValue = pInfo->AS_Data.nSpursFound;
  2163. break;
  2164. /* >0 spurs avoided */
  2165. case MT2063_SPUR_AVOIDED:
  2166. *pValue = pInfo->AS_Data.bSpurAvoided;
  2167. break;
  2168. /* >0 spurs in output (mathematically) */
  2169. case MT2063_SPUR_PRESENT:
  2170. *pValue = pInfo->AS_Data.bSpurPresent;
  2171. break;
  2172. /* Predefined receiver setup combination */
  2173. case MT2063_RCVR_MODE:
  2174. *pValue = pInfo->rcvr_mode;
  2175. break;
  2176. case MT2063_PD1:
  2177. case MT2063_PD2:
  2178. {
  2179. u8 mask = (param == MT2063_PD1 ? 0x01 : 0x03); /* PD1 vs PD2 */
  2180. u8 orig = (pInfo->reg[MT2063_REG_BYP_CTRL]);
  2181. u8 reg = (orig & 0xF1) | mask; /* Only set 3 bits (not 5) */
  2182. int i;
  2183. *pValue = 0;
  2184. /* Initiate ADC output to reg 0x0A */
  2185. if (reg != orig)
  2186. status |=
  2187. MT2063_WriteSub(pInfo->hUserData,
  2188. pInfo->address,
  2189. MT2063_REG_BYP_CTRL,
  2190. &reg, 1);
  2191. if (MT2063_IS_ERROR(status))
  2192. return (status);
  2193. for (i = 0; i < 8; i++) {
  2194. status |=
  2195. MT2063_ReadSub(pInfo->hUserData,
  2196. pInfo->address,
  2197. MT2063_REG_ADC_OUT,
  2198. &pInfo->
  2199. reg
  2200. [MT2063_REG_ADC_OUT],
  2201. 1);
  2202. if (MT2063_NO_ERROR(status))
  2203. *pValue +=
  2204. pInfo->
  2205. reg[MT2063_REG_ADC_OUT];
  2206. else {
  2207. if (i)
  2208. *pValue /= i;
  2209. return (status);
  2210. }
  2211. }
  2212. *pValue /= 8; /* divide by number of reads */
  2213. *pValue >>= 2; /* only want 6 MSB's out of 8 */
  2214. /* Restore value of Register BYP_CTRL */
  2215. if (reg != orig)
  2216. status |=
  2217. MT2063_WriteSub(pInfo->hUserData,
  2218. pInfo->address,
  2219. MT2063_REG_BYP_CTRL,
  2220. &orig, 1);
  2221. }
  2222. break;
  2223. /* Get LNA attenuator code */
  2224. case MT2063_ACLNA:
  2225. {
  2226. u8 val;
  2227. status |=
  2228. MT2063_GetReg(pInfo, MT2063_REG_XO_STATUS,
  2229. &val);
  2230. *pValue = val & 0x1f;
  2231. }
  2232. break;
  2233. /* Get RF attenuator code */
  2234. case MT2063_ACRF:
  2235. {
  2236. u8 val;
  2237. status |=
  2238. MT2063_GetReg(pInfo, MT2063_REG_RF_STATUS,
  2239. &val);
  2240. *pValue = val & 0x1f;
  2241. }
  2242. break;
  2243. /* Get FIF attenuator code */
  2244. case MT2063_ACFIF:
  2245. {
  2246. u8 val;
  2247. status |=
  2248. MT2063_GetReg(pInfo, MT2063_REG_FIF_STATUS,
  2249. &val);
  2250. *pValue = val & 0x1f;
  2251. }
  2252. break;
  2253. /* Get LNA attenuator limit */
  2254. case MT2063_ACLNA_MAX:
  2255. {
  2256. u8 val;
  2257. status |=
  2258. MT2063_GetReg(pInfo, MT2063_REG_LNA_OV,
  2259. &val);
  2260. *pValue = val & 0x1f;
  2261. }
  2262. break;
  2263. /* Get RF attenuator limit */
  2264. case MT2063_ACRF_MAX:
  2265. {
  2266. u8 val;
  2267. status |=
  2268. MT2063_GetReg(pInfo, MT2063_REG_RF_OV,
  2269. &val);
  2270. *pValue = val & 0x1f;
  2271. }
  2272. break;
  2273. /* Get FIF attenuator limit */
  2274. case MT2063_ACFIF_MAX:
  2275. {
  2276. u8 val;
  2277. status |=
  2278. MT2063_GetReg(pInfo, MT2063_REG_FIF_OV,
  2279. &val);
  2280. *pValue = val & 0x1f;
  2281. }
  2282. break;
  2283. /* Get current used DNC output */
  2284. case MT2063_DNC_OUTPUT_ENABLE:
  2285. {
  2286. if ((pInfo->reg[MT2063_REG_DNC_GAIN] & 0x03) == 0x03) { /* if DNC1 is off */
  2287. if ((pInfo->reg[MT2063_REG_VGA_GAIN] & 0x03) == 0x03) /* if DNC2 is off */
  2288. *pValue =
  2289. (u32) MT2063_DNC_NONE;
  2290. else
  2291. *pValue =
  2292. (u32) MT2063_DNC_2;
  2293. } else { /* DNC1 is on */
  2294. if ((pInfo->reg[MT2063_REG_VGA_GAIN] & 0x03) == 0x03) /* if DNC2 is off */
  2295. *pValue =
  2296. (u32) MT2063_DNC_1;
  2297. else
  2298. *pValue =
  2299. (u32) MT2063_DNC_BOTH;
  2300. }
  2301. }
  2302. break;
  2303. /* Get VGA Gain Code */
  2304. case MT2063_VGAGC:
  2305. *pValue =
  2306. ((pInfo->reg[MT2063_REG_VGA_GAIN] & 0x0C) >> 2);
  2307. break;
  2308. /* Get VGA bias current */
  2309. case MT2063_VGAOI:
  2310. *pValue = (pInfo->reg[MT2063_REG_RSVD_31] & 0x07);
  2311. break;
  2312. /* Get TAGC setting */
  2313. case MT2063_TAGC:
  2314. *pValue = (pInfo->reg[MT2063_REG_RSVD_1E] & 0x03);
  2315. break;
  2316. /* Get AMP Gain Code */
  2317. case MT2063_AMPGC:
  2318. *pValue = (pInfo->reg[MT2063_REG_TEMP_SEL] & 0x03);
  2319. break;
  2320. /* Avoid DECT Frequencies */
  2321. case MT2063_AVOID_DECT:
  2322. *pValue = pInfo->AS_Data.avoidDECT;
  2323. break;
  2324. /* Cleartune filter selection: 0 - by IC (default), 1 - by software */
  2325. case MT2063_CTFILT_SW:
  2326. *pValue = pInfo->ctfilt_sw;
  2327. break;
  2328. case MT2063_EOP:
  2329. default:
  2330. status |= MT2063_ARG_RANGE;
  2331. }
  2332. }
  2333. return (status);
  2334. }
  2335. /****************************************************************************
  2336. **
  2337. ** Name: MT2063_GetReg
  2338. **
  2339. ** Description: Gets an MT2063 register.
  2340. **
  2341. ** Parameters: h - Tuner handle (returned by MT2063_Open)
  2342. ** reg - MT2063 register/subaddress location
  2343. ** *val - MT2063 register/subaddress value
  2344. **
  2345. ** Returns: status:
  2346. ** MT_OK - No errors
  2347. ** MT_COMM_ERR - Serial bus communications error
  2348. ** MT_INV_HANDLE - Invalid tuner handle
  2349. ** MT_ARG_NULL - Null pointer argument passed
  2350. ** MT_ARG_RANGE - Argument out of range
  2351. **
  2352. ** Dependencies: USERS MUST CALL MT2063_Open() FIRST!
  2353. **
  2354. ** Use this function if you need to read a register from
  2355. ** the MT2063.
  2356. **
  2357. ** Revision History:
  2358. **
  2359. ** SCR Date Author Description
  2360. ** -------------------------------------------------------------------------
  2361. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  2362. **
  2363. ****************************************************************************/
  2364. static u32 MT2063_GetReg(void *h, u8 reg, u8 * val)
  2365. {
  2366. u32 status = MT2063_OK; /* Status to be returned */
  2367. struct MT2063_Info_t *pInfo = (struct MT2063_Info_t *)h;
  2368. /* Verify that the handle passed points to a valid tuner */
  2369. if (MT2063_IsValidHandle(pInfo) == 0)
  2370. status |= MT2063_INV_HANDLE;
  2371. if (val == NULL)
  2372. status |= MT2063_ARG_NULL;
  2373. if (reg >= MT2063_REG_END_REGS)
  2374. status |= MT2063_ARG_RANGE;
  2375. if (MT2063_NO_ERROR(status)) {
  2376. status |=
  2377. MT2063_ReadSub(pInfo->hUserData, pInfo->address, reg,
  2378. &pInfo->reg[reg], 1);
  2379. if (MT2063_NO_ERROR(status))
  2380. *val = pInfo->reg[reg];
  2381. }
  2382. return (status);
  2383. }
  2384. /******************************************************************************
  2385. **
  2386. ** Name: MT2063_SetReceiverMode
  2387. **
  2388. ** Description: Set the MT2063 receiver mode
  2389. **
  2390. ** --------------+----------------------------------------------
  2391. ** Mode 0 : | MT2063_CABLE_QAM
  2392. ** Mode 1 : | MT2063_CABLE_ANALOG
  2393. ** Mode 2 : | MT2063_OFFAIR_COFDM
  2394. ** Mode 3 : | MT2063_OFFAIR_COFDM_SAWLESS
  2395. ** Mode 4 : | MT2063_OFFAIR_ANALOG
  2396. ** Mode 5 : | MT2063_OFFAIR_8VSB
  2397. ** --------------+----+----+----+----+-----+--------------------
  2398. ** (DNC1GC & DNC2GC are the values, which are used, when the specific
  2399. ** DNC Output is selected, the other is always off)
  2400. **
  2401. ** |<---------- Mode -------------->|
  2402. ** Reg Field | 0 | 1 | 2 | 3 | 4 | 5 |
  2403. ** ------------+-----+-----+-----+-----+-----+-----+
  2404. ** RFAGCen | OFF | OFF | OFF | OFF | OFF | OFF
  2405. ** LNARin | 0 | 0 | 3 | 3 | 3 | 3
  2406. ** FIFFQen | 1 | 1 | 1 | 1 | 1 | 1
  2407. ** FIFFq | 0 | 0 | 0 | 0 | 0 | 0
  2408. ** DNC1gc | 0 | 0 | 0 | 0 | 0 | 0
  2409. ** DNC2gc | 0 | 0 | 0 | 0 | 0 | 0
  2410. ** GCU Auto | 1 | 1 | 1 | 1 | 1 | 1
  2411. ** LNA max Atn | 31 | 31 | 31 | 31 | 31 | 31
  2412. ** LNA Target | 44 | 43 | 43 | 43 | 43 | 43
  2413. ** ign RF Ovl | 0 | 0 | 0 | 0 | 0 | 0
  2414. ** RF max Atn | 31 | 31 | 31 | 31 | 31 | 31
  2415. ** PD1 Target | 36 | 36 | 38 | 38 | 36 | 38
  2416. ** ign FIF Ovl | 0 | 0 | 0 | 0 | 0 | 0
  2417. ** FIF max Atn | 5 | 5 | 5 | 5 | 5 | 5
  2418. ** PD2 Target | 40 | 33 | 42 | 42 | 33 | 42
  2419. **
  2420. **
  2421. ** Parameters: pInfo - ptr to MT2063_Info_t structure
  2422. ** Mode - desired reciever mode
  2423. **
  2424. ** Usage: status = MT2063_SetReceiverMode(hMT2063, Mode);
  2425. **
  2426. ** Returns: status:
  2427. ** MT_OK - No errors
  2428. ** MT_COMM_ERR - Serial bus communications error
  2429. **
  2430. ** Dependencies: MT2063_SetReg - Write a byte of data to a HW register.
  2431. ** Assumes that the tuner cache is valid.
  2432. **
  2433. ** Revision History:
  2434. **
  2435. ** SCR Date Author Description
  2436. ** -------------------------------------------------------------------------
  2437. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  2438. ** N/A 01-10-2007 PINZ Added additional GCU Settings, FIFF Calib will be triggered
  2439. ** 155 10-01-2007 DAD Ver 1.06: Add receiver mode for SECAM positive
  2440. ** modulation
  2441. ** (MT2063_ANALOG_TV_POS_NO_RFAGC_MODE)
  2442. ** N/A 10-22-2007 PINZ Ver 1.07: Changed some Registers at init to have
  2443. ** the same settings as with MT Launcher
  2444. ** N/A 10-30-2007 PINZ Add SetParam VGAGC & VGAOI
  2445. ** Add SetParam DNC_OUTPUT_ENABLE
  2446. ** Removed VGAGC from receiver mode,
  2447. ** default now 1
  2448. ** N/A 10-31-2007 PINZ Ver 1.08: Add SetParam TAGC, removed from rcvr-mode
  2449. ** Add SetParam AMPGC, removed from rcvr-mode
  2450. ** Corrected names of GCU values
  2451. ** reorganized receiver modes, removed,
  2452. ** (MT2063_ANALOG_TV_POS_NO_RFAGC_MODE)
  2453. ** Actualized Receiver-Mode values
  2454. ** N/A 11-12-2007 PINZ Ver 1.09: Actualized Receiver-Mode values
  2455. ** N/A 11-27-2007 PINZ Improved buffered writing
  2456. ** 01-03-2008 PINZ Ver 1.10: Added a trigger of BYPATNUP for
  2457. ** correct wakeup of the LNA after shutdown
  2458. ** Set AFCsd = 1 as default
  2459. ** Changed CAP1sel default
  2460. ** 01-14-2008 PINZ Ver 1.11: Updated gain settings
  2461. ** 04-18-2008 PINZ Ver 1.15: Add SetParam LNARIN & PDxTGT
  2462. ** Split SetParam up to ACLNA / ACLNA_MAX
  2463. ** removed ACLNA_INRC/DECR (+RF & FIF)
  2464. ** removed GCUAUTO / BYPATNDN/UP
  2465. **
  2466. ******************************************************************************/
  2467. static u32 MT2063_SetReceiverMode(struct MT2063_Info_t *pInfo,
  2468. enum MT2063_RCVR_MODES Mode)
  2469. {
  2470. u32 status = MT2063_OK; /* Status to be returned */
  2471. u8 val;
  2472. u32 longval;
  2473. if (Mode >= MT2063_NUM_RCVR_MODES)
  2474. status = MT2063_ARG_RANGE;
  2475. /* RFAGCen */
  2476. if (MT2063_NO_ERROR(status)) {
  2477. val =
  2478. (pInfo->
  2479. reg[MT2063_REG_PD1_TGT] & (u8) ~ 0x40) | (RFAGCEN[Mode]
  2480. ? 0x40 :
  2481. 0x00);
  2482. if (pInfo->reg[MT2063_REG_PD1_TGT] != val) {
  2483. status |= MT2063_SetReg(pInfo, MT2063_REG_PD1_TGT, val);
  2484. }
  2485. }
  2486. /* LNARin */
  2487. if (MT2063_NO_ERROR(status)) {
  2488. status |= MT2063_SetParam(pInfo, MT2063_LNA_RIN, LNARIN[Mode]);
  2489. }
  2490. /* FIFFQEN and FIFFQ */
  2491. if (MT2063_NO_ERROR(status)) {
  2492. val =
  2493. (pInfo->
  2494. reg[MT2063_REG_FIFF_CTRL2] & (u8) ~ 0xF0) |
  2495. (FIFFQEN[Mode] << 7) | (FIFFQ[Mode] << 4);
  2496. if (pInfo->reg[MT2063_REG_FIFF_CTRL2] != val) {
  2497. status |=
  2498. MT2063_SetReg(pInfo, MT2063_REG_FIFF_CTRL2, val);
  2499. /* trigger FIFF calibration, needed after changing FIFFQ */
  2500. val =
  2501. (pInfo->reg[MT2063_REG_FIFF_CTRL] | (u8) 0x01);
  2502. status |=
  2503. MT2063_SetReg(pInfo, MT2063_REG_FIFF_CTRL, val);
  2504. val =
  2505. (pInfo->
  2506. reg[MT2063_REG_FIFF_CTRL] & (u8) ~ 0x01);
  2507. status |=
  2508. MT2063_SetReg(pInfo, MT2063_REG_FIFF_CTRL, val);
  2509. }
  2510. }
  2511. /* DNC1GC & DNC2GC */
  2512. status |= MT2063_GetParam(pInfo, MT2063_DNC_OUTPUT_ENABLE, &longval);
  2513. status |= MT2063_SetParam(pInfo, MT2063_DNC_OUTPUT_ENABLE, longval);
  2514. /* acLNAmax */
  2515. if (MT2063_NO_ERROR(status)) {
  2516. status |=
  2517. MT2063_SetParam(pInfo, MT2063_ACLNA_MAX, ACLNAMAX[Mode]);
  2518. }
  2519. /* LNATGT */
  2520. if (MT2063_NO_ERROR(status)) {
  2521. status |= MT2063_SetParam(pInfo, MT2063_LNA_TGT, LNATGT[Mode]);
  2522. }
  2523. /* ACRF */
  2524. if (MT2063_NO_ERROR(status)) {
  2525. status |=
  2526. MT2063_SetParam(pInfo, MT2063_ACRF_MAX, ACRFMAX[Mode]);
  2527. }
  2528. /* PD1TGT */
  2529. if (MT2063_NO_ERROR(status)) {
  2530. status |= MT2063_SetParam(pInfo, MT2063_PD1_TGT, PD1TGT[Mode]);
  2531. }
  2532. /* FIFATN */
  2533. if (MT2063_NO_ERROR(status)) {
  2534. status |=
  2535. MT2063_SetParam(pInfo, MT2063_ACFIF_MAX, ACFIFMAX[Mode]);
  2536. }
  2537. /* PD2TGT */
  2538. if (MT2063_NO_ERROR(status)) {
  2539. status |= MT2063_SetParam(pInfo, MT2063_PD2_TGT, PD2TGT[Mode]);
  2540. }
  2541. /* Ignore ATN Overload */
  2542. if (MT2063_NO_ERROR(status)) {
  2543. val =
  2544. (pInfo->
  2545. reg[MT2063_REG_LNA_TGT] & (u8) ~ 0x80) | (RFOVDIS[Mode]
  2546. ? 0x80 :
  2547. 0x00);
  2548. if (pInfo->reg[MT2063_REG_LNA_TGT] != val) {
  2549. status |= MT2063_SetReg(pInfo, MT2063_REG_LNA_TGT, val);
  2550. }
  2551. }
  2552. /* Ignore FIF Overload */
  2553. if (MT2063_NO_ERROR(status)) {
  2554. val =
  2555. (pInfo->
  2556. reg[MT2063_REG_PD1_TGT] & (u8) ~ 0x80) |
  2557. (FIFOVDIS[Mode] ? 0x80 : 0x00);
  2558. if (pInfo->reg[MT2063_REG_PD1_TGT] != val) {
  2559. status |= MT2063_SetReg(pInfo, MT2063_REG_PD1_TGT, val);
  2560. }
  2561. }
  2562. if (MT2063_NO_ERROR(status))
  2563. pInfo->rcvr_mode = Mode;
  2564. return (status);
  2565. }
  2566. /******************************************************************************
  2567. **
  2568. ** Name: MT2063_ReInit
  2569. **
  2570. ** Description: Initialize the tuner's register values.
  2571. **
  2572. ** Parameters: h - Tuner handle (returned by MT2063_Open)
  2573. **
  2574. ** Returns: status:
  2575. ** MT_OK - No errors
  2576. ** MT_TUNER_ID_ERR - Tuner Part/Rev code mismatch
  2577. ** MT_INV_HANDLE - Invalid tuner handle
  2578. ** MT_COMM_ERR - Serial bus communications error
  2579. **
  2580. ** Dependencies: MT_ReadSub - Read byte(s) of data from the two-wire bus
  2581. ** MT_WriteSub - Write byte(s) of data to the two-wire bus
  2582. **
  2583. ** Revision History:
  2584. **
  2585. ** SCR Date Author Description
  2586. ** -------------------------------------------------------------------------
  2587. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  2588. ** 148 09-04-2007 RSK Ver 1.02: Corrected logic of Reg 3B Reference
  2589. ** 153 09-07-2007 RSK Ver 1.03: Lock Time improvements
  2590. ** N/A 10-31-2007 PINZ Ver 1.08: Changed values suitable to rcvr-mode 0
  2591. ** N/A 11-12-2007 PINZ Ver 1.09: Changed values suitable to rcvr-mode 0
  2592. ** N/A 01-03-2007 PINZ Ver 1.10: Added AFCsd = 1 into defaults
  2593. ** N/A 01-04-2007 PINZ Ver 1.10: Changed CAP1sel default
  2594. ** 01-14-2008 PINZ Ver 1.11: Updated gain settings
  2595. ** 03-18-2008 PINZ Ver 1.13: Added Support for B3
  2596. ** 175 I 06-19-2008 RSK Ver 1.17: Refactor DECT control to SpurAvoid.
  2597. ** 06-24-2008 PINZ Ver 1.18: Add Get/SetParam CTFILT_SW
  2598. **
  2599. ******************************************************************************/
  2600. static u32 MT2063_ReInit(void *h)
  2601. {
  2602. u8 all_resets = 0xF0; /* reset/load bits */
  2603. u32 status = MT2063_OK; /* Status to be returned */
  2604. struct MT2063_Info_t *pInfo = (struct MT2063_Info_t *)h;
  2605. u8 *def = NULL;
  2606. u8 MT2063B0_defaults[] = { /* Reg, Value */
  2607. 0x19, 0x05,
  2608. 0x1B, 0x1D,
  2609. 0x1C, 0x1F,
  2610. 0x1D, 0x0F,
  2611. 0x1E, 0x3F,
  2612. 0x1F, 0x0F,
  2613. 0x20, 0x3F,
  2614. 0x22, 0x21,
  2615. 0x23, 0x3F,
  2616. 0x24, 0x20,
  2617. 0x25, 0x3F,
  2618. 0x27, 0xEE,
  2619. 0x2C, 0x27, /* bit at 0x20 is cleared below */
  2620. 0x30, 0x03,
  2621. 0x2C, 0x07, /* bit at 0x20 is cleared here */
  2622. 0x2D, 0x87,
  2623. 0x2E, 0xAA,
  2624. 0x28, 0xE1, /* Set the FIFCrst bit here */
  2625. 0x28, 0xE0, /* Clear the FIFCrst bit here */
  2626. 0x00
  2627. };
  2628. /* writing 0x05 0xf0 sw-resets all registers, so we write only needed changes */
  2629. u8 MT2063B1_defaults[] = { /* Reg, Value */
  2630. 0x05, 0xF0,
  2631. 0x11, 0x10, /* New Enable AFCsd */
  2632. 0x19, 0x05,
  2633. 0x1A, 0x6C,
  2634. 0x1B, 0x24,
  2635. 0x1C, 0x28,
  2636. 0x1D, 0x8F,
  2637. 0x1E, 0x14,
  2638. 0x1F, 0x8F,
  2639. 0x20, 0x57,
  2640. 0x22, 0x21, /* New - ver 1.03 */
  2641. 0x23, 0x3C, /* New - ver 1.10 */
  2642. 0x24, 0x20, /* New - ver 1.03 */
  2643. 0x2C, 0x24, /* bit at 0x20 is cleared below */
  2644. 0x2D, 0x87, /* FIFFQ=0 */
  2645. 0x2F, 0xF3,
  2646. 0x30, 0x0C, /* New - ver 1.11 */
  2647. 0x31, 0x1B, /* New - ver 1.11 */
  2648. 0x2C, 0x04, /* bit at 0x20 is cleared here */
  2649. 0x28, 0xE1, /* Set the FIFCrst bit here */
  2650. 0x28, 0xE0, /* Clear the FIFCrst bit here */
  2651. 0x00
  2652. };
  2653. /* writing 0x05 0xf0 sw-resets all registers, so we write only needed changes */
  2654. u8 MT2063B3_defaults[] = { /* Reg, Value */
  2655. 0x05, 0xF0,
  2656. 0x19, 0x3D,
  2657. 0x2C, 0x24, /* bit at 0x20 is cleared below */
  2658. 0x2C, 0x04, /* bit at 0x20 is cleared here */
  2659. 0x28, 0xE1, /* Set the FIFCrst bit here */
  2660. 0x28, 0xE0, /* Clear the FIFCrst bit here */
  2661. 0x00
  2662. };
  2663. /* Verify that the handle passed points to a valid tuner */
  2664. if (MT2063_IsValidHandle(pInfo) == 0)
  2665. status |= MT2063_INV_HANDLE;
  2666. /* Read the Part/Rev code from the tuner */
  2667. if (MT2063_NO_ERROR(status)) {
  2668. status |=
  2669. MT2063_ReadSub(pInfo->hUserData, pInfo->address,
  2670. MT2063_REG_PART_REV, pInfo->reg, 1);
  2671. }
  2672. if (MT2063_NO_ERROR(status) /* Check the part/rev code */
  2673. &&((pInfo->reg[MT2063_REG_PART_REV] != MT2063_B0) /* MT2063 B0 */
  2674. &&(pInfo->reg[MT2063_REG_PART_REV] != MT2063_B1) /* MT2063 B1 */
  2675. &&(pInfo->reg[MT2063_REG_PART_REV] != MT2063_B3))) /* MT2063 B3 */
  2676. status |= MT2063_TUNER_ID_ERR; /* Wrong tuner Part/Rev code */
  2677. /* Read the Part/Rev code (2nd byte) from the tuner */
  2678. if (MT2063_NO_ERROR(status))
  2679. status |=
  2680. MT2063_ReadSub(pInfo->hUserData, pInfo->address,
  2681. MT2063_REG_RSVD_3B,
  2682. &pInfo->reg[MT2063_REG_RSVD_3B], 1);
  2683. if (MT2063_NO_ERROR(status) /* Check the 2nd part/rev code */
  2684. &&((pInfo->reg[MT2063_REG_RSVD_3B] & 0x80) != 0x00)) /* b7 != 0 ==> NOT MT2063 */
  2685. status |= MT2063_TUNER_ID_ERR; /* Wrong tuner Part/Rev code */
  2686. /* Reset the tuner */
  2687. if (MT2063_NO_ERROR(status))
  2688. status |= MT2063_WriteSub(pInfo->hUserData,
  2689. pInfo->address,
  2690. MT2063_REG_LO2CQ_3, &all_resets, 1);
  2691. /* change all of the default values that vary from the HW reset values */
  2692. /* def = (pInfo->reg[PART_REV] == MT2063_B0) ? MT2063B0_defaults : MT2063B1_defaults; */
  2693. switch (pInfo->reg[MT2063_REG_PART_REV]) {
  2694. case MT2063_B3:
  2695. def = MT2063B3_defaults;
  2696. break;
  2697. case MT2063_B1:
  2698. def = MT2063B1_defaults;
  2699. break;
  2700. case MT2063_B0:
  2701. def = MT2063B0_defaults;
  2702. break;
  2703. default:
  2704. status |= MT2063_TUNER_ID_ERR;
  2705. break;
  2706. }
  2707. while (MT2063_NO_ERROR(status) && *def) {
  2708. u8 reg = *def++;
  2709. u8 val = *def++;
  2710. status |=
  2711. MT2063_WriteSub(pInfo->hUserData, pInfo->address, reg, &val,
  2712. 1);
  2713. }
  2714. /* Wait for FIFF location to complete. */
  2715. if (MT2063_NO_ERROR(status)) {
  2716. u32 FCRUN = 1;
  2717. s32 maxReads = 10;
  2718. while (MT2063_NO_ERROR(status) && (FCRUN != 0)
  2719. && (maxReads-- > 0)) {
  2720. msleep(2);
  2721. status |= MT2063_ReadSub(pInfo->hUserData,
  2722. pInfo->address,
  2723. MT2063_REG_XO_STATUS,
  2724. &pInfo->
  2725. reg[MT2063_REG_XO_STATUS], 1);
  2726. FCRUN = (pInfo->reg[MT2063_REG_XO_STATUS] & 0x40) >> 6;
  2727. }
  2728. if (FCRUN != 0)
  2729. status |= MT2063_TUNER_INIT_ERR | MT2063_TUNER_TIMEOUT;
  2730. if (MT2063_NO_ERROR(status)) /* Re-read FIFFC value */
  2731. status |=
  2732. MT2063_ReadSub(pInfo->hUserData, pInfo->address,
  2733. MT2063_REG_FIFFC,
  2734. &pInfo->reg[MT2063_REG_FIFFC], 1);
  2735. }
  2736. /* Read back all the registers from the tuner */
  2737. if (MT2063_NO_ERROR(status))
  2738. status |= MT2063_ReadSub(pInfo->hUserData,
  2739. pInfo->address,
  2740. MT2063_REG_PART_REV,
  2741. pInfo->reg, MT2063_REG_END_REGS);
  2742. if (MT2063_NO_ERROR(status)) {
  2743. /* Initialize the tuner state. */
  2744. pInfo->tuner_id = pInfo->reg[MT2063_REG_PART_REV];
  2745. pInfo->AS_Data.f_ref = MT2063_REF_FREQ;
  2746. pInfo->AS_Data.f_if1_Center =
  2747. (pInfo->AS_Data.f_ref / 8) *
  2748. ((u32) pInfo->reg[MT2063_REG_FIFFC] + 640);
  2749. pInfo->AS_Data.f_if1_bw = MT2063_IF1_BW;
  2750. pInfo->AS_Data.f_out = 43750000UL;
  2751. pInfo->AS_Data.f_out_bw = 6750000UL;
  2752. pInfo->AS_Data.f_zif_bw = MT2063_ZIF_BW;
  2753. pInfo->AS_Data.f_LO1_Step = pInfo->AS_Data.f_ref / 64;
  2754. pInfo->AS_Data.f_LO2_Step = MT2063_TUNE_STEP_SIZE;
  2755. pInfo->AS_Data.maxH1 = MT2063_MAX_HARMONICS_1;
  2756. pInfo->AS_Data.maxH2 = MT2063_MAX_HARMONICS_2;
  2757. pInfo->AS_Data.f_min_LO_Separation = MT2063_MIN_LO_SEP;
  2758. pInfo->AS_Data.f_if1_Request = pInfo->AS_Data.f_if1_Center;
  2759. pInfo->AS_Data.f_LO1 = 2181000000UL;
  2760. pInfo->AS_Data.f_LO2 = 1486249786UL;
  2761. pInfo->f_IF1_actual = pInfo->AS_Data.f_if1_Center;
  2762. pInfo->AS_Data.f_in =
  2763. pInfo->AS_Data.f_LO1 - pInfo->f_IF1_actual;
  2764. pInfo->AS_Data.f_LO1_FracN_Avoid = MT2063_LO1_FRACN_AVOID;
  2765. pInfo->AS_Data.f_LO2_FracN_Avoid = MT2063_LO2_FRACN_AVOID;
  2766. pInfo->num_regs = MT2063_REG_END_REGS;
  2767. pInfo->AS_Data.avoidDECT = MT2063_AVOID_BOTH;
  2768. pInfo->ctfilt_sw = 0;
  2769. }
  2770. if (MT2063_NO_ERROR(status)) {
  2771. pInfo->CTFiltMax[0] = 69230000;
  2772. pInfo->CTFiltMax[1] = 105770000;
  2773. pInfo->CTFiltMax[2] = 140350000;
  2774. pInfo->CTFiltMax[3] = 177110000;
  2775. pInfo->CTFiltMax[4] = 212860000;
  2776. pInfo->CTFiltMax[5] = 241130000;
  2777. pInfo->CTFiltMax[6] = 274370000;
  2778. pInfo->CTFiltMax[7] = 309820000;
  2779. pInfo->CTFiltMax[8] = 342450000;
  2780. pInfo->CTFiltMax[9] = 378870000;
  2781. pInfo->CTFiltMax[10] = 416210000;
  2782. pInfo->CTFiltMax[11] = 456500000;
  2783. pInfo->CTFiltMax[12] = 495790000;
  2784. pInfo->CTFiltMax[13] = 534530000;
  2785. pInfo->CTFiltMax[14] = 572610000;
  2786. pInfo->CTFiltMax[15] = 598970000;
  2787. pInfo->CTFiltMax[16] = 635910000;
  2788. pInfo->CTFiltMax[17] = 672130000;
  2789. pInfo->CTFiltMax[18] = 714840000;
  2790. pInfo->CTFiltMax[19] = 739660000;
  2791. pInfo->CTFiltMax[20] = 770410000;
  2792. pInfo->CTFiltMax[21] = 814660000;
  2793. pInfo->CTFiltMax[22] = 846950000;
  2794. pInfo->CTFiltMax[23] = 867820000;
  2795. pInfo->CTFiltMax[24] = 915980000;
  2796. pInfo->CTFiltMax[25] = 947450000;
  2797. pInfo->CTFiltMax[26] = 983110000;
  2798. pInfo->CTFiltMax[27] = 1021630000;
  2799. pInfo->CTFiltMax[28] = 1061870000;
  2800. pInfo->CTFiltMax[29] = 1098330000;
  2801. pInfo->CTFiltMax[30] = 1138990000;
  2802. }
  2803. /*
  2804. ** Fetch the FCU osc value and use it and the fRef value to
  2805. ** scale all of the Band Max values
  2806. */
  2807. if (MT2063_NO_ERROR(status)) {
  2808. u32 fcu_osc;
  2809. u32 i;
  2810. pInfo->reg[MT2063_REG_CTUNE_CTRL] = 0x0A;
  2811. status |=
  2812. MT2063_WriteSub(pInfo->hUserData, pInfo->address,
  2813. MT2063_REG_CTUNE_CTRL,
  2814. &pInfo->reg[MT2063_REG_CTUNE_CTRL], 1);
  2815. /* Read the ClearTune filter calibration value */
  2816. status |=
  2817. MT2063_ReadSub(pInfo->hUserData, pInfo->address,
  2818. MT2063_REG_FIFFC,
  2819. &pInfo->reg[MT2063_REG_FIFFC], 1);
  2820. fcu_osc = pInfo->reg[MT2063_REG_FIFFC];
  2821. pInfo->reg[MT2063_REG_CTUNE_CTRL] = 0x00;
  2822. status |=
  2823. MT2063_WriteSub(pInfo->hUserData, pInfo->address,
  2824. MT2063_REG_CTUNE_CTRL,
  2825. &pInfo->reg[MT2063_REG_CTUNE_CTRL], 1);
  2826. /* Adjust each of the values in the ClearTune filter cross-over table */
  2827. for (i = 0; i < 31; i++) {
  2828. pInfo->CTFiltMax[i] =
  2829. (pInfo->CTFiltMax[i] / 768) * (fcu_osc + 640);
  2830. }
  2831. }
  2832. return (status);
  2833. }
  2834. /****************************************************************************
  2835. **
  2836. ** Name: MT2063_SetParam
  2837. **
  2838. ** Description: Sets a tuning algorithm parameter.
  2839. **
  2840. ** This function provides access to the internals of the
  2841. ** tuning algorithm. You can override many of the tuning
  2842. ** algorithm defaults using this function.
  2843. **
  2844. ** Parameters: h - Tuner handle (returned by MT2063_Open)
  2845. ** param - Tuning algorithm parameter
  2846. ** (see enum MT2063_Param)
  2847. ** nValue - value to be set
  2848. **
  2849. ** param Description
  2850. ** ---------------------- --------------------------------
  2851. ** MT2063_SRO_FREQ crystal frequency
  2852. ** MT2063_STEPSIZE minimum tuning step size
  2853. ** MT2063_LO1_FREQ LO1 frequency
  2854. ** MT2063_LO1_STEPSIZE LO1 minimum step size
  2855. ** MT2063_LO1_FRACN_AVOID LO1 FracN keep-out region
  2856. ** MT2063_IF1_REQUEST Requested 1st IF
  2857. ** MT2063_ZIF_BW zero-IF bandwidth
  2858. ** MT2063_LO2_FREQ LO2 frequency
  2859. ** MT2063_LO2_STEPSIZE LO2 minimum step size
  2860. ** MT2063_LO2_FRACN_AVOID LO2 FracN keep-out region
  2861. ** MT2063_OUTPUT_FREQ output center frequency
  2862. ** MT2063_OUTPUT_BW output bandwidth
  2863. ** MT2063_LO_SEPARATION min inter-tuner LO separation
  2864. ** MT2063_MAX_HARM1 max # of intra-tuner harmonics
  2865. ** MT2063_MAX_HARM2 max # of inter-tuner harmonics
  2866. ** MT2063_RCVR_MODE Predefined modes
  2867. ** MT2063_LNA_RIN Set LNA Rin (*)
  2868. ** MT2063_LNA_TGT Set target power level at LNA (*)
  2869. ** MT2063_PD1_TGT Set target power level at PD1 (*)
  2870. ** MT2063_PD2_TGT Set target power level at PD2 (*)
  2871. ** MT2063_ACLNA_MAX LNA attenuator limit (*)
  2872. ** MT2063_ACRF_MAX RF attenuator limit (*)
  2873. ** MT2063_ACFIF_MAX FIF attenuator limit (*)
  2874. ** MT2063_DNC_OUTPUT_ENABLE DNC output selection
  2875. ** MT2063_VGAGC VGA gain code
  2876. ** MT2063_VGAOI VGA output current
  2877. ** MT2063_TAGC TAGC setting
  2878. ** MT2063_AMPGC AMP gain code
  2879. ** MT2063_AVOID_DECT Avoid DECT Frequencies
  2880. ** MT2063_CTFILT_SW Cleartune filter selection
  2881. **
  2882. ** (*) This parameter is set by MT2063_RCVR_MODE, do not call
  2883. ** additionally.
  2884. **
  2885. ** Usage: status |= MT2063_SetParam(hMT2063,
  2886. ** MT2063_STEPSIZE,
  2887. ** 50000);
  2888. **
  2889. ** Returns: status:
  2890. ** MT_OK - No errors
  2891. ** MT_INV_HANDLE - Invalid tuner handle
  2892. ** MT_ARG_NULL - Null pointer argument passed
  2893. ** MT_ARG_RANGE - Invalid parameter requested
  2894. ** or set value out of range
  2895. ** or non-writable parameter
  2896. **
  2897. ** Dependencies: USERS MUST CALL MT2063_Open() FIRST!
  2898. **
  2899. ** See Also: MT2063_GetParam, MT2063_Open
  2900. **
  2901. ** Revision History:
  2902. **
  2903. ** SCR Date Author Description
  2904. ** -------------------------------------------------------------------------
  2905. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  2906. ** 154 09-13-2007 RSK Ver 1.05: Get/SetParam changes for LOx_FREQ
  2907. ** 10-31-2007 PINZ Ver 1.08: Get/SetParam add VGAGC, VGAOI, AMPGC, TAGC
  2908. ** 04-18-2008 PINZ Ver 1.15: Add SetParam LNARIN & PDxTGT
  2909. ** Split SetParam up to ACLNA / ACLNA_MAX
  2910. ** removed ACLNA_INRC/DECR (+RF & FIF)
  2911. ** removed GCUAUTO / BYPATNDN/UP
  2912. ** 175 I 06-06-2008 PINZ Ver 1.16: Add control to avoid US DECT freqs.
  2913. ** 175 I 06-19-2008 RSK Ver 1.17: Refactor DECT control to SpurAvoid.
  2914. ** 06-24-2008 PINZ Ver 1.18: Add Get/SetParam CTFILT_SW
  2915. **
  2916. ****************************************************************************/
  2917. static u32 MT2063_SetParam(void *h, enum MT2063_Param param, u32 nValue)
  2918. {
  2919. u32 status = MT2063_OK; /* Status to be returned */
  2920. u8 val = 0;
  2921. struct MT2063_Info_t *pInfo = (struct MT2063_Info_t *)h;
  2922. /* Verify that the handle passed points to a valid tuner */
  2923. if (MT2063_IsValidHandle(pInfo) == 0)
  2924. status |= MT2063_INV_HANDLE;
  2925. if (MT2063_NO_ERROR(status)) {
  2926. switch (param) {
  2927. /* crystal frequency */
  2928. case MT2063_SRO_FREQ:
  2929. pInfo->AS_Data.f_ref = nValue;
  2930. pInfo->AS_Data.f_LO1_FracN_Avoid = 0;
  2931. pInfo->AS_Data.f_LO2_FracN_Avoid = nValue / 80 - 1;
  2932. pInfo->AS_Data.f_LO1_Step = nValue / 64;
  2933. pInfo->AS_Data.f_if1_Center =
  2934. (pInfo->AS_Data.f_ref / 8) *
  2935. (pInfo->reg[MT2063_REG_FIFFC] + 640);
  2936. break;
  2937. /* minimum tuning step size */
  2938. case MT2063_STEPSIZE:
  2939. pInfo->AS_Data.f_LO2_Step = nValue;
  2940. break;
  2941. /* LO1 frequency */
  2942. case MT2063_LO1_FREQ:
  2943. {
  2944. /* Note: LO1 and LO2 are BOTH written at toggle of LDLOos */
  2945. /* Capture the Divider and Numerator portions of other LO */
  2946. u8 tempLO2CQ[3];
  2947. u8 tempLO2C[3];
  2948. u8 tmpOneShot;
  2949. u32 Div, FracN;
  2950. u8 restore = 0;
  2951. /* Buffer the queue for restoration later and get actual LO2 values. */
  2952. status |=
  2953. MT2063_ReadSub(pInfo->hUserData,
  2954. pInfo->address,
  2955. MT2063_REG_LO2CQ_1,
  2956. &(tempLO2CQ[0]), 3);
  2957. status |=
  2958. MT2063_ReadSub(pInfo->hUserData,
  2959. pInfo->address,
  2960. MT2063_REG_LO2C_1,
  2961. &(tempLO2C[0]), 3);
  2962. /* clear the one-shot bits */
  2963. tempLO2CQ[2] = tempLO2CQ[2] & 0x0F;
  2964. tempLO2C[2] = tempLO2C[2] & 0x0F;
  2965. /* only write the queue values if they are different from the actual. */
  2966. if ((tempLO2CQ[0] != tempLO2C[0]) ||
  2967. (tempLO2CQ[1] != tempLO2C[1]) ||
  2968. (tempLO2CQ[2] != tempLO2C[2])) {
  2969. /* put actual LO2 value into queue (with 0 in one-shot bits) */
  2970. status |=
  2971. MT2063_WriteSub(pInfo->hUserData,
  2972. pInfo->address,
  2973. MT2063_REG_LO2CQ_1,
  2974. &(tempLO2C[0]), 3);
  2975. if (status == MT2063_OK) {
  2976. /* cache the bytes just written. */
  2977. pInfo->reg[MT2063_REG_LO2CQ_1] =
  2978. tempLO2C[0];
  2979. pInfo->reg[MT2063_REG_LO2CQ_2] =
  2980. tempLO2C[1];
  2981. pInfo->reg[MT2063_REG_LO2CQ_3] =
  2982. tempLO2C[2];
  2983. }
  2984. restore = 1;
  2985. }
  2986. /* Calculate the Divider and Numberator components of LO1 */
  2987. status =
  2988. MT2063_CalcLO1Mult(&Div, &FracN, nValue,
  2989. pInfo->AS_Data.f_ref /
  2990. 64,
  2991. pInfo->AS_Data.f_ref);
  2992. pInfo->reg[MT2063_REG_LO1CQ_1] =
  2993. (u8) (Div & 0x00FF);
  2994. pInfo->reg[MT2063_REG_LO1CQ_2] =
  2995. (u8) (FracN);
  2996. status |=
  2997. MT2063_WriteSub(pInfo->hUserData,
  2998. pInfo->address,
  2999. MT2063_REG_LO1CQ_1,
  3000. &pInfo->
  3001. reg[MT2063_REG_LO1CQ_1], 2);
  3002. /* set the one-shot bit to load the pair of LO values */
  3003. tmpOneShot = tempLO2CQ[2] | 0xE0;
  3004. status |=
  3005. MT2063_WriteSub(pInfo->hUserData,
  3006. pInfo->address,
  3007. MT2063_REG_LO2CQ_3,
  3008. &tmpOneShot, 1);
  3009. /* only restore the queue values if they were different from the actual. */
  3010. if (restore) {
  3011. /* put actual LO2 value into queue (0 in one-shot bits) */
  3012. status |=
  3013. MT2063_WriteSub(pInfo->hUserData,
  3014. pInfo->address,
  3015. MT2063_REG_LO2CQ_1,
  3016. &(tempLO2CQ[0]), 3);
  3017. /* cache the bytes just written. */
  3018. pInfo->reg[MT2063_REG_LO2CQ_1] =
  3019. tempLO2CQ[0];
  3020. pInfo->reg[MT2063_REG_LO2CQ_2] =
  3021. tempLO2CQ[1];
  3022. pInfo->reg[MT2063_REG_LO2CQ_3] =
  3023. tempLO2CQ[2];
  3024. }
  3025. MT2063_GetParam(pInfo->hUserData,
  3026. MT2063_LO1_FREQ,
  3027. &pInfo->AS_Data.f_LO1);
  3028. }
  3029. break;
  3030. /* LO1 minimum step size */
  3031. case MT2063_LO1_STEPSIZE:
  3032. pInfo->AS_Data.f_LO1_Step = nValue;
  3033. break;
  3034. /* LO1 FracN keep-out region */
  3035. case MT2063_LO1_FRACN_AVOID_PARAM:
  3036. pInfo->AS_Data.f_LO1_FracN_Avoid = nValue;
  3037. break;
  3038. /* Requested 1st IF */
  3039. case MT2063_IF1_REQUEST:
  3040. pInfo->AS_Data.f_if1_Request = nValue;
  3041. break;
  3042. /* zero-IF bandwidth */
  3043. case MT2063_ZIF_BW:
  3044. pInfo->AS_Data.f_zif_bw = nValue;
  3045. break;
  3046. /* LO2 frequency */
  3047. case MT2063_LO2_FREQ:
  3048. {
  3049. /* Note: LO1 and LO2 are BOTH written at toggle of LDLOos */
  3050. /* Capture the Divider and Numerator portions of other LO */
  3051. u8 tempLO1CQ[2];
  3052. u8 tempLO1C[2];
  3053. u32 Div2;
  3054. u32 FracN2;
  3055. u8 tmpOneShot;
  3056. u8 restore = 0;
  3057. /* Buffer the queue for restoration later and get actual LO2 values. */
  3058. status |=
  3059. MT2063_ReadSub(pInfo->hUserData,
  3060. pInfo->address,
  3061. MT2063_REG_LO1CQ_1,
  3062. &(tempLO1CQ[0]), 2);
  3063. status |=
  3064. MT2063_ReadSub(pInfo->hUserData,
  3065. pInfo->address,
  3066. MT2063_REG_LO1C_1,
  3067. &(tempLO1C[0]), 2);
  3068. /* only write the queue values if they are different from the actual. */
  3069. if ((tempLO1CQ[0] != tempLO1C[0])
  3070. || (tempLO1CQ[1] != tempLO1C[1])) {
  3071. /* put actual LO1 value into queue */
  3072. status |=
  3073. MT2063_WriteSub(pInfo->hUserData,
  3074. pInfo->address,
  3075. MT2063_REG_LO1CQ_1,
  3076. &(tempLO1C[0]), 2);
  3077. /* cache the bytes just written. */
  3078. pInfo->reg[MT2063_REG_LO1CQ_1] =
  3079. tempLO1C[0];
  3080. pInfo->reg[MT2063_REG_LO1CQ_2] =
  3081. tempLO1C[1];
  3082. restore = 1;
  3083. }
  3084. /* Calculate the Divider and Numberator components of LO2 */
  3085. status =
  3086. MT2063_CalcLO2Mult(&Div2, &FracN2, nValue,
  3087. pInfo->AS_Data.f_ref /
  3088. 8191,
  3089. pInfo->AS_Data.f_ref);
  3090. pInfo->reg[MT2063_REG_LO2CQ_1] =
  3091. (u8) ((Div2 << 1) |
  3092. ((FracN2 >> 12) & 0x01)) & 0xFF;
  3093. pInfo->reg[MT2063_REG_LO2CQ_2] =
  3094. (u8) ((FracN2 >> 4) & 0xFF);
  3095. pInfo->reg[MT2063_REG_LO2CQ_3] =
  3096. (u8) ((FracN2 & 0x0F));
  3097. status |=
  3098. MT2063_WriteSub(pInfo->hUserData,
  3099. pInfo->address,
  3100. MT2063_REG_LO1CQ_1,
  3101. &pInfo->
  3102. reg[MT2063_REG_LO1CQ_1], 3);
  3103. /* set the one-shot bit to load the LO values */
  3104. tmpOneShot =
  3105. pInfo->reg[MT2063_REG_LO2CQ_3] | 0xE0;
  3106. status |=
  3107. MT2063_WriteSub(pInfo->hUserData,
  3108. pInfo->address,
  3109. MT2063_REG_LO2CQ_3,
  3110. &tmpOneShot, 1);
  3111. /* only restore LO1 queue value if they were different from the actual. */
  3112. if (restore) {
  3113. /* put previous LO1 queue value back into queue */
  3114. status |=
  3115. MT2063_WriteSub(pInfo->hUserData,
  3116. pInfo->address,
  3117. MT2063_REG_LO1CQ_1,
  3118. &(tempLO1CQ[0]), 2);
  3119. /* cache the bytes just written. */
  3120. pInfo->reg[MT2063_REG_LO1CQ_1] =
  3121. tempLO1CQ[0];
  3122. pInfo->reg[MT2063_REG_LO1CQ_2] =
  3123. tempLO1CQ[1];
  3124. }
  3125. MT2063_GetParam(pInfo->hUserData,
  3126. MT2063_LO2_FREQ,
  3127. &pInfo->AS_Data.f_LO2);
  3128. }
  3129. break;
  3130. /* LO2 minimum step size */
  3131. case MT2063_LO2_STEPSIZE:
  3132. pInfo->AS_Data.f_LO2_Step = nValue;
  3133. break;
  3134. /* LO2 FracN keep-out region */
  3135. case MT2063_LO2_FRACN_AVOID:
  3136. pInfo->AS_Data.f_LO2_FracN_Avoid = nValue;
  3137. break;
  3138. /* output center frequency */
  3139. case MT2063_OUTPUT_FREQ:
  3140. pInfo->AS_Data.f_out = nValue;
  3141. break;
  3142. /* output bandwidth */
  3143. case MT2063_OUTPUT_BW:
  3144. pInfo->AS_Data.f_out_bw = nValue + 750000;
  3145. break;
  3146. /* min inter-tuner LO separation */
  3147. case MT2063_LO_SEPARATION:
  3148. pInfo->AS_Data.f_min_LO_Separation = nValue;
  3149. break;
  3150. /* max # of intra-tuner harmonics */
  3151. case MT2063_MAX_HARM1:
  3152. pInfo->AS_Data.maxH1 = nValue;
  3153. break;
  3154. /* max # of inter-tuner harmonics */
  3155. case MT2063_MAX_HARM2:
  3156. pInfo->AS_Data.maxH2 = nValue;
  3157. break;
  3158. case MT2063_RCVR_MODE:
  3159. status |=
  3160. MT2063_SetReceiverMode(pInfo,
  3161. (enum MT2063_RCVR_MODES)
  3162. nValue);
  3163. break;
  3164. /* Set LNA Rin -- nValue is desired value */
  3165. case MT2063_LNA_RIN:
  3166. val =
  3167. (pInfo->
  3168. reg[MT2063_REG_CTRL_2C] & (u8) ~ 0x03) |
  3169. (nValue & 0x03);
  3170. if (pInfo->reg[MT2063_REG_CTRL_2C] != val) {
  3171. status |=
  3172. MT2063_SetReg(pInfo, MT2063_REG_CTRL_2C,
  3173. val);
  3174. }
  3175. break;
  3176. /* Set target power level at LNA -- nValue is desired value */
  3177. case MT2063_LNA_TGT:
  3178. val =
  3179. (pInfo->
  3180. reg[MT2063_REG_LNA_TGT] & (u8) ~ 0x3F) |
  3181. (nValue & 0x3F);
  3182. if (pInfo->reg[MT2063_REG_LNA_TGT] != val) {
  3183. status |=
  3184. MT2063_SetReg(pInfo, MT2063_REG_LNA_TGT,
  3185. val);
  3186. }
  3187. break;
  3188. /* Set target power level at PD1 -- nValue is desired value */
  3189. case MT2063_PD1_TGT:
  3190. val =
  3191. (pInfo->
  3192. reg[MT2063_REG_PD1_TGT] & (u8) ~ 0x3F) |
  3193. (nValue & 0x3F);
  3194. if (pInfo->reg[MT2063_REG_PD1_TGT] != val) {
  3195. status |=
  3196. MT2063_SetReg(pInfo, MT2063_REG_PD1_TGT,
  3197. val);
  3198. }
  3199. break;
  3200. /* Set target power level at PD2 -- nValue is desired value */
  3201. case MT2063_PD2_TGT:
  3202. val =
  3203. (pInfo->
  3204. reg[MT2063_REG_PD2_TGT] & (u8) ~ 0x3F) |
  3205. (nValue & 0x3F);
  3206. if (pInfo->reg[MT2063_REG_PD2_TGT] != val) {
  3207. status |=
  3208. MT2063_SetReg(pInfo, MT2063_REG_PD2_TGT,
  3209. val);
  3210. }
  3211. break;
  3212. /* Set LNA atten limit -- nValue is desired value */
  3213. case MT2063_ACLNA_MAX:
  3214. val =
  3215. (pInfo->
  3216. reg[MT2063_REG_LNA_OV] & (u8) ~ 0x1F) | (nValue
  3217. &
  3218. 0x1F);
  3219. if (pInfo->reg[MT2063_REG_LNA_OV] != val) {
  3220. status |=
  3221. MT2063_SetReg(pInfo, MT2063_REG_LNA_OV,
  3222. val);
  3223. }
  3224. break;
  3225. /* Set RF atten limit -- nValue is desired value */
  3226. case MT2063_ACRF_MAX:
  3227. val =
  3228. (pInfo->
  3229. reg[MT2063_REG_RF_OV] & (u8) ~ 0x1F) | (nValue
  3230. &
  3231. 0x1F);
  3232. if (pInfo->reg[MT2063_REG_RF_OV] != val) {
  3233. status |=
  3234. MT2063_SetReg(pInfo, MT2063_REG_RF_OV, val);
  3235. }
  3236. break;
  3237. /* Set FIF atten limit -- nValue is desired value, max. 5 if no B3 */
  3238. case MT2063_ACFIF_MAX:
  3239. if (pInfo->reg[MT2063_REG_PART_REV] != MT2063_B3
  3240. && nValue > 5)
  3241. nValue = 5;
  3242. val =
  3243. (pInfo->
  3244. reg[MT2063_REG_FIF_OV] & (u8) ~ 0x1F) | (nValue
  3245. &
  3246. 0x1F);
  3247. if (pInfo->reg[MT2063_REG_FIF_OV] != val) {
  3248. status |=
  3249. MT2063_SetReg(pInfo, MT2063_REG_FIF_OV,
  3250. val);
  3251. }
  3252. break;
  3253. case MT2063_DNC_OUTPUT_ENABLE:
  3254. /* selects, which DNC output is used */
  3255. switch ((enum MT2063_DNC_Output_Enable)nValue) {
  3256. case MT2063_DNC_NONE:
  3257. {
  3258. val = (pInfo->reg[MT2063_REG_DNC_GAIN] & 0xFC) | 0x03; /* Set DNC1GC=3 */
  3259. if (pInfo->reg[MT2063_REG_DNC_GAIN] !=
  3260. val)
  3261. status |=
  3262. MT2063_SetReg(h,
  3263. MT2063_REG_DNC_GAIN,
  3264. val);
  3265. val = (pInfo->reg[MT2063_REG_VGA_GAIN] & 0xFC) | 0x03; /* Set DNC2GC=3 */
  3266. if (pInfo->reg[MT2063_REG_VGA_GAIN] !=
  3267. val)
  3268. status |=
  3269. MT2063_SetReg(h,
  3270. MT2063_REG_VGA_GAIN,
  3271. val);
  3272. val = (pInfo->reg[MT2063_REG_RSVD_20] & ~0x40); /* Set PD2MUX=0 */
  3273. if (pInfo->reg[MT2063_REG_RSVD_20] !=
  3274. val)
  3275. status |=
  3276. MT2063_SetReg(h,
  3277. MT2063_REG_RSVD_20,
  3278. val);
  3279. break;
  3280. }
  3281. case MT2063_DNC_1:
  3282. {
  3283. val = (pInfo->reg[MT2063_REG_DNC_GAIN] & 0xFC) | (DNC1GC[pInfo->rcvr_mode] & 0x03); /* Set DNC1GC=x */
  3284. if (pInfo->reg[MT2063_REG_DNC_GAIN] !=
  3285. val)
  3286. status |=
  3287. MT2063_SetReg(h,
  3288. MT2063_REG_DNC_GAIN,
  3289. val);
  3290. val = (pInfo->reg[MT2063_REG_VGA_GAIN] & 0xFC) | 0x03; /* Set DNC2GC=3 */
  3291. if (pInfo->reg[MT2063_REG_VGA_GAIN] !=
  3292. val)
  3293. status |=
  3294. MT2063_SetReg(h,
  3295. MT2063_REG_VGA_GAIN,
  3296. val);
  3297. val = (pInfo->reg[MT2063_REG_RSVD_20] & ~0x40); /* Set PD2MUX=0 */
  3298. if (pInfo->reg[MT2063_REG_RSVD_20] !=
  3299. val)
  3300. status |=
  3301. MT2063_SetReg(h,
  3302. MT2063_REG_RSVD_20,
  3303. val);
  3304. break;
  3305. }
  3306. case MT2063_DNC_2:
  3307. {
  3308. val = (pInfo->reg[MT2063_REG_DNC_GAIN] & 0xFC) | 0x03; /* Set DNC1GC=3 */
  3309. if (pInfo->reg[MT2063_REG_DNC_GAIN] !=
  3310. val)
  3311. status |=
  3312. MT2063_SetReg(h,
  3313. MT2063_REG_DNC_GAIN,
  3314. val);
  3315. val = (pInfo->reg[MT2063_REG_VGA_GAIN] & 0xFC) | (DNC2GC[pInfo->rcvr_mode] & 0x03); /* Set DNC2GC=x */
  3316. if (pInfo->reg[MT2063_REG_VGA_GAIN] !=
  3317. val)
  3318. status |=
  3319. MT2063_SetReg(h,
  3320. MT2063_REG_VGA_GAIN,
  3321. val);
  3322. val = (pInfo->reg[MT2063_REG_RSVD_20] | 0x40); /* Set PD2MUX=1 */
  3323. if (pInfo->reg[MT2063_REG_RSVD_20] !=
  3324. val)
  3325. status |=
  3326. MT2063_SetReg(h,
  3327. MT2063_REG_RSVD_20,
  3328. val);
  3329. break;
  3330. }
  3331. case MT2063_DNC_BOTH:
  3332. {
  3333. val = (pInfo->reg[MT2063_REG_DNC_GAIN] & 0xFC) | (DNC1GC[pInfo->rcvr_mode] & 0x03); /* Set DNC1GC=x */
  3334. if (pInfo->reg[MT2063_REG_DNC_GAIN] !=
  3335. val)
  3336. status |=
  3337. MT2063_SetReg(h,
  3338. MT2063_REG_DNC_GAIN,
  3339. val);
  3340. val = (pInfo->reg[MT2063_REG_VGA_GAIN] & 0xFC) | (DNC2GC[pInfo->rcvr_mode] & 0x03); /* Set DNC2GC=x */
  3341. if (pInfo->reg[MT2063_REG_VGA_GAIN] !=
  3342. val)
  3343. status |=
  3344. MT2063_SetReg(h,
  3345. MT2063_REG_VGA_GAIN,
  3346. val);
  3347. val = (pInfo->reg[MT2063_REG_RSVD_20] | 0x40); /* Set PD2MUX=1 */
  3348. if (pInfo->reg[MT2063_REG_RSVD_20] !=
  3349. val)
  3350. status |=
  3351. MT2063_SetReg(h,
  3352. MT2063_REG_RSVD_20,
  3353. val);
  3354. break;
  3355. }
  3356. default:
  3357. break;
  3358. }
  3359. break;
  3360. case MT2063_VGAGC:
  3361. /* Set VGA gain code */
  3362. val =
  3363. (pInfo->
  3364. reg[MT2063_REG_VGA_GAIN] & (u8) ~ 0x0C) |
  3365. ((nValue & 0x03) << 2);
  3366. if (pInfo->reg[MT2063_REG_VGA_GAIN] != val) {
  3367. status |=
  3368. MT2063_SetReg(pInfo, MT2063_REG_VGA_GAIN,
  3369. val);
  3370. }
  3371. break;
  3372. case MT2063_VGAOI:
  3373. /* Set VGA bias current */
  3374. val =
  3375. (pInfo->
  3376. reg[MT2063_REG_RSVD_31] & (u8) ~ 0x07) |
  3377. (nValue & 0x07);
  3378. if (pInfo->reg[MT2063_REG_RSVD_31] != val) {
  3379. status |=
  3380. MT2063_SetReg(pInfo, MT2063_REG_RSVD_31,
  3381. val);
  3382. }
  3383. break;
  3384. case MT2063_TAGC:
  3385. /* Set TAGC */
  3386. val =
  3387. (pInfo->
  3388. reg[MT2063_REG_RSVD_1E] & (u8) ~ 0x03) |
  3389. (nValue & 0x03);
  3390. if (pInfo->reg[MT2063_REG_RSVD_1E] != val) {
  3391. status |=
  3392. MT2063_SetReg(pInfo, MT2063_REG_RSVD_1E,
  3393. val);
  3394. }
  3395. break;
  3396. case MT2063_AMPGC:
  3397. /* Set Amp gain code */
  3398. val =
  3399. (pInfo->
  3400. reg[MT2063_REG_TEMP_SEL] & (u8) ~ 0x03) |
  3401. (nValue & 0x03);
  3402. if (pInfo->reg[MT2063_REG_TEMP_SEL] != val) {
  3403. status |=
  3404. MT2063_SetReg(pInfo, MT2063_REG_TEMP_SEL,
  3405. val);
  3406. }
  3407. break;
  3408. /* Avoid DECT Frequencies */
  3409. case MT2063_AVOID_DECT:
  3410. {
  3411. enum MT2063_DECT_Avoid_Type newAvoidSetting =
  3412. (enum MT2063_DECT_Avoid_Type)nValue;
  3413. if ((newAvoidSetting >=
  3414. MT2063_NO_DECT_AVOIDANCE)
  3415. && (newAvoidSetting <= MT2063_AVOID_BOTH)) {
  3416. pInfo->AS_Data.avoidDECT =
  3417. newAvoidSetting;
  3418. }
  3419. }
  3420. break;
  3421. /* Cleartune filter selection: 0 - by IC (default), 1 - by software */
  3422. case MT2063_CTFILT_SW:
  3423. pInfo->ctfilt_sw = (nValue & 0x01);
  3424. break;
  3425. /* These parameters are read-only */
  3426. case MT2063_IC_ADDR:
  3427. case MT2063_MAX_OPEN:
  3428. case MT2063_NUM_OPEN:
  3429. case MT2063_INPUT_FREQ:
  3430. case MT2063_IF1_ACTUAL:
  3431. case MT2063_IF1_CENTER:
  3432. case MT2063_IF1_BW:
  3433. case MT2063_AS_ALG:
  3434. case MT2063_EXCL_ZONES:
  3435. case MT2063_SPUR_AVOIDED:
  3436. case MT2063_NUM_SPURS:
  3437. case MT2063_SPUR_PRESENT:
  3438. case MT2063_ACLNA:
  3439. case MT2063_ACRF:
  3440. case MT2063_ACFIF:
  3441. case MT2063_EOP:
  3442. default:
  3443. status |= MT2063_ARG_RANGE;
  3444. }
  3445. }
  3446. return (status);
  3447. }
  3448. /****************************************************************************
  3449. **
  3450. ** Name: MT2063_ClearPowerMaskBits
  3451. **
  3452. ** Description: Clears the power-down mask bits for various sections of
  3453. ** the MT2063
  3454. **
  3455. ** Parameters: h - Tuner handle (returned by MT2063_Open)
  3456. ** Bits - Mask bits to be cleared.
  3457. **
  3458. ** See definition of MT2063_Mask_Bits type for description
  3459. ** of each of the power bits.
  3460. **
  3461. ** Returns: status:
  3462. ** MT_OK - No errors
  3463. ** MT_INV_HANDLE - Invalid tuner handle
  3464. ** MT_COMM_ERR - Serial bus communications error
  3465. **
  3466. ** Dependencies: USERS MUST CALL MT2063_Open() FIRST!
  3467. **
  3468. ** Revision History:
  3469. **
  3470. ** SCR Date Author Description
  3471. ** -------------------------------------------------------------------------
  3472. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  3473. **
  3474. ****************************************************************************/
  3475. static u32 MT2063_ClearPowerMaskBits(struct MT2063_Info_t *pInfo, enum MT2063_Mask_Bits Bits)
  3476. {
  3477. u32 status = MT2063_OK; /* Status to be returned */
  3478. /* Verify that the handle passed points to a valid tuner */
  3479. if (MT2063_IsValidHandle(pInfo) == 0)
  3480. status = MT2063_INV_HANDLE;
  3481. else {
  3482. Bits = (enum MT2063_Mask_Bits)(Bits & MT2063_ALL_SD); /* Only valid bits for this tuner */
  3483. if ((Bits & 0xFF00) != 0) {
  3484. pInfo->reg[MT2063_REG_PWR_2] &= ~(u8) (Bits >> 8);
  3485. status |=
  3486. MT2063_WriteSub(pInfo->hUserData, pInfo->address,
  3487. MT2063_REG_PWR_2,
  3488. &pInfo->reg[MT2063_REG_PWR_2], 1);
  3489. }
  3490. if ((Bits & 0xFF) != 0) {
  3491. pInfo->reg[MT2063_REG_PWR_1] &= ~(u8) (Bits & 0xFF);
  3492. status |=
  3493. MT2063_WriteSub(pInfo->hUserData, pInfo->address,
  3494. MT2063_REG_PWR_1,
  3495. &pInfo->reg[MT2063_REG_PWR_1], 1);
  3496. }
  3497. }
  3498. return (status);
  3499. }
  3500. /****************************************************************************
  3501. **
  3502. ** Name: MT2063_SoftwareShutdown
  3503. **
  3504. ** Description: Enables or disables software shutdown function. When
  3505. ** Shutdown==1, any section whose power mask is set will be
  3506. ** shutdown.
  3507. **
  3508. ** Parameters: h - Tuner handle (returned by MT2063_Open)
  3509. ** Shutdown - 1 = shutdown the masked sections, otherwise
  3510. ** power all sections on
  3511. **
  3512. ** Returns: status:
  3513. ** MT_OK - No errors
  3514. ** MT_INV_HANDLE - Invalid tuner handle
  3515. ** MT_COMM_ERR - Serial bus communications error
  3516. **
  3517. ** Dependencies: USERS MUST CALL MT2063_Open() FIRST!
  3518. **
  3519. ** Revision History:
  3520. **
  3521. ** SCR Date Author Description
  3522. ** -------------------------------------------------------------------------
  3523. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  3524. ** 01-03-2008 PINZ Ver 1.xx: Added a trigger of BYPATNUP for
  3525. ** correct wakeup of the LNA
  3526. **
  3527. ****************************************************************************/
  3528. static u32 MT2063_SoftwareShutdown(struct MT2063_Info_t *pInfo, u8 Shutdown)
  3529. {
  3530. u32 status = MT2063_OK; /* Status to be returned */
  3531. /* Verify that the handle passed points to a valid tuner */
  3532. if (MT2063_IsValidHandle(pInfo) == 0) {
  3533. status = MT2063_INV_HANDLE;
  3534. } else {
  3535. if (Shutdown == 1)
  3536. pInfo->reg[MT2063_REG_PWR_1] |= 0x04; /* Turn the bit on */
  3537. else
  3538. pInfo->reg[MT2063_REG_PWR_1] &= ~0x04; /* Turn off the bit */
  3539. status |=
  3540. MT2063_WriteSub(pInfo->hUserData, pInfo->address,
  3541. MT2063_REG_PWR_1,
  3542. &pInfo->reg[MT2063_REG_PWR_1], 1);
  3543. if (Shutdown != 1) {
  3544. pInfo->reg[MT2063_REG_BYP_CTRL] =
  3545. (pInfo->reg[MT2063_REG_BYP_CTRL] & 0x9F) | 0x40;
  3546. status |=
  3547. MT2063_WriteSub(pInfo->hUserData, pInfo->address,
  3548. MT2063_REG_BYP_CTRL,
  3549. &pInfo->reg[MT2063_REG_BYP_CTRL],
  3550. 1);
  3551. pInfo->reg[MT2063_REG_BYP_CTRL] =
  3552. (pInfo->reg[MT2063_REG_BYP_CTRL] & 0x9F);
  3553. status |=
  3554. MT2063_WriteSub(pInfo->hUserData, pInfo->address,
  3555. MT2063_REG_BYP_CTRL,
  3556. &pInfo->reg[MT2063_REG_BYP_CTRL],
  3557. 1);
  3558. }
  3559. }
  3560. return (status);
  3561. }
  3562. /****************************************************************************
  3563. **
  3564. ** Name: MT2063_SetReg
  3565. **
  3566. ** Description: Sets an MT2063 register.
  3567. **
  3568. ** Parameters: h - Tuner handle (returned by MT2063_Open)
  3569. ** reg - MT2063 register/subaddress location
  3570. ** val - MT2063 register/subaddress value
  3571. **
  3572. ** Returns: status:
  3573. ** MT_OK - No errors
  3574. ** MT_COMM_ERR - Serial bus communications error
  3575. ** MT_INV_HANDLE - Invalid tuner handle
  3576. ** MT_ARG_RANGE - Argument out of range
  3577. **
  3578. ** Dependencies: USERS MUST CALL MT2063_Open() FIRST!
  3579. **
  3580. ** Use this function if you need to override a default
  3581. ** register value
  3582. **
  3583. ** Revision History:
  3584. **
  3585. ** SCR Date Author Description
  3586. ** -------------------------------------------------------------------------
  3587. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  3588. **
  3589. ****************************************************************************/
  3590. static u32 MT2063_SetReg(void *h, u8 reg, u8 val)
  3591. {
  3592. u32 status = MT2063_OK; /* Status to be returned */
  3593. struct MT2063_Info_t *pInfo = (struct MT2063_Info_t *)h;
  3594. /* Verify that the handle passed points to a valid tuner */
  3595. if (MT2063_IsValidHandle(pInfo) == 0)
  3596. status |= MT2063_INV_HANDLE;
  3597. if (reg >= MT2063_REG_END_REGS)
  3598. status |= MT2063_ARG_RANGE;
  3599. if (MT2063_NO_ERROR(status)) {
  3600. status |=
  3601. MT2063_WriteSub(pInfo->hUserData, pInfo->address, reg, &val,
  3602. 1);
  3603. if (MT2063_NO_ERROR(status))
  3604. pInfo->reg[reg] = val;
  3605. }
  3606. return (status);
  3607. }
  3608. static u32 MT2063_Round_fLO(u32 f_LO, u32 f_LO_Step, u32 f_ref)
  3609. {
  3610. return f_ref * (f_LO / f_ref)
  3611. + f_LO_Step * (((f_LO % f_ref) + (f_LO_Step / 2)) / f_LO_Step);
  3612. }
  3613. /****************************************************************************
  3614. **
  3615. ** Name: fLO_FractionalTerm
  3616. **
  3617. ** Description: Calculates the portion contributed by FracN / denom.
  3618. **
  3619. ** This function preserves maximum precision without
  3620. ** risk of overflow. It accurately calculates
  3621. ** f_ref * num / denom to within 1 HZ with fixed math.
  3622. **
  3623. ** Parameters: num - Fractional portion of the multiplier
  3624. ** denom - denominator portion of the ratio
  3625. ** This routine successfully handles denom values
  3626. ** up to and including 2^18.
  3627. ** f_Ref - SRO frequency. This calculation handles
  3628. ** f_ref as two separate 14-bit fields.
  3629. ** Therefore, a maximum value of 2^28-1
  3630. ** may safely be used for f_ref. This is
  3631. ** the genesis of the magic number "14" and the
  3632. ** magic mask value of 0x03FFF.
  3633. **
  3634. ** Returns: f_ref * num / denom
  3635. **
  3636. ** Revision History:
  3637. **
  3638. ** SCR Date Author Description
  3639. ** -------------------------------------------------------------------------
  3640. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  3641. **
  3642. ****************************************************************************/
  3643. static u32 MT2063_fLO_FractionalTerm(u32 f_ref,
  3644. u32 num, u32 denom)
  3645. {
  3646. u32 t1 = (f_ref >> 14) * num;
  3647. u32 term1 = t1 / denom;
  3648. u32 loss = t1 % denom;
  3649. u32 term2 =
  3650. (((f_ref & 0x00003FFF) * num + (loss << 14)) + (denom / 2)) / denom;
  3651. return ((term1 << 14) + term2);
  3652. }
  3653. /****************************************************************************
  3654. **
  3655. ** Name: CalcLO1Mult
  3656. **
  3657. ** Description: Calculates Integer divider value and the numerator
  3658. ** value for a FracN PLL.
  3659. **
  3660. ** This function assumes that the f_LO and f_Ref are
  3661. ** evenly divisible by f_LO_Step.
  3662. **
  3663. ** Parameters: Div - OUTPUT: Whole number portion of the multiplier
  3664. ** FracN - OUTPUT: Fractional portion of the multiplier
  3665. ** f_LO - desired LO frequency.
  3666. ** f_LO_Step - Minimum step size for the LO (in Hz).
  3667. ** f_Ref - SRO frequency.
  3668. ** f_Avoid - Range of PLL frequencies to avoid near
  3669. ** integer multiples of f_Ref (in Hz).
  3670. **
  3671. ** Returns: Recalculated LO frequency.
  3672. **
  3673. ** Revision History:
  3674. **
  3675. ** SCR Date Author Description
  3676. ** -------------------------------------------------------------------------
  3677. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  3678. **
  3679. ****************************************************************************/
  3680. static u32 MT2063_CalcLO1Mult(u32 * Div,
  3681. u32 * FracN,
  3682. u32 f_LO,
  3683. u32 f_LO_Step, u32 f_Ref)
  3684. {
  3685. /* Calculate the whole number portion of the divider */
  3686. *Div = f_LO / f_Ref;
  3687. /* Calculate the numerator value (round to nearest f_LO_Step) */
  3688. *FracN =
  3689. (64 * (((f_LO % f_Ref) + (f_LO_Step / 2)) / f_LO_Step) +
  3690. (f_Ref / f_LO_Step / 2)) / (f_Ref / f_LO_Step);
  3691. return (f_Ref * (*Div)) + MT2063_fLO_FractionalTerm(f_Ref, *FracN, 64);
  3692. }
  3693. /****************************************************************************
  3694. **
  3695. ** Name: CalcLO2Mult
  3696. **
  3697. ** Description: Calculates Integer divider value and the numerator
  3698. ** value for a FracN PLL.
  3699. **
  3700. ** This function assumes that the f_LO and f_Ref are
  3701. ** evenly divisible by f_LO_Step.
  3702. **
  3703. ** Parameters: Div - OUTPUT: Whole number portion of the multiplier
  3704. ** FracN - OUTPUT: Fractional portion of the multiplier
  3705. ** f_LO - desired LO frequency.
  3706. ** f_LO_Step - Minimum step size for the LO (in Hz).
  3707. ** f_Ref - SRO frequency.
  3708. ** f_Avoid - Range of PLL frequencies to avoid near
  3709. ** integer multiples of f_Ref (in Hz).
  3710. **
  3711. ** Returns: Recalculated LO frequency.
  3712. **
  3713. ** Revision History:
  3714. **
  3715. ** SCR Date Author Description
  3716. ** -------------------------------------------------------------------------
  3717. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  3718. **
  3719. ****************************************************************************/
  3720. static u32 MT2063_CalcLO2Mult(u32 * Div,
  3721. u32 * FracN,
  3722. u32 f_LO,
  3723. u32 f_LO_Step, u32 f_Ref)
  3724. {
  3725. /* Calculate the whole number portion of the divider */
  3726. *Div = f_LO / f_Ref;
  3727. /* Calculate the numerator value (round to nearest f_LO_Step) */
  3728. *FracN =
  3729. (8191 * (((f_LO % f_Ref) + (f_LO_Step / 2)) / f_LO_Step) +
  3730. (f_Ref / f_LO_Step / 2)) / (f_Ref / f_LO_Step);
  3731. return (f_Ref * (*Div)) + MT2063_fLO_FractionalTerm(f_Ref, *FracN,
  3732. 8191);
  3733. }
  3734. /****************************************************************************
  3735. **
  3736. ** Name: FindClearTuneFilter
  3737. **
  3738. ** Description: Calculate the corrrect ClearTune filter to be used for
  3739. ** a given input frequency.
  3740. **
  3741. ** Parameters: pInfo - ptr to tuner data structure
  3742. ** f_in - RF input center frequency (in Hz).
  3743. **
  3744. ** Returns: ClearTune filter number (0-31)
  3745. **
  3746. ** Dependencies: MUST CALL MT2064_Open BEFORE FindClearTuneFilter!
  3747. **
  3748. ** Revision History:
  3749. **
  3750. ** SCR Date Author Description
  3751. ** -------------------------------------------------------------------------
  3752. ** 04-10-2008 PINZ Ver 1.14: Use software-controlled ClearTune
  3753. ** cross-over frequency values.
  3754. **
  3755. ****************************************************************************/
  3756. static u32 FindClearTuneFilter(struct MT2063_Info_t *pInfo, u32 f_in)
  3757. {
  3758. u32 RFBand;
  3759. u32 idx; /* index loop */
  3760. /*
  3761. ** Find RF Band setting
  3762. */
  3763. RFBand = 31; /* def when f_in > all */
  3764. for (idx = 0; idx < 31; ++idx) {
  3765. if (pInfo->CTFiltMax[idx] >= f_in) {
  3766. RFBand = idx;
  3767. break;
  3768. }
  3769. }
  3770. return (RFBand);
  3771. }
  3772. /****************************************************************************
  3773. **
  3774. ** Name: MT2063_Tune
  3775. **
  3776. ** Description: Change the tuner's tuned frequency to RFin.
  3777. **
  3778. ** Parameters: h - Open handle to the tuner (from MT2063_Open).
  3779. ** f_in - RF input center frequency (in Hz).
  3780. **
  3781. ** Returns: status:
  3782. ** MT_OK - No errors
  3783. ** MT_INV_HANDLE - Invalid tuner handle
  3784. ** MT_UPC_UNLOCK - Upconverter PLL unlocked
  3785. ** MT_DNC_UNLOCK - Downconverter PLL unlocked
  3786. ** MT_COMM_ERR - Serial bus communications error
  3787. ** MT_SPUR_CNT_MASK - Count of avoided LO spurs
  3788. ** MT_SPUR_PRESENT - LO spur possible in output
  3789. ** MT_FIN_RANGE - Input freq out of range
  3790. ** MT_FOUT_RANGE - Output freq out of range
  3791. ** MT_UPC_RANGE - Upconverter freq out of range
  3792. ** MT_DNC_RANGE - Downconverter freq out of range
  3793. **
  3794. ** Dependencies: MUST CALL MT2063_Open BEFORE MT2063_Tune!
  3795. **
  3796. ** MT_ReadSub - Read data from the two-wire serial bus
  3797. ** MT_WriteSub - Write data to the two-wire serial bus
  3798. ** MT_Sleep - Delay execution for x milliseconds
  3799. ** MT2063_GetLocked - Checks to see if LO1 and LO2 are locked
  3800. **
  3801. ** Revision History:
  3802. **
  3803. ** SCR Date Author Description
  3804. ** -------------------------------------------------------------------------
  3805. ** 138 06-19-2007 DAD Ver 1.00: Initial, derived from mt2067_b.
  3806. ** 04-10-2008 PINZ Ver 1.05: Use software-controlled ClearTune
  3807. ** cross-over frequency values.
  3808. ** 175 I 16-06-2008 PINZ Ver 1.16: Add control to avoid US DECT freqs.
  3809. ** 175 I 06-19-2008 RSK Ver 1.17: Refactor DECT control to SpurAvoid.
  3810. ** 06-24-2008 PINZ Ver 1.18: Add Get/SetParam CTFILT_SW
  3811. **
  3812. ****************************************************************************/
  3813. static u32 MT2063_Tune(void *h, u32 f_in)
  3814. { /* RF input center frequency */
  3815. struct MT2063_Info_t *pInfo = (struct MT2063_Info_t *)h;
  3816. u32 status = MT2063_OK; /* status of operation */
  3817. u32 LO1; /* 1st LO register value */
  3818. u32 Num1; /* Numerator for LO1 reg. value */
  3819. u32 f_IF1; /* 1st IF requested */
  3820. u32 LO2; /* 2nd LO register value */
  3821. u32 Num2; /* Numerator for LO2 reg. value */
  3822. u32 ofLO1, ofLO2; /* last time's LO frequencies */
  3823. u32 ofin, ofout; /* last time's I/O frequencies */
  3824. u8 fiffc = 0x80; /* FIFF center freq from tuner */
  3825. u32 fiffof; /* Offset from FIFF center freq */
  3826. const u8 LO1LK = 0x80; /* Mask for LO1 Lock bit */
  3827. u8 LO2LK = 0x08; /* Mask for LO2 Lock bit */
  3828. u8 val;
  3829. u32 RFBand;
  3830. /* Verify that the handle passed points to a valid tuner */
  3831. if (MT2063_IsValidHandle(pInfo) == 0)
  3832. return MT2063_INV_HANDLE;
  3833. /* Check the input and output frequency ranges */
  3834. if ((f_in < MT2063_MIN_FIN_FREQ) || (f_in > MT2063_MAX_FIN_FREQ))
  3835. status |= MT2063_FIN_RANGE;
  3836. if ((pInfo->AS_Data.f_out < MT2063_MIN_FOUT_FREQ)
  3837. || (pInfo->AS_Data.f_out > MT2063_MAX_FOUT_FREQ))
  3838. status |= MT2063_FOUT_RANGE;
  3839. /*
  3840. ** Save original LO1 and LO2 register values
  3841. */
  3842. ofLO1 = pInfo->AS_Data.f_LO1;
  3843. ofLO2 = pInfo->AS_Data.f_LO2;
  3844. ofin = pInfo->AS_Data.f_in;
  3845. ofout = pInfo->AS_Data.f_out;
  3846. /*
  3847. ** Find and set RF Band setting
  3848. */
  3849. if (pInfo->ctfilt_sw == 1) {
  3850. val = (pInfo->reg[MT2063_REG_CTUNE_CTRL] | 0x08);
  3851. if (pInfo->reg[MT2063_REG_CTUNE_CTRL] != val) {
  3852. status |=
  3853. MT2063_SetReg(pInfo, MT2063_REG_CTUNE_CTRL, val);
  3854. }
  3855. val = pInfo->reg[MT2063_REG_CTUNE_OV];
  3856. RFBand = FindClearTuneFilter(pInfo, f_in);
  3857. pInfo->reg[MT2063_REG_CTUNE_OV] =
  3858. (u8) ((pInfo->reg[MT2063_REG_CTUNE_OV] & ~0x1F)
  3859. | RFBand);
  3860. if (pInfo->reg[MT2063_REG_CTUNE_OV] != val) {
  3861. status |=
  3862. MT2063_SetReg(pInfo, MT2063_REG_CTUNE_OV, val);
  3863. }
  3864. }
  3865. /*
  3866. ** Read the FIFF Center Frequency from the tuner
  3867. */
  3868. if (MT2063_NO_ERROR(status)) {
  3869. status |=
  3870. MT2063_ReadSub(pInfo->hUserData, pInfo->address,
  3871. MT2063_REG_FIFFC,
  3872. &pInfo->reg[MT2063_REG_FIFFC], 1);
  3873. fiffc = pInfo->reg[MT2063_REG_FIFFC];
  3874. }
  3875. /*
  3876. ** Assign in the requested values
  3877. */
  3878. pInfo->AS_Data.f_in = f_in;
  3879. /* Request a 1st IF such that LO1 is on a step size */
  3880. pInfo->AS_Data.f_if1_Request =
  3881. MT2063_Round_fLO(pInfo->AS_Data.f_if1_Request + f_in,
  3882. pInfo->AS_Data.f_LO1_Step,
  3883. pInfo->AS_Data.f_ref) - f_in;
  3884. /*
  3885. ** Calculate frequency settings. f_IF1_FREQ + f_in is the
  3886. ** desired LO1 frequency
  3887. */
  3888. MT2063_ResetExclZones(&pInfo->AS_Data);
  3889. f_IF1 = MT2063_ChooseFirstIF(&pInfo->AS_Data);
  3890. pInfo->AS_Data.f_LO1 =
  3891. MT2063_Round_fLO(f_IF1 + f_in, pInfo->AS_Data.f_LO1_Step,
  3892. pInfo->AS_Data.f_ref);
  3893. pInfo->AS_Data.f_LO2 =
  3894. MT2063_Round_fLO(pInfo->AS_Data.f_LO1 - pInfo->AS_Data.f_out - f_in,
  3895. pInfo->AS_Data.f_LO2_Step, pInfo->AS_Data.f_ref);
  3896. /*
  3897. ** Check for any LO spurs in the output bandwidth and adjust
  3898. ** the LO settings to avoid them if needed
  3899. */
  3900. status |= MT2063_AvoidSpurs(h, &pInfo->AS_Data);
  3901. /*
  3902. ** MT_AvoidSpurs spurs may have changed the LO1 & LO2 values.
  3903. ** Recalculate the LO frequencies and the values to be placed
  3904. ** in the tuning registers.
  3905. */
  3906. pInfo->AS_Data.f_LO1 =
  3907. MT2063_CalcLO1Mult(&LO1, &Num1, pInfo->AS_Data.f_LO1,
  3908. pInfo->AS_Data.f_LO1_Step, pInfo->AS_Data.f_ref);
  3909. pInfo->AS_Data.f_LO2 =
  3910. MT2063_Round_fLO(pInfo->AS_Data.f_LO1 - pInfo->AS_Data.f_out - f_in,
  3911. pInfo->AS_Data.f_LO2_Step, pInfo->AS_Data.f_ref);
  3912. pInfo->AS_Data.f_LO2 =
  3913. MT2063_CalcLO2Mult(&LO2, &Num2, pInfo->AS_Data.f_LO2,
  3914. pInfo->AS_Data.f_LO2_Step, pInfo->AS_Data.f_ref);
  3915. /*
  3916. ** Check the upconverter and downconverter frequency ranges
  3917. */
  3918. if ((pInfo->AS_Data.f_LO1 < MT2063_MIN_UPC_FREQ)
  3919. || (pInfo->AS_Data.f_LO1 > MT2063_MAX_UPC_FREQ))
  3920. status |= MT2063_UPC_RANGE;
  3921. if ((pInfo->AS_Data.f_LO2 < MT2063_MIN_DNC_FREQ)
  3922. || (pInfo->AS_Data.f_LO2 > MT2063_MAX_DNC_FREQ))
  3923. status |= MT2063_DNC_RANGE;
  3924. /* LO2 Lock bit was in a different place for B0 version */
  3925. if (pInfo->tuner_id == MT2063_B0)
  3926. LO2LK = 0x40;
  3927. /*
  3928. ** If we have the same LO frequencies and we're already locked,
  3929. ** then skip re-programming the LO registers.
  3930. */
  3931. if ((ofLO1 != pInfo->AS_Data.f_LO1)
  3932. || (ofLO2 != pInfo->AS_Data.f_LO2)
  3933. || ((pInfo->reg[MT2063_REG_LO_STATUS] & (LO1LK | LO2LK)) !=
  3934. (LO1LK | LO2LK))) {
  3935. /*
  3936. ** Calculate the FIFFOF register value
  3937. **
  3938. ** IF1_Actual
  3939. ** FIFFOF = ------------ - 8 * FIFFC - 4992
  3940. ** f_ref/64
  3941. */
  3942. fiffof =
  3943. (pInfo->AS_Data.f_LO1 -
  3944. f_in) / (pInfo->AS_Data.f_ref / 64) - 8 * (u32) fiffc -
  3945. 4992;
  3946. if (fiffof > 0xFF)
  3947. fiffof = 0xFF;
  3948. /*
  3949. ** Place all of the calculated values into the local tuner
  3950. ** register fields.
  3951. */
  3952. if (MT2063_NO_ERROR(status)) {
  3953. pInfo->reg[MT2063_REG_LO1CQ_1] = (u8) (LO1 & 0xFF); /* DIV1q */
  3954. pInfo->reg[MT2063_REG_LO1CQ_2] = (u8) (Num1 & 0x3F); /* NUM1q */
  3955. pInfo->reg[MT2063_REG_LO2CQ_1] = (u8) (((LO2 & 0x7F) << 1) /* DIV2q */
  3956. |(Num2 >> 12)); /* NUM2q (hi) */
  3957. pInfo->reg[MT2063_REG_LO2CQ_2] = (u8) ((Num2 & 0x0FF0) >> 4); /* NUM2q (mid) */
  3958. pInfo->reg[MT2063_REG_LO2CQ_3] = (u8) (0xE0 | (Num2 & 0x000F)); /* NUM2q (lo) */
  3959. /*
  3960. ** Now write out the computed register values
  3961. ** IMPORTANT: There is a required order for writing
  3962. ** (0x05 must follow all the others).
  3963. */
  3964. status |= MT2063_WriteSub(pInfo->hUserData, pInfo->address, MT2063_REG_LO1CQ_1, &pInfo->reg[MT2063_REG_LO1CQ_1], 5); /* 0x01 - 0x05 */
  3965. if (pInfo->tuner_id == MT2063_B0) {
  3966. /* Re-write the one-shot bits to trigger the tune operation */
  3967. status |= MT2063_WriteSub(pInfo->hUserData, pInfo->address, MT2063_REG_LO2CQ_3, &pInfo->reg[MT2063_REG_LO2CQ_3], 1); /* 0x05 */
  3968. }
  3969. /* Write out the FIFF offset only if it's changing */
  3970. if (pInfo->reg[MT2063_REG_FIFF_OFFSET] !=
  3971. (u8) fiffof) {
  3972. pInfo->reg[MT2063_REG_FIFF_OFFSET] =
  3973. (u8) fiffof;
  3974. status |=
  3975. MT2063_WriteSub(pInfo->hUserData,
  3976. pInfo->address,
  3977. MT2063_REG_FIFF_OFFSET,
  3978. &pInfo->
  3979. reg[MT2063_REG_FIFF_OFFSET],
  3980. 1);
  3981. }
  3982. }
  3983. /*
  3984. ** Check for LO's locking
  3985. */
  3986. if (MT2063_NO_ERROR(status)) {
  3987. status |= MT2063_GetLocked(h);
  3988. }
  3989. /*
  3990. ** If we locked OK, assign calculated data to MT2063_Info_t structure
  3991. */
  3992. if (MT2063_NO_ERROR(status)) {
  3993. pInfo->f_IF1_actual = pInfo->AS_Data.f_LO1 - f_in;
  3994. }
  3995. }
  3996. return (status);
  3997. }
  3998. static u32 MT_Tune_atv(void *h, u32 f_in, u32 bw_in,
  3999. enum MTTune_atv_standard tv_type)
  4000. {
  4001. u32 status = MT2063_OK;
  4002. s32 pict_car = 0;
  4003. s32 pict2chanb_vsb = 0;
  4004. s32 pict2chanb_snd = 0;
  4005. s32 pict2snd1 = 0;
  4006. s32 pict2snd2 = 0;
  4007. s32 ch_bw = 0;
  4008. s32 if_mid = 0;
  4009. s32 rcvr_mode = 0;
  4010. u32 mode_get = 0;
  4011. switch (tv_type) {
  4012. case MTTUNEA_PAL_B:{
  4013. pict_car = 38900000;
  4014. ch_bw = 8000000;
  4015. pict2chanb_vsb = -1250000;
  4016. pict2snd1 = 5500000;
  4017. pict2snd2 = 5742000;
  4018. rcvr_mode = 1;
  4019. break;
  4020. }
  4021. case MTTUNEA_PAL_G:{
  4022. pict_car = 38900000;
  4023. ch_bw = 7000000;
  4024. pict2chanb_vsb = -1250000;
  4025. pict2snd1 = 5500000;
  4026. pict2snd2 = 0;
  4027. rcvr_mode = 1;
  4028. break;
  4029. }
  4030. case MTTUNEA_PAL_I:{
  4031. pict_car = 38900000;
  4032. ch_bw = 8000000;
  4033. pict2chanb_vsb = -1250000;
  4034. pict2snd1 = 6000000;
  4035. pict2snd2 = 0;
  4036. rcvr_mode = 1;
  4037. break;
  4038. }
  4039. case MTTUNEA_PAL_L:{
  4040. pict_car = 38900000;
  4041. ch_bw = 8000000;
  4042. pict2chanb_vsb = -1250000;
  4043. pict2snd1 = 6500000;
  4044. pict2snd2 = 0;
  4045. rcvr_mode = 1;
  4046. break;
  4047. }
  4048. case MTTUNEA_PAL_MN:{
  4049. pict_car = 38900000;
  4050. ch_bw = 6000000;
  4051. pict2chanb_vsb = -1250000;
  4052. pict2snd1 = 4500000;
  4053. pict2snd2 = 0;
  4054. rcvr_mode = 1;
  4055. break;
  4056. }
  4057. case MTTUNEA_PAL_DK:{
  4058. pict_car = 38900000;
  4059. ch_bw = 8000000;
  4060. pict2chanb_vsb = -1250000;
  4061. pict2snd1 = 6500000;
  4062. pict2snd2 = 0;
  4063. rcvr_mode = 1;
  4064. break;
  4065. }
  4066. case MTTUNEA_DIGITAL:{
  4067. pict_car = 36125000;
  4068. ch_bw = 8000000;
  4069. pict2chanb_vsb = -(ch_bw / 2);
  4070. pict2snd1 = 0;
  4071. pict2snd2 = 0;
  4072. rcvr_mode = 2;
  4073. break;
  4074. }
  4075. case MTTUNEA_FMRADIO:{
  4076. pict_car = 38900000;
  4077. ch_bw = 8000000;
  4078. pict2chanb_vsb = -(ch_bw / 2);
  4079. pict2snd1 = 0;
  4080. pict2snd2 = 0;
  4081. rcvr_mode = 4;
  4082. //f_in -= 2900000;
  4083. break;
  4084. }
  4085. case MTTUNEA_DVBC:{
  4086. pict_car = 36125000;
  4087. ch_bw = 8000000;
  4088. pict2chanb_vsb = -(ch_bw / 2);
  4089. pict2snd1 = 0;
  4090. pict2snd2 = 0;
  4091. rcvr_mode = MT2063_CABLE_QAM;
  4092. break;
  4093. }
  4094. case MTTUNEA_DVBT:{
  4095. pict_car = 36125000;
  4096. ch_bw = bw_in; //8000000
  4097. pict2chanb_vsb = -(ch_bw / 2);
  4098. pict2snd1 = 0;
  4099. pict2snd2 = 0;
  4100. rcvr_mode = MT2063_OFFAIR_COFDM;
  4101. break;
  4102. }
  4103. case MTTUNEA_UNKNOWN:
  4104. break;
  4105. default:
  4106. break;
  4107. }
  4108. pict2chanb_snd = pict2chanb_vsb - ch_bw;
  4109. if_mid = pict_car - (pict2chanb_vsb + (ch_bw / 2));
  4110. status |= MT2063_SetParam(h, MT2063_STEPSIZE, 125000);
  4111. status |= MT2063_SetParam(h, MT2063_OUTPUT_FREQ, if_mid);
  4112. status |= MT2063_SetParam(h, MT2063_OUTPUT_BW, ch_bw);
  4113. status |= MT2063_GetParam(h, MT2063_RCVR_MODE, &mode_get);
  4114. status |= MT2063_SetParam(h, MT2063_RCVR_MODE, rcvr_mode);
  4115. status |= MT2063_Tune(h, (f_in + (pict2chanb_vsb + (ch_bw / 2))));
  4116. status |= MT2063_GetParam(h, MT2063_RCVR_MODE, &mode_get);
  4117. return (u32) status;
  4118. }
  4119. static int mt2063_init(struct dvb_frontend *fe)
  4120. {
  4121. u32 status = MT2063_ERROR;
  4122. struct mt2063_state *state = fe->tuner_priv;
  4123. status = MT2063_Open(0xC0, &(state->MT2063_ht), fe);
  4124. status |= MT2063_SoftwareShutdown(state->MT2063_ht, 1);
  4125. status |= MT2063_ClearPowerMaskBits(state->MT2063_ht, MT2063_ALL_SD);
  4126. if (MT2063_OK != status) {
  4127. printk("%s %d error status = 0x%x!!\n", __func__, __LINE__,
  4128. status);
  4129. return -1;
  4130. }
  4131. return 0;
  4132. }
  4133. static int mt2063_get_status(struct dvb_frontend *fe, u32 * status)
  4134. {
  4135. int rc = 0;
  4136. //get tuner lock status
  4137. return rc;
  4138. }
  4139. static int mt2063_get_state(struct dvb_frontend *fe,
  4140. enum tuner_param param, struct tuner_state *state)
  4141. {
  4142. struct mt2063_state *mt2063State = fe->tuner_priv;
  4143. switch (param) {
  4144. case DVBFE_TUNER_FREQUENCY:
  4145. //get frequency
  4146. break;
  4147. case DVBFE_TUNER_TUNERSTEP:
  4148. break;
  4149. case DVBFE_TUNER_IFFREQ:
  4150. break;
  4151. case DVBFE_TUNER_BANDWIDTH:
  4152. //get bandwidth
  4153. break;
  4154. case DVBFE_TUNER_REFCLOCK:
  4155. state->refclock =
  4156. (u32)
  4157. MT2063_GetLocked((void *) (mt2063State->MT2063_ht));
  4158. break;
  4159. default:
  4160. break;
  4161. }
  4162. return (int)state->refclock;
  4163. }
  4164. static int mt2063_set_state(struct dvb_frontend *fe,
  4165. enum tuner_param param, struct tuner_state *state)
  4166. {
  4167. struct mt2063_state *mt2063State = fe->tuner_priv;
  4168. u32 status = MT2063_OK;
  4169. switch (param) {
  4170. case DVBFE_TUNER_FREQUENCY:
  4171. //set frequency
  4172. status =
  4173. MT_Tune_atv((void *) (mt2063State->MT2063_ht),
  4174. state->frequency, state->bandwidth,
  4175. mt2063State->tv_type);
  4176. mt2063State->frequency = state->frequency;
  4177. break;
  4178. case DVBFE_TUNER_TUNERSTEP:
  4179. break;
  4180. case DVBFE_TUNER_IFFREQ:
  4181. break;
  4182. case DVBFE_TUNER_BANDWIDTH:
  4183. //set bandwidth
  4184. mt2063State->bandwidth = state->bandwidth;
  4185. break;
  4186. case DVBFE_TUNER_REFCLOCK:
  4187. break;
  4188. case DVBFE_TUNER_OPEN:
  4189. status = MT2063_Open(MT2063_I2C, &(mt2063State->MT2063_ht), fe);
  4190. break;
  4191. case DVBFE_TUNER_SOFTWARE_SHUTDOWN:
  4192. status = MT2063_SoftwareShutdown(mt2063State->MT2063_ht, 1);
  4193. break;
  4194. case DVBFE_TUNER_CLEAR_POWER_MASKBITS:
  4195. status =
  4196. MT2063_ClearPowerMaskBits(mt2063State->MT2063_ht,
  4197. MT2063_ALL_SD);
  4198. break;
  4199. default:
  4200. break;
  4201. }
  4202. return (int)status;
  4203. }
  4204. static int mt2063_release(struct dvb_frontend *fe)
  4205. {
  4206. struct mt2063_state *state = fe->tuner_priv;
  4207. fe->tuner_priv = NULL;
  4208. kfree(state);
  4209. return 0;
  4210. }
  4211. static struct dvb_tuner_ops mt2063_ops = {
  4212. .info = {
  4213. .name = "MT2063 Silicon Tuner",
  4214. .frequency_min = 45000000,
  4215. .frequency_max = 850000000,
  4216. .frequency_step = 0,
  4217. },
  4218. .init = mt2063_init,
  4219. .sleep = MT2063_Sleep,
  4220. .get_status = mt2063_get_status,
  4221. .get_state = mt2063_get_state,
  4222. .set_state = mt2063_set_state,
  4223. .release = mt2063_release
  4224. };
  4225. struct dvb_frontend *mt2063_attach(struct dvb_frontend *fe,
  4226. struct mt2063_config *config,
  4227. struct i2c_adapter *i2c)
  4228. {
  4229. struct mt2063_state *state = NULL;
  4230. state = kzalloc(sizeof(struct mt2063_state), GFP_KERNEL);
  4231. if (state == NULL)
  4232. goto error;
  4233. state->config = config;
  4234. state->i2c = i2c;
  4235. state->frontend = fe;
  4236. state->reference = config->refclock / 1000; /* kHz */
  4237. state->MT2063_init = false;
  4238. fe->tuner_priv = state;
  4239. fe->ops.tuner_ops = mt2063_ops;
  4240. printk("%s: Attaching MT2063 \n", __func__);
  4241. return fe;
  4242. error:
  4243. kfree(state);
  4244. return NULL;
  4245. }
  4246. EXPORT_SYMBOL(mt2063_attach);
  4247. MODULE_PARM_DESC(verbose, "Set Verbosity level");
  4248. MODULE_AUTHOR("Henry");
  4249. MODULE_DESCRIPTION("MT2063 Silicon tuner");
  4250. MODULE_LICENSE("GPL");