mt2063.c 133 KB

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