mt2063.c 151 KB

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