1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389 |
- /*
- Copyright (c), 2004-2005,2007-2010 Trident Microsystems, Inc.
- All rights reserved.
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of Trident Microsystems nor Hauppauge Computer Works
- nor the names of its contributors may be used to endorse or promote
- products derived from this software without specific prior written
- permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
- DRXJ specific implementation of DRX driver
- authors: Dragan Savic, Milos Nikolic, Mihajlo Katona, Tao Ding, Paul Janssen
- The Linux DVB Driver for Micronas DRX39xx family (drx3933j) was
- written by Devin Heitmueller <devin.heitmueller@kernellabs.com>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
- /*-----------------------------------------------------------------------------
- INCLUDE FILES
- ----------------------------------------------------------------------------*/
- #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/string.h>
- #include <linux/slab.h>
- #include <asm/div64.h>
- #include "dvb_frontend.h"
- #include "drx39xxj.h"
- #include "drxj.h"
- #include "drxj_map.h"
- /*============================================================================*/
- /*=== DEFINES ================================================================*/
- /*============================================================================*/
- #define DRX39XX_MAIN_FIRMWARE "dvb-fe-drxj-mc-1.0.8.fw"
- /**
- * \brief Maximum u32 value.
- */
- #ifndef MAX_U32
- #define MAX_U32 ((u32) (0xFFFFFFFFL))
- #endif
- /* Customer configurable hardware settings, etc */
- #ifndef MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH
- #define MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH 0x02
- #endif
- #ifndef MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH
- #define MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH 0x02
- #endif
- #ifndef MPEG_OUTPUT_CLK_DRIVE_STRENGTH
- #define MPEG_OUTPUT_CLK_DRIVE_STRENGTH 0x06
- #endif
- #ifndef OOB_CRX_DRIVE_STRENGTH
- #define OOB_CRX_DRIVE_STRENGTH 0x02
- #endif
- #ifndef OOB_DRX_DRIVE_STRENGTH
- #define OOB_DRX_DRIVE_STRENGTH 0x02
- #endif
- /**** START DJCOMBO patches to DRXJ registermap constants *********************/
- /**** registermap 200706071303 from drxj **************************************/
- #define ATV_TOP_CR_AMP_TH_FM 0x0
- #define ATV_TOP_CR_AMP_TH_L 0xA
- #define ATV_TOP_CR_AMP_TH_LP 0xA
- #define ATV_TOP_CR_AMP_TH_BG 0x8
- #define ATV_TOP_CR_AMP_TH_DK 0x8
- #define ATV_TOP_CR_AMP_TH_I 0x8
- #define ATV_TOP_CR_CONT_CR_D_MN 0x18
- #define ATV_TOP_CR_CONT_CR_D_FM 0x0
- #define ATV_TOP_CR_CONT_CR_D_L 0x20
- #define ATV_TOP_CR_CONT_CR_D_LP 0x20
- #define ATV_TOP_CR_CONT_CR_D_BG 0x18
- #define ATV_TOP_CR_CONT_CR_D_DK 0x18
- #define ATV_TOP_CR_CONT_CR_D_I 0x18
- #define ATV_TOP_CR_CONT_CR_I_MN 0x80
- #define ATV_TOP_CR_CONT_CR_I_FM 0x0
- #define ATV_TOP_CR_CONT_CR_I_L 0x80
- #define ATV_TOP_CR_CONT_CR_I_LP 0x80
- #define ATV_TOP_CR_CONT_CR_I_BG 0x80
- #define ATV_TOP_CR_CONT_CR_I_DK 0x80
- #define ATV_TOP_CR_CONT_CR_I_I 0x80
- #define ATV_TOP_CR_CONT_CR_P_MN 0x4
- #define ATV_TOP_CR_CONT_CR_P_FM 0x0
- #define ATV_TOP_CR_CONT_CR_P_L 0x4
- #define ATV_TOP_CR_CONT_CR_P_LP 0x4
- #define ATV_TOP_CR_CONT_CR_P_BG 0x4
- #define ATV_TOP_CR_CONT_CR_P_DK 0x4
- #define ATV_TOP_CR_CONT_CR_P_I 0x4
- #define ATV_TOP_CR_OVM_TH_MN 0xA0
- #define ATV_TOP_CR_OVM_TH_FM 0x0
- #define ATV_TOP_CR_OVM_TH_L 0xA0
- #define ATV_TOP_CR_OVM_TH_LP 0xA0
- #define ATV_TOP_CR_OVM_TH_BG 0xA0
- #define ATV_TOP_CR_OVM_TH_DK 0xA0
- #define ATV_TOP_CR_OVM_TH_I 0xA0
- #define ATV_TOP_EQU0_EQU_C0_FM 0x0
- #define ATV_TOP_EQU0_EQU_C0_L 0x3
- #define ATV_TOP_EQU0_EQU_C0_LP 0x3
- #define ATV_TOP_EQU0_EQU_C0_BG 0x7
- #define ATV_TOP_EQU0_EQU_C0_DK 0x0
- #define ATV_TOP_EQU0_EQU_C0_I 0x3
- #define ATV_TOP_EQU1_EQU_C1_FM 0x0
- #define ATV_TOP_EQU1_EQU_C1_L 0x1F6
- #define ATV_TOP_EQU1_EQU_C1_LP 0x1F6
- #define ATV_TOP_EQU1_EQU_C1_BG 0x197
- #define ATV_TOP_EQU1_EQU_C1_DK 0x198
- #define ATV_TOP_EQU1_EQU_C1_I 0x1F6
- #define ATV_TOP_EQU2_EQU_C2_FM 0x0
- #define ATV_TOP_EQU2_EQU_C2_L 0x28
- #define ATV_TOP_EQU2_EQU_C2_LP 0x28
- #define ATV_TOP_EQU2_EQU_C2_BG 0xC5
- #define ATV_TOP_EQU2_EQU_C2_DK 0xB0
- #define ATV_TOP_EQU2_EQU_C2_I 0x28
- #define ATV_TOP_EQU3_EQU_C3_FM 0x0
- #define ATV_TOP_EQU3_EQU_C3_L 0x192
- #define ATV_TOP_EQU3_EQU_C3_LP 0x192
- #define ATV_TOP_EQU3_EQU_C3_BG 0x12E
- #define ATV_TOP_EQU3_EQU_C3_DK 0x18E
- #define ATV_TOP_EQU3_EQU_C3_I 0x192
- #define ATV_TOP_STD_MODE_MN 0x0
- #define ATV_TOP_STD_MODE_FM 0x1
- #define ATV_TOP_STD_MODE_L 0x0
- #define ATV_TOP_STD_MODE_LP 0x0
- #define ATV_TOP_STD_MODE_BG 0x0
- #define ATV_TOP_STD_MODE_DK 0x0
- #define ATV_TOP_STD_MODE_I 0x0
- #define ATV_TOP_STD_VID_POL_MN 0x0
- #define ATV_TOP_STD_VID_POL_FM 0x0
- #define ATV_TOP_STD_VID_POL_L 0x2
- #define ATV_TOP_STD_VID_POL_LP 0x2
- #define ATV_TOP_STD_VID_POL_BG 0x0
- #define ATV_TOP_STD_VID_POL_DK 0x0
- #define ATV_TOP_STD_VID_POL_I 0x0
- #define ATV_TOP_VID_AMP_MN 0x380
- #define ATV_TOP_VID_AMP_FM 0x0
- #define ATV_TOP_VID_AMP_L 0xF50
- #define ATV_TOP_VID_AMP_LP 0xF50
- #define ATV_TOP_VID_AMP_BG 0x380
- #define ATV_TOP_VID_AMP_DK 0x394
- #define ATV_TOP_VID_AMP_I 0x3D8
- #define IQM_CF_OUT_ENA_OFDM__M 0x4
- #define IQM_FS_ADJ_SEL_B_QAM 0x1
- #define IQM_FS_ADJ_SEL_B_OFF 0x0
- #define IQM_FS_ADJ_SEL_B_VSB 0x2
- #define IQM_RC_ADJ_SEL_B_OFF 0x0
- #define IQM_RC_ADJ_SEL_B_QAM 0x1
- #define IQM_RC_ADJ_SEL_B_VSB 0x2
- /**** END DJCOMBO patches to DRXJ registermap *********************************/
- #include "drx_driver_version.h"
- /* #define DRX_DEBUG */
- #ifdef DRX_DEBUG
- #include <stdio.h>
- #endif
- /*-----------------------------------------------------------------------------
- ENUMS
- ----------------------------------------------------------------------------*/
- /*-----------------------------------------------------------------------------
- DEFINES
- ----------------------------------------------------------------------------*/
- #ifndef DRXJ_WAKE_UP_KEY
- #define DRXJ_WAKE_UP_KEY (demod->my_i2c_dev_addr->i2c_addr)
- #endif
- /**
- * \def DRXJ_DEF_I2C_ADDR
- * \brief Default I2C address of a demodulator instance.
- */
- #define DRXJ_DEF_I2C_ADDR (0x52)
- /**
- * \def DRXJ_DEF_DEMOD_DEV_ID
- * \brief Default device identifier of a demodultor instance.
- */
- #define DRXJ_DEF_DEMOD_DEV_ID (1)
- /**
- * \def DRXJ_SCAN_TIMEOUT
- * \brief Timeout value for waiting on demod lock during channel scan (millisec).
- */
- #define DRXJ_SCAN_TIMEOUT 1000
- /**
- * \def HI_I2C_DELAY
- * \brief HI timing delay for I2C timing (in nano seconds)
- *
- * Used to compute HI_CFG_DIV
- */
- #define HI_I2C_DELAY 42
- /**
- * \def HI_I2C_BRIDGE_DELAY
- * \brief HI timing delay for I2C timing (in nano seconds)
- *
- * Used to compute HI_CFG_BDL
- */
- #define HI_I2C_BRIDGE_DELAY 750
- /**
- * \brief Time Window for MER and SER Measurement in Units of Segment duration.
- */
- #define VSB_TOP_MEASUREMENT_PERIOD 64
- #define SYMBOLS_PER_SEGMENT 832
- /**
- * \brief bit rate and segment rate constants used for SER and BER.
- */
- /* values taken from the QAM microcode */
- #define DRXJ_QAM_SL_SIG_POWER_QAM_UNKNOWN 0
- #define DRXJ_QAM_SL_SIG_POWER_QPSK 32768
- #define DRXJ_QAM_SL_SIG_POWER_QAM8 24576
- #define DRXJ_QAM_SL_SIG_POWER_QAM16 40960
- #define DRXJ_QAM_SL_SIG_POWER_QAM32 20480
- #define DRXJ_QAM_SL_SIG_POWER_QAM64 43008
- #define DRXJ_QAM_SL_SIG_POWER_QAM128 20992
- #define DRXJ_QAM_SL_SIG_POWER_QAM256 43520
- /**
- * \brief Min supported symbolrates.
- */
- #ifndef DRXJ_QAM_SYMBOLRATE_MIN
- #define DRXJ_QAM_SYMBOLRATE_MIN (520000)
- #endif
- /**
- * \brief Max supported symbolrates.
- */
- #ifndef DRXJ_QAM_SYMBOLRATE_MAX
- #define DRXJ_QAM_SYMBOLRATE_MAX (7233000)
- #endif
- /**
- * \def DRXJ_QAM_MAX_WAITTIME
- * \brief Maximal wait time for QAM auto constellation in ms
- */
- #ifndef DRXJ_QAM_MAX_WAITTIME
- #define DRXJ_QAM_MAX_WAITTIME 900
- #endif
- #ifndef DRXJ_QAM_FEC_LOCK_WAITTIME
- #define DRXJ_QAM_FEC_LOCK_WAITTIME 150
- #endif
- #ifndef DRXJ_QAM_DEMOD_LOCK_EXT_WAITTIME
- #define DRXJ_QAM_DEMOD_LOCK_EXT_WAITTIME 200
- #endif
- /**
- * \def SCU status and results
- * \brief SCU
- */
- #define DRX_SCU_READY 0
- #define DRXJ_MAX_WAITTIME 100 /* ms */
- #define FEC_RS_MEASUREMENT_PERIOD 12894 /* 1 sec */
- #define FEC_RS_MEASUREMENT_PRESCALE 1 /* n sec */
- /**
- * \def DRX_AUD_MAX_DEVIATION
- * \brief Needed for calculation of prescale feature in AUD
- */
- #ifndef DRXJ_AUD_MAX_FM_DEVIATION
- #define DRXJ_AUD_MAX_FM_DEVIATION 100 /* kHz */
- #endif
- /**
- * \brief Needed for calculation of NICAM prescale feature in AUD
- */
- #ifndef DRXJ_AUD_MAX_NICAM_PRESCALE
- #define DRXJ_AUD_MAX_NICAM_PRESCALE (9) /* dB */
- #endif
- /**
- * \brief Needed for calculation of NICAM prescale feature in AUD
- */
- #ifndef DRXJ_AUD_MAX_WAITTIME
- #define DRXJ_AUD_MAX_WAITTIME 250 /* ms */
- #endif
- /* ATV config changed flags */
- #define DRXJ_ATV_CHANGED_COEF (0x00000001UL)
- #define DRXJ_ATV_CHANGED_PEAK_FLT (0x00000008UL)
- #define DRXJ_ATV_CHANGED_NOISE_FLT (0x00000010UL)
- #define DRXJ_ATV_CHANGED_OUTPUT (0x00000020UL)
- #define DRXJ_ATV_CHANGED_SIF_ATT (0x00000040UL)
- /* UIO define */
- #define DRX_UIO_MODE_FIRMWARE_SMA DRX_UIO_MODE_FIRMWARE0
- #define DRX_UIO_MODE_FIRMWARE_SAW DRX_UIO_MODE_FIRMWARE1
- /*
- * MICROCODE RELATED DEFINES
- */
- /* Magic word for checking correct Endianness of microcode data */
- #define DRX_UCODE_MAGIC_WORD ((((u16)'H')<<8)+((u16)'L'))
- /* CRC flag in ucode header, flags field. */
- #define DRX_UCODE_CRC_FLAG (0x0001)
- /*
- * Maximum size of buffer used to verify the microcode.
- * Must be an even number
- */
- #define DRX_UCODE_MAX_BUF_SIZE (DRXDAP_MAX_RCHUNKSIZE)
- #if DRX_UCODE_MAX_BUF_SIZE & 1
- #error DRX_UCODE_MAX_BUF_SIZE must be an even number
- #endif
- /*
- * Power mode macros
- */
- #define DRX_ISPOWERDOWNMODE(mode) ((mode == DRX_POWER_MODE_9) || \
- (mode == DRX_POWER_MODE_10) || \
- (mode == DRX_POWER_MODE_11) || \
- (mode == DRX_POWER_MODE_12) || \
- (mode == DRX_POWER_MODE_13) || \
- (mode == DRX_POWER_MODE_14) || \
- (mode == DRX_POWER_MODE_15) || \
- (mode == DRX_POWER_MODE_16) || \
- (mode == DRX_POWER_DOWN))
- /* Pin safe mode macro */
- #define DRXJ_PIN_SAFE_MODE 0x0000
- /*============================================================================*/
- /*=== GLOBAL VARIABLEs =======================================================*/
- /*============================================================================*/
- /**
- */
- /**
- * \brief Temporary register definitions.
- * (register definitions that are not yet available in register master)
- */
- /******************************************************************************/
- /* Audio block 0x103 is write only. To avoid shadowing in driver accessing */
- /* RAM adresses directly. This must be READ ONLY to avoid problems. */
- /* Writing to the interface adresses is more than only writing the RAM */
- /* locations */
- /******************************************************************************/
- /**
- * \brief RAM location of MODUS registers
- */
- #define AUD_DEM_RAM_MODUS_HI__A 0x10204A3
- #define AUD_DEM_RAM_MODUS_HI__M 0xF000
- #define AUD_DEM_RAM_MODUS_LO__A 0x10204A4
- #define AUD_DEM_RAM_MODUS_LO__M 0x0FFF
- /**
- * \brief RAM location of I2S config registers
- */
- #define AUD_DEM_RAM_I2S_CONFIG1__A 0x10204B1
- #define AUD_DEM_RAM_I2S_CONFIG2__A 0x10204B2
- /**
- * \brief RAM location of DCO config registers
- */
- #define AUD_DEM_RAM_DCO_B_HI__A 0x1020461
- #define AUD_DEM_RAM_DCO_B_LO__A 0x1020462
- #define AUD_DEM_RAM_DCO_A_HI__A 0x1020463
- #define AUD_DEM_RAM_DCO_A_LO__A 0x1020464
- /**
- * \brief RAM location of Threshold registers
- */
- #define AUD_DEM_RAM_NICAM_THRSHLD__A 0x102045A
- #define AUD_DEM_RAM_A2_THRSHLD__A 0x10204BB
- #define AUD_DEM_RAM_BTSC_THRSHLD__A 0x10204A6
- /**
- * \brief RAM location of Carrier Threshold registers
- */
- #define AUD_DEM_RAM_CM_A_THRSHLD__A 0x10204AF
- #define AUD_DEM_RAM_CM_B_THRSHLD__A 0x10204B0
- /**
- * \brief FM Matrix register fix
- */
- #ifdef AUD_DEM_WR_FM_MATRIX__A
- #undef AUD_DEM_WR_FM_MATRIX__A
- #endif
- #define AUD_DEM_WR_FM_MATRIX__A 0x105006F
- /*============================================================================*/
- /**
- * \brief Defines required for audio
- */
- #define AUD_VOLUME_ZERO_DB 115
- #define AUD_VOLUME_DB_MIN -60
- #define AUD_VOLUME_DB_MAX 12
- #define AUD_CARRIER_STRENGTH_QP_0DB 0x4000
- #define AUD_CARRIER_STRENGTH_QP_0DB_LOG10T100 421
- #define AUD_MAX_AVC_REF_LEVEL 15
- #define AUD_I2S_FREQUENCY_MAX 48000UL
- #define AUD_I2S_FREQUENCY_MIN 12000UL
- #define AUD_RDS_ARRAY_SIZE 18
- /**
- * \brief Needed for calculation of prescale feature in AUD
- */
- #ifndef DRX_AUD_MAX_FM_DEVIATION
- #define DRX_AUD_MAX_FM_DEVIATION (100) /* kHz */
- #endif
- /**
- * \brief Needed for calculation of NICAM prescale feature in AUD
- */
- #ifndef DRX_AUD_MAX_NICAM_PRESCALE
- #define DRX_AUD_MAX_NICAM_PRESCALE (9) /* dB */
- #endif
- /*============================================================================*/
- /* Values for I2S Master/Slave pin configurations */
- #define SIO_PDR_I2S_CL_CFG_MODE__MASTER 0x0004
- #define SIO_PDR_I2S_CL_CFG_DRIVE__MASTER 0x0008
- #define SIO_PDR_I2S_CL_CFG_MODE__SLAVE 0x0004
- #define SIO_PDR_I2S_CL_CFG_DRIVE__SLAVE 0x0000
- #define SIO_PDR_I2S_DA_CFG_MODE__MASTER 0x0003
- #define SIO_PDR_I2S_DA_CFG_DRIVE__MASTER 0x0008
- #define SIO_PDR_I2S_DA_CFG_MODE__SLAVE 0x0003
- #define SIO_PDR_I2S_DA_CFG_DRIVE__SLAVE 0x0008
- #define SIO_PDR_I2S_WS_CFG_MODE__MASTER 0x0004
- #define SIO_PDR_I2S_WS_CFG_DRIVE__MASTER 0x0008
- #define SIO_PDR_I2S_WS_CFG_MODE__SLAVE 0x0004
- #define SIO_PDR_I2S_WS_CFG_DRIVE__SLAVE 0x0000
- /*============================================================================*/
- /*=== REGISTER ACCESS MACROS =================================================*/
- /*============================================================================*/
- /**
- * This macro is used to create byte arrays for block writes.
- * Block writes speed up I2C traffic between host and demod.
- * The macro takes care of the required byte order in a 16 bits word.
- * x -> lowbyte(x), highbyte(x)
- */
- #define DRXJ_16TO8(x) ((u8) (((u16)x) & 0xFF)), \
- ((u8)((((u16)x)>>8)&0xFF))
- /**
- * This macro is used to convert byte array to 16 bit register value for block read.
- * Block read speed up I2C traffic between host and demod.
- * The macro takes care of the required byte order in a 16 bits word.
- */
- #define DRXJ_8TO16(x) ((u16) (x[0] | (x[1] << 8)))
- /*============================================================================*/
- /*=== MISC DEFINES ===========================================================*/
- /*============================================================================*/
- /*============================================================================*/
- /*=== HI COMMAND RELATED DEFINES =============================================*/
- /*============================================================================*/
- /**
- * \brief General maximum number of retries for ucode command interfaces
- */
- #define DRXJ_MAX_RETRIES (100)
- /*============================================================================*/
- /*=== STANDARD RELATED MACROS ================================================*/
- /*============================================================================*/
- #define DRXJ_ISATVSTD(std) ((std == DRX_STANDARD_PAL_SECAM_BG) || \
- (std == DRX_STANDARD_PAL_SECAM_DK) || \
- (std == DRX_STANDARD_PAL_SECAM_I) || \
- (std == DRX_STANDARD_PAL_SECAM_L) || \
- (std == DRX_STANDARD_PAL_SECAM_LP) || \
- (std == DRX_STANDARD_NTSC) || \
- (std == DRX_STANDARD_FM))
- #define DRXJ_ISQAMSTD(std) ((std == DRX_STANDARD_ITU_A) || \
- (std == DRX_STANDARD_ITU_B) || \
- (std == DRX_STANDARD_ITU_C) || \
- (std == DRX_STANDARD_ITU_D))
- /*-----------------------------------------------------------------------------
- GLOBAL VARIABLES
- ----------------------------------------------------------------------------*/
- /*
- * DRXJ DAP structures
- */
- static int drxdap_fasi_read_block(struct i2c_device_addr *dev_addr,
- u32 addr,
- u16 datasize,
- u8 *data, u32 flags);
- static int drxj_dap_read_modify_write_reg16(struct i2c_device_addr *dev_addr,
- u32 waddr,
- u32 raddr,
- u16 wdata, u16 *rdata);
- static int drxj_dap_read_reg16(struct i2c_device_addr *dev_addr,
- u32 addr,
- u16 *data, u32 flags);
- static int drxdap_fasi_read_reg32(struct i2c_device_addr *dev_addr,
- u32 addr,
- u32 *data, u32 flags);
- static int drxdap_fasi_write_block(struct i2c_device_addr *dev_addr,
- u32 addr,
- u16 datasize,
- u8 *data, u32 flags);
- static int drxj_dap_write_reg16(struct i2c_device_addr *dev_addr,
- u32 addr,
- u16 data, u32 flags);
- static int drxdap_fasi_write_reg32(struct i2c_device_addr *dev_addr,
- u32 addr,
- u32 data, u32 flags);
- static struct drxj_data drxj_data_g = {
- false, /* has_lna : true if LNA (aka PGA) present */
- false, /* has_oob : true if OOB supported */
- false, /* has_ntsc: true if NTSC supported */
- false, /* has_btsc: true if BTSC supported */
- false, /* has_smatx: true if SMA_TX pin is available */
- false, /* has_smarx: true if SMA_RX pin is available */
- false, /* has_gpio : true if GPIO pin is available */
- false, /* has_irqn : true if IRQN pin is available */
- 0, /* mfx A1/A2/A... */
- /* tuner settings */
- false, /* tuner mirrors RF signal */
- /* standard/channel settings */
- DRX_STANDARD_UNKNOWN, /* current standard */
- DRX_CONSTELLATION_AUTO, /* constellation */
- 0, /* frequency in KHz */
- DRX_BANDWIDTH_UNKNOWN, /* curr_bandwidth */
- DRX_MIRROR_NO, /* mirror */
- /* signal quality information: */
- /* default values taken from the QAM Programming guide */
- /* fec_bits_desired should not be less than 4000000 */
- 4000000, /* fec_bits_desired */
- 5, /* fec_vd_plen */
- 4, /* qam_vd_prescale */
- 0xFFFF, /* qamVDPeriod */
- 204 * 8, /* fec_rs_plen annex A */
- 1, /* fec_rs_prescale */
- FEC_RS_MEASUREMENT_PERIOD, /* fec_rs_period */
- true, /* reset_pkt_err_acc */
- 0, /* pkt_err_acc_start */
- /* HI configuration */
- 0, /* hi_cfg_timing_div */
- 0, /* hi_cfg_bridge_delay */
- 0, /* hi_cfg_wake_up_key */
- 0, /* hi_cfg_ctrl */
- 0, /* HICfgTimeout */
- /* UIO configuartion */
- DRX_UIO_MODE_DISABLE, /* uio_sma_rx_mode */
- DRX_UIO_MODE_DISABLE, /* uio_sma_tx_mode */
- DRX_UIO_MODE_DISABLE, /* uioASELMode */
- DRX_UIO_MODE_DISABLE, /* uio_irqn_mode */
- /* FS setting */
- 0UL, /* iqm_fs_rate_ofs */
- false, /* pos_image */
- /* RC setting */
- 0UL, /* iqm_rc_rate_ofs */
- /* AUD information */
- /* false, * flagSetAUDdone */
- /* false, * detectedRDS */
- /* true, * flagASDRequest */
- /* false, * flagHDevClear */
- /* false, * flagHDevSet */
- /* (u16) 0xFFF, * rdsLastCount */
- /* ATV configuartion */
- 0UL, /* flags cfg changes */
- /* shadow of ATV_TOP_EQU0__A */
- {-5,
- ATV_TOP_EQU0_EQU_C0_FM,
- ATV_TOP_EQU0_EQU_C0_L,
- ATV_TOP_EQU0_EQU_C0_LP,
- ATV_TOP_EQU0_EQU_C0_BG,
- ATV_TOP_EQU0_EQU_C0_DK,
- ATV_TOP_EQU0_EQU_C0_I},
- /* shadow of ATV_TOP_EQU1__A */
- {-50,
- ATV_TOP_EQU1_EQU_C1_FM,
- ATV_TOP_EQU1_EQU_C1_L,
- ATV_TOP_EQU1_EQU_C1_LP,
- ATV_TOP_EQU1_EQU_C1_BG,
- ATV_TOP_EQU1_EQU_C1_DK,
- ATV_TOP_EQU1_EQU_C1_I},
- /* shadow of ATV_TOP_EQU2__A */
- {210,
- ATV_TOP_EQU2_EQU_C2_FM,
- ATV_TOP_EQU2_EQU_C2_L,
- ATV_TOP_EQU2_EQU_C2_LP,
- ATV_TOP_EQU2_EQU_C2_BG,
- ATV_TOP_EQU2_EQU_C2_DK,
- ATV_TOP_EQU2_EQU_C2_I},
- /* shadow of ATV_TOP_EQU3__A */
- {-160,
- ATV_TOP_EQU3_EQU_C3_FM,
- ATV_TOP_EQU3_EQU_C3_L,
- ATV_TOP_EQU3_EQU_C3_LP,
- ATV_TOP_EQU3_EQU_C3_BG,
- ATV_TOP_EQU3_EQU_C3_DK,
- ATV_TOP_EQU3_EQU_C3_I},
- false, /* flag: true=bypass */
- ATV_TOP_VID_PEAK__PRE, /* shadow of ATV_TOP_VID_PEAK__A */
- ATV_TOP_NOISE_TH__PRE, /* shadow of ATV_TOP_NOISE_TH__A */
- true, /* flag CVBS ouput enable */
- false, /* flag SIF ouput enable */
- DRXJ_SIF_ATTENUATION_0DB, /* current SIF att setting */
- { /* qam_rf_agc_cfg */
- DRX_STANDARD_ITU_B, /* standard */
- DRX_AGC_CTRL_AUTO, /* ctrl_mode */
- 0, /* output_level */
- 0, /* min_output_level */
- 0xFFFF, /* max_output_level */
- 0x0000, /* speed */
- 0x0000, /* top */
- 0x0000 /* c.o.c. */
- },
- { /* qam_if_agc_cfg */
- DRX_STANDARD_ITU_B, /* standard */
- DRX_AGC_CTRL_AUTO, /* ctrl_mode */
- 0, /* output_level */
- 0, /* min_output_level */
- 0xFFFF, /* max_output_level */
- 0x0000, /* speed */
- 0x0000, /* top (don't care) */
- 0x0000 /* c.o.c. (don't care) */
- },
- { /* vsb_rf_agc_cfg */
- DRX_STANDARD_8VSB, /* standard */
- DRX_AGC_CTRL_AUTO, /* ctrl_mode */
- 0, /* output_level */
- 0, /* min_output_level */
- 0xFFFF, /* max_output_level */
- 0x0000, /* speed */
- 0x0000, /* top (don't care) */
- 0x0000 /* c.o.c. (don't care) */
- },
- { /* vsb_if_agc_cfg */
- DRX_STANDARD_8VSB, /* standard */
- DRX_AGC_CTRL_AUTO, /* ctrl_mode */
- 0, /* output_level */
- 0, /* min_output_level */
- 0xFFFF, /* max_output_level */
- 0x0000, /* speed */
- 0x0000, /* top (don't care) */
- 0x0000 /* c.o.c. (don't care) */
- },
- 0, /* qam_pga_cfg */
- 0, /* vsb_pga_cfg */
- { /* qam_pre_saw_cfg */
- DRX_STANDARD_ITU_B, /* standard */
- 0, /* reference */
- false /* use_pre_saw */
- },
- { /* vsb_pre_saw_cfg */
- DRX_STANDARD_8VSB, /* standard */
- 0, /* reference */
- false /* use_pre_saw */
- },
- /* Version information */
- #ifndef _CH_
- {
- "01234567890", /* human readable version microcode */
- "01234567890" /* human readable version device specific code */
- },
- {
- { /* struct drx_version for microcode */
- DRX_MODULE_UNKNOWN,
- (char *)(NULL),
- 0,
- 0,
- 0,
- (char *)(NULL)
- },
- { /* struct drx_version for device specific code */
- DRX_MODULE_UNKNOWN,
- (char *)(NULL),
- 0,
- 0,
- 0,
- (char *)(NULL)
- }
- },
- {
- { /* struct drx_version_list for microcode */
- (struct drx_version *) (NULL),
- (struct drx_version_list *) (NULL)
- },
- { /* struct drx_version_list for device specific code */
- (struct drx_version *) (NULL),
- (struct drx_version_list *) (NULL)
- }
- },
- #endif
- false, /* smart_ant_inverted */
- /* Tracking filter setting for OOB */
- {
- 12000,
- 9300,
- 6600,
- 5280,
- 3700,
- 3000,
- 2000,
- 0},
- false, /* oob_power_on */
- 0, /* mpeg_ts_static_bitrate */
- false, /* disable_te_ihandling */
- false, /* bit_reverse_mpeg_outout */
- DRXJ_MPEGOUTPUT_CLOCK_RATE_AUTO, /* mpeg_output_clock_rate */
- DRXJ_MPEG_START_WIDTH_1CLKCYC, /* mpeg_start_width */
- /* Pre SAW & Agc configuration for ATV */
- {
- DRX_STANDARD_NTSC, /* standard */
- 7, /* reference */
- true /* use_pre_saw */
- },
- { /* ATV RF-AGC */
- DRX_STANDARD_NTSC, /* standard */
- DRX_AGC_CTRL_AUTO, /* ctrl_mode */
- 0, /* output_level */
- 0, /* min_output_level (d.c.) */
- 0, /* max_output_level (d.c.) */
- 3, /* speed */
- 9500, /* top */
- 4000 /* cut-off current */
- },
- { /* ATV IF-AGC */
- DRX_STANDARD_NTSC, /* standard */
- DRX_AGC_CTRL_AUTO, /* ctrl_mode */
- 0, /* output_level */
- 0, /* min_output_level (d.c.) */
- 0, /* max_output_level (d.c.) */
- 3, /* speed */
- 2400, /* top */
- 0 /* c.o.c. (d.c.) */
- },
- 140, /* ATV PGA config */
- 0, /* curr_symbol_rate */
- false, /* pdr_safe_mode */
- SIO_PDR_GPIO_CFG__PRE, /* pdr_safe_restore_val_gpio */
- SIO_PDR_VSYNC_CFG__PRE, /* pdr_safe_restore_val_v_sync */
- SIO_PDR_SMA_RX_CFG__PRE, /* pdr_safe_restore_val_sma_rx */
- SIO_PDR_SMA_TX_CFG__PRE, /* pdr_safe_restore_val_sma_tx */
- 4, /* oob_pre_saw */
- DRXJ_OOB_LO_POW_MINUS10DB, /* oob_lo_pow */
- {
- false /* aud_data, only first member */
- },
- };
- /**
- * \var drxj_default_addr_g
- * \brief Default I2C address and device identifier.
- */
- static struct i2c_device_addr drxj_default_addr_g = {
- DRXJ_DEF_I2C_ADDR, /* i2c address */
- DRXJ_DEF_DEMOD_DEV_ID /* device id */
- };
- /**
- * \var drxj_default_comm_attr_g
- * \brief Default common attributes of a drxj demodulator instance.
- */
- static struct drx_common_attr drxj_default_comm_attr_g = {
- NULL, /* ucode file */
- true, /* ucode verify switch */
- {0}, /* version record */
- 44000, /* IF in kHz in case no tuner instance is used */
- (151875 - 0), /* system clock frequency in kHz */
- 0, /* oscillator frequency kHz */
- 0, /* oscillator deviation in ppm, signed */
- false, /* If true mirror frequency spectrum */
- {
- /* MPEG output configuration */
- true, /* If true, enable MPEG ouput */
- false, /* If true, insert RS byte */
- false, /* If true, parallel out otherwise serial */
- false, /* If true, invert DATA signals */
- false, /* If true, invert ERR signal */
- false, /* If true, invert STR signals */
- false, /* If true, invert VAL signals */
- false, /* If true, invert CLK signals */
- true, /* If true, static MPEG clockrate will
- be used, otherwise clockrate will
- adapt to the bitrate of the TS */
- 19392658UL, /* Maximum bitrate in b/s in case
- static clockrate is selected */
- DRX_MPEG_STR_WIDTH_1 /* MPEG Start width in clock cycles */
- },
- /* Initilisations below can be omitted, they require no user input and
- are initialy 0, NULL or false. The compiler will initialize them to these
- values when omitted. */
- false, /* is_opened */
- /* SCAN */
- NULL, /* no scan params yet */
- 0, /* current scan index */
- 0, /* next scan frequency */
- false, /* scan ready flag */
- 0, /* max channels to scan */
- 0, /* nr of channels scanned */
- NULL, /* default scan function */
- NULL, /* default context pointer */
- 0, /* millisec to wait for demod lock */
- DRXJ_DEMOD_LOCK, /* desired lock */
- false,
- /* Power management */
- DRX_POWER_UP,
- /* Tuner */
- 1, /* nr of I2C port to wich tuner is */
- 0L, /* minimum RF input frequency, in kHz */
- 0L, /* maximum RF input frequency, in kHz */
- false, /* Rf Agc Polarity */
- false, /* If Agc Polarity */
- false, /* tuner slow mode */
- { /* current channel (all 0) */
- 0UL /* channel.frequency */
- },
- DRX_STANDARD_UNKNOWN, /* current standard */
- DRX_STANDARD_UNKNOWN, /* previous standard */
- DRX_STANDARD_UNKNOWN, /* di_cache_standard */
- false, /* use_bootloader */
- 0UL, /* capabilities */
- 0 /* mfx */
- };
- /**
- * \var drxj_default_demod_g
- * \brief Default drxj demodulator instance.
- */
- static struct drx_demod_instance drxj_default_demod_g = {
- &drxj_default_addr_g, /* i2c address & device id */
- &drxj_default_comm_attr_g, /* demod common attributes */
- &drxj_data_g /* demod device specific attributes */
- };
- /**
- * \brief Default audio data structure for DRK demodulator instance.
- *
- * This structure is DRXK specific.
- *
- */
- static struct drx_aud_data drxj_default_aud_data_g = {
- false, /* audio_is_active */
- DRX_AUD_STANDARD_AUTO, /* audio_standard */
- /* i2sdata */
- {
- false, /* output_enable */
- 48000, /* frequency */
- DRX_I2S_MODE_MASTER, /* mode */
- DRX_I2S_WORDLENGTH_32, /* word_length */
- DRX_I2S_POLARITY_RIGHT, /* polarity */
- DRX_I2S_FORMAT_WS_WITH_DATA /* format */
- },
- /* volume */
- {
- true, /* mute; */
- 0, /* volume */
- DRX_AUD_AVC_OFF, /* avc_mode */
- 0, /* avc_ref_level */
- DRX_AUD_AVC_MAX_GAIN_12DB, /* avc_max_gain */
- DRX_AUD_AVC_MAX_ATTEN_24DB, /* avc_max_atten */
- 0, /* strength_left */
- 0 /* strength_right */
- },
- DRX_AUD_AUTO_SOUND_SELECT_ON_CHANGE_ON, /* auto_sound */
- /* ass_thresholds */
- {
- 440, /* A2 */
- 12, /* BTSC */
- 700, /* NICAM */
- },
- /* carrier */
- {
- /* a */
- {
- 42, /* thres */
- DRX_NO_CARRIER_NOISE, /* opt */
- 0, /* shift */
- 0 /* dco */
- },
- /* b */
- {
- 42, /* thres */
- DRX_NO_CARRIER_MUTE, /* opt */
- 0, /* shift */
- 0 /* dco */
- },
- },
- /* mixer */
- {
- DRX_AUD_SRC_STEREO_OR_A, /* source_i2s */
- DRX_AUD_I2S_MATRIX_STEREO, /* matrix_i2s */
- DRX_AUD_FM_MATRIX_SOUND_A /* matrix_fm */
- },
- DRX_AUD_DEVIATION_NORMAL, /* deviation */
- DRX_AUD_AVSYNC_OFF, /* av_sync */
- /* prescale */
- {
- DRX_AUD_MAX_FM_DEVIATION, /* fm_deviation */
- DRX_AUD_MAX_NICAM_PRESCALE /* nicam_gain */
- },
- DRX_AUD_FM_DEEMPH_75US, /* deemph */
- DRX_BTSC_STEREO, /* btsc_detect */
- 0, /* rds_data_counter */
- false /* rds_data_present */
- };
- /*-----------------------------------------------------------------------------
- STRUCTURES
- ----------------------------------------------------------------------------*/
- struct drxjeq_stat {
- u16 eq_mse;
- u8 eq_mode;
- u8 eq_ctrl;
- u8 eq_stat;
- };
- /* HI command */
- struct drxj_hi_cmd {
- u16 cmd;
- u16 param1;
- u16 param2;
- u16 param3;
- u16 param4;
- u16 param5;
- u16 param6;
- };
- /*============================================================================*/
- /*=== MICROCODE RELATED STRUCTURES ===========================================*/
- /*============================================================================*/
- /**
- * struct drxu_code_block_hdr - Structure of the microcode block headers
- *
- * @addr: Destination address of the data in this block
- * @size: Size of the block data following this header counted in
- * 16 bits words
- * @CRC: CRC value of the data block, only valid if CRC flag is
- * set.
- */
- struct drxu_code_block_hdr {
- u32 addr;
- u16 size;
- u16 flags;
- u16 CRC;
- };
- /*-----------------------------------------------------------------------------
- FUNCTIONS
- ----------------------------------------------------------------------------*/
- /* Some prototypes */
- static int
- hi_command(struct i2c_device_addr *dev_addr,
- const struct drxj_hi_cmd *cmd, u16 *result);
- static int
- ctrl_lock_status(struct drx_demod_instance *demod, enum drx_lock_status *lock_stat);
- static int
- ctrl_power_mode(struct drx_demod_instance *demod, enum drx_power_mode *mode);
- static int power_down_aud(struct drx_demod_instance *demod);
- static int
- ctrl_set_cfg_pre_saw(struct drx_demod_instance *demod, struct drxj_cfg_pre_saw *pre_saw);
- static int
- ctrl_set_cfg_afe_gain(struct drx_demod_instance *demod, struct drxj_cfg_afe_gain *afe_gain);
- /*============================================================================*/
- /*============================================================================*/
- /*== HELPER FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /*============================================================================*/
- /*
- * \fn u32 frac28(u32 N, u32 D)
- * \brief Compute: (1<<28)*N/D
- * \param N 32 bits
- * \param D 32 bits
- * \return (1<<28)*N/D
- * This function is used to avoid floating-point calculations as they may
- * not be present on the target platform.
- * frac28 performs an unsigned 28/28 bits division to 32-bit fixed point
- * fraction used for setting the Frequency Shifter registers.
- * N and D can hold numbers up to width: 28-bits.
- * The 4 bits integer part and the 28 bits fractional part are calculated.
- * Usage condition: ((1<<28)*n)/d < ((1<<32)-1) => (n/d) < 15.999
- * N: 0...(1<<28)-1 = 268435454
- * D: 0...(1<<28)-1
- * Q: 0...(1<<32)-1
- */
- static u32 frac28(u32 N, u32 D)
- {
- int i = 0;
- u32 Q1 = 0;
- u32 R0 = 0;
- R0 = (N % D) << 4; /* 32-28 == 4 shifts possible at max */
- Q1 = N / D; /* integer part, only the 4 least significant bits
- will be visible in the result */
- /* division using radix 16, 7 nibbles in the result */
- for (i = 0; i < 7; i++) {
- Q1 = (Q1 << 4) | R0 / D;
- R0 = (R0 % D) << 4;
- }
- /* rounding */
- if ((R0 >> 3) >= D)
- Q1++;
- return Q1;
- }
- /**
- * \fn u32 log1_times100( u32 x)
- * \brief Compute: 100*log10(x)
- * \param x 32 bits
- * \return 100*log10(x)
- *
- * 100*log10(x)
- * = 100*(log2(x)/log2(10)))
- * = (100*(2^15)*log2(x))/((2^15)*log2(10))
- * = ((200*(2^15)*log2(x))/((2^15)*log2(10)))/2
- * = ((200*(2^15)*(log2(x/y)+log2(y)))/((2^15)*log2(10)))/2
- * = ((200*(2^15)*log2(x/y))+(200*(2^15)*log2(y)))/((2^15)*log2(10)))/2
- *
- * where y = 2^k and 1<= (x/y) < 2
- */
- static u32 log1_times100(u32 x)
- {
- static const u8 scale = 15;
- static const u8 index_width = 5;
- /*
- log2lut[n] = (1<<scale) * 200 * log2( 1.0 + ( (1.0/(1<<INDEXWIDTH)) * n ))
- 0 <= n < ((1<<INDEXWIDTH)+1)
- */
- static const u32 log2lut[] = {
- 0, /* 0.000000 */
- 290941, /* 290941.300628 */
- 573196, /* 573196.476418 */
- 847269, /* 847269.179851 */
- 1113620, /* 1113620.489452 */
- 1372674, /* 1372673.576986 */
- 1624818, /* 1624817.752104 */
- 1870412, /* 1870411.981536 */
- 2109788, /* 2109787.962654 */
- 2343253, /* 2343252.817465 */
- 2571091, /* 2571091.461923 */
- 2793569, /* 2793568.696416 */
- 3010931, /* 3010931.055901 */
- 3223408, /* 3223408.452106 */
- 3431216, /* 3431215.635215 */
- 3634553, /* 3634553.498355 */
- 3833610, /* 3833610.244726 */
- 4028562, /* 4028562.434393 */
- 4219576, /* 4219575.925308 */
- 4406807, /* 4406806.721144 */
- 4590402, /* 4590401.736809 */
- 4770499, /* 4770499.491025 */
- 4947231, /* 4947230.734179 */
- 5120719, /* 5120719.018555 */
- 5291081, /* 5291081.217197 */
- 5458428, /* 5458427.996830 */
- 5622864, /* 5622864.249668 */
- 5784489, /* 5784489.488298 */
- 5943398, /* 5943398.207380 */
- 6099680, /* 6099680.215452 */
- 6253421, /* 6253420.939751 */
- 6404702, /* 6404701.706649 */
- 6553600, /* 6553600.000000 */
- };
- u8 i = 0;
- u32 y = 0;
- u32 d = 0;
- u32 k = 0;
- u32 r = 0;
- if (x == 0)
- return 0;
- /* Scale x (normalize) */
- /* computing y in log(x/y) = log(x) - log(y) */
- if ((x & (((u32) (-1)) << (scale + 1))) == 0) {
- for (k = scale; k > 0; k--) {
- if (x & (((u32) 1) << scale))
- break;
- x <<= 1;
- }
- } else {
- for (k = scale; k < 31; k++) {
- if ((x & (((u32) (-1)) << (scale + 1))) == 0)
- break;
- x >>= 1;
- }
- }
- /*
- Now x has binary point between bit[scale] and bit[scale-1]
- and 1.0 <= x < 2.0 */
- /* correction for division: log(x) = log(x/y)+log(y) */
- y = k * ((((u32) 1) << scale) * 200);
- /* remove integer part */
- x &= ((((u32) 1) << scale) - 1);
- /* get index */
- i = (u8) (x >> (scale - index_width));
- /* compute delta (x-a) */
- d = x & ((((u32) 1) << (scale - index_width)) - 1);
- /* compute log, multiplication ( d* (.. )) must be within range ! */
- y += log2lut[i] +
- ((d * (log2lut[i + 1] - log2lut[i])) >> (scale - index_width));
- /* Conver to log10() */
- y /= 108853; /* (log2(10) << scale) */
- r = (y >> 1);
- /* rounding */
- if (y & ((u32)1))
- r++;
- return r;
- }
- /**
- * \fn u32 frac_times1e6( u16 N, u32 D)
- * \brief Compute: (N/D) * 1000000.
- * \param N nominator 16-bits.
- * \param D denominator 32-bits.
- * \return u32
- * \retval ((N/D) * 1000000), 32 bits
- *
- * No check on D=0!
- */
- static u32 frac_times1e6(u32 N, u32 D)
- {
- u32 remainder = 0;
- u32 frac = 0;
- /*
- frac = (N * 1000000) / D
- To let it fit in a 32 bits computation:
- frac = (N * (1000000 >> 4)) / (D >> 4)
- This would result in a problem in case D < 16 (div by 0).
- So we do it more elaborate as shown below.
- */
- frac = (((u32) N) * (1000000 >> 4)) / D;
- frac <<= 4;
- remainder = (((u32) N) * (1000000 >> 4)) % D;
- remainder <<= 4;
- frac += remainder / D;
- remainder = remainder % D;
- if ((remainder * 2) > D)
- frac++;
- return frac;
- }
- /*============================================================================*/
- /**
- * \brief Values for NICAM prescaler gain. Computed from dB to integer
- * and rounded. For calc used formula: 16*10^(prescaleGain[dB]/20).
- *
- */
- static const u16 nicam_presc_table_val[43] = {
- 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4,
- 5, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 16,
- 18, 20, 23, 25, 28, 32, 36, 40, 45,
- 51, 57, 64, 71, 80, 90, 101, 113, 127
- };
- /*============================================================================*/
- /*== END HELPER FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /*============================================================================*/
- /*== DRXJ DAP FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /*
- This layer takes care of some device specific register access protocols:
- -conversion to short address format
- -access to audio block
- This layer is placed between the drx_dap_fasi and the rest of the drxj
- specific implementation. This layer can use address map knowledge whereas
- dap_fasi may not use memory map knowledge.
- * For audio currently only 16 bits read and write register access is
- supported. More is not needed. RMW and 32 or 8 bit access on audio
- registers will have undefined behaviour. Flags (RMW, CRC reset, broadcast
- single/multi master) will be ignored.
- TODO: check ignoring single/multimaster is ok for AUD access ?
- */
- #define DRXJ_ISAUDWRITE(addr) (((((addr)>>16)&1) == 1) ? true : false)
- #define DRXJ_DAP_AUDTRIF_TIMEOUT 80 /* millisec */
- /*============================================================================*/
- /**
- * \fn bool is_handled_by_aud_tr_if( u32 addr )
- * \brief Check if this address is handled by the audio token ring interface.
- * \param addr
- * \return bool
- * \retval true Yes, handled by audio token ring interface
- * \retval false No, not handled by audio token ring interface
- *
- */
- static
- bool is_handled_by_aud_tr_if(u32 addr)
- {
- bool retval = false;
- if ((DRXDAP_FASI_ADDR2BLOCK(addr) == 4) &&
- (DRXDAP_FASI_ADDR2BANK(addr) > 1) &&
- (DRXDAP_FASI_ADDR2BANK(addr) < 6)) {
- retval = true;
- }
- return retval;
- }
- /*============================================================================*/
- int drxbsp_i2c_write_read(struct i2c_device_addr *w_dev_addr,
- u16 w_count,
- u8 *wData,
- struct i2c_device_addr *r_dev_addr,
- u16 r_count, u8 *r_data)
- {
- struct drx39xxj_state *state;
- struct i2c_msg msg[2];
- unsigned int num_msgs;
- if (w_dev_addr == NULL) {
- /* Read only */
- state = r_dev_addr->user_data;
- msg[0].addr = r_dev_addr->i2c_addr >> 1;
- msg[0].flags = I2C_M_RD;
- msg[0].buf = r_data;
- msg[0].len = r_count;
- num_msgs = 1;
- } else if (r_dev_addr == NULL) {
- /* Write only */
- state = w_dev_addr->user_data;
- msg[0].addr = w_dev_addr->i2c_addr >> 1;
- msg[0].flags = 0;
- msg[0].buf = wData;
- msg[0].len = w_count;
- num_msgs = 1;
- } else {
- /* Both write and read */
- state = w_dev_addr->user_data;
- msg[0].addr = w_dev_addr->i2c_addr >> 1;
- msg[0].flags = 0;
- msg[0].buf = wData;
- msg[0].len = w_count;
- msg[1].addr = r_dev_addr->i2c_addr >> 1;
- msg[1].flags = I2C_M_RD;
- msg[1].buf = r_data;
- msg[1].len = r_count;
- num_msgs = 2;
- }
- if (state->i2c == NULL) {
- pr_err("i2c was zero, aborting\n");
- return 0;
- }
- if (i2c_transfer(state->i2c, msg, num_msgs) != num_msgs) {
- pr_warn("drx3933: I2C write/read failed\n");
- return -EREMOTEIO;
- }
- #ifdef DJH_DEBUG
- if (w_dev_addr == NULL || r_dev_addr == NULL)
- return 0;
- state = w_dev_addr->user_data;
- if (state->i2c == NULL)
- return 0;
- msg[0].addr = w_dev_addr->i2c_addr;
- msg[0].flags = 0;
- msg[0].buf = wData;
- msg[0].len = w_count;
- msg[1].addr = r_dev_addr->i2c_addr;
- msg[1].flags = I2C_M_RD;
- msg[1].buf = r_data;
- msg[1].len = r_count;
- num_msgs = 2;
- pr_debug("drx3933 i2c operation addr=%x i2c=%p, wc=%x rc=%x\n",
- w_dev_addr->i2c_addr, state->i2c, w_count, r_count);
- if (i2c_transfer(state->i2c, msg, 2) != 2) {
- pr_warn("drx3933: I2C write/read failed\n");
- return -EREMOTEIO;
- }
- #endif
- return 0;
- }
- /*============================================================================*/
- /******************************
- *
- * int drxdap_fasi_read_block (
- * struct i2c_device_addr *dev_addr, -- address of I2C device
- * u32 addr, -- address of chip register/memory
- * u16 datasize, -- number of bytes to read
- * u8 *data, -- data to receive
- * u32 flags) -- special device flags
- *
- * Read block data from chip address. Because the chip is word oriented,
- * the number of bytes to read must be even.
- *
- * Make sure that the buffer to receive the data is large enough.
- *
- * Although this function expects an even number of bytes, it is still byte
- * oriented, and the data read back is NOT translated to the endianness of
- * the target platform.
- *
- * Output:
- * - 0 if reading was successful
- * in that case: data read is in *data.
- * - -EIO if anything went wrong
- *
- ******************************/
- static int drxdap_fasi_read_block(struct i2c_device_addr *dev_addr,
- u32 addr,
- u16 datasize,
- u8 *data, u32 flags)
- {
- u8 buf[4];
- u16 bufx;
- int rc;
- u16 overhead_size = 0;
- /* Check parameters ******************************************************* */
- if (dev_addr == NULL)
- return -EINVAL;
- overhead_size = (IS_I2C_10BIT(dev_addr->i2c_addr) ? 2 : 1) +
- (DRXDAP_FASI_LONG_FORMAT(addr) ? 4 : 2);
- if ((DRXDAP_FASI_OFFSET_TOO_LARGE(addr)) ||
- ((!(DRXDAPFASI_LONG_ADDR_ALLOWED)) &&
- DRXDAP_FASI_LONG_FORMAT(addr)) ||
- (overhead_size > (DRXDAP_MAX_WCHUNKSIZE)) ||
- ((datasize != 0) && (data == NULL)) || ((datasize & 1) == 1)) {
- return -EINVAL;
- }
- /* ReadModifyWrite & mode flag bits are not allowed */
- flags &= (~DRXDAP_FASI_RMW & ~DRXDAP_FASI_MODEFLAGS);
- #if DRXDAP_SINGLE_MASTER
- flags |= DRXDAP_FASI_SINGLE_MASTER;
- #endif
- /* Read block from I2C **************************************************** */
- do {
- u16 todo = (datasize < DRXDAP_MAX_RCHUNKSIZE ?
- datasize : DRXDAP_MAX_RCHUNKSIZE);
- bufx = 0;
- addr &= ~DRXDAP_FASI_FLAGS;
- addr |= flags;
- #if ((DRXDAPFASI_LONG_ADDR_ALLOWED == 1) && (DRXDAPFASI_SHORT_ADDR_ALLOWED == 1))
- /* short format address preferred but long format otherwise */
- if (DRXDAP_FASI_LONG_FORMAT(addr)) {
- #endif
- #if (DRXDAPFASI_LONG_ADDR_ALLOWED == 1)
- buf[bufx++] = (u8) (((addr << 1) & 0xFF) | 0x01);
- buf[bufx++] = (u8) ((addr >> 16) & 0xFF);
- buf[bufx++] = (u8) ((addr >> 24) & 0xFF);
- buf[bufx++] = (u8) ((addr >> 7) & 0xFF);
- #endif
- #if ((DRXDAPFASI_LONG_ADDR_ALLOWED == 1) && (DRXDAPFASI_SHORT_ADDR_ALLOWED == 1))
- } else {
- #endif
- #if (DRXDAPFASI_SHORT_ADDR_ALLOWED == 1)
- buf[bufx++] = (u8) ((addr << 1) & 0xFF);
- buf[bufx++] =
- (u8) (((addr >> 16) & 0x0F) |
- ((addr >> 18) & 0xF0));
- #endif
- #if ((DRXDAPFASI_LONG_ADDR_ALLOWED == 1) && (DRXDAPFASI_SHORT_ADDR_ALLOWED == 1))
- }
- #endif
- #if DRXDAP_SINGLE_MASTER
- /*
- * In single master mode, split the read and write actions.
- * No special action is needed for write chunks here.
- */
- rc = drxbsp_i2c_write_read(dev_addr, bufx, buf,
- NULL, 0, NULL);
- if (rc == 0)
- rc = drxbsp_i2c_write_read(NULL, 0, NULL, dev_addr, todo, data);
- #else
- /* In multi master mode, do everything in one RW action */
- rc = drxbsp_i2c_write_read(dev_addr, bufx, buf, dev_addr, todo,
- data);
- #endif
- data += todo;
- addr += (todo >> 1);
- datasize -= todo;
- } while (datasize && rc == 0);
- return rc;
- }
- /******************************
- *
- * int drxdap_fasi_read_reg16 (
- * struct i2c_device_addr *dev_addr, -- address of I2C device
- * u32 addr, -- address of chip register/memory
- * u16 *data, -- data to receive
- * u32 flags) -- special device flags
- *
- * Read one 16-bit register or memory location. The data received back is
- * converted back to the target platform's endianness.
- *
- * Output:
- * - 0 if reading was successful
- * in that case: read data is at *data
- * - -EIO if anything went wrong
- *
- ******************************/
- static int drxdap_fasi_read_reg16(struct i2c_device_addr *dev_addr,
- u32 addr,
- u16 *data, u32 flags)
- {
- u8 buf[sizeof(*data)];
- int rc;
- if (!data)
- return -EINVAL;
- rc = drxdap_fasi_read_block(dev_addr, addr, sizeof(*data), buf, flags);
- *data = buf[0] + (((u16) buf[1]) << 8);
- return rc;
- }
- /******************************
- *
- * int drxdap_fasi_read_reg32 (
- * struct i2c_device_addr *dev_addr, -- address of I2C device
- * u32 addr, -- address of chip register/memory
- * u32 *data, -- data to receive
- * u32 flags) -- special device flags
- *
- * Read one 32-bit register or memory location. The data received back is
- * converted back to the target platform's endianness.
- *
- * Output:
- * - 0 if reading was successful
- * in that case: read data is at *data
- * - -EIO if anything went wrong
- *
- ******************************/
- static int drxdap_fasi_read_reg32(struct i2c_device_addr *dev_addr,
- u32 addr,
- u32 *data, u32 flags)
- {
- u8 buf[sizeof(*data)];
- int rc;
- if (!data)
- return -EINVAL;
- rc = drxdap_fasi_read_block(dev_addr, addr, sizeof(*data), buf, flags);
- *data = (((u32) buf[0]) << 0) +
- (((u32) buf[1]) << 8) +
- (((u32) buf[2]) << 16) + (((u32) buf[3]) << 24);
- return rc;
- }
- /******************************
- *
- * int drxdap_fasi_write_block (
- * struct i2c_device_addr *dev_addr, -- address of I2C device
- * u32 addr, -- address of chip register/memory
- * u16 datasize, -- number of bytes to read
- * u8 *data, -- data to receive
- * u32 flags) -- special device flags
- *
- * Write block data to chip address. Because the chip is word oriented,
- * the number of bytes to write must be even.
- *
- * Although this function expects an even number of bytes, it is still byte
- * oriented, and the data being written is NOT translated from the endianness of
- * the target platform.
- *
- * Output:
- * - 0 if writing was successful
- * - -EIO if anything went wrong
- *
- ******************************/
- static int drxdap_fasi_write_block(struct i2c_device_addr *dev_addr,
- u32 addr,
- u16 datasize,
- u8 *data, u32 flags)
- {
- u8 buf[DRXDAP_MAX_WCHUNKSIZE];
- int st = -EIO;
- int first_err = 0;
- u16 overhead_size = 0;
- u16 block_size = 0;
- /* Check parameters ******************************************************* */
- if (dev_addr == NULL)
- return -EINVAL;
- overhead_size = (IS_I2C_10BIT(dev_addr->i2c_addr) ? 2 : 1) +
- (DRXDAP_FASI_LONG_FORMAT(addr) ? 4 : 2);
- if ((DRXDAP_FASI_OFFSET_TOO_LARGE(addr)) ||
- ((!(DRXDAPFASI_LONG_ADDR_ALLOWED)) &&
- DRXDAP_FASI_LONG_FORMAT(addr)) ||
- (overhead_size > (DRXDAP_MAX_WCHUNKSIZE)) ||
- ((datasize != 0) && (data == NULL)) || ((datasize & 1) == 1))
- return -EINVAL;
- flags &= DRXDAP_FASI_FLAGS;
- flags &= ~DRXDAP_FASI_MODEFLAGS;
- #if DRXDAP_SINGLE_MASTER
- flags |= DRXDAP_FASI_SINGLE_MASTER;
- #endif
- /* Write block to I2C ***************************************************** */
- block_size = ((DRXDAP_MAX_WCHUNKSIZE) - overhead_size) & ~1;
- do {
- u16 todo = 0;
- u16 bufx = 0;
- /* Buffer device address */
- addr &= ~DRXDAP_FASI_FLAGS;
- addr |= flags;
- #if (((DRXDAPFASI_LONG_ADDR_ALLOWED) == 1) && ((DRXDAPFASI_SHORT_ADDR_ALLOWED) == 1))
- /* short format address preferred but long format otherwise */
- if (DRXDAP_FASI_LONG_FORMAT(addr)) {
- #endif
- #if ((DRXDAPFASI_LONG_ADDR_ALLOWED) == 1)
- buf[bufx++] = (u8) (((addr << 1) & 0xFF) | 0x01);
- buf[bufx++] = (u8) ((addr >> 16) & 0xFF);
- buf[bufx++] = (u8) ((addr >> 24) & 0xFF);
- buf[bufx++] = (u8) ((addr >> 7) & 0xFF);
- #endif
- #if (((DRXDAPFASI_LONG_ADDR_ALLOWED) == 1) && ((DRXDAPFASI_SHORT_ADDR_ALLOWED) == 1))
- } else {
- #endif
- #if ((DRXDAPFASI_SHORT_ADDR_ALLOWED) == 1)
- buf[bufx++] = (u8) ((addr << 1) & 0xFF);
- buf[bufx++] =
- (u8) (((addr >> 16) & 0x0F) |
- ((addr >> 18) & 0xF0));
- #endif
- #if (((DRXDAPFASI_LONG_ADDR_ALLOWED) == 1) && ((DRXDAPFASI_SHORT_ADDR_ALLOWED) == 1))
- }
- #endif
- /*
- In single master mode block_size can be 0. In such a case this I2C
- sequense will be visible: (1) write address {i2c addr,
- 4 bytes chip address} (2) write data {i2c addr, 4 bytes data }
- (3) write address (4) write data etc...
- Address must be rewriten because HI is reset after data transport and
- expects an address.
- */
- todo = (block_size < datasize ? block_size : datasize);
- if (todo == 0) {
- u16 overhead_size_i2c_addr = 0;
- u16 data_block_size = 0;
- overhead_size_i2c_addr =
- (IS_I2C_10BIT(dev_addr->i2c_addr) ? 2 : 1);
- data_block_size =
- (DRXDAP_MAX_WCHUNKSIZE - overhead_size_i2c_addr) & ~1;
- /* write device address */
- st = drxbsp_i2c_write_read(dev_addr,
- (u16) (bufx),
- buf,
- (struct i2c_device_addr *)(NULL),
- 0, (u8 *)(NULL));
- if ((st != 0) && (first_err == 0)) {
- /* at the end, return the first error encountered */
- first_err = st;
- }
- bufx = 0;
- todo =
- (data_block_size <
- datasize ? data_block_size : datasize);
- }
- memcpy(&buf[bufx], data, todo);
- /* write (address if can do and) data */
- st = drxbsp_i2c_write_read(dev_addr,
- (u16) (bufx + todo),
- buf,
- (struct i2c_device_addr *)(NULL),
- 0, (u8 *)(NULL));
- if ((st != 0) && (first_err == 0)) {
- /* at the end, return the first error encountered */
- first_err = st;
- }
- datasize -= todo;
- data += todo;
- addr += (todo >> 1);
- } while (datasize);
- return first_err;
- }
- /******************************
- *
- * int drxdap_fasi_write_reg16 (
- * struct i2c_device_addr *dev_addr, -- address of I2C device
- * u32 addr, -- address of chip register/memory
- * u16 data, -- data to send
- * u32 flags) -- special device flags
- *
- * Write one 16-bit register or memory location. The data being written is
- * converted from the target platform's endianness to little endian.
- *
- * Output:
- * - 0 if writing was successful
- * - -EIO if anything went wrong
- *
- ******************************/
- static int drxdap_fasi_write_reg16(struct i2c_device_addr *dev_addr,
- u32 addr,
- u16 data, u32 flags)
- {
- u8 buf[sizeof(data)];
- buf[0] = (u8) ((data >> 0) & 0xFF);
- buf[1] = (u8) ((data >> 8) & 0xFF);
- return drxdap_fasi_write_block(dev_addr, addr, sizeof(data), buf, flags);
- }
- /******************************
- *
- * int drxdap_fasi_read_modify_write_reg16 (
- * struct i2c_device_addr *dev_addr, -- address of I2C device
- * u32 waddr, -- address of chip register/memory
- * u32 raddr, -- chip address to read back from
- * u16 wdata, -- data to send
- * u16 *rdata) -- data to receive back
- *
- * Write 16-bit data, then read back the original contents of that location.
- * Requires long addressing format to be allowed.
- *
- * Before sending data, the data is converted to little endian. The
- * data received back is converted back to the target platform's endianness.
- *
- * WARNING: This function is only guaranteed to work if there is one
- * master on the I2C bus.
- *
- * Output:
- * - 0 if reading was successful
- * in that case: read back data is at *rdata
- * - -EIO if anything went wrong
- *
- ******************************/
- static int drxdap_fasi_read_modify_write_reg16(struct i2c_device_addr *dev_addr,
- u32 waddr,
- u32 raddr,
- u16 wdata, u16 *rdata)
- {
- int rc = -EIO;
- #if (DRXDAPFASI_LONG_ADDR_ALLOWED == 1)
- if (rdata == NULL)
- return -EINVAL;
- rc = drxdap_fasi_write_reg16(dev_addr, waddr, wdata, DRXDAP_FASI_RMW);
- if (rc == 0)
- rc = drxdap_fasi_read_reg16(dev_addr, raddr, rdata, 0);
- #endif
- return rc;
- }
- /******************************
- *
- * int drxdap_fasi_write_reg32 (
- * struct i2c_device_addr *dev_addr, -- address of I2C device
- * u32 addr, -- address of chip register/memory
- * u32 data, -- data to send
- * u32 flags) -- special device flags
- *
- * Write one 32-bit register or memory location. The data being written is
- * converted from the target platform's endianness to little endian.
- *
- * Output:
- * - 0 if writing was successful
- * - -EIO if anything went wrong
- *
- ******************************/
- static int drxdap_fasi_write_reg32(struct i2c_device_addr *dev_addr,
- u32 addr,
- u32 data, u32 flags)
- {
- u8 buf[sizeof(data)];
- buf[0] = (u8) ((data >> 0) & 0xFF);
- buf[1] = (u8) ((data >> 8) & 0xFF);
- buf[2] = (u8) ((data >> 16) & 0xFF);
- buf[3] = (u8) ((data >> 24) & 0xFF);
- return drxdap_fasi_write_block(dev_addr, addr, sizeof(data), buf, flags);
- }
- /*============================================================================*/
- /**
- * \fn int drxj_dap_rm_write_reg16short
- * \brief Read modify write 16 bits audio register using short format only.
- * \param dev_addr
- * \param waddr Address to write to
- * \param raddr Address to read from (usually SIO_HI_RA_RAM_S0_RMWBUF__A)
- * \param wdata Data to write
- * \param rdata Buffer for data to read
- * \return int
- * \retval 0 Succes
- * \retval -EIO Timeout, I2C error, illegal bank
- *
- * 16 bits register read modify write access using short addressing format only.
- * Requires knowledge of the registermap, thus device dependent.
- * Using DAP FASI directly to avoid endless recursion of RMWs to audio registers.
- *
- */
- /* TODO correct define should be #if ( DRXDAPFASI_SHORT_ADDR_ALLOWED==1 )
- See comments drxj_dap_read_modify_write_reg16 */
- #if (DRXDAPFASI_LONG_ADDR_ALLOWED == 0)
- static int drxj_dap_rm_write_reg16short(struct i2c_device_addr *dev_addr,
- u32 waddr,
- u32 raddr,
- u16 wdata, u16 *rdata)
- {
- int rc;
- if (rdata == NULL)
- return -EINVAL;
- /* Set RMW flag */
- rc = drxdap_fasi_write_reg16(dev_addr,
- SIO_HI_RA_RAM_S0_FLG_ACC__A,
- SIO_HI_RA_RAM_S0_FLG_ACC_S0_RWM__M,
- 0x0000);
- if (rc == 0) {
- /* Write new data: triggers RMW */
- rc = drxdap_fasi_write_reg16(dev_addr, waddr, wdata,
- 0x0000);
- }
- if (rc == 0) {
- /* Read old data */
- rc = drxdap_fasi_read_reg16(dev_addr, raddr, rdata,
- 0x0000);
- }
- if (rc == 0) {
- /* Reset RMW flag */
- rc = drxdap_fasi_write_reg16(dev_addr,
- SIO_HI_RA_RAM_S0_FLG_ACC__A,
- 0, 0x0000);
- }
- return rc;
- }
- #endif
- /*============================================================================*/
- static int drxj_dap_read_modify_write_reg16(struct i2c_device_addr *dev_addr,
- u32 waddr,
- u32 raddr,
- u16 wdata, u16 *rdata)
- {
- /* TODO: correct short/long addressing format decision,
- now long format has higher prio then short because short also
- needs virt bnks (not impl yet) for certain audio registers */
- #if (DRXDAPFASI_LONG_ADDR_ALLOWED == 1)
- return drxdap_fasi_read_modify_write_reg16(dev_addr,
- waddr,
- raddr, wdata, rdata);
- #else
- return drxj_dap_rm_write_reg16short(dev_addr, waddr, raddr, wdata, rdata);
- #endif
- }
- /*============================================================================*/
- /**
- * \fn int drxj_dap_read_aud_reg16
- * \brief Read 16 bits audio register
- * \param dev_addr
- * \param addr
- * \param data
- * \return int
- * \retval 0 Succes
- * \retval -EIO Timeout, I2C error, illegal bank
- *
- * 16 bits register read access via audio token ring interface.
- *
- */
- static int drxj_dap_read_aud_reg16(struct i2c_device_addr *dev_addr,
- u32 addr, u16 *data)
- {
- u32 start_timer = 0;
- u32 current_timer = 0;
- u32 delta_timer = 0;
- u16 tr_status = 0;
- int stat = -EIO;
- /* No read possible for bank 3, return with error */
- if (DRXDAP_FASI_ADDR2BANK(addr) == 3) {
- stat = -EINVAL;
- } else {
- const u32 write_bit = ((dr_xaddr_t) 1) << 16;
- /* Force reset write bit */
- addr &= (~write_bit);
- /* Set up read */
- start_timer = jiffies_to_msecs(jiffies);
- do {
- /* RMW to aud TR IF until request is granted or timeout */
- stat = drxj_dap_read_modify_write_reg16(dev_addr,
- addr,
- SIO_HI_RA_RAM_S0_RMWBUF__A,
- 0x0000, &tr_status);
- if (stat != 0)
- break;
- current_timer = jiffies_to_msecs(jiffies);
- delta_timer = current_timer - start_timer;
- if (delta_timer > DRXJ_DAP_AUDTRIF_TIMEOUT) {
- stat = -EIO;
- break;
- }
- } while (((tr_status & AUD_TOP_TR_CTR_FIFO_LOCK__M) ==
- AUD_TOP_TR_CTR_FIFO_LOCK_LOCKED) ||
- ((tr_status & AUD_TOP_TR_CTR_FIFO_FULL__M) ==
- AUD_TOP_TR_CTR_FIFO_FULL_FULL));
- } /* if ( DRXDAP_FASI_ADDR2BANK(addr)!=3 ) */
- /* Wait for read ready status or timeout */
- if (stat == 0) {
- start_timer = jiffies_to_msecs(jiffies);
- while ((tr_status & AUD_TOP_TR_CTR_FIFO_RD_RDY__M) !=
- AUD_TOP_TR_CTR_FIFO_RD_RDY_READY) {
- stat = drxj_dap_read_reg16(dev_addr,
- AUD_TOP_TR_CTR__A,
- &tr_status, 0x0000);
- if (stat != 0)
- break;
- current_timer = jiffies_to_msecs(jiffies);
- delta_timer = current_timer - start_timer;
- if (delta_timer > DRXJ_DAP_AUDTRIF_TIMEOUT) {
- stat = -EIO;
- break;
- }
- } /* while ( ... ) */
- }
- /* Read value */
- if (stat == 0)
- stat = drxj_dap_read_modify_write_reg16(dev_addr,
- AUD_TOP_TR_RD_REG__A,
- SIO_HI_RA_RAM_S0_RMWBUF__A,
- 0x0000, data);
- return stat;
- }
- /*============================================================================*/
- static int drxj_dap_read_reg16(struct i2c_device_addr *dev_addr,
- u32 addr,
- u16 *data, u32 flags)
- {
- int stat = -EIO;
- /* Check param */
- if ((dev_addr == NULL) || (data == NULL))
- return -EINVAL;
- if (is_handled_by_aud_tr_if(addr))
- stat = drxj_dap_read_aud_reg16(dev_addr, addr, data);
- else
- stat = drxdap_fasi_read_reg16(dev_addr, addr, data, flags);
- return stat;
- }
- /*============================================================================*/
- /**
- * \fn int drxj_dap_write_aud_reg16
- * \brief Write 16 bits audio register
- * \param dev_addr
- * \param addr
- * \param data
- * \return int
- * \retval 0 Succes
- * \retval -EIO Timeout, I2C error, illegal bank
- *
- * 16 bits register write access via audio token ring interface.
- *
- */
- static int drxj_dap_write_aud_reg16(struct i2c_device_addr *dev_addr,
- u32 addr, u16 data)
- {
- int stat = -EIO;
- /* No write possible for bank 2, return with error */
- if (DRXDAP_FASI_ADDR2BANK(addr) == 2) {
- stat = -EINVAL;
- } else {
- u32 start_timer = 0;
- u32 current_timer = 0;
- u32 delta_timer = 0;
- u16 tr_status = 0;
- const u32 write_bit = ((dr_xaddr_t) 1) << 16;
- /* Force write bit */
- addr |= write_bit;
- start_timer = jiffies_to_msecs(jiffies);
- do {
- /* RMW to aud TR IF until request is granted or timeout */
- stat = drxj_dap_read_modify_write_reg16(dev_addr,
- addr,
- SIO_HI_RA_RAM_S0_RMWBUF__A,
- data, &tr_status);
- if (stat != 0)
- break;
- current_timer = jiffies_to_msecs(jiffies);
- delta_timer = current_timer - start_timer;
- if (delta_timer > DRXJ_DAP_AUDTRIF_TIMEOUT) {
- stat = -EIO;
- break;
- }
- } while (((tr_status & AUD_TOP_TR_CTR_FIFO_LOCK__M) ==
- AUD_TOP_TR_CTR_FIFO_LOCK_LOCKED) ||
- ((tr_status & AUD_TOP_TR_CTR_FIFO_FULL__M) ==
- AUD_TOP_TR_CTR_FIFO_FULL_FULL));
- } /* if ( DRXDAP_FASI_ADDR2BANK(addr)!=2 ) */
- return stat;
- }
- /*============================================================================*/
- static int drxj_dap_write_reg16(struct i2c_device_addr *dev_addr,
- u32 addr,
- u16 data, u32 flags)
- {
- int stat = -EIO;
- /* Check param */
- if (dev_addr == NULL)
- return -EINVAL;
- if (is_handled_by_aud_tr_if(addr))
- stat = drxj_dap_write_aud_reg16(dev_addr, addr, data);
- else
- stat = drxdap_fasi_write_reg16(dev_addr,
- addr, data, flags);
- return stat;
- }
- /*============================================================================*/
- /* Free data ram in SIO HI */
- #define SIO_HI_RA_RAM_USR_BEGIN__A 0x420040
- #define SIO_HI_RA_RAM_USR_END__A 0x420060
- #define DRXJ_HI_ATOMIC_BUF_START (SIO_HI_RA_RAM_USR_BEGIN__A)
- #define DRXJ_HI_ATOMIC_BUF_END (SIO_HI_RA_RAM_USR_BEGIN__A + 7)
- #define DRXJ_HI_ATOMIC_READ SIO_HI_RA_RAM_PAR_3_ACP_RW_READ
- #define DRXJ_HI_ATOMIC_WRITE SIO_HI_RA_RAM_PAR_3_ACP_RW_WRITE
- /**
- * \fn int drxj_dap_atomic_read_write_block()
- * \brief Basic access routine for atomic read or write access
- * \param dev_addr pointer to i2c dev address
- * \param addr destination/source address
- * \param datasize size of data buffer in bytes
- * \param data pointer to data buffer
- * \return int
- * \retval 0 Succes
- * \retval -EIO Timeout, I2C error, illegal bank
- *
- */
- static
- int drxj_dap_atomic_read_write_block(struct i2c_device_addr *dev_addr,
- u32 addr,
- u16 datasize,
- u8 *data, bool read_flag)
- {
- struct drxj_hi_cmd hi_cmd;
- int rc;
- u16 word;
- u16 dummy = 0;
- u16 i = 0;
- /* Parameter check */
- if (!data || !dev_addr || ((datasize % 2)) || ((datasize / 2) > 8))
- return -EINVAL;
- /* Set up HI parameters to read or write n bytes */
- hi_cmd.cmd = SIO_HI_RA_RAM_CMD_ATOMIC_COPY;
- hi_cmd.param1 =
- (u16) ((DRXDAP_FASI_ADDR2BLOCK(DRXJ_HI_ATOMIC_BUF_START) << 6) +
- DRXDAP_FASI_ADDR2BANK(DRXJ_HI_ATOMIC_BUF_START));
- hi_cmd.param2 =
- (u16) DRXDAP_FASI_ADDR2OFFSET(DRXJ_HI_ATOMIC_BUF_START);
- hi_cmd.param3 = (u16) ((datasize / 2) - 1);
- if (!read_flag)
- hi_cmd.param3 |= DRXJ_HI_ATOMIC_WRITE;
- else
- hi_cmd.param3 |= DRXJ_HI_ATOMIC_READ;
- hi_cmd.param4 = (u16) ((DRXDAP_FASI_ADDR2BLOCK(addr) << 6) +
- DRXDAP_FASI_ADDR2BANK(addr));
- hi_cmd.param5 = (u16) DRXDAP_FASI_ADDR2OFFSET(addr);
- if (!read_flag) {
- /* write data to buffer */
- for (i = 0; i < (datasize / 2); i++) {
- word = ((u16) data[2 * i]);
- word += (((u16) data[(2 * i) + 1]) << 8);
- drxj_dap_write_reg16(dev_addr,
- (DRXJ_HI_ATOMIC_BUF_START + i),
- word, 0);
- }
- }
- rc = hi_command(dev_addr, &hi_cmd, &dummy);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (read_flag) {
- /* read data from buffer */
- for (i = 0; i < (datasize / 2); i++) {
- drxj_dap_read_reg16(dev_addr,
- (DRXJ_HI_ATOMIC_BUF_START + i),
- &word, 0);
- data[2 * i] = (u8) (word & 0xFF);
- data[(2 * i) + 1] = (u8) (word >> 8);
- }
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn int drxj_dap_atomic_read_reg32()
- * \brief Atomic read of 32 bits words
- */
- static
- int drxj_dap_atomic_read_reg32(struct i2c_device_addr *dev_addr,
- u32 addr,
- u32 *data, u32 flags)
- {
- u8 buf[sizeof(*data)] = { 0 };
- int rc = -EIO;
- u32 word = 0;
- if (!data)
- return -EINVAL;
- rc = drxj_dap_atomic_read_write_block(dev_addr, addr,
- sizeof(*data), buf, true);
- if (rc < 0)
- return 0;
- word = (u32) buf[3];
- word <<= 8;
- word |= (u32) buf[2];
- word <<= 8;
- word |= (u32) buf[1];
- word <<= 8;
- word |= (u32) buf[0];
- *data = word;
- return rc;
- }
- /*============================================================================*/
- /*============================================================================*/
- /*== END DRXJ DAP FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /*============================================================================*/
- /*== HOST INTERFACE FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /**
- * \fn int hi_cfg_command()
- * \brief Configure HI with settings stored in the demod structure.
- * \param demod Demodulator.
- * \return int.
- *
- * This routine was created because to much orthogonal settings have
- * been put into one HI API function (configure). Especially the I2C bridge
- * enable/disable should not need re-configuration of the HI.
- *
- */
- static int hi_cfg_command(const struct drx_demod_instance *demod)
- {
- struct drxj_data *ext_attr = (struct drxj_data *) (NULL);
- struct drxj_hi_cmd hi_cmd;
- u16 result = 0;
- int rc;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- hi_cmd.cmd = SIO_HI_RA_RAM_CMD_CONFIG;
- hi_cmd.param1 = SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY;
- hi_cmd.param2 = ext_attr->hi_cfg_timing_div;
- hi_cmd.param3 = ext_attr->hi_cfg_bridge_delay;
- hi_cmd.param4 = ext_attr->hi_cfg_wake_up_key;
- hi_cmd.param5 = ext_attr->hi_cfg_ctrl;
- hi_cmd.param6 = ext_attr->hi_cfg_transmit;
- rc = hi_command(demod->my_i2c_dev_addr, &hi_cmd, &result);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Reset power down flag (set one call only) */
- ext_attr->hi_cfg_ctrl &= (~(SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ));
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int hi_command()
- * \brief Configure HI with settings stored in the demod structure.
- * \param dev_addr I2C address.
- * \param cmd HI command.
- * \param result HI command result.
- * \return int.
- *
- * Sends command to HI
- *
- */
- static int
- hi_command(struct i2c_device_addr *dev_addr, const struct drxj_hi_cmd *cmd, u16 *result)
- {
- u16 wait_cmd = 0;
- u16 nr_retries = 0;
- bool powerdown_cmd = false;
- int rc;
- /* Write parameters */
- switch (cmd->cmd) {
- case SIO_HI_RA_RAM_CMD_CONFIG:
- case SIO_HI_RA_RAM_CMD_ATOMIC_COPY:
- rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_PAR_6__A, cmd->param6, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_PAR_5__A, cmd->param5, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_PAR_4__A, cmd->param4, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_PAR_3__A, cmd->param3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* fallthrough */
- case SIO_HI_RA_RAM_CMD_BRDCTRL:
- rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_PAR_2__A, cmd->param2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_PAR_1__A, cmd->param1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* fallthrough */
- case SIO_HI_RA_RAM_CMD_NULL:
- /* No parameters */
- break;
- default:
- return -EINVAL;
- break;
- }
- /* Write command */
- rc = drxj_dap_write_reg16(dev_addr, SIO_HI_RA_RAM_CMD__A, cmd->cmd, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if ((cmd->cmd) == SIO_HI_RA_RAM_CMD_RESET)
- msleep(1);
- /* Detect power down to ommit reading result */
- powerdown_cmd = (bool) ((cmd->cmd == SIO_HI_RA_RAM_CMD_CONFIG) &&
- (((cmd->
- param5) & SIO_HI_RA_RAM_PAR_5_CFG_SLEEP__M)
- == SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ));
- if (!powerdown_cmd) {
- /* Wait until command rdy */
- do {
- nr_retries++;
- if (nr_retries > DRXJ_MAX_RETRIES) {
- pr_err("timeout\n");
- goto rw_error;
- }
- rc = drxj_dap_read_reg16(dev_addr, SIO_HI_RA_RAM_CMD__A, &wait_cmd, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- } while (wait_cmd != 0);
- /* Read result */
- rc = drxj_dap_read_reg16(dev_addr, SIO_HI_RA_RAM_RES__A, result, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* if ( powerdown_cmd == true ) */
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int init_hi( const struct drx_demod_instance *demod )
- * \brief Initialise and configurate HI.
- * \param demod pointer to demod data.
- * \return int Return status.
- * \retval 0 Success.
- * \retval -EIO Failure.
- *
- * Needs to know Psys (System Clock period) and Posc (Osc Clock period)
- * Need to store configuration in driver because of the way I2C
- * bridging is controlled.
- *
- */
- static int init_hi(const struct drx_demod_instance *demod)
- {
- struct drxj_data *ext_attr = (struct drxj_data *) (NULL);
- struct drx_common_attr *common_attr = (struct drx_common_attr *) (NULL);
- struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL);
- int rc;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- common_attr = (struct drx_common_attr *) demod->my_common_attr;
- dev_addr = demod->my_i2c_dev_addr;
- /* PATCH for bug 5003, HI ucode v3.1.0 */
- rc = drxj_dap_write_reg16(dev_addr, 0x4301D7, 0x801, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Timing div, 250ns/Psys */
- /* Timing div, = ( delay (nano seconds) * sysclk (kHz) )/ 1000 */
- ext_attr->hi_cfg_timing_div =
- (u16) ((common_attr->sys_clock_freq / 1000) * HI_I2C_DELAY) / 1000;
- /* Clipping */
- if ((ext_attr->hi_cfg_timing_div) > SIO_HI_RA_RAM_PAR_2_CFG_DIV__M)
- ext_attr->hi_cfg_timing_div = SIO_HI_RA_RAM_PAR_2_CFG_DIV__M;
- /* Bridge delay, uses oscilator clock */
- /* Delay = ( delay (nano seconds) * oscclk (kHz) )/ 1000 */
- /* SDA brdige delay */
- ext_attr->hi_cfg_bridge_delay =
- (u16) ((common_attr->osc_clock_freq / 1000) * HI_I2C_BRIDGE_DELAY) /
- 1000;
- /* Clipping */
- if ((ext_attr->hi_cfg_bridge_delay) > SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M)
- ext_attr->hi_cfg_bridge_delay = SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M;
- /* SCL bridge delay, same as SDA for now */
- ext_attr->hi_cfg_bridge_delay += ((ext_attr->hi_cfg_bridge_delay) <<
- SIO_HI_RA_RAM_PAR_3_CFG_DBL_SCL__B);
- /* Wakeup key, setting the read flag (as suggest in the documentation) does
- not always result into a working solution (barebones worked VI2C failed).
- Not setting the bit works in all cases . */
- ext_attr->hi_cfg_wake_up_key = DRXJ_WAKE_UP_KEY;
- /* port/bridge/power down ctrl */
- ext_attr->hi_cfg_ctrl = (SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE);
- /* transit mode time out delay and watch dog divider */
- ext_attr->hi_cfg_transmit = SIO_HI_RA_RAM_PAR_6__PRE;
- rc = hi_cfg_command(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /*== END HOST INTERFACE FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /*============================================================================*/
- /*== AUXILIARY FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /**
- * \fn int get_device_capabilities()
- * \brief Get and store device capabilities.
- * \param demod Pointer to demodulator instance.
- * \return int.
- * \return 0 Success
- * \retval -EIO Failure
- *
- * Depending on pulldowns on MDx pins the following internals are set:
- * * common_attr->osc_clock_freq
- * * ext_attr->has_lna
- * * ext_attr->has_ntsc
- * * ext_attr->has_btsc
- * * ext_attr->has_oob
- *
- */
- static int get_device_capabilities(struct drx_demod_instance *demod)
- {
- struct drx_common_attr *common_attr = (struct drx_common_attr *) (NULL);
- struct drxj_data *ext_attr = (struct drxj_data *) NULL;
- struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL);
- u16 sio_pdr_ohw_cfg = 0;
- u32 sio_top_jtagid_lo = 0;
- u16 bid = 0;
- int rc;
- common_attr = (struct drx_common_attr *) demod->my_common_attr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- dev_addr = demod->my_i2c_dev_addr;
- rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_read_reg16(dev_addr, SIO_PDR_OHW_CFG__A, &sio_pdr_ohw_cfg, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- switch ((sio_pdr_ohw_cfg & SIO_PDR_OHW_CFG_FREF_SEL__M)) {
- case 0:
- /* ignore (bypass ?) */
- break;
- case 1:
- /* 27 MHz */
- common_attr->osc_clock_freq = 27000;
- break;
- case 2:
- /* 20.25 MHz */
- common_attr->osc_clock_freq = 20250;
- break;
- case 3:
- /* 4 MHz */
- common_attr->osc_clock_freq = 4000;
- break;
- default:
- return -EIO;
- }
- /*
- Determine device capabilities
- Based on pinning v47
- */
- rc = drxdap_fasi_read_reg32(dev_addr, SIO_TOP_JTAGID_LO__A, &sio_top_jtagid_lo, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ext_attr->mfx = (u8) ((sio_top_jtagid_lo >> 29) & 0xF);
- switch ((sio_top_jtagid_lo >> 12) & 0xFF) {
- case 0x31:
- rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_read_reg16(dev_addr, SIO_PDR_UIO_IN_HI__A, &bid, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- bid = (bid >> 10) & 0xf;
- rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ext_attr->has_lna = true;
- ext_attr->has_ntsc = false;
- ext_attr->has_btsc = false;
- ext_attr->has_oob = false;
- ext_attr->has_smatx = true;
- ext_attr->has_smarx = false;
- ext_attr->has_gpio = false;
- ext_attr->has_irqn = false;
- break;
- case 0x33:
- ext_attr->has_lna = false;
- ext_attr->has_ntsc = false;
- ext_attr->has_btsc = false;
- ext_attr->has_oob = false;
- ext_attr->has_smatx = true;
- ext_attr->has_smarx = false;
- ext_attr->has_gpio = false;
- ext_attr->has_irqn = false;
- break;
- case 0x45:
- ext_attr->has_lna = true;
- ext_attr->has_ntsc = true;
- ext_attr->has_btsc = false;
- ext_attr->has_oob = false;
- ext_attr->has_smatx = true;
- ext_attr->has_smarx = true;
- ext_attr->has_gpio = true;
- ext_attr->has_irqn = false;
- break;
- case 0x46:
- ext_attr->has_lna = false;
- ext_attr->has_ntsc = true;
- ext_attr->has_btsc = false;
- ext_attr->has_oob = false;
- ext_attr->has_smatx = true;
- ext_attr->has_smarx = true;
- ext_attr->has_gpio = true;
- ext_attr->has_irqn = false;
- break;
- case 0x41:
- ext_attr->has_lna = true;
- ext_attr->has_ntsc = true;
- ext_attr->has_btsc = true;
- ext_attr->has_oob = false;
- ext_attr->has_smatx = true;
- ext_attr->has_smarx = true;
- ext_attr->has_gpio = true;
- ext_attr->has_irqn = false;
- break;
- case 0x43:
- ext_attr->has_lna = false;
- ext_attr->has_ntsc = true;
- ext_attr->has_btsc = true;
- ext_attr->has_oob = false;
- ext_attr->has_smatx = true;
- ext_attr->has_smarx = true;
- ext_attr->has_gpio = true;
- ext_attr->has_irqn = false;
- break;
- case 0x32:
- ext_attr->has_lna = true;
- ext_attr->has_ntsc = false;
- ext_attr->has_btsc = false;
- ext_attr->has_oob = true;
- ext_attr->has_smatx = true;
- ext_attr->has_smarx = true;
- ext_attr->has_gpio = true;
- ext_attr->has_irqn = true;
- break;
- case 0x34:
- ext_attr->has_lna = false;
- ext_attr->has_ntsc = true;
- ext_attr->has_btsc = true;
- ext_attr->has_oob = true;
- ext_attr->has_smatx = true;
- ext_attr->has_smarx = true;
- ext_attr->has_gpio = true;
- ext_attr->has_irqn = true;
- break;
- case 0x42:
- ext_attr->has_lna = true;
- ext_attr->has_ntsc = true;
- ext_attr->has_btsc = true;
- ext_attr->has_oob = true;
- ext_attr->has_smatx = true;
- ext_attr->has_smarx = true;
- ext_attr->has_gpio = true;
- ext_attr->has_irqn = true;
- break;
- case 0x44:
- ext_attr->has_lna = false;
- ext_attr->has_ntsc = true;
- ext_attr->has_btsc = true;
- ext_attr->has_oob = true;
- ext_attr->has_smatx = true;
- ext_attr->has_smarx = true;
- ext_attr->has_gpio = true;
- ext_attr->has_irqn = true;
- break;
- default:
- /* Unknown device variant */
- return -EIO;
- break;
- }
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int power_up_device()
- * \brief Power up device.
- * \param demod Pointer to demodulator instance.
- * \return int.
- * \return 0 Success
- * \retval -EIO Failure, I2C or max retries reached
- *
- */
- #ifndef DRXJ_MAX_RETRIES_POWERUP
- #define DRXJ_MAX_RETRIES_POWERUP 10
- #endif
- static int power_up_device(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL);
- u8 data = 0;
- u16 retry_count = 0;
- struct i2c_device_addr wake_up_addr;
- dev_addr = demod->my_i2c_dev_addr;
- wake_up_addr.i2c_addr = DRXJ_WAKE_UP_KEY;
- wake_up_addr.i2c_dev_id = dev_addr->i2c_dev_id;
- wake_up_addr.user_data = dev_addr->user_data;
- /*
- * I2C access may fail in this case: no ack
- * dummy write must be used to wake uop device, dummy read must be used to
- * reset HI state machine (avoiding actual writes)
- */
- do {
- data = 0;
- drxbsp_i2c_write_read(&wake_up_addr, 1, &data,
- (struct i2c_device_addr *)(NULL), 0,
- (u8 *)(NULL));
- msleep(10);
- retry_count++;
- } while ((drxbsp_i2c_write_read
- ((struct i2c_device_addr *) (NULL), 0, (u8 *)(NULL), dev_addr, 1,
- &data)
- != 0) && (retry_count < DRXJ_MAX_RETRIES_POWERUP));
- /* Need some recovery time .... */
- msleep(10);
- if (retry_count == DRXJ_MAX_RETRIES_POWERUP)
- return -EIO;
- return 0;
- }
- /*----------------------------------------------------------------------------*/
- /* MPEG Output Configuration Functions - begin */
- /*----------------------------------------------------------------------------*/
- /**
- * \fn int ctrl_set_cfg_mpeg_output()
- * \brief Set MPEG output configuration of the device.
- * \param devmod Pointer to demodulator instance.
- * \param cfg_data Pointer to mpeg output configuaration.
- * \return int.
- *
- * Configure MPEG output parameters.
- *
- */
- static int
- ctrl_set_cfg_mpeg_output(struct drx_demod_instance *demod, struct drx_cfg_mpeg_output *cfg_data)
- {
- struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL);
- struct drxj_data *ext_attr = (struct drxj_data *) (NULL);
- struct drx_common_attr *common_attr = (struct drx_common_attr *) (NULL);
- int rc;
- u16 fec_oc_reg_mode = 0;
- u16 fec_oc_reg_ipr_mode = 0;
- u16 fec_oc_reg_ipr_invert = 0;
- u32 max_bit_rate = 0;
- u32 rcn_rate = 0;
- u32 nr_bits = 0;
- u16 sio_pdr_md_cfg = 0;
- /* data mask for the output data byte */
- u16 invert_data_mask =
- FEC_OC_IPR_INVERT_MD7__M | FEC_OC_IPR_INVERT_MD6__M |
- FEC_OC_IPR_INVERT_MD5__M | FEC_OC_IPR_INVERT_MD4__M |
- FEC_OC_IPR_INVERT_MD3__M | FEC_OC_IPR_INVERT_MD2__M |
- FEC_OC_IPR_INVERT_MD1__M | FEC_OC_IPR_INVERT_MD0__M;
- /* check arguments */
- if ((demod == NULL) || (cfg_data == NULL))
- return -EINVAL;
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- common_attr = (struct drx_common_attr *) demod->my_common_attr;
- if (cfg_data->enable_mpeg_output == true) {
- /* quick and dirty patch to set MPEG incase current std is not
- producing MPEG */
- switch (ext_attr->standard) {
- case DRX_STANDARD_8VSB:
- case DRX_STANDARD_ITU_A:
- case DRX_STANDARD_ITU_B:
- case DRX_STANDARD_ITU_C:
- break;
- default:
- return 0;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_OCR_INVERT__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- switch (ext_attr->standard) {
- case DRX_STANDARD_8VSB:
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_FCT_USAGE__A, 7, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* 2048 bytes fifo ram */
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_TMD_CTL_UPD_RATE__A, 10, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_TMD_INT_UPD_RATE__A, 10, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_AVR_PARM_A__A, 5, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_AVR_PARM_B__A, 7, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_RCN_GAIN__A, 10, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Low Water Mark for synchronization */
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_LWM__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* High Water Mark for synchronization */
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_HWM__A, 5, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_STANDARD_ITU_A:
- case DRX_STANDARD_ITU_C:
- switch (ext_attr->constellation) {
- case DRX_CONSTELLATION_QAM256:
- nr_bits = 8;
- break;
- case DRX_CONSTELLATION_QAM128:
- nr_bits = 7;
- break;
- case DRX_CONSTELLATION_QAM64:
- nr_bits = 6;
- break;
- case DRX_CONSTELLATION_QAM32:
- nr_bits = 5;
- break;
- case DRX_CONSTELLATION_QAM16:
- nr_bits = 4;
- break;
- default:
- return -EIO;
- } /* ext_attr->constellation */
- /* max_bit_rate = symbol_rate * nr_bits * coef */
- /* coef = 188/204 */
- max_bit_rate =
- (ext_attr->curr_symbol_rate / 8) * nr_bits * 188;
- /* pass through b/c Annex A/c need following settings */
- case DRX_STANDARD_ITU_B:
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_FCT_USAGE__A, FEC_OC_FCT_USAGE__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_TMD_CTL_UPD_RATE__A, FEC_OC_TMD_CTL_UPD_RATE__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_TMD_INT_UPD_RATE__A, 5, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_AVR_PARM_A__A, FEC_OC_AVR_PARM_A__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_AVR_PARM_B__A, FEC_OC_AVR_PARM_B__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (cfg_data->static_clk == true) {
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_RCN_GAIN__A, 0xD, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- } else {
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_RCN_GAIN__A, FEC_OC_RCN_GAIN__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_LWM__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_HWM__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- default:
- break;
- } /* swtich (standard) */
- /* Check insertion of the Reed-Solomon parity bytes */
- rc = drxj_dap_read_reg16(dev_addr, FEC_OC_MODE__A, &fec_oc_reg_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_read_reg16(dev_addr, FEC_OC_IPR_MODE__A, &fec_oc_reg_ipr_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (cfg_data->insert_rs_byte == true) {
- /* enable parity symbol forward */
- fec_oc_reg_mode |= FEC_OC_MODE_PARITY__M;
- /* MVAL disable during parity bytes */
- fec_oc_reg_ipr_mode |= FEC_OC_IPR_MODE_MVAL_DIS_PAR__M;
- switch (ext_attr->standard) {
- case DRX_STANDARD_8VSB:
- rcn_rate = 0x004854D3;
- break;
- case DRX_STANDARD_ITU_B:
- fec_oc_reg_mode |= FEC_OC_MODE_TRANSPARENT__M;
- switch (ext_attr->constellation) {
- case DRX_CONSTELLATION_QAM256:
- rcn_rate = 0x008945E7;
- break;
- case DRX_CONSTELLATION_QAM64:
- rcn_rate = 0x005F64D4;
- break;
- default:
- return -EIO;
- }
- break;
- case DRX_STANDARD_ITU_A:
- case DRX_STANDARD_ITU_C:
- /* insert_rs_byte = true -> coef = 188/188 -> 1, RS bits are in MPEG output */
- rcn_rate =
- (frac28
- (max_bit_rate,
- (u32) (common_attr->sys_clock_freq / 8))) /
- 188;
- break;
- default:
- return -EIO;
- } /* ext_attr->standard */
- } else { /* insert_rs_byte == false */
- /* disable parity symbol forward */
- fec_oc_reg_mode &= (~FEC_OC_MODE_PARITY__M);
- /* MVAL enable during parity bytes */
- fec_oc_reg_ipr_mode &= (~FEC_OC_IPR_MODE_MVAL_DIS_PAR__M);
- switch (ext_attr->standard) {
- case DRX_STANDARD_8VSB:
- rcn_rate = 0x0041605C;
- break;
- case DRX_STANDARD_ITU_B:
- fec_oc_reg_mode &= (~FEC_OC_MODE_TRANSPARENT__M);
- switch (ext_attr->constellation) {
- case DRX_CONSTELLATION_QAM256:
- rcn_rate = 0x0082D6A0;
- break;
- case DRX_CONSTELLATION_QAM64:
- rcn_rate = 0x005AEC1A;
- break;
- default:
- return -EIO;
- }
- break;
- case DRX_STANDARD_ITU_A:
- case DRX_STANDARD_ITU_C:
- /* insert_rs_byte = false -> coef = 188/204, RS bits not in MPEG output */
- rcn_rate =
- (frac28
- (max_bit_rate,
- (u32) (common_attr->sys_clock_freq / 8))) /
- 204;
- break;
- default:
- return -EIO;
- } /* ext_attr->standard */
- }
- if (cfg_data->enable_parallel == true) { /* MPEG data output is parallel -> clear ipr_mode[0] */
- fec_oc_reg_ipr_mode &= (~(FEC_OC_IPR_MODE_SERIAL__M));
- } else { /* MPEG data output is serial -> set ipr_mode[0] */
- fec_oc_reg_ipr_mode |= FEC_OC_IPR_MODE_SERIAL__M;
- }
- /* Control slective inversion of output bits */
- if (cfg_data->invert_data == true)
- fec_oc_reg_ipr_invert |= invert_data_mask;
- else
- fec_oc_reg_ipr_invert &= (~(invert_data_mask));
- if (cfg_data->invert_err == true)
- fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MERR__M;
- else
- fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MERR__M));
- if (cfg_data->invert_str == true)
- fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MSTRT__M;
- else
- fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MSTRT__M));
- if (cfg_data->invert_val == true)
- fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MVAL__M;
- else
- fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MVAL__M));
- if (cfg_data->invert_clk == true)
- fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MCLK__M;
- else
- fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MCLK__M));
- if (cfg_data->static_clk == true) { /* Static mode */
- u32 dto_rate = 0;
- u32 bit_rate = 0;
- u16 fec_oc_dto_burst_len = 0;
- u16 fec_oc_dto_period = 0;
- fec_oc_dto_burst_len = FEC_OC_DTO_BURST_LEN__PRE;
- switch (ext_attr->standard) {
- case DRX_STANDARD_8VSB:
- fec_oc_dto_period = 4;
- if (cfg_data->insert_rs_byte == true)
- fec_oc_dto_burst_len = 208;
- break;
- case DRX_STANDARD_ITU_A:
- {
- u32 symbol_rate_th = 6400000;
- if (cfg_data->insert_rs_byte == true) {
- fec_oc_dto_burst_len = 204;
- symbol_rate_th = 5900000;
- }
- if (ext_attr->curr_symbol_rate >=
- symbol_rate_th) {
- fec_oc_dto_period = 0;
- } else {
- fec_oc_dto_period = 1;
- }
- }
- break;
- case DRX_STANDARD_ITU_B:
- fec_oc_dto_period = 1;
- if (cfg_data->insert_rs_byte == true)
- fec_oc_dto_burst_len = 128;
- break;
- case DRX_STANDARD_ITU_C:
- fec_oc_dto_period = 1;
- if (cfg_data->insert_rs_byte == true)
- fec_oc_dto_burst_len = 204;
- break;
- default:
- return -EIO;
- }
- bit_rate =
- common_attr->sys_clock_freq * 1000 / (fec_oc_dto_period +
- 2);
- dto_rate =
- frac28(bit_rate, common_attr->sys_clock_freq * 1000);
- dto_rate >>= 3;
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DTO_RATE_HI__A, (u16)((dto_rate >> 16) & FEC_OC_DTO_RATE_HI__M), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DTO_RATE_LO__A, (u16)(dto_rate & FEC_OC_DTO_RATE_LO_RATE_LO__M), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DTO_MODE__A, FEC_OC_DTO_MODE_DYNAMIC__M | FEC_OC_DTO_MODE_OFFSET_ENABLE__M, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_FCT_MODE__A, FEC_OC_FCT_MODE_RAT_ENA__M | FEC_OC_FCT_MODE_VIRT_ENA__M, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DTO_BURST_LEN__A, fec_oc_dto_burst_len, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (ext_attr->mpeg_output_clock_rate != DRXJ_MPEGOUTPUT_CLOCK_RATE_AUTO)
- fec_oc_dto_period = ext_attr->mpeg_output_clock_rate - 1;
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DTO_PERIOD__A, fec_oc_dto_period, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- } else { /* Dynamic mode */
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DTO_MODE__A, FEC_OC_DTO_MODE_DYNAMIC__M, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_FCT_MODE__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- rc = drxdap_fasi_write_reg32(dev_addr, FEC_OC_RCN_CTL_RATE_LO__A, rcn_rate, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Write appropriate registers with requested configuration */
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_MODE__A, fec_oc_reg_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_IPR_MODE__A, fec_oc_reg_ipr_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_IPR_INVERT__A, fec_oc_reg_ipr_invert, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* enabling for both parallel and serial now */
- /* Write magic word to enable pdr reg write */
- rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, 0xFABA, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Set MPEG TS pads to outputmode */
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MSTRT_CFG__A, 0x0013, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MERR_CFG__A, 0x0013, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MCLK_CFG__A, MPEG_OUTPUT_CLK_DRIVE_STRENGTH << SIO_PDR_MCLK_CFG_DRIVE__B | 0x03 << SIO_PDR_MCLK_CFG_MODE__B, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MVAL_CFG__A, 0x0013, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- sio_pdr_md_cfg =
- MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH <<
- SIO_PDR_MD0_CFG_DRIVE__B | 0x03 << SIO_PDR_MD0_CFG_MODE__B;
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD0_CFG__A, sio_pdr_md_cfg, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (cfg_data->enable_parallel == true) { /* MPEG data output is parallel -> set MD1 to MD7 to output mode */
- sio_pdr_md_cfg =
- MPEG_PARALLEL_OUTPUT_PIN_DRIVE_STRENGTH <<
- SIO_PDR_MD0_CFG_DRIVE__B | 0x03 <<
- SIO_PDR_MD0_CFG_MODE__B;
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD0_CFG__A, sio_pdr_md_cfg, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD1_CFG__A, sio_pdr_md_cfg, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD2_CFG__A, sio_pdr_md_cfg, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD3_CFG__A, sio_pdr_md_cfg, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD4_CFG__A, sio_pdr_md_cfg, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD5_CFG__A, sio_pdr_md_cfg, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD6_CFG__A, sio_pdr_md_cfg, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD7_CFG__A, sio_pdr_md_cfg, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- } else { /* MPEG data output is serial -> set MD1 to MD7 to tri-state */
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD1_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD2_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD3_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD4_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD5_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD6_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD7_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* Enable Monitor Bus output over MPEG pads and ctl input */
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MON_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Write nomagic word to enable pdr reg write */
- rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- } else {
- /* Write magic word to enable pdr reg write */
- rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, 0xFABA, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Set MPEG TS pads to inputmode */
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MSTRT_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MERR_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MCLK_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MVAL_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD0_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD1_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD2_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD3_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD4_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD5_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD6_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MD7_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Enable Monitor Bus output over MPEG pads and ctl input */
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_MON_CFG__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Write nomagic word to enable pdr reg write */
- rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* save values for restore after re-acquire */
- common_attr->mpeg_cfg.enable_mpeg_output = cfg_data->enable_mpeg_output;
- return 0;
- rw_error:
- return rc;
- }
- /*----------------------------------------------------------------------------*/
- /*----------------------------------------------------------------------------*/
- /* MPEG Output Configuration Functions - end */
- /*----------------------------------------------------------------------------*/
- /*----------------------------------------------------------------------------*/
- /* miscellaneous configuartions - begin */
- /*----------------------------------------------------------------------------*/
- /**
- * \fn int set_mpegtei_handling()
- * \brief Activate MPEG TEI handling settings.
- * \param devmod Pointer to demodulator instance.
- * \return int.
- *
- * This routine should be called during a set channel of QAM/VSB
- *
- */
- static int set_mpegtei_handling(struct drx_demod_instance *demod)
- {
- struct drxj_data *ext_attr = (struct drxj_data *) (NULL);
- struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL);
- int rc;
- u16 fec_oc_dpr_mode = 0;
- u16 fec_oc_snc_mode = 0;
- u16 fec_oc_ems_mode = 0;
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- rc = drxj_dap_read_reg16(dev_addr, FEC_OC_DPR_MODE__A, &fec_oc_dpr_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_read_reg16(dev_addr, FEC_OC_SNC_MODE__A, &fec_oc_snc_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_read_reg16(dev_addr, FEC_OC_EMS_MODE__A, &fec_oc_ems_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* reset to default, allow TEI bit to be changed */
- fec_oc_dpr_mode &= (~FEC_OC_DPR_MODE_ERR_DISABLE__M);
- fec_oc_snc_mode &= (~(FEC_OC_SNC_MODE_ERROR_CTL__M |
- FEC_OC_SNC_MODE_CORR_DISABLE__M));
- fec_oc_ems_mode &= (~FEC_OC_EMS_MODE_MODE__M);
- if (ext_attr->disable_te_ihandling) {
- /* do not change TEI bit */
- fec_oc_dpr_mode |= FEC_OC_DPR_MODE_ERR_DISABLE__M;
- fec_oc_snc_mode |= FEC_OC_SNC_MODE_CORR_DISABLE__M |
- ((0x2) << (FEC_OC_SNC_MODE_ERROR_CTL__B));
- fec_oc_ems_mode |= ((0x01) << (FEC_OC_EMS_MODE_MODE__B));
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_DPR_MODE__A, fec_oc_dpr_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_MODE__A, fec_oc_snc_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_EMS_MODE__A, fec_oc_ems_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*----------------------------------------------------------------------------*/
- /**
- * \fn int bit_reverse_mpeg_output()
- * \brief Set MPEG output bit-endian settings.
- * \param devmod Pointer to demodulator instance.
- * \return int.
- *
- * This routine should be called during a set channel of QAM/VSB
- *
- */
- static int bit_reverse_mpeg_output(struct drx_demod_instance *demod)
- {
- struct drxj_data *ext_attr = (struct drxj_data *) (NULL);
- struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL);
- int rc;
- u16 fec_oc_ipr_mode = 0;
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- rc = drxj_dap_read_reg16(dev_addr, FEC_OC_IPR_MODE__A, &fec_oc_ipr_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* reset to default (normal bit order) */
- fec_oc_ipr_mode &= (~FEC_OC_IPR_MODE_REVERSE_ORDER__M);
- if (ext_attr->bit_reverse_mpeg_outout)
- fec_oc_ipr_mode |= FEC_OC_IPR_MODE_REVERSE_ORDER__M;
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_IPR_MODE__A, fec_oc_ipr_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*----------------------------------------------------------------------------*/
- /**
- * \fn int set_mpeg_start_width()
- * \brief Set MPEG start width.
- * \param devmod Pointer to demodulator instance.
- * \return int.
- *
- * This routine should be called during a set channel of QAM/VSB
- *
- */
- static int set_mpeg_start_width(struct drx_demod_instance *demod)
- {
- struct drxj_data *ext_attr = (struct drxj_data *) (NULL);
- struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)(NULL);
- struct drx_common_attr *common_attr = (struct drx_common_attr *) NULL;
- int rc;
- u16 fec_oc_comm_mb = 0;
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- common_attr = demod->my_common_attr;
- if ((common_attr->mpeg_cfg.static_clk == true)
- && (common_attr->mpeg_cfg.enable_parallel == false)) {
- rc = drxj_dap_read_reg16(dev_addr, FEC_OC_COMM_MB__A, &fec_oc_comm_mb, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- fec_oc_comm_mb &= ~FEC_OC_COMM_MB_CTL_ON;
- if (ext_attr->mpeg_start_width == DRXJ_MPEG_START_WIDTH_8CLKCYC)
- fec_oc_comm_mb |= FEC_OC_COMM_MB_CTL_ON;
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_COMM_MB__A, fec_oc_comm_mb, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- return 0;
- rw_error:
- return rc;
- }
- /*----------------------------------------------------------------------------*/
- /* miscellaneous configuartions - end */
- /*----------------------------------------------------------------------------*/
- /*----------------------------------------------------------------------------*/
- /* UIO Configuration Functions - begin */
- /*----------------------------------------------------------------------------*/
- /**
- * \fn int ctrl_set_uio_cfg()
- * \brief Configure modus oprandi UIO.
- * \param demod Pointer to demodulator instance.
- * \param uio_cfg Pointer to a configuration setting for a certain UIO.
- * \return int.
- */
- static int ctrl_set_uio_cfg(struct drx_demod_instance *demod, struct drxuio_cfg *uio_cfg)
- {
- struct drxj_data *ext_attr = (struct drxj_data *) (NULL);
- int rc;
- if ((uio_cfg == NULL) || (demod == NULL))
- return -EINVAL;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- /* Write magic word to enable pdr reg write */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- switch (uio_cfg->uio) {
- /*====================================================================*/
- case DRX_UIO1:
- /* DRX_UIO1: SMA_TX UIO-1 */
- if (!ext_attr->has_smatx)
- return -EIO;
- switch (uio_cfg->mode) {
- case DRX_UIO_MODE_FIRMWARE_SMA: /* falltrough */
- case DRX_UIO_MODE_FIRMWARE_SAW: /* falltrough */
- case DRX_UIO_MODE_READWRITE:
- ext_attr->uio_sma_tx_mode = uio_cfg->mode;
- break;
- case DRX_UIO_MODE_DISABLE:
- ext_attr->uio_sma_tx_mode = uio_cfg->mode;
- /* pad configuration register is set 0 - input mode */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_SMA_TX_CFG__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- default:
- return -EINVAL;
- } /* switch ( uio_cfg->mode ) */
- break;
- /*====================================================================*/
- case DRX_UIO2:
- /* DRX_UIO2: SMA_RX UIO-2 */
- if (!ext_attr->has_smarx)
- return -EIO;
- switch (uio_cfg->mode) {
- case DRX_UIO_MODE_FIRMWARE0: /* falltrough */
- case DRX_UIO_MODE_READWRITE:
- ext_attr->uio_sma_rx_mode = uio_cfg->mode;
- break;
- case DRX_UIO_MODE_DISABLE:
- ext_attr->uio_sma_rx_mode = uio_cfg->mode;
- /* pad configuration register is set 0 - input mode */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_SMA_RX_CFG__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- default:
- return -EINVAL;
- break;
- } /* switch ( uio_cfg->mode ) */
- break;
- /*====================================================================*/
- case DRX_UIO3:
- /* DRX_UIO3: GPIO UIO-3 */
- if (!ext_attr->has_gpio)
- return -EIO;
- switch (uio_cfg->mode) {
- case DRX_UIO_MODE_FIRMWARE0: /* falltrough */
- case DRX_UIO_MODE_READWRITE:
- ext_attr->uio_gpio_mode = uio_cfg->mode;
- break;
- case DRX_UIO_MODE_DISABLE:
- ext_attr->uio_gpio_mode = uio_cfg->mode;
- /* pad configuration register is set 0 - input mode */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_GPIO_CFG__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- default:
- return -EINVAL;
- break;
- } /* switch ( uio_cfg->mode ) */
- break;
- /*====================================================================*/
- case DRX_UIO4:
- /* DRX_UIO4: IRQN UIO-4 */
- if (!ext_attr->has_irqn)
- return -EIO;
- switch (uio_cfg->mode) {
- case DRX_UIO_MODE_READWRITE:
- ext_attr->uio_irqn_mode = uio_cfg->mode;
- break;
- case DRX_UIO_MODE_DISABLE:
- /* pad configuration register is set 0 - input mode */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_IRQN_CFG__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ext_attr->uio_irqn_mode = uio_cfg->mode;
- break;
- case DRX_UIO_MODE_FIRMWARE0: /* falltrough */
- default:
- return -EINVAL;
- break;
- } /* switch ( uio_cfg->mode ) */
- break;
- /*====================================================================*/
- default:
- return -EINVAL;
- } /* switch ( uio_cfg->uio ) */
- /* Write magic word to disable pdr reg write */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_TOP_COMM_KEY__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int ctrl_uio_write()
- * \brief Write to a UIO.
- * \param demod Pointer to demodulator instance.
- * \param uio_data Pointer to data container for a certain UIO.
- * \return int.
- */
- static int
- ctrl_uio_write(struct drx_demod_instance *demod, struct drxuio_data *uio_data)
- {
- struct drxj_data *ext_attr = (struct drxj_data *) (NULL);
- int rc;
- u16 pin_cfg_value = 0;
- u16 value = 0;
- if ((uio_data == NULL) || (demod == NULL))
- return -EINVAL;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- /* Write magic word to enable pdr reg write */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- switch (uio_data->uio) {
- /*====================================================================*/
- case DRX_UIO1:
- /* DRX_UIO1: SMA_TX UIO-1 */
- if (!ext_attr->has_smatx)
- return -EIO;
- if ((ext_attr->uio_sma_tx_mode != DRX_UIO_MODE_READWRITE)
- && (ext_attr->uio_sma_tx_mode != DRX_UIO_MODE_FIRMWARE_SAW)) {
- return -EIO;
- }
- pin_cfg_value = 0;
- /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */
- pin_cfg_value |= 0x0113;
- /* io_pad_cfg_mode output mode is drive always */
- /* io_pad_cfg_drive is set to power 2 (23 mA) */
- /* write to io pad configuration register - output mode */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_SMA_TX_CFG__A, pin_cfg_value, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* use corresponding bit in io data output registar */
- rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_LO__A, &value, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (!uio_data->value)
- value &= 0x7FFF; /* write zero to 15th bit - 1st UIO */
- else
- value |= 0x8000; /* write one to 15th bit - 1st UIO */
- /* write back to io data output register */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_LO__A, value, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- /*======================================================================*/
- case DRX_UIO2:
- /* DRX_UIO2: SMA_RX UIO-2 */
- if (!ext_attr->has_smarx)
- return -EIO;
- if (ext_attr->uio_sma_rx_mode != DRX_UIO_MODE_READWRITE)
- return -EIO;
- pin_cfg_value = 0;
- /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */
- pin_cfg_value |= 0x0113;
- /* io_pad_cfg_mode output mode is drive always */
- /* io_pad_cfg_drive is set to power 2 (23 mA) */
- /* write to io pad configuration register - output mode */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_SMA_RX_CFG__A, pin_cfg_value, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* use corresponding bit in io data output registar */
- rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_LO__A, &value, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (!uio_data->value)
- value &= 0xBFFF; /* write zero to 14th bit - 2nd UIO */
- else
- value |= 0x4000; /* write one to 14th bit - 2nd UIO */
- /* write back to io data output register */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_LO__A, value, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- /*====================================================================*/
- case DRX_UIO3:
- /* DRX_UIO3: ASEL UIO-3 */
- if (!ext_attr->has_gpio)
- return -EIO;
- if (ext_attr->uio_gpio_mode != DRX_UIO_MODE_READWRITE)
- return -EIO;
- pin_cfg_value = 0;
- /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */
- pin_cfg_value |= 0x0113;
- /* io_pad_cfg_mode output mode is drive always */
- /* io_pad_cfg_drive is set to power 2 (23 mA) */
- /* write to io pad configuration register - output mode */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_GPIO_CFG__A, pin_cfg_value, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* use corresponding bit in io data output registar */
- rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_HI__A, &value, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (!uio_data->value)
- value &= 0xFFFB; /* write zero to 2nd bit - 3rd UIO */
- else
- value |= 0x0004; /* write one to 2nd bit - 3rd UIO */
- /* write back to io data output register */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_HI__A, value, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- /*=====================================================================*/
- case DRX_UIO4:
- /* DRX_UIO4: IRQN UIO-4 */
- if (!ext_attr->has_irqn)
- return -EIO;
- if (ext_attr->uio_irqn_mode != DRX_UIO_MODE_READWRITE)
- return -EIO;
- pin_cfg_value = 0;
- /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */
- pin_cfg_value |= 0x0113;
- /* io_pad_cfg_mode output mode is drive always */
- /* io_pad_cfg_drive is set to power 2 (23 mA) */
- /* write to io pad configuration register - output mode */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_IRQN_CFG__A, pin_cfg_value, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* use corresponding bit in io data output registar */
- rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_LO__A, &value, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (uio_data->value == false)
- value &= 0xEFFF; /* write zero to 12th bit - 4th UIO */
- else
- value |= 0x1000; /* write one to 12th bit - 4th UIO */
- /* write back to io data output register */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_UIO_OUT_LO__A, value, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- /*=====================================================================*/
- default:
- return -EINVAL;
- } /* switch ( uio_data->uio ) */
- /* Write magic word to disable pdr reg write */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_TOP_COMM_KEY__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*---------------------------------------------------------------------------*/
- /* UIO Configuration Functions - end */
- /*---------------------------------------------------------------------------*/
- /*----------------------------------------------------------------------------*/
- /* I2C Bridge Functions - begin */
- /*----------------------------------------------------------------------------*/
- /**
- * \fn int ctrl_i2c_bridge()
- * \brief Open or close the I2C switch to tuner.
- * \param demod Pointer to demodulator instance.
- * \param bridge_closed Pointer to bool indication if bridge is closed not.
- * \return int.
- */
- static int
- ctrl_i2c_bridge(struct drx_demod_instance *demod, bool *bridge_closed)
- {
- struct drxj_hi_cmd hi_cmd;
- u16 result = 0;
- /* check arguments */
- if (bridge_closed == NULL)
- return -EINVAL;
- hi_cmd.cmd = SIO_HI_RA_RAM_CMD_BRDCTRL;
- hi_cmd.param1 = SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY;
- if (*bridge_closed)
- hi_cmd.param2 = SIO_HI_RA_RAM_PAR_2_BRD_CFG_CLOSED;
- else
- hi_cmd.param2 = SIO_HI_RA_RAM_PAR_2_BRD_CFG_OPEN;
- return hi_command(demod->my_i2c_dev_addr, &hi_cmd, &result);
- }
- /*----------------------------------------------------------------------------*/
- /* I2C Bridge Functions - end */
- /*----------------------------------------------------------------------------*/
- /*----------------------------------------------------------------------------*/
- /* Smart antenna Functions - begin */
- /*----------------------------------------------------------------------------*/
- /**
- * \fn int smart_ant_init()
- * \brief Initialize Smart Antenna.
- * \param pointer to struct drx_demod_instance.
- * \return int.
- *
- */
- static int smart_ant_init(struct drx_demod_instance *demod)
- {
- struct drxj_data *ext_attr = NULL;
- struct i2c_device_addr *dev_addr = NULL;
- struct drxuio_cfg uio_cfg = { DRX_UIO1, DRX_UIO_MODE_FIRMWARE_SMA };
- int rc;
- u16 data = 0;
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- /* Write magic word to enable pdr reg write */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* init smart antenna */
- rc = drxj_dap_read_reg16(dev_addr, SIO_SA_TX_COMMAND__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (ext_attr->smart_ant_inverted) {
- rc = drxj_dap_write_reg16(dev_addr, SIO_SA_TX_COMMAND__A, (data | SIO_SA_TX_COMMAND_TX_INVERT__M) | SIO_SA_TX_COMMAND_TX_ENABLE__M, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- } else {
- rc = drxj_dap_write_reg16(dev_addr, SIO_SA_TX_COMMAND__A, (data & (~SIO_SA_TX_COMMAND_TX_INVERT__M)) | SIO_SA_TX_COMMAND_TX_ENABLE__M, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* config SMA_TX pin to smart antenna mode */
- rc = ctrl_set_uio_cfg(demod, &uio_cfg);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_SMA_TX_CFG__A, 0x13, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_PDR_SMA_TX_GPIO_FNC__A, 0x03, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Write magic word to disable pdr reg write */
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, SIO_TOP_COMM_KEY__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- static int scu_command(struct i2c_device_addr *dev_addr, struct drxjscu_cmd *cmd)
- {
- int rc;
- u16 cur_cmd = 0;
- unsigned long timeout;
- /* Check param */
- if (cmd == NULL)
- return -EINVAL;
- /* Wait until SCU command interface is ready to receive command */
- rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_COMMAND__A, &cur_cmd, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (cur_cmd != DRX_SCU_READY)
- return -EIO;
- switch (cmd->parameter_len) {
- case 5:
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_PARAM_4__A, *(cmd->parameter + 4), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* fallthrough */
- case 4:
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_PARAM_3__A, *(cmd->parameter + 3), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* fallthrough */
- case 3:
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_PARAM_2__A, *(cmd->parameter + 2), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* fallthrough */
- case 2:
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_PARAM_1__A, *(cmd->parameter + 1), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* fallthrough */
- case 1:
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_PARAM_0__A, *(cmd->parameter + 0), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* fallthrough */
- case 0:
- /* do nothing */
- break;
- default:
- /* this number of parameters is not supported */
- return -EIO;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_COMMAND__A, cmd->command, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Wait until SCU has processed command */
- timeout = jiffies + msecs_to_jiffies(DRXJ_MAX_WAITTIME);
- while (time_is_after_jiffies(timeout)) {
- rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_COMMAND__A, &cur_cmd, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (cur_cmd == DRX_SCU_READY)
- break;
- usleep_range(1000, 2000);
- }
- if (cur_cmd != DRX_SCU_READY)
- return -EIO;
- /* read results */
- if ((cmd->result_len > 0) && (cmd->result != NULL)) {
- s16 err;
- switch (cmd->result_len) {
- case 4:
- rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_PARAM_3__A, cmd->result + 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* fallthrough */
- case 3:
- rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_PARAM_2__A, cmd->result + 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* fallthrough */
- case 2:
- rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_PARAM_1__A, cmd->result + 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* fallthrough */
- case 1:
- rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_PARAM_0__A, cmd->result + 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* fallthrough */
- case 0:
- /* do nothing */
- break;
- default:
- /* this number of parameters is not supported */
- return -EIO;
- }
- /* Check if an error was reported by SCU */
- err = cmd->result[0];
- /* check a few fixed error codes */
- if ((err == (s16) SCU_RAM_PARAM_0_RESULT_UNKSTD)
- || (err == (s16) SCU_RAM_PARAM_0_RESULT_UNKCMD)
- || (err == (s16) SCU_RAM_PARAM_0_RESULT_INVPAR)
- || (err == (s16) SCU_RAM_PARAM_0_RESULT_SIZE)
- ) {
- return -EINVAL;
- }
- /* here it is assumed that negative means error, and positive no error */
- else if (err < 0)
- return -EIO;
- else
- return 0;
- }
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int DRXJ_DAP_SCUAtomicReadWriteBlock()
- * \brief Basic access routine for SCU atomic read or write access
- * \param dev_addr pointer to i2c dev address
- * \param addr destination/source address
- * \param datasize size of data buffer in bytes
- * \param data pointer to data buffer
- * \return int
- * \retval 0 Succes
- * \retval -EIO Timeout, I2C error, illegal bank
- *
- */
- #define ADDR_AT_SCU_SPACE(x) ((x - 0x82E000) * 2)
- static
- int drxj_dap_scu_atomic_read_write_block(struct i2c_device_addr *dev_addr, u32 addr, u16 datasize, /* max 30 bytes because the limit of SCU parameter */
- u8 *data, bool read_flag)
- {
- struct drxjscu_cmd scu_cmd;
- int rc;
- u16 set_param_parameters[15];
- u16 cmd_result[15];
- /* Parameter check */
- if (!data || !dev_addr || (datasize % 2) || ((datasize / 2) > 16))
- return -EINVAL;
- set_param_parameters[1] = (u16) ADDR_AT_SCU_SPACE(addr);
- if (read_flag) { /* read */
- set_param_parameters[0] = ((~(0x0080)) & datasize);
- scu_cmd.parameter_len = 2;
- scu_cmd.result_len = datasize / 2 + 2;
- } else {
- int i = 0;
- set_param_parameters[0] = 0x0080 | datasize;
- for (i = 0; i < (datasize / 2); i++) {
- set_param_parameters[i + 2] =
- (data[2 * i] | (data[(2 * i) + 1] << 8));
- }
- scu_cmd.parameter_len = datasize / 2 + 2;
- scu_cmd.result_len = 1;
- }
- scu_cmd.command =
- SCU_RAM_COMMAND_STANDARD_TOP |
- SCU_RAM_COMMAND_CMD_AUX_SCU_ATOMIC_ACCESS;
- scu_cmd.result = cmd_result;
- scu_cmd.parameter = set_param_parameters;
- rc = scu_command(dev_addr, &scu_cmd);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (read_flag) {
- int i = 0;
- /* read data from buffer */
- for (i = 0; i < (datasize / 2); i++) {
- data[2 * i] = (u8) (scu_cmd.result[i + 2] & 0xFF);
- data[(2 * i) + 1] = (u8) (scu_cmd.result[i + 2] >> 8);
- }
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn int DRXJ_DAP_AtomicReadReg16()
- * \brief Atomic read of 16 bits words
- */
- static
- int drxj_dap_scu_atomic_read_reg16(struct i2c_device_addr *dev_addr,
- u32 addr,
- u16 *data, u32 flags)
- {
- u8 buf[2] = { 0 };
- int rc = -EIO;
- u16 word = 0;
- if (!data)
- return -EINVAL;
- rc = drxj_dap_scu_atomic_read_write_block(dev_addr, addr, 2, buf, true);
- if (rc < 0)
- return rc;
- word = (u16) (buf[0] + (buf[1] << 8));
- *data = word;
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn int drxj_dap_scu_atomic_write_reg16()
- * \brief Atomic read of 16 bits words
- */
- static
- int drxj_dap_scu_atomic_write_reg16(struct i2c_device_addr *dev_addr,
- u32 addr,
- u16 data, u32 flags)
- {
- u8 buf[2];
- int rc = -EIO;
- buf[0] = (u8) (data & 0xff);
- buf[1] = (u8) ((data >> 8) & 0xff);
- rc = drxj_dap_scu_atomic_read_write_block(dev_addr, addr, 2, buf, false);
- return rc;
- }
- /* -------------------------------------------------------------------------- */
- /**
- * \brief Measure result of ADC synchronisation
- * \param demod demod instance
- * \param count (returned) count
- * \return int.
- * \retval 0 Success
- * \retval -EIO Failure: I2C error
- *
- */
- static int adc_sync_measurement(struct drx_demod_instance *demod, u16 *count)
- {
- struct i2c_device_addr *dev_addr = NULL;
- int rc;
- u16 data = 0;
- dev_addr = demod->my_i2c_dev_addr;
- /* Start measurement */
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_COMM_EXEC__A, IQM_AF_COMM_EXEC_ACTIVE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_START_LOCK__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Wait at least 3*128*(1/sysclk) <<< 1 millisec */
- msleep(1);
- *count = 0;
- rc = drxj_dap_read_reg16(dev_addr, IQM_AF_PHASE0__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (data == 127)
- *count = *count + 1;
- rc = drxj_dap_read_reg16(dev_addr, IQM_AF_PHASE1__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (data == 127)
- *count = *count + 1;
- rc = drxj_dap_read_reg16(dev_addr, IQM_AF_PHASE2__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (data == 127)
- *count = *count + 1;
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \brief Synchronize analog and digital clock domains
- * \param demod demod instance
- * \return int.
- * \retval 0 Success
- * \retval -EIO Failure: I2C error or failure to synchronize
- *
- * An IQM reset will also reset the results of this synchronization.
- * After an IQM reset this routine needs to be called again.
- *
- */
- static int adc_synchronization(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = NULL;
- int rc;
- u16 count = 0;
- dev_addr = demod->my_i2c_dev_addr;
- rc = adc_sync_measurement(demod, &count);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (count == 1) {
- /* Try sampling on a different edge */
- u16 clk_neg = 0;
- rc = drxj_dap_read_reg16(dev_addr, IQM_AF_CLKNEG__A, &clk_neg, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- clk_neg ^= IQM_AF_CLKNEG_CLKNEGDATA__M;
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_CLKNEG__A, clk_neg, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = adc_sync_measurement(demod, &count);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* TODO: implement fallback scenarios */
- if (count < 2)
- return -EIO;
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /*== END AUXILIARY FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /*============================================================================*/
- /*== 8VSB & QAM COMMON DATAPATH FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /**
- * \fn int init_agc ()
- * \brief Initialize AGC for all standards.
- * \param demod instance of demodulator.
- * \param channel pointer to channel data.
- * \return int.
- */
- static int init_agc(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = NULL;
- struct drx_common_attr *common_attr = NULL;
- struct drxj_data *ext_attr = NULL;
- struct drxj_cfg_agc *p_agc_rf_settings = NULL;
- struct drxj_cfg_agc *p_agc_if_settings = NULL;
- int rc;
- u16 ingain_tgt_max = 0;
- u16 clp_dir_to = 0;
- u16 sns_sum_max = 0;
- u16 clp_sum_max = 0;
- u16 sns_dir_to = 0;
- u16 ki_innergain_min = 0;
- u16 agc_ki = 0;
- u16 ki_max = 0;
- u16 if_iaccu_hi_tgt_min = 0;
- u16 data = 0;
- u16 agc_ki_dgain = 0;
- u16 ki_min = 0;
- u16 clp_ctrl_mode = 0;
- u16 agc_rf = 0;
- u16 agc_if = 0;
- dev_addr = demod->my_i2c_dev_addr;
- common_attr = (struct drx_common_attr *) demod->my_common_attr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- switch (ext_attr->standard) {
- case DRX_STANDARD_8VSB:
- clp_sum_max = 1023;
- clp_dir_to = (u16) (-9);
- sns_sum_max = 1023;
- sns_dir_to = (u16) (-9);
- ki_innergain_min = (u16) (-32768);
- ki_max = 0x032C;
- agc_ki_dgain = 0xC;
- if_iaccu_hi_tgt_min = 2047;
- ki_min = 0x0117;
- ingain_tgt_max = 16383;
- clp_ctrl_mode = 0;
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MINGAIN__A, 0x7fff, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MAXGAIN__A, 0x0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_SUM__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_CYCCNT__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_DIR_WD__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_DIR_STP__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_SUM__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_CYCCNT__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_DIR_WD__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_DIR_STP__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_INGAIN__A, 1024, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_VSB_AGC_POW_TGT__A, 22600, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_INGAIN_TGT__A, 13200, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- p_agc_if_settings = &(ext_attr->vsb_if_agc_cfg);
- p_agc_rf_settings = &(ext_attr->vsb_rf_agc_cfg);
- break;
- #ifndef DRXJ_VSB_ONLY
- case DRX_STANDARD_ITU_A:
- case DRX_STANDARD_ITU_C:
- case DRX_STANDARD_ITU_B:
- ingain_tgt_max = 5119;
- clp_sum_max = 1023;
- clp_dir_to = (u16) (-5);
- sns_sum_max = 127;
- sns_dir_to = (u16) (-3);
- ki_innergain_min = 0;
- ki_max = 0x0657;
- if_iaccu_hi_tgt_min = 2047;
- agc_ki_dgain = 0x7;
- ki_min = 0x0117;
- clp_ctrl_mode = 0;
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MINGAIN__A, 0x7fff, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MAXGAIN__A, 0x0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_SUM__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_CYCCNT__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_DIR_WD__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_DIR_STP__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_SUM__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_CYCCNT__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_DIR_WD__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_DIR_STP__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- p_agc_if_settings = &(ext_attr->qam_if_agc_cfg);
- p_agc_rf_settings = &(ext_attr->qam_rf_agc_cfg);
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_INGAIN_TGT__A, p_agc_if_settings->top, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_AGC_KI__A, &agc_ki, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- agc_ki &= 0xf000;
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI__A, agc_ki, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- #endif
- default:
- return -EINVAL;
- }
- /* for new AGC interface */
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_INGAIN_TGT_MIN__A, p_agc_if_settings->top, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_INGAIN__A, p_agc_if_settings->top, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* Gain fed from inner to outer AGC */
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_INGAIN_TGT_MAX__A, ingain_tgt_max, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT_MIN__A, if_iaccu_hi_tgt_min, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_IF_IACCU_HI__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* set to p_agc_settings->top before */
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_IF_IACCU_LO__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_RF_IACCU_HI__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_RF_IACCU_LO__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_RF_MAX__A, 32767, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_SUM_MAX__A, clp_sum_max, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_SUM_MAX__A, sns_sum_max, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_INNERGAIN_MIN__A, ki_innergain_min, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_FAST_SNS_CTRL_DELAY__A, 50, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_CYCLEN__A, 500, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_CYCLEN__A, 500, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MAXMINGAIN_TH__A, 20, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MIN__A, ki_min, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_MAX__A, ki_max, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI_RED__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_SUM_MIN__A, 8, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_CYCLEN__A, 500, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_DIR_TO__A, clp_dir_to, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_SUM_MIN__A, 8, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_SNS_DIR_TO__A, sns_dir_to, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A, 50, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_CLP_CTRL_MODE__A, clp_ctrl_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- agc_rf = 0x800 + p_agc_rf_settings->cut_off_current;
- if (common_attr->tuner_rf_agc_pol == true)
- agc_rf = 0x87ff - agc_rf;
- agc_if = 0x800;
- if (common_attr->tuner_if_agc_pol == true)
- agc_rf = 0x87ff - agc_rf;
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_AGC_RF__A, agc_rf, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_AGC_IF__A, agc_if, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Set/restore Ki DGAIN factor */
- rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_AGC_KI__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data &= ~SCU_RAM_AGC_KI_DGAIN__M;
- data |= (agc_ki_dgain << SCU_RAM_AGC_KI_DGAIN__B);
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_AGC_KI__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int set_frequency ()
- * \brief Set frequency shift.
- * \param demod instance of demodulator.
- * \param channel pointer to channel data.
- * \param tuner_freq_offset residual frequency from tuner.
- * \return int.
- */
- static int
- set_frequency(struct drx_demod_instance *demod,
- struct drx_channel *channel, s32 tuner_freq_offset)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- struct drxj_data *ext_attr = demod->my_ext_attr;
- int rc;
- s32 sampling_frequency = 0;
- s32 frequency_shift = 0;
- s32 if_freq_actual = 0;
- s32 rf_freq_residual = -1 * tuner_freq_offset;
- s32 adc_freq = 0;
- s32 intermediate_freq = 0;
- u32 iqm_fs_rate_ofs = 0;
- bool adc_flip = true;
- bool select_pos_image = false;
- bool rf_mirror;
- bool tuner_mirror;
- bool image_to_select = true;
- s32 fm_frequency_shift = 0;
- rf_mirror = (ext_attr->mirror == DRX_MIRROR_YES) ? true : false;
- tuner_mirror = demod->my_common_attr->mirror_freq_spect ? false : true;
- /*
- Program frequency shifter
- No need to account for mirroring on RF
- */
- switch (ext_attr->standard) {
- case DRX_STANDARD_ITU_A: /* fallthrough */
- case DRX_STANDARD_ITU_C: /* fallthrough */
- case DRX_STANDARD_PAL_SECAM_LP: /* fallthrough */
- case DRX_STANDARD_8VSB:
- select_pos_image = true;
- break;
- case DRX_STANDARD_FM:
- /* After IQM FS sound carrier must appear at 4 Mhz in spect.
- Sound carrier is already 3Mhz above centre frequency due
- to tuner setting so now add an extra shift of 1MHz... */
- fm_frequency_shift = 1000;
- case DRX_STANDARD_ITU_B: /* fallthrough */
- case DRX_STANDARD_NTSC: /* fallthrough */
- case DRX_STANDARD_PAL_SECAM_BG: /* fallthrough */
- case DRX_STANDARD_PAL_SECAM_DK: /* fallthrough */
- case DRX_STANDARD_PAL_SECAM_I: /* fallthrough */
- case DRX_STANDARD_PAL_SECAM_L:
- select_pos_image = false;
- break;
- default:
- return -EINVAL;
- }
- intermediate_freq = demod->my_common_attr->intermediate_freq;
- sampling_frequency = demod->my_common_attr->sys_clock_freq / 3;
- if (tuner_mirror)
- if_freq_actual = intermediate_freq + rf_freq_residual + fm_frequency_shift;
- else
- if_freq_actual = intermediate_freq - rf_freq_residual - fm_frequency_shift;
- if (if_freq_actual > sampling_frequency / 2) {
- /* adc mirrors */
- adc_freq = sampling_frequency - if_freq_actual;
- adc_flip = true;
- } else {
- /* adc doesn't mirror */
- adc_freq = if_freq_actual;
- adc_flip = false;
- }
- frequency_shift = adc_freq;
- image_to_select =
- (bool) (rf_mirror ^ tuner_mirror ^ adc_flip ^ select_pos_image);
- iqm_fs_rate_ofs = frac28(frequency_shift, sampling_frequency);
- if (image_to_select)
- iqm_fs_rate_ofs = ~iqm_fs_rate_ofs + 1;
- /* Program frequency shifter with tuner offset compensation */
- /* frequency_shift += tuner_freq_offset; TODO */
- rc = drxdap_fasi_write_reg32(dev_addr, IQM_FS_RATE_OFS_LO__A, iqm_fs_rate_ofs, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ext_attr->iqm_fs_rate_ofs = iqm_fs_rate_ofs;
- ext_attr->pos_image = (bool) (rf_mirror ^ tuner_mirror ^ select_pos_image);
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int get_acc_pkt_err()
- * \brief Retrieve signal strength for VSB and QAM.
- * \param demod Pointer to demod instance
- * \param packet_err Pointer to packet error
- * \return int.
- * \retval 0 sig_strength contains valid data.
- * \retval -EINVAL sig_strength is NULL.
- * \retval -EIO Erroneous data, sig_strength contains invalid data.
- */
- #ifdef DRXJ_SIGNAL_ACCUM_ERR
- static int get_acc_pkt_err(struct drx_demod_instance *demod, u16 *packet_err)
- {
- int rc;
- static u16 pkt_err;
- static u16 last_pkt_err;
- u16 data = 0;
- struct drxj_data *ext_attr = NULL;
- struct i2c_device_addr *dev_addr = NULL;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- dev_addr = demod->my_i2c_dev_addr;
- rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (ext_attr->reset_pkt_err_acc) {
- last_pkt_err = data;
- pkt_err = 0;
- ext_attr->reset_pkt_err_acc = false;
- }
- if (data < last_pkt_err) {
- pkt_err += 0xffff - last_pkt_err;
- pkt_err += data;
- } else {
- pkt_err += (data - last_pkt_err);
- }
- *packet_err = pkt_err;
- last_pkt_err = data;
- return 0;
- rw_error:
- return rc;
- }
- #endif
- /*============================================================================*/
- /**
- * \fn int set_agc_rf ()
- * \brief Configure RF AGC
- * \param demod instance of demodulator.
- * \param agc_settings AGC configuration structure
- * \return int.
- */
- static int
- set_agc_rf(struct drx_demod_instance *demod, struct drxj_cfg_agc *agc_settings, bool atomic)
- {
- struct i2c_device_addr *dev_addr = NULL;
- struct drxj_data *ext_attr = NULL;
- struct drxj_cfg_agc *p_agc_settings = NULL;
- struct drx_common_attr *common_attr = NULL;
- int rc;
- drx_write_reg16func_t scu_wr16 = NULL;
- drx_read_reg16func_t scu_rr16 = NULL;
- common_attr = (struct drx_common_attr *) demod->my_common_attr;
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- if (atomic) {
- scu_rr16 = drxj_dap_scu_atomic_read_reg16;
- scu_wr16 = drxj_dap_scu_atomic_write_reg16;
- } else {
- scu_rr16 = drxj_dap_read_reg16;
- scu_wr16 = drxj_dap_write_reg16;
- }
- /* Configure AGC only if standard is currently active */
- if ((ext_attr->standard == agc_settings->standard) ||
- (DRXJ_ISQAMSTD(ext_attr->standard) &&
- DRXJ_ISQAMSTD(agc_settings->standard)) ||
- (DRXJ_ISATVSTD(ext_attr->standard) &&
- DRXJ_ISATVSTD(agc_settings->standard))) {
- u16 data = 0;
- switch (agc_settings->ctrl_mode) {
- case DRX_AGC_CTRL_AUTO:
- /* Enable RF AGC DAC */
- rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data |= IQM_AF_STDBY_STDBY_TAGC_RF_A2_ACTIVE;
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Enable SCU RF AGC loop */
- rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data &= ~SCU_RAM_AGC_KI_RF__M;
- if (ext_attr->standard == DRX_STANDARD_8VSB)
- data |= (2 << SCU_RAM_AGC_KI_RF__B);
- else if (DRXJ_ISQAMSTD(ext_attr->standard))
- data |= (5 << SCU_RAM_AGC_KI_RF__B);
- else
- data |= (4 << SCU_RAM_AGC_KI_RF__B);
- if (common_attr->tuner_rf_agc_pol)
- data |= SCU_RAM_AGC_KI_INV_RF_POL__M;
- else
- data &= ~SCU_RAM_AGC_KI_INV_RF_POL__M;
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Set speed ( using complementary reduction value ) */
- rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI_RED__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data &= ~SCU_RAM_AGC_KI_RED_RAGC_RED__M;
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI_RED__A, (~(agc_settings->speed << SCU_RAM_AGC_KI_RED_RAGC_RED__B) & SCU_RAM_AGC_KI_RED_RAGC_RED__M) | data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (agc_settings->standard == DRX_STANDARD_8VSB)
- p_agc_settings = &(ext_attr->vsb_if_agc_cfg);
- else if (DRXJ_ISQAMSTD(agc_settings->standard))
- p_agc_settings = &(ext_attr->qam_if_agc_cfg);
- else if (DRXJ_ISATVSTD(agc_settings->standard))
- p_agc_settings = &(ext_attr->atv_if_agc_cfg);
- else
- return -EINVAL;
- /* Set TOP, only if IF-AGC is in AUTO mode */
- if (p_agc_settings->ctrl_mode == DRX_AGC_CTRL_AUTO) {
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, agc_settings->top, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT__A, agc_settings->top, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* Cut-Off current */
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_RF_IACCU_HI_CO__A, agc_settings->cut_off_current, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_AGC_CTRL_USER:
- /* Enable RF AGC DAC */
- rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data |= IQM_AF_STDBY_STDBY_TAGC_RF_A2_ACTIVE;
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Disable SCU RF AGC loop */
- rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data &= ~SCU_RAM_AGC_KI_RF__M;
- if (common_attr->tuner_rf_agc_pol)
- data |= SCU_RAM_AGC_KI_INV_RF_POL__M;
- else
- data &= ~SCU_RAM_AGC_KI_INV_RF_POL__M;
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Write value to output pin */
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_RF_IACCU_HI__A, agc_settings->output_level, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_AGC_CTRL_OFF:
- /* Disable RF AGC DAC */
- rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data &= (~IQM_AF_STDBY_STDBY_TAGC_RF_A2_ACTIVE);
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Disable SCU RF AGC loop */
- rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data &= ~SCU_RAM_AGC_KI_RF__M;
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- default:
- return -EINVAL;
- } /* switch ( agcsettings->ctrl_mode ) */
- }
- /* Store rf agc settings */
- switch (agc_settings->standard) {
- case DRX_STANDARD_8VSB:
- ext_attr->vsb_rf_agc_cfg = *agc_settings;
- break;
- #ifndef DRXJ_VSB_ONLY
- case DRX_STANDARD_ITU_A:
- case DRX_STANDARD_ITU_B:
- case DRX_STANDARD_ITU_C:
- ext_attr->qam_rf_agc_cfg = *agc_settings;
- break;
- #endif
- default:
- return -EIO;
- }
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int set_agc_if ()
- * \brief Configure If AGC
- * \param demod instance of demodulator.
- * \param agc_settings AGC configuration structure
- * \return int.
- */
- static int
- set_agc_if(struct drx_demod_instance *demod, struct drxj_cfg_agc *agc_settings, bool atomic)
- {
- struct i2c_device_addr *dev_addr = NULL;
- struct drxj_data *ext_attr = NULL;
- struct drxj_cfg_agc *p_agc_settings = NULL;
- struct drx_common_attr *common_attr = NULL;
- drx_write_reg16func_t scu_wr16 = NULL;
- drx_read_reg16func_t scu_rr16 = NULL;
- int rc;
- common_attr = (struct drx_common_attr *) demod->my_common_attr;
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- if (atomic) {
- scu_rr16 = drxj_dap_scu_atomic_read_reg16;
- scu_wr16 = drxj_dap_scu_atomic_write_reg16;
- } else {
- scu_rr16 = drxj_dap_read_reg16;
- scu_wr16 = drxj_dap_write_reg16;
- }
- /* Configure AGC only if standard is currently active */
- if ((ext_attr->standard == agc_settings->standard) ||
- (DRXJ_ISQAMSTD(ext_attr->standard) &&
- DRXJ_ISQAMSTD(agc_settings->standard)) ||
- (DRXJ_ISATVSTD(ext_attr->standard) &&
- DRXJ_ISATVSTD(agc_settings->standard))) {
- u16 data = 0;
- switch (agc_settings->ctrl_mode) {
- case DRX_AGC_CTRL_AUTO:
- /* Enable IF AGC DAC */
- rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data |= IQM_AF_STDBY_STDBY_TAGC_IF_A2_ACTIVE;
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Enable SCU IF AGC loop */
- rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data &= ~SCU_RAM_AGC_KI_IF_AGC_DISABLE__M;
- data &= ~SCU_RAM_AGC_KI_IF__M;
- if (ext_attr->standard == DRX_STANDARD_8VSB)
- data |= (3 << SCU_RAM_AGC_KI_IF__B);
- else if (DRXJ_ISQAMSTD(ext_attr->standard))
- data |= (6 << SCU_RAM_AGC_KI_IF__B);
- else
- data |= (5 << SCU_RAM_AGC_KI_IF__B);
- if (common_attr->tuner_if_agc_pol)
- data |= SCU_RAM_AGC_KI_INV_IF_POL__M;
- else
- data &= ~SCU_RAM_AGC_KI_INV_IF_POL__M;
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Set speed (using complementary reduction value) */
- rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI_RED__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data &= ~SCU_RAM_AGC_KI_RED_IAGC_RED__M;
- rc = (*scu_wr16) (dev_addr, SCU_RAM_AGC_KI_RED__A, (~(agc_settings->speed << SCU_RAM_AGC_KI_RED_IAGC_RED__B) & SCU_RAM_AGC_KI_RED_IAGC_RED__M) | data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (agc_settings->standard == DRX_STANDARD_8VSB)
- p_agc_settings = &(ext_attr->vsb_rf_agc_cfg);
- else if (DRXJ_ISQAMSTD(agc_settings->standard))
- p_agc_settings = &(ext_attr->qam_rf_agc_cfg);
- else if (DRXJ_ISATVSTD(agc_settings->standard))
- p_agc_settings = &(ext_attr->atv_rf_agc_cfg);
- else
- return -EINVAL;
- /* Restore TOP */
- if (p_agc_settings->ctrl_mode == DRX_AGC_CTRL_AUTO) {
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, p_agc_settings->top, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT__A, p_agc_settings->top, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- } else {
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- break;
- case DRX_AGC_CTRL_USER:
- /* Enable IF AGC DAC */
- rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data |= IQM_AF_STDBY_STDBY_TAGC_IF_A2_ACTIVE;
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Disable SCU IF AGC loop */
- rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data &= ~SCU_RAM_AGC_KI_IF_AGC_DISABLE__M;
- data |= SCU_RAM_AGC_KI_IF_AGC_DISABLE__M;
- if (common_attr->tuner_if_agc_pol)
- data |= SCU_RAM_AGC_KI_INV_IF_POL__M;
- else
- data &= ~SCU_RAM_AGC_KI_INV_IF_POL__M;
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Write value to output pin */
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, agc_settings->output_level, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_AGC_CTRL_OFF:
- /* Disable If AGC DAC */
- rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data &= (~IQM_AF_STDBY_STDBY_TAGC_IF_A2_ACTIVE);
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Disable SCU IF AGC loop */
- rc = (*scu_rr16)(dev_addr, SCU_RAM_AGC_KI__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data &= ~SCU_RAM_AGC_KI_IF_AGC_DISABLE__M;
- data |= SCU_RAM_AGC_KI_IF_AGC_DISABLE__M;
- rc = (*scu_wr16)(dev_addr, SCU_RAM_AGC_KI__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- default:
- return -EINVAL;
- } /* switch ( agcsettings->ctrl_mode ) */
- /* always set the top to support configurations without if-loop */
- rc = (*scu_wr16) (dev_addr, SCU_RAM_AGC_INGAIN_TGT_MIN__A, agc_settings->top, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* Store if agc settings */
- switch (agc_settings->standard) {
- case DRX_STANDARD_8VSB:
- ext_attr->vsb_if_agc_cfg = *agc_settings;
- break;
- #ifndef DRXJ_VSB_ONLY
- case DRX_STANDARD_ITU_A:
- case DRX_STANDARD_ITU_B:
- case DRX_STANDARD_ITU_C:
- ext_attr->qam_if_agc_cfg = *agc_settings;
- break;
- #endif
- default:
- return -EIO;
- }
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int set_iqm_af ()
- * \brief Configure IQM AF registers
- * \param demod instance of demodulator.
- * \param active
- * \return int.
- */
- static int set_iqm_af(struct drx_demod_instance *demod, bool active)
- {
- u16 data = 0;
- struct i2c_device_addr *dev_addr = NULL;
- int rc;
- dev_addr = demod->my_i2c_dev_addr;
- /* Configure IQM */
- rc = drxj_dap_read_reg16(dev_addr, IQM_AF_STDBY__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (!active)
- data &= ((~IQM_AF_STDBY_STDBY_ADC_A2_ACTIVE) & (~IQM_AF_STDBY_STDBY_AMP_A2_ACTIVE) & (~IQM_AF_STDBY_STDBY_PD_A2_ACTIVE) & (~IQM_AF_STDBY_STDBY_TAGC_IF_A2_ACTIVE) & (~IQM_AF_STDBY_STDBY_TAGC_RF_A2_ACTIVE));
- else
- data |= (IQM_AF_STDBY_STDBY_ADC_A2_ACTIVE | IQM_AF_STDBY_STDBY_AMP_A2_ACTIVE | IQM_AF_STDBY_STDBY_PD_A2_ACTIVE | IQM_AF_STDBY_STDBY_TAGC_IF_A2_ACTIVE | IQM_AF_STDBY_STDBY_TAGC_RF_A2_ACTIVE);
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /*== END 8VSB & QAM COMMON DATAPATH FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /*============================================================================*/
- /*== 8VSB DATAPATH FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /**
- * \fn int power_down_vsb ()
- * \brief Powr down QAM related blocks.
- * \param demod instance of demodulator.
- * \param channel pointer to channel data.
- * \return int.
- */
- static int power_down_vsb(struct drx_demod_instance *demod, bool primary)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- struct drxjscu_cmd cmd_scu = { /* command */ 0,
- /* parameter_len */ 0,
- /* result_len */ 0,
- /* *parameter */ NULL,
- /* *result */ NULL
- };
- struct drx_cfg_mpeg_output cfg_mpeg_output;
- int rc;
- u16 cmd_result = 0;
- /*
- STOP demodulator
- reset of FEC and VSB HW
- */
- cmd_scu.command = SCU_RAM_COMMAND_STANDARD_VSB |
- SCU_RAM_COMMAND_CMD_DEMOD_STOP;
- cmd_scu.parameter_len = 0;
- cmd_scu.result_len = 1;
- cmd_scu.parameter = NULL;
- cmd_scu.result = &cmd_result;
- rc = scu_command(dev_addr, &cmd_scu);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* stop all comm_exec */
- rc = drxj_dap_write_reg16(dev_addr, FEC_COMM_EXEC__A, FEC_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_COMM_EXEC__A, VSB_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (primary) {
- rc = drxj_dap_write_reg16(dev_addr, IQM_COMM_EXEC__A, IQM_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_iqm_af(demod, false);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- } else {
- rc = drxj_dap_write_reg16(dev_addr, IQM_FS_COMM_EXEC__A, IQM_FS_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_FD_COMM_EXEC__A, IQM_FD_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RC_COMM_EXEC__A, IQM_RC_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RT_COMM_EXEC__A, IQM_RT_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_COMM_EXEC__A, IQM_CF_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- cfg_mpeg_output.enable_mpeg_output = false;
- rc = ctrl_set_cfg_mpeg_output(demod, &cfg_mpeg_output);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int set_vsb_leak_n_gain ()
- * \brief Set ATSC demod.
- * \param demod instance of demodulator.
- * \return int.
- */
- static int set_vsb_leak_n_gain(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = NULL;
- int rc;
- const u8 vsb_ffe_leak_gain_ram0[] = {
- DRXJ_16TO8(0x8), /* FFETRAINLKRATIO1 */
- DRXJ_16TO8(0x8), /* FFETRAINLKRATIO2 */
- DRXJ_16TO8(0x8), /* FFETRAINLKRATIO3 */
- DRXJ_16TO8(0xf), /* FFETRAINLKRATIO4 */
- DRXJ_16TO8(0xf), /* FFETRAINLKRATIO5 */
- DRXJ_16TO8(0xf), /* FFETRAINLKRATIO6 */
- DRXJ_16TO8(0xf), /* FFETRAINLKRATIO7 */
- DRXJ_16TO8(0xf), /* FFETRAINLKRATIO8 */
- DRXJ_16TO8(0xf), /* FFETRAINLKRATIO9 */
- DRXJ_16TO8(0x8), /* FFETRAINLKRATIO10 */
- DRXJ_16TO8(0x8), /* FFETRAINLKRATIO11 */
- DRXJ_16TO8(0x8), /* FFETRAINLKRATIO12 */
- DRXJ_16TO8(0x10), /* FFERCA1TRAINLKRATIO1 */
- DRXJ_16TO8(0x10), /* FFERCA1TRAINLKRATIO2 */
- DRXJ_16TO8(0x10), /* FFERCA1TRAINLKRATIO3 */
- DRXJ_16TO8(0x20), /* FFERCA1TRAINLKRATIO4 */
- DRXJ_16TO8(0x20), /* FFERCA1TRAINLKRATIO5 */
- DRXJ_16TO8(0x20), /* FFERCA1TRAINLKRATIO6 */
- DRXJ_16TO8(0x20), /* FFERCA1TRAINLKRATIO7 */
- DRXJ_16TO8(0x20), /* FFERCA1TRAINLKRATIO8 */
- DRXJ_16TO8(0x20), /* FFERCA1TRAINLKRATIO9 */
- DRXJ_16TO8(0x10), /* FFERCA1TRAINLKRATIO10 */
- DRXJ_16TO8(0x10), /* FFERCA1TRAINLKRATIO11 */
- DRXJ_16TO8(0x10), /* FFERCA1TRAINLKRATIO12 */
- DRXJ_16TO8(0x10), /* FFERCA1DATALKRATIO1 */
- DRXJ_16TO8(0x10), /* FFERCA1DATALKRATIO2 */
- DRXJ_16TO8(0x10), /* FFERCA1DATALKRATIO3 */
- DRXJ_16TO8(0x20), /* FFERCA1DATALKRATIO4 */
- DRXJ_16TO8(0x20), /* FFERCA1DATALKRATIO5 */
- DRXJ_16TO8(0x20), /* FFERCA1DATALKRATIO6 */
- DRXJ_16TO8(0x20), /* FFERCA1DATALKRATIO7 */
- DRXJ_16TO8(0x20), /* FFERCA1DATALKRATIO8 */
- DRXJ_16TO8(0x20), /* FFERCA1DATALKRATIO9 */
- DRXJ_16TO8(0x10), /* FFERCA1DATALKRATIO10 */
- DRXJ_16TO8(0x10), /* FFERCA1DATALKRATIO11 */
- DRXJ_16TO8(0x10), /* FFERCA1DATALKRATIO12 */
- DRXJ_16TO8(0x10), /* FFERCA2TRAINLKRATIO1 */
- DRXJ_16TO8(0x10), /* FFERCA2TRAINLKRATIO2 */
- DRXJ_16TO8(0x10), /* FFERCA2TRAINLKRATIO3 */
- DRXJ_16TO8(0x20), /* FFERCA2TRAINLKRATIO4 */
- DRXJ_16TO8(0x20), /* FFERCA2TRAINLKRATIO5 */
- DRXJ_16TO8(0x20), /* FFERCA2TRAINLKRATIO6 */
- DRXJ_16TO8(0x20), /* FFERCA2TRAINLKRATIO7 */
- DRXJ_16TO8(0x20), /* FFERCA2TRAINLKRATIO8 */
- DRXJ_16TO8(0x20), /* FFERCA2TRAINLKRATIO9 */
- DRXJ_16TO8(0x10), /* FFERCA2TRAINLKRATIO10 */
- DRXJ_16TO8(0x10), /* FFERCA2TRAINLKRATIO11 */
- DRXJ_16TO8(0x10), /* FFERCA2TRAINLKRATIO12 */
- DRXJ_16TO8(0x10), /* FFERCA2DATALKRATIO1 */
- DRXJ_16TO8(0x10), /* FFERCA2DATALKRATIO2 */
- DRXJ_16TO8(0x10), /* FFERCA2DATALKRATIO3 */
- DRXJ_16TO8(0x20), /* FFERCA2DATALKRATIO4 */
- DRXJ_16TO8(0x20), /* FFERCA2DATALKRATIO5 */
- DRXJ_16TO8(0x20), /* FFERCA2DATALKRATIO6 */
- DRXJ_16TO8(0x20), /* FFERCA2DATALKRATIO7 */
- DRXJ_16TO8(0x20), /* FFERCA2DATALKRATIO8 */
- DRXJ_16TO8(0x20), /* FFERCA2DATALKRATIO9 */
- DRXJ_16TO8(0x10), /* FFERCA2DATALKRATIO10 */
- DRXJ_16TO8(0x10), /* FFERCA2DATALKRATIO11 */
- DRXJ_16TO8(0x10), /* FFERCA2DATALKRATIO12 */
- DRXJ_16TO8(0x07), /* FFEDDM1TRAINLKRATIO1 */
- DRXJ_16TO8(0x07), /* FFEDDM1TRAINLKRATIO2 */
- DRXJ_16TO8(0x07), /* FFEDDM1TRAINLKRATIO3 */
- DRXJ_16TO8(0x0e), /* FFEDDM1TRAINLKRATIO4 */
- DRXJ_16TO8(0x0e), /* FFEDDM1TRAINLKRATIO5 */
- DRXJ_16TO8(0x0e), /* FFEDDM1TRAINLKRATIO6 */
- DRXJ_16TO8(0x0e), /* FFEDDM1TRAINLKRATIO7 */
- DRXJ_16TO8(0x0e), /* FFEDDM1TRAINLKRATIO8 */
- DRXJ_16TO8(0x0e), /* FFEDDM1TRAINLKRATIO9 */
- DRXJ_16TO8(0x07), /* FFEDDM1TRAINLKRATIO10 */
- DRXJ_16TO8(0x07), /* FFEDDM1TRAINLKRATIO11 */
- DRXJ_16TO8(0x07), /* FFEDDM1TRAINLKRATIO12 */
- DRXJ_16TO8(0x07), /* FFEDDM1DATALKRATIO1 */
- DRXJ_16TO8(0x07), /* FFEDDM1DATALKRATIO2 */
- DRXJ_16TO8(0x07), /* FFEDDM1DATALKRATIO3 */
- DRXJ_16TO8(0x0e), /* FFEDDM1DATALKRATIO4 */
- DRXJ_16TO8(0x0e), /* FFEDDM1DATALKRATIO5 */
- DRXJ_16TO8(0x0e), /* FFEDDM1DATALKRATIO6 */
- DRXJ_16TO8(0x0e), /* FFEDDM1DATALKRATIO7 */
- DRXJ_16TO8(0x0e), /* FFEDDM1DATALKRATIO8 */
- DRXJ_16TO8(0x0e), /* FFEDDM1DATALKRATIO9 */
- DRXJ_16TO8(0x07), /* FFEDDM1DATALKRATIO10 */
- DRXJ_16TO8(0x07), /* FFEDDM1DATALKRATIO11 */
- DRXJ_16TO8(0x07), /* FFEDDM1DATALKRATIO12 */
- DRXJ_16TO8(0x06), /* FFEDDM2TRAINLKRATIO1 */
- DRXJ_16TO8(0x06), /* FFEDDM2TRAINLKRATIO2 */
- DRXJ_16TO8(0x06), /* FFEDDM2TRAINLKRATIO3 */
- DRXJ_16TO8(0x0c), /* FFEDDM2TRAINLKRATIO4 */
- DRXJ_16TO8(0x0c), /* FFEDDM2TRAINLKRATIO5 */
- DRXJ_16TO8(0x0c), /* FFEDDM2TRAINLKRATIO6 */
- DRXJ_16TO8(0x0c), /* FFEDDM2TRAINLKRATIO7 */
- DRXJ_16TO8(0x0c), /* FFEDDM2TRAINLKRATIO8 */
- DRXJ_16TO8(0x0c), /* FFEDDM2TRAINLKRATIO9 */
- DRXJ_16TO8(0x06), /* FFEDDM2TRAINLKRATIO10 */
- DRXJ_16TO8(0x06), /* FFEDDM2TRAINLKRATIO11 */
- DRXJ_16TO8(0x06), /* FFEDDM2TRAINLKRATIO12 */
- DRXJ_16TO8(0x06), /* FFEDDM2DATALKRATIO1 */
- DRXJ_16TO8(0x06), /* FFEDDM2DATALKRATIO2 */
- DRXJ_16TO8(0x06), /* FFEDDM2DATALKRATIO3 */
- DRXJ_16TO8(0x0c), /* FFEDDM2DATALKRATIO4 */
- DRXJ_16TO8(0x0c), /* FFEDDM2DATALKRATIO5 */
- DRXJ_16TO8(0x0c), /* FFEDDM2DATALKRATIO6 */
- DRXJ_16TO8(0x0c), /* FFEDDM2DATALKRATIO7 */
- DRXJ_16TO8(0x0c), /* FFEDDM2DATALKRATIO8 */
- DRXJ_16TO8(0x0c), /* FFEDDM2DATALKRATIO9 */
- DRXJ_16TO8(0x06), /* FFEDDM2DATALKRATIO10 */
- DRXJ_16TO8(0x06), /* FFEDDM2DATALKRATIO11 */
- DRXJ_16TO8(0x06), /* FFEDDM2DATALKRATIO12 */
- DRXJ_16TO8(0x2020), /* FIRTRAINGAIN1 */
- DRXJ_16TO8(0x2020), /* FIRTRAINGAIN2 */
- DRXJ_16TO8(0x2020), /* FIRTRAINGAIN3 */
- DRXJ_16TO8(0x4040), /* FIRTRAINGAIN4 */
- DRXJ_16TO8(0x4040), /* FIRTRAINGAIN5 */
- DRXJ_16TO8(0x4040), /* FIRTRAINGAIN6 */
- DRXJ_16TO8(0x4040), /* FIRTRAINGAIN7 */
- DRXJ_16TO8(0x4040), /* FIRTRAINGAIN8 */
- DRXJ_16TO8(0x4040), /* FIRTRAINGAIN9 */
- DRXJ_16TO8(0x2020), /* FIRTRAINGAIN10 */
- DRXJ_16TO8(0x2020), /* FIRTRAINGAIN11 */
- DRXJ_16TO8(0x2020), /* FIRTRAINGAIN12 */
- DRXJ_16TO8(0x0808), /* FIRRCA1GAIN1 */
- DRXJ_16TO8(0x0808), /* FIRRCA1GAIN2 */
- DRXJ_16TO8(0x0808), /* FIRRCA1GAIN3 */
- DRXJ_16TO8(0x1010), /* FIRRCA1GAIN4 */
- DRXJ_16TO8(0x1010), /* FIRRCA1GAIN5 */
- DRXJ_16TO8(0x1010), /* FIRRCA1GAIN6 */
- DRXJ_16TO8(0x1010), /* FIRRCA1GAIN7 */
- DRXJ_16TO8(0x1010) /* FIRRCA1GAIN8 */
- };
- const u8 vsb_ffe_leak_gain_ram1[] = {
- DRXJ_16TO8(0x1010), /* FIRRCA1GAIN9 */
- DRXJ_16TO8(0x0808), /* FIRRCA1GAIN10 */
- DRXJ_16TO8(0x0808), /* FIRRCA1GAIN11 */
- DRXJ_16TO8(0x0808), /* FIRRCA1GAIN12 */
- DRXJ_16TO8(0x0808), /* FIRRCA2GAIN1 */
- DRXJ_16TO8(0x0808), /* FIRRCA2GAIN2 */
- DRXJ_16TO8(0x0808), /* FIRRCA2GAIN3 */
- DRXJ_16TO8(0x1010), /* FIRRCA2GAIN4 */
- DRXJ_16TO8(0x1010), /* FIRRCA2GAIN5 */
- DRXJ_16TO8(0x1010), /* FIRRCA2GAIN6 */
- DRXJ_16TO8(0x1010), /* FIRRCA2GAIN7 */
- DRXJ_16TO8(0x1010), /* FIRRCA2GAIN8 */
- DRXJ_16TO8(0x1010), /* FIRRCA2GAIN9 */
- DRXJ_16TO8(0x0808), /* FIRRCA2GAIN10 */
- DRXJ_16TO8(0x0808), /* FIRRCA2GAIN11 */
- DRXJ_16TO8(0x0808), /* FIRRCA2GAIN12 */
- DRXJ_16TO8(0x0303), /* FIRDDM1GAIN1 */
- DRXJ_16TO8(0x0303), /* FIRDDM1GAIN2 */
- DRXJ_16TO8(0x0303), /* FIRDDM1GAIN3 */
- DRXJ_16TO8(0x0606), /* FIRDDM1GAIN4 */
- DRXJ_16TO8(0x0606), /* FIRDDM1GAIN5 */
- DRXJ_16TO8(0x0606), /* FIRDDM1GAIN6 */
- DRXJ_16TO8(0x0606), /* FIRDDM1GAIN7 */
- DRXJ_16TO8(0x0606), /* FIRDDM1GAIN8 */
- DRXJ_16TO8(0x0606), /* FIRDDM1GAIN9 */
- DRXJ_16TO8(0x0303), /* FIRDDM1GAIN10 */
- DRXJ_16TO8(0x0303), /* FIRDDM1GAIN11 */
- DRXJ_16TO8(0x0303), /* FIRDDM1GAIN12 */
- DRXJ_16TO8(0x0303), /* FIRDDM2GAIN1 */
- DRXJ_16TO8(0x0303), /* FIRDDM2GAIN2 */
- DRXJ_16TO8(0x0303), /* FIRDDM2GAIN3 */
- DRXJ_16TO8(0x0505), /* FIRDDM2GAIN4 */
- DRXJ_16TO8(0x0505), /* FIRDDM2GAIN5 */
- DRXJ_16TO8(0x0505), /* FIRDDM2GAIN6 */
- DRXJ_16TO8(0x0505), /* FIRDDM2GAIN7 */
- DRXJ_16TO8(0x0505), /* FIRDDM2GAIN8 */
- DRXJ_16TO8(0x0505), /* FIRDDM2GAIN9 */
- DRXJ_16TO8(0x0303), /* FIRDDM2GAIN10 */
- DRXJ_16TO8(0x0303), /* FIRDDM2GAIN11 */
- DRXJ_16TO8(0x0303), /* FIRDDM2GAIN12 */
- DRXJ_16TO8(0x001f), /* DFETRAINLKRATIO */
- DRXJ_16TO8(0x01ff), /* DFERCA1TRAINLKRATIO */
- DRXJ_16TO8(0x01ff), /* DFERCA1DATALKRATIO */
- DRXJ_16TO8(0x004f), /* DFERCA2TRAINLKRATIO */
- DRXJ_16TO8(0x004f), /* DFERCA2DATALKRATIO */
- DRXJ_16TO8(0x01ff), /* DFEDDM1TRAINLKRATIO */
- DRXJ_16TO8(0x01ff), /* DFEDDM1DATALKRATIO */
- DRXJ_16TO8(0x0352), /* DFEDDM2TRAINLKRATIO */
- DRXJ_16TO8(0x0352), /* DFEDDM2DATALKRATIO */
- DRXJ_16TO8(0x0000), /* DFETRAINGAIN */
- DRXJ_16TO8(0x2020), /* DFERCA1GAIN */
- DRXJ_16TO8(0x1010), /* DFERCA2GAIN */
- DRXJ_16TO8(0x1818), /* DFEDDM1GAIN */
- DRXJ_16TO8(0x1212) /* DFEDDM2GAIN */
- };
- dev_addr = demod->my_i2c_dev_addr;
- rc = drxdap_fasi_write_block(dev_addr, VSB_SYSCTRL_RAM0_FFETRAINLKRATIO1__A, sizeof(vsb_ffe_leak_gain_ram0), ((u8 *)vsb_ffe_leak_gain_ram0), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxdap_fasi_write_block(dev_addr, VSB_SYSCTRL_RAM1_FIRRCA1GAIN9__A, sizeof(vsb_ffe_leak_gain_ram1), ((u8 *)vsb_ffe_leak_gain_ram1), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int set_vsb()
- * \brief Set 8VSB demod.
- * \param demod instance of demodulator.
- * \return int.
- *
- */
- static int set_vsb(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = NULL;
- int rc;
- struct drx_common_attr *common_attr = NULL;
- struct drxjscu_cmd cmd_scu;
- struct drxj_data *ext_attr = NULL;
- u16 cmd_result = 0;
- u16 cmd_param = 0;
- const u8 vsb_taps_re[] = {
- DRXJ_16TO8(-2), /* re0 */
- DRXJ_16TO8(4), /* re1 */
- DRXJ_16TO8(1), /* re2 */
- DRXJ_16TO8(-4), /* re3 */
- DRXJ_16TO8(1), /* re4 */
- DRXJ_16TO8(4), /* re5 */
- DRXJ_16TO8(-3), /* re6 */
- DRXJ_16TO8(-3), /* re7 */
- DRXJ_16TO8(6), /* re8 */
- DRXJ_16TO8(1), /* re9 */
- DRXJ_16TO8(-9), /* re10 */
- DRXJ_16TO8(3), /* re11 */
- DRXJ_16TO8(12), /* re12 */
- DRXJ_16TO8(-9), /* re13 */
- DRXJ_16TO8(-15), /* re14 */
- DRXJ_16TO8(17), /* re15 */
- DRXJ_16TO8(19), /* re16 */
- DRXJ_16TO8(-29), /* re17 */
- DRXJ_16TO8(-22), /* re18 */
- DRXJ_16TO8(45), /* re19 */
- DRXJ_16TO8(25), /* re20 */
- DRXJ_16TO8(-70), /* re21 */
- DRXJ_16TO8(-28), /* re22 */
- DRXJ_16TO8(111), /* re23 */
- DRXJ_16TO8(30), /* re24 */
- DRXJ_16TO8(-201), /* re25 */
- DRXJ_16TO8(-31), /* re26 */
- DRXJ_16TO8(629) /* re27 */
- };
- dev_addr = demod->my_i2c_dev_addr;
- common_attr = (struct drx_common_attr *) demod->my_common_attr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- /* stop all comm_exec */
- rc = drxj_dap_write_reg16(dev_addr, FEC_COMM_EXEC__A, FEC_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_COMM_EXEC__A, VSB_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_FS_COMM_EXEC__A, IQM_FS_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_FD_COMM_EXEC__A, IQM_FD_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RC_COMM_EXEC__A, IQM_RC_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RT_COMM_EXEC__A, IQM_RT_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_COMM_EXEC__A, IQM_CF_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* reset demodulator */
- cmd_scu.command = SCU_RAM_COMMAND_STANDARD_VSB
- | SCU_RAM_COMMAND_CMD_DEMOD_RESET;
- cmd_scu.parameter_len = 0;
- cmd_scu.result_len = 1;
- cmd_scu.parameter = NULL;
- cmd_scu.result = &cmd_result;
- rc = scu_command(dev_addr, &cmd_scu);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_DCF_BYPASS__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_FS_ADJ_SEL__A, IQM_FS_ADJ_SEL_B_VSB, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RC_ADJ_SEL__A, IQM_RC_ADJ_SEL_B_VSB, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ext_attr->iqm_rc_rate_ofs = 0x00AD0D79;
- rc = drxdap_fasi_write_reg32(dev_addr, IQM_RC_RATE_OFS_LO__A, ext_attr->iqm_rc_rate_ofs, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CFAGC_GAINSHIFT__A, 4, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CYGN1TRK__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RC_CROUT_ENA__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RC_STRETCH__A, 28, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RT_ACTIVE__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_SYMMETRIC__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_MIDTAP__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_OUT_ENA__A, IQM_CF_OUT_ENA_VSB__M, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_SCALE__A, 1393, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_SCALE_SH__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_POW_MEAS_LEN__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_RE0__A, sizeof(vsb_taps_re), ((u8 *)vsb_taps_re), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_IM0__A, sizeof(vsb_taps_re), ((u8 *)vsb_taps_re), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_BNTHRESH__A, 330, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* set higher threshold */
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CLPLASTNUM__A, 90, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* burst detection on */
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_SNRTH_RCA1__A, 0x0042, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* drop thresholds by 1 dB */
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_SNRTH_RCA2__A, 0x0053, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* drop thresholds by 2 dB */
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_EQCTRL__A, 0x1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* cma on */
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_GPIO__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* GPIO */
- /* Initialize the FEC Subsystem */
- rc = drxj_dap_write_reg16(dev_addr, FEC_TOP_ANNEX__A, FEC_TOP_ANNEX_D, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- {
- u16 fec_oc_snc_mode = 0;
- rc = drxj_dap_read_reg16(dev_addr, FEC_OC_SNC_MODE__A, &fec_oc_snc_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* output data even when not locked */
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_MODE__A, fec_oc_snc_mode | FEC_OC_SNC_MODE_UNLOCK_ENABLE__M, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* set clip */
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_CLP_LEN__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_CLP_TH__A, 470, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_SNS_LEN__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_SNRTH_PT__A, 0xD4, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* no transparent, no A&C framing; parity is set in mpegoutput */
- {
- u16 fec_oc_reg_mode = 0;
- rc = drxj_dap_read_reg16(dev_addr, FEC_OC_MODE__A, &fec_oc_reg_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_MODE__A, fec_oc_reg_mode & (~(FEC_OC_MODE_TRANSPARENT__M | FEC_OC_MODE_CLEAR__M | FEC_OC_MODE_RETAIN_FRAMING__M)), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_DI_TIMEOUT_LO__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* timeout counter for restarting */
- rc = drxj_dap_write_reg16(dev_addr, FEC_DI_TIMEOUT_HI__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_RS_MODE__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* bypass disabled */
- /* initialize RS packet error measurement parameters */
- rc = drxj_dap_write_reg16(dev_addr, FEC_RS_MEASUREMENT_PERIOD__A, FEC_RS_MEASUREMENT_PERIOD, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_RS_MEASUREMENT_PRESCALE__A, FEC_RS_MEASUREMENT_PRESCALE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* init measurement period of MER/SER */
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_MEASUREMENT_PERIOD__A, VSB_TOP_MEASUREMENT_PERIOD, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxdap_fasi_write_reg32(dev_addr, SCU_RAM_FEC_ACCUM_CW_CORRECTED_LO__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_FEC_MEAS_COUNT__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CKGN1TRK__A, 128, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* B-Input to ADC, PGA+filter in standby */
- if (!ext_attr->has_lna) {
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_AMUX__A, 0x02, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* turn on IQMAF. It has to be in front of setAgc**() */
- rc = set_iqm_af(demod, true);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = adc_synchronization(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = init_agc(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_agc_if(demod, &(ext_attr->vsb_if_agc_cfg), false);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_agc_rf(demod, &(ext_attr->vsb_rf_agc_cfg), false);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- {
- /* TODO fix this, store a struct drxj_cfg_afe_gain structure in struct drxj_data instead
- of only the gain */
- struct drxj_cfg_afe_gain vsb_pga_cfg = { DRX_STANDARD_8VSB, 0 };
- vsb_pga_cfg.gain = ext_attr->vsb_pga_cfg;
- rc = ctrl_set_cfg_afe_gain(demod, &vsb_pga_cfg);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- rc = ctrl_set_cfg_pre_saw(demod, &(ext_attr->vsb_pre_saw_cfg));
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Mpeg output has to be in front of FEC active */
- rc = set_mpegtei_handling(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = bit_reverse_mpeg_output(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_mpeg_start_width(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- {
- /* TODO: move to set_standard after hardware reset value problem is solved */
- /* Configure initial MPEG output */
- struct drx_cfg_mpeg_output cfg_mpeg_output;
- memcpy(&cfg_mpeg_output, &common_attr->mpeg_cfg, sizeof(cfg_mpeg_output));
- cfg_mpeg_output.enable_mpeg_output = true;
- rc = ctrl_set_cfg_mpeg_output(demod, &cfg_mpeg_output);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* TBD: what parameters should be set */
- cmd_param = 0x00; /* Default mode AGC on, etc */
- cmd_scu.command = SCU_RAM_COMMAND_STANDARD_VSB
- | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM;
- cmd_scu.parameter_len = 1;
- cmd_scu.result_len = 1;
- cmd_scu.parameter = &cmd_param;
- cmd_scu.result = &cmd_result;
- rc = scu_command(dev_addr, &cmd_scu);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_BEAGC_GAINSHIFT__A, 0x0004, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_SNRTH_PT__A, 0x00D2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_SYSSMTRNCTRL__A, VSB_TOP_SYSSMTRNCTRL__PRE | VSB_TOP_SYSSMTRNCTRL_NCOTIMEOUTCNTEN__M, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_BEDETCTRL__A, 0x142, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_LBAGCREFLVL__A, 640, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CYGN1ACQ__A, 4, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CYGN1TRK__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_TOP_CYGN2TRK__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* start demodulator */
- cmd_scu.command = SCU_RAM_COMMAND_STANDARD_VSB
- | SCU_RAM_COMMAND_CMD_DEMOD_START;
- cmd_scu.parameter_len = 0;
- cmd_scu.result_len = 1;
- cmd_scu.parameter = NULL;
- cmd_scu.result = &cmd_result;
- rc = scu_command(dev_addr, &cmd_scu);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_COMM_EXEC__A, IQM_COMM_EXEC_ACTIVE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, VSB_COMM_EXEC__A, VSB_COMM_EXEC_ACTIVE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn static short get_vsb_post_rs_pck_err(struct i2c_device_addr *dev_addr, u16 *PckErrs)
- * \brief Get the values of packet error in 8VSB mode
- * \return Error code
- */
- static int get_vsb_post_rs_pck_err(struct i2c_device_addr *dev_addr,
- u32 *pck_errs, u32 *pck_count)
- {
- int rc;
- u16 data = 0;
- u16 period = 0;
- u16 prescale = 0;
- u16 packet_errors_mant = 0;
- u16 packet_errors_exp = 0;
- rc = drxj_dap_read_reg16(dev_addr, FEC_RS_NR_FAILURES__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- packet_errors_mant = data & FEC_RS_NR_FAILURES_FIXED_MANT__M;
- packet_errors_exp = (data & FEC_RS_NR_FAILURES_EXP__M)
- >> FEC_RS_NR_FAILURES_EXP__B;
- period = FEC_RS_MEASUREMENT_PERIOD;
- prescale = FEC_RS_MEASUREMENT_PRESCALE;
- /* packet error rate = (error packet number) per second */
- /* 77.3 us is time for per packet */
- if (period * prescale == 0) {
- pr_err("error: period and/or prescale is zero!\n");
- return -EIO;
- }
- *pck_errs = packet_errors_mant * (1 << packet_errors_exp);
- *pck_count = period * prescale * 77;
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn static short GetVSBBer(struct i2c_device_addr *dev_addr, u32 *ber)
- * \brief Get the values of ber in VSB mode
- * \return Error code
- */
- static int get_vs_bpost_viterbi_ber(struct i2c_device_addr *dev_addr,
- u32 *ber, u32 *cnt)
- {
- int rc;
- u16 data = 0;
- u16 period = 0;
- u16 prescale = 0;
- u16 bit_errors_mant = 0;
- u16 bit_errors_exp = 0;
- rc = drxj_dap_read_reg16(dev_addr, FEC_RS_NR_BIT_ERRORS__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- period = FEC_RS_MEASUREMENT_PERIOD;
- prescale = FEC_RS_MEASUREMENT_PRESCALE;
- bit_errors_mant = data & FEC_RS_NR_BIT_ERRORS_FIXED_MANT__M;
- bit_errors_exp = (data & FEC_RS_NR_BIT_ERRORS_EXP__M)
- >> FEC_RS_NR_BIT_ERRORS_EXP__B;
- *cnt = period * prescale * 207 * ((bit_errors_exp > 2) ? 1 : 8);
- if (((bit_errors_mant << bit_errors_exp) >> 3) > 68700)
- *ber = (*cnt) * 26570;
- else {
- if (period * prescale == 0) {
- pr_err("error: period and/or prescale is zero!\n");
- return -EIO;
- }
- *ber = bit_errors_mant << ((bit_errors_exp > 2) ?
- (bit_errors_exp - 3) : bit_errors_exp);
- }
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn static short get_vs_bpre_viterbi_ber(struct i2c_device_addr *dev_addr, u32 *ber)
- * \brief Get the values of ber in VSB mode
- * \return Error code
- */
- static int get_vs_bpre_viterbi_ber(struct i2c_device_addr *dev_addr,
- u32 *ber, u32 *cnt)
- {
- u16 data = 0;
- int rc;
- rc = drxj_dap_read_reg16(dev_addr, VSB_TOP_NR_SYM_ERRS__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- return -EIO;
- }
- *ber = data;
- *cnt = VSB_TOP_MEASUREMENT_PERIOD * SYMBOLS_PER_SEGMENT;
- return 0;
- }
- /**
- * \fn static int get_vsbmer(struct i2c_device_addr *dev_addr, u16 *mer)
- * \brief Get the values of MER
- * \return Error code
- */
- static int get_vsbmer(struct i2c_device_addr *dev_addr, u16 *mer)
- {
- int rc;
- u16 data_hi = 0;
- rc = drxj_dap_read_reg16(dev_addr, VSB_TOP_ERR_ENERGY_H__A, &data_hi, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- *mer =
- (u16) (log1_times100(21504) - log1_times100((data_hi << 6) / 52));
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /*== END 8VSB DATAPATH FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /*============================================================================*/
- /*== QAM DATAPATH FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /**
- * \fn int power_down_qam ()
- * \brief Powr down QAM related blocks.
- * \param demod instance of demodulator.
- * \param channel pointer to channel data.
- * \return int.
- */
- static int power_down_qam(struct drx_demod_instance *demod, bool primary)
- {
- struct drxjscu_cmd cmd_scu = { /* command */ 0,
- /* parameter_len */ 0,
- /* result_len */ 0,
- /* *parameter */ NULL,
- /* *result */ NULL
- };
- int rc;
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- struct drx_cfg_mpeg_output cfg_mpeg_output;
- struct drx_common_attr *common_attr = demod->my_common_attr;
- u16 cmd_result = 0;
- /*
- STOP demodulator
- resets IQM, QAM and FEC HW blocks
- */
- /* stop all comm_exec */
- rc = drxj_dap_write_reg16(dev_addr, FEC_COMM_EXEC__A, FEC_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- cmd_scu.command = SCU_RAM_COMMAND_STANDARD_QAM |
- SCU_RAM_COMMAND_CMD_DEMOD_STOP;
- cmd_scu.parameter_len = 0;
- cmd_scu.result_len = 1;
- cmd_scu.parameter = NULL;
- cmd_scu.result = &cmd_result;
- rc = scu_command(dev_addr, &cmd_scu);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (primary) {
- rc = drxj_dap_write_reg16(dev_addr, IQM_COMM_EXEC__A, IQM_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_iqm_af(demod, false);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- } else {
- rc = drxj_dap_write_reg16(dev_addr, IQM_FS_COMM_EXEC__A, IQM_FS_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_FD_COMM_EXEC__A, IQM_FD_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RC_COMM_EXEC__A, IQM_RC_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RT_COMM_EXEC__A, IQM_RT_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_COMM_EXEC__A, IQM_CF_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- memcpy(&cfg_mpeg_output, &common_attr->mpeg_cfg, sizeof(cfg_mpeg_output));
- cfg_mpeg_output.enable_mpeg_output = false;
- rc = ctrl_set_cfg_mpeg_output(demod, &cfg_mpeg_output);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn int set_qam_measurement ()
- * \brief Setup of the QAM Measuremnt intervals for signal quality
- * \param demod instance of demod.
- * \param constellation current constellation.
- * \return int.
- *
- * NOTE:
- * Take into account that for certain settings the errorcounters can overflow.
- * The implementation does not check this.
- *
- * TODO: overriding the ext_attr->fec_bits_desired by constellation dependent
- * constants to get a measurement period of approx. 1 sec. Remove fec_bits_desired
- * field ?
- *
- */
- #ifndef DRXJ_VSB_ONLY
- static int
- set_qam_measurement(struct drx_demod_instance *demod,
- enum drx_modulation constellation, u32 symbol_rate)
- {
- struct i2c_device_addr *dev_addr = NULL; /* device address for I2C writes */
- struct drxj_data *ext_attr = NULL; /* Global data container for DRXJ specific data */
- int rc;
- u32 fec_bits_desired = 0; /* BER accounting period */
- u16 fec_rs_plen = 0; /* defines RS BER measurement period */
- u16 fec_rs_prescale = 0; /* ReedSolomon Measurement Prescale */
- u32 fec_rs_period = 0; /* Value for corresponding I2C register */
- u32 fec_rs_bit_cnt = 0; /* Actual precise amount of bits */
- u32 fec_oc_snc_fail_period = 0; /* Value for corresponding I2C register */
- u32 qam_vd_period = 0; /* Value for corresponding I2C register */
- u32 qam_vd_bit_cnt = 0; /* Actual precise amount of bits */
- u16 fec_vd_plen = 0; /* no of trellis symbols: VD SER measur period */
- u16 qam_vd_prescale = 0; /* Viterbi Measurement Prescale */
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- fec_bits_desired = ext_attr->fec_bits_desired;
- fec_rs_prescale = ext_attr->fec_rs_prescale;
- switch (constellation) {
- case DRX_CONSTELLATION_QAM16:
- fec_bits_desired = 4 * symbol_rate;
- break;
- case DRX_CONSTELLATION_QAM32:
- fec_bits_desired = 5 * symbol_rate;
- break;
- case DRX_CONSTELLATION_QAM64:
- fec_bits_desired = 6 * symbol_rate;
- break;
- case DRX_CONSTELLATION_QAM128:
- fec_bits_desired = 7 * symbol_rate;
- break;
- case DRX_CONSTELLATION_QAM256:
- fec_bits_desired = 8 * symbol_rate;
- break;
- default:
- return -EINVAL;
- }
- /* Parameters for Reed-Solomon Decoder */
- /* fecrs_period = (int)ceil(FEC_BITS_DESIRED/(fecrs_prescale*plen)) */
- /* rs_bit_cnt = fecrs_period*fecrs_prescale*plen */
- /* result is within 32 bit arithmetic -> */
- /* no need for mult or frac functions */
- /* TODO: use constant instead of calculation and remove the fec_rs_plen in ext_attr */
- switch (ext_attr->standard) {
- case DRX_STANDARD_ITU_A:
- case DRX_STANDARD_ITU_C:
- fec_rs_plen = 204 * 8;
- break;
- case DRX_STANDARD_ITU_B:
- fec_rs_plen = 128 * 7;
- break;
- default:
- return -EINVAL;
- }
- ext_attr->fec_rs_plen = fec_rs_plen; /* for getSigQual */
- fec_rs_bit_cnt = fec_rs_prescale * fec_rs_plen; /* temp storage */
- if (fec_rs_bit_cnt == 0) {
- pr_err("error: fec_rs_bit_cnt is zero!\n");
- return -EIO;
- }
- fec_rs_period = fec_bits_desired / fec_rs_bit_cnt + 1; /* ceil */
- if (ext_attr->standard != DRX_STANDARD_ITU_B)
- fec_oc_snc_fail_period = fec_rs_period;
- /* limit to max 16 bit value (I2C register width) if needed */
- if (fec_rs_period > 0xFFFF)
- fec_rs_period = 0xFFFF;
- /* write corresponding registers */
- switch (ext_attr->standard) {
- case DRX_STANDARD_ITU_A:
- case DRX_STANDARD_ITU_C:
- break;
- case DRX_STANDARD_ITU_B:
- switch (constellation) {
- case DRX_CONSTELLATION_QAM64:
- fec_rs_period = 31581;
- fec_oc_snc_fail_period = 17932;
- break;
- case DRX_CONSTELLATION_QAM256:
- fec_rs_period = 45446;
- fec_oc_snc_fail_period = 25805;
- break;
- default:
- return -EINVAL;
- }
- break;
- default:
- return -EINVAL;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_OC_SNC_FAIL_PERIOD__A, (u16)fec_oc_snc_fail_period, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_RS_MEASUREMENT_PERIOD__A, (u16)fec_rs_period, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_RS_MEASUREMENT_PRESCALE__A, fec_rs_prescale, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ext_attr->fec_rs_period = (u16) fec_rs_period;
- ext_attr->fec_rs_prescale = fec_rs_prescale;
- rc = drxdap_fasi_write_reg32(dev_addr, SCU_RAM_FEC_ACCUM_CW_CORRECTED_LO__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_FEC_MEAS_COUNT__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (ext_attr->standard == DRX_STANDARD_ITU_B) {
- /* Parameters for Viterbi Decoder */
- /* qamvd_period = (int)ceil(FEC_BITS_DESIRED/ */
- /* (qamvd_prescale*plen*(qam_constellation+1))) */
- /* vd_bit_cnt = qamvd_period*qamvd_prescale*plen */
- /* result is within 32 bit arithmetic -> */
- /* no need for mult or frac functions */
- /* a(8 bit) * b(8 bit) = 16 bit result => mult32 not needed */
- fec_vd_plen = ext_attr->fec_vd_plen;
- qam_vd_prescale = ext_attr->qam_vd_prescale;
- qam_vd_bit_cnt = qam_vd_prescale * fec_vd_plen; /* temp storage */
- switch (constellation) {
- case DRX_CONSTELLATION_QAM64:
- /* a(16 bit) * b(4 bit) = 20 bit result => mult32 not needed */
- qam_vd_period =
- qam_vd_bit_cnt * (QAM_TOP_CONSTELLATION_QAM64 + 1)
- * (QAM_TOP_CONSTELLATION_QAM64 + 1);
- break;
- case DRX_CONSTELLATION_QAM256:
- /* a(16 bit) * b(5 bit) = 21 bit result => mult32 not needed */
- qam_vd_period =
- qam_vd_bit_cnt * (QAM_TOP_CONSTELLATION_QAM256 + 1)
- * (QAM_TOP_CONSTELLATION_QAM256 + 1);
- break;
- default:
- return -EINVAL;
- }
- if (qam_vd_period == 0) {
- pr_err("error: qam_vd_period is zero!\n");
- return -EIO;
- }
- qam_vd_period = fec_bits_desired / qam_vd_period;
- /* limit to max 16 bit value (I2C register width) if needed */
- if (qam_vd_period > 0xFFFF)
- qam_vd_period = 0xFFFF;
- /* a(16 bit) * b(16 bit) = 32 bit result => mult32 not needed */
- qam_vd_bit_cnt *= qam_vd_period;
- rc = drxj_dap_write_reg16(dev_addr, QAM_VD_MEASUREMENT_PERIOD__A, (u16)qam_vd_period, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_VD_MEASUREMENT_PRESCALE__A, qam_vd_prescale, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ext_attr->qam_vd_period = (u16) qam_vd_period;
- ext_attr->qam_vd_prescale = qam_vd_prescale;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn int set_qam16 ()
- * \brief QAM16 specific setup
- * \param demod instance of demod.
- * \return int.
- */
- static int set_qam16(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- int rc;
- const u8 qam_dq_qual_fun[] = {
- DRXJ_16TO8(2), /* fun0 */
- DRXJ_16TO8(2), /* fun1 */
- DRXJ_16TO8(2), /* fun2 */
- DRXJ_16TO8(2), /* fun3 */
- DRXJ_16TO8(3), /* fun4 */
- DRXJ_16TO8(3), /* fun5 */
- };
- const u8 qam_eq_cma_rad[] = {
- DRXJ_16TO8(13517), /* RAD0 */
- DRXJ_16TO8(13517), /* RAD1 */
- DRXJ_16TO8(13517), /* RAD2 */
- DRXJ_16TO8(13517), /* RAD3 */
- DRXJ_16TO8(13517), /* RAD4 */
- DRXJ_16TO8(13517), /* RAD5 */
- };
- rc = drxdap_fasi_write_block(dev_addr, QAM_DQ_QUAL_FUN0__A, sizeof(qam_dq_qual_fun), ((u8 *)qam_dq_qual_fun), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxdap_fasi_write_block(dev_addr, SCU_RAM_QAM_EQ_CMA_RAD0__A, sizeof(qam_eq_cma_rad), ((u8 *)qam_eq_cma_rad), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RTH__A, 140, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FTH__A, 50, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_PTH__A, 120, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_QTH__A, 230, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_CTH__A, 95, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MTH__A, 105, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RATE_LIM__A, 40, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FREQ_LIM__A, 56, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_COUNT_LIM__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, 220, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, 25, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, 6, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16)(-24), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16)(-65), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16)(-127), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_FINE__A, 15, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_COARSE__A, 40, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_FINE__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_MEDIUM__A, 20, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_COARSE__A, 255, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_FINE__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_MEDIUM__A, 10, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_COARSE__A, 50, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_FINE__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_COARSE__A, 24, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_FINE__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_COARSE__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_FINE__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_MEDIUM__A, 32, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_COARSE__A, 240, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_FINE__A, 5, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 15, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_COARSE__A, 32, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_SL_SIG_POWER__A, 40960, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn int set_qam32 ()
- * \brief QAM32 specific setup
- * \param demod instance of demod.
- * \return int.
- */
- static int set_qam32(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- int rc;
- const u8 qam_dq_qual_fun[] = {
- DRXJ_16TO8(3), /* fun0 */
- DRXJ_16TO8(3), /* fun1 */
- DRXJ_16TO8(3), /* fun2 */
- DRXJ_16TO8(3), /* fun3 */
- DRXJ_16TO8(4), /* fun4 */
- DRXJ_16TO8(4), /* fun5 */
- };
- const u8 qam_eq_cma_rad[] = {
- DRXJ_16TO8(6707), /* RAD0 */
- DRXJ_16TO8(6707), /* RAD1 */
- DRXJ_16TO8(6707), /* RAD2 */
- DRXJ_16TO8(6707), /* RAD3 */
- DRXJ_16TO8(6707), /* RAD4 */
- DRXJ_16TO8(6707), /* RAD5 */
- };
- rc = drxdap_fasi_write_block(dev_addr, QAM_DQ_QUAL_FUN0__A, sizeof(qam_dq_qual_fun), ((u8 *)qam_dq_qual_fun), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxdap_fasi_write_block(dev_addr, SCU_RAM_QAM_EQ_CMA_RAD0__A, sizeof(qam_eq_cma_rad), ((u8 *)qam_eq_cma_rad), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RTH__A, 90, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FTH__A, 50, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_PTH__A, 100, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_QTH__A, 170, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_CTH__A, 80, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MTH__A, 100, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RATE_LIM__A, 40, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FREQ_LIM__A, 56, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_COUNT_LIM__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, 140, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16)(-8), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16)(-16), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16)(-26), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16)(-56), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16)(-86), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_FINE__A, 15, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_COARSE__A, 40, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_FINE__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_MEDIUM__A, 20, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_COARSE__A, 255, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_FINE__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_MEDIUM__A, 10, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_COARSE__A, 50, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_FINE__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_COARSE__A, 24, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_FINE__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_COARSE__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_FINE__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_MEDIUM__A, 32, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_COARSE__A, 176, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_FINE__A, 5, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 15, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_COARSE__A, 8, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_SL_SIG_POWER__A, 20480, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn int set_qam64 ()
- * \brief QAM64 specific setup
- * \param demod instance of demod.
- * \return int.
- */
- static int set_qam64(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- int rc;
- const u8 qam_dq_qual_fun[] = { /* this is hw reset value. no necessary to re-write */
- DRXJ_16TO8(4), /* fun0 */
- DRXJ_16TO8(4), /* fun1 */
- DRXJ_16TO8(4), /* fun2 */
- DRXJ_16TO8(4), /* fun3 */
- DRXJ_16TO8(6), /* fun4 */
- DRXJ_16TO8(6), /* fun5 */
- };
- const u8 qam_eq_cma_rad[] = {
- DRXJ_16TO8(13336), /* RAD0 */
- DRXJ_16TO8(12618), /* RAD1 */
- DRXJ_16TO8(11988), /* RAD2 */
- DRXJ_16TO8(13809), /* RAD3 */
- DRXJ_16TO8(13809), /* RAD4 */
- DRXJ_16TO8(15609), /* RAD5 */
- };
- rc = drxdap_fasi_write_block(dev_addr, QAM_DQ_QUAL_FUN0__A, sizeof(qam_dq_qual_fun), ((u8 *)qam_dq_qual_fun), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxdap_fasi_write_block(dev_addr, SCU_RAM_QAM_EQ_CMA_RAD0__A, sizeof(qam_eq_cma_rad), ((u8 *)qam_eq_cma_rad), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RTH__A, 105, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FTH__A, 60, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_PTH__A, 100, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_QTH__A, 195, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_CTH__A, 80, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MTH__A, 84, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RATE_LIM__A, 40, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FREQ_LIM__A, 32, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_COUNT_LIM__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, 141, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, 7, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16)(-15), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16)(-45), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16)(-80), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_FINE__A, 15, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_COARSE__A, 40, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_FINE__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_MEDIUM__A, 30, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_COARSE__A, 255, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_FINE__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_MEDIUM__A, 15, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_COARSE__A, 80, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_FINE__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_COARSE__A, 24, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_FINE__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_COARSE__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_FINE__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_MEDIUM__A, 48, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_COARSE__A, 160, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_FINE__A, 5, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 15, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_COARSE__A, 32, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_SL_SIG_POWER__A, 43008, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn int set_qam128 ()
- * \brief QAM128 specific setup
- * \param demod: instance of demod.
- * \return int.
- */
- static int set_qam128(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- int rc;
- const u8 qam_dq_qual_fun[] = {
- DRXJ_16TO8(6), /* fun0 */
- DRXJ_16TO8(6), /* fun1 */
- DRXJ_16TO8(6), /* fun2 */
- DRXJ_16TO8(6), /* fun3 */
- DRXJ_16TO8(9), /* fun4 */
- DRXJ_16TO8(9), /* fun5 */
- };
- const u8 qam_eq_cma_rad[] = {
- DRXJ_16TO8(6164), /* RAD0 */
- DRXJ_16TO8(6598), /* RAD1 */
- DRXJ_16TO8(6394), /* RAD2 */
- DRXJ_16TO8(6409), /* RAD3 */
- DRXJ_16TO8(6656), /* RAD4 */
- DRXJ_16TO8(7238), /* RAD5 */
- };
- rc = drxdap_fasi_write_block(dev_addr, QAM_DQ_QUAL_FUN0__A, sizeof(qam_dq_qual_fun), ((u8 *)qam_dq_qual_fun), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxdap_fasi_write_block(dev_addr, SCU_RAM_QAM_EQ_CMA_RAD0__A, sizeof(qam_eq_cma_rad), ((u8 *)qam_eq_cma_rad), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RTH__A, 50, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FTH__A, 60, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_PTH__A, 100, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_QTH__A, 140, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_CTH__A, 80, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MTH__A, 100, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RATE_LIM__A, 40, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FREQ_LIM__A, 32, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_COUNT_LIM__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, 8, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, 65, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, 5, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16)(-1), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16)(-23), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_FINE__A, 15, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_COARSE__A, 40, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_FINE__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_MEDIUM__A, 40, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_COARSE__A, 255, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_FINE__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_MEDIUM__A, 20, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_COARSE__A, 80, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_FINE__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_COARSE__A, 24, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_FINE__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_COARSE__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_FINE__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_MEDIUM__A, 32, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_COARSE__A, 144, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_FINE__A, 5, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 15, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_COARSE__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_SL_SIG_POWER__A, 20992, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn int set_qam256 ()
- * \brief QAM256 specific setup
- * \param demod: instance of demod.
- * \return int.
- */
- static int set_qam256(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- int rc;
- const u8 qam_dq_qual_fun[] = {
- DRXJ_16TO8(8), /* fun0 */
- DRXJ_16TO8(8), /* fun1 */
- DRXJ_16TO8(8), /* fun2 */
- DRXJ_16TO8(8), /* fun3 */
- DRXJ_16TO8(12), /* fun4 */
- DRXJ_16TO8(12), /* fun5 */
- };
- const u8 qam_eq_cma_rad[] = {
- DRXJ_16TO8(12345), /* RAD0 */
- DRXJ_16TO8(12345), /* RAD1 */
- DRXJ_16TO8(13626), /* RAD2 */
- DRXJ_16TO8(12931), /* RAD3 */
- DRXJ_16TO8(14719), /* RAD4 */
- DRXJ_16TO8(15356), /* RAD5 */
- };
- rc = drxdap_fasi_write_block(dev_addr, QAM_DQ_QUAL_FUN0__A, sizeof(qam_dq_qual_fun), ((u8 *)qam_dq_qual_fun), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxdap_fasi_write_block(dev_addr, SCU_RAM_QAM_EQ_CMA_RAD0__A, sizeof(qam_eq_cma_rad), ((u8 *)qam_eq_cma_rad), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RTH__A, 50, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FTH__A, 60, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_PTH__A, 100, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_QTH__A, 150, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_CTH__A, 80, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MTH__A, 110, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RATE_LIM__A, 40, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_FREQ_LIM__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_COUNT_LIM__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, 8, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, 74, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, 18, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, 13, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, 7, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16)(-8), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_FINE__A, 15, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CA_COARSE__A, 40, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_FINE__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_MEDIUM__A, 50, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CP_COARSE__A, 255, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_FINE__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_MEDIUM__A, 25, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CI_COARSE__A, 80, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_FINE__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EP_COARSE__A, 24, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_FINE__A, 12, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_EI_COARSE__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_FINE__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_MEDIUM__A, 48, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF_COARSE__A, 80, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_FINE__A, 5, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 15, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_LC_CF1_COARSE__A, 16, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_SL_SIG_POWER__A, 43520, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- #define QAM_SET_OP_ALL 0x1
- #define QAM_SET_OP_CONSTELLATION 0x2
- #define QAM_SET_OP_SPECTRUM 0X4
- /**
- * \fn int set_qam ()
- * \brief Set QAM demod.
- * \param demod: instance of demod.
- * \param channel: pointer to channel data.
- * \return int.
- */
- static int
- set_qam(struct drx_demod_instance *demod,
- struct drx_channel *channel, s32 tuner_freq_offset, u32 op)
- {
- struct i2c_device_addr *dev_addr = NULL;
- struct drxj_data *ext_attr = NULL;
- struct drx_common_attr *common_attr = NULL;
- int rc;
- u32 adc_frequency = 0;
- u32 iqm_rc_rate = 0;
- u16 cmd_result = 0;
- u16 lc_symbol_freq = 0;
- u16 iqm_rc_stretch = 0;
- u16 set_env_parameters = 0;
- u16 set_param_parameters[2] = { 0 };
- struct drxjscu_cmd cmd_scu = { /* command */ 0,
- /* parameter_len */ 0,
- /* result_len */ 0,
- /* parameter */ NULL,
- /* result */ NULL
- };
- const u8 qam_a_taps[] = {
- DRXJ_16TO8(-1), /* re0 */
- DRXJ_16TO8(1), /* re1 */
- DRXJ_16TO8(1), /* re2 */
- DRXJ_16TO8(-1), /* re3 */
- DRXJ_16TO8(-1), /* re4 */
- DRXJ_16TO8(2), /* re5 */
- DRXJ_16TO8(1), /* re6 */
- DRXJ_16TO8(-2), /* re7 */
- DRXJ_16TO8(0), /* re8 */
- DRXJ_16TO8(3), /* re9 */
- DRXJ_16TO8(-1), /* re10 */
- DRXJ_16TO8(-3), /* re11 */
- DRXJ_16TO8(4), /* re12 */
- DRXJ_16TO8(1), /* re13 */
- DRXJ_16TO8(-8), /* re14 */
- DRXJ_16TO8(4), /* re15 */
- DRXJ_16TO8(13), /* re16 */
- DRXJ_16TO8(-13), /* re17 */
- DRXJ_16TO8(-19), /* re18 */
- DRXJ_16TO8(28), /* re19 */
- DRXJ_16TO8(25), /* re20 */
- DRXJ_16TO8(-53), /* re21 */
- DRXJ_16TO8(-31), /* re22 */
- DRXJ_16TO8(96), /* re23 */
- DRXJ_16TO8(37), /* re24 */
- DRXJ_16TO8(-190), /* re25 */
- DRXJ_16TO8(-40), /* re26 */
- DRXJ_16TO8(619) /* re27 */
- };
- const u8 qam_b64_taps[] = {
- DRXJ_16TO8(0), /* re0 */
- DRXJ_16TO8(-2), /* re1 */
- DRXJ_16TO8(1), /* re2 */
- DRXJ_16TO8(2), /* re3 */
- DRXJ_16TO8(-2), /* re4 */
- DRXJ_16TO8(0), /* re5 */
- DRXJ_16TO8(4), /* re6 */
- DRXJ_16TO8(-2), /* re7 */
- DRXJ_16TO8(-4), /* re8 */
- DRXJ_16TO8(4), /* re9 */
- DRXJ_16TO8(3), /* re10 */
- DRXJ_16TO8(-6), /* re11 */
- DRXJ_16TO8(0), /* re12 */
- DRXJ_16TO8(6), /* re13 */
- DRXJ_16TO8(-5), /* re14 */
- DRXJ_16TO8(-3), /* re15 */
- DRXJ_16TO8(11), /* re16 */
- DRXJ_16TO8(-4), /* re17 */
- DRXJ_16TO8(-19), /* re18 */
- DRXJ_16TO8(19), /* re19 */
- DRXJ_16TO8(28), /* re20 */
- DRXJ_16TO8(-45), /* re21 */
- DRXJ_16TO8(-36), /* re22 */
- DRXJ_16TO8(90), /* re23 */
- DRXJ_16TO8(42), /* re24 */
- DRXJ_16TO8(-185), /* re25 */
- DRXJ_16TO8(-46), /* re26 */
- DRXJ_16TO8(614) /* re27 */
- };
- const u8 qam_b256_taps[] = {
- DRXJ_16TO8(-2), /* re0 */
- DRXJ_16TO8(4), /* re1 */
- DRXJ_16TO8(1), /* re2 */
- DRXJ_16TO8(-4), /* re3 */
- DRXJ_16TO8(0), /* re4 */
- DRXJ_16TO8(4), /* re5 */
- DRXJ_16TO8(-2), /* re6 */
- DRXJ_16TO8(-4), /* re7 */
- DRXJ_16TO8(5), /* re8 */
- DRXJ_16TO8(2), /* re9 */
- DRXJ_16TO8(-8), /* re10 */
- DRXJ_16TO8(2), /* re11 */
- DRXJ_16TO8(11), /* re12 */
- DRXJ_16TO8(-8), /* re13 */
- DRXJ_16TO8(-15), /* re14 */
- DRXJ_16TO8(16), /* re15 */
- DRXJ_16TO8(19), /* re16 */
- DRXJ_16TO8(-27), /* re17 */
- DRXJ_16TO8(-22), /* re18 */
- DRXJ_16TO8(44), /* re19 */
- DRXJ_16TO8(26), /* re20 */
- DRXJ_16TO8(-69), /* re21 */
- DRXJ_16TO8(-28), /* re22 */
- DRXJ_16TO8(110), /* re23 */
- DRXJ_16TO8(31), /* re24 */
- DRXJ_16TO8(-201), /* re25 */
- DRXJ_16TO8(-32), /* re26 */
- DRXJ_16TO8(628) /* re27 */
- };
- const u8 qam_c_taps[] = {
- DRXJ_16TO8(-3), /* re0 */
- DRXJ_16TO8(3), /* re1 */
- DRXJ_16TO8(2), /* re2 */
- DRXJ_16TO8(-4), /* re3 */
- DRXJ_16TO8(0), /* re4 */
- DRXJ_16TO8(4), /* re5 */
- DRXJ_16TO8(-1), /* re6 */
- DRXJ_16TO8(-4), /* re7 */
- DRXJ_16TO8(3), /* re8 */
- DRXJ_16TO8(3), /* re9 */
- DRXJ_16TO8(-5), /* re10 */
- DRXJ_16TO8(0), /* re11 */
- DRXJ_16TO8(9), /* re12 */
- DRXJ_16TO8(-4), /* re13 */
- DRXJ_16TO8(-12), /* re14 */
- DRXJ_16TO8(10), /* re15 */
- DRXJ_16TO8(16), /* re16 */
- DRXJ_16TO8(-21), /* re17 */
- DRXJ_16TO8(-20), /* re18 */
- DRXJ_16TO8(37), /* re19 */
- DRXJ_16TO8(25), /* re20 */
- DRXJ_16TO8(-62), /* re21 */
- DRXJ_16TO8(-28), /* re22 */
- DRXJ_16TO8(105), /* re23 */
- DRXJ_16TO8(31), /* re24 */
- DRXJ_16TO8(-197), /* re25 */
- DRXJ_16TO8(-33), /* re26 */
- DRXJ_16TO8(626) /* re27 */
- };
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- common_attr = (struct drx_common_attr *) demod->my_common_attr;
- if ((op & QAM_SET_OP_ALL) || (op & QAM_SET_OP_CONSTELLATION)) {
- if (ext_attr->standard == DRX_STANDARD_ITU_B) {
- switch (channel->constellation) {
- case DRX_CONSTELLATION_QAM256:
- iqm_rc_rate = 0x00AE3562;
- lc_symbol_freq =
- QAM_LC_SYMBOL_FREQ_FREQ_QAM_B_256;
- channel->symbolrate = 5360537;
- iqm_rc_stretch = IQM_RC_STRETCH_QAM_B_256;
- break;
- case DRX_CONSTELLATION_QAM64:
- iqm_rc_rate = 0x00C05A0E;
- lc_symbol_freq = 409;
- channel->symbolrate = 5056941;
- iqm_rc_stretch = IQM_RC_STRETCH_QAM_B_64;
- break;
- default:
- return -EINVAL;
- }
- } else {
- adc_frequency = (common_attr->sys_clock_freq * 1000) / 3;
- if (channel->symbolrate == 0) {
- pr_err("error: channel symbolrate is zero!\n");
- return -EIO;
- }
- iqm_rc_rate =
- (adc_frequency / channel->symbolrate) * (1 << 21) +
- (frac28
- ((adc_frequency % channel->symbolrate),
- channel->symbolrate) >> 7) - (1 << 23);
- lc_symbol_freq =
- (u16) (frac28
- (channel->symbolrate +
- (adc_frequency >> 13),
- adc_frequency) >> 16);
- if (lc_symbol_freq > 511)
- lc_symbol_freq = 511;
- iqm_rc_stretch = 21;
- }
- if (ext_attr->standard == DRX_STANDARD_ITU_A) {
- set_env_parameters = QAM_TOP_ANNEX_A; /* annex */
- set_param_parameters[0] = channel->constellation; /* constellation */
- set_param_parameters[1] = DRX_INTERLEAVEMODE_I12_J17; /* interleave mode */
- } else if (ext_attr->standard == DRX_STANDARD_ITU_B) {
- set_env_parameters = QAM_TOP_ANNEX_B; /* annex */
- set_param_parameters[0] = channel->constellation; /* constellation */
- set_param_parameters[1] = channel->interleavemode; /* interleave mode */
- } else if (ext_attr->standard == DRX_STANDARD_ITU_C) {
- set_env_parameters = QAM_TOP_ANNEX_C; /* annex */
- set_param_parameters[0] = channel->constellation; /* constellation */
- set_param_parameters[1] = DRX_INTERLEAVEMODE_I12_J17; /* interleave mode */
- } else {
- return -EINVAL;
- }
- }
- if (op & QAM_SET_OP_ALL) {
- /*
- STEP 1: reset demodulator
- resets IQM, QAM and FEC HW blocks
- resets SCU variables
- */
- /* stop all comm_exec */
- rc = drxj_dap_write_reg16(dev_addr, FEC_COMM_EXEC__A, FEC_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_FS_COMM_EXEC__A, IQM_FS_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_FD_COMM_EXEC__A, IQM_FD_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RC_COMM_EXEC__A, IQM_RC_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RT_COMM_EXEC__A, IQM_RT_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_COMM_EXEC__A, IQM_CF_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- cmd_scu.command = SCU_RAM_COMMAND_STANDARD_QAM |
- SCU_RAM_COMMAND_CMD_DEMOD_RESET;
- cmd_scu.parameter_len = 0;
- cmd_scu.result_len = 1;
- cmd_scu.parameter = NULL;
- cmd_scu.result = &cmd_result;
- rc = scu_command(dev_addr, &cmd_scu);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- if ((op & QAM_SET_OP_ALL) || (op & QAM_SET_OP_CONSTELLATION)) {
- /*
- STEP 2: configure demodulator
- -set env
- -set params (resets IQM,QAM,FEC HW; initializes some SCU variables )
- */
- cmd_scu.command = SCU_RAM_COMMAND_STANDARD_QAM |
- SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV;
- cmd_scu.parameter_len = 1;
- cmd_scu.result_len = 1;
- cmd_scu.parameter = &set_env_parameters;
- cmd_scu.result = &cmd_result;
- rc = scu_command(dev_addr, &cmd_scu);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- cmd_scu.command = SCU_RAM_COMMAND_STANDARD_QAM |
- SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM;
- cmd_scu.parameter_len = 2;
- cmd_scu.result_len = 1;
- cmd_scu.parameter = set_param_parameters;
- cmd_scu.result = &cmd_result;
- rc = scu_command(dev_addr, &cmd_scu);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* set symbol rate */
- rc = drxdap_fasi_write_reg32(dev_addr, IQM_RC_RATE_OFS_LO__A, iqm_rc_rate, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ext_attr->iqm_rc_rate_ofs = iqm_rc_rate;
- rc = set_qam_measurement(demod, channel->constellation, channel->symbolrate);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* STEP 3: enable the system in a mode where the ADC provides valid signal
- setup constellation independent registers */
- /* from qam_cmd.py script (qam_driver_b) */
- /* TODO: remove re-writes of HW reset values */
- if ((op & QAM_SET_OP_ALL) || (op & QAM_SET_OP_SPECTRUM)) {
- rc = set_frequency(demod, channel, tuner_freq_offset);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- if ((op & QAM_SET_OP_ALL) || (op & QAM_SET_OP_CONSTELLATION)) {
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_SYMBOL_FREQ__A, lc_symbol_freq, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RC_STRETCH__A, iqm_rc_stretch, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- if (op & QAM_SET_OP_ALL) {
- if (!ext_attr->has_lna) {
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_AMUX__A, 0x02, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_SYMMETRIC__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_MIDTAP__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_OUT_ENA__A, IQM_CF_OUT_ENA_QAM__M, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_WR_RSV_0__A, 0x5f, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* scu temporary shut down agc */
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_SYNC_SEL__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_CLP_LEN__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_CLP_TH__A, 448, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_SNS_LEN__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_PDREF__A, 4, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_STDBY__A, 0x10, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_PGA_GAIN__A, 11, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_POW_MEAS_LEN__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_SCALE_SH__A, IQM_CF_SCALE_SH__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /*! reset default val ! */
- rc = drxj_dap_write_reg16(dev_addr, QAM_SY_TIMEOUT__A, QAM_SY_TIMEOUT__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /*! reset default val ! */
- if (ext_attr->standard == DRX_STANDARD_ITU_B) {
- rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_LWM__A, QAM_SY_SYNC_LWM__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /*! reset default val ! */
- rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_AWM__A, QAM_SY_SYNC_AWM__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /*! reset default val ! */
- rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_HWM__A, QAM_SY_SYNC_HWM__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /*! reset default val ! */
- } else {
- switch (channel->constellation) {
- case DRX_CONSTELLATION_QAM16:
- case DRX_CONSTELLATION_QAM64:
- case DRX_CONSTELLATION_QAM256:
- rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_LWM__A, 0x03, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_AWM__A, 0x04, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_HWM__A, QAM_SY_SYNC_HWM__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /*! reset default val ! */
- break;
- case DRX_CONSTELLATION_QAM32:
- case DRX_CONSTELLATION_QAM128:
- rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_LWM__A, 0x03, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_AWM__A, 0x05, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_SY_SYNC_HWM__A, 0x06, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- default:
- return -EIO;
- } /* switch */
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_MODE__A, QAM_LC_MODE__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /*! reset default val ! */
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_RATE_LIMIT__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_LPF_FACTORP__A, 4, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_LPF_FACTORI__A, 4, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_MODE__A, 7, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB0__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB1__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB2__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB3__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB4__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB5__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB6__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB8__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB9__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB10__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB12__A, 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB15__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB16__A, 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB20__A, 4, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_QUAL_TAB25__A, 4, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_FS_ADJ_SEL__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RC_ADJ_SEL__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_ADJ_SEL__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_POW_MEAS_LEN__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_GPIO__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* No more resets of the IQM, current standard correctly set =>
- now AGCs can be configured. */
- /* turn on IQMAF. It has to be in front of setAgc**() */
- rc = set_iqm_af(demod, true);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = adc_synchronization(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = init_agc(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_agc_if(demod, &(ext_attr->qam_if_agc_cfg), false);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_agc_rf(demod, &(ext_attr->qam_rf_agc_cfg), false);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- {
- /* TODO fix this, store a struct drxj_cfg_afe_gain structure in struct drxj_data instead
- of only the gain */
- struct drxj_cfg_afe_gain qam_pga_cfg = { DRX_STANDARD_ITU_B, 0 };
- qam_pga_cfg.gain = ext_attr->qam_pga_cfg;
- rc = ctrl_set_cfg_afe_gain(demod, &qam_pga_cfg);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- rc = ctrl_set_cfg_pre_saw(demod, &(ext_attr->qam_pre_saw_cfg));
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- if ((op & QAM_SET_OP_ALL) || (op & QAM_SET_OP_CONSTELLATION)) {
- if (ext_attr->standard == DRX_STANDARD_ITU_A) {
- rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_RE0__A, sizeof(qam_a_taps), ((u8 *)qam_a_taps), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_IM0__A, sizeof(qam_a_taps), ((u8 *)qam_a_taps), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- } else if (ext_attr->standard == DRX_STANDARD_ITU_B) {
- switch (channel->constellation) {
- case DRX_CONSTELLATION_QAM64:
- rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_RE0__A, sizeof(qam_b64_taps), ((u8 *)qam_b64_taps), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_IM0__A, sizeof(qam_b64_taps), ((u8 *)qam_b64_taps), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_CONSTELLATION_QAM256:
- rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_RE0__A, sizeof(qam_b256_taps), ((u8 *)qam_b256_taps), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_IM0__A, sizeof(qam_b256_taps), ((u8 *)qam_b256_taps), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- default:
- return -EIO;
- }
- } else if (ext_attr->standard == DRX_STANDARD_ITU_C) {
- rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_RE0__A, sizeof(qam_c_taps), ((u8 *)qam_c_taps), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxdap_fasi_write_block(dev_addr, IQM_CF_TAP_IM0__A, sizeof(qam_c_taps), ((u8 *)qam_c_taps), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* SETP 4: constellation specific setup */
- switch (channel->constellation) {
- case DRX_CONSTELLATION_QAM16:
- rc = set_qam16(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_CONSTELLATION_QAM32:
- rc = set_qam32(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_CONSTELLATION_QAM64:
- rc = set_qam64(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_CONSTELLATION_QAM128:
- rc = set_qam128(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_CONSTELLATION_QAM256:
- rc = set_qam256(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- default:
- return -EIO;
- } /* switch */
- }
- if ((op & QAM_SET_OP_ALL)) {
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_SCALE_SH__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Mpeg output has to be in front of FEC active */
- rc = set_mpegtei_handling(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = bit_reverse_mpeg_output(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_mpeg_start_width(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- {
- /* TODO: move to set_standard after hardware reset value problem is solved */
- /* Configure initial MPEG output */
- struct drx_cfg_mpeg_output cfg_mpeg_output;
- memcpy(&cfg_mpeg_output, &common_attr->mpeg_cfg, sizeof(cfg_mpeg_output));
- cfg_mpeg_output.enable_mpeg_output = true;
- rc = ctrl_set_cfg_mpeg_output(demod, &cfg_mpeg_output);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- }
- if ((op & QAM_SET_OP_ALL) || (op & QAM_SET_OP_CONSTELLATION)) {
- /* STEP 5: start QAM demodulator (starts FEC, QAM and IQM HW) */
- cmd_scu.command = SCU_RAM_COMMAND_STANDARD_QAM |
- SCU_RAM_COMMAND_CMD_DEMOD_START;
- cmd_scu.parameter_len = 0;
- cmd_scu.result_len = 1;
- cmd_scu.parameter = NULL;
- cmd_scu.result = &cmd_result;
- rc = scu_command(dev_addr, &cmd_scu);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_COMM_EXEC__A, IQM_COMM_EXEC_ACTIVE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_COMM_EXEC__A, QAM_COMM_EXEC_ACTIVE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- static int ctrl_get_qam_sig_quality(struct drx_demod_instance *demod);
- static int qam_flip_spec(struct drx_demod_instance *demod, struct drx_channel *channel)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- struct drxj_data *ext_attr = demod->my_ext_attr;
- int rc;
- u32 iqm_fs_rate_ofs = 0;
- u32 iqm_fs_rate_lo = 0;
- u16 qam_ctl_ena = 0;
- u16 data = 0;
- u16 equ_mode = 0;
- u16 fsm_state = 0;
- int i = 0;
- int ofsofs = 0;
- /* Silence the controlling of lc, equ, and the acquisition state machine */
- rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_QAM_CTL_ENA__A, &qam_ctl_ena, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_CTL_ENA__A, qam_ctl_ena & ~(SCU_RAM_QAM_CTL_ENA_ACQ__M | SCU_RAM_QAM_CTL_ENA_EQU__M | SCU_RAM_QAM_CTL_ENA_LC__M), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* freeze the frequency control loop */
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_CF__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_CF1__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_atomic_read_reg32(dev_addr, IQM_FS_RATE_OFS_LO__A, &iqm_fs_rate_ofs, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_atomic_read_reg32(dev_addr, IQM_FS_RATE_LO__A, &iqm_fs_rate_lo, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ofsofs = iqm_fs_rate_lo - iqm_fs_rate_ofs;
- iqm_fs_rate_ofs = ~iqm_fs_rate_ofs + 1;
- iqm_fs_rate_ofs -= 2 * ofsofs;
- /* freeze dq/fq updating */
- rc = drxj_dap_read_reg16(dev_addr, QAM_DQ_MODE__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- data = (data & 0xfff9);
- rc = drxj_dap_write_reg16(dev_addr, QAM_DQ_MODE__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_FQ_MODE__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* lc_cp / _ci / _ca */
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_CI__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_LC_EP__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_FQ_LA_FACTOR__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* flip the spec */
- rc = drxdap_fasi_write_reg32(dev_addr, IQM_FS_RATE_OFS_LO__A, iqm_fs_rate_ofs, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ext_attr->iqm_fs_rate_ofs = iqm_fs_rate_ofs;
- ext_attr->pos_image = (ext_attr->pos_image) ? false : true;
- /* freeze dq/fq updating */
- rc = drxj_dap_read_reg16(dev_addr, QAM_DQ_MODE__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- equ_mode = data;
- data = (data & 0xfff9);
- rc = drxj_dap_write_reg16(dev_addr, QAM_DQ_MODE__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_FQ_MODE__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- for (i = 0; i < 28; i++) {
- rc = drxj_dap_read_reg16(dev_addr, QAM_DQ_TAP_IM_EL0__A + (2 * i), &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_DQ_TAP_IM_EL0__A + (2 * i), -data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- for (i = 0; i < 24; i++) {
- rc = drxj_dap_read_reg16(dev_addr, QAM_FQ_TAP_IM_EL0__A + (2 * i), &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_FQ_TAP_IM_EL0__A + (2 * i), -data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- data = equ_mode;
- rc = drxj_dap_write_reg16(dev_addr, QAM_DQ_MODE__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, QAM_FQ_MODE__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_FSM_STATE_TGT__A, 4, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- i = 0;
- while ((fsm_state != 4) && (i++ < 100)) {
- rc = drxj_dap_read_reg16(dev_addr, SCU_RAM_QAM_FSM_STATE__A, &fsm_state, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_QAM_CTL_ENA__A, (qam_ctl_ena | 0x0016), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- #define NO_LOCK 0x0
- #define DEMOD_LOCKED 0x1
- #define SYNC_FLIPPED 0x2
- #define SPEC_MIRRORED 0x4
- /**
- * \fn int qam64auto ()
- * \brief auto do sync pattern switching and mirroring.
- * \param demod: instance of demod.
- * \param channel: pointer to channel data.
- * \param tuner_freq_offset: tuner frequency offset.
- * \param lock_status: pointer to lock status.
- * \return int.
- */
- static int
- qam64auto(struct drx_demod_instance *demod,
- struct drx_channel *channel,
- s32 tuner_freq_offset, enum drx_lock_status *lock_status)
- {
- struct drxj_data *ext_attr = demod->my_ext_attr;
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- struct drx39xxj_state *state = dev_addr->user_data;
- struct dtv_frontend_properties *p = &state->frontend.dtv_property_cache;
- int rc;
- u32 lck_state = NO_LOCK;
- u32 start_time = 0;
- u32 d_locked_time = 0;
- u32 timeout_ofs = 0;
- u16 data = 0;
- /* external attributes for storing acquired channel constellation */
- *lock_status = DRX_NOT_LOCKED;
- start_time = jiffies_to_msecs(jiffies);
- lck_state = NO_LOCK;
- do {
- rc = ctrl_lock_status(demod, lock_status);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- switch (lck_state) {
- case NO_LOCK:
- if (*lock_status == DRXJ_DEMOD_LOCK) {
- rc = ctrl_get_qam_sig_quality(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (p->cnr.stat[0].svalue > 20800) {
- lck_state = DEMOD_LOCKED;
- /* some delay to see if fec_lock possible TODO find the right value */
- timeout_ofs += DRXJ_QAM_DEMOD_LOCK_EXT_WAITTIME; /* see something, waiting longer */
- d_locked_time = jiffies_to_msecs(jiffies);
- }
- }
- break;
- case DEMOD_LOCKED:
- if ((*lock_status == DRXJ_DEMOD_LOCK) && /* still demod_lock in 150ms */
- ((jiffies_to_msecs(jiffies) - d_locked_time) >
- DRXJ_QAM_FEC_LOCK_WAITTIME)) {
- rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, QAM_SY_TIMEOUT__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, QAM_SY_TIMEOUT__A, data | 0x1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- lck_state = SYNC_FLIPPED;
- msleep(10);
- }
- break;
- case SYNC_FLIPPED:
- if (*lock_status == DRXJ_DEMOD_LOCK) {
- if (channel->mirror == DRX_MIRROR_AUTO) {
- /* flip sync pattern back */
- rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, QAM_SY_TIMEOUT__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, QAM_SY_TIMEOUT__A, data & 0xFFFE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* flip spectrum */
- ext_attr->mirror = DRX_MIRROR_YES;
- rc = qam_flip_spec(demod, channel);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- lck_state = SPEC_MIRRORED;
- /* reset timer TODO: still need 500ms? */
- start_time = d_locked_time =
- jiffies_to_msecs(jiffies);
- timeout_ofs = 0;
- } else { /* no need to wait lock */
- start_time =
- jiffies_to_msecs(jiffies) -
- DRXJ_QAM_MAX_WAITTIME - timeout_ofs;
- }
- }
- break;
- case SPEC_MIRRORED:
- if ((*lock_status == DRXJ_DEMOD_LOCK) && /* still demod_lock in 150ms */
- ((jiffies_to_msecs(jiffies) - d_locked_time) >
- DRXJ_QAM_FEC_LOCK_WAITTIME)) {
- rc = ctrl_get_qam_sig_quality(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (p->cnr.stat[0].svalue > 20800) {
- rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, QAM_SY_TIMEOUT__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr, QAM_SY_TIMEOUT__A, data | 0x1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* no need to wait lock */
- start_time =
- jiffies_to_msecs(jiffies) -
- DRXJ_QAM_MAX_WAITTIME - timeout_ofs;
- }
- }
- break;
- default:
- break;
- }
- msleep(10);
- } while
- ((*lock_status != DRX_LOCKED) &&
- (*lock_status != DRX_NEVER_LOCK) &&
- ((jiffies_to_msecs(jiffies) - start_time) <
- (DRXJ_QAM_MAX_WAITTIME + timeout_ofs))
- );
- /* Returning control to apllication ... */
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int qam256auto ()
- * \brief auto do sync pattern switching and mirroring.
- * \param demod: instance of demod.
- * \param channel: pointer to channel data.
- * \param tuner_freq_offset: tuner frequency offset.
- * \param lock_status: pointer to lock status.
- * \return int.
- */
- static int
- qam256auto(struct drx_demod_instance *demod,
- struct drx_channel *channel,
- s32 tuner_freq_offset, enum drx_lock_status *lock_status)
- {
- struct drxj_data *ext_attr = demod->my_ext_attr;
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- struct drx39xxj_state *state = dev_addr->user_data;
- struct dtv_frontend_properties *p = &state->frontend.dtv_property_cache;
- int rc;
- u32 lck_state = NO_LOCK;
- u32 start_time = 0;
- u32 d_locked_time = 0;
- u32 timeout_ofs = DRXJ_QAM_DEMOD_LOCK_EXT_WAITTIME;
- /* external attributes for storing acquired channel constellation */
- *lock_status = DRX_NOT_LOCKED;
- start_time = jiffies_to_msecs(jiffies);
- lck_state = NO_LOCK;
- do {
- rc = ctrl_lock_status(demod, lock_status);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- switch (lck_state) {
- case NO_LOCK:
- if (*lock_status == DRXJ_DEMOD_LOCK) {
- rc = ctrl_get_qam_sig_quality(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (p->cnr.stat[0].svalue > 26800) {
- lck_state = DEMOD_LOCKED;
- timeout_ofs += DRXJ_QAM_DEMOD_LOCK_EXT_WAITTIME; /* see something, wait longer */
- d_locked_time = jiffies_to_msecs(jiffies);
- }
- }
- break;
- case DEMOD_LOCKED:
- if (*lock_status == DRXJ_DEMOD_LOCK) {
- if ((channel->mirror == DRX_MIRROR_AUTO) &&
- ((jiffies_to_msecs(jiffies) - d_locked_time) >
- DRXJ_QAM_FEC_LOCK_WAITTIME)) {
- ext_attr->mirror = DRX_MIRROR_YES;
- rc = qam_flip_spec(demod, channel);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- lck_state = SPEC_MIRRORED;
- /* reset timer TODO: still need 300ms? */
- start_time = jiffies_to_msecs(jiffies);
- timeout_ofs = -DRXJ_QAM_MAX_WAITTIME / 2;
- }
- }
- break;
- case SPEC_MIRRORED:
- break;
- default:
- break;
- }
- msleep(10);
- } while
- ((*lock_status < DRX_LOCKED) &&
- (*lock_status != DRX_NEVER_LOCK) &&
- ((jiffies_to_msecs(jiffies) - start_time) <
- (DRXJ_QAM_MAX_WAITTIME + timeout_ofs)));
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int set_qam_channel ()
- * \brief Set QAM channel according to the requested constellation.
- * \param demod: instance of demod.
- * \param channel: pointer to channel data.
- * \return int.
- */
- static int
- set_qam_channel(struct drx_demod_instance *demod,
- struct drx_channel *channel, s32 tuner_freq_offset)
- {
- struct drxj_data *ext_attr = NULL;
- int rc;
- enum drx_lock_status lock_status = DRX_NOT_LOCKED;
- bool auto_flag = false;
- /* external attributes for storing acquired channel constellation */
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- /* set QAM channel constellation */
- switch (channel->constellation) {
- case DRX_CONSTELLATION_QAM16:
- case DRX_CONSTELLATION_QAM32:
- case DRX_CONSTELLATION_QAM128:
- return -EINVAL;
- case DRX_CONSTELLATION_QAM64:
- case DRX_CONSTELLATION_QAM256:
- if (ext_attr->standard != DRX_STANDARD_ITU_B)
- return -EINVAL;
- ext_attr->constellation = channel->constellation;
- if (channel->mirror == DRX_MIRROR_AUTO)
- ext_attr->mirror = DRX_MIRROR_NO;
- else
- ext_attr->mirror = channel->mirror;
- rc = set_qam(demod, channel, tuner_freq_offset, QAM_SET_OP_ALL);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (channel->constellation == DRX_CONSTELLATION_QAM64)
- rc = qam64auto(demod, channel, tuner_freq_offset,
- &lock_status);
- else
- rc = qam256auto(demod, channel, tuner_freq_offset,
- &lock_status);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_CONSTELLATION_AUTO: /* for channel scan */
- if (ext_attr->standard == DRX_STANDARD_ITU_B) {
- u16 qam_ctl_ena = 0;
- auto_flag = true;
- /* try to lock default QAM constellation: QAM256 */
- channel->constellation = DRX_CONSTELLATION_QAM256;
- ext_attr->constellation = DRX_CONSTELLATION_QAM256;
- if (channel->mirror == DRX_MIRROR_AUTO)
- ext_attr->mirror = DRX_MIRROR_NO;
- else
- ext_attr->mirror = channel->mirror;
- rc = set_qam(demod, channel, tuner_freq_offset,
- QAM_SET_OP_ALL);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = qam256auto(demod, channel, tuner_freq_offset,
- &lock_status);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (lock_status >= DRX_LOCKED) {
- channel->constellation = DRX_CONSTELLATION_AUTO;
- break;
- }
- /* QAM254 not locked. Try QAM64 constellation */
- channel->constellation = DRX_CONSTELLATION_QAM64;
- ext_attr->constellation = DRX_CONSTELLATION_QAM64;
- if (channel->mirror == DRX_MIRROR_AUTO)
- ext_attr->mirror = DRX_MIRROR_NO;
- else
- ext_attr->mirror = channel->mirror;
- rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr,
- SCU_RAM_QAM_CTL_ENA__A,
- &qam_ctl_ena, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr,
- SCU_RAM_QAM_CTL_ENA__A,
- qam_ctl_ena & ~SCU_RAM_QAM_CTL_ENA_ACQ__M, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr,
- SCU_RAM_QAM_FSM_STATE_TGT__A,
- 0x2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* force to rate hunting */
- rc = set_qam(demod, channel, tuner_freq_offset,
- QAM_SET_OP_CONSTELLATION);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr,
- SCU_RAM_QAM_CTL_ENA__A,
- qam_ctl_ena, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = qam64auto(demod, channel, tuner_freq_offset,
- &lock_status);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- channel->constellation = DRX_CONSTELLATION_AUTO;
- } else if (ext_attr->standard == DRX_STANDARD_ITU_C) {
- u16 qam_ctl_ena = 0;
- channel->constellation = DRX_CONSTELLATION_QAM64;
- ext_attr->constellation = DRX_CONSTELLATION_QAM64;
- auto_flag = true;
- if (channel->mirror == DRX_MIRROR_AUTO)
- ext_attr->mirror = DRX_MIRROR_NO;
- else
- ext_attr->mirror = channel->mirror;
- rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr,
- SCU_RAM_QAM_CTL_ENA__A,
- &qam_ctl_ena, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr,
- SCU_RAM_QAM_CTL_ENA__A,
- qam_ctl_ena & ~SCU_RAM_QAM_CTL_ENA_ACQ__M, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr,
- SCU_RAM_QAM_FSM_STATE_TGT__A,
- 0x2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* force to rate hunting */
- rc = set_qam(demod, channel, tuner_freq_offset,
- QAM_SET_OP_CONSTELLATION);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(demod->my_i2c_dev_addr,
- SCU_RAM_QAM_CTL_ENA__A,
- qam_ctl_ena, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = qam64auto(demod, channel, tuner_freq_offset,
- &lock_status);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- channel->constellation = DRX_CONSTELLATION_AUTO;
- } else {
- return -EINVAL;
- }
- break;
- default:
- return -EINVAL;
- }
- return 0;
- rw_error:
- /* restore starting value */
- if (auto_flag)
- channel->constellation = DRX_CONSTELLATION_AUTO;
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn static short get_qamrs_err_count(struct i2c_device_addr *dev_addr)
- * \brief Get RS error count in QAM mode (used for post RS BER calculation)
- * \return Error code
- *
- * precondition: measurement period & measurement prescale must be set
- *
- */
- static int
- get_qamrs_err_count(struct i2c_device_addr *dev_addr,
- struct drxjrs_errors *rs_errors)
- {
- int rc;
- u16 nr_bit_errors = 0,
- nr_symbol_errors = 0,
- nr_packet_errors = 0, nr_failures = 0, nr_snc_par_fail_count = 0;
- /* check arguments */
- if (dev_addr == NULL)
- return -EINVAL;
- /* all reported errors are received in the */
- /* most recently finished measurment period */
- /* no of pre RS bit errors */
- rc = drxj_dap_read_reg16(dev_addr, FEC_RS_NR_BIT_ERRORS__A, &nr_bit_errors, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* no of symbol errors */
- rc = drxj_dap_read_reg16(dev_addr, FEC_RS_NR_SYMBOL_ERRORS__A, &nr_symbol_errors, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* no of packet errors */
- rc = drxj_dap_read_reg16(dev_addr, FEC_RS_NR_PACKET_ERRORS__A, &nr_packet_errors, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* no of failures to decode */
- rc = drxj_dap_read_reg16(dev_addr, FEC_RS_NR_FAILURES__A, &nr_failures, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* no of post RS bit erros */
- rc = drxj_dap_read_reg16(dev_addr, FEC_OC_SNC_FAIL_COUNT__A, &nr_snc_par_fail_count, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* TODO: NOTE */
- /* These register values are fetched in non-atomic fashion */
- /* It is possible that the read values contain unrelated information */
- rs_errors->nr_bit_errors = nr_bit_errors & FEC_RS_NR_BIT_ERRORS__M;
- rs_errors->nr_symbol_errors = nr_symbol_errors & FEC_RS_NR_SYMBOL_ERRORS__M;
- rs_errors->nr_packet_errors = nr_packet_errors & FEC_RS_NR_PACKET_ERRORS__M;
- rs_errors->nr_failures = nr_failures & FEC_RS_NR_FAILURES__M;
- rs_errors->nr_snc_par_fail_count =
- nr_snc_par_fail_count & FEC_OC_SNC_FAIL_COUNT__M;
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn int get_sig_strength()
- * \brief Retrieve signal strength for VSB and QAM.
- * \param demod Pointer to demod instance
- * \param u16-t Pointer to signal strength data; range 0, .. , 100.
- * \return int.
- * \retval 0 sig_strength contains valid data.
- * \retval -EINVAL sig_strength is NULL.
- * \retval -EIO Erroneous data, sig_strength contains invalid data.
- */
- #define DRXJ_AGC_TOP 0x2800
- #define DRXJ_AGC_SNS 0x1600
- #define DRXJ_RFAGC_MAX 0x3fff
- #define DRXJ_RFAGC_MIN 0x800
- static int get_sig_strength(struct drx_demod_instance *demod, u16 *sig_strength)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- int rc;
- u16 rf_gain = 0;
- u16 if_gain = 0;
- u16 if_agc_sns = 0;
- u16 if_agc_top = 0;
- u16 rf_agc_max = 0;
- u16 rf_agc_min = 0;
- rc = drxj_dap_read_reg16(dev_addr, IQM_AF_AGC_IF__A, &if_gain, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if_gain &= IQM_AF_AGC_IF__M;
- rc = drxj_dap_read_reg16(dev_addr, IQM_AF_AGC_RF__A, &rf_gain, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rf_gain &= IQM_AF_AGC_RF__M;
- if_agc_sns = DRXJ_AGC_SNS;
- if_agc_top = DRXJ_AGC_TOP;
- rf_agc_max = DRXJ_RFAGC_MAX;
- rf_agc_min = DRXJ_RFAGC_MIN;
- if (if_gain > if_agc_top) {
- if (rf_gain > rf_agc_max)
- *sig_strength = 100;
- else if (rf_gain > rf_agc_min) {
- if (rf_agc_max == rf_agc_min) {
- pr_err("error: rf_agc_max == rf_agc_min\n");
- return -EIO;
- }
- *sig_strength =
- 75 + 25 * (rf_gain - rf_agc_min) / (rf_agc_max -
- rf_agc_min);
- } else
- *sig_strength = 75;
- } else if (if_gain > if_agc_sns) {
- if (if_agc_top == if_agc_sns) {
- pr_err("error: if_agc_top == if_agc_sns\n");
- return -EIO;
- }
- *sig_strength =
- 20 + 55 * (if_gain - if_agc_sns) / (if_agc_top - if_agc_sns);
- } else {
- if (!if_agc_sns) {
- pr_err("error: if_agc_sns is zero!\n");
- return -EIO;
- }
- *sig_strength = (20 * if_gain / if_agc_sns);
- }
- if (*sig_strength <= 7)
- *sig_strength = 0;
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int ctrl_get_qam_sig_quality()
- * \brief Retrieve QAM signal quality from device.
- * \param devmod Pointer to demodulator instance.
- * \param sig_quality Pointer to signal quality data.
- * \return int.
- * \retval 0 sig_quality contains valid data.
- * \retval -EINVAL sig_quality is NULL.
- * \retval -EIO Erroneous data, sig_quality contains invalid data.
- * Pre-condition: Device must be started and in lock.
- */
- static int
- ctrl_get_qam_sig_quality(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- struct drxj_data *ext_attr = demod->my_ext_attr;
- struct drx39xxj_state *state = dev_addr->user_data;
- struct dtv_frontend_properties *p = &state->frontend.dtv_property_cache;
- struct drxjrs_errors measuredrs_errors = { 0, 0, 0, 0, 0 };
- enum drx_modulation constellation = ext_attr->constellation;
- int rc;
- u32 pre_bit_err_rs = 0; /* pre RedSolomon Bit Error Rate */
- u32 post_bit_err_rs = 0; /* post RedSolomon Bit Error Rate */
- u32 pkt_errs = 0; /* no of packet errors in RS */
- u16 qam_sl_err_power = 0; /* accumulated error between raw and sliced symbols */
- u16 qsym_err_vd = 0; /* quadrature symbol errors in QAM_VD */
- u16 fec_oc_period = 0; /* SNC sync failure measurement period */
- u16 fec_rs_prescale = 0; /* ReedSolomon Measurement Prescale */
- u16 fec_rs_period = 0; /* Value for corresponding I2C register */
- /* calculation constants */
- u32 rs_bit_cnt = 0; /* RedSolomon Bit Count */
- u32 qam_sl_sig_power = 0; /* used for MER, depends of QAM constellation */
- /* intermediate results */
- u32 e = 0; /* exponent value used for QAM BER/SER */
- u32 m = 0; /* mantisa value used for QAM BER/SER */
- u32 ber_cnt = 0; /* BER count */
- /* signal quality info */
- u32 qam_sl_mer = 0; /* QAM MER */
- u32 qam_pre_rs_ber = 0; /* Pre RedSolomon BER */
- u32 qam_post_rs_ber = 0; /* Post RedSolomon BER */
- u32 qam_vd_ser = 0; /* ViterbiDecoder SER */
- u16 qam_vd_prescale = 0; /* Viterbi Measurement Prescale */
- u16 qam_vd_period = 0; /* Viterbi Measurement period */
- u32 vd_bit_cnt = 0; /* ViterbiDecoder Bit Count */
- p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- /* read the physical registers */
- /* Get the RS error data */
- rc = get_qamrs_err_count(dev_addr, &measuredrs_errors);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* get the register value needed for MER */
- rc = drxj_dap_read_reg16(dev_addr, QAM_SL_ERR_POWER__A, &qam_sl_err_power, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* get the register value needed for post RS BER */
- rc = drxj_dap_read_reg16(dev_addr, FEC_OC_SNC_FAIL_PERIOD__A, &fec_oc_period, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* get constants needed for signal quality calculation */
- fec_rs_period = ext_attr->fec_rs_period;
- fec_rs_prescale = ext_attr->fec_rs_prescale;
- rs_bit_cnt = fec_rs_period * fec_rs_prescale * ext_attr->fec_rs_plen;
- qam_vd_period = ext_attr->qam_vd_period;
- qam_vd_prescale = ext_attr->qam_vd_prescale;
- vd_bit_cnt = qam_vd_period * qam_vd_prescale * ext_attr->fec_vd_plen;
- /* DRXJ_QAM_SL_SIG_POWER_QAMxxx * 4 */
- switch (constellation) {
- case DRX_CONSTELLATION_QAM16:
- qam_sl_sig_power = DRXJ_QAM_SL_SIG_POWER_QAM16 << 2;
- break;
- case DRX_CONSTELLATION_QAM32:
- qam_sl_sig_power = DRXJ_QAM_SL_SIG_POWER_QAM32 << 2;
- break;
- case DRX_CONSTELLATION_QAM64:
- qam_sl_sig_power = DRXJ_QAM_SL_SIG_POWER_QAM64 << 2;
- break;
- case DRX_CONSTELLATION_QAM128:
- qam_sl_sig_power = DRXJ_QAM_SL_SIG_POWER_QAM128 << 2;
- break;
- case DRX_CONSTELLATION_QAM256:
- qam_sl_sig_power = DRXJ_QAM_SL_SIG_POWER_QAM256 << 2;
- break;
- default:
- return -EIO;
- }
- /* ------------------------------ */
- /* MER Calculation */
- /* ------------------------------ */
- /* MER is good if it is above 27.5 for QAM256 or 21.5 for QAM64 */
- /* 10.0*log10(qam_sl_sig_power * 4.0 / qam_sl_err_power); */
- if (qam_sl_err_power == 0)
- qam_sl_mer = 0;
- else
- qam_sl_mer = log1_times100(qam_sl_sig_power) - log1_times100((u32)qam_sl_err_power);
- /* ----------------------------------------- */
- /* Pre Viterbi Symbol Error Rate Calculation */
- /* ----------------------------------------- */
- /* pre viterbi SER is good if it is below 0.025 */
- /* get the register value */
- /* no of quadrature symbol errors */
- rc = drxj_dap_read_reg16(dev_addr, QAM_VD_NR_QSYM_ERRORS__A, &qsym_err_vd, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Extract the Exponent and the Mantisa */
- /* of number of quadrature symbol errors */
- e = (qsym_err_vd & QAM_VD_NR_QSYM_ERRORS_EXP__M) >>
- QAM_VD_NR_QSYM_ERRORS_EXP__B;
- m = (qsym_err_vd & QAM_VD_NR_SYMBOL_ERRORS_FIXED_MANT__M) >>
- QAM_VD_NR_SYMBOL_ERRORS_FIXED_MANT__B;
- if ((m << e) >> 3 > 549752)
- qam_vd_ser = 500000 * vd_bit_cnt * ((e > 2) ? 1 : 8) / 8;
- else
- qam_vd_ser = m << ((e > 2) ? (e - 3) : e);
- /* --------------------------------------- */
- /* pre and post RedSolomon BER Calculation */
- /* --------------------------------------- */
- /* pre RS BER is good if it is below 3.5e-4 */
- /* get the register values */
- pre_bit_err_rs = (u32) measuredrs_errors.nr_bit_errors;
- pkt_errs = post_bit_err_rs = (u32) measuredrs_errors.nr_snc_par_fail_count;
- /* Extract the Exponent and the Mantisa of the */
- /* pre Reed-Solomon bit error count */
- e = (pre_bit_err_rs & FEC_RS_NR_BIT_ERRORS_EXP__M) >>
- FEC_RS_NR_BIT_ERRORS_EXP__B;
- m = (pre_bit_err_rs & FEC_RS_NR_BIT_ERRORS_FIXED_MANT__M) >>
- FEC_RS_NR_BIT_ERRORS_FIXED_MANT__B;
- ber_cnt = m << e;
- /*qam_pre_rs_ber = frac_times1e6( ber_cnt, rs_bit_cnt ); */
- if (m > (rs_bit_cnt >> (e + 1)) || (rs_bit_cnt >> e) == 0)
- qam_pre_rs_ber = 500000 * rs_bit_cnt >> e;
- else
- qam_pre_rs_ber = ber_cnt;
- /* post RS BER = 1000000* (11.17 * FEC_OC_SNC_FAIL_COUNT__A) / */
- /* (1504.0 * FEC_OC_SNC_FAIL_PERIOD__A) */
- /*
- => c = (1000000*100*11.17)/1504 =
- post RS BER = (( c* FEC_OC_SNC_FAIL_COUNT__A) /
- (100 * FEC_OC_SNC_FAIL_PERIOD__A)
- *100 and /100 is for more precision.
- => (20 bits * 12 bits) /(16 bits * 7 bits) => safe in 32 bits computation
- Precision errors still possible.
- */
- e = post_bit_err_rs * 742686;
- m = fec_oc_period * 100;
- if (fec_oc_period == 0)
- qam_post_rs_ber = 0xFFFFFFFF;
- else
- qam_post_rs_ber = e / m;
- /* fill signal quality data structure */
- p->pre_bit_count.stat[0].scale = FE_SCALE_COUNTER;
- p->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
- p->pre_bit_error.stat[0].scale = FE_SCALE_COUNTER;
- p->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
- p->block_error.stat[0].scale = FE_SCALE_COUNTER;
- p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
- p->cnr.stat[0].svalue = ((u16) qam_sl_mer) * 100;
- if (ext_attr->standard == DRX_STANDARD_ITU_B) {
- p->pre_bit_error.stat[0].uvalue += qam_vd_ser;
- p->pre_bit_count.stat[0].uvalue += vd_bit_cnt * ((e > 2) ? 1 : 8) / 8;
- } else {
- p->pre_bit_error.stat[0].uvalue += qam_pre_rs_ber;
- p->pre_bit_count.stat[0].uvalue += rs_bit_cnt >> e;
- }
- p->post_bit_error.stat[0].uvalue += qam_post_rs_ber;
- p->post_bit_count.stat[0].uvalue += rs_bit_cnt >> e;
- p->block_error.stat[0].uvalue += pkt_errs;
- #ifdef DRXJ_SIGNAL_ACCUM_ERR
- rc = get_acc_pkt_err(demod, &sig_quality->packet_error);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- #endif
- return 0;
- rw_error:
- p->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- return rc;
- }
- #endif /* #ifndef DRXJ_VSB_ONLY */
- /*============================================================================*/
- /*== END QAM DATAPATH FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /*============================================================================*/
- /*== ATV DATAPATH FUNCTIONS ==*/
- /*============================================================================*/
- /*============================================================================*/
- /*
- Implementation notes.
- NTSC/FM AGCs
- Four AGCs are used for NTSC:
- (1) RF (used to attenuate the input signal in case of to much power)
- (2) IF (used to attenuate the input signal in case of to much power)
- (3) Video AGC (used to amplify the output signal in case input to low)
- (4) SIF AGC (used to amplify the output signal in case input to low)
- Video AGC is coupled to RF and IF. SIF AGC is not coupled. It is assumed
- that the coupling between Video AGC and the RF and IF AGCs also works in
- favor of the SIF AGC.
- Three AGCs are used for FM:
- (1) RF (used to attenuate the input signal in case of to much power)
- (2) IF (used to attenuate the input signal in case of to much power)
- (3) SIF AGC (used to amplify the output signal in case input to low)
- The SIF AGC is now coupled to the RF/IF AGCs.
- The SIF AGC is needed for both SIF ouput and the internal SIF signal to
- the AUD block.
- RF and IF AGCs DACs are part of AFE, Video and SIF AGC DACs are part of
- the ATV block. The AGC control algorithms are all implemented in
- microcode.
- ATV SETTINGS
- (Shadow settings will not be used for now, they will be implemented
- later on because of the schedule)
- Several HW/SCU "settings" can be used for ATV. The standard selection
- will reset most of these settings. To avoid that the end user apllication
- has to perform these settings each time the ATV or FM standards is
- selected the driver will shadow these settings. This enables the end user
- to perform the settings only once after a drx_open(). The driver must
- write the shadow settings to HW/SCU incase:
- ( setstandard FM/ATV) ||
- ( settings have changed && FM/ATV standard is active)
- The shadow settings will be stored in the device specific data container.
- A set of flags will be defined to flag changes in shadow settings.
- A routine will be implemented to write all changed shadow settings to
- HW/SCU.
- The "settings" will consist of: AGC settings, filter settings etc.
- Disadvantage of use of shadow settings:
- Direct changes in HW/SCU registers will not be reflected in the
- shadow settings and these changes will be overwritten during a next
- update. This can happen during evaluation. This will not be a problem
- for normal customer usage.
- */
- /* -------------------------------------------------------------------------- */
- /**
- * \fn int power_down_atv ()
- * \brief Power down ATV.
- * \param demod instance of demodulator
- * \param standard either NTSC or FM (sub strandard for ATV )
- * \return int.
- *
- * Stops and thus resets ATV and IQM block
- * SIF and CVBS ADC are powered down
- * Calls audio power down
- */
- static int
- power_down_atv(struct drx_demod_instance *demod, enum drx_standard standard, bool primary)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- struct drxjscu_cmd cmd_scu = { /* command */ 0,
- /* parameter_len */ 0,
- /* result_len */ 0,
- /* *parameter */ NULL,
- /* *result */ NULL
- };
- int rc;
- u16 cmd_result = 0;
- /* ATV NTSC */
- /* Stop ATV SCU (will reset ATV and IQM hardware */
- cmd_scu.command = SCU_RAM_COMMAND_STANDARD_ATV |
- SCU_RAM_COMMAND_CMD_DEMOD_STOP;
- cmd_scu.parameter_len = 0;
- cmd_scu.result_len = 1;
- cmd_scu.parameter = NULL;
- cmd_scu.result = &cmd_result;
- rc = scu_command(dev_addr, &cmd_scu);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Disable ATV outputs (ATV reset enables CVBS, undo this) */
- rc = drxj_dap_write_reg16(dev_addr, ATV_TOP_STDBY__A, (ATV_TOP_STDBY_SIF_STDBY_STANDBY & (~ATV_TOP_STDBY_CVBS_STDBY_A2_ACTIVE)), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, ATV_COMM_EXEC__A, ATV_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (primary) {
- rc = drxj_dap_write_reg16(dev_addr, IQM_COMM_EXEC__A, IQM_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_iqm_af(demod, false);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- } else {
- rc = drxj_dap_write_reg16(dev_addr, IQM_FS_COMM_EXEC__A, IQM_FS_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_FD_COMM_EXEC__A, IQM_FD_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RC_COMM_EXEC__A, IQM_RC_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_RT_COMM_EXEC__A, IQM_RT_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, IQM_CF_COMM_EXEC__A, IQM_CF_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- rc = power_down_aud(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /**
- * \brief Power up AUD.
- * \param demod instance of demodulator
- * \return int.
- *
- */
- static int power_down_aud(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = NULL;
- struct drxj_data *ext_attr = NULL;
- int rc;
- dev_addr = (struct i2c_device_addr *)demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- rc = drxj_dap_write_reg16(dev_addr, AUD_COMM_EXEC__A, AUD_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ext_attr->aud_data.audio_is_active = false;
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int set_orx_nsu_aox()
- * \brief Configure OrxNsuAox for OOB
- * \param demod instance of demodulator.
- * \param active
- * \return int.
- */
- static int set_orx_nsu_aox(struct drx_demod_instance *demod, bool active)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- int rc;
- u16 data = 0;
- /* Configure NSU_AOX */
- rc = drxj_dap_read_reg16(dev_addr, ORX_NSU_AOX_STDBY_W__A, &data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (!active)
- data &= ((~ORX_NSU_AOX_STDBY_W_STDBYADC_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYAMP_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYBIAS_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYPLL_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYPD_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYTAGC_IF_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYTAGC_RF_A2_ON) & (~ORX_NSU_AOX_STDBY_W_STDBYFLT_A2_ON));
- else
- data |= (ORX_NSU_AOX_STDBY_W_STDBYADC_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYAMP_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYBIAS_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYPLL_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYPD_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYTAGC_IF_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYTAGC_RF_A2_ON | ORX_NSU_AOX_STDBY_W_STDBYFLT_A2_ON);
- rc = drxj_dap_write_reg16(dev_addr, ORX_NSU_AOX_STDBY_W__A, data, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- return 0;
- rw_error:
- return rc;
- }
- /**
- * \fn int ctrl_set_oob()
- * \brief Set OOB channel to be used.
- * \param demod instance of demodulator
- * \param oob_param OOB parameters for channel setting.
- * \frequency should be in KHz
- * \return int.
- *
- * Accepts only. Returns error otherwise.
- * Demapper value is written after scu_command START
- * because START command causes COMM_EXEC transition
- * from 0 to 1 which causes all registers to be
- * overwritten with initial value
- *
- */
- /* Nyquist filter impulse response */
- #define IMPULSE_COSINE_ALPHA_0_3 {-3, -4, -1, 6, 10, 7, -5, -20, -25, -10, 29, 79, 123, 140} /*sqrt raised-cosine filter with alpha=0.3 */
- #define IMPULSE_COSINE_ALPHA_0_5 { 2, 0, -2, -2, 2, 5, 2, -10, -20, -14, 20, 74, 125, 145} /*sqrt raised-cosine filter with alpha=0.5 */
- #define IMPULSE_COSINE_ALPHA_RO_0_5 { 0, 0, 1, 2, 3, 0, -7, -15, -16, 0, 34, 77, 114, 128} /*full raised-cosine filter with alpha=0.5 (receiver only) */
- /* Coefficients for the nyquist fitler (total: 27 taps) */
- #define NYQFILTERLEN 27
- static int ctrl_set_oob(struct drx_demod_instance *demod, struct drxoob *oob_param)
- {
- int rc;
- s32 freq = 0; /* KHz */
- struct i2c_device_addr *dev_addr = NULL;
- struct drxj_data *ext_attr = NULL;
- u16 i = 0;
- bool mirror_freq_spect_oob = false;
- u16 trk_filter_value = 0;
- struct drxjscu_cmd scu_cmd;
- u16 set_param_parameters[3];
- u16 cmd_result[2] = { 0, 0 };
- s16 nyquist_coeffs[4][(NYQFILTERLEN + 1) / 2] = {
- IMPULSE_COSINE_ALPHA_0_3, /* Target Mode 0 */
- IMPULSE_COSINE_ALPHA_0_3, /* Target Mode 1 */
- IMPULSE_COSINE_ALPHA_0_5, /* Target Mode 2 */
- IMPULSE_COSINE_ALPHA_RO_0_5 /* Target Mode 3 */
- };
- u8 mode_val[4] = { 2, 2, 0, 1 };
- u8 pfi_coeffs[4][6] = {
- {DRXJ_16TO8(-92), DRXJ_16TO8(-108), DRXJ_16TO8(100)}, /* TARGET_MODE = 0: PFI_A = -23/32; PFI_B = -54/32; PFI_C = 25/32; fg = 0.5 MHz (Att=26dB) */
- {DRXJ_16TO8(-64), DRXJ_16TO8(-80), DRXJ_16TO8(80)}, /* TARGET_MODE = 1: PFI_A = -16/32; PFI_B = -40/32; PFI_C = 20/32; fg = 1.0 MHz (Att=28dB) */
- {DRXJ_16TO8(-80), DRXJ_16TO8(-98), DRXJ_16TO8(92)}, /* TARGET_MODE = 2, 3: PFI_A = -20/32; PFI_B = -49/32; PFI_C = 23/32; fg = 0.8 MHz (Att=25dB) */
- {DRXJ_16TO8(-80), DRXJ_16TO8(-98), DRXJ_16TO8(92)} /* TARGET_MODE = 2, 3: PFI_A = -20/32; PFI_B = -49/32; PFI_C = 23/32; fg = 0.8 MHz (Att=25dB) */
- };
- u16 mode_index;
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- mirror_freq_spect_oob = ext_attr->mirror_freq_spect_oob;
- /* Check parameters */
- if (oob_param == NULL) {
- /* power off oob module */
- scu_cmd.command = SCU_RAM_COMMAND_STANDARD_OOB
- | SCU_RAM_COMMAND_CMD_DEMOD_STOP;
- scu_cmd.parameter_len = 0;
- scu_cmd.result_len = 1;
- scu_cmd.result = cmd_result;
- rc = scu_command(dev_addr, &scu_cmd);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_orx_nsu_aox(demod, false);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, ORX_COMM_EXEC__A, ORX_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ext_attr->oob_power_on = false;
- return 0;
- }
- freq = oob_param->frequency;
- if ((freq < 70000) || (freq > 130000))
- return -EIO;
- freq = (freq - 50000) / 50;
- {
- u16 index = 0;
- u16 remainder = 0;
- u16 *trk_filtercfg = ext_attr->oob_trk_filter_cfg;
- index = (u16) ((freq - 400) / 200);
- remainder = (u16) ((freq - 400) % 200);
- trk_filter_value =
- trk_filtercfg[index] - (trk_filtercfg[index] -
- trk_filtercfg[index +
- 1]) / 10 * remainder /
- 20;
- }
- /*********/
- /* Stop */
- /*********/
- rc = drxj_dap_write_reg16(dev_addr, ORX_COMM_EXEC__A, ORX_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- scu_cmd.command = SCU_RAM_COMMAND_STANDARD_OOB
- | SCU_RAM_COMMAND_CMD_DEMOD_STOP;
- scu_cmd.parameter_len = 0;
- scu_cmd.result_len = 1;
- scu_cmd.result = cmd_result;
- rc = scu_command(dev_addr, &scu_cmd);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /*********/
- /* Reset */
- /*********/
- scu_cmd.command = SCU_RAM_COMMAND_STANDARD_OOB
- | SCU_RAM_COMMAND_CMD_DEMOD_RESET;
- scu_cmd.parameter_len = 0;
- scu_cmd.result_len = 1;
- scu_cmd.result = cmd_result;
- rc = scu_command(dev_addr, &scu_cmd);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /***********/
- /* SET_ENV */
- /***********/
- /* set frequency, spectrum inversion and data rate */
- scu_cmd.command = SCU_RAM_COMMAND_STANDARD_OOB
- | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV;
- scu_cmd.parameter_len = 3;
- /* 1-data rate;2-frequency */
- switch (oob_param->standard) {
- case DRX_OOB_MODE_A:
- if (
- /* signal is transmitted inverted */
- ((oob_param->spectrum_inverted == true) &&
- /* and tuner is not mirroring the signal */
- (!mirror_freq_spect_oob)) |
- /* or */
- /* signal is transmitted noninverted */
- ((oob_param->spectrum_inverted == false) &&
- /* and tuner is mirroring the signal */
- (mirror_freq_spect_oob))
- )
- set_param_parameters[0] =
- SCU_RAM_ORX_RF_RX_DATA_RATE_2048KBPS_INVSPEC;
- else
- set_param_parameters[0] =
- SCU_RAM_ORX_RF_RX_DATA_RATE_2048KBPS_REGSPEC;
- break;
- case DRX_OOB_MODE_B_GRADE_A:
- if (
- /* signal is transmitted inverted */
- ((oob_param->spectrum_inverted == true) &&
- /* and tuner is not mirroring the signal */
- (!mirror_freq_spect_oob)) |
- /* or */
- /* signal is transmitted noninverted */
- ((oob_param->spectrum_inverted == false) &&
- /* and tuner is mirroring the signal */
- (mirror_freq_spect_oob))
- )
- set_param_parameters[0] =
- SCU_RAM_ORX_RF_RX_DATA_RATE_1544KBPS_INVSPEC;
- else
- set_param_parameters[0] =
- SCU_RAM_ORX_RF_RX_DATA_RATE_1544KBPS_REGSPEC;
- break;
- case DRX_OOB_MODE_B_GRADE_B:
- default:
- if (
- /* signal is transmitted inverted */
- ((oob_param->spectrum_inverted == true) &&
- /* and tuner is not mirroring the signal */
- (!mirror_freq_spect_oob)) |
- /* or */
- /* signal is transmitted noninverted */
- ((oob_param->spectrum_inverted == false) &&
- /* and tuner is mirroring the signal */
- (mirror_freq_spect_oob))
- )
- set_param_parameters[0] =
- SCU_RAM_ORX_RF_RX_DATA_RATE_3088KBPS_INVSPEC;
- else
- set_param_parameters[0] =
- SCU_RAM_ORX_RF_RX_DATA_RATE_3088KBPS_REGSPEC;
- break;
- }
- set_param_parameters[1] = (u16) (freq & 0xFFFF);
- set_param_parameters[2] = trk_filter_value;
- scu_cmd.parameter = set_param_parameters;
- scu_cmd.result_len = 1;
- scu_cmd.result = cmd_result;
- mode_index = mode_val[(set_param_parameters[0] & 0xC0) >> 6];
- rc = scu_command(dev_addr, &scu_cmd);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, 0xFABA, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* Write magic word to enable pdr reg write */
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_OOB_CRX_CFG__A, OOB_CRX_DRIVE_STRENGTH << SIO_PDR_OOB_CRX_CFG_DRIVE__B | 0x03 << SIO_PDR_OOB_CRX_CFG_MODE__B, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_PDR_OOB_DRX_CFG__A, OOB_DRX_DRIVE_STRENGTH << SIO_PDR_OOB_DRX_CFG_DRIVE__B | 0x03 << SIO_PDR_OOB_DRX_CFG_MODE__B, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_TOP_COMM_KEY__A, 0x0000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- } /* Write magic word to disable pdr reg write */
- rc = drxj_dap_write_reg16(dev_addr, ORX_TOP_COMM_KEY__A, 0, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, ORX_FWP_AAG_LEN_W__A, 16000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, ORX_FWP_AAG_THR_W__A, 40, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* ddc */
- rc = drxj_dap_write_reg16(dev_addr, ORX_DDC_OFO_SET_W__A, ORX_DDC_OFO_SET_W__PRE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* nsu */
- rc = drxj_dap_write_reg16(dev_addr, ORX_NSU_AOX_LOPOW_W__A, ext_attr->oob_lo_pow, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* initialization for target mode */
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_TARGET_MODE__A, SCU_RAM_ORX_TARGET_MODE_2048KBPS_SQRT, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_FREQ_GAIN_CORR__A, SCU_RAM_ORX_FREQ_GAIN_CORR_2048KBPS, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Reset bits for timing and freq. recovery */
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_RST_CPH__A, 0x0001, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_RST_CTI__A, 0x0002, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_RST_KRN__A, 0x0004, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_RST_KRP__A, 0x0008, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* AGN_LOCK = {2048>>3, -2048, 8, -8, 0, 1}; */
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_AGN_LOCK_TH__A, 2048 >> 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_AGN_LOCK_TOTH__A, (u16)(-2048), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_AGN_ONLOCK_TTH__A, 8, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_AGN_UNLOCK_TTH__A, (u16)(-8), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_AGN_LOCK_MASK__A, 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* DGN_LOCK = {10, -2048, 8, -8, 0, 1<<1}; */
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_DGN_LOCK_TH__A, 10, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_DGN_LOCK_TOTH__A, (u16)(-2048), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_DGN_ONLOCK_TTH__A, 8, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_DGN_UNLOCK_TTH__A, (u16)(-8), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_DGN_LOCK_MASK__A, 1 << 1, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* FRQ_LOCK = {15,-2048, 8, -8, 0, 1<<2}; */
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_FRQ_LOCK_TH__A, 17, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_FRQ_LOCK_TOTH__A, (u16)(-2048), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_FRQ_ONLOCK_TTH__A, 8, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_FRQ_UNLOCK_TTH__A, (u16)(-8), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_FRQ_LOCK_MASK__A, 1 << 2, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* PHA_LOCK = {5000, -2048, 8, -8, 0, 1<<3}; */
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_PHA_LOCK_TH__A, 3000, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_PHA_LOCK_TOTH__A, (u16)(-2048), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_PHA_ONLOCK_TTH__A, 8, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_PHA_UNLOCK_TTH__A, (u16)(-8), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_PHA_LOCK_MASK__A, 1 << 3, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* TIM_LOCK = {300, -2048, 8, -8, 0, 1<<4}; */
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_TIM_LOCK_TH__A, 400, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_TIM_LOCK_TOTH__A, (u16)(-2048), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_TIM_ONLOCK_TTH__A, 8, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_TIM_UNLOCK_TTH__A, (u16)(-8), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_TIM_LOCK_MASK__A, 1 << 4, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* EQU_LOCK = {20, -2048, 8, -8, 0, 1<<5}; */
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_EQU_LOCK_TH__A, 20, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_EQU_LOCK_TOTH__A, (u16)(-2048), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_EQU_ONLOCK_TTH__A, 4, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_EQU_UNLOCK_TTH__A, (u16)(-4), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_ORX_EQU_LOCK_MASK__A, 1 << 5, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* PRE-Filter coefficients (PFI) */
- rc = drxdap_fasi_write_block(dev_addr, ORX_FWP_PFI_A_W__A, sizeof(pfi_coeffs[mode_index]), ((u8 *)pfi_coeffs[mode_index]), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, ORX_TOP_MDE_W__A, mode_index, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* NYQUIST-Filter coefficients (NYQ) */
- for (i = 0; i < (NYQFILTERLEN + 1) / 2; i++) {
- rc = drxj_dap_write_reg16(dev_addr, ORX_FWP_NYQ_ADR_W__A, i, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, ORX_FWP_NYQ_COF_RW__A, nyquist_coeffs[mode_index][i], 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- rc = drxj_dap_write_reg16(dev_addr, ORX_FWP_NYQ_ADR_W__A, 31, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, ORX_COMM_EXEC__A, ORX_COMM_EXEC_ACTIVE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /*********/
- /* Start */
- /*********/
- scu_cmd.command = SCU_RAM_COMMAND_STANDARD_OOB
- | SCU_RAM_COMMAND_CMD_DEMOD_START;
- scu_cmd.parameter_len = 0;
- scu_cmd.result_len = 1;
- scu_cmd.result = cmd_result;
- rc = scu_command(dev_addr, &scu_cmd);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_orx_nsu_aox(demod, true);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, ORX_NSU_AOX_STHR_W__A, ext_attr->oob_pre_saw, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ext_attr->oob_power_on = true;
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /*== END OOB DATAPATH FUNCTIONS ==*/
- /*============================================================================*/
- /*=============================================================================
- ===== MC command related functions ==========================================
- ===========================================================================*/
- /*=============================================================================
- ===== ctrl_set_channel() ==========================================================
- ===========================================================================*/
- /**
- * \fn int ctrl_set_channel()
- * \brief Select a new transmission channel.
- * \param demod instance of demod.
- * \param channel Pointer to channel data.
- * \return int.
- *
- * In case the tuner module is not used and in case of NTSC/FM the pogrammer
- * must tune the tuner to the centre frequency of the NTSC/FM channel.
- *
- */
- static int
- ctrl_set_channel(struct drx_demod_instance *demod, struct drx_channel *channel)
- {
- int rc;
- s32 tuner_freq_offset = 0;
- struct drxj_data *ext_attr = NULL;
- struct i2c_device_addr *dev_addr = NULL;
- enum drx_standard standard = DRX_STANDARD_UNKNOWN;
- #ifndef DRXJ_VSB_ONLY
- u32 min_symbol_rate = 0;
- u32 max_symbol_rate = 0;
- int bandwidth_temp = 0;
- int bandwidth = 0;
- #endif
- /*== check arguments ======================================================*/
- if ((demod == NULL) || (channel == NULL))
- return -EINVAL;
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- standard = ext_attr->standard;
- /* check valid standards */
- switch (standard) {
- case DRX_STANDARD_8VSB:
- #ifndef DRXJ_VSB_ONLY
- case DRX_STANDARD_ITU_A:
- case DRX_STANDARD_ITU_B:
- case DRX_STANDARD_ITU_C:
- #endif /* DRXJ_VSB_ONLY */
- break;
- case DRX_STANDARD_UNKNOWN:
- default:
- return -EINVAL;
- }
- /* check bandwidth QAM annex B, NTSC and 8VSB */
- if ((standard == DRX_STANDARD_ITU_B) ||
- (standard == DRX_STANDARD_8VSB) ||
- (standard == DRX_STANDARD_NTSC)) {
- switch (channel->bandwidth) {
- case DRX_BANDWIDTH_6MHZ:
- case DRX_BANDWIDTH_UNKNOWN: /* fall through */
- channel->bandwidth = DRX_BANDWIDTH_6MHZ;
- break;
- case DRX_BANDWIDTH_8MHZ: /* fall through */
- case DRX_BANDWIDTH_7MHZ: /* fall through */
- default:
- return -EINVAL;
- }
- }
- /* For QAM annex A and annex C:
- -check symbolrate and constellation
- -derive bandwidth from symbolrate (input bandwidth is ignored)
- */
- #ifndef DRXJ_VSB_ONLY
- if ((standard == DRX_STANDARD_ITU_A) ||
- (standard == DRX_STANDARD_ITU_C)) {
- struct drxuio_cfg uio_cfg = { DRX_UIO1, DRX_UIO_MODE_FIRMWARE_SAW };
- int bw_rolloff_factor = 0;
- bw_rolloff_factor = (standard == DRX_STANDARD_ITU_A) ? 115 : 113;
- min_symbol_rate = DRXJ_QAM_SYMBOLRATE_MIN;
- max_symbol_rate = DRXJ_QAM_SYMBOLRATE_MAX;
- /* config SMA_TX pin to SAW switch mode */
- rc = ctrl_set_uio_cfg(demod, &uio_cfg);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (channel->symbolrate < min_symbol_rate ||
- channel->symbolrate > max_symbol_rate) {
- return -EINVAL;
- }
- switch (channel->constellation) {
- case DRX_CONSTELLATION_QAM16: /* fall through */
- case DRX_CONSTELLATION_QAM32: /* fall through */
- case DRX_CONSTELLATION_QAM64: /* fall through */
- case DRX_CONSTELLATION_QAM128: /* fall through */
- case DRX_CONSTELLATION_QAM256:
- bandwidth_temp = channel->symbolrate * bw_rolloff_factor;
- bandwidth = bandwidth_temp / 100;
- if ((bandwidth_temp % 100) >= 50)
- bandwidth++;
- if (bandwidth <= 6100000) {
- channel->bandwidth = DRX_BANDWIDTH_6MHZ;
- } else if ((bandwidth > 6100000)
- && (bandwidth <= 7100000)) {
- channel->bandwidth = DRX_BANDWIDTH_7MHZ;
- } else if (bandwidth > 7100000) {
- channel->bandwidth = DRX_BANDWIDTH_8MHZ;
- }
- break;
- default:
- return -EINVAL;
- }
- }
- /* For QAM annex B:
- -check constellation
- */
- if (standard == DRX_STANDARD_ITU_B) {
- switch (channel->constellation) {
- case DRX_CONSTELLATION_AUTO:
- case DRX_CONSTELLATION_QAM256:
- case DRX_CONSTELLATION_QAM64:
- break;
- default:
- return -EINVAL;
- }
- switch (channel->interleavemode) {
- case DRX_INTERLEAVEMODE_I128_J1:
- case DRX_INTERLEAVEMODE_I128_J1_V2:
- case DRX_INTERLEAVEMODE_I128_J2:
- case DRX_INTERLEAVEMODE_I64_J2:
- case DRX_INTERLEAVEMODE_I128_J3:
- case DRX_INTERLEAVEMODE_I32_J4:
- case DRX_INTERLEAVEMODE_I128_J4:
- case DRX_INTERLEAVEMODE_I16_J8:
- case DRX_INTERLEAVEMODE_I128_J5:
- case DRX_INTERLEAVEMODE_I8_J16:
- case DRX_INTERLEAVEMODE_I128_J6:
- case DRX_INTERLEAVEMODE_I128_J7:
- case DRX_INTERLEAVEMODE_I128_J8:
- case DRX_INTERLEAVEMODE_I12_J17:
- case DRX_INTERLEAVEMODE_I5_J4:
- case DRX_INTERLEAVEMODE_B52_M240:
- case DRX_INTERLEAVEMODE_B52_M720:
- case DRX_INTERLEAVEMODE_UNKNOWN:
- case DRX_INTERLEAVEMODE_AUTO:
- break;
- default:
- return -EINVAL;
- }
- }
- if ((ext_attr->uio_sma_tx_mode) == DRX_UIO_MODE_FIRMWARE_SAW) {
- /* SAW SW, user UIO is used for switchable SAW */
- struct drxuio_data uio1 = { DRX_UIO1, false };
- switch (channel->bandwidth) {
- case DRX_BANDWIDTH_8MHZ:
- uio1.value = true;
- break;
- case DRX_BANDWIDTH_7MHZ:
- uio1.value = false;
- break;
- case DRX_BANDWIDTH_6MHZ:
- uio1.value = false;
- break;
- case DRX_BANDWIDTH_UNKNOWN:
- default:
- return -EINVAL;
- }
- rc = ctrl_uio_write(demod, &uio1);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- #endif /* DRXJ_VSB_ONLY */
- rc = drxj_dap_write_reg16(dev_addr, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- tuner_freq_offset = 0;
- /*== Setup demod for specific standard ====================================*/
- switch (standard) {
- case DRX_STANDARD_8VSB:
- if (channel->mirror == DRX_MIRROR_AUTO)
- ext_attr->mirror = DRX_MIRROR_NO;
- else
- ext_attr->mirror = channel->mirror;
- rc = set_vsb(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_frequency(demod, channel, tuner_freq_offset);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- #ifndef DRXJ_VSB_ONLY
- case DRX_STANDARD_ITU_A: /* fallthrough */
- case DRX_STANDARD_ITU_B: /* fallthrough */
- case DRX_STANDARD_ITU_C:
- rc = set_qam_channel(demod, channel, tuner_freq_offset);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- #endif
- case DRX_STANDARD_UNKNOWN:
- default:
- return -EIO;
- }
- /* flag the packet error counter reset */
- ext_attr->reset_pkt_err_acc = true;
- return 0;
- rw_error:
- return rc;
- }
- /*=============================================================================
- ===== SigQuality() ==========================================================
- ===========================================================================*/
- /**
- * \fn int ctrl_sig_quality()
- * \brief Retrieve signal quality form device.
- * \param devmod Pointer to demodulator instance.
- * \param sig_quality Pointer to signal quality data.
- * \return int.
- * \retval 0 sig_quality contains valid data.
- * \retval -EINVAL sig_quality is NULL.
- * \retval -EIO Erroneous data, sig_quality contains invalid data.
- */
- static int
- ctrl_sig_quality(struct drx_demod_instance *demod,
- enum drx_lock_status lock_status)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- struct drxj_data *ext_attr = demod->my_ext_attr;
- struct drx39xxj_state *state = dev_addr->user_data;
- struct dtv_frontend_properties *p = &state->frontend.dtv_property_cache;
- enum drx_standard standard = ext_attr->standard;
- int rc;
- u32 ber, cnt, err, pkt;
- u16 mer, strength = 0;
- rc = get_sig_strength(demod, &strength);
- if (rc < 0) {
- pr_err("error getting signal strength %d\n", rc);
- p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- } else {
- p->strength.stat[0].scale = FE_SCALE_RELATIVE;
- p->strength.stat[0].uvalue = 65535UL * strength/ 100;
- }
- switch (standard) {
- case DRX_STANDARD_8VSB:
- #ifdef DRXJ_SIGNAL_ACCUM_ERR
- rc = get_acc_pkt_err(demod, &pkt);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- #endif
- if (lock_status != DRXJ_DEMOD_LOCK && lock_status != DRX_LOCKED) {
- p->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- } else {
- rc = get_vsb_post_rs_pck_err(dev_addr, &err, &pkt);
- if (rc != 0) {
- pr_err("error %d getting UCB\n", rc);
- p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- } else {
- p->block_error.stat[0].scale = FE_SCALE_COUNTER;
- p->block_error.stat[0].uvalue += err;
- p->block_count.stat[0].scale = FE_SCALE_COUNTER;
- p->block_count.stat[0].uvalue += pkt;
- }
- /* PostViterbi is compute in steps of 10^(-6) */
- rc = get_vs_bpre_viterbi_ber(dev_addr, &ber, &cnt);
- if (rc != 0) {
- pr_err("error %d getting pre-ber\n", rc);
- p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- } else {
- p->pre_bit_error.stat[0].scale = FE_SCALE_COUNTER;
- p->pre_bit_error.stat[0].uvalue += ber;
- p->pre_bit_count.stat[0].scale = FE_SCALE_COUNTER;
- p->pre_bit_count.stat[0].uvalue += cnt;
- }
- rc = get_vs_bpost_viterbi_ber(dev_addr, &ber, &cnt);
- if (rc != 0) {
- pr_err("error %d getting post-ber\n", rc);
- p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- } else {
- p->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
- p->post_bit_error.stat[0].uvalue += ber;
- p->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
- p->post_bit_count.stat[0].uvalue += cnt;
- }
- rc = get_vsbmer(dev_addr, &mer);
- if (rc != 0) {
- pr_err("error %d getting MER\n", rc);
- p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- } else {
- p->cnr.stat[0].svalue = mer * 100;
- p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
- }
- }
- break;
- #ifndef DRXJ_VSB_ONLY
- case DRX_STANDARD_ITU_A:
- case DRX_STANDARD_ITU_B:
- case DRX_STANDARD_ITU_C:
- rc = ctrl_get_qam_sig_quality(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- #endif
- default:
- return -EIO;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn int ctrl_lock_status()
- * \brief Retrieve lock status .
- * \param dev_addr Pointer to demodulator device address.
- * \param lock_stat Pointer to lock status structure.
- * \return int.
- *
- */
- static int
- ctrl_lock_status(struct drx_demod_instance *demod, enum drx_lock_status *lock_stat)
- {
- enum drx_standard standard = DRX_STANDARD_UNKNOWN;
- struct drxj_data *ext_attr = NULL;
- struct i2c_device_addr *dev_addr = NULL;
- struct drxjscu_cmd cmd_scu = { /* command */ 0,
- /* parameter_len */ 0,
- /* result_len */ 0,
- /* *parameter */ NULL,
- /* *result */ NULL
- };
- int rc;
- u16 cmd_result[2] = { 0, 0 };
- u16 demod_lock = SCU_RAM_PARAM_1_RES_DEMOD_GET_LOCK_DEMOD_LOCKED;
- /* check arguments */
- if ((demod == NULL) || (lock_stat == NULL))
- return -EINVAL;
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- standard = ext_attr->standard;
- *lock_stat = DRX_NOT_LOCKED;
- /* define the SCU command code */
- switch (standard) {
- case DRX_STANDARD_8VSB:
- cmd_scu.command = SCU_RAM_COMMAND_STANDARD_VSB |
- SCU_RAM_COMMAND_CMD_DEMOD_GET_LOCK;
- demod_lock |= 0x6;
- break;
- #ifndef DRXJ_VSB_ONLY
- case DRX_STANDARD_ITU_A:
- case DRX_STANDARD_ITU_B:
- case DRX_STANDARD_ITU_C:
- cmd_scu.command = SCU_RAM_COMMAND_STANDARD_QAM |
- SCU_RAM_COMMAND_CMD_DEMOD_GET_LOCK;
- break;
- #endif
- case DRX_STANDARD_UNKNOWN: /* fallthrough */
- default:
- return -EIO;
- }
- /* define the SCU command parameters and execute the command */
- cmd_scu.parameter_len = 0;
- cmd_scu.result_len = 2;
- cmd_scu.parameter = NULL;
- cmd_scu.result = cmd_result;
- rc = scu_command(dev_addr, &cmd_scu);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* set the lock status */
- if (cmd_scu.result[1] < demod_lock) {
- /* 0x0000 NOT LOCKED */
- *lock_stat = DRX_NOT_LOCKED;
- } else if (cmd_scu.result[1] < SCU_RAM_PARAM_1_RES_DEMOD_GET_LOCK_LOCKED) {
- *lock_stat = DRXJ_DEMOD_LOCK;
- } else if (cmd_scu.result[1] <
- SCU_RAM_PARAM_1_RES_DEMOD_GET_LOCK_NEVER_LOCK) {
- /* 0x8000 DEMOD + FEC LOCKED (system lock) */
- *lock_stat = DRX_LOCKED;
- } else {
- /* 0xC000 NEVER LOCKED */
- /* (system will never be able to lock to the signal) */
- *lock_stat = DRX_NEVER_LOCK;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn int ctrl_set_standard()
- * \brief Set modulation standard to be used.
- * \param standard Modulation standard.
- * \return int.
- *
- * Setup stuff for the desired demodulation standard.
- * Disable and power down the previous selected demodulation standard
- *
- */
- static int
- ctrl_set_standard(struct drx_demod_instance *demod, enum drx_standard *standard)
- {
- struct drxj_data *ext_attr = NULL;
- int rc;
- enum drx_standard prev_standard;
- /* check arguments */
- if ((standard == NULL) || (demod == NULL))
- return -EINVAL;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- prev_standard = ext_attr->standard;
- /*
- Stop and power down previous standard
- */
- switch (prev_standard) {
- #ifndef DRXJ_VSB_ONLY
- case DRX_STANDARD_ITU_A: /* fallthrough */
- case DRX_STANDARD_ITU_B: /* fallthrough */
- case DRX_STANDARD_ITU_C:
- rc = power_down_qam(demod, false);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- #endif
- case DRX_STANDARD_8VSB:
- rc = power_down_vsb(demod, false);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_STANDARD_UNKNOWN:
- /* Do nothing */
- break;
- case DRX_STANDARD_AUTO: /* fallthrough */
- default:
- return -EINVAL;
- }
- /*
- Initialize channel independent registers
- Power up new standard
- */
- ext_attr->standard = *standard;
- switch (*standard) {
- #ifndef DRXJ_VSB_ONLY
- case DRX_STANDARD_ITU_A: /* fallthrough */
- case DRX_STANDARD_ITU_B: /* fallthrough */
- case DRX_STANDARD_ITU_C:
- do {
- u16 dummy;
- rc = drxj_dap_read_reg16(demod->my_i2c_dev_addr, SCU_RAM_VERSION_HI__A, &dummy, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- } while (0);
- break;
- #endif
- case DRX_STANDARD_8VSB:
- rc = set_vsb_leak_n_gain(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- default:
- ext_attr->standard = DRX_STANDARD_UNKNOWN;
- return -EINVAL;
- break;
- }
- return 0;
- rw_error:
- /* Don't know what the standard is now ... try again */
- ext_attr->standard = DRX_STANDARD_UNKNOWN;
- return rc;
- }
- /*============================================================================*/
- static void drxj_reset_mode(struct drxj_data *ext_attr)
- {
- /* Initialize default AFE configuartion for QAM */
- if (ext_attr->has_lna) {
- /* IF AGC off, PGA active */
- #ifndef DRXJ_VSB_ONLY
- ext_attr->qam_if_agc_cfg.standard = DRX_STANDARD_ITU_B;
- ext_attr->qam_if_agc_cfg.ctrl_mode = DRX_AGC_CTRL_OFF;
- ext_attr->qam_pga_cfg = 140 + (11 * 13);
- #endif
- ext_attr->vsb_if_agc_cfg.standard = DRX_STANDARD_8VSB;
- ext_attr->vsb_if_agc_cfg.ctrl_mode = DRX_AGC_CTRL_OFF;
- ext_attr->vsb_pga_cfg = 140 + (11 * 13);
- } else {
- /* IF AGC on, PGA not active */
- #ifndef DRXJ_VSB_ONLY
- ext_attr->qam_if_agc_cfg.standard = DRX_STANDARD_ITU_B;
- ext_attr->qam_if_agc_cfg.ctrl_mode = DRX_AGC_CTRL_AUTO;
- ext_attr->qam_if_agc_cfg.min_output_level = 0;
- ext_attr->qam_if_agc_cfg.max_output_level = 0x7FFF;
- ext_attr->qam_if_agc_cfg.speed = 3;
- ext_attr->qam_if_agc_cfg.top = 1297;
- ext_attr->qam_pga_cfg = 140;
- #endif
- ext_attr->vsb_if_agc_cfg.standard = DRX_STANDARD_8VSB;
- ext_attr->vsb_if_agc_cfg.ctrl_mode = DRX_AGC_CTRL_AUTO;
- ext_attr->vsb_if_agc_cfg.min_output_level = 0;
- ext_attr->vsb_if_agc_cfg.max_output_level = 0x7FFF;
- ext_attr->vsb_if_agc_cfg.speed = 3;
- ext_attr->vsb_if_agc_cfg.top = 1024;
- ext_attr->vsb_pga_cfg = 140;
- }
- /* TODO: remove min_output_level and max_output_level for both QAM and VSB after */
- /* mc has not used them */
- #ifndef DRXJ_VSB_ONLY
- ext_attr->qam_rf_agc_cfg.standard = DRX_STANDARD_ITU_B;
- ext_attr->qam_rf_agc_cfg.ctrl_mode = DRX_AGC_CTRL_AUTO;
- ext_attr->qam_rf_agc_cfg.min_output_level = 0;
- ext_attr->qam_rf_agc_cfg.max_output_level = 0x7FFF;
- ext_attr->qam_rf_agc_cfg.speed = 3;
- ext_attr->qam_rf_agc_cfg.top = 9500;
- ext_attr->qam_rf_agc_cfg.cut_off_current = 4000;
- ext_attr->qam_pre_saw_cfg.standard = DRX_STANDARD_ITU_B;
- ext_attr->qam_pre_saw_cfg.reference = 0x07;
- ext_attr->qam_pre_saw_cfg.use_pre_saw = true;
- #endif
- /* Initialize default AFE configuartion for VSB */
- ext_attr->vsb_rf_agc_cfg.standard = DRX_STANDARD_8VSB;
- ext_attr->vsb_rf_agc_cfg.ctrl_mode = DRX_AGC_CTRL_AUTO;
- ext_attr->vsb_rf_agc_cfg.min_output_level = 0;
- ext_attr->vsb_rf_agc_cfg.max_output_level = 0x7FFF;
- ext_attr->vsb_rf_agc_cfg.speed = 3;
- ext_attr->vsb_rf_agc_cfg.top = 9500;
- ext_attr->vsb_rf_agc_cfg.cut_off_current = 4000;
- ext_attr->vsb_pre_saw_cfg.standard = DRX_STANDARD_8VSB;
- ext_attr->vsb_pre_saw_cfg.reference = 0x07;
- ext_attr->vsb_pre_saw_cfg.use_pre_saw = true;
- }
- /**
- * \fn int ctrl_power_mode()
- * \brief Set the power mode of the device to the specified power mode
- * \param demod Pointer to demodulator instance.
- * \param mode Pointer to new power mode.
- * \return int.
- * \retval 0 Success
- * \retval -EIO I2C error or other failure
- * \retval -EINVAL Invalid mode argument.
- *
- *
- */
- static int
- ctrl_power_mode(struct drx_demod_instance *demod, enum drx_power_mode *mode)
- {
- struct drx_common_attr *common_attr = (struct drx_common_attr *) NULL;
- struct drxj_data *ext_attr = (struct drxj_data *) NULL;
- struct i2c_device_addr *dev_addr = (struct i2c_device_addr *)NULL;
- int rc;
- u16 sio_cc_pwd_mode = 0;
- common_attr = (struct drx_common_attr *) demod->my_common_attr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- dev_addr = demod->my_i2c_dev_addr;
- /* Check arguments */
- if (mode == NULL)
- return -EINVAL;
- /* If already in requested power mode, do nothing */
- if (common_attr->current_power_mode == *mode)
- return 0;
- switch (*mode) {
- case DRX_POWER_UP:
- case DRXJ_POWER_DOWN_MAIN_PATH:
- sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_NONE;
- break;
- case DRXJ_POWER_DOWN_CORE:
- sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_CLOCK;
- break;
- case DRXJ_POWER_DOWN_PLL:
- sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_PLL;
- break;
- case DRX_POWER_DOWN:
- sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_OSC;
- break;
- default:
- /* Unknow sleep mode */
- return -EINVAL;
- break;
- }
- /* Check if device needs to be powered up */
- if ((common_attr->current_power_mode != DRX_POWER_UP)) {
- rc = power_up_device(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- if ((*mode == DRX_POWER_UP)) {
- /* Restore analog & pin configuartion */
- /* Initialize default AFE configuartion for VSB */
- drxj_reset_mode(ext_attr);
- } else {
- /* Power down to requested mode */
- /* Backup some register settings */
- /* Set pins with possible pull-ups connected to them in input mode */
- /* Analog power down */
- /* ADC power down */
- /* Power down device */
- /* stop all comm_exec */
- /*
- Stop and power down previous standard
- */
- switch (ext_attr->standard) {
- case DRX_STANDARD_ITU_A:
- case DRX_STANDARD_ITU_B:
- case DRX_STANDARD_ITU_C:
- rc = power_down_qam(demod, true);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_STANDARD_8VSB:
- rc = power_down_vsb(demod, true);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_STANDARD_PAL_SECAM_BG: /* fallthrough */
- case DRX_STANDARD_PAL_SECAM_DK: /* fallthrough */
- case DRX_STANDARD_PAL_SECAM_I: /* fallthrough */
- case DRX_STANDARD_PAL_SECAM_L: /* fallthrough */
- case DRX_STANDARD_PAL_SECAM_LP: /* fallthrough */
- case DRX_STANDARD_NTSC: /* fallthrough */
- case DRX_STANDARD_FM:
- rc = power_down_atv(demod, ext_attr->standard, true);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- break;
- case DRX_STANDARD_UNKNOWN:
- /* Do nothing */
- break;
- case DRX_STANDARD_AUTO: /* fallthrough */
- default:
- return -EIO;
- }
- ext_attr->standard = DRX_STANDARD_UNKNOWN;
- }
- if (*mode != DRXJ_POWER_DOWN_MAIN_PATH) {
- rc = drxj_dap_write_reg16(dev_addr, SIO_CC_PWD_MODE__A, sio_cc_pwd_mode, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if ((*mode != DRX_POWER_UP)) {
- /* Initialize HI, wakeup key especially before put IC to sleep */
- rc = init_hi(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- ext_attr->hi_cfg_ctrl |= SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ;
- rc = hi_cfg_command(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- }
- common_attr->current_power_mode = *mode;
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /*== CTRL Set/Get Config related functions ===================================*/
- /*============================================================================*/
- /**
- * \fn int ctrl_set_cfg_pre_saw()
- * \brief Set Pre-saw reference.
- * \param demod demod instance
- * \param u16 *
- * \return int.
- *
- * Check arguments
- * Dispatch handling to standard specific function.
- *
- */
- static int
- ctrl_set_cfg_pre_saw(struct drx_demod_instance *demod, struct drxj_cfg_pre_saw *pre_saw)
- {
- struct i2c_device_addr *dev_addr = NULL;
- struct drxj_data *ext_attr = NULL;
- int rc;
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- /* check arguments */
- if ((pre_saw == NULL) || (pre_saw->reference > IQM_AF_PDREF__M)
- ) {
- return -EINVAL;
- }
- /* Only if standard is currently active */
- if ((ext_attr->standard == pre_saw->standard) ||
- (DRXJ_ISQAMSTD(ext_attr->standard) &&
- DRXJ_ISQAMSTD(pre_saw->standard)) ||
- (DRXJ_ISATVSTD(ext_attr->standard) &&
- DRXJ_ISATVSTD(pre_saw->standard))) {
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_PDREF__A, pre_saw->reference, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* Store pre-saw settings */
- switch (pre_saw->standard) {
- case DRX_STANDARD_8VSB:
- ext_attr->vsb_pre_saw_cfg = *pre_saw;
- break;
- #ifndef DRXJ_VSB_ONLY
- case DRX_STANDARD_ITU_A: /* fallthrough */
- case DRX_STANDARD_ITU_B: /* fallthrough */
- case DRX_STANDARD_ITU_C:
- ext_attr->qam_pre_saw_cfg = *pre_saw;
- break;
- #endif
- default:
- return -EINVAL;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn int ctrl_set_cfg_afe_gain()
- * \brief Set AFE Gain.
- * \param demod demod instance
- * \param u16 *
- * \return int.
- *
- * Check arguments
- * Dispatch handling to standard specific function.
- *
- */
- static int
- ctrl_set_cfg_afe_gain(struct drx_demod_instance *demod, struct drxj_cfg_afe_gain *afe_gain)
- {
- struct i2c_device_addr *dev_addr = NULL;
- struct drxj_data *ext_attr = NULL;
- int rc;
- u8 gain = 0;
- /* check arguments */
- if (afe_gain == NULL)
- return -EINVAL;
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- switch (afe_gain->standard) {
- case DRX_STANDARD_8VSB: /* fallthrough */
- #ifndef DRXJ_VSB_ONLY
- case DRX_STANDARD_ITU_A: /* fallthrough */
- case DRX_STANDARD_ITU_B: /* fallthrough */
- case DRX_STANDARD_ITU_C:
- #endif
- /* Do nothing */
- break;
- default:
- return -EINVAL;
- }
- /* TODO PGA gain is also written by microcode (at least by QAM and VSB)
- So I (PJ) think interface requires choice between auto, user mode */
- if (afe_gain->gain >= 329)
- gain = 15;
- else if (afe_gain->gain <= 147)
- gain = 0;
- else
- gain = (afe_gain->gain - 140 + 6) / 13;
- /* Only if standard is currently active */
- if (ext_attr->standard == afe_gain->standard) {
- rc = drxj_dap_write_reg16(dev_addr, IQM_AF_PGA_GAIN__A, gain, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- }
- /* Store AFE Gain settings */
- switch (afe_gain->standard) {
- case DRX_STANDARD_8VSB:
- ext_attr->vsb_pga_cfg = gain * 13 + 140;
- break;
- #ifndef DRXJ_VSB_ONLY
- case DRX_STANDARD_ITU_A: /* fallthrough */
- case DRX_STANDARD_ITU_B: /* fallthrough */
- case DRX_STANDARD_ITU_C:
- ext_attr->qam_pga_cfg = gain * 13 + 140;
- break;
- #endif
- default:
- return -EIO;
- }
- return 0;
- rw_error:
- return rc;
- }
- /*============================================================================*/
- /*=============================================================================
- ===== EXPORTED FUNCTIONS ====================================================*/
- static int drx_ctrl_u_code(struct drx_demod_instance *demod,
- struct drxu_code_info *mc_info,
- enum drxu_code_action action);
- static int drxj_set_lna_state(struct drx_demod_instance *demod, bool state);
- /**
- * \fn drxj_open()
- * \brief Open the demod instance, configure device, configure drxdriver
- * \return Status_t Return status.
- *
- * drxj_open() can be called with a NULL ucode image => no ucode upload.
- * This means that drxj_open() must NOT contain SCU commands or, in general,
- * rely on SCU or AUD ucode to be present.
- *
- */
- static int drxj_open(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = NULL;
- struct drxj_data *ext_attr = NULL;
- struct drx_common_attr *common_attr = NULL;
- u32 driver_version = 0;
- struct drxu_code_info ucode_info;
- struct drx_cfg_mpeg_output cfg_mpeg_output;
- int rc;
- enum drx_power_mode power_mode = DRX_POWER_UP;
- if ((demod == NULL) ||
- (demod->my_common_attr == NULL) ||
- (demod->my_ext_attr == NULL) ||
- (demod->my_i2c_dev_addr == NULL) ||
- (demod->my_common_attr->is_opened)) {
- return -EINVAL;
- }
- /* Check arguments */
- if (demod->my_ext_attr == NULL)
- return -EINVAL;
- dev_addr = demod->my_i2c_dev_addr;
- ext_attr = (struct drxj_data *) demod->my_ext_attr;
- common_attr = (struct drx_common_attr *) demod->my_common_attr;
- rc = ctrl_power_mode(demod, &power_mode);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- if (power_mode != DRX_POWER_UP) {
- rc = -EINVAL;
- pr_err("failed to powerup device\n");
- goto rw_error;
- }
- /* has to be in front of setIqmAf and setOrxNsuAox */
- rc = get_device_capabilities(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /*
- * Soft reset of sys- and osc-clockdomain
- *
- * HACK: On windows, it writes a 0x07 here, instead of just 0x03.
- * As we didn't load the firmware here yet, we should do the same.
- * Btw, this is coherent with DRX-K, where we send reset codes
- * for modulation (OFTM, in DRX-k), SYS and OSC clock domains.
- */
- rc = drxj_dap_write_reg16(dev_addr, SIO_CC_SOFT_RST__A, (0x04 | SIO_CC_SOFT_RST_SYS__M | SIO_CC_SOFT_RST_OSC__M), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- msleep(1);
- /* TODO first make sure that everything keeps working before enabling this */
- /* PowerDownAnalogBlocks() */
- rc = drxj_dap_write_reg16(dev_addr, ATV_TOP_STDBY__A, (~ATV_TOP_STDBY_CVBS_STDBY_A2_ACTIVE) | ATV_TOP_STDBY_SIF_STDBY_STANDBY, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_iqm_af(demod, false);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = set_orx_nsu_aox(demod, false);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = init_hi(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* disable mpegoutput pins */
- memcpy(&cfg_mpeg_output, &common_attr->mpeg_cfg, sizeof(cfg_mpeg_output));
- cfg_mpeg_output.enable_mpeg_output = false;
- rc = ctrl_set_cfg_mpeg_output(demod, &cfg_mpeg_output);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Stop AUD Inform SetAudio it will need to do all setting */
- rc = power_down_aud(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Stop SCU */
- rc = drxj_dap_write_reg16(dev_addr, SCU_COMM_EXEC__A, SCU_COMM_EXEC_STOP, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Upload microcode */
- if (common_attr->microcode_file != NULL) {
- /* Dirty trick to use common ucode upload & verify,
- pretend device is already open */
- common_attr->is_opened = true;
- ucode_info.mc_file = common_attr->microcode_file;
- if (DRX_ISPOWERDOWNMODE(demod->my_common_attr->current_power_mode)) {
- pr_err("Should powerup before loading the firmware.");
- return -EINVAL;
- }
- rc = drx_ctrl_u_code(demod, &ucode_info, UCODE_UPLOAD);
- if (rc != 0) {
- pr_err("error %d while uploading the firmware\n", rc);
- goto rw_error;
- }
- if (common_attr->verify_microcode == true) {
- rc = drx_ctrl_u_code(demod, &ucode_info, UCODE_VERIFY);
- if (rc != 0) {
- pr_err("error %d while verifying the firmware\n",
- rc);
- goto rw_error;
- }
- }
- common_attr->is_opened = false;
- }
- /* Run SCU for a little while to initialize microcode version numbers */
- rc = drxj_dap_write_reg16(dev_addr, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Initialize scan timeout */
- common_attr->scan_demod_lock_timeout = DRXJ_SCAN_TIMEOUT;
- common_attr->scan_desired_lock = DRX_LOCKED;
- drxj_reset_mode(ext_attr);
- ext_attr->standard = DRX_STANDARD_UNKNOWN;
- rc = smart_ant_init(demod);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* Stamp driver version number in SCU data RAM in BCD code
- Done to enable field application engineers to retrieve drxdriver version
- via I2C from SCU RAM
- */
- driver_version = (VERSION_MAJOR / 100) % 10;
- driver_version <<= 4;
- driver_version += (VERSION_MAJOR / 10) % 10;
- driver_version <<= 4;
- driver_version += (VERSION_MAJOR % 10);
- driver_version <<= 4;
- driver_version += (VERSION_MINOR % 10);
- driver_version <<= 4;
- driver_version += (VERSION_PATCH / 1000) % 10;
- driver_version <<= 4;
- driver_version += (VERSION_PATCH / 100) % 10;
- driver_version <<= 4;
- driver_version += (VERSION_PATCH / 10) % 10;
- driver_version <<= 4;
- driver_version += (VERSION_PATCH % 10);
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_DRIVER_VER_HI__A, (u16)(driver_version >> 16), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_RAM_DRIVER_VER_LO__A, (u16)(driver_version & 0xFFFF), 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = ctrl_set_oob(demod, NULL);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- /* refresh the audio data structure with default */
- ext_attr->aud_data = drxj_default_aud_data_g;
- demod->my_common_attr->is_opened = true;
- drxj_set_lna_state(demod, false);
- return 0;
- rw_error:
- common_attr->is_opened = false;
- return rc;
- }
- /*============================================================================*/
- /**
- * \fn drxj_close()
- * \brief Close the demod instance, power down the device
- * \return Status_t Return status.
- *
- */
- static int drxj_close(struct drx_demod_instance *demod)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- int rc;
- enum drx_power_mode power_mode = DRX_POWER_UP;
- if ((demod->my_common_attr == NULL) ||
- (demod->my_ext_attr == NULL) ||
- (demod->my_i2c_dev_addr == NULL) ||
- (!demod->my_common_attr->is_opened)) {
- return -EINVAL;
- }
- /* power up */
- rc = ctrl_power_mode(demod, &power_mode);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- rc = drxj_dap_write_reg16(dev_addr, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE, 0);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- power_mode = DRX_POWER_DOWN;
- rc = ctrl_power_mode(demod, &power_mode);
- if (rc != 0) {
- pr_err("error %d\n", rc);
- goto rw_error;
- }
- DRX_ATTR_ISOPENED(demod) = false;
- return 0;
- rw_error:
- DRX_ATTR_ISOPENED(demod) = false;
- return rc;
- }
- /*
- * Microcode related functions
- */
- /**
- * drx_u_code_compute_crc - Compute CRC of block of microcode data.
- * @block_data: Pointer to microcode data.
- * @nr_words: Size of microcode block (number of 16 bits words).
- *
- * returns The computed CRC residue.
- */
- static u16 drx_u_code_compute_crc(u8 *block_data, u16 nr_words)
- {
- u16 i = 0;
- u16 j = 0;
- u32 crc_word = 0;
- u32 carry = 0;
- while (i < nr_words) {
- crc_word |= (u32)be16_to_cpu(*(__be16 *)(block_data));
- for (j = 0; j < 16; j++) {
- crc_word <<= 1;
- if (carry != 0)
- crc_word ^= 0x80050000UL;
- carry = crc_word & 0x80000000UL;
- }
- i++;
- block_data += (sizeof(u16));
- }
- return (u16)(crc_word >> 16);
- }
- /**
- * drx_check_firmware - checks if the loaded firmware is valid
- *
- * @demod: demod structure
- * @mc_data: pointer to the start of the firmware
- * @size: firmware size
- */
- static int drx_check_firmware(struct drx_demod_instance *demod, u8 *mc_data,
- unsigned size)
- {
- struct drxu_code_block_hdr block_hdr;
- int i;
- unsigned count = 2 * sizeof(u16);
- u32 mc_dev_type, mc_version, mc_base_version;
- u16 mc_nr_of_blks = be16_to_cpu(*(__be16 *)(mc_data + sizeof(u16)));
- /*
- * Scan microcode blocks first for version info
- * and firmware check
- */
- /* Clear version block */
- DRX_ATTR_MCRECORD(demod).aux_type = 0;
- DRX_ATTR_MCRECORD(demod).mc_dev_type = 0;
- DRX_ATTR_MCRECORD(demod).mc_version = 0;
- DRX_ATTR_MCRECORD(demod).mc_base_version = 0;
- for (i = 0; i < mc_nr_of_blks; i++) {
- if (count + 3 * sizeof(u16) + sizeof(u32) > size)
- goto eof;
- /* Process block header */
- block_hdr.addr = be32_to_cpu(*(__be32 *)(mc_data + count));
- count += sizeof(u32);
- block_hdr.size = be16_to_cpu(*(__be16 *)(mc_data + count));
- count += sizeof(u16);
- block_hdr.flags = be16_to_cpu(*(__be16 *)(mc_data + count));
- count += sizeof(u16);
- block_hdr.CRC = be16_to_cpu(*(__be16 *)(mc_data + count));
- count += sizeof(u16);
- pr_debug("%u: addr %u, size %u, flags 0x%04x, CRC 0x%04x\n",
- count, block_hdr.addr, block_hdr.size, block_hdr.flags,
- block_hdr.CRC);
- if (block_hdr.flags & 0x8) {
- u8 *auxblk = ((void *)mc_data) + block_hdr.addr;
- u16 auxtype;
- if (block_hdr.addr + sizeof(u16) > size)
- goto eof;
- auxtype = be16_to_cpu(*(__be16 *)(auxblk));
- /* Aux block. Check type */
- if (DRX_ISMCVERTYPE(auxtype)) {
- if (block_hdr.addr + 2 * sizeof(u16) + 2 * sizeof (u32) > size)
- goto eof;
- auxblk += sizeof(u16);
- mc_dev_type = be32_to_cpu(*(__be32 *)(auxblk));
- auxblk += sizeof(u32);
- mc_version = be32_to_cpu(*(__be32 *)(auxblk));
- auxblk += sizeof(u32);
- mc_base_version = be32_to_cpu(*(__be32 *)(auxblk));
- DRX_ATTR_MCRECORD(demod).aux_type = auxtype;
- DRX_ATTR_MCRECORD(demod).mc_dev_type = mc_dev_type;
- DRX_ATTR_MCRECORD(demod).mc_version = mc_version;
- DRX_ATTR_MCRECORD(demod).mc_base_version = mc_base_version;
- pr_info("Firmware dev %x, ver %x, base ver %x\n",
- mc_dev_type, mc_version, mc_base_version);
- }
- } else if (count + block_hdr.size * sizeof(u16) > size)
- goto eof;
- count += block_hdr.size * sizeof(u16);
- }
- return 0;
- eof:
- pr_err("Firmware is truncated at pos %u/%u\n", count, size);
- return -EINVAL;
- }
- /**
- * drx_ctrl_u_code - Handle microcode upload or verify.
- * @dev_addr: Address of device.
- * @mc_info: Pointer to information about microcode data.
- * @action: Either UCODE_UPLOAD or UCODE_VERIFY
- *
- * This function returns:
- * 0:
- * - In case of UCODE_UPLOAD: code is successfully uploaded.
- * - In case of UCODE_VERIFY: image on device is equal to
- * image provided to this control function.
- * -EIO:
- * - In case of UCODE_UPLOAD: I2C error.
- * - In case of UCODE_VERIFY: I2C error or image on device
- * is not equal to image provided to this control function.
- * -EINVAL:
- * - Invalid arguments.
- * - Provided image is corrupt
- */
- static int drx_ctrl_u_code(struct drx_demod_instance *demod,
- struct drxu_code_info *mc_info,
- enum drxu_code_action action)
- {
- struct i2c_device_addr *dev_addr = demod->my_i2c_dev_addr;
- int rc;
- u16 i = 0;
- u16 mc_nr_of_blks = 0;
- u16 mc_magic_word = 0;
- const u8 *mc_data_init = NULL;
- u8 *mc_data = NULL;
- unsigned size;
- char *mc_file;
- /* Check arguments */
- if (!mc_info || !mc_info->mc_file)
- return -EINVAL;
- mc_file = mc_info->mc_file;
- if (!demod->firmware) {
- const struct firmware *fw = NULL;
- rc = request_firmware(&fw, mc_file, demod->i2c->dev.parent);
- if (rc < 0) {
- pr_err("Couldn't read firmware %s\n", mc_file);
- return rc;
- }
- demod->firmware = fw;
- if (demod->firmware->size < 2 * sizeof(u16)) {
- rc = -EINVAL;
- pr_err("Firmware is too short!\n");
- goto release;
- }
- pr_info("Firmware %s, size %zu\n",
- mc_file, demod->firmware->size);
- }
- mc_data_init = demod->firmware->data;
- size = demod->firmware->size;
- mc_data = (void *)mc_data_init;
- /* Check data */
- mc_magic_word = be16_to_cpu(*(__be16 *)(mc_data));
- mc_data += sizeof(u16);
- mc_nr_of_blks = be16_to_cpu(*(__be16 *)(mc_data));
- mc_data += sizeof(u16);
- if ((mc_magic_word != DRX_UCODE_MAGIC_WORD) || (mc_nr_of_blks == 0)) {
- rc = -EINVAL;
- pr_err("Firmware magic word doesn't match\n");
- goto release;
- }
- if (action == UCODE_UPLOAD) {
- rc = drx_check_firmware(demod, (u8 *)mc_data_init, size);
- if (rc)
- goto release;
- pr_info("Uploading firmware %s\n", mc_file);
- } else {
- pr_info("Verifying if firmware upload was ok.\n");
- }
- /* Process microcode blocks */
- for (i = 0; i < mc_nr_of_blks; i++) {
- struct drxu_code_block_hdr block_hdr;
- u16 mc_block_nr_bytes = 0;
- /* Process block header */
- block_hdr.addr = be32_to_cpu(*(__be32 *)(mc_data));
- mc_data += sizeof(u32);
- block_hdr.size = be16_to_cpu(*(__be16 *)(mc_data));
- mc_data += sizeof(u16);
- block_hdr.flags = be16_to_cpu(*(__be16 *)(mc_data));
- mc_data += sizeof(u16);
- block_hdr.CRC = be16_to_cpu(*(__be16 *)(mc_data));
- mc_data += sizeof(u16);
- pr_debug("%u: addr %u, size %u, flags 0x%04x, CRC 0x%04x\n",
- (unsigned)(mc_data - mc_data_init), block_hdr.addr,
- block_hdr.size, block_hdr.flags, block_hdr.CRC);
- /* Check block header on:
- - data larger than 64Kb
- - if CRC enabled check CRC
- */
- if ((block_hdr.size > 0x7FFF) ||
- (((block_hdr.flags & DRX_UCODE_CRC_FLAG) != 0) &&
- (block_hdr.CRC != drx_u_code_compute_crc(mc_data, block_hdr.size)))
- ) {
- /* Wrong data ! */
- rc = -EINVAL;
- pr_err("firmware CRC is wrong\n");
- goto release;
- }
- if (!block_hdr.size)
- continue;
- mc_block_nr_bytes = block_hdr.size * ((u16) sizeof(u16));
- /* Perform the desired action */
- switch (action) {
- case UCODE_UPLOAD: /* Upload microcode */
- if (drxdap_fasi_write_block(dev_addr,
- block_hdr.addr,
- mc_block_nr_bytes,
- mc_data, 0x0000)) {
- rc = -EIO;
- pr_err("error writing firmware at pos %u\n",
- (unsigned)(mc_data - mc_data_init));
- goto release;
- }
- break;
- case UCODE_VERIFY: { /* Verify uploaded microcode */
- int result = 0;
- u8 mc_data_buffer[DRX_UCODE_MAX_BUF_SIZE];
- u32 bytes_to_comp = 0;
- u32 bytes_left = mc_block_nr_bytes;
- u32 curr_addr = block_hdr.addr;
- u8 *curr_ptr = mc_data;
- while (bytes_left != 0) {
- if (bytes_left > DRX_UCODE_MAX_BUF_SIZE)
- bytes_to_comp = DRX_UCODE_MAX_BUF_SIZE;
- else
- bytes_to_comp = bytes_left;
- if (drxdap_fasi_read_block(dev_addr,
- curr_addr,
- (u16)bytes_to_comp,
- (u8 *)mc_data_buffer,
- 0x0000)) {
- pr_err("error reading firmware at pos %u\n",
- (unsigned)(mc_data - mc_data_init));
- return -EIO;
- }
- result = memcmp(curr_ptr, mc_data_buffer,
- bytes_to_comp);
- if (result) {
- pr_err("error verifying firmware at pos %u\n",
- (unsigned)(mc_data - mc_data_init));
- return -EIO;
- }
- curr_addr += ((dr_xaddr_t)(bytes_to_comp / 2));
- curr_ptr =&(curr_ptr[bytes_to_comp]);
- bytes_left -=((u32) bytes_to_comp);
- }
- break;
- }
- default:
- return -EINVAL;
- break;
- }
- mc_data += mc_block_nr_bytes;
- }
- return 0;
- release:
- release_firmware(demod->firmware);
- demod->firmware = NULL;
- return rc;
- }
- /* caller is expected to check if lna is supported before enabling */
- static int drxj_set_lna_state(struct drx_demod_instance *demod, bool state)
- {
- struct drxuio_cfg uio_cfg;
- struct drxuio_data uio_data;
- int result;
- uio_cfg.uio = DRX_UIO1;
- uio_cfg.mode = DRX_UIO_MODE_READWRITE;
- /* Configure user-I/O #3: enable read/write */
- result = ctrl_set_uio_cfg(demod, &uio_cfg);
- if (result) {
- pr_err("Failed to setup LNA GPIO!\n");
- return result;
- }
- uio_data.uio = DRX_UIO1;
- uio_data.value = state;
- result = ctrl_uio_write(demod, &uio_data);
- if (result != 0) {
- pr_err("Failed to %sable LNA!\n",
- state ? "en" : "dis");
- return result;
- }
- return 0;
- }
- /*
- * The Linux DVB Driver for Micronas DRX39xx family (drx3933j)
- *
- * Written by Devin Heitmueller <devin.heitmueller@kernellabs.com>
- */
- static int drx39xxj_set_powerstate(struct dvb_frontend *fe, int enable)
- {
- struct drx39xxj_state *state = fe->demodulator_priv;
- struct drx_demod_instance *demod = state->demod;
- int result;
- enum drx_power_mode power_mode;
- if (enable)
- power_mode = DRX_POWER_UP;
- else
- power_mode = DRX_POWER_DOWN;
- result = ctrl_power_mode(demod, &power_mode);
- if (result != 0) {
- pr_err("Power state change failed\n");
- return 0;
- }
- return 0;
- }
- static int drx39xxj_read_status(struct dvb_frontend *fe, enum fe_status *status)
- {
- struct drx39xxj_state *state = fe->demodulator_priv;
- struct drx_demod_instance *demod = state->demod;
- int result;
- enum drx_lock_status lock_status;
- *status = 0;
- result = ctrl_lock_status(demod, &lock_status);
- if (result != 0) {
- pr_err("drx39xxj: could not get lock status!\n");
- *status = 0;
- }
- switch (lock_status) {
- case DRX_NEVER_LOCK:
- *status = 0;
- pr_err("drx says NEVER_LOCK\n");
- break;
- case DRX_NOT_LOCKED:
- *status = 0;
- break;
- case DRX_LOCK_STATE_1:
- case DRX_LOCK_STATE_2:
- case DRX_LOCK_STATE_3:
- case DRX_LOCK_STATE_4:
- case DRX_LOCK_STATE_5:
- case DRX_LOCK_STATE_6:
- case DRX_LOCK_STATE_7:
- case DRX_LOCK_STATE_8:
- case DRX_LOCK_STATE_9:
- *status = FE_HAS_SIGNAL
- | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC;
- break;
- case DRX_LOCKED:
- *status = FE_HAS_SIGNAL
- | FE_HAS_CARRIER
- | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
- break;
- default:
- pr_err("Lock state unknown %d\n", lock_status);
- }
- ctrl_sig_quality(demod, lock_status);
- return 0;
- }
- static int drx39xxj_read_ber(struct dvb_frontend *fe, u32 *ber)
- {
- struct dtv_frontend_properties *p = &fe->dtv_property_cache;
- if (p->pre_bit_error.stat[0].scale == FE_SCALE_NOT_AVAILABLE) {
- *ber = 0;
- return 0;
- }
- if (!p->pre_bit_count.stat[0].uvalue) {
- if (!p->pre_bit_error.stat[0].uvalue)
- *ber = 0;
- else
- *ber = 1000000;
- } else {
- *ber = frac_times1e6(p->pre_bit_error.stat[0].uvalue,
- p->pre_bit_count.stat[0].uvalue);
- }
- return 0;
- }
- static int drx39xxj_read_signal_strength(struct dvb_frontend *fe,
- u16 *strength)
- {
- struct dtv_frontend_properties *p = &fe->dtv_property_cache;
- if (p->strength.stat[0].scale == FE_SCALE_NOT_AVAILABLE) {
- *strength = 0;
- return 0;
- }
- *strength = p->strength.stat[0].uvalue;
- return 0;
- }
- static int drx39xxj_read_snr(struct dvb_frontend *fe, u16 *snr)
- {
- struct dtv_frontend_properties *p = &fe->dtv_property_cache;
- u64 tmp64;
- if (p->cnr.stat[0].scale == FE_SCALE_NOT_AVAILABLE) {
- *snr = 0;
- return 0;
- }
- tmp64 = p->cnr.stat[0].svalue;
- do_div(tmp64, 10);
- *snr = tmp64;
- return 0;
- }
- static int drx39xxj_read_ucblocks(struct dvb_frontend *fe, u32 *ucb)
- {
- struct dtv_frontend_properties *p = &fe->dtv_property_cache;
- if (p->block_error.stat[0].scale == FE_SCALE_NOT_AVAILABLE) {
- *ucb = 0;
- return 0;
- }
- *ucb = p->block_error.stat[0].uvalue;
- return 0;
- }
- static int drx39xxj_set_frontend(struct dvb_frontend *fe)
- {
- #ifdef DJH_DEBUG
- int i;
- #endif
- struct dtv_frontend_properties *p = &fe->dtv_property_cache;
- struct drx39xxj_state *state = fe->demodulator_priv;
- struct drx_demod_instance *demod = state->demod;
- enum drx_standard standard = DRX_STANDARD_8VSB;
- struct drx_channel channel;
- int result;
- static const struct drx_channel def_channel = {
- /* frequency */ 0,
- /* bandwidth */ DRX_BANDWIDTH_6MHZ,
- /* mirror */ DRX_MIRROR_NO,
- /* constellation */ DRX_CONSTELLATION_AUTO,
- /* hierarchy */ DRX_HIERARCHY_UNKNOWN,
- /* priority */ DRX_PRIORITY_UNKNOWN,
- /* coderate */ DRX_CODERATE_UNKNOWN,
- /* guard */ DRX_GUARD_UNKNOWN,
- /* fftmode */ DRX_FFTMODE_UNKNOWN,
- /* classification */ DRX_CLASSIFICATION_AUTO,
- /* symbolrate */ 5057000,
- /* interleavemode */ DRX_INTERLEAVEMODE_UNKNOWN,
- /* ldpc */ DRX_LDPC_UNKNOWN,
- /* carrier */ DRX_CARRIER_UNKNOWN,
- /* frame mode */ DRX_FRAMEMODE_UNKNOWN
- };
- u32 constellation = DRX_CONSTELLATION_AUTO;
- /* Bring the demod out of sleep */
- drx39xxj_set_powerstate(fe, 1);
- if (fe->ops.tuner_ops.set_params) {
- u32 int_freq;
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 1);
- /* Set tuner to desired frequency and standard */
- fe->ops.tuner_ops.set_params(fe);
- /* Use the tuner's IF */
- if (fe->ops.tuner_ops.get_if_frequency) {
- fe->ops.tuner_ops.get_if_frequency(fe, &int_freq);
- demod->my_common_attr->intermediate_freq = int_freq / 1000;
- }
- if (fe->ops.i2c_gate_ctrl)
- fe->ops.i2c_gate_ctrl(fe, 0);
- }
- switch (p->delivery_system) {
- case SYS_ATSC:
- standard = DRX_STANDARD_8VSB;
- break;
- case SYS_DVBC_ANNEX_B:
- standard = DRX_STANDARD_ITU_B;
- switch (p->modulation) {
- case QAM_64:
- constellation = DRX_CONSTELLATION_QAM64;
- break;
- case QAM_256:
- constellation = DRX_CONSTELLATION_QAM256;
- break;
- default:
- constellation = DRX_CONSTELLATION_AUTO;
- break;
- }
- break;
- default:
- return -EINVAL;
- }
- /* Set the standard (will be powered up if necessary */
- result = ctrl_set_standard(demod, &standard);
- if (result != 0) {
- pr_err("Failed to set standard! result=%02x\n",
- result);
- return -EINVAL;
- }
- /* set channel parameters */
- channel = def_channel;
- channel.frequency = p->frequency / 1000;
- channel.bandwidth = DRX_BANDWIDTH_6MHZ;
- channel.constellation = constellation;
- /* program channel */
- result = ctrl_set_channel(demod, &channel);
- if (result != 0) {
- pr_err("Failed to set channel!\n");
- return -EINVAL;
- }
- /* Just for giggles, let's shut off the LNA again.... */
- drxj_set_lna_state(demod, false);
- /* After set_frontend, except for strength, stats aren't available */
- p->strength.stat[0].scale = FE_SCALE_RELATIVE;
- return 0;
- }
- static int drx39xxj_sleep(struct dvb_frontend *fe)
- {
- /* power-down the demodulator */
- return drx39xxj_set_powerstate(fe, 0);
- }
- static int drx39xxj_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
- {
- struct drx39xxj_state *state = fe->demodulator_priv;
- struct drx_demod_instance *demod = state->demod;
- bool i2c_gate_state;
- int result;
- #ifdef DJH_DEBUG
- pr_debug("i2c gate call: enable=%d state=%d\n", enable,
- state->i2c_gate_open);
- #endif
- if (enable)
- i2c_gate_state = true;
- else
- i2c_gate_state = false;
- if (state->i2c_gate_open == enable) {
- /* We're already in the desired state */
- return 0;
- }
- result = ctrl_i2c_bridge(demod, &i2c_gate_state);
- if (result != 0) {
- pr_err("drx39xxj: could not open i2c gate [%d]\n",
- result);
- dump_stack();
- } else {
- state->i2c_gate_open = enable;
- }
- return 0;
- }
- static int drx39xxj_init(struct dvb_frontend *fe)
- {
- struct drx39xxj_state *state = fe->demodulator_priv;
- struct drx_demod_instance *demod = state->demod;
- int rc = 0;
- if (fe->exit == DVB_FE_DEVICE_RESUME) {
- /* so drxj_open() does what it needs to do */
- demod->my_common_attr->is_opened = false;
- rc = drxj_open(demod);
- if (rc != 0)
- pr_err("drx39xxj_init(): DRX open failed rc=%d!\n", rc);
- } else
- drx39xxj_set_powerstate(fe, 1);
- return rc;
- }
- static int drx39xxj_set_lna(struct dvb_frontend *fe)
- {
- struct dtv_frontend_properties *c = &fe->dtv_property_cache;
- struct drx39xxj_state *state = fe->demodulator_priv;
- struct drx_demod_instance *demod = state->demod;
- struct drxj_data *ext_attr = demod->my_ext_attr;
- if (c->lna) {
- if (!ext_attr->has_lna) {
- pr_err("LNA is not supported on this device!\n");
- return -EINVAL;
- }
- }
- return drxj_set_lna_state(demod, c->lna);
- }
- static int drx39xxj_get_tune_settings(struct dvb_frontend *fe,
- struct dvb_frontend_tune_settings *tune)
- {
- tune->min_delay_ms = 1000;
- return 0;
- }
- static void drx39xxj_release(struct dvb_frontend *fe)
- {
- struct drx39xxj_state *state = fe->demodulator_priv;
- struct drx_demod_instance *demod = state->demod;
- /* if device is removed don't access it */
- if (fe->exit != DVB_FE_DEVICE_REMOVED)
- drxj_close(demod);
- kfree(demod->my_ext_attr);
- kfree(demod->my_common_attr);
- kfree(demod->my_i2c_dev_addr);
- release_firmware(demod->firmware);
- kfree(demod);
- kfree(state);
- }
- static struct dvb_frontend_ops drx39xxj_ops;
- struct dvb_frontend *drx39xxj_attach(struct i2c_adapter *i2c)
- {
- struct drx39xxj_state *state = NULL;
- struct i2c_device_addr *demod_addr = NULL;
- struct drx_common_attr *demod_comm_attr = NULL;
- struct drxj_data *demod_ext_attr = NULL;
- struct drx_demod_instance *demod = NULL;
- struct dtv_frontend_properties *p;
- int result;
- /* allocate memory for the internal state */
- state = kzalloc(sizeof(struct drx39xxj_state), GFP_KERNEL);
- if (state == NULL)
- goto error;
- demod = kmalloc(sizeof(struct drx_demod_instance), GFP_KERNEL);
- if (demod == NULL)
- goto error;
- demod_addr = kmemdup(&drxj_default_addr_g,
- sizeof(struct i2c_device_addr), GFP_KERNEL);
- if (demod_addr == NULL)
- goto error;
- demod_comm_attr = kmemdup(&drxj_default_comm_attr_g,
- sizeof(struct drx_common_attr), GFP_KERNEL);
- if (demod_comm_attr == NULL)
- goto error;
- demod_ext_attr = kmemdup(&drxj_data_g, sizeof(struct drxj_data),
- GFP_KERNEL);
- if (demod_ext_attr == NULL)
- goto error;
- /* setup the state */
- state->i2c = i2c;
- state->demod = demod;
- /* setup the demod data */
- memcpy(demod, &drxj_default_demod_g, sizeof(struct drx_demod_instance));
- demod->my_i2c_dev_addr = demod_addr;
- demod->my_common_attr = demod_comm_attr;
- demod->my_i2c_dev_addr->user_data = state;
- demod->my_common_attr->microcode_file = DRX39XX_MAIN_FIRMWARE;
- demod->my_common_attr->verify_microcode = true;
- demod->my_common_attr->intermediate_freq = 5000;
- demod->my_common_attr->current_power_mode = DRX_POWER_DOWN;
- demod->my_ext_attr = demod_ext_attr;
- ((struct drxj_data *)demod_ext_attr)->uio_sma_tx_mode = DRX_UIO_MODE_READWRITE;
- demod->i2c = i2c;
- result = drxj_open(demod);
- if (result != 0) {
- pr_err("DRX open failed! Aborting\n");
- goto error;
- }
- /* create dvb_frontend */
- memcpy(&state->frontend.ops, &drx39xxj_ops,
- sizeof(struct dvb_frontend_ops));
- state->frontend.demodulator_priv = state;
- /* Initialize stats - needed for DVBv5 stats to work */
- p = &state->frontend.dtv_property_cache;
- p->strength.len = 1;
- p->pre_bit_count.len = 1;
- p->pre_bit_error.len = 1;
- p->post_bit_count.len = 1;
- p->post_bit_error.len = 1;
- p->block_count.len = 1;
- p->block_error.len = 1;
- p->cnr.len = 1;
- p->strength.stat[0].scale = FE_SCALE_RELATIVE;
- p->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
- return &state->frontend;
- error:
- kfree(demod_ext_attr);
- kfree(demod_comm_attr);
- kfree(demod_addr);
- kfree(demod);
- kfree(state);
- return NULL;
- }
- EXPORT_SYMBOL(drx39xxj_attach);
- static struct dvb_frontend_ops drx39xxj_ops = {
- .delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B },
- .info = {
- .name = "Micronas DRX39xxj family Frontend",
- .frequency_stepsize = 62500,
- .frequency_min = 51000000,
- .frequency_max = 858000000,
- .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
- },
- .init = drx39xxj_init,
- .i2c_gate_ctrl = drx39xxj_i2c_gate_ctrl,
- .sleep = drx39xxj_sleep,
- .set_frontend = drx39xxj_set_frontend,
- .get_tune_settings = drx39xxj_get_tune_settings,
- .read_status = drx39xxj_read_status,
- .read_ber = drx39xxj_read_ber,
- .read_signal_strength = drx39xxj_read_signal_strength,
- .read_snr = drx39xxj_read_snr,
- .read_ucblocks = drx39xxj_read_ucblocks,
- .release = drx39xxj_release,
- .set_lna = drx39xxj_set_lna,
- };
- MODULE_DESCRIPTION("Micronas DRX39xxj Frontend");
- MODULE_AUTHOR("Devin Heitmueller");
- MODULE_LICENSE("GPL");
- MODULE_FIRMWARE(DRX39XX_MAIN_FIRMWARE);
|