mt2063.c 155 KB

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